From 732cd7fd5346885ae41293d7ebe44110188155d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 22 Sep 2020 11:13:51 +0300 Subject: [PATCH] MDEV-23705 Assertion 'table->data_dir_path || !space' After DISCARD TABLESPACE, the tablespace of a table will no longer exist, and dict_get_and_save_data_dir_path() would invoke dict_get_first_path() to read an entry from SYS_DATAFILES. For some reason, DISCARD TABLESPACE would not to remove the entry from there. dict_get_and_save_data_dir_path(): If the tablespace has been discarded, do not bother trying to read the name. Side note: The tables SYS_TABLESPACES and SYS_DATAFILES are redundant and subject to removal in MDEV-22343. --- mysql-test/suite/innodb/r/truncate.result | 11 +++++++++++ mysql-test/suite/innodb/t/truncate.test | 10 ++++++++++ storage/innobase/dict/dict0load.cc | 3 ++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/innodb/r/truncate.result b/mysql-test/suite/innodb/r/truncate.result index 5e9fd60d4fe..571aa2da1c5 100644 --- a/mysql-test/suite/innodb/r/truncate.result +++ b/mysql-test/suite/innodb/r/truncate.result @@ -39,3 +39,14 @@ TRUNCATE t1; SELECT * FROM t1; a DROP TEMPORARY TABLE t1; +# +# MDEV-23705 Assertion 'table->data_dir_path || !space' +# +CREATE TABLE t(c INT) ENGINE=InnoDB; +ALTER TABLE t DISCARD TABLESPACE; +RENAME TABLE t TO u; +TRUNCATE u; +Warnings: +Warning 1814 Tablespace has been discarded for table `u` +TRUNCATE u; +DROP TABLE u; diff --git a/mysql-test/suite/innodb/t/truncate.test b/mysql-test/suite/innodb/t/truncate.test index cd1d827e157..ca9ccb677e9 100644 --- a/mysql-test/suite/innodb/t/truncate.test +++ b/mysql-test/suite/innodb/t/truncate.test @@ -50,3 +50,13 @@ INSERT INTO t1 VALUES(1); TRUNCATE t1; SELECT * FROM t1; DROP TEMPORARY TABLE t1; + +--echo # +--echo # MDEV-23705 Assertion 'table->data_dir_path || !space' +--echo # +CREATE TABLE t(c INT) ENGINE=InnoDB; +ALTER TABLE t DISCARD TABLESPACE; +RENAME TABLE t TO u; +TRUNCATE u; +TRUNCATE u; +DROP TABLE u; diff --git a/storage/innobase/dict/dict0load.cc b/storage/innobase/dict/dict0load.cc index 4014d28c2fb..af14c6a4770 100644 --- a/storage/innobase/dict/dict0load.cc +++ b/storage/innobase/dict/dict0load.cc @@ -2739,7 +2739,8 @@ dict_get_and_save_data_dir_path( { ut_ad(!dict_table_is_temporary(table)); - if (!table->data_dir_path && table->space) { + if (!table->data_dir_path && table->space + && !dict_table_is_discarded(table)) { char* path = fil_space_get_first_path(table->space); if (!dict_mutex_own) {