Skip to content

Commit 2f7b6c5

Browse files
committed
MDEV-9058: protocol: COM_MULTI command (part 3)
Support of "previuousely used statement ID". All IDs with highest bit ON reserved for special use.
1 parent fd1b7d0 commit 2f7b6c5

File tree

6 files changed

+30
-5
lines changed

6 files changed

+30
-5
lines changed

mysql-test/r/mysqld--help.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ performance-schema-max-rwlock-instances -1
13401340
performance-schema-max-socket-classes 10
13411341
performance-schema-max-socket-instances -1
13421342
performance-schema-max-stage-classes 150
1343-
performance-schema-max-statement-classes 180
1343+
performance-schema-max-statement-classes 181
13441344
performance-schema-max-table-handles -1
13451345
performance-schema-max-table-instances -1
13461346
performance-schema-max-thread-classes 50

mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2965,9 +2965,9 @@ READ_ONLY YES
29652965
COMMAND_LINE_ARGUMENT REQUIRED
29662966
VARIABLE_NAME PERFORMANCE_SCHEMA_MAX_STATEMENT_CLASSES
29672967
SESSION_VALUE NULL
2968-
GLOBAL_VALUE 180
2968+
GLOBAL_VALUE 181
29692969
GLOBAL_VALUE_ORIGIN COMPILE-TIME
2970-
DEFAULT_VALUE 180
2970+
DEFAULT_VALUE 181
29712971
VARIABLE_SCOPE GLOBAL
29722972
VARIABLE_TYPE BIGINT UNSIGNED
29732973
VARIABLE_COMMENT Maximum number of statement instruments.

sql/sql_class.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,6 +1426,7 @@ void THD::init(void)
14261426
bzero((char *) &org_status_var, sizeof(org_status_var));
14271427
start_bytes_received= 0;
14281428
last_commit_gtid.seq_no= 0;
1429+
last_stmt= NULL;
14291430
status_in_global= 0;
14301431
#ifdef WITH_WSREP
14311432
wsrep_exec_mode= wsrep_applier ? REPL_RECV : LOCAL_STATE;

sql/sql_class.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,6 +1965,13 @@ class THD :public Statement,
19651965

19661966
/* all prepared statements and cursors of this connection */
19671967
Statement_map stmt_map;
1968+
1969+
/* Last created prepared statement */
1970+
Statement *last_stmt;
1971+
inline void set_last_stmt(Statement *stmt)
1972+
{ last_stmt= (is_error() ? NULL : stmt); }
1973+
inline void clear_last_stmt() { last_stmt= NULL; }
1974+
19681975
/*
19691976
A pointer to the stack frame of handle_one_connection(),
19701977
which is called first in the thread for handling a client

sql/sql_prepare.cc

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,14 @@ find_prepared_statement(THD *thd, ulong id)
326326
To strictly separate namespaces of SQL prepared statements and C API
327327
prepared statements find() will return 0 if there is a named prepared
328328
statement with such id.
329+
330+
LAST_STMT_ID is special value which mean last prepared statement ID
331+
(it was made for COM_MULTI to allow prepare and execute a statement
332+
in the same command but usage is not limited by COM_MULTI only).
329333
*/
330-
Statement *stmt= thd->stmt_map.find(id);
334+
Statement *stmt= ((id == LAST_STMT_ID) ?
335+
thd->last_stmt :
336+
thd->stmt_map.find(id));
331337

332338
if (stmt == 0 || stmt->type() != Query_arena::PREPARED_STATEMENT)
333339
return NULL;
@@ -2569,7 +2575,10 @@ void mysqld_stmt_prepare(THD *thd, const char *packet, uint packet_length)
25692575
{
25702576
/* Statement map deletes statement on erase */
25712577
thd->stmt_map.erase(stmt);
2578+
thd->clear_last_stmt();
25722579
}
2580+
else
2581+
thd->set_last_stmt(stmt);
25732582

25742583
thd->protocol= save_protocol;
25752584

@@ -3155,6 +3164,9 @@ void mysqld_stmt_close(THD *thd, char *packet)
31553164
stmt->deallocate();
31563165
general_log_print(thd, thd->get_command(), NullS);
31573166

3167+
if (thd->last_stmt == stmt)
3168+
thd->clear_last_stmt();
3169+
31583170
DBUG_VOID_RETURN;
31593171
}
31603172

@@ -3417,7 +3429,8 @@ Execute_sql_statement::execute_server_code(THD *thd)
34173429

34183430
Prepared_statement::Prepared_statement(THD *thd_arg)
34193431
:Statement(NULL, &main_mem_root,
3420-
STMT_INITIALIZED, ++thd_arg->statement_id_counter),
3432+
STMT_INITIALIZED,
3433+
((++thd_arg->statement_id_counter) & STMT_ID_MASK)),
34213434
thd(thd_arg),
34223435
result(thd_arg),
34233436
param_array(0),

sql/sql_prepare.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818

1919
#include "sql_error.h"
2020

21+
22+
#define LAST_STMT_ID 0xFFFFFFFF
23+
#define STMT_ID_MASK 0x7FFFFFFF
24+
2125
class THD;
2226
struct LEX;
2327

0 commit comments

Comments
 (0)