Commit 656f66de authored by Marko Mäkelä's avatar Marko Mäkelä

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.
parent 04eef79b
CREATE TABLE t1 (a INT UNSIGNED PRIMARY KEY) ENGINE=InnoDB; CREATE TABLE t1 (a SERIAL, b INT, c INT, d INT) ENGINE=InnoDB;
INSERT INTO t1 VALUES(42); INSERT INTO t1 () VALUES ();
connect con1,localhost,root,,test; connect con1,localhost,root,,test;
SET DEBUG_SYNC='before_rename_table_commit SIGNAL renamed WAIT_FOR ever'; SET DEBUG_SYNC='before_rename_table_commit SIGNAL renamed WAIT_FOR ever';
RENAME TABLE t1 TO t2; RENAME TABLE t1 TO t2;
...@@ -7,6 +7,29 @@ connection default; ...@@ -7,6 +7,29 @@ connection default;
SET DEBUG_SYNC='now WAIT_FOR renamed'; SET DEBUG_SYNC='now WAIT_FOR renamed';
disconnect con1; disconnect con1;
SELECT * FROM t1; SELECT * FROM t1;
a a b c d
42 1 NULL NULL NULL
BEGIN;
COMMIT;
UPDATE t1 SET b=a%7, c=a%11, d=a%13;
SET DEBUG_DBUG='+d,crash_commit_before';
ALTER TABLE t1
ADD INDEX(b,c,d,a),ADD INDEX(b,c,a,d),ADD INDEX(b,a,c,d),ADD INDEX(b,a,d,c),
ADD INDEX(b,d,a,c),ADD INDEX(b,d,c,a),ADD INDEX(a,b,c,d),ADD INDEX(a,b,d,c),
ADD INDEX(a,c,b,d),ADD INDEX(a,c,d,b),ADD INDEX(a,d,b,c),ADD INDEX(a,d,c,b),
ADD INDEX(c,a,b,d),ADD INDEX(c,a,d,b),ADD INDEX(c,b,a,d),ADD INDEX(c,b,d,a),
ADD INDEX(c,d,a,b),ADD INDEX(c,d,b,a),ADD INDEX(d,a,b,c),ADD INDEX(d,a,c,b),
ADD INDEX(d,b,a,c),ADD INDEX(d,b,c,a),ADD INDEX(d,c,a,b),ADD INDEX(d,c,b,a),
ADD INDEX(a,b,c), ADD INDEX(a,c,b), ADD INDEX(a,c,d), ADD INDEX(a,d,c),
ADD INDEX(a,b,d), ADD INDEX(a,d,b), ADD INDEX(b,c,d), ADD INDEX(b,d,c),
ALGORITHM=COPY;
ERROR HY000: Lost connection to MySQL server during query
CHECK TABLE t1;
Table Op Msg_type Msg_text
test.t1 check status OK
SELECT COUNT(*) FROM t1;
COUNT(*)
1000
DROP TABLE t1; DROP TABLE t1;
SET GLOBAL innodb_background_drop_list_empty=
@@GLOBAL.innodb_background_drop_list_empty;
...@@ -3,8 +3,10 @@ ...@@ -3,8 +3,10 @@
--source include/have_debug_sync.inc --source include/have_debug_sync.inc
--source include/not_embedded.inc --source include/not_embedded.inc
CREATE TABLE t1 (a INT UNSIGNED PRIMARY KEY) ENGINE=InnoDB; LET $datadir= `SELECT @@datadir`;
INSERT INTO t1 VALUES(42);
CREATE TABLE t1 (a SERIAL, b INT, c INT, d INT) ENGINE=InnoDB;
INSERT INTO t1 () VALUES ();
--connect (con1,localhost,root,,test) --connect (con1,localhost,root,,test)
SET DEBUG_SYNC='before_rename_table_commit SIGNAL renamed WAIT_FOR ever'; SET DEBUG_SYNC='before_rename_table_commit SIGNAL renamed WAIT_FOR ever';
...@@ -16,4 +18,37 @@ SET DEBUG_SYNC='now WAIT_FOR renamed'; ...@@ -16,4 +18,37 @@ SET DEBUG_SYNC='now WAIT_FOR renamed';
--source include/restart_mysqld.inc --source include/restart_mysqld.inc
--disconnect con1 --disconnect con1
SELECT * FROM t1; SELECT * FROM t1;
let $c = 999;
BEGIN;
--disable_query_log
while ($c) {
INSERT INTO t1() VALUES();
dec $c;
}
--enable_query_log
COMMIT;
UPDATE t1 SET b=a%7, c=a%11, d=a%13;
--source include/expect_crash.inc
SET DEBUG_DBUG='+d,crash_commit_before';
--error 2013
ALTER TABLE t1
ADD INDEX(b,c,d,a),ADD INDEX(b,c,a,d),ADD INDEX(b,a,c,d),ADD INDEX(b,a,d,c),
ADD INDEX(b,d,a,c),ADD INDEX(b,d,c,a),ADD INDEX(a,b,c,d),ADD INDEX(a,b,d,c),
ADD INDEX(a,c,b,d),ADD INDEX(a,c,d,b),ADD INDEX(a,d,b,c),ADD INDEX(a,d,c,b),
ADD INDEX(c,a,b,d),ADD INDEX(c,a,d,b),ADD INDEX(c,b,a,d),ADD INDEX(c,b,d,a),
ADD INDEX(c,d,a,b),ADD INDEX(c,d,b,a),ADD INDEX(d,a,b,c),ADD INDEX(d,a,c,b),
ADD INDEX(d,b,a,c),ADD INDEX(d,b,c,a),ADD INDEX(d,c,a,b),ADD INDEX(d,c,b,a),
ADD INDEX(a,b,c), ADD INDEX(a,c,b), ADD INDEX(a,c,d), ADD INDEX(a,d,c),
ADD INDEX(a,b,d), ADD INDEX(a,d,b), ADD INDEX(b,c,d), ADD INDEX(b,d,c),
ALGORITHM=COPY;
--source include/start_mysqld.inc
CHECK TABLE t1;
SELECT COUNT(*) FROM t1;
DROP TABLE t1; DROP TABLE t1;
# MDEV-11415 TODO: remove the following
SET GLOBAL innodb_background_drop_list_empty=
@@GLOBAL.innodb_background_drop_list_empty;
# Work around missing crash recovery at the SQL layer.
--remove_files_wildcard $datadir/test #sql-*.frm
...@@ -3712,7 +3712,7 @@ row_drop_table_for_mysql( ...@@ -3712,7 +3712,7 @@ row_drop_table_for_mysql(
if (table->n_foreign_key_checks_running > 0) { if (table->n_foreign_key_checks_running > 0) {
defer: defer:
if (!strstr(table->name.m_name, "/" TEMP_FILE_PREFIX_INNODB)) { if (!strstr(table->name.m_name, "/" TEMP_FILE_PREFIX)) {
heap = mem_heap_create(FN_REFLEN); heap = mem_heap_create(FN_REFLEN);
const char* tmp_name const char* tmp_name
= dict_mem_create_temporary_tablename( = dict_mem_create_temporary_tablename(
...@@ -4477,7 +4477,7 @@ row_rename_table_for_mysql( ...@@ -4477,7 +4477,7 @@ row_rename_table_for_mysql(
goto funct_exit; goto funct_exit;
} else if (new_is_tmp) { } else if (!old_is_tmp && new_is_tmp) {
/* MySQL is doing an ALTER TABLE command and it renames the /* MySQL is doing an ALTER TABLE command and it renames the
original table to a temporary table name. We want to preserve original table to a temporary table name. We want to preserve
the original foreign key constraint definitions despite the the original foreign key constraint definitions despite the
......
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