Re: Inefficient SELECT with OFFSET and LIMIT

Поиск
Список
Период
Сортировка
От Greg Stark
Тема Re: Inefficient SELECT with OFFSET and LIMIT
Дата
Msg-id 878ykl0wvy.fsf@stark.dyndns.tv
обсуждение исходный текст
Ответ на Inefficient SELECT with OFFSET and LIMIT  (Clive Page <cgp@leicester.ac.uk>)
Ответы Re: Inefficient SELECT with OFFSET and LIMIT  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-performance
Clive Page <cgp@leicester.ac.uk> writes:

> SELECT myfunc(mycol) FROM table LIMIT 50 OFFSET 10000 ;

> It looks as if OFFSET is implemented just be throwing away the results,
> until the OFFSET has been reached.
>
> It would be nice if OFFSET could be implemented in some more efficient
> way.

You could do something like:

select myfunc(mycol) from (select mycol from table limit 50 offset 10000) as x;

I think it's not easy for the optimizer to do it because there are lots of
cases where it can't. Consider if you had an ORDER BY clause on the myfunc
output column for example. Or if myfunc was a set-returning function.

--
greg

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

Предыдущее
От: Shridhar Daithankar
Дата:
Сообщение: Re: Select max(foo) and select count(*) optimization
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Inefficient SELECT with OFFSET and LIMIT