You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2023/06/28 11:12:42 UTC

[doris] branch master updated: [opt](nereids) use Expression's isConstant to check whether could be remove from group by key (#21195)

This is an automated email from the ASF dual-hosted git repository.

morrysnow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 016870b673 [opt](nereids) use Expression's isConstant to check whether could be remove from group by key (#21195)
016870b673 is described below

commit 016870b67350de26704707bc70978fd3a1d1917b
Author: starocean999 <40...@users.noreply.github.com>
AuthorDate: Wed Jun 28 19:12:36 2023 +0800

    [opt](nereids) use Expression's isConstant to check whether could be remove from group by key (#21195)
---
 .../apache/doris/nereids/rules/rewrite/EliminateGroupByConstant.java | 3 +--
 regression-test/suites/nereids_syntax_p0/agg_with_const.groovy       | 5 +++++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/EliminateGroupByConstant.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/EliminateGroupByConstant.java
index 4174e892cf..f5a01fe530 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/EliminateGroupByConstant.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/EliminateGroupByConstant.java
@@ -23,7 +23,6 @@ import org.apache.doris.nereids.rules.expression.ExpressionRewriteContext;
 import org.apache.doris.nereids.rules.expression.rules.FoldConstantRule;
 import org.apache.doris.nereids.trees.expressions.Expression;
 import org.apache.doris.nereids.trees.expressions.NamedExpression;
-import org.apache.doris.nereids.trees.expressions.literal.Literal;
 import org.apache.doris.nereids.trees.plans.Plan;
 import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
 
@@ -61,7 +60,7 @@ public class EliminateGroupByConstant extends OneRewriteRuleFactory {
                 //   if we do constant folding before normalize aggregate, the subtree will change and matching fail
                 //   such as: select a + 1 + 2 + 3, sum(b) from t group by a + 1 + 2
                 Expression foldExpression = FoldConstantRule.INSTANCE.rewrite(expression, context);
-                if (!(foldExpression instanceof Literal)) {
+                if (!foldExpression.isConstant()) {
                     slotGroupByExprs.add(expression);
                 } else {
                     lit = expression;
diff --git a/regression-test/suites/nereids_syntax_p0/agg_with_const.groovy b/regression-test/suites/nereids_syntax_p0/agg_with_const.groovy
index 61a8866f1f..375517ab6a 100644
--- a/regression-test/suites/nereids_syntax_p0/agg_with_const.groovy
+++ b/regression-test/suites/nereids_syntax_p0/agg_with_const.groovy
@@ -49,4 +49,9 @@ suite("agg_with_const") {
          select count(2) + 1, sum(2) + sum(2) from agg_with_const_tbl
     """
 
+    explain {
+        sql """select count(*) from ( select distinct col1 as a0, null as a1, null as a2 from agg_with_const_tbl)t"""
+        contains "projections: NULL"
+    }
+
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org