Skip to content

Commit 64f1c90

Browse files
morrySnowmorningman
authored andcommitted
[fix](protocol) only return multi result when CLIENT_MULTI_STATEMENTS been set (#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 5087f7d commit 64f1c90

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
@@ -387,7 +387,13 @@ public void executeQuery(MysqlCommand mysqlCommand, String originStmt) throws Ex
387387
if (i != stmts.size() - 1) {
388388
ctx.getState().serverStatus |= MysqlServerStatusFlag.SERVER_MORE_RESULTS_EXISTS;
389389
if (ctx.getState().getStateType() != MysqlStateType.ERR) {
390-
finalizeCommand();
390+
// here, doris do different with mysql.
391+
// when client not request CLIENT_MULTI_STATEMENTS, mysql treat all query as
392+
// single statement. Doris treat it with multi statement, but only return
393+
// the last statement result.
394+
if (getConnectContext().getCapability().isClientMultiStatements()) {
395+
finalizeCommand();
396+
}
391397
}
392398
}
393399
} else if (connectType.equals(ConnectType.ARROW_FLIGHT_SQL)) {

0 commit comments

Comments
 (0)