Greg Stark <[EMAIL PROTECTED]> writes:
> Clive Page <[EMAIL PROTECTED]> writes:
>> 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;

Note that this won't eliminate the major inefficiency, which is having
to read 10000+50 rows from the table.  But if myfunc() has side-effects
or is very expensive to run, it'd probably be worth doing.

> I think it's not easy for the optimizer to do it because there are lots of
> cases where it can't.

I don't actually know of any cases where it could do much of anything to
avoid fetching the OFFSET rows.  The problems are basically the same as
with COUNT(*) optimization: without examining each row, you don't know
if it would have been returned or not.  We could possibly postpone
evaluation of the SELECT output list until after the OFFSET step (thus
automating the above hack), but even that only works if there are no
set-returning functions in the output list ...

                        regards, tom lane

PS: BTW, the one-extra-row effect that Clive noted is gone in 7.4.

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
      subscribe-nomail command to [EMAIL PROTECTED] so that your
      message can get through to the mailing list cleanly

Reply via email to