Appropriate indices to create for these queries

From: "Gerald Gutierrez" <gutz(at)kalador(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Appropriate indices to create for these queries
Date: 2001-04-03 01:49:44
Message-ID: IIEOKIIOJMELMIFMMEBFOEILCAAA.gutz@kalador.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


I've been looking into indices and which ones to create and I'm getting
myself a little confused. The "PostgreSQL Introduction and Concepts" book
didn't help very much. I wonder if a kind soul can give me some tips.

SELECT * FROM T1 WHERE a=1 and b='hello';

Is the appropriate index for this query:

CREATE INDEX ndx ON T1 (a, b) ?

When I was testing, it seemed that even if I created the index with only
"a", EXPLAIN told me that it would just do an index scan, seemingly
indicating that it didn't matter whether I had an "a" index, or an "a, b"
index.

How about for WHERE a=1 or b='hello' and other more complex forms? Is there
documentation that describes a variety of different queries and what kind of
indices are best?

Thanks.

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Picard, Cyril 2001-04-03 07:00:26 passing null parameter to plpgsq functions
Previous Message Tom Lane 2001-04-03 01:19:07 Re: very very slow .....