when to use index, and when not to us index - *the* answer :)

From: Hubert depesz Lubaczewski <depesz(at)depesz(dot)pl>
To: pgsql-general(at)postgresql(dot)org
Subject: when to use index, and when not to us index - *the* answer :)
Date: 2002-08-12 18:24:50
Message-ID: 20020812182450.GA7452@depesz.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

hi
i just made tests which show following results:

data type: | rec# | idx-time | seq-time | diff.
--------------+------+----------+----------+----------
int4.rnd | 91 | 0.941282 | 0.984096 | 0.042814
int4.seq | 97 | 0.937176 | 0.988626 | 0.051450
int8.rnd | 135 | 0.946168 | 1.036118 | 0.089950
int8.seq | 65 | 0.941527 | 0.963275 | 0.021748
char4.rnd | 32 | 0.945356 | 0.965213 | 0.019857
char4.seq | 39 | 0.949922 | 0.997675 | 0.047753
char8.rnd | 61 | 0.963562 | 1.030349 | 0.066787
char8.seq | 35 | 0.991704 | 1.002345 | 0.010641
char16.rnd | 37 | 0.978170 | 0.990919 | 0.012749
char16.seq | 17 | 0.975246 | 0.978144 | 0.002898
char32.rnd | 34 | 0.992438 | 0.998808 | 0.006370
char32.seq | 18 | 1.005228 | 1.020824 | 0.015596
char64.rnd | 66 | 1.042605 | 1.139358 | 0.096753
char64.seq | 20 | 1.066124 | 1.128776 | 0.062652
char128.rnd | 55 | 1.146153 | 1.187139 | 0.040986
char128.seq | 12 | 1.175579 | 1.215656 | 0.040077

what exactly it is?
is shows that for a single-field table (field of type "data type"), you
get index-scan faster then seq-scan, only when you reach "rec#" records
in table.
for example:
for table:
create table test (field int4); and values inserted sequentially, you
will benefit from creating index only after you'll reach 97 records.
before this, index scan will be slower then seq-scan.

hope this helps some people.
feel free to ask questions.

depesz

--
hubert depesz lubaczewski http://www.depesz.pl/
------------------------------------------------------------------------
Mój Boże, spraw abym milczał, dopóki się nie upewnię, że naprawdę mam
coś do powiedzenia. (c) 1998 depesz

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Peter Eisentraut 2002-08-12 20:07:18 Re: [GENERAL] Linux Largefile Support In Postgresql RPMS
Previous Message Vivek Khera 2002-08-12 17:18:43 Re: O'Reilly Open Source Convention Report