summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnel Husakovic <anel@mariadb.org>2022-05-11 03:54:16 -0500
committerAnel Husakovic <anel@mariadb.org>2022-07-16 13:33:28 +0200
commitbfe77811c449052725c321a22252ad6f51d48923 (patch)
tree8ab5fd86a1db0c1c294a1f13500a99a01f423885
parenta49151ba0e24e835e015e94f869cc3f8291ff2f3 (diff)
downloadmariadb-git-bfe77811c449052725c321a22252ad6f51d48923.tar.gz
MDEV-28453: SHOW commands are inconsistent for temporary tables
- Added logic to function `fill_schema_table_names`(function responsible for `show table` command) in order to bypass `ha_table_exists()` in case where shadowing of base table exists and by setting correct string in type field of `show table` command. It is up to the caller to mark that temporary tables should be checked what is done in function `get_all_tables()` - Reviewed by: <>
-rw-r--r--mysql-test/main/information_schema_temp_table.result36
-rw-r--r--mysql-test/main/information_schema_temp_table.test25
-rw-r--r--sql/sql_show.cc29
3 files changed, 83 insertions, 7 deletions
diff --git a/mysql-test/main/information_schema_temp_table.result b/mysql-test/main/information_schema_temp_table.result
index 778227cbb99..26f53c7b05b 100644
--- a/mysql-test/main/information_schema_temp_table.result
+++ b/mysql-test/main/information_schema_temp_table.result
@@ -143,3 +143,39 @@ drop database mysqltest;
drop table test.base_in_test;
drop table test.tmp_in_test;
drop table test.tmp_in_test;
+#
+# MDEV-28453: SHOW commands are inconsistent for temporary tables
+#
+create database mysqltest;
+use mysqltest;
+create table t (a int, key(a)) engine=Aria;
+create temporary table t (b int, key(b)) engine=MyISAM;
+Warnings:
+Note 1050 Table 't' already exists
+create table base_table(t int);
+create temporary table tmp_table (b int, key(b));
+show tables;
+Tables_in_mysqltest
+tmp_table
+t
+base_table
+t
+show full tables;
+Tables_in_mysqltest Table_type
+tmp_table TEMPORARY TABLE
+t TEMPORARY TABLE
+base_table BASE TABLE
+t BASE TABLE
+show table status;
+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_table MyISAM 10 Fixed 0 0 0 1970324836974591 1024 0 NULL # # # latin1_swedish_ci NULL 288230376151710720 Y
+t MyISAM 10 Fixed 0 0 0 1970324836974591 1024 0 NULL # # # latin1_swedish_ci NULL 288230376151710720 Y
+base_table MyISAM 10 Fixed 0 0 0 1970324836974591 1024 0 NULL # # # latin1_swedish_ci NULL 17179868160 N
+t Aria 10 Page 0 0 8192 17592186011648 8192 0 NULL # # # latin1_swedish_ci NULL transactional=1 9007199254732800 N
+show columns in t;
+Field Type Null Key Default Extra
+b int(11) YES MUL NULL
+show index in t;
+Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored
+t 1 b 1 b A NULL NULL NULL YES BTREE NO
+drop database mysqltest;
diff --git a/mysql-test/main/information_schema_temp_table.test b/mysql-test/main/information_schema_temp_table.test
index a87416174f6..1e22f1598d0 100644
--- a/mysql-test/main/information_schema_temp_table.test
+++ b/mysql-test/main/information_schema_temp_table.test
@@ -150,3 +150,28 @@ 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;
+
+--echo #
+--echo # MDEV-28453: SHOW commands are inconsistent for temporary tables
+--echo #
+create database mysqltest;
+use mysqltest;
+create table t (a int, key(a)) engine=Aria;
+create temporary table t (b int, key(b)) engine=MyISAM;
+create table base_table(t int);
+create temporary table tmp_table (b int, key(b));
+
+# This should show all tables
+show tables;
+# This should show all tables with additional table_type
+show full tables;
+# This is already showing all tables (not related to bug)
+--replace_column 12 # 13 # 14 #
+show table status;
+# This is showing temporary table as expected since it is shadowing base table
+show columns in t;
+# This is showing temporary table as expected since it is shadowing base table
+show index in t;
+
+# Cleanup
+drop database mysqltest; \ No newline at end of file
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index e891fa89adc..16f391c66e6 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -4800,6 +4800,9 @@ end:
@param[in] table TABLE struct for I_S table
@param[in] db_name database name
@param[in] table_name table name
+ @param[in] is_temp flag for temporary table
+ (prevent call of ha_table_exists
+ in case of shadowing base table)
@return Operation status
@retval 0 success
@@ -4808,7 +4811,8 @@ end:
static int fill_schema_table_names(THD *thd, TABLE_LIST *tables,
LEX_CSTRING *db_name,
- LEX_CSTRING *table_name)
+ LEX_CSTRING *table_name,
+ bool is_temp= false)
{
TABLE *table= tables->table;
if (db_name == &INFORMATION_SCHEMA_NAME)
@@ -4823,7 +4827,7 @@ static int fill_schema_table_names(THD *thd, TABLE_LIST *tables,
bool is_sequence;
if (ha_table_exists(thd, db_name, table_name, NULL, NULL,
- &hton, &is_sequence))
+ &hton, &is_sequence) && !is_temp)
{
if (hton == view_pseudo_hton)
table->field[3]->store(STRING_WITH_LEN("VIEW"), cs);
@@ -4833,7 +4837,12 @@ static int fill_schema_table_names(THD *thd, TABLE_LIST *tables,
table->field[3]->store(STRING_WITH_LEN("BASE TABLE"), cs);
}
else
- table->field[3]->store(STRING_WITH_LEN("ERROR"), cs);
+ {
+ if (is_temp)
+ table->field[3]->store(STRING_WITH_LEN("TEMPORARY TABLE"), cs);
+ else
+ table->field[3]->store(STRING_WITH_LEN("ERROR"), cs);
+ }
if (unlikely(thd->is_error() &&
thd->get_stmt_da()->sql_errno() == ER_NO_SUCH_TABLE))
@@ -5300,8 +5309,11 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
init_alloc_root(PSI_INSTRUMENT_ME, &tmp_mem_root, SHOW_ALLOC_BLOCK_SIZE,
SHOW_ALLOC_BLOCK_SIZE, MY_THREAD_SPECIFIC);
- /* Handling session temporary tables from the backup state */
- if (schema_table_idx == SCH_TABLES && open_tables_state_backup.temporary_tables)
+ /* Handling session temporary tables from the backup state for table IS.tables
+ and SHOW TABLES commands.
+ */
+ if ((schema_table_idx == SCH_TABLES || schema_table_idx == SCH_TABLE_NAMES) && \
+ open_tables_state_backup.temporary_tables)
{
All_tmp_tables_list::Iterator it(*open_tables_state_backup.temporary_tables);
TMP_TABLE_SHARE *share_temp;
@@ -5330,7 +5342,11 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
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);
+ if (schema_table_idx == SCH_TABLE_NAMES)
+ fill_schema_table_names(thd, tables, &tmp_tbl->s->db,
+ &tmp_tbl->s->table_name, true);
+ else
+ process_i_s_table_temporary_tables(thd, table, tmp_tbl);
break;
}
}
@@ -5913,7 +5929,6 @@ void process_i_s_table_temporary_tables(THD *thd, TABLE *table, TABLE *tmp_tbl)
TABLE_LIST table_list;
bzero((char*) &table_list, sizeof(TABLE_LIST));
table_list.table= tmp_tbl;
-
get_schema_tables_record(thd, &table_list, table,
0, &tmp_tbl->s->db, &tmp_tbl->s->table_name);
}