Commit 2f7b6c57 authored by Oleksandr Byelkin's avatar Oleksandr Byelkin

MDEV-9058: protocol: COM_MULTI command (part 3)

Support of "previuousely used statement ID".
All IDs with highest bit ON reserved for special use.
parent fd1b7d0f
...@@ -1340,7 +1340,7 @@ performance-schema-max-rwlock-instances -1 ...@@ -1340,7 +1340,7 @@ performance-schema-max-rwlock-instances -1
performance-schema-max-socket-classes 10 performance-schema-max-socket-classes 10
performance-schema-max-socket-instances -1 performance-schema-max-socket-instances -1
performance-schema-max-stage-classes 150 performance-schema-max-stage-classes 150
performance-schema-max-statement-classes 180 performance-schema-max-statement-classes 181
performance-schema-max-table-handles -1 performance-schema-max-table-handles -1
performance-schema-max-table-instances -1 performance-schema-max-table-instances -1
performance-schema-max-thread-classes 50 performance-schema-max-thread-classes 50
......
...@@ -2965,9 +2965,9 @@ READ_ONLY YES ...@@ -2965,9 +2965,9 @@ READ_ONLY YES
COMMAND_LINE_ARGUMENT REQUIRED COMMAND_LINE_ARGUMENT REQUIRED
VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_STATEMENT_CLASSES VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_STATEMENT_CLASSES
SESSION_VALUE NULL SESSION_VALUE NULL
GLOBAL_VALUE 180 GLOBAL_VALUE 181
GLOBAL_VALUE_ORIGIN COMPILE-TIME GLOBAL_VALUE_ORIGIN COMPILE-TIME
DEFAULT_VALUE 180 DEFAULT_VALUE 181
VARIABLE_SCOPE GLOBAL VARIABLE_SCOPE GLOBAL
VARIABLE_TYPE BIGINT UNSIGNED VARIABLE_TYPE BIGINT UNSIGNED
VARIABLE_COMMENT Maximum number of statement instruments. VARIABLE_COMMENT Maximum number of statement instruments.
......
...@@ -1426,6 +1426,7 @@ void THD::init(void) ...@@ -1426,6 +1426,7 @@ void THD::init(void)
bzero((char *) &org_status_var, sizeof(org_status_var)); bzero((char *) &org_status_var, sizeof(org_status_var));
start_bytes_received= 0; start_bytes_received= 0;
last_commit_gtid.seq_no= 0; last_commit_gtid.seq_no= 0;
last_stmt= NULL;
status_in_global= 0; status_in_global= 0;
#ifdef WITH_WSREP #ifdef WITH_WSREP
wsrep_exec_mode= wsrep_applier ? REPL_RECV : LOCAL_STATE; wsrep_exec_mode= wsrep_applier ? REPL_RECV : LOCAL_STATE;
......
...@@ -1965,6 +1965,13 @@ class THD :public Statement, ...@@ -1965,6 +1965,13 @@ class THD :public Statement,
/* all prepared statements and cursors of this connection */ /* all prepared statements and cursors of this connection */
Statement_map stmt_map; 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(), A pointer to the stack frame of handle_one_connection(),
which is called first in the thread for handling a client which is called first in the thread for handling a client
......
...@@ -326,8 +326,14 @@ find_prepared_statement(THD *thd, ulong id) ...@@ -326,8 +326,14 @@ find_prepared_statement(THD *thd, ulong id)
To strictly separate namespaces of SQL prepared statements and C API To strictly separate namespaces of SQL prepared statements and C API
prepared statements find() will return 0 if there is a named prepared prepared statements find() will return 0 if there is a named prepared
statement with such id. statement with such id.
LAST_STMT_ID is special value which mean last prepared statement ID
(it was made for COM_MULTI to allow prepare and execute a statement
in the same command but usage is not limited by COM_MULTI only).
*/ */
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) if (stmt == 0 || stmt->type() != Query_arena::PREPARED_STATEMENT)
return NULL; return NULL;
...@@ -2569,7 +2575,10 @@ void mysqld_stmt_prepare(THD *thd, const char *packet, uint packet_length) ...@@ -2569,7 +2575,10 @@ void mysqld_stmt_prepare(THD *thd, const char *packet, uint packet_length)
{ {
/* Statement map deletes statement on erase */ /* Statement map deletes statement on erase */
thd->stmt_map.erase(stmt); thd->stmt_map.erase(stmt);
thd->clear_last_stmt();
} }
else
thd->set_last_stmt(stmt);
thd->protocol= save_protocol; thd->protocol= save_protocol;
...@@ -3155,6 +3164,9 @@ void mysqld_stmt_close(THD *thd, char *packet) ...@@ -3155,6 +3164,9 @@ void mysqld_stmt_close(THD *thd, char *packet)
stmt->deallocate(); stmt->deallocate();
general_log_print(thd, thd->get_command(), NullS); general_log_print(thd, thd->get_command(), NullS);
if (thd->last_stmt == stmt)
thd->clear_last_stmt();
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -3417,7 +3429,8 @@ Execute_sql_statement::execute_server_code(THD *thd) ...@@ -3417,7 +3429,8 @@ Execute_sql_statement::execute_server_code(THD *thd)
Prepared_statement::Prepared_statement(THD *thd_arg) Prepared_statement::Prepared_statement(THD *thd_arg)
:Statement(NULL, &main_mem_root, :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), thd(thd_arg),
result(thd_arg), result(thd_arg),
param_array(0), param_array(0),
......
...@@ -18,6 +18,10 @@ ...@@ -18,6 +18,10 @@
#include "sql_error.h" #include "sql_error.h"
#define LAST_STMT_ID 0xFFFFFFFF
#define STMT_ID_MASK 0x7FFFFFFF
class THD; class THD;
struct LEX; struct LEX;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment