diff options
-rw-r--r-- | mysql-test/r/temp_table.result | 15 | ||||
-rw-r--r-- | mysql-test/t/temp_table.test | 13 | ||||
-rw-r--r-- | sql/mysqld.cc | 24 | ||||
-rw-r--r-- | sql/sql_class.h | 2 | ||||
-rw-r--r-- | sql/sql_parse.cc | 9 |
5 files changed, 53 insertions, 10 deletions
diff --git a/mysql-test/r/temp_table.result b/mysql-test/r/temp_table.result index dca925040b0..2e35303c57f 100644 --- a/mysql-test/r/temp_table.result +++ b/mysql-test/r/temp_table.result @@ -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 diff --git a/mysql-test/t/temp_table.test b/mysql-test/t/temp_table.test index 542a3487196..987fbf7e848 100644 --- a/mysql-test/t/temp_table.test +++ b/mysql-test/t/temp_table.test @@ -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'; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index ac72132f531..08bacd05c7c 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -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)) diff --git a/sql/sql_class.h b/sql/sql_class.h index 0306a8c609e..37b1dd9d43d 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -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; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 29989720431..f0b2cc042a6 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -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 @@ end_with_restore_list: } 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; } |