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

amashenkov pushed a commit to branch ignite-21580
in repository https://gitbox.apache.org/repos/asf/ignite-3.git

commit dd4e70c8df3def4bba204083dced2a81f89fb687
Author: amashenkov <[email protected]>
AuthorDate: Sun Mar 31 13:24:10 2024 +0300

    Fix aggregate row count estimation.
---
 .../ignite/internal/sql/engine/rel/IgniteAggregate.java       | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git 
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/IgniteAggregate.java
 
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/IgniteAggregate.java
index 78a0a3d67b..240d142868 100644
--- 
a/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/IgniteAggregate.java
+++ 
b/modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rel/IgniteAggregate.java
@@ -66,7 +66,14 @@ public abstract class IgniteAggregate extends Aggregate 
implements IgniteRel {
 
         // Estimation of the groups count is not available.
         // Use heuristic estimation for result rows count.
-        return super.estimateRowCount(mq);
+        int groupCount = groupSet.cardinality();
+        if (groupCount == 0) {
+            return 1;
+        } else {
+            double rowCount = mq.getRowCount(input);
+            rowCount *= 1.0 - Math.pow(.75, groupCount);
+            return rowCount;
+        }
     }
 
     /**
@@ -85,7 +92,7 @@ public abstract class IgniteAggregate extends Aggregate 
implements IgniteRel {
                     Double distinctRowCount = 
mq.getDistinctRowCount(getInput(), aggGroup, null);
 
                     double distinctRows = distinctRowCount != null ? 
distinctRowCount
-                            : mq.getRowCount(getInput()) * (1 - Math.pow(0.5, 
aggGroup.cardinality()));
+                            : mq.getRowCount(getInput()) * (1 - Math.pow(0.75, 
aggGroup.cardinality()));
 
                     mem += IgniteCost.AGG_CALL_MEM_COST * distinctRows / grps;
                 } else {

Reply via email to