You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by kx...@apache.org on 2023/07/09 02:57:16 UTC
[doris] 10/29: [fix](Nereids) union distinct should not prune any column (#21610)
This is an automated email from the ASF dual-hosted git repository.
kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git
commit cc54beef4e666b88d0bdfd7c55f6e26e8f3b4340
Author: morrySnow <10...@users.noreply.github.com>
AuthorDate: Fri Jul 7 14:38:28 2023 +0800
[fix](Nereids) union distinct should not prune any column (#21610)
---
.../java/org/apache/doris/nereids/rules/rewrite/ColumnPruning.java | 5 +++++
regression-test/data/nereids_syntax_p0/set_operation.out | 3 +++
regression-test/suites/nereids_syntax_p0/set_operation.groovy | 5 +++++
3 files changed, 13 insertions(+)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/ColumnPruning.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/ColumnPruning.java
index ff50074df3..7f3205d8f2 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/ColumnPruning.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/ColumnPruning.java
@@ -24,6 +24,7 @@ import org.apache.doris.nereids.trees.expressions.NamedExpression;
import org.apache.doris.nereids.trees.expressions.Slot;
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.trees.plans.algebra.Aggregate;
+import org.apache.doris.nereids.trees.plans.algebra.SetOperation.Qualifier;
import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
import org.apache.doris.nereids.trees.plans.logical.LogicalCTEProducer;
import org.apache.doris.nereids.trees.plans.logical.LogicalExcept;
@@ -111,6 +112,10 @@ public class ColumnPruning extends DefaultPlanRewriter<PruneContext> implements
// union can not prune children by the common logic, we must override visit method to write special code.
@Override
public Plan visitLogicalUnion(LogicalUnion union, PruneContext context) {
+ if (union.getQualifier() == Qualifier.DISTINCT) {
+ return skipPruneThisAndFirstLevelChildren(union);
+ }
+
LogicalUnion prunedOutputUnion = pruneOutput(union, union.getOutputs(), union::pruneOutputs, context);
// start prune children of union
diff --git a/regression-test/data/nereids_syntax_p0/set_operation.out b/regression-test/data/nereids_syntax_p0/set_operation.out
index 8f8db3a540..1fa3a8ebee 100644
--- a/regression-test/data/nereids_syntax_p0/set_operation.out
+++ b/regression-test/data/nereids_syntax_p0/set_operation.out
@@ -589,3 +589,6 @@ hell0
2020-05-25
2020-05-25 00
+-- !union45 --
+2
+
diff --git a/regression-test/suites/nereids_syntax_p0/set_operation.groovy b/regression-test/suites/nereids_syntax_p0/set_operation.groovy
index 94baeb47f3..58cc456bc1 100644
--- a/regression-test/suites/nereids_syntax_p0/set_operation.groovy
+++ b/regression-test/suites/nereids_syntax_p0/set_operation.groovy
@@ -285,4 +285,9 @@ suite("test_nereids_set_operation") {
) a
order by 1
"""
+
+ // test union distinct column prune
+ qt_union45 """
+ select count(*) from (select 1, 2 union select 1,1 ) a;
+ """
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org