• Tom Lane's avatar
    Repair planner bug introduced in 8.2 by ability to rearrange outer joins: · 11086f2f
    Tom Lane authored
    in cases where a sub-SELECT inserts a WHERE clause between two outer joins,
    that clause may prevent us from re-ordering the two outer joins.  The code
    was considering only the joins' own ON-conditions in determining reordering
    safety, which is not good enough.  Add a "delay_upper_joins" flag to
    OuterJoinInfo to flag that we have detected such a clause and higher-level
    outer joins shouldn't be permitted to commute with this one.  (This might
    seem overly coarse, but given the current rules for OJ reordering, it's
    sufficient AFAICT.)
    
    The failure case is actually pretty narrow: it needs a WHERE clause within
    the RHS of a left join that checks the RHS of a lower left join, but is not
    strict for that RHS (else we'd have simplified the lower join to a plain
    join).  Even then no failure will be manifest unless the planner chooses to
    rearrange the join order.
    
    Per bug report from Adam Terrey.
    11086f2f
equalfuncs.c 50.8 KB