Re: A slow query - Help please?

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Alban Hertroys <alban(at)magproductions(dot)nl>
Cc: Jim Nasby <jnasby(at)pervasive(dot)com>, hubert depesz lubaczewski <depesz(at)gmail(dot)com>, Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: A slow query - Help please?
Date: 2006-06-21 10:05:22
Message-ID: 20060621100522.GA7859@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message simon 2006-06-21 10:23:44 Re: merge result sets
Previous Message Oleg Golovanov 2006-06-21 10:01:44 Re: [GENERAL] DocBook 4.2 detecting at configure time