Skip to content

Commit 656f66d

Browse files
committed
Follow-up fix to MDEV-14585 Automatically remove #sql- tables in InnoDB dictionary during recovery
If InnoDB is killed while ALTER TABLE...ALGORITHM=COPY is in progress, after recovery there could be undo log records some records that were inserted into an intermediate copy of the table. Due to these undo log records, InnoDB would resurrect locks at recovery, and the intermediate table would be locked while we are trying to drop it. This would cause a call to row_rename_table_for_mysql(), either from row_mysql_drop_garbage_tables() or from the rollback of a RENAME operation that was part of the ALTER TABLE. row_rename_table_for_mysql(): Do not attempt to parse FOREIGN KEY constraints when renaming from #sql-something to #sql-something-else, because it does not make any sense. row_drop_table_for_mysql(): When deferring DROP TABLE due to locks, do not rename the table if its name already starts with the #sql- prefix, which is what row_mysql_drop_garbage_tables() uses. Previously, the too strict prefix #sql-ib was used, and some tables were renamed unnecessarily.
1 parent 04eef79 commit 656f66d

File tree

3 files changed

+66
-8
lines changed

3 files changed

+66
-8
lines changed
Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,35 @@
1-
CREATE TABLE t1 (a INT UNSIGNED PRIMARY KEY) ENGINE=InnoDB;
2-
INSERT INTO t1 VALUES(42);
1+
CREATE TABLE t1 (a SERIAL, b INT, c INT, d INT) ENGINE=InnoDB;
2+
INSERT INTO t1 () VALUES ();
33
connect con1,localhost,root,,test;
44
SET DEBUG_SYNC='before_rename_table_commit SIGNAL renamed WAIT_FOR ever';
55
RENAME TABLE t1 TO t2;
66
connection default;
77
SET DEBUG_SYNC='now WAIT_FOR renamed';
88
disconnect con1;
99
SELECT * FROM t1;
10-
a
11-
42
10+
a b c d
11+
1 NULL NULL NULL
12+
BEGIN;
13+
COMMIT;
14+
UPDATE t1 SET b=a%7, c=a%11, d=a%13;
15+
SET DEBUG_DBUG='+d,crash_commit_before';
16+
ALTER TABLE t1
17+
ADD INDEX(b,c,d,a),ADD INDEX(b,c,a,d),ADD INDEX(b,a,c,d),ADD INDEX(b,a,d,c),
18+
ADD INDEX(b,d,a,c),ADD INDEX(b,d,c,a),ADD INDEX(a,b,c,d),ADD INDEX(a,b,d,c),
19+
ADD INDEX(a,c,b,d),ADD INDEX(a,c,d,b),ADD INDEX(a,d,b,c),ADD INDEX(a,d,c,b),
20+
ADD INDEX(c,a,b,d),ADD INDEX(c,a,d,b),ADD INDEX(c,b,a,d),ADD INDEX(c,b,d,a),
21+
ADD INDEX(c,d,a,b),ADD INDEX(c,d,b,a),ADD INDEX(d,a,b,c),ADD INDEX(d,a,c,b),
22+
ADD INDEX(d,b,a,c),ADD INDEX(d,b,c,a),ADD INDEX(d,c,a,b),ADD INDEX(d,c,b,a),
23+
ADD INDEX(a,b,c), ADD INDEX(a,c,b), ADD INDEX(a,c,d), ADD INDEX(a,d,c),
24+
ADD INDEX(a,b,d), ADD INDEX(a,d,b), ADD INDEX(b,c,d), ADD INDEX(b,d,c),
25+
ALGORITHM=COPY;
26+
ERROR HY000: Lost connection to MySQL server during query
27+
CHECK TABLE t1;
28+
Table Op Msg_type Msg_text
29+
test.t1 check status OK
30+
SELECT COUNT(*) FROM t1;
31+
COUNT(*)
32+
1000
1233
DROP TABLE t1;
34+
SET GLOBAL innodb_background_drop_list_empty=
35+
@@GLOBAL.innodb_background_drop_list_empty;

mysql-test/suite/innodb/t/rename_table_debug.test

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
--source include/have_debug_sync.inc
44
--source include/not_embedded.inc
55

6-
CREATE TABLE t1 (a INT UNSIGNED PRIMARY KEY) ENGINE=InnoDB;
7-
INSERT INTO t1 VALUES(42);
6+
LET $datadir= `SELECT @@datadir`;
7+
8+
CREATE TABLE t1 (a SERIAL, b INT, c INT, d INT) ENGINE=InnoDB;
9+
INSERT INTO t1 () VALUES ();
810

911
--connect (con1,localhost,root,,test)
1012
SET DEBUG_SYNC='before_rename_table_commit SIGNAL renamed WAIT_FOR ever';
@@ -16,4 +18,37 @@ SET DEBUG_SYNC='now WAIT_FOR renamed';
1618
--source include/restart_mysqld.inc
1719
--disconnect con1
1820
SELECT * FROM t1;
21+
22+
let $c = 999;
23+
BEGIN;
24+
--disable_query_log
25+
while ($c) {
26+
INSERT INTO t1() VALUES();
27+
dec $c;
28+
}
29+
--enable_query_log
30+
COMMIT;
31+
UPDATE t1 SET b=a%7, c=a%11, d=a%13;
32+
33+
--source include/expect_crash.inc
34+
SET DEBUG_DBUG='+d,crash_commit_before';
35+
--error 2013
36+
ALTER TABLE t1
37+
ADD INDEX(b,c,d,a),ADD INDEX(b,c,a,d),ADD INDEX(b,a,c,d),ADD INDEX(b,a,d,c),
38+
ADD INDEX(b,d,a,c),ADD INDEX(b,d,c,a),ADD INDEX(a,b,c,d),ADD INDEX(a,b,d,c),
39+
ADD INDEX(a,c,b,d),ADD INDEX(a,c,d,b),ADD INDEX(a,d,b,c),ADD INDEX(a,d,c,b),
40+
ADD INDEX(c,a,b,d),ADD INDEX(c,a,d,b),ADD INDEX(c,b,a,d),ADD INDEX(c,b,d,a),
41+
ADD INDEX(c,d,a,b),ADD INDEX(c,d,b,a),ADD INDEX(d,a,b,c),ADD INDEX(d,a,c,b),
42+
ADD INDEX(d,b,a,c),ADD INDEX(d,b,c,a),ADD INDEX(d,c,a,b),ADD INDEX(d,c,b,a),
43+
ADD INDEX(a,b,c), ADD INDEX(a,c,b), ADD INDEX(a,c,d), ADD INDEX(a,d,c),
44+
ADD INDEX(a,b,d), ADD INDEX(a,d,b), ADD INDEX(b,c,d), ADD INDEX(b,d,c),
45+
ALGORITHM=COPY;
46+
--source include/start_mysqld.inc
47+
CHECK TABLE t1;
48+
SELECT COUNT(*) FROM t1;
1949
DROP TABLE t1;
50+
# MDEV-11415 TODO: remove the following
51+
SET GLOBAL innodb_background_drop_list_empty=
52+
@@GLOBAL.innodb_background_drop_list_empty;
53+
# Work around missing crash recovery at the SQL layer.
54+
--remove_files_wildcard $datadir/test #sql-*.frm

storage/innobase/row/row0mysql.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3712,7 +3712,7 @@ row_drop_table_for_mysql(
37123712

37133713
if (table->n_foreign_key_checks_running > 0) {
37143714
defer:
3715-
if (!strstr(table->name.m_name, "/" TEMP_FILE_PREFIX_INNODB)) {
3715+
if (!strstr(table->name.m_name, "/" TEMP_FILE_PREFIX)) {
37163716
heap = mem_heap_create(FN_REFLEN);
37173717
const char* tmp_name
37183718
= dict_mem_create_temporary_tablename(
@@ -4477,7 +4477,7 @@ row_rename_table_for_mysql(
44774477

44784478
goto funct_exit;
44794479

4480-
} else if (new_is_tmp) {
4480+
} else if (!old_is_tmp && new_is_tmp) {
44814481
/* MySQL is doing an ALTER TABLE command and it renames the
44824482
original table to a temporary table name. We want to preserve
44834483
the original foreign key constraint definitions despite the

0 commit comments

Comments
 (0)