englefly commented on code in PR #65703: URL: https://github.com/apache/doris/pull/65703#discussion_r3594937347
########## regression-test/suites/query_p0/eager_agg/scalar_agg_pushdown.groovy: ########## @@ -0,0 +1,54 @@ +// 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("scalar_agg_pushdown") { + sql "set eager_aggregation_mode=1;" + sql "set eager_aggregation_on_join=true;" + sql "set disable_nereids_rules='SALT_JOIN';" + + // Test: scalar aggregation (no GROUP BY) must not be pushed below a join, + // because scalar agg on empty input returns 1 NULL row (SQL standard), + // which would be cross-joined with the other side to produce phantom rows. + // Regression test for: scalar agg pushdown producing phantom rows when + // constant propagation replaces GROUP BY key with a literal that doesn't + // exist in the table. + + sql """drop table if exists t1;""" + sql """create table t1 (a int, b int) distributed by hash(a) properties("replication_num" = "1");""" + sql """insert into t1 values (1,10),(2,20);""" + + sql """drop table if exists t2;""" + sql """create table t2 (c int) distributed by hash(c) properties("replication_num" = "1");""" + sql """insert into t2 values (1),(2);""" + + // WHERE t1.a = 999 matches no rows in t1. + // GROUP BY includes t1.a, t2.c (cross-table GROUP BY). + // Without the fix, eager aggregation pushes a scalar partial aggregate + // below the join, which on empty input returns 1 NULL row. + // That NULL row cross-joins with t2's 2 rows, producing 2 phantom rows. + // With the fix, pushdown is forbidden for scalar child aggregates. + qt_scalar_agg_no_pushdown """ + SELECT t1.a, SUM(t1.b), t2.c + FROM t1, t2 + WHERE t1.a = 999 + GROUP BY t1.a, t2.c + ORDER BY t2.c; + """ + + sql """drop table if exists t1;""" Review Comment: done -- 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]
