From: Tom Lane <tgl@sss.pgh.pa.us>
To: Mark Jewiss <Mark.Jewiss@knowledge.com>
Cc: Oleg Bartunov <oleg@sai.msu.su>
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] Limit rows
Date: Wed, 29 Sep 1999 19:36:58 -0400
Message-ID: <5408.938648218@sss.pgh.pa.us> (raw)
In-Reply-To: <Pine.BSO.4.10.9909291706390.5608-100000@office.knowledge.com>
Mark Jewiss <Mark.Jewiss@knowledge.com> writes:
> [ re LIMIT ]
> I'm interested now in how this method actually works - is a query
> performed that reads all of the rows of a table into memory, and then the
> non-requested rows are discarded before the results are sent back?
> I'm interested in how this would work with a massive table......
The executor will stop generating rows as soon as it's satisfied the
limit+offset. Whether that's actually quick depends on your query;
for example, if you do something that requires an explicit sort step,
the full sort has to be done anyway (since there's no way to tell
which rows it'd return first without finishing the sort...). You can
use EXPLAIN if you're not sure whether a query will use a sort.
Also, a large offset and a small limit might not be as fast as you'd
like, since the rows discarded by OFFSET will be generated and then
dropped. So, you should not consider this feature as a substitute for a
cursor. If you intend to fetch most of a table a little bit at a time,
you want to use DECLARE CURSOR and FETCH.
regards, tom lane
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, Mark.Jewiss@knowledge.com, oleg@sai.msu.su
Subject: Re: [SQL] Limit rows
In-Reply-To: <5408.938648218@sss.pgh.pa.us>
References: <Pine.BSO.4.10.9909291706390.5608-100000@office.knowledge.com> <5408.938648218@sss.pgh.pa.us>
* 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