diff options
author | Alexey Botchkov <holyfoot@askmonty.org> | 2022-01-22 06:59:40 +0400 |
---|---|---|
committer | Alexey Botchkov <holyfoot@askmonty.org> | 2022-01-22 18:46:56 +0400 |
commit | 5fe3919fe10e38a0fb03b68c1ffd0d370d3083f2 (patch) | |
tree | fcd0157fb01f12a25eada2a96f8cde383c251153 | |
parent | 2c16fd9bafa1945463dadc9c7bc8f7d455791d5a (diff) | |
download | mariadb-git-bb-10.2-hf-mdev-25917.tar.gz |
MDEV-25917 create table like fails if source table is partitioned and engine is myisam or aria with data directory.bb-10.2-hf-mdev-25917
Create table like removes data_file_path/index_file_path from the
thd->work_partition_info.
-rw-r--r-- | mysql-test/r/partition_symlink.result | 24 | ||||
-rw-r--r-- | mysql-test/t/partition_symlink.test | 21 | ||||
-rw-r--r-- | sql/sql_table.cc | 38 |
3 files changed, 83 insertions, 0 deletions
diff --git a/mysql-test/r/partition_symlink.result b/mysql-test/r/partition_symlink.result index 90048eb3438..5651772214b 100644 --- a/mysql-test/r/partition_symlink.result +++ b/mysql-test/r/partition_symlink.result @@ -177,3 +177,27 @@ partition by key (a) (partition p0, partition p1 DATA DIRECTORY 'part-data' INDEX DIRECTORY 'part-data'); Got one of the listed errors +# +# MDEV-25917 create table like fails if source table is partitioned and engine is myisam or aria with data directory. +# +CREATE TABLE t1 (a INT) +ENGINE = MyISAM +PARTITION BY LIST (a) +(PARTITION p0 VALUES IN (0) +DATA DIRECTORY 'MYSQLTEST_VARDIR/tmp' + INDEX DIRECTORY 'MYSQLTEST_VARDIR/tmp', +PARTITION p1 VALUES IN (1) +DATA DIRECTORY 'MYSQLTEST_VARDIR/tmp' + INDEX DIRECTORY 'MYSQLTEST_VARDIR/tmp', +PARTITION p2 VALUES IN (2)); +CREATE TABLE t2 LIKE t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 + PARTITION BY LIST (`a`) +(PARTITION `p0` VALUES IN (0) ENGINE = MyISAM, + PARTITION `p1` VALUES IN (1) ENGINE = MyISAM, + PARTITION `p2` VALUES IN (2) ENGINE = MyISAM) +DROP TABLE t1, t2; diff --git a/mysql-test/t/partition_symlink.test b/mysql-test/t/partition_symlink.test index 8f6e837299a..aec389fb5a6 100644 --- a/mysql-test/t/partition_symlink.test +++ b/mysql-test/t/partition_symlink.test @@ -220,3 +220,24 @@ ENGINE = MyISAM partition by key (a) (partition p0, partition p1 DATA DIRECTORY 'part-data' INDEX DIRECTORY 'part-data'); + +--echo # +--echo # MDEV-25917 create table like fails if source table is partitioned and engine is myisam or aria with data directory. +--echo # +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval CREATE TABLE t1 (a INT) +ENGINE = MyISAM +PARTITION BY LIST (a) +(PARTITION p0 VALUES IN (0) + DATA DIRECTORY '$MYSQLTEST_VARDIR/tmp' + INDEX DIRECTORY '$MYSQLTEST_VARDIR/tmp', + PARTITION p1 VALUES IN (1) + DATA DIRECTORY '$MYSQLTEST_VARDIR/tmp' + INDEX DIRECTORY '$MYSQLTEST_VARDIR/tmp', + PARTITION p2 VALUES IN (2)); + +CREATE TABLE t2 LIKE t1; +SHOW CREATE TABLE t2; + +DROP TABLE t1, t2; + diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 33daa15b9b7..354dd401a0f 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -5547,7 +5547,45 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, #ifdef WITH_PARTITION_STORAGE_ENGINE /* Partition info is not handled by mysql_prepare_alter_table() call. */ if (src_table->table->part_info) + { + List_iterator_fast <partition_element> + part_it(src_table->table->part_info->partitions); + partition_element *pe; + thd->work_part_info= src_table->table->part_info->get_clone(thd); + + /* + The CREATE TABLE LIKE should not inherit the DATA DIRECTORY + and INDEX DIRECTORY from the base table. + So we create clones for partitions and subpartitions just + to set these empty. + If they are empty already, we don't have to clone at all + but decided to do it always for sake of uniformity. + */ + thd->work_part_info->partitions.empty(); + while ((pe= part_it++)) + { + partition_element *pe_clone= new (thd->mem_root) partition_element(); + partition_element *sub_pe; + *pe_clone= *pe; + pe_clone->data_file_name= pe_clone->index_file_name= NULL; + if (thd->work_part_info->is_sub_partitioned()) + { + List_iterator<partition_element> sub_it(pe->subpartitions); + pe_clone->subpartitions.empty(); + while ((sub_pe= sub_it++)) + { + partition_element *sub_clone= + new (thd->mem_root) partition_element(); + + *sub_clone= *sub_pe; + sub_clone->data_file_name= sub_clone->index_file_name= NULL; + pe_clone->subpartitions.push_back(sub_clone, thd->mem_root); + } + } + thd->work_part_info->partitions.push_back(pe_clone, thd->mem_root); + } + } #endif /* |