Re: [SQL] Limit rows

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [SQL] Limit rows
Дата
Msg-id 5408.938648218@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: [SQL] Limit rows  (Mark Jewiss <Mark.Jewiss@knowledge.com>)
Список pgsql-sql
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


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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: [SQL] Date: Wed, 29 Sep 1999 23:49:15 +0300
Следующее
От: Chairudin Sentosa Harjo
Дата:
Сообщение: Constraint Problem