Commit 1ce71c84 authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-7832 Add status variables to track CREATE TEMPORARY TABLE and DROP TEMPORARY TABLE

Pretend that CREATE TABLE and CREATE TEMPORARY TABLE are
two different commands internally. The user doesn't need
to know that they both are SQLCOM_CREATE_TABLE.

Same for DROP [TEMPORARY] TABLE
parent e24caa75
......@@ -293,3 +293,18 @@ test.t3 repair status OK
DROP TABLES t1, t2, t3;
create temporary temporary table t1 (a int);
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'temporary table t1 (a int)' at line 1
flush status;
create table t1 (a int);
create temporary table t2 (a int);
create temporary table t3 (a int);
drop table t1;
drop table t2;
drop temporary table t3;
show status like 'com_create%table';
Variable_name Value
Com_create_table 1
Com_create_temporary_table 2
show status like 'com_drop%table';
Variable_name Value
Com_drop_table 2
Com_drop_temporary_table 1
......@@ -325,3 +325,16 @@ DROP TABLES t1, t2, t3;
#
--error ER_PARSE_ERROR
create temporary temporary table t1 (a int);
#
# MDEV-7832 Add status variables to track CREATE TEMPORARY TABLE and DROP TEMPORARY TABLE
#
flush status;
create table t1 (a int);
create temporary table t2 (a int);
create temporary table t3 (a int);
drop table t1;
drop table t2;
drop temporary table t3;
show status like 'com_create%table';
show status like 'com_drop%table';
......@@ -3756,6 +3756,7 @@ SHOW_VAR com_status_vars[]= {
{"create_role", STMT_STATUS(SQLCOM_CREATE_ROLE)},
{"create_server", STMT_STATUS(SQLCOM_CREATE_SERVER)},
{"create_table", STMT_STATUS(SQLCOM_CREATE_TABLE)},
{"create_temporary_table", COM_STATUS(com_create_tmp_table)},
{"create_trigger", STMT_STATUS(SQLCOM_CREATE_TRIGGER)},
{"create_udf", STMT_STATUS(SQLCOM_CREATE_FUNCTION)},
{"create_user", STMT_STATUS(SQLCOM_CREATE_USER)},
......@@ -3772,6 +3773,7 @@ SHOW_VAR com_status_vars[]= {
{"drop_role", STMT_STATUS(SQLCOM_DROP_ROLE)},
{"drop_server", STMT_STATUS(SQLCOM_DROP_SERVER)},
{"drop_table", STMT_STATUS(SQLCOM_DROP_TABLE)},
{"drop_temporary_table", COM_STATUS(com_drop_tmp_table)},
{"drop_trigger", STMT_STATUS(SQLCOM_DROP_TRIGGER)},
{"drop_user", STMT_STATUS(SQLCOM_DROP_USER)},
{"drop_view", STMT_STATUS(SQLCOM_DROP_VIEW)},
......@@ -4207,25 +4209,27 @@ static int init_common_variables()
We have few debug-only commands in com_status_vars, only visible in debug
builds. for simplicity we enable the assert only in debug builds
There are 8 Com_ variables which don't have corresponding SQLCOM_ values:
There are 10 Com_ variables which don't have corresponding SQLCOM_ values:
(TODO strictly speaking they shouldn't be here, should not have Com_ prefix
that is. Perhaps Stmt_ ? Comstmt_ ? Prepstmt_ ?)
Com_admin_commands => com_other
Com_stmt_close => com_stmt_close
Com_stmt_execute => com_stmt_execute
Com_stmt_fetch => com_stmt_fetch
Com_stmt_prepare => com_stmt_prepare
Com_stmt_reprepare => com_stmt_reprepare
Com_stmt_reset => com_stmt_reset
Com_stmt_send_long_data => com_stmt_send_long_data
Com_admin_commands => com_other
Com_create_temporary_table => com_create_tmp_table
Com_drop_temporary_table => com_drop_tmp_table
Com_stmt_close => com_stmt_close
Com_stmt_execute => com_stmt_execute
Com_stmt_fetch => com_stmt_fetch
Com_stmt_prepare => com_stmt_prepare
Com_stmt_reprepare => com_stmt_reprepare
Com_stmt_reset => com_stmt_reset
Com_stmt_send_long_data => com_stmt_send_long_data
With this correction the number of Com_ variables (number of elements in
the array, excluding the last element - terminator) must match the number
of SQLCOM_ constants.
*/
compile_time_assert(sizeof(com_status_vars)/sizeof(com_status_vars[0]) - 1 ==
SQLCOM_END + 8);
SQLCOM_END + 10);
#endif
if (get_options(&remaining_argc, &remaining_argv))
......
......@@ -675,6 +675,8 @@ typedef struct system_variables
typedef struct system_status_var
{
ulong com_stat[(uint) SQLCOM_END];
ulong com_create_tmp_table;
ulong com_drop_tmp_table;
ulong com_other;
ulong com_stmt_prepare;
......
......@@ -3176,6 +3176,12 @@ mysql_execute_command(THD *thd)
TABLE_LIST *create_table= first_table;
TABLE_LIST *select_tables= lex->create_last_non_select_table->next_global;
if (lex->tmp_table())
{
status_var_decrement(thd->status_var.com_stat[SQLCOM_CREATE_TABLE]);
status_var_increment(thd->status_var.com_create_tmp_table);
}
/*
Code below (especially in mysql_create_table() and select_create
methods) may modify HA_CREATE_INFO structure in LEX, so we have to
......@@ -4131,6 +4137,9 @@ mysql_execute_command(THD *thd)
}
else
{
status_var_decrement(thd->status_var.com_stat[SQLCOM_DROP_TABLE]);
status_var_increment(thd->status_var.com_drop_tmp_table);
/* So that DROP TEMPORARY TABLE gets to binlog at commit/rollback */
thd->variables.option_bits|= OPTION_KEEP_LOG;
}
......
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