Re: A slow query - Help please? - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: A slow query - Help please?
Date
Msg-id 20060621100522.GA7859@svana.org
Whole thread Raw
In response to Re: A slow query - Help please?  (Alban Hertroys <alban@magproductions.nl>)
Responses Re: A slow query - Help please?
List pgsql-general
On Wed, Jun 21, 2006 at 11:56:27AM +0200, Alban Hertroys wrote:
> Say we take the query I posted:
>     "SELECT * FROM mm_posrel ORDER BY number DESC LIMIT 25;"
> and the knowledge that this table is inherited by two other tables, with
> number being unique across them (though PostgreSQL probably doesn't know
> about this).
> Can constraint exclusion determine that the last 25 number values do not
> occur in some of the tables?

ISTM that what would really work well is some kind of "Merge Sort" node
that would work by having multiple subnodes which are already sorted
and merging them into one sorted list.

The planner would use this whenever it saw a query of the form:

SELECT * FROM a
UNION ALL
SELECT * FROM b
ORDER BY c;

It would push the ORDER BY down to the subqueries and then merge the
results. If the subqueries can be read efficiently sorted (via an index
for example) then you would get very quick output, especially if you
have a LIMIT clause.

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.

Attachment

pgsql-general by date:

Previous
From: "Oleg Golovanov"
Date:
Subject: Re: DocBook 4.2 detecting at configure time
Next
From: simon
Date:
Subject: Re: merge result sets