From 62b695550f5565bba4998a739035f417ec44c764 Mon Sep 17 00:00:00 2001 From: zhoujiaqi Date: Fri, 3 Jan 2025 16:32:32 +0800 Subject: [PATCH] Adapting aggsplit in multi stage agg --- .../translate/CTranslatorDXLToPlStmt.cpp | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/backend/gpopt/translate/CTranslatorDXLToPlStmt.cpp b/src/backend/gpopt/translate/CTranslatorDXLToPlStmt.cpp index c94e2040213..3955a50814b 100644 --- a/src/backend/gpopt/translate/CTranslatorDXLToPlStmt.cpp +++ b/src/backend/gpopt/translate/CTranslatorDXLToPlStmt.cpp @@ -2703,23 +2703,38 @@ CTranslatorDXLToPlStmt::TranslateDXLAgg( // Set the aggsplit for the agg node ListCell *lc; INT aggsplit = 0; - foreach (lc, plan->targetlist) + int idx = 0; + ForEach (lc, plan->targetlist) { TargetEntry *te = (TargetEntry *) lfirst(lc); if (IsA(te->expr, Aggref)) { Aggref *aggref = (Aggref *) te->expr; - aggsplit |= aggref->aggsplit; - - if (AGGSPLIT_INTERMEDIATE == aggsplit) + if (AGGSPLIT_INTERMEDIATE != aggsplit) { - break; + aggsplit |= aggref->aggsplit; } + + aggref->aggno = idx; + aggref->aggtransno = idx; + idx++; } } agg->aggsplit = (AggSplit) aggsplit; + ForEach (lc, plan->qual) + { + Expr *expr = (Expr *) lfirst(lc); + if (IsA(expr, Aggref)) + { + Aggref *aggref = (Aggref *) expr; + aggref->aggno = idx; + aggref->aggtransno = idx; + idx++; + } + } + plan->lefttree = child_plan; // translate aggregation strategy