diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/RuleType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/RuleType.java index 51a20847ce5277..8319645319084c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/RuleType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/RuleType.java @@ -342,6 +342,7 @@ public enum RuleType { LOGICAL_ASSERT_NUM_ROWS_TO_PHYSICAL_ASSERT_NUM_ROWS(RuleTypeClass.IMPLEMENTATION), STORAGE_LAYER_AGGREGATE_WITHOUT_PROJECT(RuleTypeClass.IMPLEMENTATION), STORAGE_LAYER_AGGREGATE_WITH_PROJECT(RuleTypeClass.IMPLEMENTATION), + STORAGE_LAYER_AGGREGATE_WITHOUT_PROJECT_FOR_FILE_SCAN(RuleTypeClass.IMPLEMENTATION), STORAGE_LAYER_AGGREGATE_WITH_PROJECT_FOR_FILE_SCAN(RuleTypeClass.IMPLEMENTATION), COUNT_ON_INDEX(RuleTypeClass.IMPLEMENTATION), COUNT_ON_INDEX_WITHOUT_PROJECT(RuleTypeClass.IMPLEMENTATION), 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 166ddd3bd9ad6a..511312ddd8264b 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 @@ -161,6 +161,13 @@ public List buildRules() { return storageLayerAggregate(agg, project, olapScan, ctx.cascadesContext); }) ), + RuleType.STORAGE_LAYER_AGGREGATE_WITHOUT_PROJECT_FOR_FILE_SCAN.build( + logicalAggregate( + logicalFileScan() + ) + .when(agg -> agg.isNormalized() && enablePushDownNoGroupAgg()) + .thenApply(ctx -> storageLayerAggregate(ctx.root, null, ctx.root.child(), ctx.cascadesContext)) + ), RuleType.STORAGE_LAYER_AGGREGATE_WITH_PROJECT_FOR_FILE_SCAN.build( logicalAggregate( logicalProject( diff --git a/regression-test/suites/external_table_p2/hive/test_select_count_optimize.groovy b/regression-test/suites/external_table_p2/hive/test_select_count_optimize.groovy index fadf452bdb53c3..840ab77da2c1c4 100644 --- a/regression-test/suites/external_table_p2/hive/test_select_count_optimize.groovy +++ b/regression-test/suites/external_table_p2/hive/test_select_count_optimize.groovy @@ -88,6 +88,108 @@ suite("test_select_count_optimize", "p2,external,hive,external_remote,external_r qt_sql """ select count(*) as a from tpch_1000.nation group by n_regionkey order by a;""" + explain { + + sql "select count(*) from tpch_1000_parquet.nation;" + + contains "pushdown agg=COUNT" + } + + explain { + + sql "select count(1) from tpch_1000_parquet.nation;" + + contains "pushdown agg=COUNT" + } + + + explain { + + sql "select count(2) from tpch_1000_parquet.nation;" + + contains "pushdown agg=COUNT" + } + + + explain { + + sql "select count(n_name) from tpch_1000_parquet.nation;" + + notContains "pushdown agg=COUNT" + } + + explain { + + sql "select count(n_name) from tpch_1000_parquet.nation where n_nationkey = 1;" + + notContains "pushdown agg=COUNT" + } + + explain { + + sql "select count(*) from tpch_1000_parquet.nation group by n_regionkey ;" + + notContains "pushdown agg=COUNT" + } + + + explain { + + sql " select count(*) from multi_catalog.test_csv_format_error; " + + contains "pushdown agg=COUNT" + } + + explain { + sql "select count(*) from multi_catalog.hits_orc ; " + + contains "pushdown agg=COUNT" + + } + + + explain { + sql "select count(*) from multi_catalog.hits_orc ; " + + contains "pushdown agg=COUNT" + + } + + + explain { + + sql "select count(*) from multi_catalog.parquet_one_column;" + + contains "pushdown agg=COUNT" + } + + explain { + + sql "select count(col1) from multi_catalog.parquet_one_column;" + + notContains "pushdown agg=COUNT" + } + + explain { + + sql "select count(*) from multi_catalog.parquet_two_column;" + + contains "pushdown agg=COUNT" + } + explain { + + sql "select count(*) from multi_catalog.parquet_two_column where col1 = 1;" + + notContains "pushdown agg=COUNT" + } + + + explain { + + sql "select count(*) from multi_catalog.logs2_orc;" + + contains "pushdown agg=COUNT" + } } }