• Tom Lane's avatar
    Fix mis-optimization of semijoins with more than one LHS relation. · 2057a58d
    Tom Lane authored
    The inner-unique patch (commit 9c7f5229) supposed that if we're
    considering a JOIN_UNIQUE_INNER join path, we can always set inner_unique
    for the join, because the inner path produced by create_unique_path should
    be unique relative to the outer relation.  However, that's true only if
    we're considering joining to the whole outer relation --- otherwise we may
    be applying only some of the join quals, and so the inner path might be
    non-unique from the perspective of this join.  Adjust the test to only
    believe that we can set inner_unique if we have the whole semijoin LHS on
    the outer side.
    
    There is more that can be done in this area, but this commit is only
    intended to provide the minimal fix needed to get correct plans.
    
    Per report from Teodor Sigaev.  Thanks to David Rowley for preliminary
    investigation.
    
    Discussion: https://postgr.es/m/f994fc98-389f-4a46-d1bc-c42e05cb43ed@sigaev.ru
    2057a58d
join.sql 52.9 KB