From 475b0bf79f933fdd60d2edb069e8a4d39c068c54 Mon Sep 17 00:00:00 2001 From: seawinde Date: Fri, 22 Dec 2023 14:22:19 +0800 Subject: [PATCH] fix get related table column from null generate side --- .../exploration/mv/MaterializedViewUtils.java | 9 ++++++ .../mv/MaterializedViewUtilsTest.java | 29 ++++++++++++++++++- .../mv/join/inner/inner_join.groovy | 2 +- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtils.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtils.java index e219bec04ba343..27e6dd29400587 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtils.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtils.java @@ -272,6 +272,7 @@ private static final class IncrementCheckerContext { private boolean pctPossible = true; private TableIf relatedTable; private Column relatedTableColumn; + private boolean joinNullGenerateSide; public IncrementCheckerContext(SlotReference mvPartitionColumn) { this.mvPartitionColumn = mvPartitionColumn; @@ -304,6 +305,14 @@ public Column getRelatedTableColumn() { public void setRelatedTableColumn(Column relatedTableColumn) { this.relatedTableColumn = relatedTableColumn; } + + public boolean isJoinNullGenerateSide() { + return joinNullGenerateSide; + } + + public void setJoinNullGenerateSide(boolean joinNullGenerateSide) { + this.joinNullGenerateSide = joinNullGenerateSide; + } } /** diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtilsTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtilsTest.java index 898b5843031865..c2af1dbdf4aa17 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtilsTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/exploration/mv/MaterializedViewUtilsTest.java @@ -186,7 +186,7 @@ public void getRelatedTableInfoUseRightTest() { + " (select * from " + " lineitem " + " where L_SHIPDATE in ('2017-01-30')) t1 " - + "left join " + + "right join " + " (select * from " + " orders " + " where O_ORDERDATE in ('2017-01-30')) t2 " @@ -207,6 +207,33 @@ public void getRelatedTableInfoUseRightTest() { }); } + @Test + public void getRelatedTableInfoUseNullGenerateSideTest() { + PlanChecker.from(connectContext) + .checkExplain("SELECT t1.L_SHIPDATE, t2.O_ORDERDATE, t1.L_QUANTITY, t2.O_ORDERSTATUS, " + + "count(distinct case when t1.L_SUPPKEY > 0 then t2.O_ORDERSTATUS else null end) as cnt_1 " + + "from " + + " (select * from " + + " lineitem " + + " where L_SHIPDATE in ('2017-01-30')) t1 " + + "left join " + + " (select * from " + + " orders " + + " where O_ORDERDATE in ('2017-01-30')) t2 " + + "on t1.L_ORDERKEY = t2.O_ORDERKEY " + + "group by " + + "t1.L_SHIPDATE, " + + "t2.O_ORDERDATE, " + + "t1.L_QUANTITY, " + + "t2.O_ORDERSTATUS;", + nereidsPlanner -> { + Plan rewrittenPlan = nereidsPlanner.getRewrittenPlan(); + Optional relatedTableInfo = + MaterializedViewUtils.getRelatedTableInfo("o_orderdate", rewrittenPlan); + Assertions.assertFalse(relatedTableInfo.isPresent()); + }); + } + @Test public void getRelatedTableInfoTestWithoutPartitionTest() { PlanChecker.from(connectContext) diff --git a/regression-test/suites/nereids_rules_p0/mv/join/inner/inner_join.groovy b/regression-test/suites/nereids_rules_p0/mv/join/inner/inner_join.groovy index d8025e0bc60b14..0dcf33a9d87eb2 100644 --- a/regression-test/suites/nereids_rules_p0/mv/join/inner/inner_join.groovy +++ b/regression-test/suites/nereids_rules_p0/mv/join/inner/inner_join.groovy @@ -393,7 +393,7 @@ suite("inner_join") { sql """ DROP MATERIALIZED VIEW IF EXISTS mv6_0""" - // filter inside + inner + right + // filter inside + left + right def mv7_0 = "select l_shipdate, o_orderdate, l_partkey, l_suppkey " + "from lineitem " + "inner join (select * from orders where o_orderdate = '2023-12-08') t2 " +