ORDER BY, LIMIT and indexes

Поиск
Список
Период
Сортировка
От Ivan Voras
Тема ORDER BY, LIMIT and indexes
Дата
Msg-id CAF-QHFW2S7XHMFY-nCSbBRsFQFC--3NyVqOcW7SMeNAs28NDcQ@mail.gmail.com
обсуждение исходный текст
Ответы Re: ORDER BY, LIMIT and indexes  (Claudio Freire <klaussfreire@gmail.com>)
Список pgsql-performance
Hello,

Assuming I have a huge table (doesn't fit in RAM), of which the most
important fields are "id" which is a SERIAL PRIMARY KEY and "active"
which is a boolean, and I'm issuing a query like:

SELECT * FROM table ORDER BY id DESC LIMIT 10

... is pgsql smart enough to use the index to fetch only the 10
required rows instead of reading the whole table, then sorting it,
then trimming the result set? How about in the following queries:

SELECT * FROM table ORDER BY id DESC LIMIT 10 OFFSET 10

SELECT * FROM table WHERE active ORDER BY id DESC LIMIT 10 OFFSET 10

Or, more generally, is there some set of circumstances under which the
catastrophic scenario will happen?


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

Предыдущее
От: Tomas Vondra
Дата:
Сообщение: Re: PG performance issues related to storage I/O waits
Следующее
От: Claudio Freire
Дата:
Сообщение: Re: ORDER BY, LIMIT and indexes