From: | Odd Hogstad <odd(dot)hogstad(at)smartm(dot)no> |
---|---|
To: | "Jean-Yves F(dot) Barbier" <12ukwn(at)gmail(dot)com> |
Cc: | "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org> |
Subject: | Re: Order-by and indexes |
Date: | 2011-06-30 10:01:13 |
Message-ID: | BANLkTikyHAErwdxaTkJbzO179sTpKxg0TQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
>> 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.
I added an index for this, and now it goes much faster, thanks. The ones
that contain data is now superfast, 1-2 ms, but the ones that does not
match, and returns empty sets, are considerably slower, 150 -200 ms. Is this
something I have to live with, or are there any tricks that will make these
queries fast to?
Thanks again!
Odd-R.
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Wood | 2011-06-30 11:05:29 | Re: Connecting to PostgreSQL server |
Previous Message | Vincent Ficet | 2011-06-30 08:30:45 | Re: pg_advisory_locks in a multithreaded application context |