Re: Indexing problem with OFFSET LIMIT

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Indexing problem with OFFSET LIMIT
Дата
Msg-id 7115.1220065114@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Indexing problem with OFFSET LIMIT  ("Merlin Moncure" <mmoncure@gmail.com>)
Список pgsql-general
"Merlin Moncure" <mmoncure@gmail.com> writes:
> On Fri, Aug 29, 2008 at 4:38 PM, Oliver Weichhold <oliver@weichhold.com> wrote:
>> Consider this query:
>>
>> SELECT * FROM foo WHERE realm_id = 228 order by foo_name LIMIT 200 OFFSET
>> 15000

> try this:
> SELECT * FROM foo WHERE realm_id = 228 order by realm_id, foo_name
> LIMIT 200 OFFSET
>  15000

> Or even better don't use 'offset' at all.   It's simply lousy.   If
> you want to skip ahead 200 rows at a time, save off the previous last
> extracted rows in the app:

Yeah, large OFFSET values are always going to suck performance-wise,
because there is no magic way to skip over those rows --- the backend
has to read them, and then throw them away internally.  Avoid OFFSET.

Aside from the type of trick Merlin mentions, have you considered using
a cursor?

            regards, tom lane

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

Предыдущее
От: Bill Todd
Дата:
Сообщение: SELECT INTO returns incorrect values
Следующее
От: Ron Mayer
Дата:
Сообщение: Re: Postgresql 8.3 statistic stadistinct value dead wrong even with default_statistics_target=1000