Commit 80439e69 authored by Anel Husakovic's avatar Anel Husakovic Committed by Sergei Golubchik

MDEV-31618: Server crashes in...

MDEV-31618: Server crashes in process_i_s_table_temporary_tables/get_all_tables after alter in rename query

Any TMP_TABLE_SHARE must always have at least one TABLE instance.
So whenever a temporary TABLE that is marked for reopen is closed,
reopen it at once if its TMP_TABLE_SHARE list of tables becomes empty.
parent de57da73
......@@ -266,3 +266,56 @@ mysqltest s1
DROP TABLE seq1;
DROP TABLE mysqltest.s1;
DROP TABLE mysqltest.s2;
#
# MDEV-31618: Server crashes in
# process_i_s_table_temporary_tables/get_all_tables after alter in rename
#
CREATE table seq1 (a bigint, b int);
CREATE TEMPORARY TABLE tmp LIKE seq1;
INSERT tmp SELECT * FROM seq1;
ALTER TABLE tmp RENAME TO seq1;
ALTER TABLE seq1 CHANGE a b int ;
Got one of the listed errors
RENAME TABLE seq1 TO seq1;
ERROR 42S01: Table 'seq1' already exists
show full tables;
Tables_in_test Table_type
seq1 TEMPORARY TABLE
seq1 BASE TABLE
drop table seq1;
drop table seq1;
CREATE SEQUENCE seq2;
CREATE TEMPORARY sequence tmp;
show full tables;
Tables_in_test Table_type
tmp TEMPORARY SEQUENCE
seq2 SEQUENCE
ALTER table `tmp` RENAME TO seq1;
show full tables;
Tables_in_test Table_type
seq1 TEMPORARY SEQUENCE
seq2 SEQUENCE
ALTER TABLE `seq1` CHANGE `cache_size` cache_size int ;
ERROR HY000: Sequence 'test.seq1' table structure is invalid (cache_size)
show full tables;
Tables_in_test Table_type
seq1 TEMPORARY SEQUENCE
seq2 SEQUENCE
RENAME TABLE seq1 TO seq1;
ERROR 42S01: Table 'seq1' already exists
show full tables;
Tables_in_test Table_type
seq1 TEMPORARY SEQUENCE
seq2 SEQUENCE
RENAME TABLE seq1 TO seq3;
show full tables;
Tables_in_test Table_type
seq3 TEMPORARY SEQUENCE
seq2 SEQUENCE
drop table seq2;
show full tables;
Tables_in_test Table_type
seq3 TEMPORARY SEQUENCE
drop table seq3;
show full tables;
Tables_in_test Table_type
......@@ -242,3 +242,39 @@ SELECT table_schema, table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_type
DROP TABLE seq1;
DROP TABLE mysqltest.s1;
DROP TABLE mysqltest.s2;
--echo #
--echo # MDEV-31618: Server crashes in
--echo # process_i_s_table_temporary_tables/get_all_tables after alter in rename
--echo #
# Check on temporary tables
CREATE table seq1 (a bigint, b int);
CREATE TEMPORARY TABLE tmp LIKE seq1;
INSERT tmp SELECT * FROM seq1;
ALTER TABLE tmp RENAME TO seq1;
--error 4086,1060
ALTER TABLE seq1 CHANGE a b int ;
--error 1050
RENAME TABLE seq1 TO seq1;
show full tables;
drop table seq1;
drop table seq1;
# Check on sequences
CREATE SEQUENCE seq2;
CREATE TEMPORARY sequence tmp;
show full tables;
ALTER table `tmp` RENAME TO seq1;
show full tables;
--error ER_SEQUENCE_INVALID_TABLE_STRUCTURE
ALTER TABLE `seq1` CHANGE `cache_size` cache_size int ;
show full tables;
--error ER_TABLE_EXISTS_ERROR
RENAME TABLE seq1 TO seq1;
show full tables;
RENAME TABLE seq1 TO seq3;
show full tables;
drop table seq2;
show full tables;
drop table seq3;
show full tables;
......@@ -1086,8 +1086,13 @@ TABLE *THD::find_temporary_table(const char *key, uint key_length,
{
share->all_tmp_tables.remove(table);
free_temporary_table(table);
it.rewind();
continue;
if (share->all_tmp_tables.is_empty())
table= open_temporary_table(share, share->table_name.str);
else
{
it.rewind();
continue;
}
}
result= table;
break;
......
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