Re: Order-by and indexes - Mailing list pgsql-novice

From Tom Lane
Subject Re: Order-by and indexes
Date
Msg-id 6005.1309360004@sss.pgh.pa.us
Whole thread Raw
In response to Order-by and indexes  (Odd Hogstad <odd.hogstad@smartm.no>)
List pgsql-novice
Odd Hogstad <odd.hogstad@smartm.no> writes:
> I need to get the latest entry of a large table matching a certain criteria.
> This is my query:

> SELECT * FROM "data" WHERE "data"."fk" = 238496 ORDER BY "data"."id" DESC
> LIMIT 1

A two-column index on (fk, id) would help for this.  If you think about
the ordering of the index entries you'll see why.

            regards, tom lane

pgsql-novice by date:

Previous
From: "Jean-Yves F. Barbier"
Date:
Subject: Re: Order-by and indexes
Next
From: Vincent Ficet
Date:
Subject: pg_advisory_locks in a multithreaded application context