github-actions[bot] commented on code in PR #62548:
URL: https://github.com/apache/doris/pull/62548#discussion_r3090773695
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Count.java:
##########
@@ -77,7 +77,7 @@ private Count(boolean isStar, AggregateFunctionParams
functionParams) {
public boolean isCountStar() {
return isStar
|| children.isEmpty()
- || (children.size() == 1 && child(0) instanceof Literal);
+ || (children.size() == 1 && child(0) instanceof Literal &&
!child(0).isNullLiteral());
Review Comment:
`isCountStar()` also gates the `COUNT_ON_INDEX` implementation rules in
`AggregateStrategies`. The new regression suite only covers logical rewrites,
so we still do not have a test proving that `count(null)` no longer gets pushed
to `COUNT_ON_MATCH` / `COUNT_ON_INDEX` (for example with
`enable_count_on_index_pushdown` and a `MATCH` predicate). Since this helper is
now the gate for that FE->BE fast path too, please add at least one plan or
regression case for it.
##########
regression-test/suites/nereids_rules_p0/count_null_not_count_star/count_null_not_count_star.groovy:
##########
@@ -0,0 +1,80 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("count_null_not_count_star") {
+ sql "SET enable_nereids_planner=true"
+ sql "SET enable_fallback_to_original_planner=false"
+
+ sql "DROP TABLE IF EXISTS count_null_test"
+
+ sql """
+ create table count_null_test(pk int, a int, b int) distributed by
hash(pk) buckets 10
+ properties('replication_num' = '1');
+ """
+
+ sql """
+ insert into count_null_test values(1, 1, 1), (2, null, 2), (3, 3,
null), (4, null, null);
+ """
+ sql "sync"
+
+ // count(null) should always return 0 regardless of row count
+ order_qt_count_null """select count(null) from count_null_test"""
+
+ // count(*) should return total number of rows
+ order_qt_count_star """select count(*) from count_null_test"""
+
+ // count(1) should be equivalent to count(*)
+ order_qt_count_literal """select count(1) from count_null_test"""
+
+ // count(null) with group by should return 0 for each group
+ order_qt_count_null_group_by """select pk, count(null) from
count_null_test group by pk order by pk"""
+
+ // mixed: count(null) vs count(*) vs count(column)
+ order_qt_count_mixed """select count(null), count(*), count(a), count(b)
from count_null_test"""
+
+ // count(null) in subquery with union all
+ order_qt_count_null_union """
+ select count(null) from (
+ select a from count_null_test
+ union all
+ select a from count_null_test
+ ) t
+ """
+
+ // count(null) as window function
+ order_qt_count_null_window """
+ select pk, count(null) over (order by pk) from count_null_test order
by pk
+ """
+
+ // count(null) through join must still return 0, not get rewritten by
PushDownAggThroughJoin
Review Comment:
This join case does not reach `PushDownAggThroughJoin`'s `count(*)` rewrite
branch. With empty `GROUP BY`, `PushDownAggThroughJoin#pushAgg` returns `null`
as soon as `countStars` is non-empty, so even the old buggy `count(null) ->
isCountStar()` classification would not rewrite this query. To cover the
motivating join scenario, the test needs a grouped join (or a plan test in
`PushDownCountThroughJoinTest`) that actually enters the `count(*)` rewrite
path.
##########
regression-test/suites/nereids_rules_p0/count_null_not_count_star/count_null_not_count_star.groovy:
##########
@@ -0,0 +1,80 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("count_null_not_count_star") {
+ sql "SET enable_nereids_planner=true"
+ sql "SET enable_fallback_to_original_planner=false"
+
+ sql "DROP TABLE IF EXISTS count_null_test"
+
+ sql """
+ create table count_null_test(pk int, a int, b int) distributed by
hash(pk) buckets 10
+ properties('replication_num' = '1');
+ """
+
+ sql """
+ insert into count_null_test values(1, 1, 1), (2, null, 2), (3, 3,
null), (4, null, null);
+ """
+ sql "sync"
+
+ // count(null) should always return 0 regardless of row count
+ order_qt_count_null """select count(null) from count_null_test"""
+
+ // count(*) should return total number of rows
+ order_qt_count_star """select count(*) from count_null_test"""
+
+ // count(1) should be equivalent to count(*)
+ order_qt_count_literal """select count(1) from count_null_test"""
+
+ // count(null) with group by should return 0 for each group
+ order_qt_count_null_group_by """select pk, count(null) from
count_null_test group by pk order by pk"""
+
+ // mixed: count(null) vs count(*) vs count(column)
+ order_qt_count_mixed """select count(null), count(*), count(a), count(b)
from count_null_test"""
+
+ // count(null) in subquery with union all
+ order_qt_count_null_union """
+ select count(null) from (
+ select a from count_null_test
+ union all
+ select a from count_null_test
+ ) t
+ """
+
+ // count(null) as window function
Review Comment:
This window query does not actually exercise `SimplifyWindowExpression`.
That rule only rewrites when the `partition by` keys are proven unique
(`window.getLogicalProperties().getTrait().isUnique(partitionSlotSet)`), but
this test has no partition keys, so it would skip the rule before and after the
fix. Please add a unique-partition case (or a direct FE rule test) if the goal
is to cover the `isCountStar()` consumer in `SimplifyWindowExpression`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]