Skip to content

Commit

Permalink
MDEV-31618: Server crashes in process_i_s_table_temporary_tables/get_…
Browse files Browse the repository at this point in the history
…all_tables

- Pre-open temporary table on sequence creation.
- Without this patch, if rename alter is done on the temporary sequence,
  and after that `create replace`, since table is not preopened and
  alter rename marked the table as reopen, and such table is deleted in
  the `find_temporary_table()` leaving the share without the table, that
  causes `show tables` to fail
- Closes PR #2685
- Reviewer: <serg@mariadb.com>
  • Loading branch information
an3l committed Aug 2, 2023
1 parent cb6307f commit 579dcf0
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
35 changes: 35 additions & 0 deletions mysql-test/main/information_schema_temp_table.result
Expand Up @@ -231,3 +231,38 @@ def test t1 BASE TABLE MyISAM 10 Fixed 1 7 X X X X NULL X X NULL latin1_swedish_
def test t2 TEMPORARY MRG_MyISAM 10 Fixed 0 0 X X X X NULL X X NULL latin1_swedish_ci NULL X Y
def test t3 BASE TABLE MRG_MyISAM 10 Fixed 1 5 X X X X NULL X X NULL latin1_swedish_ci NULL X N
DROP TABLE t1,t2,t3;
#
# MDEV-31618: Server crashes in
# process_i_s_table_temporary_tables/get_all_tables
#
CREATE TEMPORARY SEQUENCE seq1;
SHOW FULL TABLES;
Tables_in_test Table_type
seq1 TEMPORARY SEQUENCE
SELECT table_schema, table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_type='temporary sequence';
table_schema table_name
test seq1
mysqltest s2
mysqltest s1
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
SELECT table_schema, table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_type='temporary sequence';
table_schema table_name
test seq1
mysqltest s2
mysqltest s1
CREATE OR REPLACE TEMPORARY SEQUENCE seq1;
SHOW FULL TABLES;
Tables_in_test Table_type
seq1 TEMPORARY SEQUENCE
SELECT table_schema, table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_type='temporary sequence';
table_schema table_name
test seq1
mysqltest s2
mysqltest s1
DROP TABLE seq1;
DROP TABLE mysqltest.s1;
DROP TABLE mysqltest.s2;
23 changes: 23 additions & 0 deletions mysql-test/main/information_schema_temp_table.test
Expand Up @@ -219,3 +219,26 @@ CREATE TABLE t3 (a INT) ENGINE=MERGE UNION=(t1);
--replace_column 10 X 11 X 12 X 13 X 15 X 16 X 22 X
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'test';
DROP TABLE t1,t2,t3;

--echo #
--echo # MDEV-31618: Server crashes in
--echo # process_i_s_table_temporary_tables/get_all_tables
--echo #

CREATE TEMPORARY SEQUENCE seq1;
# Check show temp tables before alter
SHOW FULL TABLES;
SELECT table_schema, table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_type='temporary sequence';
--error 4086
ALTER TABLE `seq1` CHANGE `cache_size` cache_size int;
# Check show temp tables after alter
SHOW FULL TABLES;
SELECT table_schema, table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_type='temporary sequence';

CREATE OR REPLACE TEMPORARY SEQUENCE seq1;
# Check show temp tables after create/replace alter
SHOW FULL TABLES;
SELECT table_schema, table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_type='temporary sequence';
DROP TABLE seq1;
DROP TABLE mysqltest.s1;
DROP TABLE mysqltest.s2;
1 change: 1 addition & 0 deletions sql/sql_parse.cc
Expand Up @@ -787,6 +787,7 @@ void init_update_queries(void)
Note that SQLCOM_RENAME_TABLE should not be in this list!
*/
sql_command_flags[SQLCOM_CREATE_TABLE]|= CF_PREOPEN_TMP_TABLES;
sql_command_flags[SQLCOM_CREATE_SEQUENCE]|= CF_PREOPEN_TMP_TABLES;
sql_command_flags[SQLCOM_CREATE_INDEX]|= CF_PREOPEN_TMP_TABLES;
sql_command_flags[SQLCOM_ALTER_TABLE]|= CF_PREOPEN_TMP_TABLES;
sql_command_flags[SQLCOM_TRUNCATE]|= CF_PREOPEN_TMP_TABLES;
Expand Down
4 changes: 2 additions & 2 deletions sql/sql_show.cc
Expand Up @@ -5326,7 +5326,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
system_charset_info);
schema_table_store_record(thd, table);
}
else /* SCH_TABLE */
else /* SCH_TABLES */
process_i_s_table_temporary_tables(thd, table, tmp_tbl);
}
}
Expand Down Expand Up @@ -5372,7 +5372,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
continue;
}
#endif
restore_record(table, s->default_values);
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]->
Expand Down

0 comments on commit 579dcf0

Please sign in to comment.