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 42afe20f0b5ba97..d3f19736d0c27d9 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 @@ -1827,17 +1827,19 @@ public PlanFragment visitPhysicalNestedLoopJoin( @Override public PlanFragment visitPhysicalLimit(PhysicalLimit physicalLimit, PlanTranslatorContext context) { - Plan childPlan = physicalLimit.child(0); PlanFragment inputFragment = physicalLimit.child(0).accept(this, context); PlanNode child = inputFragment.getPlanRoot(); - if (childPlan instanceof PhysicalLimit) { - child.setLimit(Math.min(physicalLimit.getLimit() + physicalLimit.getOffset(), child.getLimit())); + + if (!(inputFragment.getPlanRoot() instanceof ExchangeNode)) { + inputFragment.getPlanRoot().setLimit(physicalLimit.getLimit()); + inputFragment.getPlanRoot().setOffset(physicalLimit.getOffset()); + return inputFragment; } else { child.setLimit(MergeLimits.mergeLimit(physicalLimit.getLimit(), physicalLimit.getOffset(), child.getLimit())); + // TODO: plan node don't support limit + // child.setOffset(MergeLimits.mergeOffset(physicalLimit.getOffset(), child.getOffset())); } - // TODO: plan node don't support limit - // child.setOffset(MergeLimits.mergeOffset(physicalLimit.getOffset(), child.getOffset())); updateLegacyPlanIdToPhysicalPlan(child, physicalLimit); return inputFragment; } diff --git a/regression-test/suites/nereids_syntax_p0/test_limit.groovy b/regression-test/suites/nereids_syntax_p0/test_limit.groovy index 7fb68c0922c40c8..c51a05b15aac958 100644 --- a/regression-test/suites/nereids_syntax_p0/test_limit.groovy +++ b/regression-test/suites/nereids_syntax_p0/test_limit.groovy @@ -19,11 +19,6 @@ suite("test_limit") { sql 'set enable_nereids_planner=true' sql 'set enable_fallback_to_original_planner=false' - def DBname = "limit_test_db" - sql "DROP DATABASE IF EXISTS ${DBname}" - sql "CREATE DATABASE IF NOT EXISTS ${DBname}" - sql "use ${DBname}" - sql """ drop table if exists test1 """ @@ -80,7 +75,4 @@ suite("test_limit") { select row_number() over(order by k6 desc) k6s, t.* from row_number_limit_tbl t limit 1 offset 2; """ - sql """ drop database IF EXISTS ${DBname} """ - - }