Re: Why my cursor construction is so slow?

Поиск
Список
Период
Сортировка
От Martijn van Oosterhout
Тема Re: Why my cursor construction is so slow?
Дата
Msg-id 20060622071944.GB23150@svana.org
обсуждение исходный текст
Ответ на Why my cursor construction is so slow?  ("biuro@globeinphotos.com" <biuro@globeinphotos.com>)
Ответы Re: Why my cursor construction is so slow?
Список pgsql-general
On Tue, Jun 20, 2006 at 02:06:19AM -0700, biuro@globeinphotos.com wrote:
> Such construction is very slow but when I modify SQL to:
>         OPEN cursor1 FOR SELECT * FROM alias WHERE mask>=alias_out
> ORDER BY mask LIMIT 100;
>
> it works very fast. It is strange for me becuase I've understood so far
> that when cursor is open select is executed but Postgres does not
> select all rows - only cursor is positioned on first row, when you
> execute fetch next row is read. But this example shows something
> different.

PostgreSQL tries to optimise for overall query time. Without the limit
it tries to find a plan that will return the whole set as quick as
possible. With the LIMIT it might take a different approach, which
might be worse if you read the whole lot, but better for a limited set.
A fast-start plan so to speak.

To see detail I'd suggest doing an EXPLAIN ANALYZE over the query with
and with limit to see the changes.

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

Вложения

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

Предыдущее
От: "A. Kretschmer"
Дата:
Сообщение: Re: SELECT statement takes 10 minutes to answer
Следующее
От: Martijn van Oosterhout
Дата:
Сообщение: Re: Dynamic loading of C functions