Inefficient SELECT with OFFSET and LIMIT

Поиск
Список
Период
Сортировка
От Clive Page
Тема Inefficient SELECT with OFFSET and LIMIT
Дата
Msg-id Pine.SGI.4.21.0401061539460.10317357-100000@harrier.le.ac.uk
обсуждение исходный текст
Ответы Re: Inefficient SELECT with OFFSET and LIMIT
Список pgsql-performance
I have just discovered that if one does a SELECT with a LIMIT and OFFSET
     values, say

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

Then the whole of the selection expressions, including the function calls,
are actuall executed for every record, not just those being selected but
also those being skipped, i.e. 10050 in this case.
Actually it's even odder, as the number is that plus one, as the next
record in sequence is also passed to the function.

I discovered this by accident, since I was using a user-defined function
in pl/pgsql and included by mistake some debug code using RAISE INFO, so
this diagnostic output gave the game away (and all of it came out before
any of the results of the selection, which was another surprise).

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.



--
Clive Page,
Dept of Physics & Astronomy,
University of Leicester, U.K.


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

Предыдущее
От: Shridhar Daithankar
Дата:
Сообщение: Re: Select max(foo) and select count(*) optimization
Следующее
От: Robert Treat
Дата:
Сообщение: Re: Select max(foo) and select count(*) optimization