[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.
This commit is contained in:
@ -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),
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user