Fix an error in make_outerjoininfo introduced by my patch of 30-Aug: the code
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 24 Oct 2007 20:54:33 +0000 (20:54 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 24 Oct 2007 20:54:33 +0000 (20:54 +0000)
neglected to test whether an outer join's join-condition actually refers to
the lower outer join it is looking at.  (The comment correctly described what
was supposed to happen, but the code didn't do it...)  This often resulted in
adding an unnecessary constraint on the join order of the two outer joins,
which was bad enough.  However, it also seems to expose a performance
problem in an older patch (from 15-Feb): once we've decided that there is a
join ordering constraint, we will start trying clauseless joins between every
combination of rels within the constraint, which pointlessly eats up lots of
time and space if there are numerous rels below the outer join.  That probably
needs to be revisited :-(.  Per gripe from Jakub Ouhrabka.

src/backend/optimizer/plan/initsplan.c

index c49f6bd4d9ad3a561e166bb1706df3be03e3a91e..ae8f699d9a2b3752f90a7d8318612bd79386f30b 100644 (file)
@@ -623,6 +623,7 @@ make_outerjoininfo(PlannerInfo *root,
                 * rel in the lower OJ's min_righthand, not its whole syn_righthand.
                 */
                if (bms_overlap(left_rels, otherinfo->syn_righthand) &&
+                       bms_overlap(clause_relids, otherinfo->syn_righthand) &&
                        !bms_overlap(strict_relids, otherinfo->min_righthand))
                {
                        min_lefthand = bms_add_members(min_lefthand,