>> 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?