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

englefly pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


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

commit e2140ebebcfacfa656964d9105693ab6ddc0e8c3
Author: minghong <[email protected]>
AuthorDate: Mon Jun 29 17:06:46 2026 +0800

    [fix](agg push down) guard Count(*) child access with arity() check in 
PushDownAggThroughJoinOnPkFk (#64848)
    
    ### What problem does this PR solve?
    
    Related PR: #36035
    
    Problem Summary:
    
    COUNT(*) has no arguments; calling child(0) on it throws
    ArrayIndexOutOfBoundsException. Added arity() > 0 guard before accessing
    Count's child slot for FK rewrite.
    
    Regression test testCountStar() added to verify COUNT(*) with PK/FK join
    does not crash.
---
 .../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 f2dbf786561..69340329208 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