Which index can i use ?

Gerardo Herzig gherzig at fmed.uba.ar
Mon Oct 29 08:45:46 EDT 2007


Abandoned wrote:

>Hi..
>I want to do index in postgresql & python.
>My table:
>id(int) | id2(int) | w(int) | d(int)
>
>My query:
>select id, w where id=x and id2=y (sometimes and d=z)
>
>I have too many insert and select operation on this table.
>And which index type can i use ? Btree, Rtree, Gist or Hash ?
>Also I want to unique (id, id2)..
>Now this is my index. is it give me good performance ?
>CREATE UNIQUE INDEX ind1 ON test USING btree (id, id2)
>CREATE INDEX ind2 ON test USING btree (id)
>CREATE INDEX ind3 ON test USING btree (id2)
>CREATE INDEX ind4 ON test USING btree (w)
>CREATE INDEX ind5 ON test USING btree (d)
>
>I'm too sorry my bad english.
>King regards..
>
>  
>
Well, this is no python-related at all. But, for a start, if you are not 
using the 'w' field in the WHERE clause, the ind4 index is not necesary 
at all. Having more indexes that you need is a waste of space and 
perfomance. It also depends on the amount of records your table has.
-Hash indexes are discouraged
-GiST indexes are for more advanced uses than equality comparisons
-Rtree are used in multidimentional indexing

So, keep the default btree. Do the test with the diff indexes if you 
want. You may use EXPLAIN for viewing the  index usage.
And dont forget about VACUUM too!

Cheers.
Gerardo



More information about the Python-list mailing list