Re: Order-by and indexes

Поиск
Список
Период
Сортировка
От Odd Hogstad
Тема Re: Order-by and indexes
Дата
Msg-id BANLkTikyHAErwdxaTkJbzO179sTpKxg0TQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Order-by and indexes  ("Jean-Yves F. Barbier" <12ukwn@gmail.com>)
Список 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.

В списке pgsql-novice по дате отправления:

Предыдущее
От: Vincent Ficet
Дата:
Сообщение: Re: pg_advisory_locks in a multithreaded application context
Следующее
От: Michael Wood
Дата:
Сообщение: Re: Connecting to PostgreSQL server