Commit a72f34c0 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-12868 MySQL bug #84038 also affects MariaDB 10.2

Cherry-pick the commit from MySQL 5.7.19, and adapt the test case:

commit 45c933ac19c73a3e9c756a87ee1ba18ba1ac564c
Author: Aakanksha Verma <aakanksha.verma@oracle.com>
Date:   Tue Mar 21 10:31:43 2017 +0530

    Bug #25189192   ERRORS WHEN RESTARTING MYSQL AFTER RENAME TABLE.

    PROBLEM

    While renaming table innodb doesn't update the InnoDB Dictionary table
    INNODB_SYS_DATAFILES incase there is change in database while doing
    rename table. Hence on a restart the server log shows error that it
    couldnt find table with old path before rename which has actually been
    renamed. So the errors would only vanish if we update the system
    tablespace

    FIX

    Update the innodb dictionary table with new path in the case there is
    not a change in the table but the database holding the table as well.

    Reviewed-by: Jimmy Yang<Jimmy.Yang@oracle.com>
    RB: 15751
parent 067ee84d
CREATE DATABASE test_jfg;
CREATE DATABASE test_jfg2;
CREATE TABLE test_jfg.test (a int unsigned PRIMARY KEY) ENGINE=InnoDB;
RENAME TABLE test_jfg.test TO test_jfg2.test;
SELECT REPLACE(path,'\\','/') path
FROM INFORMATION_SCHEMA.INNODB_SYS_DATAFILES WHERE PATH LIKE '%test%';
path
./test_jfg2/test.ibd
DROP DATABASE test_jfg;
DROP DATABASE test_jfg2;
CREATE DATABASE abc_def;
CREATE DATABASE abc_def2;
CREATE TABLE abc_def.test (a int unsigned PRIMARY KEY) ENGINE=InnoDB;
RENAME TABLE abc_def.test TO abc_def2.test1;
SELECT REPLACE(path,'\\','/') path
FROM INFORMATION_SCHEMA.INNODB_SYS_DATAFILES WHERE PATH LIKE '%test%';
path
./abc_def2/test1.ibd
DROP DATABASE abc_def;
DROP DATABASE abc_def2;
--innodb
--innodb-sys-datafiles
--source include/have_innodb.inc
--source include/not_embedded.inc
CREATE DATABASE test_jfg;
CREATE DATABASE test_jfg2;
CREATE TABLE test_jfg.test (a int unsigned PRIMARY KEY) ENGINE=InnoDB;
RENAME TABLE test_jfg.test TO test_jfg2.test;
SELECT REPLACE(path,'\\','/') path
FROM INFORMATION_SCHEMA.INNODB_SYS_DATAFILES WHERE PATH LIKE '%test%';
DROP DATABASE test_jfg;
--source include/restart_mysqld.inc
DROP DATABASE test_jfg2;
CREATE DATABASE abc_def;
CREATE DATABASE abc_def2;
CREATE TABLE abc_def.test (a int unsigned PRIMARY KEY) ENGINE=InnoDB;
RENAME TABLE abc_def.test TO abc_def2.test1;
SELECT REPLACE(path,'\\','/') path
FROM INFORMATION_SCHEMA.INNODB_SYS_DATAFILES WHERE PATH LIKE '%test%';
DROP DATABASE abc_def;
--source include/restart_mysqld.inc
DROP DATABASE abc_def2;
......@@ -4595,6 +4595,15 @@ row_rename_table_for_mysql(
&& dict_table_is_file_per_table(table)) {
/* Make a new pathname to update SYS_DATAFILES. */
char* new_path = row_make_new_pathname(table, new_name);
char* old_path = fil_space_get_first_path(table->space);
/* If old path and new path are the same means tablename
has not changed and only the database name holding the table
has changed so we need to make the complete filepath again. */
if (!dict_tables_have_same_db(old_name, new_name)) {
ut_free(new_path);
new_path = fil_make_filepath(NULL, new_name, IBD, false);
}
info = pars_info_create();
......@@ -4614,6 +4623,7 @@ row_rename_table_for_mysql(
"END;\n"
, FALSE, trx);
ut_free(old_path);
ut_free(new_path);
}
if (err != DB_SUCCESS) {
......
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