Skip to content

Commit fcf1416

Browse files
committed
MDEV-37968 GTT: is allowed to us as mysql.help_topic, failing assertions
HELP caused opening a child GTT, whish has table category TEMPORARY, while only SYSTEM/STATISTICS tables are allowed. In another assertion, ref_count didn't reach 0 in innodb on shutdown. We really don't want allowing GTT to work as a system table. The problem is table->s->table_category is determined at *open* stage, merely by a name: share->table_category= get_table_category(share->db, share->table_name) We could forbid GTT creation when its name maches non-user category. However, RENAME never opens a table, which means, we anyway can rename GTT to a system table. All we can do is make sure we don't open it. Parent issue: MDEV-35915
1 parent 3f2a3fe commit fcf1416

5 files changed

Lines changed: 51 additions & 0 deletions

File tree

mysql-test/main/global_temporary_table.result

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,4 +1342,12 @@ create or replace global temporary table t2 select 0;
13421342
alter table t2 force;
13431343
flush table t2;
13441344
drop table t2;
1345+
# MDEV-37968 GTT: is allowed to us as mysql.help_topic, causing various assertion failures
1346+
rename table mysql.help_topic to mysql.help_topic1;
1347+
create global temporary table test.t1 (help_topic_id int unsigned,name char);
1348+
rename table test.t1 to mysql.help_topic;
1349+
help '';
1350+
ERROR HY000: 'mysql.help_topic' is not of type 'BASE TABLE'
1351+
drop table mysql.help_topic;
1352+
rename table mysql.help_topic1 to mysql.help_topic;
13451353
disconnect con1;

mysql-test/main/global_temporary_table.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,4 +1223,14 @@ alter table t2 force;
12231223
flush table t2;
12241224
drop table t2;
12251225

1226+
--echo # MDEV-37968 GTT: is allowed to us as mysql.help_topic, causing various assertion failures
1227+
rename table mysql.help_topic to mysql.help_topic1;
1228+
create global temporary table test.t1 (help_topic_id int unsigned,name char);
1229+
rename table test.t1 to mysql.help_topic;
1230+
--error ER_WRONG_OBJECT
1231+
help '';
1232+
1233+
drop table mysql.help_topic;
1234+
rename table mysql.help_topic1 to mysql.help_topic;
1235+
12261236
--disconnect con1

mysql-test/suite/binlog/r/global_temporary_table.result

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,14 @@ create or replace global temporary table t2 select 0;
13451345
alter table t2 force;
13461346
flush table t2;
13471347
drop table t2;
1348+
# MDEV-37968 GTT: is allowed to us as mysql.help_topic, causing various assertion failures
1349+
rename table mysql.help_topic to mysql.help_topic1;
1350+
create global temporary table test.t1 (help_topic_id int unsigned,name char);
1351+
rename table test.t1 to mysql.help_topic;
1352+
help '';
1353+
ERROR HY000: 'mysql.help_topic' is not of type 'BASE TABLE'
1354+
drop table mysql.help_topic;
1355+
rename table mysql.help_topic1 to mysql.help_topic;
13481356
disconnect con1;
13491357
include/show_binlog_events.inc
13501358
Log_name Pos Event_type Server_id End_log_pos Info
@@ -2113,5 +2121,15 @@ master-bin.000001 # Gtid # # GTID #-#-#
21132121
master-bin.000001 # Query # # use `test`; flush table t2
21142122
master-bin.000001 # Gtid # # GTID #-#-#
21152123
master-bin.000001 # Query # # use `test`; DROP TABLE `t2` /* generated by server */
2124+
master-bin.000001 # Gtid # # GTID #-#-#
2125+
master-bin.000001 # Query # # use `test`; rename table mysql.help_topic to mysql.help_topic1
2126+
master-bin.000001 # Gtid # # GTID #-#-#
2127+
master-bin.000001 # Query # # use `test`; create global temporary table test.t1 (help_topic_id int unsigned,name char)
2128+
master-bin.000001 # Gtid # # GTID #-#-#
2129+
master-bin.000001 # Query # # use `test`; rename table test.t1 to mysql.help_topic
2130+
master-bin.000001 # Gtid # # GTID #-#-#
2131+
master-bin.000001 # Query # # use `test`; DROP TABLE `mysql`.`help_topic` /* generated by server */
2132+
master-bin.000001 # Gtid # # GTID #-#-#
2133+
master-bin.000001 # Query # # use `test`; rename table mysql.help_topic1 to mysql.help_topic
21162134
set global binlog_annotate_row_events= @old_binlog_annotate_row_events;
21172135
reset master;

mysql-test/suite/rpl/r/global_temporary_table.result

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,14 @@ create or replace global temporary table t2 select 0;
13451345
alter table t2 force;
13461346
flush table t2;
13471347
drop table t2;
1348+
# MDEV-37968 GTT: is allowed to us as mysql.help_topic, causing various assertion failures
1349+
rename table mysql.help_topic to mysql.help_topic1;
1350+
create global temporary table test.t1 (help_topic_id int unsigned,name char);
1351+
rename table test.t1 to mysql.help_topic;
1352+
help '';
1353+
ERROR HY000: 'mysql.help_topic' is not of type 'BASE TABLE'
1354+
drop table mysql.help_topic;
1355+
rename table mysql.help_topic1 to mysql.help_topic;
13481356
disconnect con1;
13491357
connection slave;
13501358
connection master;

sql/sql_table.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6239,6 +6239,13 @@ my_bool open_global_temporary_table(THD *thd, TABLE_SHARE *source,
62396239
return TRUE;
62406240
}
62416241

6242+
if (source->table_category != TABLE_CATEGORY_USER)
6243+
{
6244+
my_error(ER_WRONG_OBJECT, MYF(0), source->db.str, source->table_name.str,
6245+
"BASE TABLE");
6246+
return TRUE;
6247+
}
6248+
62426249
/*
62436250
First, lookup in tmp tables list for cases like "t join t"
62446251
This also could happen if tl->open_type is OT_BASE_ONLY

0 commit comments

Comments
 (0)