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

yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 60253c827c0b4f484a1944fb25a9550fef8b32a1
Author: minghong <engle...@gmail.com>
AuthorDate: Sat Apr 20 20:05:00 2024 +0800

    [fix](nereids) do not push RF into nested cte (#33769)
---
 .../processor/post/RuntimeFilterGenerator.java     | 13 ++--
 .../data/nereids_syntax_p0/runtime_filter.out      | 39 ++++++++++++
 .../org/apache/doris/regression/suite/Suite.groovy | 11 ++++
 .../suites/nereids_syntax_p0/runtime_filter.groovy | 69 ++++++++++++++++++++++
 .../suites/tpch_sf0.1_p1/sql/cse.groovy            |  3 +
 5 files changed, 129 insertions(+), 6 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/RuntimeFilterGenerator.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/RuntimeFilterGenerator.java
index d7e3f95be6a..fbb62ece9f2 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/RuntimeFilterGenerator.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/RuntimeFilterGenerator.java
@@ -547,12 +547,11 @@ public class RuntimeFilterGenerator extends 
PlanPostProcessor {
         PhysicalRelation cteNode = 
ctx.getAliasTransferPair(unwrappedSlot).first;
         long buildSideNdv = rf.getBuildSideNdv();
         if (cteNode instanceof PhysicalCTEConsumer && inputPlanNode instanceof 
PhysicalProject) {
-            PhysicalProject project = (PhysicalProject) inputPlanNode;
+            PhysicalProject<Plan> project = (PhysicalProject<Plan>) 
inputPlanNode;
             NamedExpression targetExpr = null;
-            for (Object column : project.getProjects()) {
-                NamedExpression alias = (NamedExpression) column;
-                if (cteSlot.getName().equals(alias.getName())) {
-                    targetExpr = alias;
+            for (NamedExpression ne : project.getProjects()) {
+                if (cteSlot.getName().equals(ne.getName())) {
+                    targetExpr = ne;
                     break;
                 }
             }
@@ -576,7 +575,9 @@ public class RuntimeFilterGenerator extends 
PlanPostProcessor {
                         ctx.addJoinToTargetMap(rf.getBuilderNode(), 
targetSlot.getExprId());
                         ctx.setTargetsOnScanNode(scan, targetSlot);
                     }
-
+                    if (targetList.isEmpty()) {
+                        return false;
+                    }
                     RuntimeFilter filter = new 
RuntimeFilter(generator.getNextId(),
                             rf.getSrcExpr(), targetList, targetExpressions, 
rf.getType(), rf.getExprOrder(),
                             rf.getBuilderNode(), buildSideNdv, 
rf.isBloomFilterSizeCalculatedByNdv(),
diff --git a/regression-test/data/nereids_syntax_p0/runtime_filter.out 
b/regression-test/data/nereids_syntax_p0/runtime_filter.out
new file mode 100644
index 00000000000..dfd7fd6f29a
--- /dev/null
+++ b/regression-test/data/nereids_syntax_p0/runtime_filter.out
@@ -0,0 +1,39 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !rqg --
+\N             1       \N      will    6       \N      here    4       0       
want    4
+\N             1       \N      will    6       \N      i       5       \N      
g       5
+\N             1       \N      will    6       \N      now     6       \N      
\N      6
+\N             1       \N      will    6       \N      t       8       \N      
\N      8
+\N             1       \N      will    6       0       \N      0       \N      
my      0
+\N             1       \N      will    6       2               3       0       
that    3
+\N             1       \N      will    6       5       c       7       \N      
        7
+\N             1       \N      will    6       6       \N      1       \N      
a       1
+\N             1       \N      will    6       9       \N      2       5       
        2
+\N             1       \N      x       4       \N      here    4       0       
want    4
+\N             1       \N      x       4       \N      i       5       \N      
g       5
+\N             1       \N      x       4       \N      now     6       \N      
\N      6
+\N             1       \N      x       4       \N      t       8       \N      
\N      8
+\N             1       \N      x       4       0       \N      0       \N      
my      0
+\N             1       \N      x       4       2               3       0       
that    3
+\N             1       \N      x       4       5       c       7       \N      
        7
+\N             1       \N      x       4       6       \N      1       \N      
a       1
+\N             1       \N      x       4       9       \N      2       5       
        2
+\N     think   0       \N              5       \N      here    4       0       
want    4
+\N     think   0       \N              5       \N      i       5       \N      
g       5
+\N     think   0       \N              5       \N      now     6       \N      
\N      6
+\N     think   0       \N              5       \N      t       8       \N      
\N      8
+\N     think   0       \N              5       0       \N      0       \N      
my      0
+\N     think   0       \N              5       2               3       0       
that    3
+\N     think   0       \N              5       5       c       7       \N      
        7
+\N     think   0       \N              5       6       \N      1       \N      
a       1
+\N     think   0       \N              5       9       \N      2       5       
        2
+\N     think   0       7       k       3       \N      here    4       0       
want    4
+\N     think   0       7       k       3       \N      i       5       \N      
g       5
+\N     think   0       7       k       3       \N      now     6       \N      
\N      6
+\N     think   0       7       k       3       \N      t       8       \N      
\N      8
+\N     think   0       7       k       3       0       \N      0       \N      
my      0
+\N     think   0       7       k       3       2               3       0       
that    3
+\N     think   0       7       k       3       5       c       7       \N      
        7
+\N     think   0       7       k       3       6       \N      1       \N      
a       1
+\N     think   0       7       k       3       9       \N      2       5       
        2
+
diff --git 
a/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy
 
b/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy
index e08658c91cd..d17f9182817 100644
--- 
a/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy
+++ 
b/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy
@@ -338,6 +338,17 @@ class Suite implements GroovyInterceptable {
         }
     }
 
+    List<List<Object>> multi_sql(String sqlStr, boolean isOrder = false) {
+        String[] sqls = sqlStr.split(";")
+        def result = new ArrayList<Object>();
+        for (String query : sqls) {
+            if (!query.trim().isEmpty()) {
+                result.add(sql(query, isOrder));
+            }
+        }
+        return result
+    }
+
     List<List<Object>> arrow_flight_sql_no_prepared (String sqlStr, boolean 
isOrder = false){
         logger.info("Execute ${isOrder ? "order_" : ""}sql: 
${sqlStr}".toString())
         def (result, meta) = 
JdbcUtils.executeQueryToList(context.getArrowFlightSqlConnection(), (String) 
("USE ${context.dbName};" + sqlStr))
diff --git a/regression-test/suites/nereids_syntax_p0/runtime_filter.groovy 
b/regression-test/suites/nereids_syntax_p0/runtime_filter.groovy
index a677771cf43..3592aa5055b 100644
--- a/regression-test/suites/nereids_syntax_p0/runtime_filter.groovy
+++ b/regression-test/suites/nereids_syntax_p0/runtime_filter.groovy
@@ -46,4 +46,73 @@ suite("runtime_filter") {
             result([[1L]])
         }
     }
+
+    multi_sql """
+
+    drop table if exists 
table_2_undef_partitions2_keys3_properties4_distributed_by5;
+    create table table_2_undef_partitions2_keys3_properties4_distributed_by5 (
+    col_int_undef_signed int/*agg_type_placeholder*/   ,
+    col_varchar_10__undef_signed varchar(10)/*agg_type_placeholder*/   ,
+    pk int/*agg_type_placeholder*/
+    ) engine=olap
+    distributed by hash(pk) buckets 10
+    properties("replication_num" = "1");
+    insert into 
table_2_undef_partitions2_keys3_properties4_distributed_by5(pk,col_int_undef_signed,col_varchar_10__undef_signed)
 values (0,1,null),(1,7,null);
+
+    drop table if exists 
table_6_undef_partitions2_keys3_properties4_distributed_by5;
+    create table table_6_undef_partitions2_keys3_properties4_distributed_by5 (
+    col_int_undef_signed int/*agg_type_placeholder*/   ,
+    col_varchar_10__undef_signed varchar(10)/*agg_type_placeholder*/   ,
+    pk int/*agg_type_placeholder*/
+    ) engine=olap
+    distributed by hash(pk) buckets 10
+    properties("replication_num" = "1");
+    insert into 
table_6_undef_partitions2_keys3_properties4_distributed_by5(pk,col_int_undef_signed,col_varchar_10__undef_signed)
 values 
(0,null,'think'),(1,null,''),(2,2,''),(3,null,'r'),(4,null,null),(5,8,'here');
+
+
+
+    drop table if exists 
table_9_undef_partitions2_keys3_properties4_distributed_by5;
+    create table table_9_undef_partitions2_keys3_properties4_distributed_by5 (
+    col_int_undef_signed int/*agg_type_placeholder*/   ,
+    col_varchar_10__undef_signed varchar(10)/*agg_type_placeholder*/   ,
+    pk int/*agg_type_placeholder*/
+    ) engine=olap
+    distributed by hash(pk) buckets 10
+    properties("replication_num" = "1");
+    insert into 
table_9_undef_partitions2_keys3_properties4_distributed_by5(pk,col_int_undef_signed,col_varchar_10__undef_signed)
 values 
(0,0,null),(1,6,null),(2,9,null),(3,2,''),(4,null,'here'),(5,null,'i'),(6,null,'now'),(7,5,'c'),(8,null,'t');
+
+
+    drop table if exists 
table_20_undef_partitions2_keys3_properties4_distributed_by5;
+    create table table_20_undef_partitions2_keys3_properties4_distributed_by5 (
+    col_int_undef_signed int/*agg_type_placeholder*/   ,
+    col_varchar_10__undef_signed varchar(10)/*agg_type_placeholder*/   ,
+    pk int/*agg_type_placeholder*/
+    ) engine=olap
+    distributed by hash(pk) buckets 10
+    properties("replication_num" = "1");
+    insert into 
table_20_undef_partitions2_keys3_properties4_distributed_by5(pk,col_int_undef_signed,col_varchar_10__undef_signed)
 values 
(0,null,'my'),(1,null,'a'),(2,5,''),(3,0,'that'),(4,0,'want'),(5,null,'g'),(6,null,null),(7,null,''),(8,null,null),(9,3,'b'),(10,null,'her'),(11,6,''),(12,null,'k'),(13,null,'then'),(14,2,null),(15,null,''),(16,null,'g'),(17,null,'x'),(18,null,'d'),(19,null,null);
+
+    create table table_8_undef_partitions2_keys3_properties4_distributed_by5 (
+    col_int_undef_signed int/*agg_type_placeholder*/   ,
+    col_varchar_10__undef_signed varchar(10)/*agg_type_placeholder*/   ,
+    pk int/*agg_type_placeholder*/
+    ) engine=olap
+    distributed by hash(pk) buckets 10
+    properties("replication_num" = "1");
+    insert into 
table_8_undef_partitions2_keys3_properties4_distributed_by5(pk,col_int_undef_signed,col_varchar_10__undef_signed)
 values 
(0,3,'s'),(1,8,''),(2,null,null),(3,7,'k'),(4,null,'x'),(5,null,''),(6,null,'will'),(7,null,'so');
+
+    """
+    //do not push rf inside recursive ctes
+    // rule OR_EXPANSION genereates recursive ctes
+    order_qt_rqg """
+    SELECT
+        *
+    FROM
+        table_2_undef_partitions2_keys3_properties4_distributed_by5 AS t1 
RIGHT SEMI
+        JOIN table_6_undef_partitions2_keys3_properties4_distributed_by5 AS t2 
ON t1.`pk` + 1 = t2.`pk` + 1
+        LEFT OUTER JOIN 
table_8_undef_partitions2_keys3_properties4_distributed_by5 AS alias1 ON 
t2.`pk` + 5 = alias1.`pk`
+        OR t2.`pk` + 4 = alias1.`pk` + 1
+        INNER JOIN table_9_undef_partitions2_keys3_properties4_distributed_by5 
AS alias2
+        INNER JOIN 
table_20_undef_partitions2_keys3_properties4_distributed_by5 AS alias3 ON 
alias2.`pk` = alias3.`pk`;    
+     """
 }
\ No newline at end of file
diff --git a/regression-test/suites/tpch_sf0.1_p1/sql/cse.groovy 
b/regression-test/suites/tpch_sf0.1_p1/sql/cse.groovy
index c4c1ecb2e63..9ce13d1c47b 100644
--- a/regression-test/suites/tpch_sf0.1_p1/sql/cse.groovy
+++ b/regression-test/suites/tpch_sf0.1_p1/sql/cse.groovy
@@ -21,6 +21,9 @@
 
 suite('cse') {
     sql "set enable_common_sub_expression=true"
+    sql "set enable_nereids_planner=true;"
+    sql "set enable_fallback_to_original_planner=false;"
+
     def q1 = """select s_suppkey,n_regionkey,(s_suppkey + n_regionkey) + 1 as 
x, (s_suppkey + n_regionkey) + 2 as y 
             from supplier join nation on s_nationkey=n_nationkey order by 
s_suppkey , n_regionkey limit 10 ;
             """


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

Reply via email to