• Tom Lane's avatar
    Further adjustments to PlaceHolderVar removal. · 89db8392
    Tom Lane authored
    A new test case from Andreas Seltenreich showed that we were still a bit
    confused about removing PlaceHolderVars during join removal.  Specifically,
    remove_rel_from_query would remove a PHV that was used only underneath
    the removable join, even if the place where it's used was the join partner
    relation and not the join clause being deleted.  This would lead to a
    "too late to create a new PlaceHolderInfo" error later on.  We can defend
    against that by checking ph_eval_at to see if the PHV could possibly be
    getting used at some partner rel.
    
    Also improve some nearby LATERAL-related logic.  I decided that the check
    on ph_lateral needed to take precedence over the check on ph_needed, in
    case there's a lateral reference underneath the join being considered.
    (That may be impossible, but I'm not convinced of it, and it's easy enough
    to defend against the case.)  Also, I realized that remove_rel_from_query's
    logic for updating LateralJoinInfos is dead code, because we don't build
    those at all until after join removal.
    
    Back-patch to 9.3.  Previous versions didn't have the LATERAL issues, of
    course, and they also didn't attempt to remove PlaceHolderInfos during join
    removal.  (I'm starting to wonder if changing that was really such a great
    idea.)
    89db8392
analyzejoins.c 24.5 KB