Re: multiple joins + Order by + LIMIT query performance issue

From: Matthew Wakeling <matthew(at)flymine(dot)org>
To: "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: multiple joins + Order by + LIMIT query performance issue
Date: 2008-05-07 10:42:23
Message-ID: Pine.LNX.4.64.0805071141270.16756@aragorn.flymine.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Tue, 6 May 2008, Tom Lane wrote:
> If a misestimate of this kind is bugging you enough that you're willing
> to change the query, I think you can fix it like this:
>
> select ... from foo order by x limit n;
> =>
> select ... from (select ... from foo order by x) ss limit n;
>
> The subselect will be planned without awareness of the LIMIT, so you
> should get a plan using a sort rather than one that bets on the LIMIT
> being reached quickly.

Surely if that's the case, that in itself is a bug? Apart from being
"useful", I mean.

Matthew

--
"Television is a medium because it is neither rare nor well done."
-- Fred Friendly

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Matthew Wakeling 2008-05-07 10:46:27 Re: RAID 10 Benchmark with different I/O schedulers
Previous Message Albe Laurenz *EXTERN* 2008-05-07 07:29:05 Re: RAID 10 Benchmark with different I/O schedulers