diff options
author | anel <anel@mariadb.org> | 2022-04-26 09:14:12 -0700 |
---|---|---|
committer | anel <anel@mariadb.org> | 2022-04-27 03:50:51 -0700 |
commit | b98aad19f52861e6c80893e26d360d3b8221fa34 (patch) | |
tree | d9ac14d8fd81d624ad6f585437a77b3e507495ca | |
parent | f49425389a5246b80f26c6d32d86979f4bc8fd62 (diff) | |
download | mariadb-git-bb-10.9-anel-MDEV-28334-show_table_status.tar.gz |
MDEV-28334: SHOW TABLE STATUS shows all temporary tables ignoring database and conditionsbb-10.9-anel-MDEV-28334-show_table_status
Reviewed by <monty@mariadb.org>
-rw-r--r-- | mysql-test/main/information_schema_temp_table.result | 35 | ||||
-rw-r--r-- | mysql-test/main/information_schema_temp_table.test | 49 | ||||
-rw-r--r-- | sql/sql_show.cc | 32 |
3 files changed, 112 insertions, 4 deletions
diff --git a/mysql-test/main/information_schema_temp_table.result b/mysql-test/main/information_schema_temp_table.result index ab2cd811ba2..a483aa7d1ec 100644 --- a/mysql-test/main/information_schema_temp_table.result +++ b/mysql-test/main/information_schema_temp_table.result @@ -108,3 +108,38 @@ Message Table 't' already exists alter table t add c int; drop temporary table t; drop table t; +# +# MDEV-28334: SHOW TABLE STATUS shows all temporary tables +# ignoring database and conditions +# +create temporary table test.tmp_in_test (a int); +create table test.base_in_test (t int); +create table test.tmp_in_test (t int); +create temporary table test.tmp_innodb_in_test (a int) engine=InnoDB; +create database mysqltest; +use mysqltest; +show table status; +show table status in mysqltest; +show table status in test; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment Max_index_length Temporary +tmp_innodb_in_test InnoDB 10 Dynamic 0 0 16384 0 0 6291456 NULL # # # latin1_swedish_ci NULL 0 Y +tmp_in_test MyISAM 10 Fixed 0 0 0 1970324836974591 1024 0 NULL # # # latin1_swedish_ci NULL 17179868160 Y +base_in_test MyISAM 10 Fixed 0 0 0 1970324836974591 1024 0 NULL # # # latin1_swedish_ci NULL 17179868160 N +tmp_in_test MyISAM 10 Fixed 0 0 0 1970324836974591 1024 0 NULL # # # latin1_swedish_ci NULL 17179868160 N +show table status from test; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment Max_index_length Temporary +tmp_innodb_in_test InnoDB 10 Dynamic 0 0 16384 0 0 6291456 NULL # # # latin1_swedish_ci NULL 0 Y +tmp_in_test MyISAM 10 Fixed 0 0 0 1970324836974591 1024 0 NULL # # # latin1_swedish_ci NULL 17179868160 Y +base_in_test MyISAM 10 Fixed 0 0 0 1970324836974591 1024 0 NULL # # # latin1_swedish_ci NULL 17179868160 N +tmp_in_test MyISAM 10 Fixed 0 0 0 1970324836974591 1024 0 NULL # # # latin1_swedish_ci NULL 17179868160 N +# check that InnoDB temporary table +# has a NULL value for `Create time` column (MDEV-28333) +select create_time from information_schema.tables where table_name='tmp_innodb_in_test'; +create_time +NULL +show table status like 'nonexisting'; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment Max_index_length Temporary +drop database mysqltest; +drop table test.base_in_test; +drop table test.tmp_in_test; +drop table test.tmp_in_test; diff --git a/mysql-test/main/information_schema_temp_table.test b/mysql-test/main/information_schema_temp_table.test index f8b1935edcf..0070b517d4d 100644 --- a/mysql-test/main/information_schema_temp_table.test +++ b/mysql-test/main/information_schema_temp_table.test @@ -102,4 +102,51 @@ alter table t add c int; # Cleanup drop temporary table t; -drop table t;
\ No newline at end of file +drop table t; + +--echo # +--echo # MDEV-28334: SHOW TABLE STATUS shows all temporary tables +--echo # ignoring database and conditions +--echo # + +create temporary table test.tmp_in_test (a int); +create table test.base_in_test (t int); +# The base table with the same name as temporary table +create table test.tmp_in_test (t int); +# The temporary InnoDB table - CREATE TIME should be NULL, MDEV-28333 +create temporary table test.tmp_innodb_in_test (a int) engine=InnoDB; + +create database mysqltest; +use mysqltest; + +# This should show tables from currently used DB +# no temporary tables created and empty result set should be returned +show table status; + +# The same as before +show table status in mysqltest; + +# The should show all ables from `test` DB +--replace_column 12 # 13 # 14 # +--horizontal_results +show table status in test; + +# The same as before +--replace_column 12 # 13 # 14 # +--horizontal_results +show table status from test; + + +--echo # check that InnoDB temporary table +--echo # has a NULL value for `Create time` column (MDEV-28333) +select create_time from information_schema.tables where table_name='tmp_innodb_in_test'; + +# This shouldn't give any results +show table status like 'nonexisting'; + +# Cleanup +drop database mysqltest; +drop table test.base_in_test; +# We need first to drop temporary table that shadows the base table +drop table test.tmp_in_test; +drop table test.tmp_in_test;
\ No newline at end of file diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 165317d80be..5e93c25d6ef 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -151,8 +151,10 @@ static int show_create_sequence(THD *thd, TABLE_LIST *table_list, static const LEX_CSTRING *view_algorithm(TABLE_LIST *table); -bool get_lookup_field_values(THD *, COND *, TABLE_LIST *, LOOKUP_FIELD_VALUES *); -void process_i_s_table_temporary_tables(THD *thd, TABLE * table, TABLE *tmp_tbl); +bool get_lookup_field_values(THD *, COND *, TABLE_LIST *, + LOOKUP_FIELD_VALUES *); +void process_i_s_table_temporary_tables(THD *thd, TABLE * table, + TABLE *tmp_tbl); /** Try to lock a mutex, but give up after a short while to not cause deadlocks @@ -5240,13 +5242,37 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) { All_tmp_tables_list::Iterator it(*open_tables_state_backup.temporary_tables); TMP_TABLE_SHARE *share_temp; + const char *wild= thd->lex->wild ? thd->lex->wild->ptr() : NullS; while ((share_temp= it++)) { All_share_tables_list::Iterator it2(share_temp->all_tmp_tables); while (TABLE *tmp_tbl= it2++) { if (IS_USER_TEMP_TABLE(share_temp)) - process_i_s_table_temporary_tables(thd, table, tmp_tbl); + { + for (size_t i=0; i < db_names.elements(); i++) + { + LEX_CSTRING *db_name= db_names.at(i); + LEX_CSTRING *table_name= &share_temp->table_name; + + if (!my_strcasecmp(system_charset_info, db_name->str, + share_temp->db.str)) + { + restore_record(table, s->default_values); + table->field[schema_table->idx_field1]-> + store(db_name->str, db_name->length, system_charset_info); + table->field[schema_table->idx_field2]-> + store(table_name->str, table_name->length, + system_charset_info); + if ((!partial_cond || partial_cond->val_int()) && + (!wild || !wild_compare(table_name->str, wild, 0))) + { + process_i_s_table_temporary_tables(thd, table, tmp_tbl); + break; + } + } + } + } } } } |