diff options
author | Nayuta Yanagisawa <nayuta.yanagisawa@hey.com> | 2022-03-29 23:41:40 +0900 |
---|---|---|
committer | Nayuta Yanagisawa <nayuta.yanagisawa@hey.com> | 2022-04-08 16:49:10 +0900 |
commit | 27b5d814e2c851569a0d75e4217da4a552b79f25 (patch) | |
tree | 2bf9b71be287604ce968bfe32ca47cd48c49a5ea | |
parent | 5a8766a98059b93798aa34d6824c6e130727d552 (diff) | |
download | mariadb-git-27b5d814e2c851569a0d75e4217da4a552b79f25.tar.gz |
MDEV-27065 Partitioning tables with custom data directories moves data back to default directory
The partitioning engine does not support the table-level DATA/INDEX
DIRECTORY specification.
If one create a non-partitioned table with the DATA/INDEX DIRECTORY
option and then performs ALTER TABLE ... PARTITION BY on it, the
DATA/INDEX DIRECTORY specification of the old schema is ignored.
The behavior might be a bit surprising for users because the value
of a usual table option applies to all the partitions. Thus, we raise
a warning on such ALTER TABLE ... PARTITION BY.
-rw-r--r-- | mysql-test/suite/parts/inc/part_alter_values.inc | 37 | ||||
-rw-r--r-- | mysql-test/suite/parts/r/partition_alter_innodb.result | 13 | ||||
-rw-r--r-- | mysql-test/suite/parts/r/partition_alter_maria.result | 20 | ||||
-rw-r--r-- | mysql-test/suite/parts/r/partition_alter_myisam.result | 20 | ||||
-rw-r--r-- | sql/ha_partition.cc | 22 |
5 files changed, 108 insertions, 4 deletions
diff --git a/mysql-test/suite/parts/inc/part_alter_values.inc b/mysql-test/suite/parts/inc/part_alter_values.inc index ac69169a9ca..2f16476c78b 100644 --- a/mysql-test/suite/parts/inc/part_alter_values.inc +++ b/mysql-test/suite/parts/inc/part_alter_values.inc @@ -36,12 +36,43 @@ ALTER TABLE t1 REORGANIZE PARTITION p1 INTO ); DROP TABLE t1; -# -# MDEV-15456 Server crashes upon adding or dropping a partition in ALTER under LOCK TABLE after ER_SAME_NAME_PARTITION -# +--echo # +--echo # MDEV-15456 Server crashes upon adding or dropping a partition in ALTER under LOCK TABLE after ER_SAME_NAME_PARTITION +--echo # --eval create table t1 (i int) engine=$engine partition by range(i) (partition p0 values less than (10)) lock table t1 write; --error ER_SAME_NAME_PARTITION alter table t1 add partition (partition p0 values less than (20)); alter table t1 add partition (partition p1 values less than (20)) /* comment */; drop table t1; + +--echo # +--echo # MDEV-27065 Partitioning tables with custom data directories moves data back to default directory +--echo # + +--mkdir $MYSQLTEST_VARDIR/tmp/mdev_27065 + +--disable_query_log +--eval CREATE TABLE t1 (id INT) ENGINE=$engine DATA DIRECTORY='$MYSQLTEST_VARDIR/tmp/mdev_27065' +--enable_query_log +ALTER TABLE t1 PARTITION BY RANGE(id)( + PARTITION p0 VALUES LESS THAN (1000), + PARTITION p1 VALUES LESS THAN MAXVALUE +); +DROP TABLE t1; + +# InnoDB doesn't support INDEX DIRECTORY. +if (`SELECT IF('$engine' != 'InnoDB', 1, 0)`) +{ + --disable_query_log + --eval CREATE TABLE t2 (id INT) ENGINE=$engine INDEX DIRECTORY='$MYSQLTEST_VARDIR/tmp/mdev_27065' + --enable_query_log + ALTER TABLE t2 PARTITION BY RANGE(id)( + PARTITION p0 VALUES LESS THAN (1000), + PARTITION p1 VALUES LESS THAN MAXVALUE + ); + DROP TABLE t2; +} + +--remove_files_wildcard $MYSQLTEST_VARDIR/tmp/mdev_27065 * +--rmdir $MYSQLTEST_VARDIR/tmp/mdev_27065 diff --git a/mysql-test/suite/parts/r/partition_alter_innodb.result b/mysql-test/suite/parts/r/partition_alter_innodb.result index f3921a1db26..ae3caaa4981 100644 --- a/mysql-test/suite/parts/r/partition_alter_innodb.result +++ b/mysql-test/suite/parts/r/partition_alter_innodb.result @@ -42,9 +42,22 @@ PARTITION p3 VALUES IN (4,5,6) ); ERROR HY000: Syntax error: LIST PARTITIONING requires definition of VALUES IN for each partition DROP TABLE t1; +# +# MDEV-15456 Server crashes upon adding or dropping a partition in ALTER under LOCK TABLE after ER_SAME_NAME_PARTITION +# create table t1 (i int) engine=InnoDB partition by range(i) (partition p0 values less than (10)); lock table t1 write; alter table t1 add partition (partition p0 values less than (20)); ERROR HY000: Duplicate partition name p0 alter table t1 add partition (partition p1 values less than (20)) /* comment */; drop table t1; +# +# MDEV-27065 Partitioning tables with custom data directories moves data back to default directory +# +ALTER TABLE t1 PARTITION BY RANGE(id)( +PARTITION p0 VALUES LESS THAN (1000), +PARTITION p1 VALUES LESS THAN MAXVALUE +); +Warnings: +Warning 1618 <DATA DIRECTORY> table option of old schema is ignored +DROP TABLE t1; diff --git a/mysql-test/suite/parts/r/partition_alter_maria.result b/mysql-test/suite/parts/r/partition_alter_maria.result index 77f511d9b3b..358ffbdfbe7 100644 --- a/mysql-test/suite/parts/r/partition_alter_maria.result +++ b/mysql-test/suite/parts/r/partition_alter_maria.result @@ -69,9 +69,29 @@ PARTITION p3 VALUES IN (4,5,6) ); ERROR HY000: Syntax error: LIST PARTITIONING requires definition of VALUES IN for each partition DROP TABLE t1; +# +# MDEV-15456 Server crashes upon adding or dropping a partition in ALTER under LOCK TABLE after ER_SAME_NAME_PARTITION +# create table t1 (i int) engine=Aria partition by range(i) (partition p0 values less than (10)); lock table t1 write; alter table t1 add partition (partition p0 values less than (20)); ERROR HY000: Duplicate partition name p0 alter table t1 add partition (partition p1 values less than (20)) /* comment */; drop table t1; +# +# MDEV-27065 Partitioning tables with custom data directories moves data back to default directory +# +ALTER TABLE t1 PARTITION BY RANGE(id)( +PARTITION p0 VALUES LESS THAN (1000), +PARTITION p1 VALUES LESS THAN MAXVALUE +); +Warnings: +Warning 1618 <DATA DIRECTORY> table option of old schema is ignored +DROP TABLE t1; +ALTER TABLE t2 PARTITION BY RANGE(id)( +PARTITION p0 VALUES LESS THAN (1000), +PARTITION p1 VALUES LESS THAN MAXVALUE +); +Warnings: +Warning 1618 <INDEX DIRECTORY> table option of old schema is ignored +DROP TABLE t2; diff --git a/mysql-test/suite/parts/r/partition_alter_myisam.result b/mysql-test/suite/parts/r/partition_alter_myisam.result index ce3e04d6c97..9d76881fdfa 100644 --- a/mysql-test/suite/parts/r/partition_alter_myisam.result +++ b/mysql-test/suite/parts/r/partition_alter_myisam.result @@ -42,12 +42,32 @@ PARTITION p3 VALUES IN (4,5,6) ); ERROR HY000: Syntax error: LIST PARTITIONING requires definition of VALUES IN for each partition DROP TABLE t1; +# +# MDEV-15456 Server crashes upon adding or dropping a partition in ALTER under LOCK TABLE after ER_SAME_NAME_PARTITION +# create table t1 (i int) engine=MyISAM partition by range(i) (partition p0 values less than (10)); lock table t1 write; alter table t1 add partition (partition p0 values less than (20)); ERROR HY000: Duplicate partition name p0 alter table t1 add partition (partition p1 values less than (20)) /* comment */; drop table t1; +# +# MDEV-27065 Partitioning tables with custom data directories moves data back to default directory +# +ALTER TABLE t1 PARTITION BY RANGE(id)( +PARTITION p0 VALUES LESS THAN (1000), +PARTITION p1 VALUES LESS THAN MAXVALUE +); +Warnings: +Warning 1618 <DATA DIRECTORY> table option of old schema is ignored +DROP TABLE t1; +ALTER TABLE t2 PARTITION BY RANGE(id)( +PARTITION p0 VALUES LESS THAN (1000), +PARTITION p1 VALUES LESS THAN MAXVALUE +); +Warnings: +Warning 1618 <INDEX DIRECTORY> table option of old schema is ignored +DROP TABLE t2; create table t1 ( c1 int, c2 int, c3 varchar(100)) delay_key_write=1 partition by key(c1) ( partition p01 data directory = 'MYSQL_TMP_DIR' diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 4345f9eb9ca..3f9da331334 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -678,6 +678,7 @@ int ha_partition::create(const char *name, TABLE *table_arg, HA_CREATE_INFO *create_info) { int error; + THD *thd= ha_thd(); char name_buff[FN_REFLEN + 1], name_lc_buff[FN_REFLEN]; char *name_buffer_ptr; const char *path; @@ -695,8 +696,27 @@ int ha_partition::create(const char *name, TABLE *table_arg, my_error(ER_PARTITION_NO_TEMPORARY, MYF(0)); DBUG_RETURN(TRUE); } + /* + The following block should be removed once the table-level data directory + specification is supported by the partitioning engine (MDEV-28108). + */ + if (thd_sql_command(thd) == SQLCOM_ALTER_TABLE && create_info) + { + if (create_info->data_file_name) + { + push_warning_printf( + thd, Sql_condition::WARN_LEVEL_WARN, WARN_OPTION_IGNORED, + "<DATA DIRECTORY> table option of old schema is ignored"); + } + if (create_info->index_file_name) + { + push_warning_printf( + thd, Sql_condition::WARN_LEVEL_WARN, WARN_OPTION_IGNORED, + "<INDEX DIRECTORY> table option of old schema is ignored"); + } + } - if (get_from_handler_file(name, ha_thd()->mem_root, false)) + if (get_from_handler_file(name, thd->mem_root, false)) DBUG_RETURN(TRUE); DBUG_ASSERT(m_file_buffer); DBUG_PRINT("enter", ("name: (%s)", name)); |