Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6d85bb1

Browse files
committed
Correctly set up aggregate FILTER expression in partial-aggregation plans.
The aggfilter expression should be removed from the parent (combining)Aggref, since it's not supposed to apply the filter, and indeed cannotbecause any Vars used in the filter would not be available after thelower-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 commit59a3795, when setrefs.cbegan processing the parent Aggref's fields normally and thus would detectsuch Vars. The special-case coding previously used in setrefs.c skippedover the parent's aggfilter field without processing it. That was brokenin its own way because no other setrefs.c processing got applied either;though since the executor would not execute the filter expression, onlyinitialize it, that oversight might not have had any visible symptoms atpresent.)Report: <CAMkU=1xfuPf2edAe4ZGXTmJpU7jxuKukKyvNtEXwu35B7dvejg@mail.gmail.com>
1 parent9d7abca commit6d85bb1

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

‎src/backend/optimizer/plan/setrefs.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,6 +1752,10 @@ convert_combining_aggrefs(Node *node, void *context)
17521752
Aggref*child_agg;
17531753
Aggref*parent_agg;
17541754

1755+
/* Assert we've not chosen to partial-ize any unsupported cases */
1756+
Assert(orig_agg->aggorder==NIL);
1757+
Assert(orig_agg->aggdistinct==NIL);
1758+
17551759
/*
17561760
* Since aggregate calls can't be nested, we needn't recurse into the
17571761
* arguments. But for safety, flat-copy the Aggref node itself rather
@@ -1762,13 +1766,17 @@ convert_combining_aggrefs(Node *node, void *context)
17621766

17631767
/*
17641768
* For the parent Aggref, we want to copy all the fields of the
1765-
* original aggregate *except* the args list. Rather than explicitly
1766-
* knowing what they all are here, we can momentarily modify child_agg
1767-
* to provide a source for copyObject.
1769+
* original aggregate *except* the args list, which we'll replace
1770+
* below, and the aggfilter expression, which should be applied only
1771+
* by the child not the parent. Rather than explicitly knowing about
1772+
* all the other fields here, we can momentarily modify child_agg to
1773+
* provide a suitable source for copyObject.
17681774
*/
17691775
child_agg->args=NIL;
1776+
child_agg->aggfilter=NULL;
17701777
parent_agg= (Aggref*)copyObject(child_agg);
17711778
child_agg->args=orig_agg->args;
1779+
child_agg->aggfilter=orig_agg->aggfilter;
17721780

17731781
/*
17741782
* Now, set up child_agg to represent the first phase of partial

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp