aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/nodeAgg.c
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2017-11-23 17:13:09 -0800
committerAndres Freund <andres@anarazel.de>2017-11-23 17:15:27 -0800
commit59b71c6fe6ca89566f40439bcdff94a2f5b39a92 (patch)
treeb48777dda27a440d7b90a624a93275e105cab28b /src/backend/executor/nodeAgg.c
parent07bd77b95a7846de2b193d1574951436d5783800 (diff)
downloadpostgresql-59b71c6fe6ca89566f40439bcdff94a2f5b39a92.tar.gz
postgresql-59b71c6fe6ca89566f40439bcdff94a2f5b39a92.zip
Fix handling of NULLs returned by aggregate combine functions.
When strict aggregate combine functions, used in multi-stage/parallel aggregation, returned NULL, we didn't check for that, invoking the combine function with NULL the next round, despite it being strict. The equivalent code invoking normal transition functions has a check for that situation, which did not get copied in a7de3dc5c346. Fix the bug by adding the equivalent check. Based on a quick look I could not find any strict combine functions in core actually returning NULL, and it doesn't seem very likely external users have done so. So this isn't likely to have caused issues in practice. Add tests verifying transition / combine functions returning NULL is tested. Reported-By: Andres Freund Author: Andres Freund Discussion: https://postgr.es/m/20171121033642.7xvmjqrl4jdaaat3@alap3.anarazel.de Backpatch: 9.6, where parallel aggregation was introduced
Diffstat (limited to 'src/backend/executor/nodeAgg.c')
-rw-r--r--src/backend/executor/nodeAgg.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c
index d26ce0847a0..da6ef1a94c4 100644
--- a/src/backend/executor/nodeAgg.c
+++ b/src/backend/executor/nodeAgg.c
@@ -1246,6 +1246,17 @@ advance_combine_function(AggState *aggstate,
pergroupstate->noTransValue = false;
return;
}
+
+ if (pergroupstate->transValueIsNull)
+ {
+ /*
+ * Don't call a strict function with NULL inputs. Note it is
+ * possible to get here despite the above tests, if the combinefn
+ * is strict *and* returned a NULL on a prior cycle. If that
+ * happens we will propagate the NULL all the way to the end.
+ */
+ return;
+ }
}
/* We run the combine functions in per-input-tuple memory context */