This is an automated email from the ASF dual-hosted git repository. kxiao pushed a commit to branch branch-2.0 in repository https://gitbox.apache.org/repos/asf/doris.git
commit d9357cc58f3271aae464505ab612d1ee6b761508 Author: daidai <[email protected]> AuthorDate: Wed Oct 11 10:17:30 2023 -0500 [fix](Nereids)Fix the bug that count(*) does not push down for tables with only one column. (#25222) after pr #22115 . Fixed the bug that when selecting count(*) from table, if the table has only one column, the aggregate count is not pushed down. --- .../org/apache/doris/nereids/rules/RuleType.java | 1 + .../rules/implementation/AggregateStrategies.java | 7 ++ .../hive/test_select_count_optimize.groovy | 102 +++++++++++++++++++++ 3 files changed, 110 insertions(+) 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 b1489e47165..654fd51f0b1 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 @@ -324,6 +324,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 166ddd3bd9a..511312ddd82 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 class AggregateStrategies implements ImplementationRuleFactory { 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 88a9cfeb12f..5aa335b0e8f 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") { 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" + } } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
