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

lijibing pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 579e442d99f [fix](prepare statement)Use client prepare statement when 
placeholders are more than 65536. (#54568)
579e442d99f is described below

commit 579e442d99f51b44e17b1d52d845174a27270ad2
Author: James <[email protected]>
AuthorDate: Wed Aug 13 14:30:46 2025 +0800

    [fix](prepare statement)Use client prepare statement when placeholders are 
more than 65536. (#54568)
    
    ### What problem does this PR solve?
    Use client prepare statement when placeholders are more than 65536. This
    is the requirement of MySql.
    
    Issue Number: close #xxx
    
    Related PR: #xxx
    
    Problem Summary:
    
    ### Release note
    
    None
    
    ### Check List (For Author)
    
    - Test <!-- At least one of them must be included. -->
        - [x] Regression test
        - [ ] Unit Test
        - [ ] Manual test (add detailed scripts or steps below)
        - [ ] No need to test or manual test. Explain why:
    - [ ] This is a refactor/code format and no logic has been changed.
            - [ ] Previous test can cover this change.
            - [ ] No code files have been changed.
            - [ ] Other reason <!-- Add your reason?  -->
    
    - Behavior changed:
        - [x] No.
        - [ ] Yes. <!-- Explain the behavior change -->
    
    - Does this need documentation?
        - [x] No.
    - [ ] Yes. <!-- Add document PR link here. eg:
    https://github.com/apache/doris-website/pull/1214 -->
    
    ### Check List (For Reviewer who merge this PR)
    
    - [ ] Confirm the release note
    - [ ] Confirm test cases
    - [ ] Confirm document
    - [ ] Add branch pick label <!-- Add branch pick label that this PR
    should merge into -->
---
 .../doris/nereids/trees/plans/commands/PrepareCommand.java   |  6 ++++++
 regression-test/suites/prepared_stmt_p0/prepared_stmt.groovy | 12 +++++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/PrepareCommand.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/PrepareCommand.java
index 663e6c94323..f4dbebd3126 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/PrepareCommand.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/PrepareCommand.java
@@ -19,6 +19,8 @@ package org.apache.doris.nereids.trees.plans.commands;
 
 import org.apache.doris.analysis.StmtType;
 import org.apache.doris.catalog.Column;
+import org.apache.doris.common.ErrorCode;
+import org.apache.doris.common.ErrorReport;
 import org.apache.doris.mysql.MysqlCommand;
 import org.apache.doris.nereids.StatementContext;
 import org.apache.doris.nereids.trees.expressions.Placeholder;
@@ -50,6 +52,7 @@ public class PrepareCommand extends Command {
 
     private final List<Placeholder> placeholders = new ArrayList<>();
     private final LogicalPlan logicalPlan;
+    private final int maxPlaceholderCount = 65536;
 
     private final String name;
 
@@ -106,6 +109,9 @@ public class PrepareCommand extends Command {
     @Override
     public void run(ConnectContext ctx, StmtExecutor executor) throws 
Exception {
         List<String> labels = getLabels();
+        if (labels.size() >= maxPlaceholderCount) {
+            ErrorReport.reportAnalysisException(ErrorCode.ERR_PS_MANY_PARAM);
+        }
         StatementContext statementContext = ctx.getStatementContext();
         statementContext.setPrepareStage(true);
         List<Slot> slots;
diff --git a/regression-test/suites/prepared_stmt_p0/prepared_stmt.groovy 
b/regression-test/suites/prepared_stmt_p0/prepared_stmt.groovy
index ba8a2c98f66..e644a8ed97d 100644
--- a/regression-test/suites/prepared_stmt_p0/prepared_stmt.groovy
+++ b/regression-test/suites/prepared_stmt_p0/prepared_stmt.groovy
@@ -70,7 +70,17 @@ suite("test_prepared_stmt", "nonConcurrent") {
         sql "set enable_fallback_to_original_planner = false"
         sql """set global enable_server_side_prepared_statement = true"""
 
-        def stmt_read = prepareStatement "select * from ${tableName} where k1 
= ? order by k1"
+        int count = 65536;
+        StringBuilder sb = new StringBuilder();
+        sb.append("?");
+        for (int i = 1; i < count; i++) {
+            sb.append(", ?");
+        }
+        String sqlWithTooManyPlaceholder = sb.toString();
+        def stmt_read = prepareStatement "select * from ${tableName} where k1 
in ${sqlWithTooManyPlaceholder}"
+        assertEquals(com.mysql.cj.jdbc.ClientPreparedStatement, 
stmt_read.class)
+
+        stmt_read = prepareStatement "select * from ${tableName} where k1 = ? 
order by k1"
         assertEquals(com.mysql.cj.jdbc.ServerPreparedStatement, 
stmt_read.class)
         stmt_read.setInt(1, 1231)
         qe_select0 stmt_read


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

Reply via email to