• Tom Lane's avatar
    Correctly set up aggregate FILTER expression in partial-aggregation plans. · 6d85bb1b
    Tom Lane authored
    The aggfilter expression should be removed from the parent (combining)
    Aggref, since it's not supposed to apply the filter, and indeed cannot
    because any Vars used in the filter would not be available after the
    lower-level aggregation step.  Per report from Jeff Janes.
    
    (This has been broken since the introduction of partial aggregation,
    I think.  The error became obvious after commit 59a3795c, when setrefs.c
    began processing the parent Aggref's fields normally and thus would detect
    such Vars.  The special-case coding previously used in setrefs.c skipped
    over the parent's aggfilter field without processing it.  That was broken
    in its own way because no other setrefs.c processing got applied either;
    though since the executor would not execute the filter expression, only
    initialize it, that oversight might not have had any visible symptoms at
    present.)
    
    Report: <CAMkU=1xfuPf2edAe4ZGXTmJpU7jxuKukKyvNtEXwu35B7dvejg@mail.gmail.com>
    6d85bb1b
setrefs.c 74.6 KB