From 16201592a29395b1e86f6a7c772f3952b8b2ebb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Fri, 23 Jun 2017 13:40:15 +0300 Subject: [PATCH] MXS-852: Fix execution of COM_STMT_FETCH The COM_STMT_FETCH queries are always executed when the result has not been fully read. This means that the statement queuing code needs to allow COM_STMT_FETCH commands to pass if a statement is being executed but the command queue is empty. --- server/modules/protocol/MySQL/mysql_common.c | 3 ++- server/modules/routing/readwritesplit/readwritesplit.cc | 6 ++++-- server/modules/routing/readwritesplit/rwsplit_route_stmt.cc | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/server/modules/protocol/MySQL/mysql_common.c b/server/modules/protocol/MySQL/mysql_common.c index 767f0a46d..ecf7fb684 100644 --- a/server/modules/protocol/MySQL/mysql_common.c +++ b/server/modules/protocol/MySQL/mysql_common.c @@ -1654,5 +1654,6 @@ bool mxs_mysql_command_will_respond(uint8_t cmd) { return cmd != MYSQL_COM_STMT_SEND_LONG_DATA && cmd != MYSQL_COM_QUIT && - cmd != MYSQL_COM_STMT_CLOSE; + cmd != MYSQL_COM_STMT_CLOSE && + cmd != MYSQL_COM_STMT_FETCH; } diff --git a/server/modules/routing/readwritesplit/readwritesplit.cc b/server/modules/routing/readwritesplit/readwritesplit.cc index 3b0bce5b2..fb277e030 100644 --- a/server/modules/routing/readwritesplit/readwritesplit.cc +++ b/server/modules/routing/readwritesplit/readwritesplit.cc @@ -919,8 +919,10 @@ static int routeQuery(MXS_ROUTER *instance, MXS_ROUTER_SESSION *router_session, } else { - if ((rses->expected_responses == 0 && rses->query_queue == NULL) || - rses->load_data_state == LOAD_DATA_ACTIVE) + if (rses->query_queue == NULL && + (rses->expected_responses == 0 || + mxs_mysql_get_command(querybuf) == MYSQL_COM_STMT_FETCH || + rses->load_data_state == LOAD_DATA_ACTIVE)) { /** No active or pending queries */ if (route_single_stmt(inst, rses, querybuf)) diff --git a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc index 770e63683..549247ac9 100644 --- a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc +++ b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc @@ -1076,7 +1076,8 @@ static inline bool query_creates_reply(mysql_server_cmd_t cmd) { return cmd != MYSQL_COM_QUIT && cmd != MYSQL_COM_STMT_SEND_LONG_DATA && - cmd != MYSQL_COM_STMT_CLOSE; + cmd != MYSQL_COM_STMT_CLOSE && + cmd != MYSQL_COM_STMT_FETCH; // Fetch is done mid-result } /**