Skip to content

Commit bfd634f

Browse files
[fix](protocol) only return multi result when CLIENT_MULTI_STATEMENTS been set (#36759) (#36919)
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 a05d5cc commit bfd634f

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,13 @@ public void executeQuery(MysqlCommand mysqlCommand, String originStmt) throws Ex
315315
if (i != stmts.size() - 1) {
316316
ctx.getState().serverStatus |= MysqlServerStatusFlag.SERVER_MORE_RESULTS_EXISTS;
317317
if (ctx.getState().getStateType() != MysqlStateType.ERR) {
318-
finalizeCommand();
318+
// here, doris do different with mysql.
319+
// when client not request CLIENT_MULTI_STATEMENTS, mysql treat all query as
320+
// single statement. Doris treat it with multi statement, but only return
321+
// the last statement result.
322+
if (getConnectContext().getCapability().isClientMultiStatements()) {
323+
finalizeCommand();
324+
}
319325
}
320326
}
321327
} else if (connectType.equals(ConnectType.ARROW_FLIGHT_SQL)) {

0 commit comments

Comments
 (0)