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

yiguolei pushed a commit to branch branch-4.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-4.1 by this push:
     new 24f5bd8de2a branch-4.1: [fix](agg push down) guard Count(*) child 
access with arity() check in PushDownAggThroughJoinOnPkFk #64848 (#64951)
24f5bd8de2a is described below

commit 24f5bd8de2a2bda01ce24976d8082be610095b36
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Wed Jul 1 10:39:40 2026 +0800

    branch-4.1: [fix](agg push down) guard Count(*) child access with arity() 
check in PushDownAggThroughJoinOnPkFk #64848 (#64951)
    
    Cherry-picked from #64848
    
    Co-authored-by: minghong <[email protected]>
---
 .../rules/rewrite/PushDownAggThroughJoinOnPkFk.java        |  1 +
 .../rules/rewrite/PushDownAggThroughJoinOnPkFkTest.java    | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushDownAggThroughJoinOnPkFk.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushDownAggThroughJoinOnPkFk.java
index 28dcc005ce4..f1d6e0816d1 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushDownAggThroughJoinOnPkFk.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushDownAggThroughJoinOnPkFk.java
@@ -215,6 +215,7 @@ public class PushDownAggThroughJoinOnPkFk implements 
RewriteRuleFactory {
             }
             if (expression instanceof Alias
                     && expression.child(0) instanceof Count
+                    && expression.child(0).arity() > 0
                     && expression.child(0).child(0) instanceof Slot) {
                 // count(slot) can be rewritten by circle deps
                 Slot slot = (Slot) expression.child(0).child(0);
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/PushDownAggThroughJoinOnPkFkTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/PushDownAggThroughJoinOnPkFkTest.java
index 1ef4653e36c..52dd0c55b61 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/PushDownAggThroughJoinOnPkFkTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/PushDownAggThroughJoinOnPkFkTest.java
@@ -156,6 +156,20 @@ class PushDownAggThroughJoinOnPkFkTest extends 
TestWithFeService implements Memo
                 .printlnTree();
     }
 
+    @Test
+    void testCountStar() {
+        // Regression: COUNT(*) has no children, and calling child(0) on it
+        // would throw ArrayIndexOutOfBoundsException if not guarded by 
arity() > 0
+        String sql = "select count(*), pri.name from pri inner join 
foreign_not_null\n"
+                + "on pri.id1 = foreign_not_null.id2\n"
+                + "group by pri.id1, pri.name, foreign_not_null.id2";
+        PlanChecker.from(connectContext)
+                .analyze(sql)
+                .rewrite()
+                .matches(logicalJoin(logicalAggregate(), any()))
+                .printlnTree();
+    }
+
     @Test
     void testMissSlot() {
         String sql = "select count(pri.name) from pri inner join 
foreign_not_null on pri.name = foreign_not_null.name";


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

Reply via email to