Skip to content

Commit 6ac990b

Browse files
[fix](protocol) only return multi result when CLIENT_MULTI_STATEMENTS been set (#36759) (#36924)
pick from master #36759 multi statement support by PR #3050. But there is a minor issue in implementation. as MySQL dev doc say in https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_command_phase_sp.html#sect_protocol_command_phase_sp_multi_statement server should only process multi statement when client set CLIENT_MULTI_STATEMENTS. When client not set CLIENT_MULTI_STATEMENTS, server should treat query as single statement. but Doris do slightly different with MySQL server. Doris always treat query as multi statement, but only return multi result when client set CLIENT_MULTI_STATEMENTS. When client do not set CLIENT_MULTI_STATEMENTS, Doris will return the last statement result only. --------- Co-authored-by: Mingyu Chen <[email protected]>
1 parent 8f78103 commit 6ac990b

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

fe/fe-core/src/main/java/org/apache/doris/mysql/MysqlCapability.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,13 @@ public boolean isDeprecatedEOF() {
161161
return (flags & Flag.CLIENT_DEPRECATE_EOF.getFlagBit()) != 0;
162162
}
163163

164+
public boolean isClientMultiStatements() {
165+
return (flags & Flag.CLIENT_MULTI_STATEMENTS.getFlagBit()) != 0;
166+
}
167+
164168
@Override
165169
public boolean equals(Object obj) {
166-
if (obj == null || !(obj instanceof MysqlCapability)) {
170+
if (!(obj instanceof MysqlCapability)) {
167171
return false;
168172
}
169173
if (flags != ((MysqlCapability) obj).flags) {

fe/fe-core/src/main/java/org/apache/doris/qe/ConnectProcessor.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,11 @@ private void handleQuery(MysqlCommand mysqlCommand) {
430430
executor.execute();
431431
if (i != stmts.size() - 1) {
432432
ctx.getState().serverStatus |= MysqlServerStatusFlag.SERVER_MORE_RESULTS_EXISTS;
433-
if (ctx.getState().getStateType() != MysqlStateType.ERR) {
433+
// here, doris do different with mysql.
434+
// when client not request CLIENT_MULTI_STATEMENTS, mysql treat all query as
435+
// single statement. Doris treat it with multi statement, but only return
436+
// the last statement result.
437+
if (ctx.getCapability().isClientMultiStatements()) {
434438
finalizeCommand();
435439
}
436440
}

0 commit comments

Comments
 (0)