[Bug] Fix mysql return bug (#4450)

Send fields after first row arrived so that error packet can be send to client
when exception thrown from coord.getNext(). 
Golang and Python can not identify error if fields packet arrived before error packet.
This commit is contained in:
gengjun-git
2020-08-27 12:17:24 +08:00
committed by GitHub
parent 3c784b9c90
commit fe0c21bf93

View File

@ -608,9 +608,6 @@ public class StmtExecutor {
coord.exec();
// if python's MysqlDb get error after sendfields, it can't catch the exception
// so We need to send fields after first batch arrived
// send result
// 1. If this is a query with OUTFILE clause, eg: select * from tbl1 into outfile xxx,
// We will not send real query result to client. Instead, we only send OK to client with
@ -622,13 +619,17 @@ public class StmtExecutor {
RowBatch batch;
MysqlChannel channel = context.getMysqlChannel();
boolean isOutfileQuery = queryStmt.hasOutFileClause();
if (!isOutfileQuery) {
sendFields(queryStmt.getColLabels(), queryStmt.getResultExprs());
}
boolean isSendFields = false;
while (true) {
batch = coord.getNext();
// for outfile query, there will be only one empty batch send back with eos flag
if (batch.getBatch() != null && !isOutfileQuery) {
// For some language driver, getting error packet after fields packet will be recognized as a success result
// so We need to send fields after first batch arrived
if (!isSendFields) {
sendFields(queryStmt.getColLabels(), queryStmt.getResultExprs());
isSendFields = true;
}
for (ByteBuffer row : batch.getBatch().getRows()) {
channel.sendOnePacket(row);
}
@ -638,6 +639,9 @@ public class StmtExecutor {
break;
}
}
if (!isSendFields && !isOutfileQuery) {
sendFields(queryStmt.getColLabels(), queryStmt.getResultExprs());
}
statisticsForAuditLog = batch.getQueryStatistics();
if (!isOutfileQuery) {