[Commits] 7e70658: MDEV-9947: COM_MULTI united response

Olaksandr Byelkin sanja at mariadb.com
Mon May 9 16:26:18 EEST 2016


revision-id: 7e70658d1e88b4a255e3c28426f8259e5e596a85 (mariadb-10.2.0-20-g7e70658)
parent(s): c0a59b46be5be341bd6ffc9fe188a236ced46522
committer: Oleksandr Byelkin
timestamp: 2016-05-09 15:26:18 +0200
message:

MDEV-9947: COM_MULTI united response

---
 libmysqld/lib_sql.cc |  3 ++-
 sql/log_event.cc     |  2 +-
 sql/protocol.cc      | 17 ++++++++++-------
 sql/protocol.h       |  2 +-
 sql/sql_error.cc     |  1 +
 sql/sql_error.h      |  8 ++++++++
 sql/sql_parse.cc     | 36 +++++++++++++++++++++++++++---------
 sql/sql_parse.h      |  3 ++-
 sql/sql_prepare.cc   |  4 ++--
 sql/wsrep_sst.cc     |  2 +-
 10 files changed, 55 insertions(+), 23 deletions(-)

diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc
index a067856..bcb45ae 100644
--- a/libmysqld/lib_sql.cc
+++ b/libmysqld/lib_sql.cc
@@ -1170,7 +1170,8 @@ bool Protocol_binary::write()
 bool
 net_send_ok(THD *thd,
             uint server_status, uint statement_warn_count,
-            ulonglong affected_rows, ulonglong id, const char *message)
+            ulonglong affected_rows, ulonglong id, const char *message,
+            bool unused __attribute__((unused)))
 {
   DBUG_ENTER("emb_net_send_ok");
   MYSQL_DATA *data;
diff --git a/sql/log_event.cc b/sql/log_event.cc
index 3715f0c..c966d36 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -4439,7 +4439,7 @@ int Query_log_event::do_apply_event(rpl_group_info *rgi,
 
         thd->enable_slow_log= thd->variables.sql_log_slow;
         mysql_parse(thd, thd->query(), thd->query_length(), &parser_state,
-                    FALSE);
+                    FALSE, FALSE);
         /* Finalize server status flags after executing a statement. */
         thd->update_server_status();
         log_slow_statement(thd);
diff --git a/sql/protocol.cc b/sql/protocol.cc
index 9e52870..0bf2a05 100644
--- a/sql/protocol.cc
+++ b/sql/protocol.cc
@@ -35,7 +35,7 @@ static const unsigned int PACKET_BUFFER_EXTRA_ALLOC= 1024;
 /* Declared non-static only because of the embedded library. */
 bool net_send_error_packet(THD *, uint, const char *, const char *);
 /* Declared non-static only because of the embedded library. */
-bool net_send_ok(THD *, uint, uint, ulonglong, ulonglong, const char *);
+bool net_send_ok(THD *, uint, uint, ulonglong, ulonglong, const char *, bool);
 /* Declared non-static only because of the embedded library. */
 bool net_send_eof(THD *thd, uint server_status, uint statement_warn_count);
 #ifndef EMBEDDED_LIBRARY
@@ -208,7 +208,8 @@ bool net_send_error(THD *thd, uint sql_errno, const char *err,
 bool
 net_send_ok(THD *thd,
             uint server_status, uint statement_warn_count,
-            ulonglong affected_rows, ulonglong id, const char *message)
+            ulonglong affected_rows, ulonglong id, const char *message,
+            bool postpond_flush)
 {
   NET *net= &thd->net;
   uchar buff[MYSQL_ERRMSG_SIZE+10],*pos;
@@ -250,7 +251,7 @@ net_send_ok(THD *thd,
   if (message && message[0])
     pos= net_store_data(pos, (uchar*) message, strlen(message));
   error= my_net_write(net, buff, (size_t) (pos-buff));
-  if (!error)
+  if (!error && !postpond_flush)
     error= net_flush(net);
 
 
@@ -514,14 +515,16 @@ void Protocol::end_statement()
                    thd->get_stmt_da()->statement_warn_count(),
                    thd->get_stmt_da()->affected_rows(),
                    thd->get_stmt_da()->last_insert_id(),
-                   thd->get_stmt_da()->message());
+                   thd->get_stmt_da()->message(),
+                   thd->get_stmt_da()->postpond_flush());
     break;
   case Diagnostics_area::DA_DISABLED:
     break;
   case Diagnostics_area::DA_EMPTY:
   default:
     DBUG_ASSERT(0);
-    error= send_ok(thd->server_status, 0, 0, 0, NULL);
+    error= send_ok(thd->server_status, 0, 0, 0, NULL,
+                   thd->get_stmt_da()->postpond_flush());
     break;
   }
   if (!error)
@@ -540,12 +543,12 @@ void Protocol::end_statement()
 
 bool Protocol::send_ok(uint server_status, uint statement_warn_count,
                        ulonglong affected_rows, ulonglong last_insert_id,
-                       const char *message)
+                       const char *message, bool postpond_flush)
 {
   DBUG_ENTER("Protocol::send_ok");
   const bool retval= 
     net_send_ok(thd, server_status, statement_warn_count,
-                affected_rows, last_insert_id, message);
+                affected_rows, last_insert_id, message, postpond_flush);
   DBUG_RETURN(retval);
 }
 
diff --git a/sql/protocol.h b/sql/protocol.h
index ea33c6b..baac78d 100644
--- a/sql/protocol.h
+++ b/sql/protocol.h
@@ -62,7 +62,7 @@ class Protocol
 
   virtual bool send_ok(uint server_status, uint statement_warn_count,
                        ulonglong affected_rows, ulonglong last_insert_id,
-                       const char *message);
+                       const char *message, bool postpond_flush);
 
   virtual bool send_eof(uint server_status, uint statement_warn_count);
 
diff --git a/sql/sql_error.cc b/sql/sql_error.cc
index b72d642..be5e664 100644
--- a/sql/sql_error.cc
+++ b/sql/sql_error.cc
@@ -347,6 +347,7 @@ void
 Diagnostics_area::reset_diagnostics_area()
 {
   DBUG_ENTER("reset_diagnostics_area");
+  m_postpond_flush= FALSE;
 #ifdef DBUG_OFF
   m_can_overwrite_status= FALSE;
   /** Don't take chances in production */
diff --git a/sql/sql_error.h b/sql/sql_error.h
index e03c3dd..98c8d77 100644
--- a/sql/sql_error.h
+++ b/sql/sql_error.h
@@ -704,6 +704,12 @@ class Diagnostics_area
   const char *message() const
   { DBUG_ASSERT(m_status == DA_ERROR || m_status == DA_OK); return m_message; }
 
+  bool postpond_flush() const
+  { DBUG_ASSERT(m_status == DA_OK); return m_postpond_flush; }
+
+  void set_postpond_flush()
+  { m_postpond_flush= TRUE; }
+
   uint sql_errno() const
   { DBUG_ASSERT(m_status == DA_ERROR); return m_sql_errno; }
 
@@ -857,6 +863,8 @@ class Diagnostics_area
   /** Set to make set_error_status after set_{ok,eof}_status possible. */
   bool m_can_overwrite_status;
 
+  bool m_postpond_flush;
+
   /** Message buffer. Can be used by OK or ERROR status. */
   char m_message[MYSQL_ERRMSG_SIZE];
 
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index a6bb89f..25fa05d 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -111,7 +111,9 @@
 #include "wsrep_thd.h"
 
 static void wsrep_mysql_parse(THD *thd, char *rawbuf, uint length,
-                              Parser_state *parser_state, bool is_next_command);
+                              Parser_state *parser_state,
+                              bool is_com_multi,
+                              bool is_next_command);
 
 /**
   @defgroup Runtime_Environment Runtime Environment
@@ -1020,7 +1022,7 @@ static void handle_bootstrap_impl(THD *thd)
       break;
     }
 
-    mysql_parse(thd, thd->query(), length, &parser_state, FALSE);
+    mysql_parse(thd, thd->query(), length, &parser_state, FALSE, FALSE);
 
     bootstrap_error= thd->is_error();
     thd->protocol->end_statement();
@@ -1633,6 +1635,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
     drop_more_results= !MY_TEST(thd->server_status &
                                 SERVER_MORE_RESULTS_EXISTS);
     thd->server_status|= SERVER_MORE_RESULTS_EXISTS;
+    if (is_com_multi)
+      thd->get_stmt_da()->set_postpond_flush();
   }
 
   switch (command) {
@@ -1784,10 +1788,10 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
 
     if (WSREP_ON)
       wsrep_mysql_parse(thd, thd->query(), thd->query_length(), &parser_state,
-                        is_next_command);
+                        is_com_multi, is_next_command);
     else
       mysql_parse(thd, thd->query(), thd->query_length(), &parser_state,
-                  is_next_command);
+                  is_com_multi, is_next_command);
 
     while (!thd->killed && (parser_state.m_lip.found_semicolon != NULL) &&
            ! thd->is_error())
@@ -1873,10 +1877,10 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
 
       if (WSREP_ON)
         wsrep_mysql_parse(thd, beginning_of_next_stmt, length, &parser_state,
-                          is_next_command);
+                          is_com_multi, is_next_command);
       else
         mysql_parse(thd, beginning_of_next_stmt, length, &parser_state,
-                    is_next_command);
+                    is_com_multi, is_next_command);
 
     }
 
@@ -1930,7 +1934,12 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
     thd->reset_for_next_command();
     // thd->reset_for_next_command reset state => restore it
     if (is_next_command)
+    {
       thd->server_status|= SERVER_MORE_RESULTS_EXISTS;
+      if (is_com_multi)
+        thd->get_stmt_da()->set_postpond_flush();
+    }
+
     lex_start(thd);
     /* Must be before we init the table list. */
     if (lower_case_table_names)
@@ -7500,7 +7509,9 @@ void mysql_init_multi_delete(LEX *lex)
 }
 
 static void wsrep_mysql_parse(THD *thd, char *rawbuf, uint length,
-                              Parser_state *parser_state, bool is_next_command)
+                              Parser_state *parser_state,
+                              bool is_com_multi,
+                              bool is_next_command)
 {
 #ifdef WITH_WSREP
   bool is_autocommit=
@@ -7519,7 +7530,8 @@ static void wsrep_mysql_parse(THD *thd, char *rawbuf, uint length,
       MYSQL_SET_STATEMENT_TEXT(thd->m_statement_psi, thd->query(),
 	                       thd->query_length());
     }
-    mysql_parse(thd, rawbuf, length, parser_state, is_next_command);
+    mysql_parse(thd, rawbuf, length, parser_state, is_com_multi,
+                is_next_command);
 
     if (WSREP(thd)) {
       /* wsrep BF abort in query exec phase */
@@ -7621,7 +7633,9 @@ static void wsrep_mysql_parse(THD *thd, char *rawbuf, uint length,
 */
 
 void mysql_parse(THD *thd, char *rawbuf, uint length,
-                 Parser_state *parser_state, bool is_next_command)
+                 Parser_state *parser_state,
+                 bool is_com_multi,
+                 bool is_next_command)
 {
   int error __attribute__((unused));
   DBUG_ENTER("mysql_parse");
@@ -7646,7 +7660,11 @@ void mysql_parse(THD *thd, char *rawbuf, uint length,
   lex_start(thd);
   thd->reset_for_next_command();
   if (is_next_command)
+  {
     thd->server_status|= SERVER_MORE_RESULTS_EXISTS;
+    if (is_com_multi)
+      thd->get_stmt_da()->set_postpond_flush();
+  }
 
   if (query_cache_send_result_to_client(thd, rawbuf, length) <= 0)
   {
diff --git a/sql/sql_parse.h b/sql/sql_parse.h
index 53a9ed3..aa8d081 100644
--- a/sql/sql_parse.h
+++ b/sql/sql_parse.h
@@ -88,7 +88,8 @@ bool is_log_table_write_query(enum enum_sql_command command);
 bool alloc_query(THD *thd, const char *packet, uint packet_length);
 void mysql_init_select(LEX *lex);
 void mysql_parse(THD *thd, char *rawbuf, uint length,
-                 Parser_state *parser_state, bool is_com_multi);
+                 Parser_state *parser_state, bool is_com_multi,
+                 bool is_next_command);
 bool mysql_new_select(LEX *lex, bool move_down);
 void create_select_for_variable(const char *var_name);
 void create_table_set_open_action_and_adjust_tables(LEX *lex);
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 2d6a730..89e68dd 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -277,7 +277,7 @@ class Protocol_local :public Protocol
 
   virtual bool send_ok(uint server_status, uint statement_warn_count,
                        ulonglong affected_rows, ulonglong last_insert_id,
-                       const char *message);
+                       const char *message, bool postpond_flush);
 
   virtual bool send_eof(uint server_status, uint statement_warn_count);
   virtual bool send_error(uint sql_errno, const char *err_msg, const char* sqlstate);
@@ -4877,7 +4877,7 @@ bool Protocol_local::send_out_parameters(List<Item_param> *sp_params)
 bool
 Protocol_local::send_ok(uint server_status, uint statement_warn_count,
                         ulonglong affected_rows, ulonglong last_insert_id,
-                        const char *message)
+                        const char *message, bool postpond_flush)
 {
   /*
     Just make sure nothing is sent to the client, we have grabbed
diff --git a/sql/wsrep_sst.cc b/sql/wsrep_sst.cc
index 562bc7e..3ebbeda 100644
--- a/sql/wsrep_sst.cc
+++ b/sql/wsrep_sst.cc
@@ -957,7 +957,7 @@ static int run_sql_command(THD *thd, const char *query)
     return -1;
   }
 
-  mysql_parse(thd, thd->query(), thd->query_length(), &ps, FALSE);
+  mysql_parse(thd, thd->query(), thd->query_length(), &ps, FALSE, FALSE);
   if (thd->is_error())
   {
     int const err= thd->get_stmt_da()->sql_errno();


More information about the commits mailing list