This is an automated email from the ASF dual-hosted git repository.

maxyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git

commit 62b695550f5565bba4998a739035f417ec44c764
Author: zhoujiaqi <[email protected]>
AuthorDate: Fri Jan 3 16:32:32 2025 +0800

    Adapting aggsplit in multi stage agg
---
 .../gpopt/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 c94e204021..3955a50814 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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to