From: Tom Lane <tgl@sss.pgh.pa.us>
To: Sam Mason <sam@samason.me.uk>
Cc: pgsql-performance@postgresql.org
Subject: Re: Optimising queries involving unions
Date: Thu, 26 May 2005 12:53:54 -0400
Message-ID: <3339.1117126434@sss.pgh.pa.us> (raw)
In-Reply-To: <20050526152203.GI15205@colo.samason.me.uk>
References: <20050526152203.GI15205@colo.samason.me.uk>
Sam Mason <sam@samason.me.uk> writes:
> Here's a bad example:
> SELECT u.txt
> FROM smalltable t, (
> SELECT id, txt FROM largetable1
> UNION ALL
> SELECT id, txt FROM largetable2) u
> WHERE t.id = u.id
> AND t.foo = 'bar';
> I was hoping that "smalltable" would get moved up into the union,
> but it doesn't at the moment and the database does a LOT of extra
> work.
I'm afraid we're a long way away from being able to do that; the
parse/plan representation of UNION wasn't chosen with an eye to
being able to optimize it at all :-(. We can push restriction
clauses down into a union, but we can't do much with join clauses,
because they necessarily refer to tables that don't even exist
within the sub-query formed by the UNION.
It'd be nice to fix this someday, but don't hold your breath ...
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: tgl@sss.pgh.pa.us, sam@samason.me.uk
Subject: Re: Optimising queries involving unions
In-Reply-To: <3339.1117126434@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox