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

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


The following commit(s) were added to refs/heads/branch-3.0 by this push:
     new e915a6c910c [fix] (inverted index) fix the error result in the query 
when using count on index (#42346) (#42361)
e915a6c910c is described below

commit e915a6c910cf9bab213f19730280d5c8aeae35e9
Author: Sun Chenyang <csun5...@gmail.com>
AuthorDate: Thu Oct 24 17:44:05 2024 +0800

    [fix] (inverted index) fix the error result in the query when using count 
on index (#42346) (#42361)
    
    ## Proposed changes
    
    pick from master #42346
---
 .../rules/implementation/AggregateStrategies.java  |  8 ++---
 .../inverted_index_p0/test_count_on_index.groovy   | 38 ++++++++++++++++++++++
 2 files changed, 42 insertions(+), 4 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/AggregateStrategies.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/AggregateStrategies.java
index aeff011fe07..6cf243bbfee 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/AggregateStrategies.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/AggregateStrategies.java
@@ -130,8 +130,8 @@ public class AggregateStrategies implements 
ImplementationRuleFactory {
                     Set<Slot> aggSlots = funcs.stream()
                             .flatMap(f -> f.getInputSlots().stream())
                             .collect(Collectors.toSet());
-                    return conjuncts.stream().allMatch(expr -> 
checkSlotInOrExpression(expr, aggSlots)
-                                                                && 
checkIsNullExpr(expr, aggSlots));
+                    return aggSlots.isEmpty() || 
conjuncts.stream().allMatch(expr ->
+                                checkSlotInOrExpression(expr, aggSlots) && 
checkIsNullExpr(expr, aggSlots));
                 })
                 .thenApply(ctx -> {
                     LogicalAggregate<LogicalFilter<LogicalOlapScan>> agg = 
ctx.root;
@@ -164,8 +164,8 @@ public class AggregateStrategies implements 
ImplementationRuleFactory {
                     Set<Slot> aggSlots = funcs.stream()
                             .flatMap(f -> f.getInputSlots().stream())
                             .collect(Collectors.toSet());
-                    return conjuncts.stream().allMatch(expr -> 
checkSlotInOrExpression(expr, aggSlots)
-                                                                && 
checkIsNullExpr(expr, aggSlots));
+                    return aggSlots.isEmpty() || 
conjuncts.stream().allMatch(expr ->
+                                checkSlotInOrExpression(expr, aggSlots) && 
checkIsNullExpr(expr, aggSlots));
                 })
                 .thenApply(ctx -> {
                     
LogicalAggregate<LogicalProject<LogicalFilter<LogicalOlapScan>>> agg = ctx.root;
diff --git 
a/regression-test/suites/inverted_index_p0/test_count_on_index.groovy 
b/regression-test/suites/inverted_index_p0/test_count_on_index.groovy
index ec2c556d835..0143f37997a 100644
--- a/regression-test/suites/inverted_index_p0/test_count_on_index.groovy
+++ b/regression-test/suites/inverted_index_p0/test_count_on_index.groovy
@@ -337,6 +337,44 @@ suite("test_count_on_index_httplogs", "p0") {
                 contains "pushAggOp=NONE"
         }
         qt_sql_bad2 "${bad_sql2}"
+
+        // case 6: test select count() from table where a or b;
+        def tableName6 = 'test_count_where_or'
+        sql "DROP TABLE IF EXISTS ${tableName6}"
+        sql """
+        CREATE TABLE IF NOT EXISTS ${tableName6} (
+            `key_id` varchar(20) NULL COMMENT '',
+            `value1` int NULL,
+            `value2` bigint NULL,
+            INDEX idx_key (`key_id`) USING INVERTED PROPERTIES("parser" = 
"english"),
+            INDEX idx_v1 (`value1`) USING INVERTED,
+            INDEX idx_v2 (`value2`) USING INVERTED
+        ) ENGINE=OLAP
+        DUPLICATE KEY(`key_id`)
+        COMMENT 'OLAP'
+        DISTRIBUTED BY HASH(`key_id`) BUCKETS 3
+        PROPERTIES("replication_num" = "1");
+        """
+
+        sql "INSERT INTO ${tableName6} values ('dt_bjn001', 100, 200);"
+        sql "INSERT INTO ${tableName6} values ('dt_bjn002', 300, 400);"
+        sql "INSERT INTO ${tableName6} values ('dt_bjn003', 500, 600);"
+
+        sql "sync"
+        sql "analyze table  ${tableName6} with sync;"
+        explain {
+            sql("select COUNT() from ${tableName6} where value1 > 20 or value2 
< 10")
+            contains "pushAggOp=COUNT_ON_INDEX"
+        }
+        explain {
+            sql("select COUNT(value1) from ${tableName6} where value1 > 20 and 
value2 > 5")
+            contains "pushAggOp=COUNT_ON_INDEX"
+        }
+        explain {
+            sql("select COUNT(value1) from ${tableName6} where value1 > 20 or 
value2 < 10")
+            contains "pushAggOp=NONE"
+        }
+
     } finally {
         //try_sql("DROP TABLE IF EXISTS ${testTable}")
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to