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

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


The following commit(s) were added to refs/heads/branch-3.0 by this push:
     new 484807ab688 branch-3.0: [fix](sql_select_limit) sql_select_limit 
should not affect DML #53379 (#53528)
484807ab688 is described below

commit 484807ab68875124aa996fa12b10085ac3b76d99
Author: morrySnow <[email protected]>
AuthorDate: Mon Jul 21 20:12:44 2025 +0800

    branch-3.0: [fix](sql_select_limit) sql_select_limit should not affect DML 
#53379 (#53528)
    
    cherry picked from #53379
---
 .../nereids/rules/rewrite/AddDefaultLimit.java     |  10 ++++++
 .../java/org/apache/doris/qe/SessionVariable.java  |   2 +-
 .../session_variable/test_default_limit.out        | Bin 0 -> 257 bytes
 .../session_variable/test_default_limit.groovy     |  38 +++++++++++++++++++++
 4 files changed, 49 insertions(+), 1 deletion(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AddDefaultLimit.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AddDefaultLimit.java
index 7887836475c..8885092051b 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AddDefaultLimit.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AddDefaultLimit.java
@@ -25,6 +25,7 @@ import 
org.apache.doris.nereids.trees.plans.logical.LogicalCTEAnchor;
 import org.apache.doris.nereids.trees.plans.logical.LogicalLimit;
 import org.apache.doris.nereids.trees.plans.logical.LogicalSink;
 import org.apache.doris.nereids.trees.plans.logical.LogicalSort;
+import org.apache.doris.nereids.trees.plans.logical.LogicalTableSink;
 import org.apache.doris.nereids.trees.plans.visitor.CustomRewriter;
 import org.apache.doris.nereids.trees.plans.visitor.DefaultPlanRewriter;
 import org.apache.doris.qe.ConnectContext;
@@ -36,6 +37,10 @@ public class AddDefaultLimit extends 
DefaultPlanRewriter<StatementContext> imple
 
     @Override
     public Plan rewriteRoot(Plan plan, JobContext jobContext) {
+        if (jobContext.getCascadesContext().getConnectContext() == null
+                || 
!jobContext.getCascadesContext().getConnectContext().getState().isQuery()) {
+            return plan;
+        }
         return plan.accept(this, 
jobContext.getCascadesContext().getStatementContext());
     }
 
@@ -52,6 +57,11 @@ public class AddDefaultLimit extends 
DefaultPlanRewriter<StatementContext> imple
         return plan;
     }
 
+    @Override
+    public Plan visitLogicalTableSink(LogicalTableSink<? extends Plan> 
logicalTableSink, StatementContext context) {
+        return logicalTableSink;
+    }
+
     // should add limit under anchor to keep optimize opportunity
     @Override
     public Plan visitLogicalCTEAnchor(LogicalCTEAnchor<? extends Plan, ? 
extends Plan> cteAnchor,
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java 
b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
index 6400ae19a7b..806f23bc8d9 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
@@ -903,7 +903,7 @@ public class SessionVariable implements Serializable, 
Writable {
     @VariableMgr.VarAttr(name = SQL_AUTO_IS_NULL)
     public boolean sqlAutoIsNull = false;
 
-    @VariableMgr.VarAttr(name = SQL_SELECT_LIMIT)
+    @VariableMgr.VarAttr(name = SQL_SELECT_LIMIT, needForward = true)
     private long sqlSelectLimit = Long.MAX_VALUE;
 
     // this is used to make c3p0 library happy
diff --git 
a/regression-test/data/nereids_p0/session_variable/test_default_limit.out 
b/regression-test/data/nereids_p0/session_variable/test_default_limit.out
new file mode 100644
index 00000000000..c44140a25c3
Binary files /dev/null and 
b/regression-test/data/nereids_p0/session_variable/test_default_limit.out differ
diff --git 
a/regression-test/suites/nereids_p0/session_variable/test_default_limit.groovy 
b/regression-test/suites/nereids_p0/session_variable/test_default_limit.groovy
index 2854d87b8e3..214f4a304cb 100644
--- 
a/regression-test/suites/nereids_p0/session_variable/test_default_limit.groovy
+++ 
b/regression-test/suites/nereids_p0/session_variable/test_default_limit.groovy
@@ -281,4 +281,42 @@ suite('test_default_limit') {
         '''
         assertEquals(res.size(), 8)
     }
+
+    // test dml
+    sql 'set default_order_by_limit = -1'
+    sql 'set sql_select_limit = 1'
+
+    sql """truncate table baseall"""
+    sql """truncate table bigtable"""
+    sql """drop table if exists unique_table"""
+    sql """create table unique_table (
+            k0 int,
+            k1 int,
+            k2 int
+        )
+        unique key (k0)
+        distributed by hash(k0) buckets 16
+        properties(
+            'replication_num'='1'
+        )
+    """
+    sql """insert into baseall values(1, 1, 1), (2, 2, 2),(3, 3, 3), (4, 4, 
4)"""
+    sql """insert into unique_table values(1, 1, 1), (2, 2, 2),(3, 3, 3)"""
+    sql "sync"
+    // should execute successful
+    sql "delete from baseall where k0 in (3, 4)"
+    sql "sync"
+    // should insert 2 lines
+    sql "insert into bigtable select * from baseall"
+    sql "sync"
+    // should update 2 lines
+    sql "update unique_table set k1 = 4 where k1 in (2, 3, 4)"
+    sql "sync"
+    // should delete 2 lines
+    sql "delete from unique_table where k0 = 1 or k0 = 2"
+    sql "sync"
+    sql 'set sql_select_limit = -1'
+    qt_baseall_should_delete_2_lines "select * from baseall order by k0"
+    qt_unique_should_delete_2_lines_and_update_1_line "select * from 
unique_table order by k0"
+    qt_bigtable_should_insert_2_lines "select * from bigtable order by k0"
 }
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to