[improve](nereids) support agg function of count(const value) pushdown #26677

support sql: select count(1)-count(not null) from table, the agg of count could push down.
This commit is contained in:
zhangstar333
2023-11-23 11:26:06 +08:00
committed by GitHub
parent 301bfe4d5d
commit 33de92cc61
2 changed files with 41 additions and 1 deletions

View File

@ -57,7 +57,7 @@ public class CountLiteralToCountStar extends OneRewriteRuleFactory {
.filter(this::isCountLiteral)
.forEach(c -> replaced.put(c, new Count()));
expr = expr.rewriteUp(s -> replaced.getOrDefault(s, s));
changed = !replaced.isEmpty();
changed |= !replaced.isEmpty();
newExprs.add((NamedExpression) expr);
}
return changed;

View File

@ -25,4 +25,44 @@ suite("test_pushdown_explain") {
contains "PREDICATES:"
}
qt_select "select k1 from baseall where k1 = 1"
sql "DROP TABLE IF EXISTS test_lineorder"
sql """ CREATE TABLE `test_lineorder` (
`lo_orderkey` INT NOT NULL COMMENT '\"\"',
`lo_linenumber` INT NOT NULL COMMENT '\"\"',
`lo_shipmode` VARCHAR(11) NOT NULL COMMENT '\"\"'
) ENGINE=OLAP
DUPLICATE KEY(`lo_orderkey`)
DISTRIBUTED BY HASH(`lo_orderkey`) BUCKETS 48
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"min_load_replica_num" = "-1",
"is_being_synced" = "false",
"colocate_with" = "groupa1",
"storage_format" = "V2",
"light_schema_change" = "true",
"disable_auto_compaction" = "false",
"enable_single_replica_compaction" = "false"
); """
sql """ insert into test_lineorder values(1,2,"asd"); """
explain {
sql("select count(1) from test_lineorder;")
contains "pushAggOp=COUNT"
}
explain {
sql("select count(*) from test_lineorder;")
contains "pushAggOp=COUNT"
}
explain {
sql("select count(1) - count(lo_shipmode) from test_lineorder;")
contains "pushAggOp=COUNT"
}
explain {
sql("select count(lo_orderkey) from test_lineorder;")
contains "pushAggOp=COUNT"
}
explain {
sql("select count(cast(lo_orderkey as bigint)) from test_lineorder;")
contains "pushAggOp=COUNT"
}
}