diff --git a/src/backend/executor/nodeAgg.c b/src/backend/executor/nodeAgg.c index 0ae5873..b5d6545 100644 --- a/src/backend/executor/nodeAgg.c +++ b/src/backend/executor/nodeAgg.c @@ -3808,6 +3808,17 @@ find_compatible_pertrans(AggState *aggstate, Aggref *newagg, { ListCell *lc; + /* + * Don't attempt to share aggregate states between ordered-set aggregates. + * Really this is a bit of a hack since some of the builtin ordered-set + * aggregate's final functions are destructive to the transition state. + * A proper fix for this would be to devise a method of allowing a final + * function to know if it was the first or last final function to be + * called on the aggregate state. + */ + if (newagg->aggkind == AGGKIND_HYPOTHETICAL) + return -1; + foreach(lc, transnos) { int transno = lfirst_int(lc);