Skip to content

Commit

Permalink
[fix](Nereids)Fix the bug that count(*) does not push down for tables…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
hubgeter authored and xiaokang committed Oct 11, 2023
1 parent d9fccf5 commit d9357cc
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ public List<Rule> 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}

0 comments on commit d9357cc

Please sign in to comment.