aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/nodeAgg.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2017-10-11 22:18:01 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2017-10-11 22:18:10 -0400
commit52328727bea4d9f95af9622e4624b9d1492df88e (patch)
treeb17b554f63a4e1c7fd1ae2ba8d11f4d0076ab6f3 /src/backend/executor/nodeAgg.c
parent36b4b91ba07843406d5a30106facb59d8275c6de (diff)
downloadpostgresql-52328727bea4d9f95af9622e4624b9d1492df88e.tar.gz
postgresql-52328727bea4d9f95af9622e4624b9d1492df88e.zip
Prevent sharing transition states between ordered-set aggregates.
This ought to work, but the built-in OSAs are not capable of coping, because their final-functions destructively modify their transition state (specifically, the contained tuplesort object). That was fine when those functions were written, but commit 804163bc2 moved the goalposts without telling orderedsetaggs.c. We should fix the built-in OSAs to support this, but it will take a little work, especially if we don't want to sacrifice performance in the normal non-shared-state case. Given that it took a year after 9.6 release for anyone to notice this bug, we should not prioritize sharable-state over nonsharable-state performance. And a proper fix is likely to be more complicated than we'd want to back-patch, too. Therefore, let's just put in this stop-gap patch to prevent nodeAgg.c from choosing to use shared state for OSAs. We can revert it in HEAD when we get a better fix. Report from Lukas Eder, diagnosis by me, patch by David Rowley. Back-patch to 9.6 where the problem was introduced. Discussion: https://postgr.es/m/CAB4ELO5RZhOamuT9Xsf72ozbenDLLXZKSk07FiSVsuJNZB861A@mail.gmail.com
Diffstat (limited to 'src/backend/executor/nodeAgg.c')
-rw-r--r--src/backend/executor/nodeAgg.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c
index 0ae5873868b..1a1aebe7b08 100644
--- a/src/backend/executor/nodeAgg.c
+++ b/src/backend/executor/nodeAgg.c
@@ -3808,6 +3808,16 @@ find_compatible_pertrans(AggState *aggstate, Aggref *newagg,
{
ListCell *lc;
+ /*
+ * For the moment, never try to share transition states between different
+ * ordered-set aggregates. This is necessary because the finalfns of the
+ * built-in OSAs (see orderedsetaggs.c) are destructive of their
+ * transition states. We should fix them so we can allow this, but not
+ * losing performance in the normal non-shared case will take some work.
+ */
+ if (AGGKIND_IS_ORDERED_SET(newagg->aggkind))
+ return -1;
+
foreach(lc, transnos)
{
int transno = lfirst_int(lc);