Re: How to force PostgreSQL using an index

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Daniel Caune" <daniel(dot)caune(at)ubisoft(dot)com>
Cc: "Andrew Sullivan" <ajs(at)crankycanuck(dot)ca>, pgsql-sql(at)postgresql(dot)org
Subject: Re: How to force PostgreSQL using an index
Date: 2006-02-15 22:47:15
Message-ID: 20471.1140043635@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Daniel Caune" <daniel(dot)caune(at)ubisoft(dot)com> writes:
> SELECT <some-columns>
> FROM GSLOG_EVENT
> WHERE EVENT_NAME = 'player-status-update'
> AND EVENT_DATE_CREATED >= <start-time>
> AND EVENT_DATE_CREATED < <end-time>

> I have an index on EVENT_DATE_CREATED that does it job. But I though
> that I can help my favourite PostgreSQL if I create a composite index on
> EVENT_DATE_CREATED and EVENT_NAME (in that order as EVENT_DATE_CREATED
> is more dense that EVENT_NAME).

Wrong ... should be EVENT_NAME first. Think about the sort order of the
data to see why --- your query represents a contiguous subset of the
index if EVENT_NAME is first, but not if EVENT_DATE_CREATED is first.

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Daniel Caune 2006-02-15 22:48:06 Re: How to force PostgreSQL using an index
Previous Message Andrew Sullivan 2006-02-15 22:33:46 Re: How to force PostgreSQL using an index