Re: Query slows after offset of 100K

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Query slows after offset of 100K
Дата
Msg-id 17159.1203016095@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Query slows after offset of 100K  (Michael Lorenz <mlorenz1@hotmail.com>)
Ответы Re: Query slows after offset of 100K
Список pgsql-performance
Michael Lorenz <mlorenz1@hotmail.com> writes:
> My query is as follows:
> SELECT o.objectid, o.objectname, o.isactive, o.modificationtime
> FROM    object o
> WHERE  ( o.deleted = false OR o.deleted IS NULL )
> AND      o.accountid = 111
> ORDER BY 2
> LIMIT 20 OFFSET 10000;

This is guaranteed to lose --- huge OFFSET values are never a good idea
(hint: the database still has to fetch those rows it's skipping over).

A saner way to do pagination is to remember the last key you displayed
and do something like "WHERE key > $lastkey ORDER BY key LIMIT 20",
which will allow the database to go directly to the desired rows,
as long as you have an index on the key.  You do need a unique ordering
key for this to work, though.

            regards, tom lane

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

Предыдущее
От: Michael Lorenz
Дата:
Сообщение: Query slows after offset of 100K
Следующее
От: Michael Lorenz
Дата:
Сообщение: Re: Query slows after offset of 100K