Re: Any better plan for this query?..

From: Scott Carey <scott(at)richrelevance(dot)com>
To: Matthew Wakeling <matthew(at)flymine(dot)org>, Simon Riggs <simon(at)2ndQuadrant(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Dimitri <dimitrik(dot)fr(at)gmail(dot)com>, Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>, Dimitri Fontaine <dfontaine(at)hi-media(dot)com>, Alvaro Herrera <alvherre(at)commandprompt(dot)com>, Aidan Van Dyk <aidan(at)highrise(dot)ca>, Merlin Moncure <mmoncure(at)gmail(dot)com>, PostgreSQL Performance <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Any better plan for this query?..
Date: 2009-05-19 16:38:27
Message-ID: C6382E93.652C%scott@richrelevance.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance


On 5/19/09 5:01 AM, "Matthew Wakeling" <matthew(at)flymine(dot)org> wrote:

> On Tue, 19 May 2009, Simon Riggs wrote:
>>> Speaking of avoiding large sorts, I'd like to push again for partial
>>> sorts. This is the situation where an index provides data sorted by
>>> column "a", and the query requests data sorted by "a, b". Currently,
>>> Postgres sorts the entire data set, whereas it need only group each
>>> set of identical "a" and sort each by "b".
>>
>> Partially sorted data takes much less effort to sort (OK, not zero, I
>> grant) so this seems like a high complexity, lower value feature. I
>> agree it should be on the TODO, just IMHO at a lower priority than some
>> other features.
>
> Not arguing with you, however I'd like to point out that partial sorting
> allows the results to be streamed, which would lower the cost to produce
> the first row of results significantly, and reduce the amount of RAM used
> by the query, and prevent temporary tables from being used. That has to be
> a fairly major win. Queries with a LIMIT would see the most benefit.
>

I will second that point --
Although for smaller sorts, the partial sort doesn't help much and is just
complicated -- once the sort is large, it reduces the amount of work_mem
needed significantly for large performance gain, and large concurrent query
scale gain.
And those benefits occur without using LIMIT.

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Scott Carey 2009-05-19 17:13:25 Re: Any better plan for this query?..
Previous Message Dimitri 2009-05-19 15:53:51 Re: Any better plan for this query?..