Re: Terrible plan for join to nested union

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Nate Allan <nallan(at)ancestry(dot)com>
Cc: "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Terrible plan for join to nested union
Date: 2012-07-08 15:56:35
Message-ID: 3857.1341762995@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Nate Allan <nallan(at)ancestry(dot)com> writes:
> It seems to me that the join condition (and hence the restriction) should be pushed down into both sides of the union to bring the cardinality limit from millions to 1. I'm imagining a rewrite like this:
> R(a) J (b U c) -> (b J R(a)) U (c J R(a))
> ...where R = Restrict, J = Join, U = Union

[ eyes that suspiciously ... ] I'm not convinced that such a
transformation is either correct in general (you seem to be assuming
at least that A's join column is unique, and what is the UNION operator
supposed to do with A's other columns?) or likely to lead to a
performance improvement in general.

We possibly could push down a join condition on the inner side of a
nestloop, similarly to what's done in the UNION ALL case ... but that
would require a complete refactoring of what the planner does with
UNIONs. By and large, very little optimization effort has been put
into non-ALL UNION (or INTERSECT or EXCEPT). You should not expect
that to change on a time scale of less than years.

regards, tom lane

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Nate Allan 2012-07-09 04:02:23 Re: Terrible plan for join to nested union
Previous Message Nate Allan 2012-07-08 09:43:58 Re: Terrible plan for join to nested union