Re: A question about indexes... - Mailing list pgsql-sql

From Tom Lane
Subject Re: A question about indexes...
Date
Msg-id 19357.965334090@sss.pgh.pa.us
Whole thread Raw
In response to A question about indexes...  (Alexaki Sofia <alexaki@ics.forth.gr>)
List pgsql-sql
Alexaki Sofia <alexaki@ics.forth.gr> writes:
> I can either define the field id as a Primary Key or create an Btree index
> on it. What is more effient?? 
> From  my test I see that creating  Btree index is  a bit faster!!. 

I think you're seeing things.  Declaring a field primary key creates
a btree index on it (and also enables UNIQUE and NOT NULL checks, but
those don't affect the speed of lookups).  There isn't going to be
any difference between the two ways of doing it --- whatever difference
you measured was due to other factors, eg, disk pages already in cache.

As for your other point I'd generally recommend btree over hash indexes.
The btree code is much more thoroughly tested, supports concurrent
updates which hash indexes don't, and allows order-based index scans
which hash doesn't.  I don't see any redeeming social value in a hash
index, actually...
        regards, tom lane


pgsql-sql by date:

Previous
From: John McKown
Date:
Subject: Re: Extracting data by months
Next
From: Mark Volpe
Date:
Subject: Re: PL/pgSQL evaluation order