diff options
author | Oleksandr Byelkin <sanja@mariadb.com> | 2016-01-07 16:00:02 +0100 |
---|---|---|
committer | Oleksandr Byelkin <sanja@mariadb.com> | 2016-01-29 18:36:45 +0100 |
commit | e145f0f5b65ff15c1c59bb39c3f23bdf2ab9bf43 (patch) | |
tree | 14b4f2014c31292af15fb6b7256dc6eb8b2b1275 | |
parent | 4ae982f5178e08886e482e43841cb68661553de0 (diff) | |
download | mariadb-git-bb-sanja-10.2.tar.gz |
MDEV-9058: protocol: COM_MULTI command (part 3)bb-sanja-10.2
Support of "previuousely used statement ID".
All IDs with highest bit ON reserved for special use.
-rw-r--r-- | sql/sql_class.cc | 1 | ||||
-rw-r--r-- | sql/sql_class.h | 7 | ||||
-rw-r--r-- | sql/sql_prepare.cc | 13 | ||||
-rw-r--r-- | sql/sql_prepare.h | 4 |
4 files changed, 23 insertions, 2 deletions
diff --git a/sql/sql_class.cc b/sql/sql_class.cc index a38822c3f16..13ff89e73f9 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -1425,6 +1425,7 @@ void THD::init(void) bzero((char *) &org_status_var, sizeof(org_status_var)); start_bytes_received= 0; last_commit_gtid.seq_no= 0; + last_stmt= NULL; status_in_global= 0; #ifdef WITH_WSREP wsrep_exec_mode= wsrep_applier ? REPL_RECV : LOCAL_STATE; diff --git a/sql/sql_class.h b/sql/sql_class.h index da33e7c3331..da011a58947 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1963,6 +1963,13 @@ public: /* all prepared statements and cursors of this connection */ Statement_map stmt_map; + + /* Last created prepared statement */ + Statement *last_stmt; + inline void set_last_stmt(Statement *stmt) + { last_stmt= (is_error() ? NULL : stmt); } + inline void clear_last_stmt() { last_stmt= NULL; } + /* A pointer to the stack frame of handle_one_connection(), which is called first in the thread for handling a client diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 809e6d63338..c139f3e5c8a 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -324,7 +324,9 @@ find_prepared_statement(THD *thd, ulong id) prepared statements find() will return 0 if there is a named prepared statement with such id. */ - Statement *stmt= thd->stmt_map.find(id); + Statement *stmt= ((id == LAST_STMT_ID) ? + thd->last_stmt : + thd->stmt_map.find(id)); if (stmt == 0 || stmt->type() != Query_arena::PREPARED_STATEMENT) return NULL; @@ -2322,7 +2324,10 @@ void mysqld_stmt_prepare(THD *thd, const char *packet, uint packet_length) { /* Statement map deletes statement on erase */ thd->stmt_map.erase(stmt); + thd->clear_last_stmt(); } + else + thd->set_last_stmt(stmt); thd->protocol= save_protocol; @@ -2908,6 +2913,9 @@ void mysqld_stmt_close(THD *thd, char *packet) stmt->deallocate(); general_log_print(thd, thd->get_command(), NullS); + if (thd->last_stmt == stmt) + thd->clear_last_stmt(); + DBUG_VOID_RETURN; } @@ -3170,7 +3178,8 @@ end: Prepared_statement::Prepared_statement(THD *thd_arg) :Statement(NULL, &main_mem_root, - STMT_INITIALIZED, ++thd_arg->statement_id_counter), + STMT_INITIALIZED, + ((++thd_arg->statement_id_counter) & STMT_ID_MASK)), thd(thd_arg), result(thd_arg), param_array(0), diff --git a/sql/sql_prepare.h b/sql/sql_prepare.h index b468ac1bf9b..aec4ac40036 100644 --- a/sql/sql_prepare.h +++ b/sql/sql_prepare.h @@ -18,6 +18,10 @@ #include "sql_error.h" + +#define LAST_STMT_ID 0xFFFFFFFF +#define STMT_ID_MASK 0x7FFFFFFF + class THD; struct LEX; |