This is an automated email from the ASF dual-hosted git repository.
morrysnow pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.0 by this push:
new 78437297407 [fix](Nereids) filter-limit-project translate to wrong
plan (#32496) (#32857)
78437297407 is described below
commit 784372974071c1e867706b5827a981deef0f38cd
Author: morrySnow <[email protected]>
AuthorDate: Tue Mar 26 20:25:33 2024 +0800
[fix](Nereids) filter-limit-project translate to wrong plan (#32496)
(#32857)
pick from master
PR #32496
commit id e4e8fe80a24ee4b0a314d36c4e432af0a7697b82
---
.../glue/translator/PhysicalPlanTranslator.java | 8 ++-
.../data/nereids_p0/limit/filterLimitProject.out | 8 +++
.../nereids_p0/limit/filterLimitProject.groovy | 58 ++++++++++++++++++++++
3 files changed, 73 insertions(+), 1 deletion(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java
index 2e47c9fc62b..1842e193152 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java
@@ -1042,7 +1042,13 @@ public class PhysicalPlanTranslator extends
DefaultPlanVisitor<PlanFragment, Pla
}
PlanNode planNode = inputFragment.getPlanRoot();
- if (planNode instanceof ExchangeNode || planNode instanceof SortNode
|| planNode instanceof UnionNode) {
+ Plan child = filter.child();
+ while (child instanceof PhysicalLimit) {
+ child = ((PhysicalLimit<?>) child).child();
+ }
+ if (planNode instanceof ExchangeNode || planNode instanceof SortNode
|| planNode instanceof UnionNode
+ // this means we have filter->limit->project, need a SelectNode
+ || child instanceof PhysicalProject) {
// the three nodes don't support conjuncts, need create a
SelectNode to filter data
SelectNode selectNode = new
SelectNode(filter.translatePlanNodeId(), planNode);
addConjunctsToPlanNode(filter, selectNode, context);
diff --git a/regression-test/data/nereids_p0/limit/filterLimitProject.out
b/regression-test/data/nereids_p0/limit/filterLimitProject.out
new file mode 100644
index 00000000000..29359255a3f
--- /dev/null
+++ b/regression-test/data/nereids_p0/limit/filterLimitProject.out
@@ -0,0 +1,8 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !test_translator --
+0
+0
+0
+0
+0
+
diff --git a/regression-test/suites/nereids_p0/limit/filterLimitProject.groovy
b/regression-test/suites/nereids_p0/limit/filterLimitProject.groovy
new file mode 100644
index 00000000000..e30285a196e
--- /dev/null
+++ b/regression-test/suites/nereids_p0/limit/filterLimitProject.groovy
@@ -0,0 +1,58 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_filter_limit_project_translate", "query") {
+ sql "SET enable_nereids_planner=true"
+ sql "SET enable_fallback_to_original_planner=false"
+
+ sql """
+ drop table if exists t1;
+ """
+
+ sql """
+ create table t1 (
+ pk int,
+ c1 int ,
+ c2 varchar(10)
+ ) engine=olap
+ UNIQUE KEY(pk)
+ distributed by hash(pk) buckets 10
+ properties("replication_num" = "1");
+ """
+
+ sql """
+ insert into t1(pk,c1,c2) values
(0,null,'k'),(1,2,'him'),(2,2,'think'),(3,null,'not'),(4,1,'k'),(5,null,'so'),(6,null,'j'),(7,5,'p'),(8,0,'did');
+ """
+
+ qt_test_translator """
+ WITH cte1 AS (
+ SELECT FIRST_VALUE (t1.`pk`) OVER(
+ ORDER BY t1.`pk`
+ ) as pk
+ FROM t1
+ LIMIT 66666666
+ ), cte2 AS (
+ SELECT MIN (t1.`pk`) AS `pk`
+ FROM t1
+ )
+ SELECT cte1.`pk` AS pk1
+ FROM cte1
+ WHERE cte1.`pk` < 4
+ ORDER BY 1 ASC
+ LIMIT 100 OFFSET 4;
+ """
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]