Re: Terrible plan for join to nested union - Mailing list pgsql-performance

From Tom Lane
Subject Re: Terrible plan for join to nested union
Date
Msg-id 3857.1341762995@sss.pgh.pa.us
Whole thread Raw
In response to Re: Terrible plan for join to nested union  (Nate Allan <nallan@ancestry.com>)
Responses Re: Terrible plan for join to nested union
List pgsql-performance
Nate Allan <nallan@ancestry.com> writes:
> It seems to me that the join condition (and hence the restriction) should be pushed down into both sides of the union
tobring 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

pgsql-performance by date:

Previous
From: Nate Allan
Date:
Subject: Re: Terrible plan for join to nested union
Next
From: Nate Allan
Date:
Subject: Re: Terrible plan for join to nested union