From: Greg Stark <gsstark@mit.edu>
To: Clive Page <cgp@leicester.ac.uk>
Cc: pgsql-performance@postgresql.org
Subject: Re: Inefficient SELECT with OFFSET and LIMIT
Date: 06 Jan 2004 13:12:17 -0500
Message-ID: <878ykl0wvy.fsf@stark.dyndns.tv> (raw)
In-Reply-To: <Pine.SGI.4.21.0401061539460.10317357-100000@harrier.le.ac.uk>
References: <Pine.SGI.4.21.0401061539460.10317357-100000@harrier.le.ac.uk>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: gsstark@mit.edu, cgp@leicester.ac.uk
Subject: Re: Inefficient SELECT with OFFSET and LIMIT
In-Reply-To: <878ykl0wvy.fsf@stark.dyndns.tv>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox