diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/ProjectAggregateExpressionsForCse.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/ProjectAggregateExpressionsForCse.java index ac67b47eceb2c1f..00220a00ffd784c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/ProjectAggregateExpressionsForCse.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/ProjectAggregateExpressionsForCse.java @@ -23,6 +23,7 @@ import org.apache.doris.nereids.trees.expressions.Alias; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.NamedExpression; +import org.apache.doris.nereids.trees.expressions.OrderExpression; import org.apache.doris.nereids.trees.expressions.Slot; import org.apache.doris.nereids.trees.expressions.SlotReference; import org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunction; @@ -130,7 +131,7 @@ public Plan visitPhysicalHashAggregate(PhysicalHashAggregate agg private void getCseCandidatesFromAggregateFunction(Expression expr, Map result) { if (expr instanceof AggregateFunction) { for (Expression child : expr.children()) { - if (!(child instanceof SlotReference) && !child.isConstant()) { + if (!(child instanceof SlotReference) && !child.isConstant() && !(child instanceof OrderExpression)) { if (child instanceof Alias) { result.put(child, (Alias) child); } else { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/NullableAggregateFunction.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/NullableAggregateFunction.java index fc62710ebb7a61a..bbb36f338317b65 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/NullableAggregateFunction.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/NullableAggregateFunction.java @@ -27,7 +27,7 @@ /** * nullable aggregate function */ -public abstract class NullableAggregateFunction extends AggregateFunction implements + public abstract class NullableAggregateFunction extends AggregateFunction implements PropagateNullable, AlwaysNullable { protected final boolean alwaysNullable; diff --git a/regression-test/data/nereids_tpch_p0/tpch/agg_cse.out b/regression-test/data/nereids_tpch_p0/tpch/agg_cse.out index 16995bb9240c9a6..0dfa6b2c075ab11 100644 --- a/regression-test/data/nereids_tpch_p0/tpch/agg_cse.out +++ b/regression-test/data/nereids_tpch_p0/tpch/agg_cse.out @@ -1,10 +1,10 @@ -- This file is automatically generated. You should know what you did if you want to edit this --- !select -- -2 2.0 3 -8 8.0 9 +-- !1 -- 0 0.0 1 +2 2.0 3 4 4.0 5 6 6.0 7 +8 8.0 9 -- !agg_cse_subquery -- 0 0.0 1 diff --git a/regression-test/suites/nereids_tpch_p0/tpch/agg_cse.groovy b/regression-test/suites/nereids_tpch_p0/tpch/agg_cse.groovy index 52e337b216e1d91..f370520308a1169 100644 --- a/regression-test/suites/nereids_tpch_p0/tpch/agg_cse.groovy +++ b/regression-test/suites/nereids_tpch_p0/tpch/agg_cse.groovy @@ -23,9 +23,9 @@ suite("agg_cse") { sql 'set enable_nereids_planner=true' sql 'set enable_fallback_to_original_planner=false' - qt_select """ + qt_1 """ select sum(r_regionkey + r_regionkey), avg(r_regionkey + r_regionkey), sum(r_regionkey + (r_regionkey+1)) - from region group by r_name; + from region group by r_name order by 1, 2, 3; """ explain{ sql """