Re: Cursors with Large, Ordered Result Sets

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Rupert <rminnett(at)rsmas(dot)miami(dot)edu>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Cursors with Large, Ordered Result Sets
Date: 2003-04-01 18:27:35
Message-ID: 20030401095839.N51133-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 27 Mar 2003, Rupert wrote:

> Thanks for the quick reply and sorry for the slow response.
>
> Yes, this is very similar to what we are currently doing and it seems
> to be working rather well - much to my surprise. However, I still have
> the same questions regarding the actual steps being taken by the DBMS
> to order a massive result set. Doesn't it need to have the entire
> result in memory before it can return the first records? If so, and

Whether or not you need to sort depends on the query.

For example:

select * from foo order by a;

could choose to use an index on foo.a to do the ordering rather than a
sort. It'll choose based on what it thinks will be the best plan.

> the result is larger than the RAM, does it dump it to disk and then
> sort?

It's based on the sort_mem GUC parameter and will go to disk if necessary.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Joe Conway 2003-04-01 18:46:26 Re: create type problem!
Previous Message scott.marlowe 2003-04-01 17:26:27 Re: Dates in inserts