Re: [ADMIN] Q: Structured index - which one runs faster? - Mailing list pgsql-general

From Tom Lane
Subject Re: [ADMIN] Q: Structured index - which one runs faster?
Date
Msg-id 17188.1053711517@sss.pgh.pa.us
Whole thread Raw
In response to Re: [ADMIN] Q: Structured index - which one runs faster?  (Vivek Khera <khera@kcilink.com>)
Responses Re: [ADMIN] Q: Structured index - which one runs faster?
List pgsql-general
Vivek Khera <khera@kcilink.com> writes:
> Are any of these indexes redundant:

>  CREATE UNIQUE INDEX user_list_id_email ON user_list (owner_id,user_email);
>  CREATE INDEX user_list_owner_id ON user_list (owner_id);
>  CREATE INDEX user_list_oid_created ON user_list (owner_id,user_created);

> In particular, is user_list_owner_id redundant to
> user_list_oid_created?

Any of the three indexes can be used for a search on owner_id alone, so
yeah, user_list_owner_id is redundant.  It would be marginally faster to
use user_list_owner_id for such a search, just because it's physically
smaller than the other two indexes, but against that you have to balance
the extra update cost of maintaining the additional index.

Also, I can imagine scenarios where even a pure SELECT query load could
find the extra index to be a net loss: if you have a mix of queries that
use two or all three indexes, and the indexes don't fit in kernel disk
cache but just one or two would, then you'll lose on extra I/O as the
indexes compete for cache space.  Not sure how likely that scenario is,
but it's something to think about.

            regards, tom lane

pgsql-general by date:

Previous
From: "scott.marlowe"
Date:
Subject: Re: caching query results
Next
From: Vivek Khera
Date:
Subject: Re: [ADMIN] Q: Structured index - which one runs faster?