diff options
Diffstat (limited to 'mysql-test/suite/parts/inc')
98 files changed, 12500 insertions, 0 deletions
diff --git a/mysql-test/suite/parts/inc/engines.combinations b/mysql-test/suite/parts/inc/engines.combinations new file mode 100644 index 00000000..17e01265 --- /dev/null +++ b/mysql-test/suite/parts/inc/engines.combinations @@ -0,0 +1,8 @@ +[innodb] +default-storage-engine=innodb + +[myisam] +default-storage-engine=myisam + +[aria] +default-storage-engine=aria diff --git a/mysql-test/suite/parts/inc/engines.inc b/mysql-test/suite/parts/inc/engines.inc new file mode 100644 index 00000000..b8995ef0 --- /dev/null +++ b/mysql-test/suite/parts/inc/engines.inc @@ -0,0 +1,4 @@ +--source include/have_innodb.inc + +let $engine= `select @@default_storage_engine`; + diff --git a/mysql-test/suite/parts/inc/methods1.inc b/mysql-test/suite/parts/inc/methods1.inc new file mode 100644 index 00000000..d986b67a --- /dev/null +++ b/mysql-test/suite/parts/inc/methods1.inc @@ -0,0 +1,205 @@ +################################################################################ +# inc/partition_methods1.inc # +# # +# Purpose: # +# Create and check partitioned tables # +# The partitioning function use the column f_int1 # +# # +# For all partitioning methods # +# PARTITION BY HASH/KEY/LIST/RANGE # +# PARTITION BY RANGE/LIST ... SUBPARTITION BY HASH/KEY ... # +# do # +# 1. Create the partitioned table # +# 2 Insert the content of the table t0_template into t1 # +# 3. Execute inc/partition_check.inc # +# 4. Drop the table t1 # +# done # +# # +# The parameter # +# $unique -- PRIMARY KEY or UNIQUE INDEXes to be created within the # +# CREATE TABLE STATEMENT # +# has to be set before sourcing this routine. # +# Example: # +# let $unique= , UNIQUE INDEX uidx1 (f_int1); # +# inc/partition_method1s.inc # +# # +# Attention: The routine inc/partition_methods2.inc is very similar # +# to this one. So if something has to be changed here it # +# might be necessary to do it also there # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-03-05 # +# Change Author: # +# Change Date: # +# Change: # +################################################################################ + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +let $partitioning= ; +#----------- PARTITION BY HASH +if ($with_partitioning) +{ +let $partitioning= PARTITION BY HASH(f_int1) PARTITIONS 2; +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; + +#----------- PARTITION BY KEY +if ($with_partitioning) +{ +let $partitioning= PARTITION BY KEY(f_int1) PARTITIONS 5; +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; + +#----------- PARTITION BY LIST +if ($with_partitioning) +{ +let $partitioning= PARTITION BY LIST(MOD(f_int1,4)) +(PARTITION part_3 VALUES IN (-3), + PARTITION part_2 VALUES IN (-2), + PARTITION part_1 VALUES IN (-1), + PARTITION part_N VALUES IN (NULL), + PARTITION part0 VALUES IN (0), + PARTITION part1 VALUES IN (1), + PARTITION part2 VALUES IN (2), + PARTITION part3 VALUES IN (3)); +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; + +#----------- PARTITION BY RANGE +if ($with_partitioning) +{ +--disable_query_log +eval SET @aux = 'PARTITION BY RANGE(f_int1) +(PARTITION parta VALUES LESS THAN (0), +PARTITION partb VALUES LESS THAN ($max_row_div4), +PARTITION partc VALUES LESS THAN ($max_row_div2), +PARTITION partd VALUES LESS THAN ($max_row_div2 + $max_row_div4), +PARTITION parte VALUES LESS THAN ($max_row), +PARTITION partf VALUES LESS THAN $MAX_VALUE)'; +let $partitioning= `SELECT @aux`; +--enable_query_log +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; + +#----------- PARTITION BY RANGE -- SUBPARTITION BY HASH +if ($with_partitioning) +{ +--disable_query_log +eval SET @aux = +'PARTITION BY RANGE(f_int1 DIV 2) SUBPARTITION BY HASH(f_int1) SUBPARTITIONS 2 +(PARTITION parta VALUES LESS THAN (0), +PARTITION partb VALUES LESS THAN ($max_row_div4), +PARTITION partc VALUES LESS THAN ($max_row_div2), +PARTITION partd VALUES LESS THAN $MAX_VALUE)'; +let $partitioning= `SELECT @aux`; +--enable_query_log +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; + +#----------- PARTITION BY RANGE -- SUBPARTITION BY KEY +if ($with_partitioning) +{ +--disable_query_log +eval SET @aux = 'PARTITION BY RANGE(f_int1) SUBPARTITION BY KEY(f_int1) +(PARTITION part1 VALUES LESS THAN (0) +(SUBPARTITION subpart11, SUBPARTITION subpart12), +PARTITION part2 VALUES LESS THAN ($max_row_div4) +(SUBPARTITION subpart21, SUBPARTITION subpart22), +PARTITION part3 VALUES LESS THAN ($max_row_div2) +(SUBPARTITION subpart31, SUBPARTITION subpart32), +PARTITION part4 VALUES LESS THAN $MAX_VALUE +(SUBPARTITION subpart41, SUBPARTITION subpart42))'; +let $partitioning= `SELECT @aux`; +--enable_query_log +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; + +#----------- PARTITION BY LIST -- SUBPARTITION BY HASH +if ($with_partitioning) +{ +let $partitioning= PARTITION BY LIST(ABS(MOD(f_int1,3))) SUBPARTITION BY HASH(f_int1 + 1) +(PARTITION part1 VALUES IN (0) + (SUBPARTITION sp11, SUBPARTITION sp12), + PARTITION part2 VALUES IN (1) + (SUBPARTITION sp21, SUBPARTITION sp22), + PARTITION part3 VALUES IN (2) + (SUBPARTITION sp31, SUBPARTITION sp32), + PARTITION part4 VALUES IN (NULL) + (SUBPARTITION sp41, SUBPARTITION sp42)); +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; + +#----------- PARTITION BY LIST -- SUBPARTITION BY KEY +if ($with_partitioning) +{ +--disable_query_log +eval SET @aux = +'PARTITION BY LIST(ABS(MOD(f_int1,2))) +SUBPARTITION BY KEY(f_int1) SUBPARTITIONS $sub_part_no +(PARTITION part1 VALUES IN (0), + PARTITION part2 VALUES IN (1), + PARTITION part3 VALUES IN (NULL))'; +let $partitioning= `SELECT @aux`; +--enable_query_log +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; diff --git a/mysql-test/suite/parts/inc/part_alter_values.inc b/mysql-test/suite/parts/inc/part_alter_values.inc new file mode 100644 index 00000000..d3b63a46 --- /dev/null +++ b/mysql-test/suite/parts/inc/part_alter_values.inc @@ -0,0 +1,88 @@ +--source include/have_symlink.inc + +--echo # +--echo # MDEV-14641 Incompatible key or row definition between the MariaDB .frm file and the information in the storage engine +--echo # + +--eval CREATE TABLE t1 (i INT) ENGINE=$engine PARTITION BY LIST(i) (PARTITION p0 VALUES IN (1), PARTITION p1 VALUES IN (2)); +ALTER TABLE t1 ROW_FORMAT=COMPRESSED; +ALTER TABLE t1 DROP PARTITION p1; +SELECT * FROM t1; + +# Cleanup +DROP TABLE t1; + + +--echo # +--echo # MDEV-13788 Server crash when issuing bad SQL partition syntax +--echo # + +--eval CREATE TABLE t1 (id int, d date) ENGINE=$engine PARTITION BY RANGE COLUMNS(d) (PARTITION p1 VALUES LESS THAN (MAXVALUE)) +SHOW CREATE TABLE t1; +--error ER_PARTITION_REQUIRES_VALUES_ERROR +ALTER TABLE t1 REORGANIZE PARTITION p1 INTO +( + PARTITION p2, /* Notice no values */ + PARTITION p3 VALUES LESS THAN (MAXVALUE) +); +DROP TABLE t1; + + +--eval CREATE TABLE t1 (id int, d date) ENGINE=$engine PARTITION BY LIST (id) (PARTITION p1 VALUES IN (1,2,3)) +SHOW CREATE TABLE t1; +--error ER_PARTITION_REQUIRES_VALUES_ERROR +ALTER TABLE t1 REORGANIZE PARTITION p1 INTO +( + PARTITION p2, /* Notice no values */ + PARTITION p3 VALUES IN (4,5,6) +); +DROP TABLE t1; + +--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 + +--echo # +--echo # MDEV-26127 Assertion `err != DB_DUPLICATE_KEY' failed or InnoDB: Failing assertion: id != 0 on ALTER ... REBUILD PARTITION +--echo # +--eval CREATE TABLE t1 (c INT) ENGINE=$engine PARTITION BY KEY(c) PARTITIONS 4; +LOCK TABLES t1 WRITE, t1 AS a READ; +ALTER TABLE t1 REBUILD PARTITION p0; +DROP TABLE t1; diff --git a/mysql-test/suite/parts/inc/part_blocked_sql_funcs_main.inc b/mysql-test/suite/parts/inc/part_blocked_sql_funcs_main.inc new file mode 100644 index 00000000..be02e4e0 --- /dev/null +++ b/mysql-test/suite/parts/inc/part_blocked_sql_funcs_main.inc @@ -0,0 +1,261 @@ +################################################################################ +# t/partition_blocked_sql_funcs_main.inc # +# # +# Purpose: # +# Tests around sql functions # +# # +# # +#------------------------------------------------------------------------------# +# Original Author: HH # +# Original Date: 2006-11-22 # +# Change Author: # +# Change Date: # +# Change: # +################################################################################ + +--echo ------------------------------------------------------------------------- +--echo --- All SQL functions should be rejected, otherwise BUG (see 18198) +--echo ------------------------------------------------------------------------- + +let $sqlfunc = ascii(col1); +let $valsqlfunc = ascii('a'); +let $coltype = char(30); +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = ord(col1); +let $valsqlfunc = ord('a'); +let $coltype = char(30); +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = greatest(col1,15); +let $valsqlfunc = greatest(1,15); +let $coltype = int; +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = isnull(col1); +let $valsqlfunc = isnull(15); +let $coltype = int; +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = least(col1,15); +let $valsqlfunc = least(15,30); +let $coltype = int; +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = case when col1>15 then 20 else 10 end; +let $valsqlfunc = case when 1>30 then 20 else 15 end; +let $coltype = int; +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = ifnull(col1,30); +let $valsqlfunc = ifnull(1,30); +let $coltype = int; +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = nullif(col1,30); +let $valsqlfunc = nullif(1,30); +let $coltype = int; +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = bit_length(col1); +let $valsqlfunc = bit_length(255); +let $coltype = int; +--source suite/parts/inc/partition_blocked_sql_funcs.inc +let $coltype = char(30); +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = char_length(col1); +let $valsqlfunc = char_length('a'); +#let $coltype = int; +#--source suite/parts/inc/partition_blocked_sql_funcs.inc +let $coltype = char(30); +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = character_length(col1); +let $valsqlfunc = character_length('a'); +let $coltype = char(30) +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = find_in_set(col1,'1,2,3,4,5,6,7,8,9'); +let $valsqlfunc = find_in_set('i','a,b,c,d,e,f,g,h,i'); +let $coltype = int; +--source suite/parts/inc/partition_blocked_sql_funcs.inc +let $coltype = char(30); +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = instr(col1,'acb'); +let $valsqlfunc = instr('i','a,b,c,d,e,f,g,h,i'); +let $coltype = int; +--source suite/parts/inc/partition_blocked_sql_funcs.inc +let $coltype = char(30); +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = length(col1); +let $valsqlfunc = length('a,b,c,d,e,f,g,h,i'); +let $coltype = int; +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = locate('a',col1); +let $valsqlfunc = locate('i','a,b,c,d,e,f,g,h,i'); +let $coltype = int; +--source suite/parts/inc/partition_blocked_sql_funcs.inc +let $coltype = char(30); +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = octet_length(col1); +let $valsqlfunc = octet_length('a,b,c,d,e,f,g,h,i'); +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = position('a' in col1); +let $valsqlfunc = position('i' in 'a,b,c,d,e,f,g,h,i'); +let $coltype = int; +--source suite/parts/inc/partition_blocked_sql_funcs.inc +let $coltype = char(30); +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = strcmp(col1,'acb'); +let $valsqlfunc = strcmp('i','a,b,c,d,e,f,g,h,i'); +let $coltype = int; +--source suite/parts/inc/partition_blocked_sql_funcs.inc +let $coltype = char(30); +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = crc32(col1); +let $valsqlfunc = crc32('a,b,c,d,e,f,g,h,i'); +let $coltype = char(30); +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = round(col1); +let $valsqlfunc = round(15); +let $coltype = int; +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = sign(col1); +let $valsqlfunc = sign(123); +let $coltype = int; +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = period_add(col1,5); +let $valsqlfunc = period_add(9804,5); +let $coltype = datetime; +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = period_diff(col1,col2); +let $valsqlfunc = period_diff(9809,199907); +let $coltype = datetime,col2 datetime; +--source suite/parts/inc/partition_blocked_sql_funcs.inc +let $coltype = int,col2 int; +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = timestampdiff(day,5,col1); +let $valsqlfunc = timestampdiff(YEAR,'2002-05-01','2001-01-01'); +let $coltype = datetime; +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +################################################################################ +# After the fix for bug #42849 the server behavior does not fit into this test's +# architecture: for UNIX_TIMESTAMP() some of the queries in +# suite/parts/inc/partition_blocked_sql_funcs.inc will fail with a different +# error (ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR) and some will succeed where +################################################################################ +#let $sqlfunc = unix_timestamp(col1); +#let $valsqlfunc = unix_timestamp ('2002-05-01'); +#let $coltype = date; +#--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = week(col1); +let $valsqlfunc = week('2002-05-01'); +let $coltype = datetime; +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = weekofyear(col1); +let $valsqlfunc = weekofyear('2002-05-01'); +let $coltype = datetime; +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = cast(col1 as signed); +let $valsqlfunc = cast(123 as signed); +let $coltype = varchar(30); +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = convert(col1,unsigned); +let $valsqlfunc = convert(123,unsigned); +let $coltype = varchar(30); +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = col1 | 20; +let $valsqlfunc = 10 | 20; +let $coltype = int; +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = col1 & 20; +let $valsqlfunc = 10 & 20; +let $coltype = int; +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = col1 ^ 20; +let $valsqlfunc = 10 ^ 20; +let $coltype = int; +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = col1 << 20; +let $valsqlfunc = 10 << 20; +let $coltype = int; +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = col1 >> 20; +let $valsqlfunc = 10 >> 20; +let $coltype = int; +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = ~col1; +let $valsqlfunc = ~20; +let $coltype = int; +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = bit_count(col1); +let $valsqlfunc = bit_count(20); +let $coltype = int; +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +let $sqlfunc = inet_aton(col1); +let $valsqlfunc = inet_aton('192.168.1.1'); +let $coltype = int; +--source suite/parts/inc/partition_blocked_sql_funcs.inc + +set @var =20; +let $sqlfunc = bit_length(col1)+@var-@var; +let $valsqlfunc = bit_length(20)+@var-@var; +let $coltype = int; +--source suite/parts/inc/partition_blocked_sql_funcs.inc + + +delimiter //; +create function getmaxsigned_t1(col int) returns int +begin + declare done int default 0; + declare v4 int; + declare max int; + declare cur1 cursor for + select col from t1; + declare continue handler for sqlstate '01000' set done = 1; + declare continue handler for sqlstate '02000' set done = 1; + open cur1; + set max = 0; + fetch cur1 into v4; + wl_loop: WHILE NOT done DO + fetch cur1 into v4; + IF v4 > max + then set max = v4; + END IF; + END WHILE wl_loop; + close cur1; + return max; + end// +delimiter ;// + +let $sqlfunc = getmaxsigned_t1(col1); +let $valsqlfunc = getmaxsigned(10); +let $coltype = int; +--source suite/parts/inc/partition_blocked_sql_funcs.inc +drop function if exists getmaxsigned_t1; diff --git a/mysql-test/suite/parts/inc/part_exch_drop_tabs.inc b/mysql-test/suite/parts/inc/part_exch_drop_tabs.inc new file mode 100644 index 00000000..7d6441b1 --- /dev/null +++ b/mysql-test/suite/parts/inc/part_exch_drop_tabs.inc @@ -0,0 +1,12 @@ +DROP TABLE IF EXISTS t_10; +DROP TABLE IF EXISTS t_100; +DROP TABLE IF EXISTS t_1000; +DROP TABLE IF EXISTS tp; +DROP TABLE IF EXISTS tsp; +DROP TABLE IF EXISTS tsp_00; +DROP TABLE IF EXISTS tsp_01; +DROP TABLE IF EXISTS tsp_02; +DROP TABLE IF EXISTS tsp_03; +DROP TABLE IF EXISTS tsp_04; +DROP TABLE IF EXISTS t_empty; +DROP TABLE IF EXISTS t_null; diff --git a/mysql-test/suite/parts/inc/part_exch_qa.inc b/mysql-test/suite/parts/inc/part_exch_qa.inc new file mode 100644 index 00000000..1f5329a5 --- /dev/null +++ b/mysql-test/suite/parts/inc/part_exch_qa.inc @@ -0,0 +1,148 @@ +use test; + +--disable_result_log +--disable_query_log +--source suite/parts/inc/part_exch_tabs.inc +--enable_result_log +--enable_query_log + +--sorted_result +SELECT * FROM t_10; +--sorted_result +SELECT * FROM t_100; +--sorted_result +SELECT * FROM t_1000; +--sorted_result +SELECT * FROM tp; +--sorted_result +SELECT * FROM tsp; +--sorted_result +SELECT * FROM tsp_00; +--sorted_result +SELECT * FROM tsp_01; +--sorted_result +SELECT * FROM tsp_02; +--sorted_result +SELECT * FROM tsp_03; +--sorted_result +SELECT * FROM tsp_04; + +# 1) Valid exchange with partitions. +# exchange of values < 10 of tp to t and complete contents of t to p0 and back. +ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10; +--sorted_result +SELECT * FROM t_10; +--sorted_result +SELECT * FROM tp WHERE a BETWEEN 0 AND 10; +# Back to the former contents. +ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10; +--sorted_result +SELECT * FROM t_10; +--sorted_result +SELECT * FROM tp WHERE a BETWEEN 0 AND 10; + +# Exchange with empty table. +ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_empty; +--sorted_result +SELECT * FROM t_empty; +--sorted_result +SELECT * FROM tp WHERE a BETWEEN 0 AND 10; +# Back to the former contents. +ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_empty; +--sorted_result +SELECT * FROM t_empty; +--sorted_result +SELECT * FROM tp WHERE a BETWEEN 0 AND 10; + +# Exchange with null table. +ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_null; +--sorted_result +SELECT * FROM t_null; +--sorted_result +SELECT * FROM tp WHERE a BETWEEN 0 AND 10; +# Back to the former contents. +ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_null; +--sorted_result +SELECT * FROM t_null; +--sorted_result +SELECT * FROM tp WHERE a BETWEEN 0 AND 10; + +# exchange of values < 100 of tp to t and complete contents of t to p1 and back. +ALTER TABLE tp EXCHANGE PARTITION p1 WITH TABLE t_100; +--sorted_result +SELECT * FROM t_100; +--sorted_result +SELECT * FROM tp WHERE a BETWEEN 10 AND 100; +# Back to the former contents. +ALTER TABLE tp EXCHANGE PARTITION p1 WITH TABLE t_100; +--sorted_result +SELECT * FROM t_100; +--sorted_result +SELECT * FROM tp WHERE a BETWEEN 10 AND 100; + +# exchange of values < 1000 of tp to t and complete contents of t to p2 and back. +ALTER TABLE tp EXCHANGE PARTITION p2 WITH TABLE t_1000; +--sorted_result +SELECT * FROM t_1000; +--sorted_result +SELECT * FROM tp WHERE a BETWEEN 100 AND 1000; +# Back to the former contents. +ALTER TABLE tp EXCHANGE PARTITION p2 WITH TABLE t_1000; +--sorted_result +SELECT * FROM t_1000; +--sorted_result +SELECT * FROM tp WHERE a BETWEEN 100 AND 1000; + +# 2) Valid exchange of subpartitions. +# exchange of values < 10 of tsp to t and complete contents of t to p0 and back. +ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00; +ALTER TABLE tsp EXCHANGE PARTITION sp01 WITH TABLE tsp_01; +ALTER TABLE tsp EXCHANGE PARTITION sp02 WITH TABLE tsp_02; +ALTER TABLE tsp EXCHANGE PARTITION sp03 WITH TABLE tsp_03; +ALTER TABLE tsp EXCHANGE PARTITION sp04 WITH TABLE tsp_04; +--sorted_result +SELECT * FROM tsp_00; +--sorted_result +SELECT * FROM tsp_01; +--sorted_result +SELECT * FROM tsp_02; +--sorted_result +SELECT * FROM tsp_03; +--sorted_result +SELECT * FROM tsp_04; +--sorted_result +SELECT * FROM tsp WHERE a BETWEEN 0 AND 10; +# Back to the former contents. +ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00; +ALTER TABLE tsp EXCHANGE PARTITION sp01 WITH TABLE tsp_01; +ALTER TABLE tsp EXCHANGE PARTITION sp02 WITH TABLE tsp_02; +ALTER TABLE tsp EXCHANGE PARTITION sp03 WITH TABLE tsp_03; +ALTER TABLE tsp EXCHANGE PARTITION sp04 WITH TABLE tsp_04; +--sorted_result +SELECT * FROM tsp_00; +--sorted_result +SELECT * FROM tsp_01; +--sorted_result +SELECT * FROM tsp_02; +--sorted_result +SELECT * FROM tsp_03; +--sorted_result +SELECT * FROM tsp_04; +--sorted_result +SELECT * FROM tsp WHERE a BETWEEN 0 AND 10; + +# Exchange with null table. +ALTER TABLE tsp EXCHANGE PARTITION sp01 WITH TABLE t_null; +--sorted_result +SELECT * FROM t_null; +--sorted_result +SELECT * FROM tsp WHERE a BETWEEN 0 AND 10; +# Back to the former contents. +ALTER TABLE tsp EXCHANGE PARTITION sp01 WITH TABLE t_null; +--sorted_result +SELECT * FROM t_null; +--sorted_result +SELECT * FROM tsp WHERE a BETWEEN 0 AND 10; + +--source suite/parts/inc/part_exch_drop_tabs.inc + diff --git a/mysql-test/suite/parts/inc/part_exch_qa_1.inc b/mysql-test/suite/parts/inc/part_exch_qa_1.inc new file mode 100644 index 00000000..d790f29a --- /dev/null +++ b/mysql-test/suite/parts/inc/part_exch_qa_1.inc @@ -0,0 +1,62 @@ +use test; + +--disable_result_log +--disable_query_log +--source suite/parts/inc/part_exch_tabs.inc +--enable_result_log +--enable_query_log + +--sorted_result +SELECT * FROM t_10; +--sorted_result +SELECT * FROM t_100; +--sorted_result +SELECT * FROM t_1000; +--sorted_result +SELECT * FROM tp; +--sorted_result +SELECT * FROM tsp; +--sorted_result +SELECT * FROM tsp_00; +--sorted_result +SELECT * FROM tsp_01; +--sorted_result +SELECT * FROM tsp_02; +--sorted_result +SELECT * FROM tsp_03; +--sorted_result +SELECT * FROM tsp_04; + +# 13) Exchanges with indexes. +# IGNORE was removed in bug#57708. +CREATE INDEX id_t_10_b USING BTREE ON t_10 (b); +--error ER_TABLES_DIFFERENT_METADATA +ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10; +#--error ER_TABLES_DIFFERENT_METADATA +#ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10 IGNORE; +CREATE INDEX id_tp_b USING BTREE ON tp (b); +--error ER_TABLES_DIFFERENT_METADATA +ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10; +#--error ER_TABLES_DIFFERENT_METADATA +#ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10 IGNORE; +DROP INDEX id_t_10_b ON t_10; +DROP INDEX id_tp_b ON tp; +ALTER TABLE t_10 ADD UNIQUE INDEX USING BTREE (a); +--error ER_TABLES_DIFFERENT_METADATA +ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10; +#--error ER_TABLES_DIFFERENT_METADATA +#ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10 IGNORE; +ALTER TABLE tp ADD UNIQUE INDEX USING BTREE (a); +ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10; +show create table t_10; +show create table tp ; +ALTER TABLE tp DROP INDEX a; +ALTER TABLE t_10 DROP INDEX a; +ALTER TABLE tp ADD UNIQUE INDEX USING BTREE (a,b); +ALTER TABLE t_10 ADD UNIQUE INDEX USING BTREE (a,b); +ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10; +show create table t_10; +show create table tp ; + +--source suite/parts/inc/part_exch_drop_tabs.inc + diff --git a/mysql-test/suite/parts/inc/part_exch_qa_13.inc b/mysql-test/suite/parts/inc/part_exch_qa_13.inc new file mode 100644 index 00000000..aba75d22 --- /dev/null +++ b/mysql-test/suite/parts/inc/part_exch_qa_13.inc @@ -0,0 +1,202 @@ +# Author: Horst Hunger +# Created: 2010-07-13 + +use test; + +--disable_result_log +--disable_query_log +--disable_warnings +DROP TABLE IF EXISTS t_10; +DROP TABLE IF EXISTS t_100; +DROP TABLE IF EXISTS t_1000; +DROP TABLE IF EXISTS tp; +DROP TABLE IF EXISTS tsp; +DROP TABLE IF EXISTS t_empty; +DROP TABLE IF EXISTS t_null; +--enable_warnings + +eval CREATE TABLE t_10 (a INT, b VARCHAR(55), PRIMARY KEY (a)) +CHECKSUM= 1, +ENGINE = $engine_table; + +eval CREATE TABLE t_100 (a INT, b VARCHAR(55), PRIMARY KEY (a)) +COMMENT= 'comment', +ENGINE = $engine_table; + +eval CREATE TABLE t_1000 (a INT, b VARCHAR(55), PRIMARY KEY (a)) +MIN_ROWS= 1, +MAX_ROWS= 2000, +ENGINE = $engine_table; + +eval CREATE TABLE t_empty (a INT, b VARCHAR(55), PRIMARY KEY (a)) +ENGINE = $engine_table; + +eval CREATE TABLE t_null (a INT, b VARCHAR(55), PRIMARY KEY (a)) +ENGINE = $engine_table; + +eval CREATE TABLE tp (a INT, b VARCHAR(55), PRIMARY KEY (a)) +CHECKSUM= 1, +ENGINE = $engine_part +PARTITION BY RANGE (a) +(PARTITION p0 VALUES LESS THAN (10), + PARTITION p1 VALUES LESS THAN (100), + PARTITION p2 VALUES LESS THAN (1000)); + +eval CREATE TABLE tp1 (a INT, b VARCHAR(55), PRIMARY KEY (a)) +ENGINE = $engine_part +PARTITION BY RANGE (a) +(PARTITION p0 VALUES LESS THAN (10) MAX_ROWS=2000 MIN_ROWS=1, + PARTITION p1 VALUES LESS THAN (100) MAX_ROWS=2000 MIN_ROWS=1, + PARTITION p2 VALUES LESS THAN (1000) MAX_ROWS=2000 MIN_ROWS=1 +); + +eval CREATE TABLE tsp (a INT, + b VARCHAR(55), + PRIMARY KEY (a)) +COMMENT= 'comment', +ENGINE = $engine_subpart +PARTITION BY RANGE (a) +SUBPARTITION BY HASH(a) +(PARTITION p0 VALUES LESS THAN (10) + (SUBPARTITION sp00 MAX_ROWS=2000 MIN_ROWS=1, + SUBPARTITION sp01 MAX_ROWS=2000 MIN_ROWS=1, + SUBPARTITION sp02 MAX_ROWS=2000 MIN_ROWS=1, + SUBPARTITION sp03 MAX_ROWS=2000 MIN_ROWS=1, + SUBPARTITION sp04 MAX_ROWS=2000 MIN_ROWS=1), + PARTITION p1 VALUES LESS THAN (100) + (SUBPARTITION sp10, + SUBPARTITION sp11, + SUBPARTITION sp12, + SUBPARTITION sp13, + SUBPARTITION sp14), + PARTITION p2 VALUES LESS THAN (1000) + (SUBPARTITION sp20, + SUBPARTITION sp21, + SUBPARTITION sp22, + SUBPARTITION sp23, + SUBPARTITION sp24)); + +# Values t_10 (not partitioned) +INSERT INTO t_10 VALUES (1, "One"), (3, "Three"), (5, "Five"), (9, "Nine"); + +# Values t_100 (not partitioned) +INSERT INTO t_100 VALUES (11, "Eleven"), (13, "Thirdteen"), (15, "Fifeteen"), (19, "Nineteen"); +INSERT INTO t_100 VALUES (91, "Ninety-one"), (93, "Ninety-three"), (95, "Ninety-five"), (99, "Ninety-nine"); + +# Values t_1000 (not partitioned) +INSERT INTO t_1000 VALUES (111, "Hundred elven"), (113, "Hundred thirdteen"), (115, "Hundred fiveteen"), (119, "Hundred nineteen"); +INSERT INTO t_1000 VALUES (131, "Hundred thirty-one"), (133, "Hundred thirty-three"), (135, "Hundred thirty-five"), (139, "Hundred thirty-nine"); +INSERT INTO t_1000 VALUES (151, "Hundred fifty-one"), (153, "Hundred fifty-three"), (155, "Hundred fity-five"), (159, "Hundred fifty-nine"); +INSERT INTO t_1000 VALUES (191, "Hundred ninety-one"), (193, "Hundred ninety-three"), (195, "Hundred ninety-five"), (199, "Hundred ninety-nine"); + +# Values t_null (not partitioned) +INSERT INTO t_null VALUES (1, "NULL"); + +# Values tp (partitions) +INSERT INTO tp VALUES (2, "Two"), (4, "Four"), (6, "Six"), (8, "Eight"); +INSERT INTO tp VALUES (12, "twelve"), (14, "Fourteen"), (16, "Sixteen"), (18, "Eightteen"); +INSERT INTO tp VALUES (112, "Hundred twelve"), (114, "Hundred fourteen"), (116, "Hundred sixteen"), (118, "Hundred eightteen"); +INSERT INTO tp VALUES (122, "Hundred twenty-two"), (124, "Hundred twenty-four"), (126, "Hundred twenty-six"), (128, "Hundred twenty-eight"); +INSERT INTO tp VALUES (162, "Hundred sixty-two"), (164, "Hundred sixty-four"), (166, "Hundred sixty-six"), (168, "Hundred sixty-eight"); +INSERT INTO tp VALUES (182, "Hundred eighty-two"), (184, "Hundred eighty-four"), (186, "Hundred eighty-six"), (188, "Hundred eighty-eight"); + +# Values tp1 (partitions) +INSERT INTO tp1 VALUES (2, "Two"), (4, "Four"), (6, "Six"), (8, "Eight"); +INSERT INTO tp1 VALUES (12, "twelve"), (14, "Fourteen"), (16, "Sixteen"), (18, "Eightteen"); +INSERT INTO tp1 VALUES (112, "Hundred twelve"), (114, "Hundred fourteen"), (116, "Hundred sixteen"), (118, "Hundred eightteen"); +INSERT INTO tp1 VALUES (122, "Hundred twenty-two"), (124, "Hundred twenty-four"), (126, "Hundred twenty-six"), (128, "Hundred twenty-eight"); +INSERT INTO tp1 VALUES (162, "Hundred sixty-two"), (164, "Hundred sixty-four"), (166, "Hundred sixty-six"), (168, "Hundred sixty-eight"); +INSERT INTO tp1 VALUES (182, "Hundred eighty-two"), (184, "Hundred eighty-four"), (186, "Hundred eighty-six"), (188, "Hundred eighty-eight"); + +# Values tps (subpartitions) +INSERT INTO tsp VALUES (2, "Two"), (4, "Four"), (6, "Six"), (8, "Eight"); +INSERT INTO tsp VALUES (12, "twelve"), (14, "Fourteen"), (16, "Sixteen"), (18, "Eightteen"); +INSERT INTO tsp VALUES (112, "Hundred twelve"), (114, "Hundred fourteen"), (116, "Hundred sixteen"), (118, "Hundred eightteen"); +INSERT INTO tsp VALUES (122, "Hundred twenty-two"), (124, "Hundred twenty-four"), (126, "Hundred twenty-six"), (128, "Hundred twenty-eight"); +INSERT INTO tsp VALUES (162, "Hundred sixty-two"), (164, "Hundred sixty-four"), (166, "Hundred sixty-six"), (168, "Hundred sixty-eight"); +INSERT INTO tsp VALUES (182, "Hundred eight-two"), (184, "Hundred eighty-four"), (186, "Hundred eighty-six"), (188, "Hundred eighty-eight"); + +eval CREATE TABLE tsp_01(a INT,b VARCHAR(55),PRIMARY KEY (a)) ENGINE = $engine_table + AS SELECT a, b FROM t_10 WHERE MOD(a,5)= 1; +eval CREATE TABLE tsp_02(a INT,b VARCHAR(55),PRIMARY KEY (a)) ENGINE = $engine_table + AS SELECT a, b FROM t_10 WHERE MOD(a,5)= 2; +eval CREATE TABLE tsp_03(a INT,b VARCHAR(55),PRIMARY KEY (a)) ENGINE = $engine_table, + MAX_ROWS=2000, MIN_ROWS=1 + AS SELECT a, b FROM t_10 WHERE MOD(a,5)= 3; +eval CREATE TABLE tsp_04(a INT,b VARCHAR(55),PRIMARY KEY (a)) ENGINE = $engine_table + AS SELECT a, b FROM t_10 WHERE MOD(a,5)= 4; +eval CREATE TABLE tsp_00(a INT,b VARCHAR(55),PRIMARY KEY (a)) ENGINE = $engine_table + AS SELECT a, b FROM t_10 WHERE MOD(a,5)= 0; + +SHOW CREATE TABLE t_100; +SHOW CREATE TABLE t_1000; +SHOW CREATE TABLE tp; +SHOW CREATE TABLE tsp; + +--enable_result_log +--enable_query_log + +--sorted_result +SELECT * FROM t_10; +--sorted_result +SELECT * FROM t_100; +--sorted_result +SELECT * FROM t_1000; +--sorted_result +SELECT * FROM tp; +--sorted_result +SELECT * FROM tsp; +--sorted_result +SELECT * FROM tsp_00; +--sorted_result +SELECT * FROM tsp_01; +--sorted_result +SELECT * FROM tsp_02; +--sorted_result +SELECT * FROM tsp_03; +--sorted_result +SELECT * FROM tsp_04; + +# 13) Exchanges with different table options. +# See bug#55944 to change the IGNORE +# IGNORE was removed in bug#57708. +INSERT INTO t_10 VALUES (10, "TEN"); +--error ER_ROW_DOES_NOT_MATCH_PARTITION +ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10; +--sorted_result +SELECT * FROM tp WHERE a < 11; +--sorted_result +SELECT * FROM t_10 WHERE a < 11; +#ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10 IGNORE; +#--sorted_result +#SELECT * FROM tp WHERE a < 11; +#--sorted_result +#SELECT * FROM t_10 WHERE a < 11; +INSERT INTO t_1000 VALUES (99, "Ninetynine"); +--error ER_ROW_DOES_NOT_MATCH_PARTITION +ALTER TABLE tp1 EXCHANGE PARTITION p2 WITH TABLE t_1000; +--sorted_result +SELECT * FROM tp1 WHERE a < 1000 AND a > 98; +--sorted_result +SELECT * FROM t_1000 WHERE a < 1000 AND a > 98; +#ALTER TABLE tp1 EXCHANGE PARTITION p2 WITH TABLE t_1000 IGNORE; +#--sorted_result +#SELECT * FROM tp1 WHERE a < 1000 AND a > 98; +#--sorted_result +#SELECT * FROM t_1000 WHERE a < 1000 AND a > 98; +INSERT INTO tsp_03 VALUES (20, "Twenty"); +--error ER_ROW_DOES_NOT_MATCH_PARTITION +ALTER TABLE tsp EXCHANGE PARTITION sp03 WITH TABLE tsp_03; +--sorted_result +SELECT * FROM tsp; +--sorted_result +SELECT * FROM tsp_03; +#ALTER TABLE tsp EXCHANGE PARTITION sp03 WITH TABLE tsp_03 IGNORE; +#--sorted_result +#SELECT * FROM tsp; +#--sorted_result +#SELECT * FROM tsp_03; + +DROP TABLE tp1; +--source suite/parts/inc/part_exch_drop_tabs.inc + diff --git a/mysql-test/suite/parts/inc/part_exch_qa_4.inc b/mysql-test/suite/parts/inc/part_exch_qa_4.inc new file mode 100644 index 00000000..55ac87ec --- /dev/null +++ b/mysql-test/suite/parts/inc/part_exch_qa_4.inc @@ -0,0 +1,47 @@ +--source include/default_charset.inc + +CREATE DATABASE test_2; + +USE test; +--disable_result_log +--disable_query_log +--source suite/parts/inc/part_exch_tabs.inc + +USE test_2; +--source suite/parts/inc/part_exch_tabs.inc + +--enable_result_log +--enable_query_log + +USE test; +# 10) Exchanges with different databases. +ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE test_2.t_10; +--sorted_result +SELECT * FROM test_2.t_10; +--sorted_result +SELECT * FROM tp WHERE a BETWEEN 0 AND 10; +# Back to former values. +ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE test_2.t_10; +--sorted_result +SELECT * FROM test_2.t_10; +--sorted_result +SELECT * FROM tp WHERE a BETWEEN 0 AND 10; +ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE test_2.tsp_00; +--sorted_result +SELECT * FROM test_2.tsp_00; +--sorted_result +SELECT * FROM tsp WHERE a BETWEEN 0 AND 10; +# Back to former values. +ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE test_2.tsp_00; +--sorted_result +SELECT * FROM test_2.tsp_00; +--sorted_result +SELECT * FROM tsp WHERE a BETWEEN 0 AND 10; + +--source suite/parts/inc/part_exch_drop_tabs.inc +USE test_2; +--source suite/parts/inc/part_exch_drop_tabs.inc +USE test; + +DROP DATABASE test_2; + diff --git a/mysql-test/suite/parts/inc/part_exch_qa_5.inc b/mysql-test/suite/parts/inc/part_exch_qa_5.inc new file mode 100644 index 00000000..68255711 --- /dev/null +++ b/mysql-test/suite/parts/inc/part_exch_qa_5.inc @@ -0,0 +1,81 @@ +--source include/not_embedded.inc + +CREATE USER test1@localhost; +CREATE USER test2@localhost; +GRANT USAGE ON *.* TO test1@localhost; +GRANT USAGE ON *.* TO test2@localhost; +GRANT CREATE, DROP, INSERT, SELECT ON test.* TO test1@localhost; +GRANT CREATE, DROP, ALTER, UPDATE, INSERT, SELECT ON test.* TO test2@localhost; + +connect (test1,localhost,test1,,test,$MASTER_MYPORT,$MASTER_MYSOCK); +SELECT current_user(); +SHOW GRANTS FOR CURRENT_USER; +--disable_result_log +--disable_query_log +--source suite/parts/inc/part_exch_tabs.inc +--enable_result_log +--enable_query_log +--error ER_TABLEACCESS_DENIED_ERROR +ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10; +disconnect test1; + + +connect (test2,localhost,test2,,test,$MASTER_MYPORT,$MASTER_MYSOCK); +USE test; +SELECT current_user(); +SHOW GRANTS FOR CURRENT_USER; + +# 9) Exchanges with different owner. +# Privilege for ALTER and SELECT +ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10; +--sorted_result +SELECT * FROM t_10; +--sorted_result +SELECT * FROM tp WHERE a BETWEEN 0 AND 10; +# Back to former values. +ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10; +--sorted_result +SELECT * FROM t_10; +--sorted_result +SELECT * FROM tp WHERE a BETWEEN 0 AND 10; +ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00; +--sorted_result +SELECT * FROM tsp_00; +--sorted_result +SELECT * FROM tsp WHERE a BETWEEN 0 AND 10; +# Back to former values. +ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00; +--sorted_result +SELECT * FROM tsp_00; +--sorted_result +SELECT * FROM tsp WHERE a BETWEEN 0 AND 10; +disconnect test2; + +connection default; +REVOKE ALTER ON test.* FROM test2@localhost; + +connect (test2,localhost,test2,,test,$MASTER_MYPORT,$MASTER_MYSOCK); +USE test; +SELECT current_user(); +SHOW GRANTS FOR CURRENT_USER; +# Privilege for ALTER and SELECT +--error ER_TABLEACCESS_DENIED_ERROR +ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10; +SELECT * FROM tp WHERE a BETWEEN 0 AND 10; +# Back to former values. +--error ER_TABLEACCESS_DENIED_ERROR +ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10; +--error ER_TABLEACCESS_DENIED_ERROR +ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00; +# Back to former values. +--error ER_TABLEACCESS_DENIED_ERROR +ALTER TABLE tsp EXCHANGE PARTITION sp00 WITH TABLE tsp_00; + +connection default; +disconnect test2; + +--source suite/parts/inc/part_exch_drop_tabs.inc + +DROP USER test1@localhost; +DROP USER test2@localhost; + diff --git a/mysql-test/suite/parts/inc/part_exch_qa_7.inc b/mysql-test/suite/parts/inc/part_exch_qa_7.inc new file mode 100644 index 00000000..11707767 --- /dev/null +++ b/mysql-test/suite/parts/inc/part_exch_qa_7.inc @@ -0,0 +1,58 @@ +CREATE USER test_2@localhost; +GRANT SELECT,INSERT,CREATE,ALTER,DROP on test.* to test_2@localhost; + +--source include/not_embedded.inc +--disable_result_log +--disable_query_log +--source suite/parts/inc/part_exch_tabs.inc +--enable_result_log +--enable_query_log + +# 8) Exchanges partition and table and back in 2 sessions with an insert. +# Parallel INSERT and SELECT +# LOCK behaviour when exchanging different partitons. +--echo send +--send +ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10; + +connect (test_2,localhost,test_2,,test,$MASTER_MYPORT,$MASTER_MYSOCK); +# Wait until exchange has been done. +let $wait_condition= SELECT count(a)>0 FROM tp WHERE a=1; +--source include/wait_condition.inc +# Expect 1,3,5,9 in tp and 2,4,6,8 in t_10 +--sorted_result +SELECT * FROM t_10; +--sorted_result +SELECT * FROM tp WHERE a BETWEEN 0 AND 10; +# Exchange back. +INSERT INTO tp VALUES (7,"Seven"); +# Expect 2,4,6,8 in tp +--sorted_result +SELECT * FROM tp WHERE a BETWEEN 0 AND 10; +ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10; + +connection default; +--echo reap; +reap; +--sorted_result +SELECT * FROM t_10; +--sorted_result +SELECT * FROM tp WHERE a BETWEEN 0 AND 10; + +connection test_2; +let $wait_condition= SELECT count(a)>0 FROM tp WHERE a=2; +--source include/wait_condition.inc +--sorted_result +SELECT * FROM t_10; +--sorted_result +SELECT * FROM tp WHERE a BETWEEN 0 AND 10; +disconnect test_2; + +connection default; +--sorted_result +SELECT * FROM t_10; +--sorted_result +SELECT * FROM tp WHERE a BETWEEN 0 AND 10; +--source suite/parts/inc/part_exch_drop_tabs.inc + +DROP USER test_2@localhost; diff --git a/mysql-test/suite/parts/inc/part_exch_qa_8.inc b/mysql-test/suite/parts/inc/part_exch_qa_8.inc new file mode 100644 index 00000000..410c9840 --- /dev/null +++ b/mysql-test/suite/parts/inc/part_exch_qa_8.inc @@ -0,0 +1,66 @@ +--source include/default_charset.inc + +CREATE USER test2@localhost; + +--source include/not_embedded.inc +--disable_result_log +--disable_query_log +--source suite/parts/inc/part_exch_tabs.inc +--enable_result_log +--enable_query_log + +CREATE DATABASE testdb; +USE testdb; +--disable_result_log +--disable_query_log +--source suite/parts/inc/part_exch_tabs.inc +--enable_result_log +--enable_query_log + +USE test; +GRANT CREATE, ALTER, DROP, INSERT, SELECT on test.* TO test2@localhost; +GRANT CREATE, ALTER, DROP, INSERT, SELECT on testdb.* TO test2@localhost; + +# 8) Exchanges partition and table and back in 2 sessions with 2 databases. +connect (test2,localhost,test2,,test,$MASTER_MYPORT,$MASTER_MYSOCK); +# Privileges on both DB's +ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE testdb.t_10; +--sorted_result +SELECT * FROM testdb.t_10; +--sorted_result +SELECT * FROM tp WHERE a BETWEEN 0 AND 10; +# Exchange back. +ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE testdb.t_10; +--sorted_result +SELECT * FROM testdb.t_10; +--sorted_result +SELECT * FROM tp WHERE a BETWEEN 0 AND 10; + +ALTER TABLE testdb.tp EXCHANGE PARTITION p0 WITH TABLE t_10; +--sorted_result +SELECT * FROM t_10; +--sorted_result +SELECT * FROM testdb.tp WHERE a BETWEEN 0 AND 10; +# Exchange back. +ALTER TABLE testdb.tp EXCHANGE PARTITION p0 WITH TABLE t_10; +--sorted_result +SELECT * FROM t_10; +--sorted_result +SELECT * FROM testdb.tp WHERE a BETWEEN 0 AND 10; +disconnect test2; + +connection default; +REVOKE INSERT ON testdb.* FROM test2@localhost; + +connect (test2,localhost,test2,,test,$MASTER_MYPORT,$MASTER_MYSOCK); +--error ER_TABLEACCESS_DENIED_ERROR +ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE testdb.t_10; +--error ER_TABLEACCESS_DENIED_ERROR +ALTER TABLE testdb.tp EXCHANGE PARTITION p0 WITH TABLE t_10; +disconnect test2; + +connection default; +--source suite/parts/inc/part_exch_drop_tabs.inc + +DROP USER test2@localhost; +DROP DATABASE testdb; diff --git a/mysql-test/suite/parts/inc/part_exch_tabs.inc b/mysql-test/suite/parts/inc/part_exch_tabs.inc new file mode 100644 index 00000000..482c9d37 --- /dev/null +++ b/mysql-test/suite/parts/inc/part_exch_tabs.inc @@ -0,0 +1,86 @@ +replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR; +eval CREATE TABLE t_10 (a INT, b VARCHAR(55), PRIMARY KEY (a)) $data_directory $index_directory ENGINE = $engine_table; + +replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR; +eval CREATE TABLE t_100 (a INT, b VARCHAR(55), PRIMARY KEY (a)) $data_directory $index_directory ENGINE = $engine_table; + +replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR; +eval CREATE TABLE t_1000 (a INT, b VARCHAR(55), PRIMARY KEY (a)) $data_directory $index_directory ENGINE = $engine_table; + +replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR; +eval CREATE TABLE t_empty (a INT, b VARCHAR(55), PRIMARY KEY (a)) $data_directory $index_directory ENGINE = $engine_table; + +replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR; +eval CREATE TABLE t_null (a INT, b VARCHAR(55), PRIMARY KEY (a)) $data_directory $index_directory ENGINE = $engine_table; + +replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR; +eval CREATE TABLE tp (a INT, b VARCHAR(55), PRIMARY KEY (a)) $data_directory $index_directory ENGINE = $engine_part +PARTITION BY RANGE (a) +(PARTITION p0 VALUES LESS THAN (10) $p_data_directory $p_index_directory, + PARTITION p1 VALUES LESS THAN (100) $p_data_directory $p_index_directory, + PARTITION p2 VALUES LESS THAN (1000) $p_data_directory $p_index_directory); + +replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR; +eval CREATE TABLE tsp (a INT, b VARCHAR(55), PRIMARY KEY (a)) $data_directory $index_directory ENGINE = $engine_subpart +PARTITION BY RANGE (a) +SUBPARTITION BY HASH(a) +(PARTITION p0 VALUES LESS THAN (10) $p_data_directory $p_index_directory + (SUBPARTITION sp00, + SUBPARTITION sp01, + SUBPARTITION sp02, + SUBPARTITION sp03, + SUBPARTITION sp04), PARTITION p1 VALUES LESS THAN (100) + (SUBPARTITION sp10 $p_data_directory $p_index_directory, + SUBPARTITION sp11 $p_data_directory $p_index_directory, + SUBPARTITION sp12 $p_data_directory $p_index_directory, + SUBPARTITION sp13 $p_data_directory $p_index_directory, + SUBPARTITION sp14 $p_data_directory $p_index_directory), + PARTITION p2 VALUES LESS THAN (1000) $p_data_directory $p_index_directory + (SUBPARTITION sp20, + SUBPARTITION sp21, + SUBPARTITION sp22, + SUBPARTITION sp23, + SUBPARTITION sp24)); + +# Values t_10 (not partitioned) +INSERT INTO t_10 VALUES (1, "One"), (3, "Three"), (5, "Five"), (9, "Nine"); + +# Values t_100 (not partitioned) +INSERT INTO t_100 VALUES (11, "Eleven"), (13, "Thirdteen"), (15, "Fifeteen"), (19, "Nineteen"); +INSERT INTO t_100 VALUES (91, "Ninety-one"), (93, "Ninety-three"), (95, "Ninety-five"), (99, "Ninety-nine"); + +# Values t_1000 (not partitioned) +INSERT INTO t_1000 VALUES (111, "Hundred elven"), (113, "Hundred thirdteen"), (115, "Hundred fiveteen"), (119, "Hundred nineteen"); +INSERT INTO t_1000 VALUES (131, "Hundred thirty-one"), (133, "Hundred thirty-three"), (135, "Hundred thirty-five"), (139, "Hundred thirty-nine"); +INSERT INTO t_1000 VALUES (151, "Hundred fifty-one"), (153, "Hundred fifty-three"), (155, "Hundred fity-five"), (159, "Hundred fifty-nine"); +INSERT INTO t_1000 VALUES (191, "Hundred ninety-one"), (193, "Hundred ninety-three"), (195, "Hundred ninety-five"), (199, "Hundred ninety-nine"); + +# Values t_null (not partitioned) +INSERT INTO t_null VALUES (1, "NULL"); + +# Values tp (partitions) +INSERT INTO tp VALUES (2, "Two"), (4, "Four"), (6, "Six"), (8, "Eight"); +INSERT INTO tp VALUES (12, "twelve"), (14, "Fourteen"), (16, "Sixteen"), (18, "Eightteen"); +INSERT INTO tp VALUES (112, "Hundred twelve"), (114, "Hundred fourteen"), (116, "Hundred sixteen"), (118, "Hundred eightteen"); +INSERT INTO tp VALUES (122, "Hundred twenty-two"), (124, "Hundred twenty-four"), (126, "Hundred twenty-six"), (128, "Hundred twenty-eight"); +INSERT INTO tp VALUES (162, "Hundred sixty-two"), (164, "Hundred sixty-four"), (166, "Hundred sixty-six"), (168, "Hundred sixty-eight"); +INSERT INTO tp VALUES (182, "Hundred eighty-two"), (184, "Hundred eighty-four"), (186, "Hundred eighty-six"), (188, "Hundred eighty-eight"); + +# Values tps (subpartitions) +INSERT INTO tsp VALUES (2, "Two"), (4, "Four"), (6, "Six"), (8, "Eight"); +INSERT INTO tsp VALUES (12, "twelve"), (14, "Fourteen"), (16, "Sixteen"), (18, "Eightteen"); +INSERT INTO tsp VALUES (112, "Hundred twelve"), (114, "Hundred fourteen"), (116, "Hundred sixteen"), (118, "Hundred eightteen"); +INSERT INTO tsp VALUES (122, "Hundred twenty-two"), (124, "Hundred twenty-four"), (126, "Hundred twenty-six"), (128, "Hundred twenty-eight"); +INSERT INTO tsp VALUES (162, "Hundred sixty-two"), (164, "Hundred sixty-four"), (166, "Hundred sixty-six"), (168, "Hundred sixty-eight"); +INSERT INTO tsp VALUES (182, "Hundred eight-two"), (184, "Hundred eighty-four"), (186, "Hundred eighty-six"), (188, "Hundred eighty-eight"); + +replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR; +eval CREATE TABLE tsp_01(a INT,b VARCHAR(55),PRIMARY KEY (a)) ENGINE = $engine_table $data_directory $index_directory AS SELECT a, b FROM t_10 WHERE MOD(a,5)= 1; +replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR; +eval CREATE TABLE tsp_02(a INT,b VARCHAR(55),PRIMARY KEY (a)) ENGINE = $engine_table $data_directory $index_directory AS SELECT a, b FROM t_10 WHERE MOD(a,5)= 2; +replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR; +eval CREATE TABLE tsp_03(a INT,b VARCHAR(55),PRIMARY KEY (a)) ENGINE = $engine_table $data_directory $index_directory AS SELECT a, b FROM t_10 WHERE MOD(a,5)= 3; +replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR; +eval CREATE TABLE tsp_04(a INT,b VARCHAR(55),PRIMARY KEY (a)) ENGINE = $engine_table $data_directory $index_directory AS SELECT a, b FROM t_10 WHERE MOD(a,5)= 4; +replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR; +eval CREATE TABLE tsp_00(a INT,b VARCHAR(55),PRIMARY KEY (a)) ENGINE = $engine_table $data_directory $index_directory AS SELECT a, b FROM t_10 WHERE MOD(a,5)= 0; diff --git a/mysql-test/suite/parts/inc/part_supported_sql_funcs_delete.inc b/mysql-test/suite/parts/inc/part_supported_sql_funcs_delete.inc new file mode 100644 index 00000000..844ba70d --- /dev/null +++ b/mysql-test/suite/parts/inc/part_supported_sql_funcs_delete.inc @@ -0,0 +1,64 @@ +################################################################################ +# t/part_supported_sql_funcs_delete.inc # +# # +# Purpose: # +# Delete access of the tests frame for allowed sql functions # +# # +# # +#------------------------------------------------------------------------------# +# Original Author: HH # +# Original Date: 2006-11-22 # +# Change Author: # +# Change Date: # +# Change: # +################################################################################ +--echo ------------------------------------------------------------------------- +--echo --- Delete rows and partitions of tables with $sqlfunc +--echo ------------------------------------------------------------------------- + +begin; +eval delete from $t1 where col1=$val2; +eval delete from $t2 where col1=$val2; +eval delete from $t3 where col1=$val2; +eval delete from $t4 where col1=$val2; +eval delete from $t5 where col1=$val2; +eval delete from $t6 where col1=$val2; +commit; + +eval select * from $t1 order by col1; +eval select * from $t2 order by col1; +eval select * from $t3 order by col1; +eval select * from $t4 order by colint; +eval select * from $t5 order by colint; + +begin; +eval insert into $t1 values ($val2); +eval insert into $t2 values ($val2); +eval insert into $t3 values ($val2); +eval insert into $t4 values (60,$val2); +eval insert into $t5 values (60,$val2); +eval insert into $t6 values (60,$val2); +commit; + +eval select * from $t1 order by col1; +eval select * from $t2 order by col1; +eval select * from $t3 order by col1; +eval select * from $t4 order by colint; +eval select * from $t5 order by colint; +eval select * from $t6 order by colint; + +if (!$drop_partition_not_supported) +{ +eval alter table $t1 drop partition p0; +eval alter table $t2 drop partition p0; +eval alter table $t4 drop partition p0; +eval alter table $t5 drop partition p0; +eval alter table $t6 drop partition p0; + +eval select * from $t1 order by col1; +eval select * from $t2 order by col1; +eval select * from $t3 order by col1; +eval select * from $t4 order by colint; +eval select * from $t5 order by colint; +eval select * from $t6 order by colint; +} diff --git a/mysql-test/suite/parts/inc/part_supported_sql_funcs_main.inc b/mysql-test/suite/parts/inc/part_supported_sql_funcs_main.inc new file mode 100644 index 00000000..565731db --- /dev/null +++ b/mysql-test/suite/parts/inc/part_supported_sql_funcs_main.inc @@ -0,0 +1,231 @@ +################################################################################ +# t/partition_supported_sql_funcs_main.inc # +# # +# Purpose: # +# Tests which SQL functions are allowed in partinioning clauses. # +# # +# # +#------------------------------------------------------------------------------# +# Original Author: HH # +# Original Date: 2006-11-22 # +# Change Author: # +# Change Date: # +# Change: # +# # +# This test uses a test frame (partition_supported_sql_funcs.inc) for every # +# SQL function allowed in the partitioning parts of CREATE and ALTE TABLE. # +# The variales represent the # +# - SQL function isself with a column (sqlfunc) and a literal (valsqlsunc), # +# - the type of the column (coltype), # +# - a file with test values of the coltype (infile) and # +# - single test values (val1 to val4). # +# The test frame includes CREATE/ALTER TABLE and some access statements. # +# Column types are int, float(7,4), char(1), date and time depending on the # +# SQL function. The test frame uses the include file # +# "part_supported_sql_funcs_delete.inc" testing the deletion of # +# partitions. # +# The CREATE and ALTER TABLE statement do not cover the complete partitions # +# functions, but will ashure that the SQL functions are basically working. # +################################################################################ + + +let $sqlfunc = abs(col1); +let $valsqlfunc = abs(15); +let $coltype = int; +let $infile = part_supported_sql_funcs_int_int.inc; +let $val1 = 5 ; +let $val2 = 13 ; +let $val3 = 17 ; +let $val4 = 15 ; +--source suite/parts/inc/partition_supported_sql_funcs.inc + +let $sqlfunc = mod(col1,10); +let $valsqlfunc = mod(15,10); +let $coltype = int; +let $infile = part_supported_sql_funcs_int_int.inc; +let $val1 = 5; +let $val2 = 19; +let $val3 = 17; +let $val4 = 15 ; +--source suite/parts/inc/partition_supported_sql_funcs.inc + +let $sqlfunc = day(col1); +let $valsqlfunc = day('2006-12-21'); +let $coltype = date; +let $infile = part_supported_sql_funcs_int_date.inc; +let $val1 = '2006-02-03'; +let $val2 = '2006-01-17'; +let $val3 = '2006-01-25'; +let $val4 = '2006-02-05'; +--source suite/parts/inc/partition_supported_sql_funcs.inc + +let $sqlfunc = dayofmonth(col1); +let $valsqlfunc = dayofmonth('2006-12-24'); +let $coltype = date; +let $infile = part_supported_sql_funcs_int_date.inc; +let $val1 = '2006-02-03'; +let $val2 = '2006-01-17'; +let $val3 = '2006-01-25'; +let $val4 = '2006-02-05'; +--source suite/parts/inc/partition_supported_sql_funcs.inc + +let $sqlfunc = dayofweek(col1); +let $valsqlfunc = dayofweek('2006-12-24'); +let $coltype = date; +let $infile = part_supported_sql_funcs_int_date.inc; +let $val1 = '2006-01-03'; +let $val2 = '2006-02-17'; +let $val3 = '2006-01-25'; +let $val4 = '2006-02-05'; +--source suite/parts/inc/partition_supported_sql_funcs.inc + +let $sqlfunc = dayofyear(col1); +let $valsqlfunc = dayofyear('2006-12-25'); +let $coltype = date; +let $infile = part_supported_sql_funcs_int_date.inc; +let $val1 = '2006-01-03'; +let $val2 = '2006-01-17'; +let $val3 = '2006-02-25'; +let $val4 = '2006-02-05'; +--source suite/parts/inc/partition_supported_sql_funcs.inc +# Disabled after fixing bug#54483. +#let $coltype = char(30); +#--source suite/parts/inc/partition_supported_sql_funcs.inc + +let $sqlfunc = extract(month from col1); +let $valsqlfunc = extract(year from '1998-11-23'); +let $coltype = date; +let $infile = part_supported_sql_funcs_int_date.inc; +let $val1 = '2006-01-03'; +let $val2 = '2006-02-17'; +let $val3 = '2006-01-25'; +let $val4 = '2006-02-05'; +--source suite/parts/inc/partition_supported_sql_funcs.inc + +let $sqlfunc = hour(col1); +let $valsqlfunc = hour('18:30'); +let $coltype = time; +let $infile = part_supported_sql_funcs_int_time.inc; +let $val1 = '09:09'; +let $val2 = '14:30'; +let $val3 = '21:59'; +let $val4 = '10:30'; +--source suite/parts/inc/partition_supported_sql_funcs.inc + +let $sqlfunc = microsecond(col1); +let $valsqlfunc = microsecond('10:30:10.000010'); +let $coltype = time(6); +let $infile = part_supported_sql_funcs_int_time.inc; +let $val1 = '09:09:15.000002'; +let $val2 = '04:30:01.000018'; +let $val3 = '00:59:22.000024'; +let $val4 = '05:30:34.000037'; +--source suite/parts/inc/partition_supported_sql_funcs.inc + +let $sqlfunc = minute(col1); +let $valsqlfunc = minute('18:30'); +let $coltype = time; +let $val1 = '09:09:15'; +let $val2 = '14:30:45'; +let $val3 = '21:59:22'; +let $val4 = '10:24:23'; +--source suite/parts/inc/partition_supported_sql_funcs.inc + +let $sqlfunc = second(col1); +let $valsqlfunc = second('18:30:14'); +let $coltype = time; +let $infile = part_supported_sql_funcs_int_time.inc; +let $val1 = '09:09:09'; +let $val2 = '14:30:20'; +let $val3 = '21:59:22'; +let $val4 = '10:22:33'; +--source suite/parts/inc/partition_supported_sql_funcs.inc +# second(non_time_col) is disabled after bug#54483. +#let $coltype = char(30); +#--source suite/parts/inc/partition_supported_sql_funcs.inc + +let $sqlfunc = month(col1); +let $valsqlfunc = month('2006-10-14'); +let $coltype = date; +let $infile = part_supported_sql_funcs_int_date.inc; +let $val1 = '2006-01-03'; +let $val2 = '2006-12-17'; +let $val3 = '2006-05-25'; +let $val4 = '2006-11-06'; +--source suite/parts/inc/partition_supported_sql_funcs.inc + +let $sqlfunc = quarter(col1); +let $valsqlfunc = quarter('2006-10-14'); +let $coltype = date; +let $infile = part_supported_sql_funcs_int_date.inc; +let $val1 = '2006-01-03'; +let $val2 = '2006-12-17'; +let $val3 = '2006-09-25'; +let $val4 = '2006-07-30'; +--source suite/parts/inc/partition_supported_sql_funcs.inc + +# time_to_sec() is now a double function, so it can't be portioned upon +--disable_parsing +let $sqlfunc = time_to_sec(col1)-(time_to_sec(col1)-20); +let $valsqlfunc = time_to_sec('18:30:14')-(time_to_sec('17:59:59')); +let $coltype = time; +let $infile = part_supported_sql_funcs_int_time.inc; +let $val1 = '09:09:15'; +let $val2 = '14:30:45'; +let $val3 = '21:59:22'; +let $val4 = '10:33:11'; +--source suite/parts/inc/partition_supported_sql_funcs.inc +--enable_parsing + +# to_days(non_date_col) is disabled after bug#54483. +#let $sqlfunc = to_days(col1)-to_days('2006-01-01'); +#let $valsqlfunc = to_days('2006-02-02')-to_days('2006-01-01'); +#let $coltype = date; +#let $infile = part_supported_sql_funcs_int_date.inc; +#let $val1 = '2006-02-03'; +#let $val2 = '2006-01-17'; +#let $val3 = '2006-01-25'; +#let $val4 = '2006-02-06'; +#--source suite/parts/inc/partition_supported_sql_funcs.inc + +# to_days(non_date_col) is disabled after bug#54483. +# DATEDIFF() is implemented as (TO_DAYS(d1) - TO_DAYS(d2)) +#let $sqlfunc = datediff(col1, '2006-01-01'); +#let $valsqlfunc = datediff('2006-02-02', '2006-01-01'); +#let $coltype = date; +#let $infile = part_supported_sql_funcs_int_date.inc; +#let $val1 = '2006-02-03'; +#let $val2 = '2006-01-17'; +#let $val3 = '2006-01-25'; +#let $val4 = '2006-02-06'; +#--source suite/parts/inc/partition_supported_sql_funcs.inc + +let $sqlfunc = weekday(col1); +let $valsqlfunc = weekday('2006-10-14'); +let $coltype = date; +let $infile = part_supported_sql_funcs_int_date.inc; +let $val1 = '2006-12-03'; +let $val2 = '2006-11-17'; +let $val3 = '2006-05-25'; +let $val4 = '2006-02-06'; +--source suite/parts/inc/partition_supported_sql_funcs.inc + +let $sqlfunc = year(col1)-1990; +let $valsqlfunc = year('2005-10-14')-1990; +let $coltype = date; +let $infile = part_supported_sql_funcs_int_date.inc; +let $val1 = '1996-01-03'; +let $val2 = '2000-02-17'; +let $val3 = '2004-05-25'; +let $val4 = '2002-02-15'; +--source suite/parts/inc/partition_supported_sql_funcs.inc + +let $sqlfunc = yearweek(col1)-200600; +let $valsqlfunc = yearweek('2006-10-14')-200600; +let $coltype = date; +let $infile = part_supported_sql_funcs_int_date.inc; +let $val1 = '2006-01-03'; +let $val2 = '2006-08-17'; +let $val3 = '2006-03-25'; +let $val4 = '2006-11-15'; +--source suite/parts/inc/partition_supported_sql_funcs.inc diff --git a/mysql-test/suite/parts/inc/partition.pre b/mysql-test/suite/parts/inc/partition.pre new file mode 100644 index 00000000..3c9bbe9a --- /dev/null +++ b/mysql-test/suite/parts/inc/partition.pre @@ -0,0 +1,414 @@ +################################################################################ +# inc/partition.pre # +# # +# Purpose: # +# Auxiliary script creating prerequisites needed by the partitioning tests # +# The name of the toplevel scripts sourcing this one is # +# t/partition_<feature>_<storage engine>.test # +# # +# Several parameters have to be set before this file is sourced. # +# Please refer to the README. # +# # +# The README for the partitioning testcases is at the end of this file. # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-03-05 # +# Change Author: mleich # +# Change Date: 2007-10-08 # +# Change: Minor cleanup and fix for # +# Bug#31243 Test "partition_basic_myisam" truncates path names# +# - Blow column file_list up to VARBINARY(10000) # +# - remove reference to fixed bugs #17455, #19305 # +################################################################################ + +# Set the session storage engine +eval SET @@session.default_storage_engine = $engine; + +--echo +--echo #------------------------------------------------------------------------ +--echo # 0. Setting of auxiliary variables + Creation of an auxiliary tables +--echo # needed in many testcases +--echo #------------------------------------------------------------------------ +# Set the variable $no_debug depending on the current value of $debug; +--disable_query_log +eval SET @aux = $debug; +let $no_debug= `SELECT @aux = 0`; +--enable_query_log +if ($debug) +{ +--echo # Attention: Script debugging is swiched on. +--echo # - all statements will be protocolled +--echo # - some additional will be executed +--echo # It is to be expected, that we get huge differences. +} + +let $ER_DUP_KEY= 1022; +let $ER_GET_ERRNO= 1030; +let $ER_BAD_NULL_ERROR= 1048; +let $ER_DUP_ENTRY= 1062; +let $ER_PARSE_ERROR= 1064; +let $ER_TOO_MANY_PARTITIONS_ERROR= 1499; +let $ER_UNIQUE_KEY_NEED_ALL_FIELDS_IN_PF= 1503; +let $ER_NO_PARTS_ERROR= 1504; +let $ER_PARTITION_DOES_NOT_EXIST= 1507; +let $ER_SAME_NAME_PARTITION= 1517; +let $ER_NO_PARTITION_FOR_GIVEN_VALUE= 1526; + +# Set the variable $engine_other to a storage engine <> $engine +--disable_query_log +eval SELECT UPPER($engine) = 'MEMORY' INTO @aux; +let $aux= `SELECT @aux`; +if ($aux) +{ + let $engine_other= 'MyISAM'; +} +if (!$aux) +{ + let $engine_other= 'MEMORY'; +} +--enable_query_log + +# Numbers used for +# - partitioning Example: ... PARTITION part1 VALUES LESS THAN ($max_row_div2) +# - INSERT/SELECT/UPDATE/DELETE Example: ... WHERE f_int1 > @max_row_div3 +let $max_row= `SELECT @max_row`; +SELECT @max_row DIV 2 INTO @max_row_div2; +let $max_row_div2= `SELECT @max_row_div2`; +SELECT @max_row DIV 3 INTO @max_row_div3; +let $max_row_div3= `SELECT @max_row_div3`; +SELECT @max_row DIV 4 INTO @max_row_div4; +let $max_row_div4= `SELECT @max_row_div4`; +SET @max_int_4 = 2147483647; +let $max_int_4= `SELECT @max_int_4`; + +# Three insert statements used in many testcases. +let $insert_first_half= INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template +WHERE f_int1 BETWEEN 1 AND @max_row_div2 - 1; +let $insert_second_half= INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template +WHERE f_int1 BETWEEN @max_row_div2 AND @max_row; +# +let $insert_first_third= INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template +WHERE f_int1 BETWEEN 1 AND @max_row_div3 - 1; +let $insert_second_third= INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template +WHERE f_int1 BETWEEN @max_row_div3 AND 2 * @max_row_div3 - 1; +let $insert_third_third= INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template +WHERE f_int1 BETWEEN 2 * @max_row_div3 AND @max_row; +# +let $insert_all= INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template; + +# Column list with definition for all tables to be checked +let $column_list= f_int1 INTEGER DEFAULT 0, +f_int2 INTEGER DEFAULT 0, +f_char1 CHAR(20), +f_char2 CHAR(20), +f_charbig VARCHAR(1000); + +let $sub_part_no= 3; + +# Auxiliary table used for many experiments (INSERT INTO t1 ... SELECT ...) +# on the tables to be checked +--disable_warnings +DROP TABLE IF EXISTS t0_template; +--enable_warnings +eval CREATE TABLE t0_template ( +$column_list , +PRIMARY KEY(f_int1)) +ENGINE = MEMORY; +--echo # Logging of <max_row> INSERTs into t0_template suppressed +--disable_query_log +let $num= `SELECT @max_row`; +begin; +while ($num) +{ + eval INSERT INTO t0_template +SET f_int1 = $num, f_int2 = $num, f_char1 = '$num', f_char2 = '$num', +f_charbig = '===$num==='; + + dec $num; +} +commit; +--enable_query_log + +# Auxiliary table used for comparisons of table definitions and file lists +--disable_warnings +DROP TABLE IF EXISTS t0_definition; +--enable_warnings +CREATE TABLE t0_definition ( +state CHAR(3), +create_command VARBINARY(5000), +file_list VARBINARY(10000), +PRIMARY KEY (state) +) ENGINE = MEMORY; + +# Auxiliary table used for trigger experiments +--disable_warnings +DROP TABLE IF EXISTS t0_aux; +--enable_warnings +eval CREATE TABLE t0_aux ( $column_list ) +ENGINE = MEMORY; + +# Prevent that a change of defaults breaks the tests. +SET AUTOCOMMIT= 1; +SET @@session.sql_mode= ''; + +--echo # End of basic preparations needed for all tests +--echo #----------------------------------------------- + +if (0) +{ +# README for the partioning tests (t/partition_<feature>_<engine>.test) +# ======================================================================== +# +# 1. Explanation of the variables to be assigned in the top-level storage engine +# specific scripts +#------------------------------------------------------------------------------# +# +# Options, for mostly test(script+logic+result) debugging support: +# $debug= 0 (default) +# --> The protocolling of auxiliary stuff is suppressed. +# The file with expected results fits to this setting. +# $debug= 1 +# --> All executed statements will be printed into the protocol. +# That means statements which +# - are most time of low interest and do auxiliary stuff +# like generating the next SQL statement to be executed +# - additional statements giving information about table +# contents or the value of some variables +# You will get huge differences, because the file with the +# expected results was created with $debug = 0 . +# +# $with_partitioning= 1 (default) +# --> Do the test with really partitioned tables. +# $with_partitioning= 0 +# --> Do not use partitioned tables. This means omit the +# "PARTITION BY ... SUBPARTITION BY ..." part of the CREATE TABLE +# statement. This setting has only an effect on tests where +# partition_methods1.inc and/or partition_methods2.inc are sourced. +# +# You will get differences when the CREATE TABLE statements +# and table related files are printed or testcases check +# partition borders, but most server responses and result +# sets should be usable as reference for the test with the +# partioned tables. +# Please make a run with $with_partitioning= 0, whenever +# - you do not trust the scripts (routines checking server codes/ +# result sets) +# - fear that there is a new bug affecting partitioned and non +# partitioned tables +# +# +# Execute the test of "table" files +# $do_file_tests= 1 (default for +# - all storage engines within the extended QA test +# - only MyISAM within the main regression tests) +# --> Collect the file list and compare the file list before and after +# OPTIMIZE/REPAIR/TRUNCATE +# $do_file_tests= 0 (default for non MyISAM storage engines within the +# main regression tests) +# --> Do not collect the file list. +# Only MyISAM has files per PARTITION/SUBPARTITION, PRIMARY KEY, INDEX, .. +# There is a low probability that this tests detects bugs when used in +# connection with other storage engines. +# +# Option, for displaying files: +# $ls= 1 (default) +# --> Display the table related directory content via +# "ls $MYSQLTEST_VARDIR/mysqld.1/data/test/t1*" +# if these information were collected. +# This is probably not portable to some OS. +# $ls= 0 +# --> Omit displaying the directory +# +# +# Number of rows for the INSERT/UPDATE/DELETE/SELECT experiments +# on partitioned tables: +# @max_row is the number of rows which will be filled into the auxiliary +# MEMORY table t0_template. This table is used for INSERT ... SELECT +# experiments. The typical test table t1 contains most of the time +# about @max_row DIV 2 rows. +# Too small values of @max_row should be avoided, because some statements +# should affect several rows and partitions. +# Too big values of @max_row should be avoided, because of runtime issues. +# @max_row= 20 (default for the main regression tests) +# The file with expected results fits to this amount of rows. +# @max_row= 300 (default for extended QA test) +# --> Use <number rows>. +# There should be only a few systematic differences to the file +# with expected results, because most SQL statements use @max_row and +# variables like max_row_div2 instead of a constant with the actual +# number of rows. +# I assume a value of 300 rows should be +# +# +# Perform the variant with extended tests: +# $more_trigger_tests, $more_pk_ui_tests(PK=PRIMARY KEY,UI=UNIQUE INDEX), +# =0 (default for the main regression tests) +# - There is a very low probability, that the omitted tests reveal a +# bug which cannot be detected with the other tests. +# - Limiting the partitioning tests solves issues with runtime and +# protocol size. +# =1 (default for extended QA test) +# +# +# Perform PRIMARY KEY specific tests: +# $do_pk_tests= 0; +# --> Do not execute the PRIMARY KEY related tests. +# $do_pk_tests= 1 (default for extended QA test) +# --> Execute the PRIMARY KEY related tests. +# The default setting for the main regression tests depends on the +# storage engine. The PRIMARY KEY tests must be executed for every storage +# engine, where the existence of a PRIMARY KEY affects the kind how the +# table rows are stored. +# Examples for the main rgression tests: +# InnoDB - The PRIMARY KEY is a clustered index where the data for the +# rows are stored. $do_pk_tests= 1 +# MyISAM - AFAIK there is no effect on the tree containing the rows. +# $do_pk_tests= 0 +# +# Assign a big number smaller than the maximum value for partitions +# and smaller than the maximum value of SIGNED INTEGER +# +# +# 2. Typical architecture of a test: +#------------------------------------------------------------------------------# +# 2.1. storage engine specific script on top level +# (t/partition_<feature>_<engine>.test) +# a) General not engine specific settings and requirements +# $debug, $ls, @max_row, $more_trigger_tests, ..... +# --source inc/have_partition.inc +# b) Engine specific settings and requirements +# $do_pk_tests, $MAX_VALUE, $engine +# SET SESSION default_storage_engine +# $engine_other +# c) Generate the prerequisites ($variables, @variables, tables) needed +# via +# --source inc/partition.pre +# d) Set "fixed_bug<number>" variables to 1 if there are open engine +# specific bugs which need worarounds. +# e) Execute the feature specific testscript via +# --source inc/partition_<feature>.inc +# f) Perform a cleanup by removing all objects created within the tests +# --source inc/partition_cleanup.inc +# +# 2.2. script generating the prerequisites needed in all tests +# (inc/partition.pre) +# a) Message about open bugs causing that +# - some testcases are disabled +# - it cannot be avoided that the file with expected results suffers +# from open bugs +# This should not occur often ! +# Example: There is extreme often an auxiliary testscript sourced, +# but the the conditions vary. We get under a certain combination +# of conditions a wrong result set or server response. +# b) Set "fixed_bug<number>" variables to 0 if there are open engine +# specific bugs. They are later set to 1 within the toplevel script. +# Set "fixed_bug<number>" variables to 1 if there are open NOT engine +# specific bugs. +# c) Setting of auxiliary variables +# d) Creation of auxiliary tables .... +# +# 2.3. script checking a feature +# (inc/partition_<feature.inc>.inc) +# Example: +# a) "set/compute" a CREATE TABLE t1 .. and an ALTER TABLE ... statement +# b) CREATE TABLE t1 ... +# c) INSERT INTO t1 (.....) SELECT .... FROM t0_template WHERE ... +# The first 50 % of all t0_template rows will be inserted into t1. +# d) ALTER TABLE t1 (Example: ADD/DROP UNIQUE INDEX) +# e) INSERT INTO t1 (.....) SELECT .... FROM t0_template WHERE ... +# The second 50 % of all t0_template rows will be inserted into t1. +# Now t1 and t0_template should have the same content. +# f) Check the "usability" of the current table t1 +# via +# --source inc/partition_check.pre +# g) DROP TABLE t1 +# Switch to other CREATE and ALTER statements and run sequence a)-g) again +# ... +# +# 2.4. script checking if a certain table shows the expected behaviour +# ("usability" check): inc/partition_check.inc +# - SELECT/INSERT/UPDATE/DELETE affecting single and multiple records +# - check of values of special interest like NULL etc. +# - INSERT/UPDATE with BEFORE/AFTER triggers +# - violations of UNIQUE constraints, if there are any defined +# - transactions ... +# - TRUNCATE/OPTIMIZE/.. +# - ... +# +# +# 2.5. There are some auxiliary scripts with sub tests where we cannot predict +# if we get an error and if we get one, which one. +# Example: INSERT a record where the value for a certain column equals +# some existing record. +# Depending on existing/not existing PRIMARY KEYs, UNIQUE INDEXes +# the response might be "no error", ER_DUP_KEY, ER_DUP_ENTRY. +# Our requirements: +# 1. We cannot abort whenever get an error message from the server. +# 2. We want the exact server message into the protocol. +# 3. We want abort testing if we know that a certain error must not happen. +# Common but unusable Solutions: +# a) --error 0, ER_DUP_KEY, ER_DUP_ENTRY +# <statment> +# We get no error message even if the statement fails. +# b) --error ER_DUP_KEY, ER_DUP_ENTRY +# <statment> +# We might get "got one of the expected errors". +# There are situations where the statement must be successful. +# c) --disable_abort_on_error +# <statment> +# --enable_abort_on_error +# And nothing extra +# We do not abort in case of unexpected server errors. +# +# Final solution: +# --disable_abort_on_error +# <statment> +# --enable_abort_on_error +# Check via error number if the error is not totally unexpected. +# The sub tests use $ER_DUP_KEY, $ER_DUP_ENTRY, etc. +# Assignment of values happen in this file. +# +# +# 3. How to analyze a partitioning bug revealed with these tests/ How to build +# a small replay script from the monstrous protocols ? +#------------------------------------------------------------------------------# +# a) crash -- use the file var/mysqld.1/data/mysql/general_log.CSV +# b) no crash, but unexpected server response (there is no "reject file) +# -- use the file r/<testcase>.log +# Please be aware that the option $debug= 0 suppresses the +# protocolling of some queries. +# c) no crash, but unexpected result set +# -- use the file r/<testcase>.reject +# Please be aware that the option $debug= 0 suppresses the +# protocolling of some queries. +# In most cases you will find that the r/<testcase>.<log/reject> contains at +# least a line "# # check <something>: 0". +# That means that a check within inc/partition_check did not got the +# expected result. +# A good start for a replay script would be +# 1. Copy t/partition_<feature>_<engine>.test to t/my_test.test +# 2. Edit t/my_test.test +# - set $debug to 1 +# - replace the line +# "--source inc/partition_<feature>.inc" +# with all statements between the last +# CREATE TABLE t1 statement (included this) +# and the line +# "# Start usability test (inc/partition_check.inc)" +# - add the content of inc/partition_check.inc at the end. +# +# Please excuse that the partitioning tests generate such huge protocols which +# and are not very handy when it comes to bug analysis. I tried to squeez out +# as much test coverage as possible by writing some hopefully smart routines +# and reusing them in various combinations. +# +# Matthias +# +} diff --git a/mysql-test/suite/parts/inc/partition_10.inc b/mysql-test/suite/parts/inc/partition_10.inc new file mode 100644 index 00000000..2050c809 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_10.inc @@ -0,0 +1,67 @@ +# inc/partition_10.inc +# +# Do some basic checks on a table. +# +# FIXME: Do not write the statements and results, if SQL return code = 0 +# and result set like expected. Write a message, that all is like +# expected instead. +# +# All SELECTs are so written, that we get my_value = 1, when everything +# is like expected. +# + +--source suite/parts/inc/partition_layout.inc + +####### Variations with multiple records +# Select on empty table +SELECT COUNT(*) = 0 AS my_value FROM t1; +# (mass) Insert of $max_row records +eval INSERT INTO t1 SELECT * FROM t0_template WHERE f1 BETWEEN 1 AND $max_row; +# Select +eval SELECT (COUNT(*) = $max_row) AND (MIN(f1) = 1) AND (MAX(f1) = $max_row) + AS my_value FROM t1; +# DEBUG SELECT COUNT(*),MIN(f1),MAX(f1) FROM t1; +# (mass) Update $max_row_div4 * 2 + 1 records +eval UPDATE t1 SET f1 = f1 + $max_row +WHERE f1 BETWEEN $max_row_div2 - $max_row_div4 AND $max_row_div2 + $max_row_div4; +# Select +eval SELECT (COUNT(*) = $max_row) AND (MIN(f1) = 1) AND (MAX(f1) = $max_row_div2 + $max_row_div4 + $max_row ) + AS my_value FROM t1; +# DEBUG SELECT COUNT(*),MIN(f1),MAX(f1) FROM t1; +# (mass) Delete $max_row_div4 * 2 + 1 records +eval DELETE FROM t1 +WHERE f1 BETWEEN $max_row_div2 - $max_row_div4 + $max_row AND $max_row_div2 + $max_row_div4 + $max_row; +# Select +eval SELECT (COUNT(*) = $max_row - $max_row_div4 - $max_row_div4 - 1) AND (MIN(f1) = 1) AND (MAX(f1) = $max_row) + AS my_value FROM t1; +# DEBUG SELECT COUNT(*),MIN(f1),MAX(f1) FROM t1; + +####### Variations with single records +# Insert one record at beginning +INSERT INTO t1 SET f1 = 0 , f2 = '#######'; +# Select this record +SELECT COUNT(*) = 1 AS my_value FROM t1 WHERE f1 = 0 AND f2 = '#######'; +# Insert one record at end +eval INSERT INTO t1 SET f1 = $max_row + 1, f2 = '#######'; +# Select this record +eval SELECT COUNT(*) = 1 AS my_value FROM t1 WHERE f1 = $max_row + 1 AND f2 = '#######'; +# Update one record +eval UPDATE t1 SET f1 = $max_row + 2, f2 = 'ZZZZZZZ' + WHERE f1 = 0 AND f2 = '#######'; +# Select +eval SELECT COUNT(*) = 1 AS my_value FROM t1 WHERE f1 = $max_row + 2 AND f2 = 'ZZZZZZZ'; +# Bug #15968: Partitions: crash when INSERT with f1 = -1 into PARTITION BY HASH(f1) +eval UPDATE t1 SET f1 = 0 - 1, f2 = 'ZZZZZZZ' + WHERE f1 = $max_row + 1 AND f2 = '#######'; +# Select +SELECT COUNT(*) AS my_value FROM t1 WHERE f1 = 0 - 1 AND f2 = 'ZZZZZZZ'; +# Delete +eval DELETE FROM t1 WHERE f1 = $max_row + 2 AND f2 = 'ZZZZZZZ'; +DELETE FROM t1 WHERE f1 = 0 - 1 AND f2 = 'ZZZZZZZ'; +# Select +SELECT COUNT(*) = 0 AS my_value FROM t1 WHERE f2 = 'ZZZZZZZ'; + +# Truncate +TRUNCATE t1; +# Select on empty table +SELECT COUNT(*) = 0 AS my_value FROM t1; diff --git a/mysql-test/suite/parts/inc/partition_11.inc b/mysql-test/suite/parts/inc/partition_11.inc new file mode 100644 index 00000000..9f10f58a --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_11.inc @@ -0,0 +1,34 @@ +# inc/partition_11.inc +# +# Try to create a table with the given partition number +# + +eval CREATE TABLE t1 ( f1 INTEGER, f2 char(20)) +PARTITION BY HASH(f1) PARTITIONS $part_number; +--disable_query_log +eval SET @my_errno= $mysql_errno ; +let $run= `SELECT @my_errno = 0`; +--enable_query_log +# +# If this operation was successfull, check + drop this table +if ($run) +{ + --source suite/parts/inc/partition_10.inc + eval DROP TABLE t1; +} +#### Try to create a table with the given subpartition number +eval CREATE TABLE t1 ( f1 INTEGER, f2 char(20)) +PARTITION BY RANGE(f1) SUBPARTITION BY HASH(f1) +SUBPARTITIONS $part_number +(PARTITION part1 VALUES LESS THAN ($max_row_div2), PARTITION part2 VALUES LESS THAN ($max_int_4)); +--disable_query_log +eval SET @my_errno= $mysql_errno ; +let $run= `SELECT @my_errno = 0`; +--enable_query_log +# +# If this operation was successfull, check + drop this table +if ($run) +{ + --source suite/parts/inc/partition_10.inc + eval DROP TABLE t1; +} diff --git a/mysql-test/suite/parts/inc/partition_12.inc b/mysql-test/suite/parts/inc/partition_12.inc new file mode 100644 index 00000000..c30990a6 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_12.inc @@ -0,0 +1,59 @@ +# inc/partition_12.inc +# +# Do some basic things on a table, if the SQL command executed just before +# sourcing this file was successful. +# + +--source suite/parts/inc/partition_layout.inc + +####### Variations with multiple records + # (mass) Insert max_row_div2 + 1 records + eval INSERT INTO t1 SELECT * FROM t0_template WHERE f1 BETWEEN $max_row_div2 AND $max_row; + # Select + eval SELECT (COUNT(*) = $max_row) AND (MIN(f1) = 1) AND (MAX(f1) = $max_row) + AS my_value FROM t1; + # DEBUG SELECT COUNT(*),MIN(f1),MAX(f1) FROM t1; + # (mass) Update $max_row_div4 * 2 + 1 records + eval UPDATE t1 SET f1 = f1 + $max_row + WHERE f1 BETWEEN $max_row_div2 - $max_row_div4 AND $max_row_div2 + $max_row_div4; + # Select + eval SELECT (COUNT(*) = $max_row) AND (MIN(f1) = 1) AND (MAX(f1) = $max_row_div2 + $max_row_div4 + $max_row ) + AS my_value FROM t1; + # DEBUG SELECT COUNT(*),MIN(f1),MAX(f1) FROM t1; + # (mass) Delete $max_row_div4 * 2 + 1 records + eval DELETE FROM t1 + WHERE f1 BETWEEN $max_row_div2 - $max_row_div4 + $max_row AND $max_row_div2 + $max_row_div4 + $max_row; + # Select + eval SELECT (COUNT(*) = $max_row - $max_row_div4 - $max_row_div4 - 1) AND (MIN(f1) = 1) AND (MAX(f1) = $max_row) + AS my_value FROM t1; + # DEBUG SELECT COUNT(*),MIN(f1),MAX(f1) FROM t1; + +####### Variations with single records +# Insert one record at beginning +INSERT INTO t1 SET f1 = 0 , f2 = '#######'; +# Select this record +SELECT COUNT(*) = 1 AS my_value FROM t1 WHERE f1 = 0 AND f2 = '#######'; +# Insert one record at end +eval INSERT INTO t1 SET f1 = $max_row + 1, f2 = '#######'; +# Select this record +eval SELECT COUNT(*) = 1 AS my_value FROM t1 WHERE f1 = $max_row + 1 AND f2 = '#######'; +# Update one record +eval UPDATE t1 SET f1 = $max_row + 2, f2 = 'ZZZZZZZ' + WHERE f1 = 0 AND f2 = '#######'; +# Select +eval SELECT COUNT(*) = 1 AS my_value FROM t1 WHERE f1 = $max_row + 2 AND f2 = 'ZZZZZZZ'; +# Bug #15968: Partitions: crash when INSERT with f1 = -1 into PARTITION BY HASH(f1) +eval UPDATE t1 SET f1 = 0 - 1, f2 = 'ZZZZZZZ' + WHERE f1 = $max_row + 1 AND f2 = '#######'; +# Select +SELECT COUNT(*) AS my_value FROM t1 WHERE f1 = 0 - 1 AND f2 = 'ZZZZZZZ'; +# Delete +eval DELETE FROM t1 WHERE f1 = $max_row + 2 AND f2 = 'ZZZZZZZ'; +DELETE FROM t1 WHERE f1 = 0 - 1 AND f2 = 'ZZZZZZZ'; +# Select +SELECT COUNT(*) = 0 AS my_value FROM t1 WHERE f2 = 'ZZZZZZZ'; + +# Truncate +TRUNCATE t1; +# Select on empty table +SELECT COUNT(*) = 0 AS my_value FROM t1; diff --git a/mysql-test/suite/parts/inc/partition_20.inc b/mysql-test/suite/parts/inc/partition_20.inc new file mode 100644 index 00000000..cc820b83 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_20.inc @@ -0,0 +1,43 @@ +################################################################################ +# inc/partition_20.inc # +# # +# Purpose: # +# Auxiliary script, only useful when sourced by # +# suite/parts/inc/partition_check.inc. # +# # +# 1. Check if the preceding statement caused that the expected number of # +# records was # +# - inserted # +# - updated or deleted+inserted # +# 2. Revert the modifications # +# # +# The parameters # +# @try_count = total number of inserted and updated or deleted+inserted # +# records # +# @clash_count = number of records where a DUPLICATE KEY appears # +# must be set before sourcing this routine. # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-03-05 # +# Change Author: # +# Change Date: # +# Change: # +################################################################################ + +if ($no_debug) +{ + --disable_query_log +} +eval SELECT '# check unique-$num-a success: ' AS "", COUNT(*) = @clash_count AS "" +FROM t1 WHERE f_charbig = 'was updated'; +eval SELECT '# check unique-$num-b success: ' AS "", COUNT(*) = @try_count AS "" +FROM t1 WHERE f_charbig IN ('was updated','was inserted'); +--enable_query_log +# Revert the modification +DELETE FROM t1 WHERE f_charbig = 'was inserted'; +UPDATE t1 SET f_int1 = CAST(f_char1 AS SIGNED INT), + f_int2 = CAST(f_char1 AS SIGNED INT), + f_charbig = CONCAT('===',f_char1,'===') +WHERE f_charbig = 'was updated'; +inc $num; diff --git a/mysql-test/suite/parts/inc/partition_alter1_1.inc b/mysql-test/suite/parts/inc/partition_alter1_1.inc new file mode 100644 index 00000000..0f904fcb --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_alter1_1.inc @@ -0,0 +1,67 @@ +################################################################################ +# inc/partition_alter1_1.inc # +# # +# Purpose: # +# ADD/DROP PRIMARY KEYs and/or UNIQUE INDEXes tests on partitioned tables # +# This routine is only useful for the partition_<feature>_<engine> tests. # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-03-05 # +# Change Author: # +# Change Date: # +# Change: # +################################################################################ + +--echo +--echo #======================================================================== +--echo # 1. ALTER TABLE ADD PRIMARY KEY and/or UNIQUE INDEX +--echo #======================================================================== +# Rule: The table does not have a PRIMARY KEY or UNIQUE INDEX. +# ---> $unique must be empty +# ---> The PRIMARY KEY or UNIQUE INDEX to be created must contain +# the columns used for partitioning. +--echo #------------------------------------------------------------------------ +--echo # 1.1 ADD PRIMARY KEY or UNIQUE INDEX to table with one column (f_int1) +--echo # within the partitioning function +--echo #------------------------------------------------------------------------ +# Rule: Only f_int1 is used within the partitioning function +# ---> inc/partition_alter_11.inc +if ($do_pk_tests) +{ + # The value of the following test is maybe covered by 1.1.3. + if ($more_pk_ui_tests) + { + --echo # 1.1.1 PRIMARY KEY consisting of one column + let $alter= ALTER TABLE t1 ADD PRIMARY KEY(f_int1); + --source suite/parts/inc/partition_alter_11.inc + } + # This must fail, because PRIMARY KEY does not contain f_int1 + let $alter= ALTER TABLE t1 ADD PRIMARY KEY(f_int2); + --source suite/parts/inc/partition_alter_11.inc +} +# The value of the following test is maybe covered by 1.1.4. +if ($more_pk_ui_tests) +{ + --echo # 1.1.2 UNIQUE INDEX consisting of one column + let $alter= ALTER TABLE t1 ADD UNIQUE INDEX uidx1 (f_int1); + --source suite/parts/inc/partition_alter_11.inc +} +# This must fail, because UNIQUE INDEX does not contain f_int1 +let $alter= ALTER TABLE t1 ADD UNIQUE INDEX uidx1 (f_int2); +--source suite/parts/inc/partition_alter_11.inc +if ($do_pk_tests) +{ + --echo # 1.1.3 PRIMARY KEY consisting of two columns + let $alter= ALTER TABLE t1 ADD PRIMARY KEY(f_int1,f_int2); + --source suite/parts/inc/partition_alter_11.inc + let $alter= ALTER TABLE t1 ADD PRIMARY KEY(f_int2,f_int1); + --source suite/parts/inc/partition_alter_11.inc +} +--echo # 1.1.4 UNIQUE INDEX consisting of two columns +let $alter= ALTER TABLE t1 ADD UNIQUE INDEX uidx1 (f_int1,f_int2); +--source suite/parts/inc/partition_alter_11.inc +let $alter= ALTER TABLE t1 ADD UNIQUE INDEX uidx1 (f_int2,f_int1); +--source suite/parts/inc/partition_alter_11.inc + + diff --git a/mysql-test/suite/parts/inc/partition_alter1_1_2.inc b/mysql-test/suite/parts/inc/partition_alter1_1_2.inc new file mode 100644 index 00000000..65dd3406 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_alter1_1_2.inc @@ -0,0 +1,54 @@ +################################################################################ +# inc/partition_alter1_1_2.inc # +# # +# Purpose: # +# ADD/DROP PRIMARY KEYs and/or UNIQUE INDEXes tests on partitioned tables # +# This routine is only useful for the partition_<feature>_<engine> tests. # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-03-05 # +# Change Author: # +# Change Date: # +# Change: # +################################################################################ + +--echo +--echo #======================================================================== +--echo # 1. ALTER TABLE ADD PRIMARY KEY and/or UNIQUE INDEX +--echo #======================================================================== +# Rule: The table does not have a PRIMARY KEY or UNIQUE INDEX. +# ---> $unique must be empty +# ---> The PRIMARY KEY or UNIQUE INDEX to be created must contain +# the columns used for partitioning. +# +--echo #------------------------------------------------------------------------ +--echo # 1.2 ADD PRIMARY KEY or UNIQUE INDEX to table with two columns +--echo # (f_int1 and f_int2) within the partitioning function +--echo #------------------------------------------------------------------------ +# Rule: f_int1 and f_int2 is used within the partitioning function +# ---> inc/partition_alter_13.inc +if ($do_pk_tests) +{ + --echo # 1.2.1 PRIMARY KEY consisting of two columns + let $alter= ALTER TABLE t1 ADD PRIMARY KEY(f_int1,f_int2); + --source suite/parts/inc/partition_alter_13.inc + let $alter= ALTER TABLE t1 ADD PRIMARY KEY(f_int2,f_int1); + --source suite/parts/inc/partition_alter_13.inc +} +--echo # 1.2.2 UNIQUE INDEX consisting of two columns +let $alter= ALTER TABLE t1 ADD UNIQUE INDEX uidx1 (f_int1,f_int2); +--source suite/parts/inc/partition_alter_13.inc +let $alter= ALTER TABLE t1 ADD UNIQUE INDEX uidx1 (f_int2,f_int1); +--source suite/parts/inc/partition_alter_13.inc +if ($do_pk_tests) +{ + --echo # 1.2.3 PRIMARY KEY and UNIQUE INDEX consisting of two columns + let $alter= ALTER TABLE t1 ADD UNIQUE INDEX uidx1 (f_int1,f_int2), ADD PRIMARY KEY(f_int2,f_int1); + --source suite/parts/inc/partition_alter_13.inc + let $alter= ALTER TABLE t1 ADD UNIQUE INDEX uidx1 (f_int2,f_int1), ADD PRIMARY KEY(f_int1,f_int2); + --source suite/parts/inc/partition_alter_13.inc + let $unique= ; + --source suite/parts/inc/partition_alter_13.inc +} + diff --git a/mysql-test/suite/parts/inc/partition_alter1_2.inc b/mysql-test/suite/parts/inc/partition_alter1_2.inc new file mode 100644 index 00000000..89e723cb --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_alter1_2.inc @@ -0,0 +1,126 @@ +################################################################################ +# inc/partition_alter1_2.inc # +# # +# Purpose: # +# ADD/DROP PRIMARY KEYs and/or UNIQUE INDEXes tests on partitioned tables # +# This routine is only useful for the partition_<feature>_<engine> tests. # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-03-05 # +# Change Author: # +# Change Date: # +# Change: # +################################################################################ +# +--echo +--echo #======================================================================== +--echo # 2 DROP PRIMARY KEY or UNIQUE INDEX +--echo #======================================================================== +# Rule: The table must have a PRIMARY KEY or UNIQUE INDEX. +# ---> $unique must not be empty +# ---> The PRIMARY KEY or UNIQUE INDEX to be dropped must contain +# the columns used for partitioning. +--echo #------------------------------------------------------------------------ +--echo # 2.1 Partitioning function contains one column(f_int1) +--echo #------------------------------------------------------------------------ +# Rule: Only f_int1 is used within the partitioning function +# ---> inc/partition_alter_11.inc +# The value of the following test is maybe covered by 2.1.5. +if ($more_pk_ui_tests) +{ + if ($do_pk_tests) + { + --echo # 2.1.1 DROP PRIMARY KEY consisting of one column + let $unique= , PRIMARY KEY(f_int1); + let $alter= ALTER TABLE t1 DROP PRIMARY KEY; + --source suite/parts/inc/partition_alter_11.inc + } + # + --echo # 2.1.2 DROP UNIQUE INDEX consisting of one column + let $unique= , UNIQUE INDEX uidx1 (f_int1); + let $alter= ALTER TABLE t1 DROP INDEX uidx1; + --source suite/parts/inc/partition_alter_11.inc + # + if ($do_pk_tests) + { + --echo # 2.1.3 DROP PRIMARY KEY consisting of two columns + let $alter= ALTER TABLE t1 DROP PRIMARY KEY; + let $unique= , PRIMARY KEY(f_int1,f_int2); + --source suite/parts/inc/partition_alter_11.inc + let $unique= , PRIMARY KEY(f_int2,f_int1); + --source suite/parts/inc/partition_alter_11.inc + } + # + --echo # 2.1.4 DROP UNIQUE INDEX consisting of two columns + let $alter= ALTER TABLE t1 DROP INDEX uidx1; + let $unique= , UNIQUE INDEX uidx1 (f_int1,f_int2); + --source suite/parts/inc/partition_alter_11.inc + let $unique= , UNIQUE INDEX uidx1 (f_int2,f_int1); + --source suite/parts/inc/partition_alter_11.inc + } +# +if ($do_pk_tests) +{ + --echo # 2.1.5 DROP PRIMARY KEY + UNIQUE INDEX consisting of two columns + let $unique= , UNIQUE INDEX uidx1 (f_int1,f_int2), PRIMARY KEY(f_int2,f_int1); + let $alter= ALTER TABLE t1 DROP PRIMARY KEY, DROP INDEX uidx1; + --source suite/parts/inc/partition_alter_11.inc + let $unique= , UNIQUE INDEX uidx1 (f_int2,f_int1), PRIMARY KEY(f_int1,f_int2); + let $alter= ALTER TABLE t1 DROP PRIMARY KEY, DROP INDEX uidx1; + --source suite/parts/inc/partition_alter_11.inc +} +let $unique= , UNIQUE INDEX uidx1 (f_int1,f_int2), UNIQUE INDEX uidx2 (f_int2,f_int1); +let $alter= ALTER TABLE t1 DROP INDEX uidx1, DROP INDEX uidx2; +--source suite/parts/inc/partition_alter_11.inc +# +--echo #------------------------------------------------------------------------ +--echo # 2.2 Partitioning function contains two columns (f_int1,f_int2) +--echo #------------------------------------------------------------------------ +# Rule: f_int1 and f_int2 is used within the partitioning function +# ---> inc/partition_alter_13.inc +if ($do_pk_tests) +{ + --echo # 2.2.1 DROP PRIMARY KEY consisting of two columns + let $alter= ALTER TABLE t1 DROP PRIMARY KEY; + let $unique= , PRIMARY KEY(f_int1,f_int2); + --source suite/parts/inc/partition_alter_13.inc + let $unique= , PRIMARY KEY(f_int2,f_int1); + --source suite/parts/inc/partition_alter_13.inc +} +# +--echo # 2.2.2 DROP UNIQUE INDEX consisting of two columns +let $alter= ALTER TABLE t1 DROP INDEX uidx1; +let $unique= , UNIQUE INDEX uidx1 (f_int1,f_int2); +--source suite/parts/inc/partition_alter_13.inc +let $unique= , UNIQUE INDEX uidx1 (f_int2,f_int1); +--source suite/parts/inc/partition_alter_13.inc +# +if ($do_pk_tests) +{ + --echo # 2.2.3 DROP PRIMARY KEY + UNIQUE INDEX consisting of two columns + let $unique= , UNIQUE INDEX uidx1 (f_int1,f_int2), PRIMARY KEY(f_int2,f_int1); + let $alter= ALTER TABLE t1 DROP PRIMARY KEY, DROP INDEX uidx1; + --source suite/parts/inc/partition_alter_13.inc + let $unique= , UNIQUE INDEX uidx1 (f_int2,f_int1), PRIMARY KEY(f_int1,f_int2); + let $alter= ALTER TABLE t1 DROP PRIMARY KEY, DROP INDEX uidx1; + --source suite/parts/inc/partition_alter_13.inc +} +let $unique= , UNIQUE INDEX uidx1 (f_int1,f_int2), UNIQUE INDEX uidx2 (f_int2,f_int1); +let $alter= ALTER TABLE t1 DROP INDEX uidx1, DROP INDEX uidx2; +--source suite/parts/inc/partition_alter_13.inc + +if (0) +{ +--echo +--echo #======================================================================== +--echo # 3. ALTER TABLE "ALTER" PRIMARY KEY +--echo # mleich: I think that an ALTER TABLE statement where a PRIMARY +--echo # KEY is dropped and recreated (with different layout) might +--echo # be of interest, if the tree containing the table data has +--echo # to be reorganized during this operation. +--echo # To be implemented +--echo #======================================================================== +--echo +} + diff --git a/mysql-test/suite/parts/inc/partition_alter2_1.inc b/mysql-test/suite/parts/inc/partition_alter2_1.inc new file mode 100644 index 00000000..23c083a7 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_alter2_1.inc @@ -0,0 +1,165 @@ +################################################################################ +# inc/partition_alter2_1.inc # +# # +# Purpose: # +# Tests where the columns used within the partitioning function are altered. # +# This routine is only useful for the partition_<feature>_<engine> tests. .# +# Part 1: increasing size of column +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-03-05 # +# Change Author: MattiasJ # +# Change Date: 2008-09-08 # +# Change: Splitted the test in two different parts (increasing/decreasing col) # +################################################################################ + +if (!$only_part_2) +{ +--echo +--echo #======================================================================== +--echo # 1 Increase the size of the column used in the partitioning +--echo # function and/or PRIMARY KEY and/or UNIQUE INDEX +--echo #======================================================================== +--echo #------------------------------------------------------------------------ +--echo # 1.1 ALTER column f_int2 not used in partitioning function +--echo #------------------------------------------------------------------------ +# Rule: Only f_int1 is used within the partitioning function +# ---> inc/partition_alter_11.inc +let $alter= ALTER TABLE t1 MODIFY f_int2 BIGINT; +--echo # 1.1.1 no PRIMARY KEY or UNIQUE INDEX exists +let $unique= ; +--source suite/parts/inc/partition_alter_11.inc +# +if ($do_pk_tests) +{ + --echo # 1.1.2 PRIMARY KEY exists + # The value of the direct following test is maybe covered by the test with + # the PRIMARY KEY containing two columns. + if ($more_pk_ui_tests) + { + let $unique= , PRIMARY KEY (f_int1); + --source suite/parts/inc/partition_alter_11.inc + } + let $unique= , PRIMARY KEY (f_int1,f_int2); + --source suite/parts/inc/partition_alter_11.inc + let $unique= , PRIMARY KEY (f_int2,f_int1); + --source suite/parts/inc/partition_alter_11.inc +} +# +--echo # 1.1.3 UNIQUE INDEX exists +# The value of the direct following test is maybe covered by the test with +# the UNIQUE INDEX containing two columns +if ($more_pk_ui_tests) +{ + let $unique= , UNIQUE INDEX uidx1 (f_int1); + --source suite/parts/inc/partition_alter_11.inc +} +let $unique= , UNIQUE INDEX uidx1 (f_int1,f_int2); +--source suite/parts/inc/partition_alter_11.inc +let $unique= , UNIQUE INDEX uidx1 (f_int2,f_int1); +--source suite/parts/inc/partition_alter_11.inc +# +if ($more_pk_ui_tests) +{ + # The value of the tests 1.2 is maybe covered by the tests 1.3 + --echo #------------------------------------------------------------------------ + --echo # 1.2 ALTER column f_int1 used in partitioning function + --echo #------------------------------------------------------------------------ + # Rule: Only f_int1 is used within the partitioning function + # ---> inc/partition_alter_11.inc + let $alter= ALTER TABLE t1 MODIFY f_int1 BIGINT; + --echo # 1.2.1 no PRIMARY KEY or UNIQUE INDEX exists + let $unique= ; + --source suite/parts/inc/partition_alter_11.inc + --source suite/parts/inc/partition_alter_13.inc + # + if ($do_pk_tests) + { + --echo # 1.2.2 PRIMARY KEY exists + let $unique= , PRIMARY KEY (f_int1); + --source suite/parts/inc/partition_alter_11.inc + let $unique= , PRIMARY KEY (f_int1,f_int2); + --source suite/parts/inc/partition_alter_11.inc + --source suite/parts/inc/partition_alter_13.inc + let $unique= , PRIMARY KEY (f_int2,f_int1); + --source suite/parts/inc/partition_alter_11.inc + --source suite/parts/inc/partition_alter_13.inc + } + # + --echo # 1.2.3 UNIQUE INDEX exists + let $unique= , UNIQUE INDEX uidx (f_int1); + --source suite/parts/inc/partition_alter_11.inc + let $unique= , UNIQUE INDEX uidx (f_int1,f_int2); + #--source suite/parts/inc/partition_alter_11.inc + --source suite/parts/inc/partition_alter_13.inc + let $unique= , UNIQUE INDEX uidx (f_int2,f_int1); + #--source suite/parts/inc/partition_alter_11.inc + --source suite/parts/inc/partition_alter_13.inc +} +} +# +if (!$only_part_1) +{ +--echo #------------------------------------------------------------------------ +--echo # 1.3 ALTER column f_int1 and f_int2 +--echo # f_int1 or (f_int1 and f_int2) used in partitioning function +--echo #------------------------------------------------------------------------ +# Rule: f_int1 and f_int2 is used within the partitioning function +# ---> inc/partition_alter_13.inc +let $alter= ALTER TABLE t1 MODIFY f_int1 BIGINT, MODIFY f_int2 BIGINT; +--echo # 1.3.1 no PRIMARY KEY or UNIQUE INDEX exists +let $unique= ; +#--source suite/parts/inc/partition_alter_11.inc +--source suite/parts/inc/partition_alter_13.inc +# +if ($do_pk_tests) +{ + --echo # 1.3.2 PRIMARY KEY exists + # The value of the direct following test is maybe covered by the test with + # the PRIMARY KEY containing two columns. + if ($more_pk_ui_tests) + { + let $unique= , PRIMARY KEY (f_int1); + --source suite/parts/inc/partition_alter_11.inc + } + let $unique= , PRIMARY KEY (f_int1,f_int2); + #--source suite/parts/inc/partition_alter_11.inc + --source suite/parts/inc/partition_alter_13.inc + let $unique= , PRIMARY KEY (f_int2,f_int1); + #--source suite/parts/inc/partition_alter_11.inc + --source suite/parts/inc/partition_alter_13.inc +} +# +--echo # 1.3.3 UNIQUE INDEX exists +# The value of the direct following test is maybe covered by the test with +# the UNIQUE INDEX containing two columns. +if ($more_pk_ui_tests) +{ + let $unique= , UNIQUE INDEX uidx (f_int1); + --source suite/parts/inc/partition_alter_11.inc +} +let $unique= , UNIQUE INDEX uidx (f_int1,f_int2); +#--source suite/parts/inc/partition_alter_11.inc +--source suite/parts/inc/partition_alter_13.inc +let $unique= , UNIQUE INDEX uidx (f_int2,f_int1); +#--source suite/parts/inc/partition_alter_11.inc +--source suite/parts/inc/partition_alter_13.inc +} + +if (0) +{ +--echo +--echo #======================================================================== +--echo # 3 ALTER the type of the column used in the partitioning +--echo # function and/or PRIMARY KEY and/or UNIQUE INDEX +--echo # INTEGER --> FLOAT +--echo # INTEGER --> DECIMAL +--echo # INTEGER --> VARCHAR +--echo # mleich: I assume that at least the first two variants are of +--echo # some interest. But I am unsure if the server allows such +--echo # conversions. I also think that such operations have a +--echo # conversions very small likelihood. +--echo # To be implemented. +--echo #======================================================================== +} diff --git a/mysql-test/suite/parts/inc/partition_alter2_2.inc b/mysql-test/suite/parts/inc/partition_alter2_2.inc new file mode 100644 index 00000000..37dca198 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_alter2_2.inc @@ -0,0 +1,165 @@ +################################################################################ +# inc/partition_alter2_2.inc # +# # +# Purpose: # +# Tests where the columns used within the partitioning function are altered. # +# This routine is only useful for the partition_<feature>_<engine> tests. .# +# Part 2: decreasing size of column +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-03-05 # +# Change Author: MattiasJ # +# Change Date: 2008-09-08 # +# Change: Splitted the test in two different parts (increasing/decreasing col) # +################################################################################ + +if (!$only_part_2) +{ +--echo +--echo #======================================================================== +--echo # 2 Decrease the size of the column used in the partitioning +--echo # function and/or PRIMARY KEY and/or UNIQUE INDEX +--echo #======================================================================== +--echo #------------------------------------------------------------------------ +--echo # 2.1 ALTER column f_int2 not used in partitioning function +--echo #------------------------------------------------------------------------ +# Rule: Only f_int1 is used within the partitioning function +# ---> inc/partition_alter_11.inc +let $alter= ALTER TABLE t1 MODIFY f_int2 MEDIUMINT; +--echo # 2.1.1 no PRIMARY KEY or UNIQUE INDEX exists +let $unique= ; +--source suite/parts/inc/partition_alter_11.inc +# +if ($do_pk_tests) +{ + # The value of the direct following test is maybe covered by the test with + # the PRIMARY KEY containing two columns. + if ($more_pk_ui_tests) + { + --echo # 2.1.2 PRIMARY KEY exists + let $unique= , PRIMARY KEY (f_int1); + --source suite/parts/inc/partition_alter_11.inc + } + let $unique= , PRIMARY KEY (f_int1,f_int2); + --source suite/parts/inc/partition_alter_11.inc + let $unique= , PRIMARY KEY (f_int2,f_int1); + --source suite/parts/inc/partition_alter_11.inc +} +# +--echo # 2.1.3 UNIQUE INDEX exists +# The value of the direct following test is maybe covered by the test with +# the UNIQUE INDEX containing two columns. +if ($more_pk_ui_tests) +{ + let $unique= , UNIQUE INDEX uidx1 (f_int1); + --source suite/parts/inc/partition_alter_11.inc +} +let $unique= , UNIQUE INDEX uidx1 (f_int1,f_int2); +--source suite/parts/inc/partition_alter_11.inc +let $unique= , UNIQUE INDEX uidx1 (f_int2,f_int1); +--source suite/parts/inc/partition_alter_11.inc +# +if ($more_pk_ui_tests) +{ + # The value of the tests 2.2 is maybe covered by the tests 2.3 + --echo #------------------------------------------------------------------------ + --echo # 2.2 ALTER column f_int1 used in partitioning function + --echo #------------------------------------------------------------------------ + # Rule: Only f_int1 is used within the partitioning function + # ---> inc/partition_alter_11.inc + let $alter= ALTER TABLE t1 MODIFY f_int1 MEDIUMINT; + --echo # 2.2.1 no PRIMARY KEY or UNIQUE INDEX exists + let $unique= ; + --source suite/parts/inc/partition_alter_11.inc + --source suite/parts/inc/partition_alter_13.inc + # + if ($do_pk_tests) + { + --echo # 2.2.2 PRIMARY KEY exists + let $unique= , PRIMARY KEY (f_int1); + --source suite/parts/inc/partition_alter_11.inc + let $unique= , PRIMARY KEY (f_int1,f_int2); + --source suite/parts/inc/partition_alter_11.inc + --source suite/parts/inc/partition_alter_13.inc + let $unique= , PRIMARY KEY (f_int2,f_int1); + --source suite/parts/inc/partition_alter_11.inc + --source suite/parts/inc/partition_alter_13.inc + } + # + --echo # 2.2.3 UNIQUE INDEX exists + let $unique= , UNIQUE INDEX uidx (f_int1); + --source suite/parts/inc/partition_alter_11.inc + let $unique= , UNIQUE INDEX uidx (f_int1,f_int2); + --source suite/parts/inc/partition_alter_11.inc + --source suite/parts/inc/partition_alter_13.inc + let $unique= , UNIQUE INDEX uidx (f_int2,f_int1); + --source suite/parts/inc/partition_alter_11.inc + --source suite/parts/inc/partition_alter_13.inc +} +} +# +if (!$only_part_1) +{ +--echo #------------------------------------------------------------------------ +--echo # 2.3 ALTER column f_int1 and f_int2 used in partitioning function +--echo #------------------------------------------------------------------------ +# Rule: f_int1 and f_int2 is used within the partitioning function +# ---> inc/partition_alter_13.inc +let $alter= ALTER TABLE t1 MODIFY f_int1 MEDIUMINT, MODIFY f_int2 MEDIUMINT; +--echo # 2.3.1 no PRIMARY KEY or UNIQUE INDEX exists +let $unique= ; +#--source suite/parts/inc/partition_alter_11.inc +--source suite/parts/inc/partition_alter_13.inc +# +if ($do_pk_tests) +{ + --echo # 2.3.2 PRIMARY KEY exists + # The value of the direct following test is maybe covered by the test with + # the PRIMARY KEY containing two columns. + if ($more_pk_ui_tests) + { + let $unique= , PRIMARY KEY (f_int1); + --source suite/parts/inc/partition_alter_11.inc + } + let $unique= , PRIMARY KEY (f_int1,f_int2); + #--source suite/parts/inc/partition_alter_11.inc + --source suite/parts/inc/partition_alter_13.inc + let $unique= , PRIMARY KEY (f_int2,f_int1); + #--source suite/parts/inc/partition_alter_11.inc + --source suite/parts/inc/partition_alter_13.inc +} +# +--echo # 2.3.3 UNIQUE INDEX exists +# The value of the direct following test is maybe covered by the test with +# the UNIQUE INDEX containing two columns. +if ($more_pk_ui_tests) +{ + let $unique= , UNIQUE INDEX uidx (f_int1); + --source suite/parts/inc/partition_alter_11.inc +} +let $unique= , UNIQUE INDEX uidx (f_int1,f_int2); +#--source suite/parts/inc/partition_alter_11.inc +--source suite/parts/inc/partition_alter_13.inc +let $unique= , UNIQUE INDEX uidx (f_int2,f_int1); +#--source suite/parts/inc/partition_alter_11.inc +--source suite/parts/inc/partition_alter_13.inc +} +# + +if (0) +{ +--echo +--echo #======================================================================== +--echo # 3 ALTER the type of the column used in the partitioning +--echo # function and/or PRIMARY KEY and/or UNIQUE INDEX +--echo # INTEGER --> FLOAT +--echo # INTEGER --> DECIMAL +--echo # INTEGER --> VARCHAR +--echo # mleich: I assume that at least the first two variants are of +--echo # some interest. But I am unsure if the server allows such +--echo # conversions. I also think that such operations have a +--echo # conversions very small likelihood. +--echo # To be implemented. +--echo #======================================================================== +} diff --git a/mysql-test/suite/parts/inc/partition_alter3.inc b/mysql-test/suite/parts/inc/partition_alter3.inc new file mode 100644 index 00000000..395f93f4 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_alter3.inc @@ -0,0 +1,201 @@ +################################################################################ +# inc/partition_alter3.inc # +# # +# Purpose: # +# Tests for partition management commands for HASH and KEY partitioning # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-04-11 # +# Change Author: # +# Change Date: # +# Change: # +################################################################################ + +--echo +--echo #======================================================================== +--echo # 1. Partition management commands on HASH partitioned table +--echo # column in partitioning function is of type DATE +--echo #======================================================================== +# 1. Create the table +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings +eval CREATE TABLE t1 (f_date DATE, f_varchar VARCHAR(30)); +# 2. Fill the table t1 with records +INSERT INTO t1 (f_date, f_varchar) +SELECT CONCAT(CAST((f_int1 + 999) AS CHAR),'-02-10'), CAST(f_char1 AS CHAR) +FROM t0_template +WHERE f_int1 + 999 BETWEEN 1000 AND 9999; +# 3. Calculate the number of inserted records. +SELECT IF(9999 - 1000 + 1 > @max_row, @max_row , 9999 - 1000 + 1) + INTO @exp_row_count; +# DEBUG SELECT @exp_row_count; +# 4. Print the layout, check Readability +--source suite/parts/inc/partition_layout.inc +--source suite/parts/inc/partition_check_read1.inc +# +--echo #------------------------------------------------------------------------ +--echo # 1.1 Increase number of PARTITIONS +--echo #------------------------------------------------------------------------ +--echo # 1.1.1 ADD PARTITION to not partitioned table --> must fail +--error ER_PARTITION_MGMT_ON_NONPARTITIONED +ALTER TABLE t1 ADD PARTITION (PARTITION part2); +# +--echo # 1.1.2 Assign HASH partitioning +ALTER TABLE t1 PARTITION BY HASH(YEAR(f_date)); +--source suite/parts/inc/partition_layout.inc +--source suite/parts/inc/partition_check_read1.inc +# +--echo # 1.1.3 Assign other HASH partitioning to already partitioned table +--echo # + test and switch back + test +ALTER TABLE t1 PARTITION BY HASH(DAYOFYEAR(f_date)); +--source suite/parts/inc/partition_layout.inc +--source suite/parts/inc/partition_check_read1.inc +ALTER TABLE t1 PARTITION BY HASH(YEAR(f_date)); +--source suite/parts/inc/partition_layout.inc +--source suite/parts/inc/partition_check_read1.inc +# +--echo # 1.1.4 Add PARTITIONS not fitting to HASH --> must fail +--error ER_PARTITION_WRONG_VALUES_ERROR +ALTER TABLE t1 ADD PARTITION (PARTITION part1 VALUES IN (0)); +--error ER_PARTITION_WRONG_VALUES_ERROR +ALTER TABLE t1 ADD PARTITION (PARTITION part2 VALUES LESS THAN (0)); +# +--echo # 1.1.5 Add two named partitions + test +ALTER TABLE t1 ADD PARTITION (PARTITION part1, PARTITION part7); +--source suite/parts/inc/partition_layout.inc +--source suite/parts/inc/partition_check_read1.inc +# +--echo # 1.1.6 Add two named partitions, name clash --> must fail +--error ER_SAME_NAME_PARTITION +ALTER TABLE t1 ADD PARTITION (PARTITION part1, PARTITION part7); +# +--echo # 1.1.7 Add one named partition + test +ALTER TABLE t1 ADD PARTITION (PARTITION part2); +--source suite/parts/inc/partition_layout.inc +--source suite/parts/inc/partition_check_read1.inc +# +--echo # 1.1.8 Add four not named partitions + test +ALTER TABLE t1 ADD PARTITION PARTITIONS 4; +--source suite/parts/inc/partition_layout.inc +--source suite/parts/inc/partition_check_read1.inc + +--echo #------------------------------------------------------------------------ +--echo # 1.2 Decrease number of PARTITIONS +--echo #------------------------------------------------------------------------ +--echo # 1.2.1 DROP PARTITION is not supported for HASH --> must fail +--error ER_ONLY_ON_RANGE_LIST_PARTITION +ALTER TABLE t1 DROP PARTITION part1; +# +--echo # 1.2.2 COALESCE PARTITION partitionname is not supported +--error ER_PARSE_ERROR +ALTER TABLE t1 COALESCE PARTITION part1; +# +--echo # 1.2.3 Decrease by 0 is non sense --> must fail +--error ER_COALESCE_PARTITION_NO_PARTITION +ALTER TABLE t1 COALESCE PARTITION 0; +# +--echo # 1.2.4 COALESCE one partition + test loop +let $loop= 7; +while ($loop) +{ + ALTER TABLE t1 COALESCE PARTITION 1; + --source suite/parts/inc/partition_layout.inc + --source suite/parts/inc/partition_check_read1.inc + dec $loop; +} +--echo # 1.2.5 COALESCE of last partition --> must fail +--error ER_DROP_LAST_PARTITION +ALTER TABLE t1 COALESCE PARTITION 1; +# +--echo # 1.2.6 Remove partitioning +ALTER TABLE t1 REMOVE PARTITIONING; +--source suite/parts/inc/partition_layout.inc +--source suite/parts/inc/partition_check_read1.inc +# +--echo # 1.2.7 Remove partitioning from not partitioned table --> ???? +--error ER_PARTITION_MGMT_ON_NONPARTITIONED +ALTER TABLE t1 REMOVE PARTITIONING; +DROP TABLE t1; +--source suite/parts/inc/partition_check_drop.inc + +--echo +--echo #======================================================================== +--echo # 2. Partition management commands on KEY partitioned table +--echo #======================================================================== +# 1. Create the table +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings +eval CREATE TABLE t1 ( +$column_list +); +# 2. Fill the table t1 with some records +eval $insert_all; +# 4. Print the layout, check Readability +--source suite/parts/inc/partition_layout.inc +--source suite/parts/inc/partition_check_read2.inc +# +--echo #------------------------------------------------------------------------ +--echo # 2.1 Increase number of PARTITIONS +--echo # Some negative testcases are omitted (already checked with HASH). +--echo #------------------------------------------------------------------------ +--echo # 2.1.1 Assign KEY partitioning +ALTER TABLE t1 PARTITION BY KEY(f_int1); +--source suite/parts/inc/partition_layout.inc +--source suite/parts/inc/partition_check_read2.inc +# +--echo # 2.1.2 Add PARTITIONS not fitting to KEY --> must fail +--error ER_PARTITION_WRONG_VALUES_ERROR +ALTER TABLE t1 ADD PARTITION (PARTITION part1 VALUES IN (0)); +--error ER_PARTITION_WRONG_VALUES_ERROR +ALTER TABLE t1 ADD PARTITION (PARTITION part2 VALUES LESS THAN (0)); +# +--echo # 2.1.3 Add two named partitions + test +ALTER TABLE t1 ADD PARTITION (PARTITION part1, PARTITION part7); +--source suite/parts/inc/partition_layout.inc +--source suite/parts/inc/partition_check_read2.inc +# +--echo # 2.1.4 Add one named partition + test +ALTER TABLE t1 ADD PARTITION (PARTITION part2); +--source suite/parts/inc/partition_layout.inc +--source suite/parts/inc/partition_check_read2.inc +# +--echo # 2.1.5 Add four not named partitions + test +ALTER TABLE t1 ADD PARTITION PARTITIONS 4; +--source suite/parts/inc/partition_layout.inc +--source suite/parts/inc/partition_check_read2.inc + +--echo #------------------------------------------------------------------------ +--echo # 2.2 Decrease number of PARTITIONS +--echo # Some negative testcases are omitted (already checked with HASH). +--echo #------------------------------------------------------------------------ +--echo # 2.2.1 DROP PARTITION is not supported for KEY --> must fail +--error ER_ONLY_ON_RANGE_LIST_PARTITION +ALTER TABLE t1 DROP PARTITION part1; +# +--echo # 2.2.4 COALESCE one partition + test loop +let $loop= 7; +while ($loop) +{ + ALTER TABLE t1 COALESCE PARTITION 1; + --source suite/parts/inc/partition_layout.inc + --source suite/parts/inc/partition_check_read2.inc + dec $loop; +} +--echo # 2.2.5 COALESCE of last partition --> must fail +--error ER_DROP_LAST_PARTITION +ALTER TABLE t1 COALESCE PARTITION 1; +# +--echo # 2.2.6 Remove partitioning +ALTER TABLE t1 REMOVE PARTITIONING; +--source suite/parts/inc/partition_layout.inc +--source suite/parts/inc/partition_check_read2.inc +# +--echo # 2.2.7 Remove partitioning from not partitioned table --> ???? +--error ER_PARTITION_MGMT_ON_NONPARTITIONED +ALTER TABLE t1 REMOVE PARTITIONING; +DROP TABLE t1; +--source suite/parts/inc/partition_check_drop.inc + diff --git a/mysql-test/suite/parts/inc/partition_alter4.inc b/mysql-test/suite/parts/inc/partition_alter4.inc new file mode 100644 index 00000000..74b1f3a2 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_alter4.inc @@ -0,0 +1,120 @@ +################################################################################ +# inc/partition_alter1.inc # +# # +# Purpose: # +# Execute ALTER ... OPTIMIZE/CHECK/REBUID/ANALYZE statements (maintenance) # +# # +#------------------------------------------------------------------------------# +# Original Author: HH # +# Original Date: 2006-07-27 # +# Change Author: # +# Change Date: # +# Change: # +################################################################################ + +--echo +--echo #======================================================================== +--echo # 1.1.1.12 ALTER TABLE <maintenance> PARTITION +--echo #======================================================================== +--echo #------------------------------------------------------------------------ +--echo # 1 ALTER ... ANALYZE PARTITION +--echo #------------------------------------------------------------------------ +--echo # 1.1 ALTER ... ANALYZE PARTITION part_1; +let $alter= ALTER TABLE t1 ANALYZE PARTITION part_1; +--source suite/parts/inc/partition_alter_41.inc +--echo # 1.2 ALTER ... ANALYZE PARTITION part_1,part_2; +let $alter= ALTER TABLE t1 ANALYZE PARTITION part_1,part_2; +--source suite/parts/inc/partition_alter_41.inc +--echo # 1.3 ALTER ... ANALYZE PARTITION part_1,part_2,part_5,part_6,part_10; +let $alter= ALTER TABLE t1 ANALYZE PARTITION part_1,part_2,part_5,part_6,part_10; +--source suite/parts/inc/partition_alter_41.inc +--echo # 1.4 ALTER ... ANALYZE PARTITION part_1,part_1,part_1; +let $alter= ALTER TABLE t1 ANALYZE PARTITION part_1,part_1,part_1; +--source suite/parts/inc/partition_alter_41.inc +--echo # 1.5 ALTER ... ANALYZE PARTITION ALL; +let $alter= ALTER TABLE t1 ANALYZE PARTITION ALL; +--source suite/parts/inc/partition_alter_41.inc + +--echo #------------------------------------------------------------------------ +--echo # 2 ALTER ... CHECK PARTITION +--echo #------------------------------------------------------------------------ +--echo # 2.1 ALTER ... CHECK PARTITION part_1; +let $alter= ALTER TABLE t1 CHECK PARTITION part_1; +--source suite/parts/inc/partition_alter_41.inc +--echo # 2.2 ALTER ... CHECK PARTITION part_1,part_2; +let $alter= ALTER TABLE t1 CHECK PARTITION part_1,part_2; +--source suite/parts/inc/partition_alter_41.inc +--echo # 2.3 ALTER ... CHECK PARTITION part_1,part_2,part_5,part_6,part_10; +let $alter= ALTER TABLE t1 CHECK PARTITION part_1,part_2,part_5,part_6,part_10; +--source suite/parts/inc/partition_alter_41.inc +--echo # 2.4 ALTER ... CHECK PARTITION part_1,part_1,part_1; +let $alter= ALTER TABLE t1 CHECK PARTITION part_1,part_1,part_1; +--source suite/parts/inc/partition_alter_41.inc +--echo # 2.5 ALTER ... CHECK PARTITION ALL; +let $alter= ALTER TABLE t1 CHECK PARTITION ALL; +--source suite/parts/inc/partition_alter_41.inc + +--echo #------------------------------------------------------------------------ +--echo # 3 ALTER ... OPTIMIZE PARTITION +--echo #------------------------------------------------------------------------ +--echo # 3.1 ALTER ... OPTIMIZE PARTITION part_1; +let $alter= ALTER TABLE t1 OPTIMIZE PARTITION part_1; +--source suite/parts/inc/partition_alter_41.inc +--echo # 3.2 ALTER ... OPTIMIZE PARTITION part_1,part_2; +let $alter= ALTER TABLE t1 OPTIMIZE PARTITION part_1,part_2; +--source suite/parts/inc/partition_alter_41.inc +--echo # 3.3 ALTER ... OPTIMIZE PARTITION part_1,part_2,part_5,part_6,part_10; +let $alter= ALTER TABLE t1 OPTIMIZE PARTITION part_1,part_2,part_5,part_6,part_10; +--source suite/parts/inc/partition_alter_41.inc +--echo # 3.4 ALTER ... OPTIMIZE PARTITION part_1,part_1,part_1; +let $alter= ALTER TABLE t1 OPTIMIZE PARTITION part_1,part_1,part_1; +--source suite/parts/inc/partition_alter_41.inc +--echo # 3.5 ALTER ... OPTIMIZE PARTITION ALL; +let $alter= ALTER TABLE t1 OPTIMIZE PARTITION ALL; +--source suite/parts/inc/partition_alter_41.inc + +--echo #------------------------------------------------------------------------ +--echo # 4 ALTER ... REBUILD PARTITION +--echo #------------------------------------------------------------------------ +--echo # 4.1 ALTER ... REBUILD PARTITION part_1; +let $alter= ALTER TABLE t1 REBUILD PARTITION part_1; +--source suite/parts/inc/partition_alter_41.inc +--echo # 4.2 ALTER ... REBUILD PARTITION part_1,part_2; +let $alter= ALTER TABLE t1 REBUILD PARTITION part_1,part_2; +--source suite/parts/inc/partition_alter_41.inc +--echo # 4.3 ALTER ... REBUILD PARTITION part_1,part_2,part_5,part_6,part_10; +let $alter= ALTER TABLE t1 REBUILD PARTITION part_1,part_2,part_5,part_6,part_10; +--source suite/parts/inc/partition_alter_41.inc +--echo # 4.4 ALTER ... REBUILD PARTITION part_1,part_1,part_1; +let $alter= ALTER TABLE t1 REBUILD PARTITION part_1,part_1,part_1; +--source suite/parts/inc/partition_alter_41.inc +--echo # 4.5 ALTER ... REBUILD PARTITION ALL; +let $alter= ALTER TABLE t1 REBUILD PARTITION ALL; +--source suite/parts/inc/partition_alter_41.inc + +--echo #------------------------------------------------------------------------ +--echo # 5 ALTER ... REPAIR PARTITION +--echo #------------------------------------------------------------------------ +--echo # 5.1 ALTER ... REPAIR PARTITION part_1; +let $alter= ALTER TABLE t1 REPAIR PARTITION part_1; +--source suite/parts/inc/partition_alter_41.inc +--echo # 5.2 ALTER ... REPAIR PARTITION part_1,part_2; +let $alter= ALTER TABLE t1 REPAIR PARTITION part_1,part_2; +--source suite/parts/inc/partition_alter_41.inc +--echo # 5.3 ALTER ... REPAIR PARTITION part_1,part_2,part_5,part_6,part_10; +let $alter= ALTER TABLE t1 REPAIR PARTITION part_1,part_2,part_5,part_6,part_10; +--source suite/parts/inc/partition_alter_41.inc +--echo # 5.4 ALTER ... REPAIR PARTITION part_1,part_1,part_1; +let $alter= ALTER TABLE t1 REPAIR PARTITION part_1,part_1,part_1; +--source suite/parts/inc/partition_alter_41.inc +--echo # 5.5 ALTER ... REPAIR PARTITION ALL; +let $alter= ALTER TABLE t1 REPAIR PARTITION ALL; +--source suite/parts/inc/partition_alter_41.inc + +--echo #------------------------------------------------------------------------ +--echo # 6 ALTER ... REMOVE PARTITIONING +--echo #------------------------------------------------------------------------ +--echo # 6.1 ALTER ... REMOVE PARTITIONING; +let $alter= ALTER TABLE t1 REMOVE PARTITIONING; +--source suite/parts/inc/partition_alter_41.inc + diff --git a/mysql-test/suite/parts/inc/partition_alter_1.inc b/mysql-test/suite/parts/inc/partition_alter_1.inc new file mode 100644 index 00000000..a348407a --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_alter_1.inc @@ -0,0 +1,72 @@ +################################################################################ +# inc/partition_alter_1.inc # +# # +# Purpose: # +# Alter a partioned table and check the usability afterwards # +# This script is only usefule when sourced by # +# inc/partition_alter_1[1|3].inc # +# # +# 0. Expect there is a table t1 # +# 1. Insert the first half of the table t0_template into t1 # +# 2. Execute the ALTER TABLE statement within the variable $alter # +# Case SQL code in # +# 0: 1. Insert the second half of the table t0_template into t1 # +# 2. Execute the usability test inc/partition_check.inc # +# >0, but expected: nothing # +# >0 and unexpected: abort # +# 3. DROP the table t1 # +# # +# The parameter $alter has to be set before sourcing this script. # +# Example: # +# CREATE TABLE t1 (f_int1 INT,f_int2 INT, .... ); # +# let $alter= ALTER TABLE t1 ADD PRIMARY KEY(f_int2); # +# inc/partition_alter_1.inc # +# # +# The parameters $insert_first_half and $insert_second_half # +# are also to be set outside (source ./inc/partition.pre). # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-03-05 # +# Change Author: mleich # +# Change Date: 2007-10-08 # +# Change: Fix for # +# Bug#31481 test suite parts: Many tests fail because of # +# changed server error codes # +################################################################################ + +eval $insert_first_half; +# Possible/Expected return codes for ALTER TABLE ... +# 0 +# 1030: ER_GET_ERRNO +# 1502: ER_UNIQUE_KEY_NEED_ALL_FIELDS_IN_PF +# 1506: ER_PARTITION_DOES_NOT_EXIST +--disable_abort_on_error +eval $alter; +--enable_abort_on_error +if ($no_debug) +{ +--disable_query_log +} +eval SET @my_errno = $mysql_errno; +let $run_test= `SELECT @my_errno = 0`; +if (`SELECT @my_errno NOT IN (0,$ER_GET_ERRNO, + $ER_UNIQUE_KEY_NEED_ALL_FIELDS_IN_PF, + $ER_PARTITION_DOES_NOT_EXIST)`); +{ + --echo # The last command got an unexepected error response. + --echo # Expected/handled SQL codes are 0,$ER_GET_ERRNO,$ER_UNIQUE_KEY_NEED_ALL_FIELDS_IN_PF,$ER_PARTITION_DOES_NOT_EXIST + SELECT '# SQL code we got was: ' AS "", @my_errno AS ""; + --echo # Sorry, have to abort. + --echo # Please check the error name to number mapping in inc/partition.pre. + exit; + --echo +} +--enable_query_log +# Prevent execution of following usage tests, when ALTER TABLE failed +if ($run_test) +{ +eval $insert_second_half; +--source suite/parts/inc/partition_check.inc +} +DROP TABLE t1; diff --git a/mysql-test/suite/parts/inc/partition_alter_11.inc b/mysql-test/suite/parts/inc/partition_alter_11.inc new file mode 100644 index 00000000..9d9800e3 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_alter_11.inc @@ -0,0 +1,180 @@ +################################################################################ +# inc/partition_alter_11.inc # +# # +# Purpose: # +# Check ALTER partitioned table and the state of the table afterwards # +# The partitioning function use the column f_int1 # +# # +# For all partitioning methods # +# PARTITION BY HASH/KEY/LIST/RANGE # +# PARTITION BY RANGE/LIST ... SUBPARTITION BY HASH/KEY ... # +# do # +# 1. Create the partitioned table # +# 2. Execute inc/partition_alter_1.inc, which will # +# - Insert the first half of the table t0_template into t1 # +# - Execute the ALTER TABLE statement # +# - Insert the second half of the table t0_template into t1 # +# - Execute the usability test include/partition_check.inc # +# - Drop the table t1 # +# done # +# # +# The parameters # +# $unique -- PRIMARY KEY or UNIQUE INDEXes to be created within the # +# CREATE TABLE STATEMENT # +# $alter -- ALTER TABLE statement, which has to be executed # +# have to be set before sourcing this routine. # +# Example: # +# let $unique= , UNIQUE INDEX uidx1 (f_int1); # +# let $alter= ALTER TABLE t1 DROP UNIQUE INDEX uidx1; # +# inc/partition_alter1.inc # +# # +# Attention: The routine include/partition_alter_13.inc is very similar # +# to this one. So if something has to be changed here it # +# might be necessary to do it also there # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-03-05 # +# Change Author: # +# Change Date: # +# Change: # +################################################################################ + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +let $partitioning= ; +#----------- PARTITION BY HASH +if ($with_partitioning) +{ +let $partitioning= PARTITION BY HASH(f_int1) PARTITIONS 2; +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +--source suite/parts/inc/partition_alter_1.inc + +#----------- PARTITION BY KEY +if ($with_partitioning) +{ +let $partitioning= PARTITION BY KEY(f_int1) PARTITIONS 5; +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +--source suite/parts/inc/partition_alter_1.inc + +#----------- PARTITION BY LIST +if ($with_partitioning) +{ +let $partitioning= PARTITION BY LIST(MOD(f_int1,4)) +(PARTITION part_3 VALUES IN (-3), + PARTITION part_2 VALUES IN (-2), + PARTITION part_1 VALUES IN (-1), + PARTITION part_N VALUES IN (NULL), + PARTITION part0 VALUES IN (0), + PARTITION part1 VALUES IN (1), + PARTITION part2 VALUES IN (2), + PARTITION part3 VALUES IN (3)); +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +--source suite/parts/inc/partition_alter_1.inc + +#----------- PARTITION BY RANGE +if ($with_partitioning) +{ +let $partitioning= PARTITION BY RANGE(f_int1) +(PARTITION parta VALUES LESS THAN (0), +PARTITION partb VALUES LESS THAN ($max_row_div4), +PARTITION partc VALUES LESS THAN ($max_row_div2), +PARTITION partd VALUES LESS THAN ($max_row_div2 + $max_row_div4), +PARTITION parte VALUES LESS THAN ($max_row), +PARTITION partf VALUES LESS THAN $MAX_VALUE); +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +--source suite/parts/inc/partition_alter_1.inc + +#----------- PARTITION BY RANGE -- SUBPARTITION BY HASH +if ($with_partitioning) +{ +let $partitioning= PARTITION BY RANGE(f_int1 DIV 2) SUBPARTITION BY HASH(f_int1) SUBPARTITIONS 2 +(PARTITION parta VALUES LESS THAN (0), +PARTITION partb VALUES LESS THAN ($max_row_div4), +PARTITION partc VALUES LESS THAN ($max_row_div2), +PARTITION partd VALUES LESS THAN $MAX_VALUE); +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +--source suite/parts/inc/partition_alter_1.inc + +#----------- PARTITION BY RANGE -- SUBPARTITION BY KEY +if ($with_partitioning) +{ +let $partitioning= PARTITION BY RANGE(f_int1) SUBPARTITION BY KEY(f_int1) +(PARTITION part1 VALUES LESS THAN (0) +(SUBPARTITION subpart11, SUBPARTITION subpart12), +PARTITION part2 VALUES LESS THAN ($max_row_div4) +(SUBPARTITION subpart21, SUBPARTITION subpart22), +PARTITION part3 VALUES LESS THAN ($max_row_div2) +(SUBPARTITION subpart31, SUBPARTITION subpart32), +PARTITION part4 VALUES LESS THAN $MAX_VALUE +(SUBPARTITION subpart41, SUBPARTITION subpart42)); +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +--source suite/parts/inc/partition_alter_1.inc + +#----------- PARTITION BY LIST -- SUBPARTITION BY HASH +if ($with_partitioning) +{ +let $partitioning= PARTITION BY LIST(ABS(MOD(f_int1,3))) SUBPARTITION BY HASH(f_int1 + 1) +(PARTITION part1 VALUES IN (0) + (SUBPARTITION sp11, SUBPARTITION sp12), + PARTITION part2 VALUES IN (1) + (SUBPARTITION sp21, SUBPARTITION sp22), + PARTITION part3 VALUES IN (2) + (SUBPARTITION sp31, SUBPARTITION sp32), + PARTITION part4 VALUES IN (NULL) + (SUBPARTITION sp41, SUBPARTITION sp42)); +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +--source suite/parts/inc/partition_alter_1.inc + +#----------- PARTITION BY LIST -- SUBPARTITION BY KEY +if ($with_partitioning) +{ +let $partitioning= PARTITION BY LIST(ABS(MOD(f_int1,2))) +SUBPARTITION BY KEY(f_int1) SUBPARTITIONS $sub_part_no +(PARTITION part1 VALUES IN (0), + PARTITION part2 VALUES IN (1), + PARTITION part3 VALUES IN (NULL)); +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +--source suite/parts/inc/partition_alter_1.inc diff --git a/mysql-test/suite/parts/inc/partition_alter_13.inc b/mysql-test/suite/parts/inc/partition_alter_13.inc new file mode 100644 index 00000000..0964f5ee --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_alter_13.inc @@ -0,0 +1,180 @@ +################################################################################ +# inc/partition_alter_13.inc # +# # +# Purpose: # +# Check ALTER partitioned table and the state of the table afterwards # +# The partitioning function uses the columns f_int1 and f_int2 # +# # +# For all partitioning methods # +# PARTITION BY HASH/KEY/LIST/RANGE # +# PARTITION BY RANGE/LIST ... SUBPARTITION BY HASH/KEY ... # +# do # +# 1. Create the partitioned table # +# 2. Execute inc/partition_alter_1.inc, which will # +# - Insert the first half of the table t0_template into t1 # +# - Execute the ALTER TABLE statement # +# - Insert the second half of the table t0_template into t1 # +# - Execute the usability test include/partition_check.inc # +# - Drop the table t1 # +# done # +# # +# The parameters # +# $unique -- PRIMARY KEY or UNIQUE INDEXes to be created within the # +# CREATE TABLE STATEMENT # +# $alter -- ALTER TABLE statement, which has to be executed # +# have to be set before sourcing this routine. # +# Example: # +# let $unique= , UNIQUE INDEX uidx1 (f_int1); # +# let $alter= ALTER TABLE t1 DROP UNIQUE INDEX uidx1; # +# inc/partition_alter1.inc # +# # +# Attention: The routine include/partition_alter_11.inc is very similar # +# to this one. So if something has to be changed here it # +# might be necessary to do it also there # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-03-05 # +# Change Author: # +# Change Date: # +# Change: # +################################################################################ + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +let $partitioning= ; +#----------- PARTITION BY HASH +if ($with_partitioning) +{ +let $partitioning= PARTITION BY HASH(f_int1 + f_int2) PARTITIONS 2; +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +--source suite/parts/inc/partition_alter_1.inc + +#----------- PARTITION BY KEY +if ($with_partitioning) +{ +let $partitioning= PARTITION BY KEY(f_int1,f_int2) PARTITIONS 5; +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +--source suite/parts/inc/partition_alter_1.inc + +#----------- PARTITION BY LIST +if ($with_partitioning) +{ +let $partitioning= PARTITION BY LIST(MOD(f_int1 + f_int2,4)) +(PARTITION part_3 VALUES IN (-3), + PARTITION part_2 VALUES IN (-2), + PARTITION part_1 VALUES IN (-1), + PARTITION part_N VALUES IN (NULL), + PARTITION part0 VALUES IN (0), + PARTITION part1 VALUES IN (1), + PARTITION part2 VALUES IN (2), + PARTITION part3 VALUES IN (3)); +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +--source suite/parts/inc/partition_alter_1.inc + +#----------- PARTITION BY RANGE +if ($with_partitioning) +{ +let $partitioning= PARTITION BY RANGE((f_int1 + f_int2) DIV 2) +(PARTITION parta VALUES LESS THAN (0), +PARTITION partb VALUES LESS THAN ($max_row_div4), +PARTITION partc VALUES LESS THAN ($max_row_div2), +PARTITION partd VALUES LESS THAN ($max_row_div2 + $max_row_div4), +PARTITION parte VALUES LESS THAN ($max_row), +PARTITION partf VALUES LESS THAN $MAX_VALUE); +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +--source suite/parts/inc/partition_alter_1.inc + +#----------- PARTITION BY RANGE -- SUBPARTITION BY HASH +if ($with_partitioning) +{ +let $partitioning= PARTITION BY RANGE(f_int1) SUBPARTITION BY HASH(f_int2) SUBPARTITIONS 2 +(PARTITION parta VALUES LESS THAN (0), +PARTITION partb VALUES LESS THAN ($max_row_div4), +PARTITION partc VALUES LESS THAN ($max_row_div2), +PARTITION partd VALUES LESS THAN $MAX_VALUE); +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +--source suite/parts/inc/partition_alter_1.inc + +#----------- PARTITION BY RANGE -- SUBPARTITION BY KEY +if ($with_partitioning) +{ +let $partitioning= PARTITION BY RANGE(f_int1) SUBPARTITION BY KEY(f_int2) +(PARTITION part1 VALUES LESS THAN (0) +(SUBPARTITION subpart11, SUBPARTITION subpart12), +PARTITION part2 VALUES LESS THAN ($max_row_div4) +(SUBPARTITION subpart21, SUBPARTITION subpart22), +PARTITION part3 VALUES LESS THAN ($max_row_div2) +(SUBPARTITION subpart31, SUBPARTITION subpart32), +PARTITION part4 VALUES LESS THAN $MAX_VALUE +(SUBPARTITION subpart41, SUBPARTITION subpart42)); +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +--source suite/parts/inc/partition_alter_1.inc + +#----------- PARTITION BY LIST -- SUBPARTITION BY HASH +if ($with_partitioning) +{ +let $partitioning= PARTITION BY LIST(ABS(MOD(f_int1,3))) SUBPARTITION BY HASH(f_int2 + 1) +(PARTITION part1 VALUES IN (0) + (SUBPARTITION sp11, SUBPARTITION sp12), + PARTITION part2 VALUES IN (1) + (SUBPARTITION sp21, SUBPARTITION sp22), + PARTITION part3 VALUES IN (2) + (SUBPARTITION sp31, SUBPARTITION sp32), + PARTITION part4 VALUES IN (NULL) + (SUBPARTITION sp41, SUBPARTITION sp42)); +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +--source suite/parts/inc/partition_alter_1.inc + +#----------- PARTITION BY LIST -- SUBPARTITION BY KEY +if ($with_partitioning) +{ +let $partitioning= PARTITION BY LIST(ABS(MOD(f_int1,2))) +SUBPARTITION BY KEY(f_int2) SUBPARTITIONS $sub_part_no +(PARTITION part1 VALUES IN (0), + PARTITION part2 VALUES IN (1), + PARTITION part3 VALUES IN (NULL)); +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +--source suite/parts/inc/partition_alter_1.inc diff --git a/mysql-test/suite/parts/inc/partition_alter_41.inc b/mysql-test/suite/parts/inc/partition_alter_41.inc new file mode 100644 index 00000000..53469c08 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_alter_41.inc @@ -0,0 +1,194 @@ +################################################################################ +# inc/partition_alter_11.inc # +# # +# Purpose: # +# Check ALTER partitioned table and the state of the table afterwards # +# The partitioning function use the column f_int1 # +# # +# For all partitioning methods # +# PARTITION BY HASH/KEY/LIST/RANGE # +# PARTITION BY RANGE/LIST ... SUBPARTITION BY HASH/KEY ... # +# do # +# 1. Create the partitioned table # +# 2. Execute inc/partition_alter_1.inc, which will # +# - Insert the first half of the table t0_template into t1 # +# - Execute the ALTER TABLE statement # +# - Insert the second half of the table t0_template into t1 # +# - Execute the usability test inc/partition_check.inc # +# - Drop the table t1 # +# done # +# # +# The parameters # +# $unique -- PRIMARY KEY or UNIQUE INDEXes to be created within the # +# CREATE TABLE STATEMENT # +# $alter -- ALTER TABLE statement, which has to be executed # +# have to be set before sourcing this routine. # +# Example: # +# let $unique= , UNIQUE INDEX uidx1 (f_int1); # +# let $alter= ALTER TABLE t1 DROP UNIQUE INDEX uidx1; # +# inc/partition_alter1.inc # +# # +# Attention: The routine inc/partition_alter_13.inc is very similar # +# to this one. So if something has to be changed here it # +# might be necessary to do it also there # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-03-05 # +# Change Author: # +# Change Date: # +# Change: # +################################################################################ + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +let $partitioning= ; +#----------- PARTITION BY HASH +if ($with_partitioning) +{ +let $partitioning= PARTITION BY HASH(f_int1) PARTITIONS 2 (partition part_1, partition part_2); +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +--source suite/parts/inc/partition_alter_1.inc + +#----------- PARTITION BY KEY +if ($with_partitioning) +{ +let $partitioning= PARTITION BY KEY(f_int1) PARTITIONS 5 (partition part_1, partition part_2, partition part_3, partition part_4, partition part_5); +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +--source suite/parts/inc/partition_alter_1.inc + +#----------- PARTITION BY LIST +if ($with_partitioning) +{ +let $partitioning= PARTITION BY LIST(MOD(f_int1,4)) +(PARTITION part_3 VALUES IN (-3), + PARTITION part_2 VALUES IN (-2), + PARTITION part_1 VALUES IN (-1), + PARTITION part_N VALUES IN (NULL), + PARTITION part0 VALUES IN (0), + PARTITION part1 VALUES IN (1), + PARTITION part2 VALUES IN (2), + PARTITION part3 VALUES IN (3)); +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +--source suite/parts/inc/partition_alter_1.inc + +#----------- PARTITION BY RANGE +if ($with_partitioning) +{ +--disable_query_log +eval SET @aux = 'PARTITION BY RANGE(f_int1) +(PARTITION parta VALUES LESS THAN (0), +PARTITION part_1 VALUES LESS THAN ($max_row_div4), +PARTITION part_2 VALUES LESS THAN ($max_row_div2), +PARTITION part_3 VALUES LESS THAN ($max_row_div2 + $max_row_div4), +PARTITION part_4 VALUES LESS THAN ($max_row), +PARTITION part_5 VALUES LESS THAN $MAX_VALUE)'; +let $partitioning= `SELECT @aux`; +--enable_query_log +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +--source suite/parts/inc/partition_alter_1.inc + +#----------- PARTITION BY RANGE -- SUBPARTITION BY HASH +if ($with_partitioning) +{ +--disable_query_log +eval SET @aux = +'PARTITION BY RANGE(f_int1 DIV 2) SUBPARTITION BY HASH(f_int1) SUBPARTITIONS 2 +(PARTITION part_1 VALUES LESS THAN (0), +PARTITION part_2 VALUES LESS THAN ($max_row_div4), +PARTITION part_3 VALUES LESS THAN ($max_row_div2), +PARTITION part_4 VALUES LESS THAN $MAX_VALUE)'; +let $partitioning= `SELECT @aux`; +--enable_query_log +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +--source suite/parts/inc/partition_alter_1.inc + +#----------- PARTITION BY RANGE -- SUBPARTITION BY KEY +if ($with_partitioning) +{ +--disable_query_log +eval SET @aux = 'PARTITION BY RANGE(f_int1) SUBPARTITION BY KEY(f_int1) +(PARTITION part_1 VALUES LESS THAN (0) +(SUBPARTITION subpart11, SUBPARTITION subpart12), +PARTITION part_2 VALUES LESS THAN ($max_row_div4) +(SUBPARTITION subpart21, SUBPARTITION subpart22), +PARTITION part_3 VALUES LESS THAN ($max_row_div2) +(SUBPARTITION subpart31, SUBPARTITION subpart32), +PARTITION part_4 VALUES LESS THAN $MAX_VALUE +(SUBPARTITION subpart41, SUBPARTITION subpart42))'; +let $partitioning= `SELECT @aux`; +--enable_query_log +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +--source suite/parts/inc/partition_alter_1.inc + +#----------- PARTITION BY LIST -- SUBPARTITION BY HASH +if ($with_partitioning) +{ +let $partitioning= PARTITION BY LIST(ABS(MOD(f_int1,3))) SUBPARTITION BY HASH(f_int1 + 1) +(PARTITION part_1 VALUES IN (0) + (SUBPARTITION sp11, SUBPARTITION sp12), + PARTITION part_2 VALUES IN (1) + (SUBPARTITION sp21, SUBPARTITION sp22), + PARTITION part_3 VALUES IN (2) + (SUBPARTITION sp31, SUBPARTITION sp32), + PARTITION part_4 VALUES IN (NULL) + (SUBPARTITION sp41, SUBPARTITION sp42)); +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +--source suite/parts/inc/partition_alter_1.inc + +#----------- PARTITION BY LIST -- SUBPARTITION BY KEY +if ($with_partitioning) +{ +--disable_query_log +eval SET @aux = +'PARTITION BY LIST(ABS(MOD(f_int1,2))) +SUBPARTITION BY KEY(f_int1) SUBPARTITIONS $sub_part_no +(PARTITION part_1 VALUES IN (0), + PARTITION part_2 VALUES IN (1), + PARTITION part_3 VALUES IN (NULL))'; +let $partitioning= `SELECT @aux`; +--enable_query_log +} +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +--source suite/parts/inc/partition_alter_1.inc diff --git a/mysql-test/suite/parts/inc/partition_auto_increment.inc b/mysql-test/suite/parts/inc/partition_auto_increment.inc new file mode 100644 index 00000000..567733ed --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_auto_increment.inc @@ -0,0 +1,925 @@ +# inc/partition_auto_increment.inc +# +# auto_increment test +# used variables: $engine +# +--disable_query_log +set sql_mode=""; +--enable_query_log + +-- disable_warnings +DROP TABLE IF EXISTS t1; +-- enable_warnings + +-- echo # test without partitioning for reference +eval CREATE TABLE t1 ( + c1 INT NOT NULL AUTO_INCREMENT, + PRIMARY KEY (c1)) +ENGINE=$engine; +SHOW CREATE TABLE t1; +SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test' +AND TABLE_NAME='t1'; +INSERT INTO t1 VALUES (2); +INSERT INTO t1 VALUES (4); +INSERT INTO t1 VALUES (NULL); +SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test' +AND TABLE_NAME='t1'; +SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test' +AND TABLE_NAME='t1'; +INSERT INTO t1 VALUES (0); +-- error 0, ER_DUP_KEY, ER_DUP_ENTRY +INSERT INTO t1 VALUES (5), (16); +if (!$mysql_errno) +{ + echo # ERROR (only OK if Blackhole) should give ER_DUP_KEY or ER_DUP_ENTRY; + echo # mysql_errno: $mysql_errno; +} +INSERT INTO t1 VALUES (17); +INSERT INTO t1 VALUES (19), (NULL); +-- error 0, ER_DUP_ENTRY, ER_DUP_KEY +INSERT INTO t1 VALUES (NULL), (10), (NULL); +if ($mysql_errno) +{ + echo # ERROR (only OK if Archive) mysql_errno: $mysql_errno; +} +INSERT INTO t1 VALUES (NULL); +SET INSERT_ID = 30; +INSERT INTO t1 VALUES (NULL); +SET INSERT_ID = 29; +-- error 0, ER_DUP_ENTRY, ER_DUP_KEY +INSERT INTO t1 VALUES (NULL), (NULL), (NULL); +if (!$mysql_errno) +{ + echo # ERROR (only OK if Blackhole) should give ER_DUP_KEY or ER_DUP_ENTRY; + echo # mysql_errno: $mysql_errno; +} +INSERT INTO t1 VALUES (NULL); +if (!$skip_update) +{ +# InnoDB Does not handle this correctly, see bug#14793, bug#21641 + UPDATE t1 SET c1 = 50 WHERE c1 = 17; + UPDATE t1 SET c1 = 51 WHERE c1 = 19; + FLUSH TABLES; + UPDATE t1 SET c1 = 40 WHERE c1 = 50; + SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test' + AND TABLE_NAME='t1'; + UPDATE t1 SET c1 = NULL WHERE c1 = 4; + INSERT INTO t1 VALUES (NULL); + INSERT INTO t1 VALUES (NULL); +} +SELECT * FROM t1 ORDER BY c1; +DROP TABLE t1; +eval CREATE TABLE t1 ( + c1 INT NOT NULL AUTO_INCREMENT, + PRIMARY KEY (c1)) +ENGINE=$engine; +SHOW CREATE TABLE t1; +FLUSH TABLE; +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (4); +FLUSH TABLE; +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (NULL); +FLUSH TABLE; +SHOW CREATE TABLE t1; +if (!$skip_delete) +{ +DELETE FROM t1; +} +INSERT INTO t1 VALUES (NULL); +SHOW CREATE TABLE t1; +SELECT * FROM t1 ORDER BY c1; +if (!$skip_truncate) +{ +TRUNCATE TABLE t1; +} +INSERT INTO t1 VALUES (NULL); +SHOW CREATE TABLE t1; +SELECT * FROM t1 ORDER BY c1; +INSERT INTO t1 VALUES (100); +INSERT INTO t1 VALUES (NULL); +if (!$skip_delete) +{ +DELETE FROM t1 WHERE c1 >= 100; +} +# InnoDB does reset auto_increment on OPTIMIZE, Bug#18274 +# Archive does reset auto_increment on OPTIMIZE, Bug#40216 +OPTIMIZE TABLE t1; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +if (!$skip_update) +{ +eval CREATE TABLE t1 +(a INT NULL AUTO_INCREMENT, + UNIQUE KEY (a)) +ENGINE=$engine; +SET LAST_INSERT_ID = 999; +SET INSERT_ID = 0; +INSERT INTO t1 SET a = 1 ON DUPLICATE KEY UPDATE a = NULL; +SELECT LAST_INSERT_ID(); +SELECT * FROM t1; +INSERT INTO t1 SET a = 1 ON DUPLICATE KEY UPDATE a = NULL; +SELECT LAST_INSERT_ID(); +SELECT * FROM t1; +UPDATE t1 SET a = 1 WHERE a IS NULL; +SELECT LAST_INSERT_ID(); +SELECT * FROM t1; +UPDATE t1 SET a = NULL WHERE a = 1; +SELECT LAST_INSERT_ID(); +SELECT * FROM t1; +DROP TABLE t1; +SET INSERT_ID = 1; +} + +-- echo # Simple test with NULL +eval CREATE TABLE t1 ( + c1 INT NOT NULL AUTO_INCREMENT, + PRIMARY KEY (c1)) +ENGINE=$engine +PARTITION BY HASH(c1) +PARTITIONS 2; +INSERT INTO t1 VALUES (NULL); +SHOW CREATE TABLE t1; +SELECT * FROM t1; +DROP TABLE t1; + +-- echo # Test with sql_mode and first insert as 0 +eval CREATE TABLE t1 ( + c1 INT, + c2 INT NOT NULL AUTO_INCREMENT, + PRIMARY KEY (c2)) +ENGINE=$engine +PARTITION BY HASH(c2) +PARTITIONS 2; +INSERT INTO t1 VALUES (1, NULL); +-- error 0, ER_DUP_KEY, ER_DUP_ENTRY +INSERT INTO t1 VALUES (1, 1), (99, 99); +if (!$mysql_errno) +{ + echo # ERROR (only OK if Blackhole) should give ER_DUP_KEY or ER_DUP_ENTRY; + echo # mysql_errno: $mysql_errno; +} +INSERT INTO t1 VALUES (1, NULL); +let $old_sql_mode = `select @@session.sql_mode`; +SET @@session.sql_mode = 'NO_AUTO_VALUE_ON_ZERO'; +-- error 0, ER_DUP_ENTRY, ER_DUP_KEY +INSERT INTO t1 VALUES (1, 0); +if ($mysql_errno) +{ + echo # ERROR (only OK if Archive) mysql_errno: $mysql_errno; +} +SELECT * FROM t1 ORDER BY c1, c2; +DROP TABLE t1; +eval CREATE TABLE t1 ( + c1 INT, + c2 INT NOT NULL AUTO_INCREMENT, + PRIMARY KEY (c2)) +ENGINE=$engine +PARTITION BY HASH(c2) +PARTITIONS 2; +-- error 0, ER_DUP_ENTRY, ER_DUP_KEY +INSERT INTO t1 VALUES (1, 0); +if ($mysql_errno) +{ + echo # ERROR (only OK if Archive) mysql_errno: $mysql_errno; +} +INSERT INTO t1 VALUES (1, 1), (1, NULL); +INSERT INTO t1 VALUES (2, NULL), (4, 7); +INSERT INTO t1 VALUES (1, NULL); +SELECT * FROM t1 ORDER BY c1, c2; +eval SET @@session.sql_mode = '$old_sql_mode'; +DROP TABLE t1; + + +-- echo # Simple test with NULL, 0 and explicit values both incr. and desc. +eval CREATE TABLE t1 ( + c1 INT NOT NULL AUTO_INCREMENT, + PRIMARY KEY (c1)) +ENGINE=$engine +PARTITION BY HASH(c1) +PARTITIONS 2; +INSERT INTO t1 VALUES (2), (4), (NULL); +INSERT INTO t1 VALUES (0); +-- error 0, ER_DUP_KEY, ER_DUP_ENTRY +INSERT INTO t1 VALUES (5), (16); +if (!$mysql_errno) +{ + echo # ERROR (only OK if Blackhole) should give ER_DUP_KEY or ER_DUP_ENTRY; + echo # mysql_errno: $mysql_errno; +} +INSERT INTO t1 VALUES (17), (19), (NULL); +-- error 0, ER_DUP_ENTRY, ER_DUP_KEY +INSERT INTO t1 VALUES (NULL), (10), (NULL); +if ($mysql_errno) +{ + echo # ERROR (only OK if Archive) mysql_errno: $mysql_errno; +} +-- error 0, ER_DUP_ENTRY, ER_DUP_KEY +INSERT INTO t1 VALUES (NULL), (9); +if ($mysql_errno) +{ + echo # ERROR (only OK if Archive) mysql_errno: $mysql_errno; +} +-- error 0, ER_DUP_ENTRY, ER_DUP_KEY +INSERT INTO t1 VALUES (59), (55); +if ($mysql_errno) +{ + echo # ERROR (only OK if Archive) mysql_errno: $mysql_errno; +} +INSERT INTO t1 VALUES (NULL), (90); +INSERT INTO t1 VALUES (NULL); +if (!$skip_update) +{ + UPDATE t1 SET c1 = 150 WHERE c1 = 17; + UPDATE t1 SET c1 = 151 WHERE c1 = 19; + FLUSH TABLES; + UPDATE t1 SET c1 = 140 WHERE c1 = 150; + SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test' + AND TABLE_NAME='t1'; + UPDATE t1 SET c1 = NULL WHERE c1 = 4; + INSERT INTO t1 VALUES (NULL); + INSERT INTO t1 VALUES (NULL); +} +SELECT * FROM t1 ORDER BY c1; +DROP TABLE t1; + +-- echo # Test with auto_increment_increment and auto_increment_offset. +eval CREATE TABLE t1 ( + c1 INT NOT NULL AUTO_INCREMENT, + PRIMARY KEY (c1)) +ENGINE=$engine +PARTITION BY HASH(c1) +PARTITIONS 2; +let $old_increment = `SELECT @@session.auto_increment_increment`; +let $old_offset = `SELECT @@session.auto_increment_offset`; +SET @@session.auto_increment_increment = 10; +SET @@session.auto_increment_offset = 5; +INSERT INTO t1 VALUES (1); +INSERT INTO t1 VALUES (NULL), (NULL), (NULL); +SET @@session.auto_increment_increment = 5; +SET @@session.auto_increment_offset = 3; +INSERT INTO t1 VALUES (NULL); +let $new_val = `SELECT LAST_INSERT_ID()`; +eval INSERT INTO t1 VALUES ($new_val + 1); +INSERT INTO t1 VALUES (NULL); +let $new_val = `SELECT LAST_INSERT_ID()`; +eval INSERT INTO t1 VALUES ($new_val + 2); +INSERT INTO t1 VALUES (NULL); +let $new_val = `SELECT LAST_INSERT_ID()`; +eval INSERT INTO t1 VALUES ($new_val + 3); +INSERT INTO t1 VALUES (NULL); +let $new_val = `SELECT LAST_INSERT_ID()`; +eval INSERT INTO t1 VALUES ($new_val + 4); +INSERT INTO t1 VALUES (NULL); +let $new_val = `SELECT LAST_INSERT_ID()`; +eval INSERT INTO t1 VALUES ($new_val + 5); +INSERT INTO t1 VALUES (NULL); +let $new_val = `SELECT LAST_INSERT_ID()`; +eval INSERT INTO t1 VALUES ($new_val + 6); +INSERT INTO t1 VALUES (NULL); +eval SET @@session.auto_increment_increment = $old_increment; +eval SET @@session.auto_increment_offset = $old_offset; +SELECT * FROM t1 ORDER BY c1; +DROP TABLE t1; + + +-- echo # Test reported auto_increment value +eval CREATE TABLE t1 ( + c1 INT NOT NULL AUTO_INCREMENT, + PRIMARY KEY (c1)) +ENGINE=$engine +PARTITION BY HASH (c1) +PARTITIONS 2; +SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test' +AND TABLE_NAME='t1'; +INSERT INTO t1 VALUES (2); +SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test' +AND TABLE_NAME='t1'; +INSERT INTO t1 VALUES (4); +INSERT INTO t1 VALUES (NULL); +SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test' +AND TABLE_NAME='t1'; +INSERT INTO t1 VALUES (NULL); +INSERT INTO t1 VALUES (17); +INSERT INTO t1 VALUES (19); +INSERT INTO t1 VALUES (NULL); +INSERT INTO t1 VALUES (NULL); +SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test' +AND TABLE_NAME='t1'; +SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test' +AND TABLE_NAME='t1'; +-- error 0, ER_DUP_ENTRY, ER_DUP_KEY +INSERT INTO t1 VALUES (10); +if ($mysql_errno) +{ + echo # ERROR (only OK if Archive) mysql_errno: $mysql_errno; +} +SELECT * FROM t1 ORDER BY c1; +INSERT INTO t1 VALUES (NULL); +SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='test' +AND TABLE_NAME='t1'; +INSERT INTO t1 VALUES (NULL); +-- error 0, ER_DUP_ENTRY, ER_DUP_KEY +INSERT INTO t1 VALUES (15); +if ($mysql_errno) +{ + echo # ERROR (only OK if Archive) mysql_errno: $mysql_errno; +} +INSERT INTO t1 VALUES (NULL); +SELECT * FROM t1 ORDER BY c1; +INSERT INTO t1 VALUES (NULL); +if (!$skip_delete) +{ +DELETE FROM t1; +} +INSERT INTO t1 VALUES (NULL); +SHOW CREATE TABLE t1; +SELECT * FROM t1 ORDER BY c1; +if (!$skip_truncate) +{ +TRUNCATE TABLE t1; +} +INSERT INTO t1 VALUES (NULL); +SHOW CREATE TABLE t1; +SELECT * FROM t1 ORDER BY c1; +INSERT INTO t1 VALUES (100); +INSERT INTO t1 VALUES (NULL); +if (!$skip_delete) +{ +DELETE FROM t1 WHERE c1 >= 100; +} +# InnoDB does reset auto_increment on OPTIMIZE, Bug#18274 +OPTIMIZE TABLE t1; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +-- echo # Test with two threads +connection default; +eval CREATE TABLE t1 (c1 INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (c1)) + ENGINE = $engine + PARTITION BY HASH(c1) + PARTITIONS 2; +INSERT INTO t1 (c1) VALUES (2); +INSERT INTO t1 (c1) VALUES (4); +connect(con1, localhost, root,,); +connection con1; +INSERT INTO t1 (c1) VALUES (NULL); +INSERT INTO t1 (c1) VALUES (10); +connection default; +INSERT INTO t1 (c1) VALUES (NULL); +INSERT INTO t1 (c1) VALUES (NULL); +INSERT INTO t1 (c1) VALUES (19); +INSERT INTO t1 (c1) VALUES (21); +connection con1; +INSERT INTO t1 (c1) VALUES (NULL); +connection default; +-- error 0, ER_DUP_ENTRY, ER_DUP_KEY +INSERT INTO t1 (c1) VALUES (16); +if ($mysql_errno) +{ + echo # ERROR (only OK if Archive) mysql_errno: $mysql_errno; +} +connection con1; +INSERT INTO t1 (c1) VALUES (NULL); +disconnect con1; +connection default; +INSERT INTO t1 (c1) VALUES (NULL); +SELECT * FROM t1 ORDER BY c1; +DROP TABLE t1; + +-- echo # Test with two threads + start transaction NO PARTITIONING +connect(con1, localhost, root,,); +connection default; +eval CREATE TABLE t1 (c1 INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (c1)) + ENGINE = $engine; +if ($engine == "'InnoDB'") +{ +# MDEV-515 takes X-lock on the table for the first insert. +# So concurrent insert won't happen on the table +INSERT INTO t1(c1) VALUES(100); +} +START TRANSACTION; +INSERT INTO t1 (c1) VALUES (2); +INSERT INTO t1 (c1) VALUES (4); +connection con1; +START TRANSACTION; +INSERT INTO t1 (c1) VALUES (NULL); +INSERT INTO t1 (c1) VALUES (10); +connection default; +INSERT INTO t1 (c1) VALUES (NULL); +INSERT INTO t1 (c1) VALUES (NULL); +INSERT INTO t1 (c1) VALUES (19); +INSERT INTO t1 (c1) VALUES (21); +connection con1; +INSERT INTO t1 (c1) VALUES (NULL); +connection default; +-- error 0, ER_DUP_KEY +INSERT INTO t1 (c1) VALUES (16); +if ($mysql_errno) +{ + echo # ERROR (only OK if Archive) mysql_errno: $mysql_errno; +} +connection con1; +INSERT INTO t1 (c1) VALUES (NULL); +SELECT * FROM t1 ORDER BY c1; +COMMIT; +SELECT * FROM t1 ORDER BY c1; +disconnect con1; +connection default; +INSERT INTO t1 (c1) VALUES (NULL); +SELECT * FROM t1 ORDER BY c1; +COMMIT; +SELECT * FROM t1 ORDER BY c1; +DROP TABLE t1; + +-- echo # Test with two threads + start transaction +connect(con1, localhost, root,,); +connection default; +eval CREATE TABLE t1 (c1 INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (c1)) + ENGINE = $engine + PARTITION BY HASH(c1) + PARTITIONS 2; +IF ($engine == "'InnoDB'") +{ +# MDEV-515 takes X-lock on the table for the first insert. +# So concurrent insert won't happen on the table +INSERT INTO t1 (c1) VALUES (100); +INSERT INTO t1 (c1) VALUES (101); +} +START TRANSACTION; +INSERT INTO t1 (c1) VALUES (2); +INSERT INTO t1 (c1) VALUES (4); +connection con1; +START TRANSACTION; +INSERT INTO t1 (c1) VALUES (NULL), (10); +connection default; +INSERT INTO t1 (c1) VALUES (NULL), (NULL), (19); +INSERT INTO t1 (c1) VALUES (21); +connection con1; +INSERT INTO t1 (c1) VALUES (NULL); +connection default; +-- error 0, ER_DUP_ENTRY, ER_DUP_KEY +INSERT INTO t1 (c1) VALUES (16); +if ($mysql_errno) +{ + echo # ERROR (only OK if Archive) mysql_errno: $mysql_errno; +} +connection con1; +INSERT INTO t1 (c1) VALUES (NULL); +SELECT * FROM t1 ORDER BY c1; +COMMIT; +SELECT * FROM t1 ORDER BY c1; +disconnect con1; +connection default; +INSERT INTO t1 (c1) VALUES (NULL); +SELECT * FROM t1 ORDER BY c1; +COMMIT; +SELECT * FROM t1 ORDER BY c1; +DROP TABLE t1; + +if (!$only_ai_pk) +{ +-- echo # Test with another column after +eval CREATE TABLE t1 ( +c1 INT NOT NULL AUTO_INCREMENT, +c2 INT, +PRIMARY KEY (c1,c2)) +ENGINE = $engine +PARTITION BY HASH(c2) +PARTITIONS 2; +INSERT INTO t1 VALUES (1, 0); +INSERT INTO t1 VALUES (1, 1); +INSERT INTO t1 VALUES (NULL, 1), (NULL, 2), (NULL, 3); +INSERT INTO t1 VALUES (NULL, 3); +INSERT INTO t1 VALUES (2, 0), (NULL, 2); +INSERT INTO t1 VALUES (2, 2); +INSERT INTO t1 VALUES (2, 22); +INSERT INTO t1 VALUES (NULL, 2); +SELECT * FROM t1 ORDER BY c1,c2; +DROP TABLE t1; +} + +-- echo # Test with another column before +eval CREATE TABLE t1 ( +c1 INT, +c2 INT NOT NULL AUTO_INCREMENT, +PRIMARY KEY (c2)) +ENGINE = $engine +PARTITION BY HASH(c2) +PARTITIONS 2; +INSERT INTO t1 VALUES (1, 0); +-- error 0, ER_DUP_KEY, ER_DUP_ENTRY +INSERT INTO t1 VALUES (1, 1); +if (!$mysql_errno) +{ + echo # ERROR (only OK if Blackhole) should give ER_DUP_KEY or ER_DUP_ENTRY; + echo # mysql_errno: $mysql_errno; +} +INSERT INTO t1 VALUES (1, NULL); +INSERT INTO t1 VALUES (2, NULL), (3, 11), (3, NULL), (2, 0); +INSERT INTO t1 VALUES (2, NULL); +-- error 0, ER_DUP_KEY, ER_DUP_ENTRY +INSERT INTO t1 VALUES (2, 2); +if (!$mysql_errno) +{ + echo # ERROR (only OK if Blackhole) should give ER_DUP_KEY or ER_DUP_ENTRY; + echo # mysql_errno: $mysql_errno; +} +INSERT INTO t1 VALUES (2, 22); +INSERT INTO t1 VALUES (2, NULL); +SELECT * FROM t1 ORDER BY c1,c2; +DROP TABLE t1; + +-- echo # Test with auto_increment on secondary column in multi-column-index +-- disable_abort_on_error +eval CREATE TABLE t1 ( +c1 INT, +c2 INT NOT NULL AUTO_INCREMENT, +PRIMARY KEY (c1,c2)) +ENGINE = $engine +PARTITION BY HASH(c2) +PARTITIONS 2; +-- enable_abort_on_error +-- disable_query_log +eval SET @my_errno= $mysql_errno ; +let $run = `SELECT @my_errno = 0`; +# ER_WRONG_AUTO_KEY is 1075 +let $ER_WRONG_AUTO_KEY= 1075; +if (`SELECT @my_errno NOT IN (0,$ER_WRONG_AUTO_KEY)`) +{ + -- echo # Unknown error code, exits + exit; +} +-- enable_query_log +if ($run) +{ +INSERT INTO t1 VALUES (1, 0); +-- error 0, ER_DUP_KEY, ER_DUP_ENTRY +INSERT INTO t1 VALUES (1, 1); +if (!$mysql_errno) +{ + echo # ERROR (only OK if Blackhole) should give ER_DUP_KEY or ER_DUP_ENTRY; + echo # mysql_errno: $mysql_errno; +} +INSERT INTO t1 VALUES (1, NULL); +INSERT INTO t1 VALUES (2, NULL); +INSERT INTO t1 VALUES (3, NULL); +INSERT INTO t1 VALUES (3, NULL), (2, 0), (2, NULL); +-- error 0, ER_DUP_ENTRY, ER_DUP_KEY +INSERT INTO t1 VALUES (2, 2); +if (!$mysql_errno) +{ + echo # ERROR (only OK if Blackhole) should give ER_DUP_KEY or ER_DUP_ENTRY; + echo # mysql_errno: $mysql_errno; +} +INSERT INTO t1 VALUES (2, 22), (2, NULL); +SELECT * FROM t1 ORDER BY c1,c2; +DROP TABLE t1; +} + +-- echo # Test AUTO_INCREMENT in CREATE +eval CREATE TABLE t1 (c1 INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (c1)) + ENGINE = $engine + AUTO_INCREMENT = 15 + PARTITION BY HASH(c1) + PARTITIONS 2; +SHOW CREATE TABLE t1; +-- error 0, ER_DUP_ENTRY, ER_DUP_KEY +INSERT INTO t1 (c1) VALUES (4); +if ($mysql_errno) +{ + echo # ERROR (only OK if Archive) mysql_errno: $mysql_errno; +} +SHOW CREATE TABLE t1; +INSERT INTO t1 (c1) VALUES (0); +SHOW CREATE TABLE t1; +INSERT INTO t1 (c1) VALUES (NULL); +SHOW CREATE TABLE t1; +SELECT * FROM t1 ORDER BY c1; + +-- echo # Test sql_mode 'NO_AUTO_VALUE_ON_ZERO' +let $old_sql_mode = `select @@session.sql_mode`; +SET @@session.sql_mode = 'NO_AUTO_VALUE_ON_ZERO'; +INSERT INTO t1 (c1) VALUES (300); +SHOW CREATE TABLE t1; +-- error 0, ER_DUP_ENTRY, ER_DUP_KEY +INSERT INTO t1 (c1) VALUES (0); +if ($mysql_errno) +{ + echo # ERROR (only OK if Archive) mysql_errno: $mysql_errno; +} +SHOW CREATE TABLE t1; +INSERT INTO t1 (c1) VALUES (NULL); +SHOW CREATE TABLE t1; +SELECT * FROM t1 ORDER BY c1; +eval SET @@session.sql_mode = '$old_sql_mode'; +DROP TABLE t1; + +-- echo # Test SET INSERT_ID +eval CREATE TABLE t1 (c1 INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (c1)) + ENGINE = $engine + PARTITION BY HASH(c1) + PARTITIONS 2; +SHOW CREATE TABLE t1; +INSERT INTO t1 (c1) VALUES (NULL); +SHOW CREATE TABLE t1; +SELECT * FROM t1; +SET INSERT_ID = 23; +SHOW CREATE TABLE t1; +INSERT INTO t1 (c1) VALUES (NULL); +SHOW CREATE TABLE t1; +SET INSERT_ID = 22; +-- error 0, ER_DUP_ENTRY, ER_DUP_KEY +INSERT INTO t1 VALUES (NULL), (NULL), (NULL); +if (!$mysql_errno) +{ + echo # ERROR (only OK if Blackhole) should give ER_DUP_KEY or ER_DUP_ENTRY; + echo # mysql_errno: $mysql_errno; +} +INSERT INTO t1 VALUES (NULL); +SELECT * FROM t1 ORDER BY c1; +DROP TABLE t1; + +-- echo # Testing with FLUSH TABLE +eval CREATE TABLE t1 ( + c1 INT NOT NULL AUTO_INCREMENT, + PRIMARY KEY (c1)) + ENGINE=$engine + PARTITION BY HASH(c1) + PARTITIONS 2; +SHOW CREATE TABLE t1; +FLUSH TABLE; +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (4); +FLUSH TABLE; +SHOW CREATE TABLE t1; +INSERT INTO t1 VALUES (NULL); +FLUSH TABLE; +SHOW CREATE TABLE t1; +SELECT * FROM t1 ORDER BY c1; +DROP TABLE t1; + +if (!$skip_negative_auto_inc) +{ +--echo ############################################################################# +--echo # Bug #45823 - Assertion failure in file row/row0mysql.c line 1386 +--echo # Bug #43988 - AUTO_INCREMENT errors with partitioned InnoDB tables in 5.1.31 +--echo ############################################################################## + +--echo # Inserting negative autoincrement values into a partition table (partitions >= 4) + +eval CREATE TABLE t (c1 INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(c1), + c2 INT) ENGINE=$engine PARTITION BY HASH(c1) PARTITIONS 4; + +INSERT INTO t(c2) VALUES (10); +INSERT INTO t(c2) VALUES (20); +INSERT INTO t VALUES (-1,-10); +INSERT INTO t(c2) VALUES (30); +INSERT INTO t(c2) VALUES (40); + +SELECT * FROM t ORDER BY c1 ASC; + +DROP TABLE t; + +--echo # Reading from a partition table (partitions >= 2 ) after inserting a negative +--echo # value into the auto increment column + + +eval CREATE TABLE t (c1 INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(c1), + c2 INT) ENGINE=$engine PARTITION BY HASH(c1) PARTITIONS 2; + +INSERT INTO t VALUES (-2,-20); +INSERT INTO t(c2) VALUES (30); + +SELECT * FROM t ORDER BY c1 ASC; + +DROP TABLE t; + +--echo # Inserting negative auto increment value into a partition table (partitions >= 2) +--echo # auto increment value > 2. + +eval CREATE TABLE t (c1 INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(c1), + c2 INT) ENGINE=$engine PARTITION BY HASH(c1) PARTITIONS 2; + +INSERT INTO t VALUES (-4,-20); +INSERT INTO t(c2) VALUES (30); +INSERT INTO t(c2) VALUES (40); + +SELECT * FROM t ORDER BY c1 ASC; + +DROP TABLE t; + +--echo # Inserting -1 into autoincrement column of a partition table (partition >= 4) + +eval CREATE TABLE t (c1 INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(c1), + c2 INT) ENGINE=$engine PARTITION BY HASH(c1) PARTITIONS 4; + +INSERT INTO t(c2) VALUES (10); +INSERT INTO t(c2) VALUES (20); +INSERT INTO t VALUES (-1,-10); + +SELECT * FROM t ORDER BY c1 ASC; + +INSERT INTO t(c2) VALUES (30); + +SELECT * FROM t ORDER BY c1 ASC; + +DROP TABLE t; + +--echo # Deleting from an auto increment table after inserting negative values + +eval CREATE TABLE t (c1 INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(c1), + c2 INT) ENGINE=$engine PARTITION BY HASH(c1) PARTITIONS 4; + +INSERT INTO t(c2) VALUES (10); +INSERT INTO t(c2) VALUES (20); +INSERT INTO t VALUES (-1,-10); +INSERT INTO t(c2) VALUES (30); +INSERT INTO t VALUES (-3,-20); +INSERT INTO t(c2) VALUES (40); + +SELECT * FROM t ORDER BY c1 ASC; + +if (!$skip_delete) +{ +DELETE FROM t WHERE c1 > 1; +} + +SELECT * FROM t ORDER BY c1 ASC; + +DROP TABLE t; + +--echo # Inserting a positive value that exceeds maximum allowed value for an +--echo # Auto Increment column (positive maximum) + +eval CREATE TABLE t (c1 TINYINT NOT NULL AUTO_INCREMENT, PRIMARY KEY(c1), + c2 INT) ENGINE=$engine PARTITION BY HASH(c1) PARTITIONS 4; + +INSERT INTO t(c2) VALUES (10); +INSERT INTO t(c2) VALUES (20); +INSERT INTO t VALUES (126,30); +INSERT INTO t VALUES (127,40); + +--error ER_DUP_ENTRY +INSERT INTO t VALUES (128,50); +--error ER_DUP_ENTRY +INSERT INTO t VALUES (129,60); + +SELECT * FROM t ORDER BY c1 ASC; + +DROP TABLE t; + +--echo # Inserting a negative value that goes below minimum allowed value for an +--echo # Auto Increment column (negative minimum) + +eval CREATE TABLE t (c1 TINYINT NOT NULL AUTO_INCREMENT, PRIMARY KEY(c1), + c2 INT) ENGINE=$engine PARTITION BY HASH(c1) PARTITIONS 4; + +INSERT INTO t(c2) VALUES (10); +INSERT INTO t(c2) VALUES (20); +INSERT INTO t VALUES (-127,30); +INSERT INTO t VALUES (-128,40); + +--error ER_DUP_ENTRY +INSERT INTO t VALUES (-129,50); +--error ER_DUP_ENTRY +INSERT INTO t VALUES (-130,60); + +SELECT * FROM t ORDER BY c1 ASC; + +DROP TABLE t; + +--echo # Updating the partition table with a negative Auto Increment value + +eval CREATE TABLE t (c1 INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(c1), + c2 INT) ENGINE=$engine PARTITION BY HASH(c1) PARTITIONS 4; + +INSERT INTO t(c2) VALUES (10); +INSERT INTO t(c2) VALUES (20); +INSERT INTO t VALUES (-1,-10); +INSERT INTO t(c2) VALUES (30); + +SELECT * FROM t ORDER BY c1 ASC; + +if (!$skip_update) +{ +UPDATE t SET c1 = -6 WHERE c1 = 2; +} + +SELECT * FROM t ORDER BY c1 ASC; + +INSERT INTO t(c2) VALUES (40); +INSERT INTO t(c2) VALUES (50); + +if (!$skip_update) +{ +UPDATE t SET c1 = -6 WHERE c1 = 2; +} + +SELECT * FROM t ORDER BY c1 ASC; + +DROP TABLE t; + +--echo # Updating the partition table with a value that crosses the upper limits +--echo # on both the positive and the negative side. + +eval CREATE TABLE t (c1 TINYINT NOT NULL AUTO_INCREMENT, PRIMARY KEY(c1), + c2 INT) ENGINE=$engine PARTITION BY HASH(c1) PARTITIONS 4; + +INSERT INTO t(c2) VALUES (10); +INSERT INTO t(c2) VALUES (20); +INSERT INTO t VALUES (126,30); +INSERT INTO t VALUES (127,40); + +SELECT * FROM t ORDER BY c1 ASC; + +if (!$skip_update) +{ +UPDATE t SET c1 = 130 where c1 = 127; +} + +SELECT * FROM t ORDER BY c1 ASC; + +if (!$skip_update) +{ +UPDATE t SET c1 = -140 where c1 = 126; +} + +SELECT * FROM t ORDER BY c1 ASC; + +DROP TABLE t; + +if (!$skip_update) +{ +eval CREATE TABLE t1 +(a INT NULL AUTO_INCREMENT, + UNIQUE KEY (a)) +ENGINE=$engine +PARTITION BY KEY(a) PARTITIONS 2; +SET LAST_INSERT_ID = 999; +SET INSERT_ID = 0; +INSERT INTO t1 SET a = 1 ON DUPLICATE KEY UPDATE a = NULL; +SELECT LAST_INSERT_ID(); +SELECT * FROM t1; +INSERT INTO t1 SET a = 1 ON DUPLICATE KEY UPDATE a = NULL; +SELECT LAST_INSERT_ID(); +SELECT * FROM t1; +UPDATE t1 SET a = 1 WHERE a IS NULL; +SELECT LAST_INSERT_ID(); +SELECT * FROM t1; +UPDATE t1 SET a = NULL WHERE a = 1; +SELECT LAST_INSERT_ID(); +SELECT * FROM t1; +DROP TABLE t1; +} +--echo ############################################################################## +} + +if (!$skip_update) +{ +--echo # +--echo # MDEV-19622 Assertion failures in +--echo # ha_partition::set_auto_increment_if_higher upon UPDATE on Aria table +--echo # +eval CREATE OR REPLACE TABLE t1 (pk INT AUTO_INCREMENT, a INT, KEY(pk)) ENGINE=$engine PARTITION BY HASH(a); +INSERT INTO t1 VALUES (1,1),(2,2); +UPDATE t1 SET pk = 0; +DROP TABLE t1; + +--echo # +--echo # MDEV-29636 Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()' +--echo # failed in ha_partition::set_auto_increment_if_higher upon REPLACE +--echo # with partition pruning +--echo # +eval CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY) ENGINE=$engine +PARTITION BY RANGE (a) ( + PARTITION p0 VALUES LESS THAN (10), + PARTITION pn VALUES LESS THAN MAXVALUE +); +REPLACE INTO t1 PARTITION (p0) SELECT 1; +DROP TABLE t1; +} + +if (!$skip_delete) +{ +--echo # +--echo # MDEV-21027 Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()' +--echo # ha_partition::set_auto_increment_if_higher +--echo # +eval CREATE TABLE t1 (a INT AUTO_INCREMENT PRIMARY KEY) ENGINE=$engine PARTITION BY HASH (a) PARTITIONS 3; +REPLACE INTO t1 PARTITION (p0) VALUES (3); +DROP TABLE t1; +} + +if (!$skip_truncate) +{ +--echo # +--echo # MDEV-21310 AUTO_INCREMENT column throws range error on INSERT in partitioned table | +--echo # Assertion `part_share->auto_inc_initialized || !can_use_for_auto_inc_init()' failed. +--echo # +eval CREATE TABLE t1 (c INT AUTO_INCREMENT KEY) ENGINE=$engine PARTITION BY LIST (c) (PARTITION p1 VALUES IN (1), PARTITION p2 VALUES IN (2)); +ALTER TABLE t1 TRUNCATE PARTITION p1; +INSERT INTO t1 PARTITION (p1) (c) SELECT 1; +DROP TABLE t1; +} diff --git a/mysql-test/suite/parts/inc/partition_basic.inc b/mysql-test/suite/parts/inc/partition_basic.inc new file mode 100644 index 00000000..35b016d5 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_basic.inc @@ -0,0 +1,113 @@ +################################################################################ +# inc/partition_basic.inc # +# # +# Purpose: # +# Basic tests around create partitioned table with/without PRIMARY KEY and # +# /or UNIQUE INDEX # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-03-05 # +# Change Author: # +# Change Date: # +# Change: # +################################################################################ +--enable_abort_on_error + +--echo +--echo #======================================================================== +--echo # Check partitioning methods on just created tables +--echo # The tables should be defined without/with PRIMARY KEY and +--echo # UNIQUE INDEXes. +--echo # Every test round has to check +--echo # PARTITION BY HASH/KEY/LIST/RANGE +--echo # PARTITION BY RANGE/LIST ... SUBPARTITION BY HASH/KEY ... +--echo #======================================================================== +--echo #------------------------------------------------------------------------ +--echo # 1 Tables without PRIMARY KEY or UNIQUE INDEXes +--echo #------------------------------------------------------------------------ +--echo # 1.1 The partitioning function contains one column. +let $unique= ; +--source suite/parts/inc/partition_methods1.inc +# +--echo # 1.2 The partitioning function contains two columns. +let $unique= ; +--source suite/parts/inc/partition_methods2.inc +# +--echo #------------------------------------------------------------------------ +--echo # 2 Tables with PRIMARY KEY and/or UNIQUE INDEXes +--echo # The partitioning function contains one column. +--echo #------------------------------------------------------------------------ +if ($more_pk_ui_tests) +{ + if ($do_pk_tests) + { + --echo # 2.1 PRIMARY KEY consisting of one column + let $unique= , PRIMARY KEY(f_int1); + --source suite/parts/inc/partition_methods1.inc + } + --echo # 2.2 UNIQUE INDEX consisting of one column + let $unique= , UNIQUE INDEX uidx1 (f_int1); + --source suite/parts/inc/partition_methods1.inc + # + if ($do_pk_tests) + { + --echo # 2.3 PRIMARY KEY consisting of two columns + let $unique= , PRIMARY KEY(f_int1,f_int2); + --source suite/parts/inc/partition_methods1.inc + let $unique= , PRIMARY KEY(f_int2,f_int1); + --source suite/parts/inc/partition_methods1.inc + } + # + --echo # 2.4 UNIQUE INDEX consisting of two columns + let $unique= , UNIQUE INDEX uidx1 (f_int1,f_int2); + --source suite/parts/inc/partition_methods1.inc + let $unique= , UNIQUE INDEX uidx1 (f_int2,f_int1); + --source suite/parts/inc/partition_methods1.inc + # +} +--echo # 2.5 PRIMARY KEY + UNIQUE INDEX consisting of two columns +if ($do_pk_tests) +{ + let $unique= , UNIQUE INDEX uidx1 (f_int1,f_int2), PRIMARY KEY(f_int2,f_int1); + --source suite/parts/inc/partition_methods1.inc + let $unique= , UNIQUE INDEX uidx1 (f_int2,f_int1), PRIMARY KEY(f_int1,f_int2); + --source suite/parts/inc/partition_methods1.inc +} +let $unique= , UNIQUE INDEX uidx1 (f_int1,f_int2), UNIQUE INDEX uidx2 (f_int2,f_int1); +--source suite/parts/inc/partition_methods1.inc + +--echo #------------------------------------------------------------------------ +--echo # 3 Tables with PRIMARY KEY and/or UNIQUE INDEXes +--echo # The partitioning function contains two columns. +--echo #------------------------------------------------------------------------ +# +if ($more_pk_ui_tests) +{ + if ($do_pk_tests) + { + --echo # 3.1 PRIMARY KEY consisting of two columns + let $unique= , PRIMARY KEY(f_int1,f_int2); + --source suite/parts/inc/partition_methods2.inc + + let $unique= , PRIMARY KEY(f_int2,f_int1); + --source suite/parts/inc/partition_methods2.inc + } + # + --echo # 3.2 UNIQUE INDEX consisting of two columns + let $unique= , UNIQUE INDEX uidx1 (f_int1,f_int2); + --source suite/parts/inc/partition_methods2.inc + let $unique= , UNIQUE INDEX uidx1 (f_int2,f_int1); + --source suite/parts/inc/partition_methods2.inc +} +# +--echo # 3.3 PRIMARY KEY and UNIQUE INDEX consisting of two columns +if ($do_pk_tests) +{ + let $unique= , UNIQUE INDEX uidx1 (f_int1,f_int2), PRIMARY KEY(f_int2,f_int1); + --source suite/parts/inc/partition_methods2.inc + let $unique= , UNIQUE INDEX uidx1 (f_int2,f_int1), PRIMARY KEY(f_int1,f_int2); + --source suite/parts/inc/partition_methods2.inc +} +let $unique= , UNIQUE INDEX uidx1 (f_int1,f_int2), UNIQUE INDEX uidx2 (f_int2,f_int1); +--source suite/parts/inc/partition_methods2.inc diff --git a/mysql-test/suite/parts/inc/partition_basic_symlink.inc b/mysql-test/suite/parts/inc/partition_basic_symlink.inc new file mode 100644 index 00000000..94d48fca --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_basic_symlink.inc @@ -0,0 +1,44 @@ +################################################################################ +# inc/partition_basic_symlink.inc # +# # +# Purpose: # +# Basic tests around create partitioned table with/without PRIMARY KEY and # +# /or UNIQUE INDEX # +# Also includes test for DATA/INDEX DIR which requires symlinked files # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-03-05 # +# Change Author: mattiasj # +# Change Date: 2008-02-06 # +# Change: copied it from partition_basic.inc and kept DATA/INDEX DIR # +################################################################################ +--enable_abort_on_error + +--echo +let $unique= ; + +# DATA DIRECTORY +# Make directory for partition data +let $data_dir_path= $MYSQLTEST_VARDIR/mysql-test-data-dir; +--mkdir $data_dir_path +let $data_directory= DATA DIRECTORY = '$data_dir_path'; + +#INDEX DIRECTORY +# Make directory for partition index +let $idx_dir_path= $MYSQLTEST_VARDIR/mysql-test-idx-dir; +--mkdir $idx_dir_path +let $index_directory= INDEX DIRECTORY = '$idx_dir_path'; + +let $with_directories= 1; +--echo #======================================================================== +--echo # 0.5 use partition_basic with DATA/INDEX DIRECTORY +--echo #======================================================================== +--source suite/parts/inc/partition_basic.inc +--echo #======================================================================== +--echo # 5 use partition_directory with DATA/INDEX DIRECTORY +--echo #======================================================================== +--source suite/parts/inc/partition_directory.inc +--rmdir $data_dir_path +--rmdir $idx_dir_path +let $with_directories= 0; diff --git a/mysql-test/suite/parts/inc/partition_bigint.inc b/mysql-test/suite/parts/inc/partition_bigint.inc new file mode 100644 index 00000000..dfab6dc6 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_bigint.inc @@ -0,0 +1,56 @@ +eval create table t1 (a bigint unsigned not null, primary key(a)) engine=$engine +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +insert into t1 values (18446744073709551615), (0xFFFFFFFFFFFFFFFE), (18446744073709551613), (18446744073709551612), (1), (2), (65535); +--sorted_result +select * from t1; +select * from t1 where a=-2; +delete from t1 where a=-2; +--sorted_result +select * from t1; +select * from t1 where a=18446744073709551615; +delete from t1 where a=18446744073709551615; +--sorted_result +select * from t1; +drop table t1; + +eval create table t2 (a bigint unsigned not null, primary key(a)) engine=$engine +partition by key (a) partitions 8; +show create table t2; +insert into t2 values (18446744073709551615), (0xFFFFFFFFFFFFFFFE), (18446744073709551613), (18446744073709551612); +--sorted_result +select * from t2; +select * from t2 where a=18446744073709551615; +delete from t2 where a=18446744073709551615; +--sorted_result +select * from t2; +delete from t2; +let $count=$maxrows; +--echo $maxrows inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t2 values ($count); +dec $count; +} +commit; +--enable_query_log +select count(*) from t2; +drop table t2; + +eval create table t3 (a bigint not null, primary key(a)) engine=$engine +partition by key (a) partitions 7; +show create table t3; +insert into t3 values (9223372036854775807), (9223372036854775806), (9223372036854775805), (9223372036854775804), (-9223372036854775808), (-9223372036854775807), (1), (-1), (0); +--sorted_result +select * from t3; +select * from t3 where a=9223372036854775806; +delete from t3 where a=9223372036854775806; +--sorted_result +select * from t3; +drop table t3; diff --git a/mysql-test/suite/parts/inc/partition_binary.inc b/mysql-test/suite/parts/inc/partition_binary.inc new file mode 100644 index 00000000..21e9635c --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_binary.inc @@ -0,0 +1,99 @@ +--echo ---- Partitioning and binary data type + +eval create table t1 (a binary(255) not null, primary key(a)) engine=$engine +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +insert into t1 values (repeat('a',255)), ('b'), (repeat('a',128)), (repeat('b',64)); +--sorted_result +select hex(a) from t1; +select a from t1 where substr(a,1,2)='b\0'; +update t1 set a='cc' where substr(a,1,2)= 'b\0'; +select a from t1 where substr(a,1,1)='c'; +delete from t1 where substr(a,1,2)='cc'; +--sorted_result +select hex(a) from t1; +drop table t1; + +eval create table t2 (a binary(255) not null, primary key(a)) engine=$engine +partition by key (a) partitions 27; +show create table t2; +let $count=26; +let $letter=0; +--echo $count inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t2 values (repeat(char(ascii('a')+$letter),$count+54)); +dec $count; +inc $letter; +} +commit; +--enable_query_log +select count(*) from t2; +--sorted_result +select hex(a) from t2; +drop table t2; + +# mleich: Several partitioning functions are no more allowed. +if (0) +{ +eval create table t3 (a binary(255) not null, primary key(a)) engine=$engine +partition by range (ascii(a)) subpartition by key (a) subpartitions 4 ( +partition pa16 values less than (16), +partition pa32 values less than (32), +partition pa64 values less than (64), +partition pa128 values less than (128), +partition pa256 values less than (256) +); +show create table t3; +let $count=26; +let $letter=0; +--echo $count inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t3 values (repeat(char(ascii('a')+$letter),$count+54)); +dec $count; +inc $letter; +} +commit; +--enable_query_log +select count(*) from t3; +select hex(a) from t3; +drop table t3; + + +eval create table t4 (a binary(255) not null, primary key(a)) engine=$engine +partition by list (ascii(a)) subpartition by key (a) subpartitions 4 ( +partition pa16 values in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16), +partition pa32 values in (17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32), +partition pa64 values in (33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64), +partition pa128 values in (65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128), +partition pa256 values in (129,130,131,132,133,134,135,136,137,138,139,140 +,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256) +); +show create table t4; +let $count=26; +let $letter=0; +--echo $count inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t4 values (repeat(char(ascii('a')+$letter),$count+54)); +dec $count; +inc $letter; +} +commit; +--enable_query_log +select count(*) from t4; +select hex(a) from t4; +drop table t4; +} +# End of tests with disallowed partitioning functions. diff --git a/mysql-test/suite/parts/inc/partition_bit.inc b/mysql-test/suite/parts/inc/partition_bit.inc new file mode 100644 index 00000000..4badbe59 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_bit.inc @@ -0,0 +1,114 @@ +--disable_warnings +drop table if exists t1; +--enable_warnings + +--error ER_TOO_BIG_DISPLAYWIDTH +eval create table t1 (a bit(65), primary key (a)) engine=$engine partition by key (a); + +eval create table t1 (a bit(0), primary key (a)) engine=$engine partition by key (a); +show create table t1; +drop table t1; + +eval create table t1 (a bit(0), primary key (a)) engine=$engine +partition by key (a) ( +partition pa1, +partition pa2); +show create table t1; +drop table t1; + +eval create table t1 (a bit(64), primary key (a)) engine=$engine +partition by key (a) partitions 2; +show create table t1; +insert into t1 values +(b'1111111111111111111111111111111111111111111111111111111111111111'), +(b'1000000000000000000000000000000000000000000000000000000000000000'), +(b'0000000000000000000000000000000000000000000000000000000000000001'), +(b'1010101010101010101010101010101010101010101010101010101010101010'), +(b'0101010101010101010101010101010101010101010101010101010101010101'); +--sorted_result +select hex(a) from t1; +drop table t1; + +eval create table t1 (a bit(64), primary key (a)) engine=$engine +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +insert into t1 values +(b'1111111111111111111111111111111111111111111111111111111111111111'), +(b'1000000000000000000000000000000000000000000000000000000000000000'), +(b'0000000000000000000000000000000000000000000000000000000000000001'), +(b'1010101010101010101010101010101010101010101010101010101010101010'), +(b'0101010101010101010101010101010101010101010101010101010101010101'); +select hex(a) from t1 where a=b'0101010101010101010101010101010101010101010101010101010101010101'; +delete from t1 where a=b'0101010101010101010101010101010101010101010101010101010101010101'; +--sorted_result +select hex(a) from t1; +drop table t1; + +eval create table t2 (a bit, primary key (a)) engine=$engine +partition by key (a) partitions 4; +show create table t2; +insert into t2 values (b'0'), (b'1'); +--sorted_result +select hex(a) from t2; +alter table t2 drop primary key; +show create table t2; +--sorted_result +select hex(a) from t2; +alter table t2 add primary key (a); +show create table t2; +--sorted_result +select hex(a) from t2; +drop table t2; + +eval create table t3 (a bit(8), primary key (a)) engine=$engine +partition by range (a) subpartition by key (a) subpartitions 2 ( +partition pa1 values less than (3), +partition pa2 values less than (16), +partition pa3 values less than (64), +partition pa4 values less than (256)); +show create table t3; +let $count=255; +--echo $count inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t3 values ($count); +dec $count; +} +commit; +--enable_query_log +select hex(a) from t3 where a=b'01010101'; +delete from t3 where a=b'01010101'; +select count(*) from t3; +--sorted_result +select hex(a) from t3; +drop table t3; + +eval create table t4 (a bit(8), primary key (a)) engine=$engine +partition by list (a) subpartition by key (a) subpartitions 2 ( +partition pa1 values in (0,1,2,3), +partition pa2 values in (4,5,6,7,8,9,10,11,12,13,14,15,16), +partition pa3 values in (17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32)); +show create table t4; +let $count=32; +--echo $count inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t4 values ($count); +dec $count; +} +commit; +--enable_query_log +select hex(a) from t4 where a=b'00000001'; +delete from t4 where a=b'00000001'; +select count(*) from t4; +--sorted_result +select hex(a) from t4; +drop table t4; diff --git a/mysql-test/suite/parts/inc/partition_blob.inc b/mysql-test/suite/parts/inc/partition_blob.inc new file mode 100644 index 00000000..0c3ec3fc --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_blob.inc @@ -0,0 +1,50 @@ +--echo ---- Partitioning and blob data type + +--error ER_BLOB_FIELD_IN_PART_FUNC_ERROR +eval create table t1 (a blob not null, primary key(a(767))) engine=$engine +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); + +#show create table t1; +#insert into t1 values (repeat('a',1000)), ('b'), (repeat('a',500)), (repeat('b',64)); +#select * from t1; +#select * from t1 where a='b'; +#update t1 set a='bb' where a='b'; +#delete from t1 where a='bb'; +#select * from t1; +#drop table t1; + +--error ER_BLOB_FIELD_IN_PART_FUNC_ERROR +eval create table t2 (a blob not null, primary key(a(767))) engine=$engine +partition by key (a) partitions 30; + +--error ER_BLOB_FIELD_IN_PART_FUNC_ERROR +eval create table t2 (a tinyblob not null, primary key(a(767))) engine=$engine +partition by key (a) partitions 30; + +--error ER_BLOB_FIELD_IN_PART_FUNC_ERROR +eval create table t2 (a mediumblob not null, primary key(a(767))) engine=$engine +partition by key (a) partitions 30; + +--error ER_BLOB_FIELD_IN_PART_FUNC_ERROR +eval create table t2 (a longblob not null, primary key(a(767))) engine=$engine +partition by key (a) partitions 30; + +#show create table t2; +#let $count=30; +#let $letter=0; +#--echo $count inserts; +#--disable_query_log +#while ($count) +#{ +#eval insert into t2 values (repeat(char(ascii('a')+$letter),$count*$count)); +#dec $count; +#inc $letter; +#} +#select count(*) from t2; +#select * from t2; +#drop table t2; + diff --git a/mysql-test/suite/parts/inc/partition_blocked_sql_funcs.inc b/mysql-test/suite/parts/inc/partition_blocked_sql_funcs.inc new file mode 100644 index 00000000..3e687666 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_blocked_sql_funcs.inc @@ -0,0 +1,141 @@ +################################################################################ +# t/partition_blocked_sql_funcs.inc # +# # +# Purpose: # +# Tests around sql functions # +# # +# # +#------------------------------------------------------------------------------# +# Original Author: HH # +# Original Date: 2006-11-22 # +# Change Author: # +# Change Date: # +# Change: # +################################################################################ +--echo ------------------------------------------------------------------------- +--echo --- $sqlfunc in partition with coltype $coltype +--echo ------------------------------------------------------------------------- +--echo must all fail! +--disable_warnings +drop table if exists t1 ; +drop table if exists t2 ; +drop table if exists t3 ; +drop table if exists t4 ; +drop table if exists t5 ; +drop table if exists t6 ; +--enable_warnings + +--error ER_PARTITION_FUNCTION_IS_NOT_ALLOWED,ER_PARSE_ERROR +eval create table t1 (col1 $coltype) engine=$engine +partition by range($sqlfunc) +(partition p0 values less than (15), + partition p1 values less than (31)); + +--error ER_PARTITION_FUNCTION_IS_NOT_ALLOWED,ER_PARSE_ERROR +eval create table t2 (col1 $coltype) engine=$engine +partition by list($sqlfunc) +(partition p0 values in (1,2,3,4,5,6,7,8,9,10), + partition p1 values in (11,12,13,14,15,16,17,18,19,20), + partition p2 values in (21,22,23,24,25,26,27,28,29,30)); + +--error ER_PARTITION_FUNCTION_IS_NOT_ALLOWED,ER_PARSE_ERROR +eval create table t3 (col1 $coltype) engine=$engine +partition by hash($sqlfunc); + +--error ER_PARTITION_FUNCTION_IS_NOT_ALLOWED,ER_PARSE_ERROR +eval create table t4 (colint int, col1 $coltype) engine=$engine +partition by range(colint) +subpartition by hash($sqlfunc) subpartitions 2 +(partition p0 values less than (15), + partition p1 values less than (31)); + +--error ER_PARTITION_FUNCTION_IS_NOT_ALLOWED,ER_PARSE_ERROR +eval create table t5 (colint int, col1 $coltype) engine=$engine +partition by list(colint) +subpartition by hash($sqlfunc) subpartitions 2 +(partition p0 values in (1,2,3,4,5,6,7,8,9,10), + partition p1 values in (11,12,13,14,15,16,17,18,19,20), + partition p2 values in (21,22,23,24,25,26,27,28,29,30)); + +--error ER_PARTITION_FUNCTION_IS_NOT_ALLOWED,ER_PARSE_ERROR +eval create table t6 (colint int, col1 $coltype) engine=$engine +partition by range(colint) +(partition p0 values less than ($valsqlfunc), + partition p1 values less than maxvalue); + +--disable_abort_on_error +--disable_warnings +drop table if exists t11 ; +drop table if exists t22 ; +drop table if exists t33 ; +drop table if exists t44 ; +drop table if exists t55 ; +drop table if exists t66 ; +--enable_warnings + +eval create table t11 (col1 $coltype) engine=$engine ; + +eval create table t22 (col1 $coltype) engine=$engine ; + +eval create table t33 (col1 $coltype) engine=$engine ; + +eval create table t44 (colint int, col1 $coltype) engine=$engine ; + +eval create table t55 (colint int, col1 $coltype) engine=$engine ; + +eval create table t66 (colint int, col1 $coltype) engine=$engine ; + +--error ER_PARTITION_FUNCTION_IS_NOT_ALLOWED,ER_PARSE_ERROR +eval alter table t11 +partition by range($sqlfunc) +(partition p0 values less than (15), + partition p1 values less than (31)); + +--error ER_PARTITION_FUNCTION_IS_NOT_ALLOWED,ER_PARSE_ERROR +eval alter table t22 +partition by list($sqlfunc) +(partition p0 values in (1,2,3,4,5,6,7,8,9,10), + partition p1 values in (11,12,13,14,15,16,17,18,19,20), + partition p2 values in (21,22,23,24,25,26,27,28,29,30)); + +--error ER_PARTITION_FUNCTION_IS_NOT_ALLOWED,ER_PARSE_ERROR +eval alter table t33 +partition by hash($sqlfunc); +--enable_abort_on_error + +--error ER_PARTITION_FUNCTION_IS_NOT_ALLOWED,ER_PARSE_ERROR +eval alter table t44 +partition by range(colint) +subpartition by hash($sqlfunc) subpartitions 2 +(partition p0 values less than (15), + partition p1 values less than (31)); + +--error ER_PARTITION_FUNCTION_IS_NOT_ALLOWED,ER_PARSE_ERROR +eval alter table t55 +partition by list(colint) +subpartition by hash($sqlfunc) subpartitions 2 +(partition p0 values in (1,2,3,4,5,6,7,8,9,10), + partition p1 values in (11,12,13,14,15,16,17,18,19,20), + partition p2 values in (21,22,23,24,25,26,27,28,29,30)); + +--error ER_PARTITION_FUNCTION_IS_NOT_ALLOWED,ER_PARSE_ERROR +eval alter table t66 +partition by range(colint) +(partition p0 values less than ($valsqlfunc), + partition p1 values less than maxvalue); + +--disable_warnings +drop table if exists t1 ; +drop table if exists t2 ; +drop table if exists t3 ; +drop table if exists t4 ; +drop table if exists t5 ; +drop table if exists t6 ; +drop table if exists t11 ; +drop table if exists t22 ; +drop table if exists t33 ; +drop table if exists t44 ; +drop table if exists t55 ; +drop table if exists t66 ; +--enable_warnings + diff --git a/mysql-test/suite/parts/inc/partition_char.inc b/mysql-test/suite/parts/inc/partition_char.inc new file mode 100644 index 00000000..d28ed315 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_char.inc @@ -0,0 +1,97 @@ +--echo ---- Partitioning and char data type + +eval create table t1 (a char(255) not null, primary key(a)) engine=$engine +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +insert into t1 values (repeat('a',255)), ('b'), (repeat('a',128)), (repeat('b',64)); +--sorted_result +select * from t1; +select * from t1 where a='b'; +update t1 set a='bb' where a='b'; +delete from t1 where a='bb'; +--sorted_result +select * from t1; +drop table t1; + +eval create table t2 (a char(255) not null, primary key(a)) engine=$engine +partition by key (a) partitions 27; +show create table t2; +let $count=26; +let $letter=0; +--echo $count inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t2 values (repeat(char(ascii('a')+$letter),$count+54)); +dec $count; +inc $letter; +} +commit; +--enable_query_log +select count(*) from t2; +--sorted_result +select * from t2; +drop table t2; + +# mleich: Several partitioning functions are no more allowed. +if (0) +{ +eval create table t3 (a char(255) not null, primary key(a)) engine=$engine +partition by range (ascii(a)) subpartition by key (a) subpartitions 4 ( +partition pa16 values less than (16), +partition pa32 values less than (32), +partition pa64 values less than (64), +partition pa128 values less than (128), +partition pa256 values less than (256) +); +show create table t3; +let $count=26; +let $letter=0; +--echo $count inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t3 values (repeat(char(ascii('a')+$letter),$count+54)); +dec $count; +inc $letter; +} +commit; +--enable_query_log +select count(*) from t3; +select a from t3; +drop table t3; + +eval create table t4 (a char(255) not null, primary key(a)) engine=$engine +partition by list (ascii(a)) subpartition by key (a) subpartitions 4 ( +partition pa16 values in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16), +partition pa32 values in (17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32), +partition pa64 values in (33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64), +partition pa128 values in (65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128), +partition pa256 values in (129,130,131,132,133,134,135,136,137,138,139,140 +,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256) +); +show create table t4; +let $count=26; +let $letter=0; +--echo $count inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t4 values (repeat(char(ascii('a')+$letter),$count+54)); +dec $count; +inc $letter; +} +commit; +--enable_query_log +select count(*) from t4; +select a from t4; +drop table t4; +} +# End of tests with disallowed partitioning functions. diff --git a/mysql-test/suite/parts/inc/partition_check.inc b/mysql-test/suite/parts/inc/partition_check.inc new file mode 100644 index 00000000..ed323dfa --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_check.inc @@ -0,0 +1,1152 @@ +################################################################################ +# inc/partition_check.inc # +# # +# Purpose: # +# Do some basic usability checks on table t1. # +# This routine is only useful for the partition_<feature>_<engine> tests. # +# # +# Some Notes: # +# It is intended that in many testcases (statements) more than one partition # +# or subpartition is affected. # +# Without analysis of the partitioning function used during CREATE TABLE # +# we cannot be 100% sure that this goal is reached. # +# But statements affecting many rows give a good probability that this # +# appears. # +# # +# It is expected that the table to be checked contains at the beginning # +# of this script records following the scheme # +# f_int1 f_int2 f_char1 f_char2 f_charbig # +# 1 1 '1' '1' '###1###' # +# 2 2 '2' '1' '###2###' # +# ... ... ... ... ... # +# x x 'x' 'x' '###x###' # +# x = @max_row # +# # +# The table content must be equal to the content of the table t0_template. # +# Attention: Please be careful when modiying the data. # +# Records can be deleted or inserted, but the content of the # +# records after a test/testsequence should follow this scheme. # +# # +# All checks of preceding statements via Select are so written, # +# that they deliver a # +# # check <n> success: 1 # +# when everything is like expected. # +# - f_charbig is typically used for showing if something was changed. # +# This is useful for cleanups. # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-03-05 # +# Change Author: mleich # +# Change Date: 2007-10-08 # +# Change: Around fix for # +# Bug#31243 Test "partition_basic_myisam" truncates path names# +# Adjustments of expected error codes: # +# ER_NO_PARTITION_FOR_GIVEN_VALUE is now 1525 # +# ER_SAME_NAME_PARTITION is now 1516 # +################################################################################ + + +--echo # Start usability test (inc/partition_check.inc) +# Print the CREATE TABLE STATEMENT and store the current layout of the table +--source suite/parts/inc/partition_layout_check1.inc + + +#------------------------------------------------------------------------------- +## 1. Check the prerequisites for the following tests +# (sideeffect some SELECT functionality is also tested) +# Determine if we have PRIMARY KEYs or UNIQUE INDEXes +## 1.1 Check if the content of the records is like expected +# Sideeffect: mass SELECT, all records/partitions/subpartitions have to be +# read, because at least f_charbig is not part of any +# INDEX/PRIMARY KEY +if ($no_debug) +{ +--disable_query_log +} +let $my_stmt= SELECT COUNT(*) <> 0 INTO @aux FROM t1 +WHERE f_int1 <> f_int2 OR f_char1 <> CAST(f_int1 AS CHAR) OR f_char1 <> f_char2 + OR f_charbig <> CONCAT('===',f_char1,'===') + OR f_int1 IS NULL OR f_int2 IS NULL OR f_char1 IS NULL OR f_char2 IS NULL + OR f_charbig IS NULL; +eval $my_stmt; +let $run= `SELECT @aux`; +--enable_query_log +if ($run) +{ + --echo # Prerequisites for following tests not fullfilled. + --echo # The content of the table t1 is unexpected + eval $my_stmt; + SELECT @aux; + --echo # Sorry, have to abort. + exit; +} +# Give a success message like in the other following tests +--echo # check prerequisites-1 success: 1 +#------------------------------------------------------------------------------- +## 1.2 Check if the number of records and the maximum and minimum values are +# like expected +# Sideeffect: Check +# - COUNT(*) +# - MIN/MAX on all columns possibly used in part. function +# The optimizer might decide to run on INDEX only, if available. +# +## 1.2.1 Check COUNT(*) +if ($no_debug) +{ +--disable_query_log +} +let $my_stmt= SELECT COUNT(*) <> @max_row INTO @aux FROM t1; +let $run= `SELECT @aux`; +--enable_query_log +if ($run) +{ + --echo # Prerequisites for following tests not fullfilled. + --echo # The content of the table t1 is unexpected + eval $my_stmt; + SELECT @aux; + --echo # Sorry, have to abort. + exit; +} +# Give a success message like in the other following tests +--echo # check COUNT(*) success: 1 +## 1.2.2 Check MAX(f_int1),MIN(f_int1) +if ($no_debug) +{ +--disable_query_log +} +let $my_stmt= SELECT MIN(f_int1) <> 1 AND MAX(f_int1) <> @max_row INTO @aux +FROM t1; +let $run= `SELECT @aux`; +--enable_query_log +if ($run) +{ + --echo # Prerequisites for following tests not fullfilled. + --echo # The content of the table t1 is unexpected + eval $my_stmt; + SELECT @aux; + --echo # Sorry, have to abort. + exit; +} +# Give a success message like in the other following tests +--echo # check MIN/MAX(f_int1) success: 1 +## 1.2.3 Check MAX(f_int2),MIN(f_int2) +if ($no_debug) +{ +--disable_query_log +} +let $my_stmt= SELECT MIN(f_int2) <> 1 AND MAX(f_int2) <> @max_row INTO @aux +FROM t1; +let $run= `SELECT @aux`; +--enable_query_log +if ($run) +{ + --echo # Prerequisites for following tests not fullfilled. + --echo # The content of the table t1 is unexpected + eval $my_stmt; + SELECT @aux; + --echo # Sorry, have to abort. + exit; +} +# Give a success message like in the other following tests +--echo # check MIN/MAX(f_int2) success: 1 + +#------------------------------------------------------------------------------- +## 1.3 Check, if f_int1 and/or f_char2 and/or (f_char1,f_char2) is UNIQUE +# by testing if any DUPLICATE KEY might appear +# Note: INFORMATION_SCHEMA SELECTs could be also used, but testing the +# table via INSERT and SELECT is better because is stresses the +# partitioning mechanism. +# Sideeffect: Attempt to INSERT one record +# DUPLICATE KEY will appear if we have UNIQUE columns +# ER_DUP_KEY, ER_DUP_ENTRY +--disable_abort_on_error +INSERT INTO t1 (f_int1, f_int2, f_char1, f_char2, f_charbig) +SELECT f_int1, f_int1, CAST(f_int1 AS CHAR), + CAST(f_int1 AS CHAR), 'delete me' FROM t0_template +WHERE f_int1 IN (2,3); +--enable_abort_on_error +if ($no_debug) +{ +--disable_query_log +} +eval SET @my_errno = $mysql_errno; +let $run_delete= `SELECT @my_errno = 0`; +let $any_unique= `SELECT @my_errno IN ($ER_DUP_KEY,$ER_DUP_ENTRY)`; +# DEBUG eval SELECT $run_delete AS run_delete, $any_unique AS any_unique, +# @my_errno AS sql_errno; +if (`SELECT @my_errno NOT IN (0,$ER_DUP_KEY,$ER_DUP_ENTRY)`) +{ + --echo # The last command got an unexpected error response. + --echo # Expected/handled SQL codes are 0,$ER_DUP_KEY,$ER_DUP_ENTRY + SELECT '# SQL code we got was: ' AS "", @my_errno AS ""; + --echo # Sorry, have to abort. + exit; + --echo +} +# Give a success message like in the other following tests +--echo # check prerequisites-3 success: 1 +--enable_query_log +# DEBUG eval SELECT $run_delete AS run_delete, $any_unique AS any_unique; +if ($run_delete) +{ + # INSERT was successful -> DELETE this new record + DELETE FROM t1 WHERE f_charbig = 'delete me'; + --echo # INFO: Neither f_int1 nor f_int2 nor (f_int1,f_int2) is UNIQUE +} +if ($any_unique) +{ + --echo # INFO: f_int1 AND/OR f_int2 AND/OR (f_int1,f_int2) is UNIQUE + + ## 1.3.1 Check, if f_int1 is UNIQUE + # Sideeffect: Attempt to INSERT one record + # DUPLICATE KEY will appear if we have UNIQUE columns + # ER_DUP_KEY, ER_DUP_ENTRY + --disable_abort_on_error + INSERT INTO t1 (f_int1, f_int2, f_char1, f_char2, f_charbig) + SELECT f_int1, 2 * @max_row + f_int1, CAST((2 * @max_row + f_int1) AS CHAR), + CAST((2 * @max_row + f_int1) AS CHAR), 'delete me' FROM t0_template + WHERE f_int1 IN (2,3); + --enable_abort_on_error + if ($no_debug) + { + --disable_query_log + } + eval SET @my_errno = $mysql_errno; + let $run_delete= `SELECT @my_errno = 0`; + let $f_int1_is_unique= `SELECT @my_errno IN ($ER_DUP_KEY,$ER_DUP_ENTRY)`; + # DEBUG eval SELECT $run_delete AS run_delete, $f_int1_is_unique AS any_unique, + # @my_errno AS sql_errno; + if (`SELECT @my_errno NOT IN (0,$ER_DUP_KEY,$ER_DUP_ENTRY)`) + { + --echo # The last command got an unexpected error response. + --echo # Expected/handled SQL codes are 0,$ER_DUP_KEY,$ER_DUP_ENTRY + SELECT '# SQL code we got was: ' AS "", @my_errno AS ""; + --echo # Sorry, have to abort. + exit; + --echo + } + --enable_query_log + if ($f_int1_is_unique) + { + --echo # INFO: f_int1 is UNIQUE + } + if ($run_delete) + { + # INSERT was successful -> DELETE this new record + DELETE FROM t1 WHERE f_charbig = 'delete me'; + } + + ## 1.3.2 Check, if f_int2 is UNIQUE (get ER_DUP_KEY or ER_DUP_ENTRY + --disable_abort_on_error + INSERT INTO t1 (f_int1, f_int2, f_char1, f_char2, f_charbig) + SELECT 2 * @max_row + f_int1, f_int1, CAST((2 * @max_row + f_int1) AS CHAR), + CAST((2 * @max_row + f_int1) AS CHAR), 'delete me' FROM t0_template + WHERE f_int1 IN (2,3); + --enable_abort_on_error + if ($no_debug) + { + --disable_query_log + } + eval SET @my_errno = $mysql_errno; + let $run_delete= `SELECT @my_errno = 0`; + let $f_int1_is_unique= `SELECT @my_errno IN ($ER_DUP_KEY,$ER_DUP_ENTRY)`; + # DEBUG eval SELECT $run_delete AS run_delete, $f_int1_is_unique AS any_unique, + # @my_errno AS sql_errno; + if (`SELECT @my_errno NOT IN (0,$ER_DUP_KEY,$ER_DUP_ENTRY)`) + { + --echo # The last command got an unexpected error response. + --echo # Expected/handled SQL codes are 0,$ER_DUP_KEY,$ER_DUP_ENTRY + SELECT '# SQL code we got was: ' AS "", @my_errno AS ""; + --echo # Sorry, have to abort. + exit; + --echo + } + if ($f_int2_is_unique) + { + --echo # INFO: f_int2 is UNIQUE + } + --enable_query_log + if ($run_delete) + { + # INSERT was successful -> DELETE this new record + DELETE FROM t1 WHERE f_charbig = 'delete me'; + } +} + + +#------------------------------------------------------------------------------- +## 2. Read the table row by row +# Note: There were crashes in history when reading a partitioned table +# PRIMARY KEY AND/OR UNIQUE INDEXes +## 2.1 Read all existing and some not existing records of table +# per f_int1 used in partitioning function +let $col_to_check= f_int1; +--source suite/parts/inc/partition_check_read.inc +## 2.2 Read all existing and some not existing records of table +# per f_int2 used in partitioning function +let $col_to_check= f_int2; +--source suite/parts/inc/partition_check_read.inc + + +#------------------------------------------------------------------------------- +# 3 Some operations with multiple records +# 3.1 Select on "full" table +if ($no_debug) +{ +--disable_query_log +} +SELECT '# check multiple-1 success: ' AS "",COUNT(*) = @max_row AS "" FROM t1; +--enable_query_log +# +# 3.2 (mass) DELETE of @max_row_div3 records +DELETE FROM t1 WHERE MOD(f_int1,3) = 0; +if ($no_debug) +{ +--disable_query_log +} +SELECT '# check multiple-2 success: ' AS "",COUNT(*) = @max_row - @max_row_div3 AS "" FROM t1; +--enable_query_log +# +# 3.3 (mass) Insert of @max_row_div3 records +# (Insert the records deleted in 3.2) +INSERT INTO t1 SELECT * FROM t0_template +WHERE MOD(f_int1,3) = 0; +# Check of preceding statement via Select +if ($no_debug) +{ +--disable_query_log +} +SELECT '# check multiple-3 success: ' AS "", +(COUNT(*) = @max_row) AND (MIN(f_int1) = 1) AND (MAX(f_int1) = @max_row) AS "" +FROM t1; +--enable_query_log +# DEBUG SELECT COUNT(*),MIN(f_int1),MAX(f_int1) FROM t1; +# +# 3.4 (mass) Update @max_row_div4 * 2 + 1 records +UPDATE t1 SET f_int1 = f_int1 + @max_row +WHERE f_int1 BETWEEN @max_row_div2 - @max_row_div4 + AND @max_row_div2 + @max_row_div4; +# Check of preceding statement via Select +if ($no_debug) +{ +--disable_query_log +} +SELECT '# check multiple-4 success: ' AS "",(COUNT(*) = @max_row) AND (MIN(f_int1) = 1) AND +(MAX(f_int1) = @max_row_div2 + @max_row_div4 + @max_row ) AS "" FROM t1; +--enable_query_log +# DEBUG SELECT COUNT(*),MIN(f_int1),MAX(f_int1) FROM t1; +# +# 3.5 (mass) Delete @max_row_div4 * 2 + 1 records +# (Delete the records updated in 3.4) +DELETE FROM t1 +WHERE f_int1 BETWEEN @max_row_div2 - @max_row_div4 + @max_row + AND @max_row_div2 + @max_row_div4 + @max_row; +# Check of preceding statement via Select +if ($no_debug) +{ +--disable_query_log +} +SELECT '# check multiple-5 success: ' AS "", +(COUNT(*) = @max_row - @max_row_div4 - @max_row_div4 - 1) +AND (MIN(f_int1) = 1) AND (MAX(f_int1) = @max_row) AS "" FROM t1; +--enable_query_log +# DEBUG SELECT COUNT(*),MIN(f_int1),MAX(f_int1) FROM t1; + +#------------------------------------------------------------------------------- +# Attention: After this section all modification on the table have to be reverted ! +# Current content of t1 follows the rule: +# <value>,<value>,'<value>','<value>',===<value>=== +# <value> contains all INTEGER values +# between 1 and @max_row_div2 - @max_row_div4 - 1 +# and +# between @max_row_div2 + @max_row_div4 + 1 and @max_row +# With other words the values between @max_row_div2 - @max_row_div4 +# and @max_row_div2 + @max_row_div4 are "missing". +#------------------------------------------------------------------------------- +# The following is only needed for tests of UNIQUE CONSTRAINTs. +if ($any_unique) +{ + # Calculate the number of records, where we will try INSERT ..... or REPLACE + SELECT COUNT(*) INTO @try_count FROM t0_template + WHERE MOD(f_int1,3) = 0 + AND f_int1 BETWEEN @max_row_div2 AND @max_row; + # + # Calculate the number of records, where we will get DUPLICATE KEY + # f_int1 is sufficient for calculating this, because 1.1 + # checks, that f_int1 = f_int2 is valid for all rows. + SELECT COUNT(*) INTO @clash_count + FROM t1 INNER JOIN t0_template USING(f_int1) + WHERE MOD(f_int1,3) = 0 + AND f_int1 BETWEEN @max_row_div2 AND @max_row; + if ($debug) + { + SELECT @try_count, @clash_count; + } +} + + +#------------------------------------------------------------------------------- +# 4 Some operations with single records +# 4.1 Insert one record with a value for f_int1 which is lower than in all +# existing records. +SELECT MIN(f_int1) - 1 INTO @cur_value FROM t1; +INSERT INTO t1 +SET f_int1 = @cur_value , f_int2 = @cur_value, + f_char1 = CAST(@cur_value AS CHAR), f_char2 = CAST(@cur_value AS CHAR), + f_charbig = '#SINGLE#'; +# Check of preceding statement via Select +if ($no_debug) +{ +--disable_query_log +} +SELECT '# check single-1 success: ' AS "",COUNT(*) = 1 AS "" FROM t1 +WHERE f_int1 = @cur_value AND f_int2 = @cur_value + AND f_char1 = CAST(@cur_value AS CHAR) + AND f_char2 = CAST(@cur_value AS CHAR) AND f_charbig = '#SINGLE#'; +--enable_query_log +# +# 4.2 Insert one record with a value for f_int1 which is higher than in all +# existing records. +SELECT MAX(f_int1) + 1 INTO @cur_value FROM t1; +INSERT INTO t1 +SET f_int1 = @cur_value , f_int2 = @cur_value, + f_char1 = CAST(@cur_value AS CHAR), f_char2 = CAST(@cur_value AS CHAR), + f_charbig = '#SINGLE#'; +# Check of preceding statement via Select +if ($no_debug) +{ +--disable_query_log +} +SELECT '# check single-2 success: ' AS "",COUNT(*) = 1 AS "" FROM t1 +WHERE f_int1 = @cur_value AND f_int2 = @cur_value + AND f_char1 = CAST(@cur_value AS CHAR) + AND f_char2 = CAST(@cur_value AS CHAR) AND f_charbig = '#SINGLE#'; +--enable_query_log +# +# 4.3 Update one record. The value of f_int1 is altered from the lowest to +# the highest value of all existing records. +# If f_int1 is used for the partitioning expression a movement of the +# record to another partition/subpartition might appear. +SELECT MIN(f_int1) INTO @cur_value1 FROM t1; +SELECT MAX(f_int1) + 1 INTO @cur_value2 FROM t1; +UPDATE t1 SET f_int1 = @cur_value2 +WHERE f_int1 = @cur_value1 AND f_charbig = '#SINGLE#'; +# Check of preceding statement via Select +if ($no_debug) +{ +--disable_query_log +} +SELECT '# check single-3 success: ' AS "",COUNT(*) = 1 AS "" FROM t1 +WHERE f_int1 = @cur_value2 AND f_charbig = '#SINGLE#'; +--enable_query_log +# +# 4.4 Update one record. The value of f_int1 is altered from the highest value +# to a value lower than in all existing records. +# If f_int1 is used for the partitioning expression a movement of the +# record to another partition/subpartition might appear. +# f_int1 gets the delicate value '-1'. +SET @cur_value1= -1; +SELECT MAX(f_int1) INTO @cur_value2 FROM t1; +# Bug#15968: Partitions: crash when INSERT with f_int1 = -1 into PARTITION BY HASH(f_int1) +UPDATE t1 SET f_int1 = @cur_value1 +WHERE f_int1 = @cur_value2 AND f_charbig = '#SINGLE#'; +# Check of preceding statement via Select +if ($no_debug) +{ +--disable_query_log +} +SELECT '# check single-4 success: ' AS "",COUNT(*) AS "" FROM t1 +WHERE f_int1 = @cur_value1 AND f_charbig = '#SINGLE#'; +--enable_query_log +# +# 4.5 Delete the record with the highest value of f_int1. +SELECT MAX(f_int1) INTO @cur_value FROM t1; +DELETE FROM t1 WHERE f_int1 = @cur_value AND f_charbig = '#SINGLE#'; +# Check of preceding statements via Select +if ($no_debug) +{ +--disable_query_log +} +SELECT '# check single-5 success: ' AS "",COUNT(*) = 0 AS "" FROM t1 +WHERE f_charbig = '#SINGLE#' AND f_int1 = f_int1 = @cur_value; +--enable_query_log +# +# 4.6 Delete the record with f_int1 = -1 +DELETE FROM t1 WHERE f_int1 = -1 AND f_charbig = '#SINGLE#'; +# Check of preceding statements via Select +if ($no_debug) +{ +--disable_query_log +} +SELECT '# check single-6 success: ' AS "",COUNT(*) = 0 AS "" FROM t1 +WHERE f_charbig = '#SINGLE#' AND f_int1 IN (-1,@cur_value); +--enable_query_log +# +# 4.7 Insert one record with such a big value for f_int1, so that in case +# - f_int1 is used within the partitioning algorithm +# - we use range partitioning +# we get error ER_NO_PARTITION_FOR_GIVEN_VALUE +# "Table has no partition for value ...." +# or ER_SAME_NAME_PARTITION +--disable_abort_on_error +eval INSERT INTO t1 SET f_int1 = @max_int_4 , f_int2 = @max_int_4, f_charbig = '#$max_int_4##'; +--enable_abort_on_error +if ($no_debug) +{ +--disable_query_log +} +eval SET @my_errno = $mysql_errno; +if (`SELECT @my_errno NOT IN (0,$ER_SAME_NAME_PARTITION,$ER_NO_PARTITION_FOR_GIVEN_VALUE)`) +{ + --echo # The last command got an unexpected error response. + --echo # Expected/handled SQL codes are 0,$ER_SAME_NAME_PARTITION,$ER_NO_PARTITION_FOR_GIVEN_VALUE + SELECT '# SQL code we got was: ' AS "", @my_errno AS ""; + --echo # Sorry, have to abort. + exit; + --echo +} +# Check of preceding statement via Select, if the INSERT was successful +let $run= `SELECT @my_errno = 0`; +if ($run) +{ +# Attention: There are some tests where the column type is changed from +# INTEGER to MEDIUMINT. MEDIUMINT has a smaller range and the +# inserted value is automatically adjusted to the maximum value +# of the data type. +# that's the reason why we cannot use WHERE <column> = @max_int_4 here. +# +eval SELECT '# check single-7 success: ' AS "", +COUNT(*) = 1 AS "" FROM t1 WHERE f_charbig = '#$max_int_4##'; +# Revert this modification +--enable_query_log +eval DELETE FROM t1 WHERE f_charbig = '#$max_int_4##'; +} +--enable_query_log + + +#------------------------------------------------------------------------------- +# 5 Experiments with NULL +# If the result of the partitioning function IS NULL partitioning treats +# this record as if the the result of the partitioning function is +# MySQL 5.1 < March 2006 : zero +# MySQL 5.1 >= March 2006 : LONGLONG_MIN +# Let's INSERT a record where the result of the partitioning function is +# probably (depends on function currently used) zero and look if there are +# any strange effects during the execution of the next statements. +# Bug#18659: Partitions: wrong result on WHERE <col. used in part. function> IS NULL +DELETE FROM t1 WHERE f_int1 IS NULL OR f_int1 = 0; +# Attention: Zero should be tested +INSERT t1 SET f_int1 = 0 , f_int2 = 0, + f_char1 = CAST(0 AS CHAR), f_char2 = CAST(0 AS CHAR), + f_charbig = '#NULL#'; +# 5.1 Insert one record with f_int1 IS NULL. +# f1 "=" NULL is a delicate value which might stress the partitioning +# mechanism if the result of the expression in the partitioning algorithm +# becomes NULL. +# This INSERT will fail, if f_int1 is PRIMARY KEY or UNIQUE INDEX +# with ER_BAD_NULL_ERROR. +--disable_abort_on_error +INSERT INTO t1 + SET f_int1 = NULL , f_int2 = -@max_row, + f_char1 = CAST(-@max_row AS CHAR), f_char2 = CAST(-@max_row AS CHAR), + f_charbig = '#NULL#'; +# Some other NULL experiments if preceding INSERT was successfull +--enable_abort_on_error +if ($no_debug) +{ +--disable_query_log +} +eval SET @my_errno = $mysql_errno; +let $run= `SELECT @my_errno = 0`; +if (`SELECT @my_errno NOT IN (0,$ER_BAD_NULL_ERROR)`) +{ + --echo # The last command got an unexpected error response. + --echo # Expected/handled SQL codes are 0,$ER_BAD_NULL_ERROR + SELECT '# SQL code we got was: ' AS "", @my_errno AS ""; + --echo # Sorry, have to abort. + --echo # Please check the error name to number mapping in inc/partition.pre. + exit; + --echo +} +--enable_query_log +# Give a success message like in the other following tests +--echo # check null success: 1 +# The following checks do not make sense if f_int1 cannot be NULL +if ($run) +{ +# Check of preceding statement via Select +if ($no_debug) +{ +--disable_query_log +} +# Bug#17432: Partitions: wrong result, SELECT ... where <column> is null +SELECT '# check null-1 success: ' AS "",COUNT(*) = 1 AS "" FROM t1 +WHERE f_int1 IS NULL AND f_charbig = '#NULL#'; +--enable_query_log +# +# 5.2 Update of f_int1 from NULL to negative value +# Bug#17432: Partitions: wrong result, SELECT ... where <column> is null +UPDATE t1 SET f_int1 = -@max_row +WHERE f_int1 IS NULL AND f_int2 = -@max_row AND f_char1 = CAST(-@max_row AS CHAR) + AND f_char2 = CAST(-@max_row AS CHAR) AND f_charbig = '#NULL#'; +if ($no_debug) +{ +--disable_query_log +} +# Check of preceding statement via Select +SELECT '# check null-2 success: ' AS "",COUNT(*) = 1 AS "" FROM t1 +WHERE f_int1 = -@max_row AND f_charbig = '#NULL#'; +--enable_query_log +# 5.3 Update of f_int1 from negative value to NULL +UPDATE t1 SET f_int1 = NULL +WHERE f_int1 = -@max_row AND f_int2 = -@max_row AND f_char1 = CAST(-@max_row AS CHAR) + AND f_char2 = CAST(-@max_row AS CHAR) AND f_charbig = '#NULL#'; +if ($no_debug) +{ +--disable_query_log +} +# Check of preceding statement via Select +SELECT '# check null-3 success: ' AS "",COUNT(*) = 1 AS "" FROM t1 +WHERE f_int1 IS NULL AND f_charbig = '#NULL#'; +--enable_query_log +# 5.4 DELETE of the record with f_int1 IS NULL +DELETE FROM t1 +WHERE f_int1 IS NULL AND f_int2 = -@max_row AND f_char1 = CAST(-@max_row AS CHAR) + AND f_char2 = CAST(-@max_row AS CHAR) AND f_charbig = '#NULL#'; +# Check of preceding statement via Select +if ($no_debug) +{ +--disable_query_log +} +SELECT '# check null-4 success: ' AS "",COUNT(*) = 0 AS "" FROM t1 +WHERE f_int1 IS NULL; +--enable_query_log +} +# Remove the "0" record +DELETE FROM t1 +WHERE f_int1 = 0 AND f_int2 = 0 + AND f_char1 = CAST(0 AS CHAR) AND f_char2 = CAST(0 AS CHAR) + AND f_charbig = '#NULL#'; + + +#------------------------------------------------------------------------------- +## 6. UPDATEs of columns used in the partitioning function and the PRIMARY KEY +# the UNIQUE INDEX without using straight forward UPDATE. +# INSERT .... ON DUPLICATE KEY UPDATE .... --> update existing record +# REPLACE --> delete existing record + insert new record +# Note: +# - This test is skipped for tables without any PRIMARY KEY or +# UNIQUE INDEX. +# - MOD(<column>,n) with n = prime number, n <> 2 is used to cause +# that many records and most probably more than one PARTITION/ +# SUBPARTITION are affected. +# - Under certain circumstanditions a movement of one or more records +# to other PARTITIONs/SUBPARTITIONs might appear. +# - There are some storage engines, which are unable to revert changes +# of a failing statement. This has to be taken into account when +# checking if a DUPLICATE KEY might occur. +# +# What to test ? +# UNIQUE columns +# f_int1 IU f_int1 IU f_int1,f_int2 R +# f_int2 IU f_int2 IU f_int1,f_int2 R +# f_int1,f_int2 IU f_int1,f_int2 R +# +# IU column = INSERT .. ON DUPLICATE KEY UPDATE column +# R = REPLACE .. +# +# Current state of the data +# 1. f_int1 = f_int2, f_char1 = CAST(f_int1 AS CHAR), f_char2 = f_char1, +# f_charbig = CONCAT('===',f_char1,'===); +# 2. f_int1 FROM 1 TO @max_row_div4 +# AND @max_row_div2 + @max_row_div4 TO @max_row +# +# Do not apply the following tests to tables without UNIQUE columns. +if ($any_unique) +{ + let $num= 1; + if ($f_int1_is_unique) + { + ## 6.1 f_int1 is UNIQUE, UPDATE f_int1 when DUPLICATE KEY + # Bug#15236 Partitions: crash, if Insert .. on duplicate key causes update of existing row + INSERT INTO t1 (f_int1, f_int2, f_char1, f_char2, f_charbig) + SELECT f_int1, f_int1, '', '', 'was inserted' + FROM t0_template source_tab + WHERE MOD(f_int1,3) = 0 + AND f_int1 BETWEEN @max_row_div2 AND @max_row + ON DUPLICATE KEY + UPDATE f_int1 = 2 * @max_row + source_tab.f_int1, + f_charbig = 'was updated'; + --source suite/parts/inc/partition_20.inc + } + + if ($f_int2_is_unique) + { + ## 6.2 f_int2 is UNIQUE, UPDATE f_int2 when DUPLICATE KEY + # Bug#15236 Partitions: crash, if Insert .. on duplicate key causes update of existing row + INSERT INTO t1 (f_int1, f_int2, f_char1, f_char2, f_charbig) + SELECT f_int1, f_int1, '', '', 'was inserted' + FROM t0_template source_tab + WHERE MOD(f_int1,3) = 0 + AND f_int1 BETWEEN @max_row_div2 AND @max_row + ON DUPLICATE KEY + UPDATE f_int2 = 2 * @max_row + source_tab.f_int1, + f_charbig = 'was updated'; + --source suite/parts/inc/partition_20.inc + } + + ## 6.3 f_int1, f_int2 is UNIQUE, UPDATE f_int1, f_int2 when DUPLICATE KEY + INSERT INTO t1 (f_int1, f_int2, f_char1, f_char2, f_charbig) + SELECT f_int1, f_int1, '', '', 'was inserted' + FROM t0_template source_tab + WHERE MOD(f_int1,3) = 0 + AND f_int1 BETWEEN @max_row_div2 AND @max_row + ON DUPLICATE KEY + UPDATE f_int1 = 2 * @max_row + source_tab.f_int1, + f_int2 = 2 * @max_row + source_tab.f_int1, + f_charbig = 'was updated'; + --source suite/parts/inc/partition_20.inc + + ## 6.4 REPLACE + # Bug#16782: Partitions: crash, REPLACE .. on table with PK, DUPLICATE KEY + REPLACE INTO t1 (f_int1, f_int2, f_char1, f_char2, f_charbig) + SELECT f_int1, - f_int1, '', '', 'was inserted or replaced' + FROM t0_template source_tab + WHERE MOD(f_int1,3) = 0 AND f_int1 BETWEEN @max_row_div2 AND @max_row; + # DEBUG SELECT * FROM t1 ORDER BY f_int1, f_int2; + # Check of preceding statement via Select + if ($no_debug) + { + --disable_query_log + } + SELECT '# check replace success: ' AS "", COUNT(*) = @try_count AS "" + FROM t1 WHERE f_charbig = 'was inserted or replaced'; + --enable_query_log + # Revert the modification + DELETE FROM t1 + WHERE f_int1 BETWEEN @max_row_div2 AND @max_row_div2 + @max_row_div4; + # If there is only UNIQUE (f1,f2) we will have pairs f_int1,f_int2 + # <n>, <n> and <n>, <-n> + # where MOD(f_int1,3) = 0 + # and f_int1 between @max_row_div2 + @max_row_div4 and @max_row. + # Delete the <n>, <n> records. + DELETE FROM t1 + WHERE f_int1 = f_int2 AND MOD(f_int1,3) = 0 AND + f_int1 BETWEEN @max_row_div2 + @max_row_div4 AND @max_row; + UPDATE t1 SET f_int2 = f_int1, + f_char1 = CAST(f_int1 AS CHAR), + f_char2 = CAST(f_int1 AS CHAR), + f_charbig = CONCAT('===',CAST(f_int1 AS CHAR),'===') + WHERE f_charbig = 'was inserted or replaced' AND f_int1 = - f_int2; + # DEBUG SELECT * FROM t1 ORDER BY f_int1, f_int2; +} + + +#------------------------------------------------------------------------------- +# 7 Transactions +SET AUTOCOMMIT= 0; +# DEBUG SELECT @max_row_div4 , @max_row_div2 + @max_row_div4; +if ($no_debug) +{ + --disable_query_log +} +SELECT COUNT(f_int1) INTO @start_count FROM t1 +WHERE f_int1 BETWEEN @max_row_div4 AND @max_row_div2 + @max_row_div4; +--enable_query_log +let $run= `SELECT @start_count <> 0`; +if ($run) +{ + --echo # Prerequisites for following tests not fullfilled. + --echo # The content of the table t1 is unexpected + --echo # There must be no rows BETWEEN @max_row_div4 AND @max_row_div2 + @max_row_div4; + SELECT COUNT(f_int1) FROM t1 + WHERE f_int1 BETWEEN @max_row_div4 AND @max_row_div2 + @max_row_div4; + --echo # Sorry, have to abort. + exit; +} +# Number of records to be inserted +if ($no_debug) +{ + --disable_query_log +} +SELECT @max_row_div2 + @max_row_div4 - @max_row_div4 + 1 INTO @exp_inserted_rows; +--enable_query_log +# 7.1 Successful INSERT + COMMIT +INSERT INTO t1 (f_int1, f_int2, f_char1, f_char2, f_charbig) +SELECT f_int1, f_int1, '', '', 'was inserted' +FROM t0_template source_tab +WHERE f_int1 BETWEEN @max_row_div4 AND @max_row_div2 + @max_row_div4; +# The inserted records must be visible (at least for our current session) +if ($no_debug) +{ + --disable_query_log +} +SELECT '# check transactions-1 success: ' AS "", + COUNT(*) = @exp_inserted_rows AS "" +FROM t1 WHERE f_int1 BETWEEN @max_row_div4 AND @max_row_div2 + @max_row_div4; +--enable_query_log +# Make the changes persistent for all storage engines +COMMIT WORK; +# The inserted records must be visible (for all open and future sessions) +if ($no_debug) +{ + --disable_query_log +} +SELECT '# check transactions-2 success: ' AS "", + COUNT(*) = @exp_inserted_rows AS "" +FROM t1 WHERE f_int1 BETWEEN @max_row_div4 AND @max_row_div2 + @max_row_div4; +--enable_query_log +# Let's assume we have a transactional engine + COMMIT is ill. +# A correct working ROLLBACK might revert the INSERT. +ROLLBACK WORK; +if ($no_debug) +{ + --disable_query_log +} +SELECT '# check transactions-3 success: ' AS "", + COUNT(*) = @exp_inserted_rows AS "" +FROM t1 WHERE f_int1 BETWEEN @max_row_div4 AND @max_row_div2 + @max_row_div4; +--enable_query_log +# Revert the changes +DELETE FROM t1 WHERE f_charbig = 'was inserted'; +COMMIT WORK; +ROLLBACK WORK; +if ($no_debug) +{ + --disable_query_log +} +SELECT '# check transactions-4 success: ' AS "", + COUNT(*) = 0 AS "" +FROM t1 WHERE f_int1 BETWEEN @max_row_div4 AND @max_row_div2 + @max_row_div4; +--enable_query_log +# +# 7.2 Successful INSERT + ROLLBACK +INSERT INTO t1 (f_int1, f_int2, f_char1, f_char2, f_charbig) +SELECT f_int1, f_int1, '', '', 'was inserted' +FROM t0_template source_tab +WHERE f_int1 BETWEEN @max_row_div4 AND @max_row_div2 + @max_row_div4; +if ($no_debug) +{ + --disable_query_log +} +SELECT '# check transactions-5 success: ' AS "", + COUNT(*) = @exp_inserted_rows AS "" +FROM t1 WHERE f_int1 BETWEEN @max_row_div4 AND @max_row_div2 + @max_row_div4; +--enable_query_log +ROLLBACK WORK; +if ($no_debug) +{ + --disable_query_log +} +SELECT COUNT(*) INTO @my_count +FROM t1 WHERE f_int1 BETWEEN @max_row_div4 AND @max_row_div2 + @max_row_div4; +SELECT '# check transactions-6 success: ' AS "", + @my_count IN (0,@exp_inserted_rows) AS ""; +let $run= `SELECT @my_count = 0`; +if ($run) +{ + --echo # INFO: Storage engine used for t1 seems to be transactional. +} +let $run= `SELECT @my_count = @exp_inserted_rows`; +if ($run) +{ + --echo # INFO: Storage engine used for t1 seems to be not transactional. +} +--enable_query_log +# Let's assume we have a transactional engine + ROLLBACK is ill. +# A correct working COMMIT might make the inserted records again visible. +COMMIT; +if ($no_debug) +{ + --disable_query_log +} +SELECT '# check transactions-7 success: ' AS "", + COUNT(*) IN (0,@exp_inserted_rows) AS "" +FROM t1 WHERE f_int1 BETWEEN @max_row_div4 AND @max_row_div2 + @max_row_div4; +--enable_query_log +# Revert the changes +DELETE FROM t1 WHERE f_charbig = 'was inserted'; +COMMIT WORK; +# +# 7.3 Failing INSERT (in mid of statement processing) + COMMIT +SET @@session.sql_mode = 'traditional'; +# Number of records where a INSERT has to be tried +SELECT @max_row_div2 + @max_row_div4 - @max_row_div4 + 1 INTO @exp_inserted_rows; +# +--disable_abort_on_error +INSERT INTO t1 (f_int1, f_int2, f_char1, f_char2, f_charbig) +SELECT IF(f_int1 = @max_row_div2,f_int1 / 0,f_int1),f_int1, + '', '', 'was inserted' FROM t0_template +WHERE f_int1 BETWEEN @max_row_div4 AND @max_row_div2 + @max_row_div4; +--enable_abort_on_error +COMMIT; +# How many new records should be now visible ? +# 1. storage engine unable to revert changes made by the failing statement +# @max_row_div2 - 1 - @max_row_div4 + 1 +# 2. storage engine able to revert changes made by the failing statement +# 0 +if ($no_debug) +{ + --disable_query_log +} +SELECT COUNT(*) INTO @my_count +FROM t1 WHERE f_int1 BETWEEN @max_row_div4 AND @max_row_div2 + @max_row_div4; +SELECT '# check transactions-8 success: ' AS "", + @my_count IN (@max_row_div2 - 1 - @max_row_div4 + 1,0) AS ""; +let $run= `SELECT @my_count = @max_row_div2 - 1 - @max_row_div4 + 1`; +if ($run) +{ + --echo # INFO: Storage engine used for t1 seems to be unable to revert + --echo # changes made by the failing statement. +} +let $run= `SELECT @my_count = 0`; +if ($run) +{ + --echo # INFO: Storage engine used for t1 seems to be able to revert + --echo # changes made by the failing statement. +} +--enable_query_log +SET @@session.sql_mode = ''; +SET AUTOCOMMIT= 1; +# Revert the changes +DELETE FROM t1 WHERE f_charbig = 'was inserted'; +COMMIT WORK; + +if ($debug) +{ + SELECT * FROM t1 ORDER BY f_int1; +} + + +#------------------------------------------------------------------------------- +# 8 Some special cases +# 8.1 Dramatic increase of the record/partition/subpartition/table sizes +UPDATE t1 SET f_charbig = REPEAT('b', 1000); +# partial check of preceding statement via Select +if ($no_debug) +{ +--disable_query_log +} +eval SELECT '# check special-1 success: ' AS "",1 AS "" FROM t1 +WHERE f_int1 = 1 AND f_charbig = REPEAT('b', 1000); +--enable_query_log +# +# 8.2 Dramatic decrease of the record/partition/subpartition/table sizes +UPDATE t1 SET f_charbig = ''; +# partial check of preceding statement via Select +if ($no_debug) +{ +--disable_query_log +} +eval SELECT '# check special-2 success: ' AS "",1 AS "" FROM t1 +WHERE f_int1 = 1 AND f_charbig = ''; +--enable_query_log +# Revert the changes +UPDATE t1 SET f_charbig = CONCAT('===',CAST(f_int1 AS CHAR),'==='); + +if ($debug) +{ + SELECT * FROM t1 ORDER BY f_int1; +} + + +#------------------------------------------------------------------------------- +# 9 TRIGGERs +let $num= 1; +# 9.1 BEFORE/AFTER INSERT/UPDATE/DELETE TRIGGER on table t0_aux causes that +# column values used in partitioning function of t1 are changed. +let $tab_has_trigg= t0_aux; +let $tab_in_trigg= t1; + +# Insert three records, which will be updated by the trigger +eval INSERT INTO $tab_in_trigg(f_int1,f_int2,f_char1,f_char2,f_charbig) +SELECT f_int1,f_int2,f_char1,f_char2,'just inserted' FROM t0_template +WHERE f_int1 BETWEEN @max_row_div2 - 1 AND @max_row_div2 + 1; + +let $statement= INSERT INTO t0_aux(f_int1,f_int2,f_char1,f_char2,f_charbig) +SELECT f_int1,f_int2,f_char1,f_char2,NULL FROM t0_template +WHERE f_int1 BETWEEN @max_row_div2 - 1 AND @max_row_div2 + 1; +let $event= BEFORE INSERT; +--source suite/parts/inc/partition_trigg1.inc +let $event= AFTER INSERT; +--source suite/parts/inc/partition_trigg1.inc + +let $statement= UPDATE t0_aux SET f_int1 = - f_int1, f_int2 = - f_int2 +WHERE f_int1 IN (- (@max_row_div2 - 1),- @max_row_div2,- (@max_row_div2 + 1)); +let $event= BEFORE UPDATE; +--source suite/parts/inc/partition_trigg1.inc +let $event= AFTER UPDATE; +--source suite/parts/inc/partition_trigg1.inc + +let $statement= DELETE FROM t0_aux +WHERE f_int1 IN (- (@max_row_div2 - 1),- @max_row_div2,- (@max_row_div2 + 1)); +let $event= BEFORE DELETE; +--source suite/parts/inc/partition_trigg1.inc +let $event= AFTER DELETE; +--source suite/parts/inc/partition_trigg1.inc + +# Cleanup +eval DELETE FROM $tab_in_trigg +WHERE f_int1 BETWEEN @max_row_div2 - 1 AND @max_row_div2 + 1; + +# Two currently (February 2006) impossible operations. +# 1442: 'Can't update table 't1' in stored function/trigger because it is +# already used by statement which invoked this stored function/trigger.' +# 1362: 'Updating of OLD row is not allowed in trigger' + +if ($debug) +{ + SELECT * FROM t1 ORDER BY f_int1; +} + +if ($more_trigger_tests) +{ +# 9.2 BEFORE/AFTER INSERT/UPDATE/DELETE TRIGGER on partitioned table t1 causes +# that column values in not partitioned table t0_aux are changed. +let $tab_has_trigg= t1; +let $tab_in_trigg= t0_aux; + +# Insert three records, which will be updated by the trigger +eval INSERT INTO $tab_in_trigg(f_int1,f_int2,f_char1,f_char2,f_charbig) +SELECT f_int1,f_int2,f_char1,f_char2,'just inserted' FROM t0_template +WHERE f_int1 BETWEEN @max_row_div2 - 1 AND @max_row_div2 + 1; + +let $statement= INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +SELECT f_int1,f_int2,f_char1,f_char2,NULL FROM t0_template +WHERE f_int1 BETWEEN @max_row_div2 - 1 AND @max_row_div2 + 1; +let $event= BEFORE INSERT; +--source suite/parts/inc/partition_trigg1.inc +let $event= AFTER INSERT; +--source suite/parts/inc/partition_trigg1.inc + +let $statement= UPDATE t1 SET f_int1 = - f_int1, f_int2 = - f_int2 +WHERE f_int1 IN (- (@max_row_div2 - 1),- @max_row_div2,- (@max_row_div2 + 1)); +let $event= BEFORE UPDATE; +--source suite/parts/inc/partition_trigg1.inc +let $event= AFTER UPDATE; +--source suite/parts/inc/partition_trigg1.inc + +let $statement= DELETE FROM t1 +WHERE f_int1 IN (- (@max_row_div2 - 1),- @max_row_div2,- (@max_row_div2 + 1)); +let $event= BEFORE DELETE; +--source suite/parts/inc/partition_trigg1.inc +let $event= AFTER DELETE; +--source suite/parts/inc/partition_trigg1.inc +eval DELETE FROM $tab_in_trigg +WHERE f_int1 BETWEEN @max_row_div2 - 1 AND @max_row_div2 + 1; +} + +if ($debug) +{ + SELECT * FROM t1 ORDER BY f_int1; +} + +# 9.3 BEFORE/AFTER UPDATE TRIGGER on partitioned table causes that the value +# of columns in partitioning function is recalculated +if ($more_trigger_tests) +{ +# 9.3.1 The UPDATE itself changes a column which is not used in the partitioning +# function. +# "old" values are used as source within the trigger. +let $statement= UPDATE t1 +SET f_charbig = '####updated per update statement itself####'; +let $source= old; +let $event= BEFORE UPDATE; +--source suite/parts/inc/partition_trigg2.inc +# FIXME when AFTER TRIGGER can be used +# Currently (2006-02-23) a AFTER TRIGGER is not allowed to modify a row, which +# was just modified: 1362: Updating of NEW row is not allowed in after trigger +} + +# 9.3.2 The UPDATE itself changes a column which is used in the partitioning +# function. +let $statement= UPDATE t1 +SET f_int1 = f_int1 + @max_row, f_int2 = f_int2 - @max_row, +f_charbig = '####updated per update statement itself####'; + +# 9.3.2.1 "old" values are used as source within the trigger. +let $source= old; +let $event= BEFORE UPDATE; +--source suite/parts/inc/partition_trigg2.inc +# FIXME when AFTER TRIGGER can be used +# Currently (2006-02-23) a AFTER TRIGGER is not allowed to modify a row, which +# was just modified: 1362: Updating of NEW row is not allowed in after trigger +# 9.3.2.2 "new" values are used as source within the trigger. +let $source= new; +let $event= BEFORE UPDATE; +--source suite/parts/inc/partition_trigg2.inc +# FIXME when AFTER TRIGGER can be used + +if ($debug) +{ + SELECT * FROM t1 ORDER BY f_int1; +} + +# 9.4 BEFORE/AFTER INSERT TRIGGER on partitioned table causes that the value of +# columns in partitioning function is recalculated. +# 9.4.1 INSERT assigns values to the recalculate columns +let $statement= INSERT INTO t1 (f_int1, f_int2, f_char1, f_char2, f_charbig) +SELECT f_int1, f_int1, CAST(f_int1 AS CHAR), + CAST(f_int1 AS CHAR), 'just inserted' FROM t0_template +WHERE f_int1 BETWEEN @max_row_div2 - 1 AND @max_row_div2 + 1 +ORDER BY f_int1; +let $event= BEFORE INSERT; +let $source= new; +--source suite/parts/inc/partition_trigg3.inc +# FIXME when AFTER TRIGGER can be used + +# 9.4.2 INSERT assigns no values to the recalculate columns +let $statement= INSERT INTO t1 (f_char1, f_char2, f_charbig) +SELECT CAST(f_int1 AS CHAR), + CAST(f_int1 AS CHAR), 'just inserted' FROM t0_template +WHERE f_int1 BETWEEN @max_row_div2 - 1 AND @max_row_div2 + 1 +ORDER BY f_int1; +let $event= BEFORE INSERT; +let $source= new; +--source suite/parts/inc/partition_trigg3.inc +# FIXME when AFTER TRIGGER can be used + +if ($debug) +{ + SELECT * FROM t1 ORDER BY f_int1; +} + + +#------------------------------------------------------------------------------- +# 10 ANALYZE/CHECK/CHECKSUM +ANALYZE TABLE t1; +CHECK TABLE t1 EXTENDED; +# Checksum depends on @max_row so we have to unify the value +--replace_column 2 <some_value> +CHECKSUM TABLE t1 EXTENDED; + + +#------------------------------------------------------------------------------- +# 11 Some special statements, which may lead to a rebuild of the trees +# depending on the storage engine and some particular conditions +# 11.1 OPTIMIZE TABLE +# Manual about OPTIMIZE <InnoDB table>: +# ... , it is mapped to ALTER TABLE, which rebuilds the table. +# Rebuilding updates index statistics and frees unused space in the +# clustered index. +OPTIMIZE TABLE t1; +--source suite/parts/inc/partition_layout_check2.inc +# 10.2 REPAIR TABLE +REPAIR TABLE t1 EXTENDED; +--source suite/parts/inc/partition_layout_check2.inc +# +# 11.3 Truncate +# Manual about TRUNCATE on tables ( != InnoDB table with FOREIGN KEY ): +# Truncate operations drop and re-create the table .... +TRUNCATE t1; +# Check of preceding statement via Select +if ($no_debug) +{ +--disable_query_log +} +SELECT '# check TRUNCATE success: ' AS "",COUNT(*) = 0 AS "" FROM t1; +--enable_query_log +--source suite/parts/inc/partition_layout_check2.inc +--echo # End usability test (inc/partition_check.inc) + diff --git a/mysql-test/suite/parts/inc/partition_check_drop.inc b/mysql-test/suite/parts/inc/partition_check_drop.inc new file mode 100644 index 00000000..e7767d66 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_check_drop.inc @@ -0,0 +1,76 @@ +################################################################################ +# inc/partition_check_drop.inc # +# # +# Purpose: # +# Check that a drop table removes all files belonging to this table. # +# Remaining unused files can be caused by imperfect DROP TABLE or # +# ALTER TABLE <alter partitioning>. # +# # +# This routine is only useful for the partition_<feature>_<engine> tests. # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-05-12 # +################################################################################ + +if ($no_debug) +{ + --disable_query_log +} + +# Get the MySQL Servers datadir without ending slash +let $MYSQLD_DATADIR= `select LEFT(@@datadir, LENGTH(@@datadir)-1)`; +#echo MYSQLD_DATADIR: $MYSQLD_DATADIR; + +if ($do_file_tests) +{ + let $ls_file= $MYSQLD_DATADIR/test/tmp2; + # List the files belonging to the table t1 + --replace_result $MYSQLTEST_VARDIR \$MYSQLTEST_VARDIR #p# #P# #sp# #SP# + --list_files_write_file $ls_file $MYSQLD_DATADIR/test t1* + --chmod 0644 $ls_file + if ($with_directories) + { + --replace_result $MYSQLTEST_VARDIR \$MYSQLTEST_VARDIR #p# #P# #sp# #SP# + --list_files_append_file $ls_file $MYSQLTEST_VARDIR/tmp t1* + } + eval SET @aux = load_file('$ls_file'); + + # clean up + --remove_file $ls_file +} +if (!$do_file_tests) +{ + SET @aux = '--- not determined ---'; +} + +# UPDATE the current filelist of the table t1 within t0_definition +# Note: This list should be empty, because the table t1 was dropped ! +eval INSERT INTO t0_definition SET state = 'old', file_list = @aux +ON DUPLICATE KEY UPDATE file_list = @aux; +# eval UPDATE t0_definition SET file_list = @aux WHERE state = 'old'; + +# Check if filelist is empty. +let $found_garbage= `SELECT file_list <> '' FROM t0_definition WHERE state = 'old'`; +if ($found_garbage) +{ + # Unfortunately the DROP TABLE did not remove the unused files + if ($ls) + { + --echo # Attention: There are unused files. + --echo # Either the DROP TABLE or a preceding ALTER TABLE + --echo # <alter partitioning> worked incomplete. + --echo # We found: + # Print the list of files into the protocol + eval SELECT file_list AS "unified filelist" + FROM t0_definition WHERE state = 'old'; + } + # Do a manual cleanup, because the following tests should not suffer from + # remaining files + --remove_files_wildcard $MYSQLD_DATADIR/test t1* + if ($with_directories) + { + --remove_files_wildcard $MYSQLTEST_VARDIR/tmp t1* + } +} +--enable_query_log diff --git a/mysql-test/suite/parts/inc/partition_check_read.inc b/mysql-test/suite/parts/inc/partition_check_read.inc new file mode 100644 index 00000000..e42bb9c9 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_check_read.inc @@ -0,0 +1,89 @@ +################################################################################ +# inc/partition_check_read.inc # +# # +# Purpose: # +# Read table t1 row by row # +# This routine is only useful for the partition_<feature>_<engine> tests. # +# # +# Note: If this routine is successful, at least the following is fullfilled # +# - select single row via $col_to_check basically works -- no crash # +# - the table contains all expected rows # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-03-05 # +# Change Author: # +# Change Date: # +# Change: # +################################################################################ + +let $success= 1; + +## Read all existing records +let $num= `SELECT @max_row`; +while ($num) +{ + if ($no_debug) + { + --disable_query_log + } + eval SELECT COUNT(*) <> 1 INTO @aux FROM t1 WHERE $col_to_check = $num; + --enable_query_log + let $run= `SELECT @aux`; + if ($run) + { + --echo # Unexpected result on SELECT + eval SELECT COUNT(*) <> 1 FROM t1 WHERE $col_to_check = $num; + let $success= 0; + } + dec $num; +} +## Read some not existing records +let $num= `SELECT @max_row_div2`; +while ($num) +{ + if ($no_debug) + { + --disable_query_log + } + eval SELECT COUNT(*) = 1 INTO @aux FROM t1 WHERE $col_to_check = @max_row + $num; + --enable_query_log + let $run= `SELECT @aux`; + if ($run) + { + --echo # Unexpected result on SELECT + eval SELECT COUNT(*) <> 1 FROM t1 WHERE $col_to_check = @max_row + $num; + let $success= 0; + } + dec $num; +} +let $num= `SELECT @max_row_div2`; +while ($num) +{ + if ($no_debug) + { + --disable_query_log + } + eval SELECT COUNT(*) = 1 INTO @aux FROM t1 WHERE $col_to_check = 1 - $num; + --enable_query_log + let $run= `SELECT @aux`; + if ($run) + { + --echo # Unexpected result on SELECT + eval SELECT COUNT(*) <> 1 FROM t1 WHERE $col_to_check = 1 - $num; + let $success= 0; + } + dec $num; +} +if ($no_debug) +{ +--disable_query_log +} +--echo # check read via $col_to_check success: $success +# mleich: The following is omitted because of not reported mysqltest bug +# (@max_row time the success message) +if (0) +{ +eval SELECT '# check read via $col_to_check success: ' AS "", $success AS "" FROM t1; +} +--enable_query_log diff --git a/mysql-test/suite/parts/inc/partition_check_read1.inc b/mysql-test/suite/parts/inc/partition_check_read1.inc new file mode 100644 index 00000000..0b8b800a --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_check_read1.inc @@ -0,0 +1,79 @@ +################################################################################ +# inc/partition_check_read1.inc # +# # +# Purpose: # +# Read rows from table t1 in different ways # +# This routine is only useful for the partition_<feature>_<engine> tests. # +# # +# The parameter # +# @exp_row_count -- expected number of rows within t1 # +# must be set before sourcing this routine. # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-04-11 # +# Change Author: # +# Change Date: # +# Change: # +################################################################################ + +## EXPLAIN PARTITIONS SELECT for one single row +EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; + +## Check SELECT for one single row +let $success= 1; +if ($no_debug) +{ +--disable_query_log +} +SELECT COUNT(*) <> 1 INTO @aux FROM t1 WHERE f_date = '1000-02-10'; +--enable_query_log +let $run= `SELECT @aux`; +if ($run) +{ + --echo # Unexpected result on SELECT + eval SELECT COUNT(*) <> 1 FROM t1 WHERE f_date = '1000-02-10'; + let $success= 0; +} +--echo # check read single success: $success + +## Read all existing records in one step +let $success= 1; +if ($no_debug) +{ +--disable_query_log +} +eval SELECT COUNT(*) <> @exp_row_count INTO @aux FROM t1; +--enable_query_log +let $run= `SELECT @aux`; +if ($run) +{ + --echo # Unexpected result on SELECT + eval SELECT COUNT(*) <> @exp_row_count FROM t1; + let $success= 0; +} +--echo # check read all success: $success + +## Read all existing records row by row +let $success= 1; +let $num= `SELECT @exp_row_count`; +while ($num) +{ + if ($no_debug) + { + --disable_query_log + } + eval SELECT COUNT(*) <> 1 INTO @aux FROM t1 + WHERE f_date = CONCAT(CAST(999 + $num AS CHAR),'-02-10'); + --enable_query_log + let $run= `SELECT @aux`; + if ($run) + { + --echo # Unexpected result on SELECT + eval SELECT COUNT(*) <> 1 FROM t1 + WHERE f_date = CONCAT(CAST(999 + $num AS CHAR),'-02-10'); + let $success= 0; + } + dec $num; +} +--echo # check read row by row success: $success diff --git a/mysql-test/suite/parts/inc/partition_check_read2.inc b/mysql-test/suite/parts/inc/partition_check_read2.inc new file mode 100644 index 00000000..60964355 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_check_read2.inc @@ -0,0 +1,75 @@ +################################################################################ +# inc/partition_check_read2.inc # +# # +# Purpose: # +# Read rows from table t1 in different ways # +# This routine is only useful for the partition_<feature>_<engine> tests. # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-04-11 # +# Change Author: # +# Change Date: # +# Change: # +################################################################################ + +## EXPLAIN PARTITIONS SELECT for one single row +EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; + +## Check SELECT for one single row +let $success= 1; +if ($no_debug) +{ +--disable_query_log +} +SELECT COUNT(*) <> 1 INTO @aux FROM t1 WHERE f_int1 = 3; +--enable_query_log +let $run= `SELECT @aux`; +if ($run) +{ + --echo # Unexpected result on SELECT + eval SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; + let $success= 0; +} +--echo # check read single success: $success + +## Read all existing records in one step +let $success= 1; +if ($no_debug) +{ +--disable_query_log +} +eval SELECT COUNT(*) <> @max_row INTO @aux FROM t1; +--enable_query_log +let $run= `SELECT @aux`; +if ($run) +{ + --echo # Unexpected result on SELECT + eval SELECT COUNT(*) <> @max_row FROM t1; + let $success= 0; +} +--echo # check read all success: $success + +## Read all existing records row by row +let $success= 1; +let $num= `SELECT @max_row`; +while ($num) +{ + if ($no_debug) + { + --disable_query_log + } + eval SELECT COUNT(*) <> 1 INTO @aux FROM t1 + WHERE f_int1 = 3; + --enable_query_log + let $run= `SELECT @aux`; + if ($run) + { + --echo # Unexpected result on SELECT + eval SELECT COUNT(*) <> 1 FROM t1 + WHERE f_int1 = 3; + let $success= 0; + } + dec $num; +} +--echo # check read row by row success: $success diff --git a/mysql-test/suite/parts/inc/partition_cleanup.inc b/mysql-test/suite/parts/inc/partition_cleanup.inc new file mode 100644 index 00000000..34d3e435 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_cleanup.inc @@ -0,0 +1,22 @@ +################################################################################ +# inc/partition_cleanup.inc # +# # +# Purpose: # +# Removal of the objects created by the t/partition_<feature>_<engine>.test # +# scripts. # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-03-05 # +# Change Author: # +# Change Date: # +# Change: # +################################################################################ + +--disable_warnings +DROP VIEW IF EXISTS v1; +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t0_aux; +DROP TABLE IF EXISTS t0_definition; +DROP TABLE IF EXISTS t0_template; +--enable_warnings diff --git a/mysql-test/suite/parts/inc/partition_crash.inc b/mysql-test/suite/parts/inc/partition_crash.inc new file mode 100644 index 00000000..c657ba88 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_crash.inc @@ -0,0 +1,36 @@ +# Include file to decrease test code duplication + +--eval $create_statement +--eval $insert_statement +--echo # State before crash + +--list_files_write_file $DATADIR.files.txt $DATADIR/test +--replace_result #p# #P# #sp# #SP# +--cat_file $DATADIR.files.txt +--remove_file $DATADIR.files.txt +SHOW CREATE TABLE t1; +--sorted_result +SELECT * FROM t1; +--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--disable_reconnect +# CR_SERVER_LOST +--error 2013 +--eval $crash_statement +--echo # State after crash (before recovery) +--list_files_write_file $DATADIR.files.txt $DATADIR/test +--replace_result #p# #P# #sp# #SP# #tmp# #TMP# +--replace_regex /sql-exchange.*\./sql-exchange./ /sql-shadow-[0-9a-f]*-/sql-shadow-/ +--cat_file $DATADIR.files.txt +--remove_file $DATADIR.files.txt +--exec echo "restart" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect +--enable_reconnect +--source include/wait_until_connected_again.inc +--echo # State after crash recovery +--list_files_write_file $DATADIR.files.txt $DATADIR/test +--replace_result #p# #P# #sp# #SP# +--cat_file $DATADIR.files.txt +--remove_file $DATADIR.files.txt +SHOW CREATE TABLE t1; +--sorted_result +SELECT * FROM t1; +DROP TABLE t1; diff --git a/mysql-test/suite/parts/inc/partition_crash_add.inc b/mysql-test/suite/parts/inc/partition_crash_add.inc new file mode 100644 index 00000000..43b0c5c8 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_crash_add.inc @@ -0,0 +1,34 @@ +# To be used with partition mgm commands like +# ALTER TABLE t1 ADD PARTITION (LIST/RANGE PARTITIONING). +--echo # Crash testing ADD PARTITION +SET @save_dbug=@@debug_dbug; +SET SESSION debug_dbug="+d,crash_add_partition_1"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,crash_add_partition_2"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,crash_add_partition_3"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,crash_add_partition_4"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,crash_add_partition_5"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,crash_add_partition_6"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,crash_add_partition_7"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,crash_add_partition_8"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,crash_add_partition_9"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,crash_add_partition_10"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; diff --git a/mysql-test/suite/parts/inc/partition_crash_change.inc b/mysql-test/suite/parts/inc/partition_crash_change.inc new file mode 100644 index 00000000..501bc78a --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_crash_change.inc @@ -0,0 +1,41 @@ +# To be used with partition mgm commands like +# ALTER TABLE t1 COALESCE/REBUILD/REORGANIZE PARTITION. +--echo # Test change partition (REORGANIZE/REBUILD/COALESCE +--echo # or ADD HASH PARTITION). +SET @save_dbug=@@debug_dbug; +SET SESSION debug_dbug="+d,crash_change_partition_1"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,crash_change_partition_2"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,crash_change_partition_3"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,crash_change_partition_4"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,crash_change_partition_5"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,crash_change_partition_6"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,crash_change_partition_7"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,crash_change_partition_8"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,crash_change_partition_9"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,crash_change_partition_10"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,crash_change_partition_11"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,crash_change_partition_12"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; diff --git a/mysql-test/suite/parts/inc/partition_crash_drop.inc b/mysql-test/suite/parts/inc/partition_crash_drop.inc new file mode 100644 index 00000000..80730bb9 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_crash_drop.inc @@ -0,0 +1,31 @@ +# To be used with partition mgm commands like +# ALTER TABLE t1 DROP PARTITION. +--echo # Test DROP PARTITION +SET @save_dbug=@@debug_dbug; +SET SESSION debug_dbug="+d,crash_drop_partition_1"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,crash_drop_partition_2"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,crash_drop_partition_3"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,crash_drop_partition_4"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,crash_drop_partition_5"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,crash_drop_partition_6"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,crash_drop_partition_7"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,crash_drop_partition_8"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,crash_drop_partition_9"; +--source suite/parts/inc/partition_crash.inc +SET SESSION debug_dbug=@save_dbug; diff --git a/mysql-test/suite/parts/inc/partition_crash_exchange.inc b/mysql-test/suite/parts/inc/partition_crash_exchange.inc new file mode 100644 index 00000000..32b88870 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_crash_exchange.inc @@ -0,0 +1,30 @@ +# To be used with WL#4445: EXCHANGE PARTITION WITH TABLE. +SET @save_dbug=@@debug_dbug; +SET SESSION debug_dbug="+d,exchange_partition_abort_1"; +--source suite/parts/inc/partition_crash_t2.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,exchange_partition_abort_2"; +--source suite/parts/inc/partition_crash_t2.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,exchange_partition_abort_3"; +--source suite/parts/inc/partition_crash_t2.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,exchange_partition_abort_4"; +--source suite/parts/inc/partition_crash_t2.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,exchange_partition_abort_5"; +--source suite/parts/inc/partition_crash_t2.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,exchange_partition_abort_6"; +--source suite/parts/inc/partition_crash_t2.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,exchange_partition_abort_7"; +--source suite/parts/inc/partition_crash_t2.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,exchange_partition_abort_8"; +--source suite/parts/inc/partition_crash_t2.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,exchange_partition_abort_9"; +--source suite/parts/inc/partition_crash_t2.inc +SET SESSION debug_dbug=@save_dbug; + diff --git a/mysql-test/suite/parts/inc/partition_crash_t2.inc b/mysql-test/suite/parts/inc/partition_crash_t2.inc new file mode 100644 index 00000000..fd88cc60 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_crash_t2.inc @@ -0,0 +1,12 @@ +# Include file to extend partition_crash with a second table. +# To be used with WL#4445: EXCHANGE PARTITION WITH TABLE. +--eval $create_statement2 +--eval $insert_statement2 +SHOW CREATE TABLE t2; +--sorted_result +SELECT * FROM t2; +--source suite/parts/inc/partition_crash.inc +SHOW CREATE TABLE t2; +--sorted_result +SELECT * FROM t2; +DROP TABLE t2; diff --git a/mysql-test/suite/parts/inc/partition_date.inc b/mysql-test/suite/parts/inc/partition_date.inc new file mode 100644 index 00000000..11e68388 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_date.inc @@ -0,0 +1,87 @@ +eval create table t1 (a date not null, primary key(a)) engine=$engine +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +insert into t1 values ('1975-01-01'), ('2020-12-31'), ('1980-10-14'), ('2000-06-15'); +select * from t1; +select * from t1 where a=19801014; +delete from t1 where a=19801014; +select * from t1; +drop table t1; + +eval create table t2 (a date not null, primary key(a)) engine=$engine +partition by key (a) partitions 12; +show create table t2; +insert into t2 values ('1975-01-01'), ('2020-12-31'), ('1980-10-14'), ('2000-06-15'); +select * from t2; +select * from t2 where a='1980-10-14'; +delete from t2 where a='1980-10-14'; +select * from t2; +delete from t2; +let $count=28; +--echo $count inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t2 values (19700101+$count-1); +eval insert into t2 values (19700201+$count-1); +eval insert into t2 values (19700301+$count-1); +dec $count; +} +commit; +--enable_query_log +select count(*) from t2; +select * from t2; +drop table t2; + +eval create table t3 (a date not null, primary key(a)) engine=$engine +partition by range (month(a)) subpartition by key (a) +subpartitions 3 ( +partition quarter1 values less than (4), +partition quarter2 values less than (7), +partition quarter3 values less than (10), +partition quarter4 values less than (13) +); +show create table t3; +let $count=12; +--echo $count inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t3 values (adddate(19700101,interval $count-1 month)); +dec $count; +} +commit; +--enable_query_log +select count(*) from t3; +select * from t3; +drop table t3; + +eval create table t4 (a date not null, primary key(a)) engine=$engine +partition by list (month(a)) subpartition by key (a) +subpartitions 3 ( +partition quarter1 values in (1,2,3), +partition quarter2 values in (4,5,6), +partition quarter3 values in (7,8,9), +partition quarter4 values in (10,11,12) +); +show create table t4; +let $count=12; +--echo $count inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t4 values (adddate(19700101,interval $count-1 month)); +dec $count; +} +commit; +--enable_query_log +select count(*) from t4; +select * from t4; +drop table t4; diff --git a/mysql-test/suite/parts/inc/partition_datetime.inc b/mysql-test/suite/parts/inc/partition_datetime.inc new file mode 100644 index 00000000..e2135d90 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_datetime.inc @@ -0,0 +1,85 @@ +eval create table t1 (a datetime not null, primary key(a)) engine=$engine +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +insert into t1 values ('1975-01-01 21:21:21'), ('2020-12-31 12:10:30'), ('1980-10-14 03:03'), ('2000-06-15 23:59'); +select * from t1; +select * from t1 where a=19801014030300; +delete from t1 where a=19801014030300; +select * from t1; +drop table t1; + +eval create table t2 (a datetime not null, primary key(a)) engine=$engine +partition by key (a) partitions 12; +show create table t2; +insert into t2 values ('1975-01-01 0:1:1'), ('2020-12-31 10:11:12'), ('1980-10-14 13:14:15'), ('2000-06-15 14:15:16'); +select * from t2; +select * from t2 where a='1980-10-14 13:14:15'; +delete from t2 where a='1980-10-14 13:14:15'; +select * from t2; +delete from t2; +let $count=59; +--echo $count inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t2 values (19700101000000+$count); +dec $count; +} +commit; +--enable_query_log +select count(*) from t2; +select * from t2; +drop table t2; + +eval create table t3 (a datetime not null, primary key(a)) engine=$engine +partition by range (month(a)) subpartition by key (a) +subpartitions 3 ( +partition quarter1 values less than (4), +partition quarter2 values less than (7), +partition quarter3 values less than (10), +partition quarter4 values less than (13) +); +show create table t3; +let $count=12; +--echo $count inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t3 values (adddate(19700101000000,interval $count-1 month)); +dec $count; +} +commit; +--enable_query_log +select count(*) from t3; +select * from t3; +drop table t3; + +eval create table t4 (a datetime not null, primary key(a)) engine=$engine +partition by list (month(a)) subpartition by key (a) +subpartitions 3 ( +partition quarter1 values in (1,2,3), +partition quarter2 values in (4,5,6), +partition quarter3 values in (7,8,9), +partition quarter4 values in (10,11,12) +); +show create table t4; +let $count=12; +--echo $count inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t4 values (adddate(19700101000000,interval $count-1 month)); +dec $count; +} +commit; +--enable_query_log +select count(*) from t4; +select * from t4; +drop table t4; diff --git a/mysql-test/suite/parts/inc/partition_decimal.inc b/mysql-test/suite/parts/inc/partition_decimal.inc new file mode 100644 index 00000000..93e9e48c --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_decimal.inc @@ -0,0 +1,93 @@ +eval create table t1 (a decimal(10,4) not null, primary key(a)) engine=$engine +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +insert into t1 values (999999.9999), (-999999.9999), (123456.7899), (-123456.7899), (-1.5), (1), (0), (-1), (1.5), (1234.567), (-1234.567); +select * from t1; +select * from t1 where a=1234.567; +delete from t1 where a=1234.567; +select * from t1; +drop table t1; + +eval create table t2 (a decimal(18,9) not null, primary key(a)) engine=$engine +partition by key (a) partitions 10; +show create table t2; +insert into t2 values (999999999.999999999), (-999999999.999999999), (-1.5), (-1), (0), (1.5), (1234.567), (-1234.567); +select * from t2; +select * from t2 where a=1234.567; +delete from t2 where a=1234.567; +select * from t2; +delete from t2; +let $count=$maxrows; +--echo $count*3 inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t2 values ($count); +eval insert into t2 values ($count+0.333333333); +eval insert into t2 values ($count+0.755555555); +dec $count; +} +commit; +--enable_query_log +select count(*) from t2; +drop table t2; + +# Bug 30577: FLOOR() and CEILING() not usable as partition functions +# Partition functions are required to return INT_RESULT; FLOOR() and +# CEILING() do not, unless they have an INT or DECIMAL argument. + + +eval create table t3 (a decimal(18,9) not null, primary key(a)) engine=$engine +partition by range (floor(a)) subpartition by key (a) subpartitions 2 ( +partition pa2 values less than (2), +partition pa4 values less than (4), +partition pa6 values less than (6), +partition pa8 values less than (8), +partition pa10 values less than (10) +); +show create table t3; +let $count=9; +--echo $count*3 inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t3 values ($count); +eval insert into t3 values ($count+0.333333333); +eval insert into t3 values ($count+0.755555555); +dec $count; +} +commit; +--enable_query_log +select count(*) from t3; +drop table t3; + +eval create table t4 (a decimal(18,9) not null, primary key(a)) engine=$engine +partition by list (ceiling(a)) subpartition by key (a) subpartitions 2 ( +partition pa2 values in (1,2), +partition pa4 values in (3,4), +partition pa6 values in (5,6), +partition pa8 values in (7,8), +partition pa10 values in (9,10) +); +show create table t4; +let $count=9; +--echo $count*3 inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t4 values ($count); +eval insert into t4 values ($count+0.333333333); +eval insert into t4 values ($count+0.755555555); +dec $count; +} +commit; +--enable_query_log +select count(*) from t4; +drop table t4; diff --git a/mysql-test/suite/parts/inc/partition_directory.inc b/mysql-test/suite/parts/inc/partition_directory.inc new file mode 100644 index 00000000..2d270374 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_directory.inc @@ -0,0 +1,219 @@ +################################################################################ +# inc/partition_directory.inc # +# # +# Purpose: # +# Create and check partitioned tables # +# The partitioning function use the column f_int1 # +# # +# For all Data/Index directory combinations # +# do # +# 1. Create the partitioned table # +# 2 Insert the content of the table t0_template into t1 # +# 3. Execute inc/partition_check.inc # +# 4. Drop the table t1 # +# done # +#------------------------------------------------------------------------------# +# Original Author: HH # +# Original Date: 2006-05-11 # +# Change Author: # +# Change Date: # +# Change: # +################################################################################ + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +let $partitioning= ; +#----------- PARTITION BY HASH +if ($with_partitioning) +{ +let $partitioning= PARTITION BY HASH(f_int1) PARTITIONS 2; +if ($with_directories) +{ +let $partitioning= +PARTITION BY HASH(f_int1) PARTITIONS 2 +(PARTITION p1 +$index_directory, +PARTITION p2 +$index_directory); +} +} +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; +--source suite/parts/inc/partition_check_drop.inc + +#----------- PARTITION BY KEY +if ($with_partitioning) +{ +let $partitioning= PARTITION BY KEY(f_int1) PARTITIONS 5; +if ($with_directories) +{ +let $partitioning= +PARTITION BY HASH(f_int1) PARTITIONS 5 +(PARTITION p1 +$data_directory, +PARTITION p2 +$index_directory, +PARTITION p3 +$data_directory +$index_directory, +PARTITION p4, +PARTITION p5 +$index_directory); +} +} +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; +--source suite/parts/inc/partition_check_drop.inc + +#----------- PARTITION BY LIST +if ($with_partitioning) +{ +let $partitioning= +PARTITION BY LIST(MOD(f_int1,4)) +(PARTITION part_3 VALUES IN (-3) +$index_directory, + PARTITION part_2 VALUES IN (-2) +$data_directory, + PARTITION part_1 VALUES IN (-1) +$data_directory $index_directory, + PARTITION part_N VALUES IN (NULL) +$data_directory, + PARTITION part0 VALUES IN (0) +$index_directory, + PARTITION part1 VALUES IN (1) +, + PARTITION part2 VALUES IN (2) +$data_directory, + PARTITION part3 VALUES IN (3) +$data_directory $index_directory); +} +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; +--source suite/parts/inc/partition_check_drop.inc + +#----------- PARTITION BY RANGE +if ($with_partitioning) +{ +let $partitioning= PARTITION BY RANGE(f_int1) +(PARTITION parta VALUES LESS THAN (0) +$index_directory, +PARTITION partb VALUES LESS THAN ($max_row_div4) +$data_directory, +PARTITION partc VALUES LESS THAN ($max_row_div2) +$data_directory +$index_directory, +PARTITION partd VALUES LESS THAN ($max_row_div2 + $max_row_div4), +PARTITION parte VALUES LESS THAN ($max_row) +$data_directory, +PARTITION partf VALUES LESS THAN $MAX_VALUE +$index_directory); +} +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; +--source suite/parts/inc/partition_check_drop.inc + +#----------- PARTITION BY RANGE -- SUBPARTITION BY HASH +if ($with_partitioning) +{ +let $partitioning= +PARTITION BY RANGE(f_int1 DIV 2) SUBPARTITION BY HASH(f_int1) SUBPARTITIONS 2 +(PARTITION parta VALUES LESS THAN (0) +$index_directory, +PARTITION partb VALUES LESS THAN ($max_row_div4) +$data_directory, +PARTITION partc VALUES LESS THAN ($max_row_div2), +PARTITION partd VALUES LESS THAN $MAX_VALUE +$data_directory +$index_directory); +} +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; +--source suite/parts/inc/partition_check_drop.inc + +#----------- PARTITION BY RANGE -- SUBPARTITION BY KEY +if ($with_partitioning) +{ +# use the new (from bug#14326) partitioning format (i.e. multi-line comments) +let $partitioning= +/*!50100 PARTITION BY RANGE(f_int1) +SUBPARTITION BY KEY(f_int1) +(PARTITION part1 VALUES LESS THAN (0) $data_directory + (SUBPARTITION subpart11, + SUBPARTITION subpart12), + PARTITION part2 VALUES LESS THAN ($max_row_div4) $index_directory + (SUBPARTITION subpart21, + SUBPARTITION subpart22), + PARTITION part3 VALUES LESS THAN ($max_row_div2) $data_directory $index_directory + (SUBPARTITION subpart31, + SUBPARTITION subpart32), + PARTITION part4 VALUES LESS THAN $MAX_VALUE + (SUBPARTITION subpart41, + SUBPARTITION subpart42)) */; +} +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; +--source suite/parts/inc/partition_check_drop.inc + +#----------- PARTITION BY LIST -- SUBPARTITION BY HASH +if ($with_partitioning) +{ +# use the old (pre bug#14326) format (i.e. one line comment) +let $partitioning= /*!50100 PARTITION BY LIST(ABS(MOD(f_int1,3))) SUBPARTITION BY HASH(f_int1 + 1) (PARTITION part1 VALUES IN (0) $index_directory (SUBPARTITION sp11 $data_directory, SUBPARTITION sp12 $index_directory), PARTITION part2 VALUES IN (1) $data_directory (SUBPARTITION sp21 $data_directory, SUBPARTITION sp22 $index_directory), PARTITION part3 VALUES IN (2) $data_directory $index_directory (SUBPARTITION sp31, SUBPARTITION sp32), PARTITION part4 VALUES IN (NULL) (SUBPARTITION sp41 $data_directory $index_directory, SUBPARTITION sp42 $data_directory $index_directory)) */; +} +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; +--source suite/parts/inc/partition_check_drop.inc + +let $with_directories= FALSE; + diff --git a/mysql-test/suite/parts/inc/partition_double.inc b/mysql-test/suite/parts/inc/partition_double.inc new file mode 100644 index 00000000..9e43887b --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_double.inc @@ -0,0 +1,39 @@ +eval create table t1 (a double not null, primary key(a)) engine=$engine +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +insert into t1 values (-2.2250738585072014E+208), (-2.2250738585072014E-208), (-1.5), (-1), (0), (1.5), (1234.567), (2.2250738585072014E+208); +select * from t1; +select * from t1 where a=1.5; +delete from t1 where a=1.5; +select * from t1; +drop table t1; + +eval create table t2 (a double not null, primary key(a)) engine=$engine +partition by key (a) partitions 10; +show create table t2; +insert into t2 values (-2.2250738585072014E+208), (-2.2250738585072014E-208), (-1.5), (-1), (0), (1.5), (1234.567), (2.2250738585072014E+208); +select * from t2; +select * from t2 where a=1234.567; +delete from t2 where a=1234.567; +select * from t2; +delete from t2; +let $count=$maxrows; +--echo $maxrows*3 inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t2 values ($count); +eval insert into t2 values ($count+0.33); +eval insert into t2 values ($count+0.75); +dec $count; +} +commit; +--enable_query_log +select count(*) from t2; +drop table t2; + diff --git a/mysql-test/suite/parts/inc/partition_engine.inc b/mysql-test/suite/parts/inc/partition_engine.inc new file mode 100644 index 00000000..c964557e --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_engine.inc @@ -0,0 +1,289 @@ +################################################################################ +# inc/partition_engine.inc # +# # +# Purpose: # +# Tests around Create/Alter partitioned tables and storage engine settings # +# at different places within the statement. # +# This routine is only useful for the partition_<feature>_<engine> tests. # +# # +# Note: There were some problems in history. # +# It looks like a table holds information about the storage engine # +# for # +# "the whole table" -> in statement after column list before partitioning # +# a partition -> in statement after definition of partition # +# a subpartition -> in statement after definition of subpartition # +# If there is a CREATE TABLE statement where not at all of these place # +# a storage engine is assigned, the server must decide by itself whic # +# storage engine to use. # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-03-05 # +# Change Author: # +# Change Date: # +# Change: # +################################################################################ + +--echo +--echo #======================================================================== +--echo # Checks where the engine is assigned on all supported (CREATE TABLE +--echo # statement) positions + basic operations on the tables +--echo # Storage engine mixups are currently (2005-12-23) not supported +--echo #======================================================================== +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +# +--echo #------------------------------------------------------------------------ +--echo # 1 Assignment of storage engine just after column list only +--echo #------------------------------------------------------------------------ +eval CREATE TABLE t1 ( +$column_list +) ENGINE = $engine + PARTITION BY HASH(f_int1) PARTITIONS 2; +INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; +# +--echo #------------------------------------------------------------------------ +--echo # 2 Assignment of storage engine just after partition or subpartition +--echo # name only +--echo #------------------------------------------------------------------------ +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY HASH(f_int1) +( PARTITION part1 STORAGE ENGINE = $engine, + PARTITION part2 STORAGE ENGINE = $engine +); +INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY RANGE(f_int1) +SUBPARTITION BY HASH(f_int1) +( PARTITION part1 VALUES LESS THAN ($max_row_div2) + (SUBPARTITION subpart11 STORAGE ENGINE = $engine, + SUBPARTITION subpart12 STORAGE ENGINE = $engine), + PARTITION part2 VALUES LESS THAN $MAX_VALUE + (SUBPARTITION subpart21 STORAGE ENGINE = $engine, + SUBPARTITION subpart22 STORAGE ENGINE = $engine) +); +INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; +# +--echo #------------------------------------------------------------------------ +--echo # 3 Some but not all named partitions or subpartitions get a storage +--echo # engine assigned +--echo #------------------------------------------------------------------------ +--error ER_MIX_HANDLER_ERROR +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY HASH(f_int1) +( PARTITION part1 STORAGE ENGINE = $engine, + PARTITION part2 +); +--error ER_MIX_HANDLER_ERROR +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY HASH(f_int1) +( PARTITION part1 , + PARTITION part2 STORAGE ENGINE = $engine +); +--error ER_MIX_HANDLER_ERROR +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY RANGE(f_int1) +SUBPARTITION BY HASH(f_int1) +( PARTITION part1 VALUES LESS THAN ($max_row_div2) + (SUBPARTITION subpart11, + SUBPARTITION subpart12 STORAGE ENGINE = $engine), + PARTITION part2 VALUES LESS THAN $MAX_VALUE + (SUBPARTITION subpart21 STORAGE ENGINE = $engine, + SUBPARTITION subpart22 STORAGE ENGINE = $engine) +); +--error ER_MIX_HANDLER_ERROR +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY RANGE(f_int1) +SUBPARTITION BY HASH(f_int1) +( PARTITION part1 VALUES LESS THAN ($max_row_div2) + (SUBPARTITION subpart11 STORAGE ENGINE = $engine, + SUBPARTITION subpart12 STORAGE ENGINE = $engine), + PARTITION part2 VALUES LESS THAN $MAX_VALUE + (SUBPARTITION subpart21, + SUBPARTITION subpart22 ) +); +eval CREATE TABLE t1 ( +$column_list +) +ENGINE = $engine +PARTITION BY RANGE(f_int1) +SUBPARTITION BY HASH(f_int1) +( PARTITION part1 VALUES LESS THAN ($max_row_div2) + (SUBPARTITION subpart11 STORAGE ENGINE = $engine, + SUBPARTITION subpart12 STORAGE ENGINE = $engine), + PARTITION part2 VALUES LESS THAN $MAX_VALUE + (SUBPARTITION subpart21, + SUBPARTITION subpart22 ) +); +INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; +# +--echo #------------------------------------------------------------------------ +--echo # 4 Storage engine assignment after partition name + after name of +--echo # subpartitions belonging to another partition +--echo #------------------------------------------------------------------------ +--error ER_MIX_HANDLER_ERROR +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY RANGE(f_int1) +SUBPARTITION BY HASH(f_int1) +( PARTITION part1 VALUES LESS THAN ($max_row_div2) + (SUBPARTITION subpart11, + SUBPARTITION subpart12), + PARTITION part2 VALUES LESS THAN $MAX_VALUE + (SUBPARTITION subpart21 STORAGE ENGINE = $engine, + SUBPARTITION subpart22 STORAGE ENGINE = $engine) +); +eval CREATE TABLE t1 ( +$column_list +) +ENGINE = $engine +PARTITION BY RANGE(f_int1) +SUBPARTITION BY HASH(f_int1) +( PARTITION part1 VALUES LESS THAN ($max_row_div2) ENGINE = $engine + (SUBPARTITION subpart11, + SUBPARTITION subpart12), + PARTITION part2 VALUES LESS THAN $MAX_VALUE + (SUBPARTITION subpart21, + SUBPARTITION subpart22 STORAGE ENGINE = $engine) +); +DROP TABLE t1; +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY RANGE(f_int1) +SUBPARTITION BY HASH(f_int1) +( PARTITION part1 VALUES LESS THAN ($max_row_div2) ENGINE = $engine + (SUBPARTITION subpart11, + SUBPARTITION subpart12), + PARTITION part2 VALUES LESS THAN $MAX_VALUE + (SUBPARTITION subpart21 STORAGE ENGINE = $engine, + SUBPARTITION subpart22 STORAGE ENGINE = $engine) +); +INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY RANGE(f_int1) +SUBPARTITION BY HASH(f_int1) +( PARTITION part1 VALUES LESS THAN ($max_row_div2) + (SUBPARTITION subpart11 STORAGE ENGINE = $engine, + SUBPARTITION subpart12 STORAGE ENGINE = $engine), + PARTITION part2 VALUES LESS THAN $MAX_VALUE ENGINE = $engine + (SUBPARTITION subpart21 ENGINE = $engine, + SUBPARTITION subpart22) +); +INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; +# +--echo #------------------------------------------------------------------------ +--echo # 5 Precedence of storage engine assignments (if there is any) +--echo #------------------------------------------------------------------------ +--echo # 5.1 Storage engine assignment after column list + after partition +--echo # or subpartition name +eval CREATE TABLE t1 ( +$column_list +) ENGINE = $engine +PARTITION BY HASH(f_int1) +( PARTITION part1 STORAGE ENGINE = $engine, + PARTITION part2 STORAGE ENGINE = $engine +); +INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY RANGE(f_int1) +SUBPARTITION BY HASH(f_int1) +( PARTITION part1 VALUES LESS THAN ($max_row_div2) + (SUBPARTITION subpart11 STORAGE ENGINE = $engine, + SUBPARTITION subpart12 STORAGE ENGINE = $engine), + PARTITION part2 VALUES LESS THAN $MAX_VALUE + (SUBPARTITION subpart21 STORAGE ENGINE = $engine, + SUBPARTITION subpart22 STORAGE ENGINE = $engine) +); +INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; +--echo # 6.2 Storage engine assignment after partition name + after +--echo # subpartition name +--echo # in partition part + in sub partition part +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY RANGE(f_int1) +SUBPARTITION BY HASH(f_int1) +( PARTITION part1 VALUES LESS THAN ($max_row_div2) STORAGE ENGINE = $engine + (SUBPARTITION subpart11 STORAGE ENGINE = $engine, + SUBPARTITION subpart12 STORAGE ENGINE = $engine), + PARTITION part2 VALUES LESS THAN $MAX_VALUE + (SUBPARTITION subpart21 STORAGE ENGINE = $engine, + SUBPARTITION subpart22 STORAGE ENGINE = $engine) +); +INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; + +--echo #------------------------------------------------------------------------ +--echo # 6 Session default engine differs from engine used within create table +--echo #------------------------------------------------------------------------ +eval SET SESSION default_storage_engine=$engine_other; +# Bug#16775 Partitions: strange effects on subpartitioned tables, mixed storage engines +# Bug#15966 Partitions: crash if session default engine <> engine used in create table +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY HASH(f_int1) ( PARTITION part1 ENGINE = $engine); +INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; +# Bug#15966 Partitions: crash if session default engine <> engine used in create table +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY RANGE(f_int1) +SUBPARTITION BY HASH(f_int1) +( PARTITION part1 VALUES LESS THAN (1000) + (SUBPARTITION subpart11 STORAGE ENGINE = $engine, + SUBPARTITION subpart12 STORAGE ENGINE = $engine)); +INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +SELECT f_int1,f_int2,f_char1,f_char2,f_charbig FROM t0_template; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; +eval SET SESSION default_storage_engine=$engine; diff --git a/mysql-test/suite/parts/inc/partition_enum.inc b/mysql-test/suite/parts/inc/partition_enum.inc new file mode 100644 index 00000000..f056162e --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_enum.inc @@ -0,0 +1,77 @@ +--echo ---- Partitioning and enum data type + +eval create table t1 (a enum('A','B','C','D','E','F','G','H','I','J','K','L') not null, primary key(a)) engine=$engine +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +insert into t1 values ('A'),('D'),('L'),('G'); +--sorted_result +select * from t1; +select * from t1 where a='A'; +update t1 set a='E' where a='L'; +select * from t1; +delete from t1 where a='E'; +--sorted_result +select * from t1; +drop table t1; + +eval create table t2 (a enum ( +'1','2','3','4','5','6','7','8','9','0', +'A','B','C','D','E','F','G','H','I','J','K','L', +'M','N','O','P','Q','R','S','T','U','V','W','X', +'Y','Z' +) not null, primary key(a)) engine=$engine +partition by key (a) partitions 27; +show create table t2; +let $letter=26; +--echo $count inserts; +--disable_query_log +begin; +while ($letter) +{ +eval insert ignore into t2 values (char(ascii('A')+$letter)); +dec $letter; +} +commit; +--enable_query_log +insert into t2 values ('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9'),('0'); +select count(*) from t2; +--sorted_result +select * from t2; +drop table t2; + +# mleich: Several partitioning functions are no more allowed. +if (0) +{ +eval create table t3 (a enum ( +'1','2','3','4','5','6','7','8','9','0', +'A','B','C','D','E','F','G','H','I','J','K','L', +'M','N','O','P','Q','R','S','T','U','V','W','X', +'Y','Z' +) not null, primary key(a)) engine=$engine +partition by range (a) subpartition by key (a) subpartitions 3 ( +partition pa9 values less than (10), +partition pa18 values less than (19), +partition pa27 values less than (28), +partition pa36 values less than (37) +); +show create table t3; +let $letter=36; +--echo $count inserts; +--disable_query_log + begin; +while ($letter) +{ +#eval insert into t3 values ($letter); +dec $letter; +} +commit; +--enable_query_log +select count(*) from t3; +select * from t3; +drop table t3; +} +# End of tests with disallowed partitioning functions. diff --git a/mysql-test/suite/parts/inc/partition_exchange.inc b/mysql-test/suite/parts/inc/partition_exchange.inc new file mode 100644 index 00000000..95a67a33 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_exchange.inc @@ -0,0 +1,354 @@ +# Include file to test PARTITION EXCHANGE usable with different engines +# Written by Mattias.Jonsson@Sun.Com + +--echo # Test with AUTO_INCREMENT +eval CREATE TABLE tp +(a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, + b varchar(24)) +ENGINE = $engine +PARTITION BY HASH (a) PARTITIONS 4; +CREATE TABLE t LIKE tp; +ALTER TABLE t REMOVE PARTITIONING; +SHOW CREATE TABLE tp; +SHOW CREATE TABLE t; +INSERT INTO tp (b) VALUES ("One"), ("Two"), ("Three"), ("Four"), ("Five"), +("Six"), ("Seven"), ("Eight"), ("Nine"), ("Ten"), ("Eleven"), ("Twelwe"); +if ($no_update) +{ +# Archive handles auto inc by only allowing increasing values, +# so this must be inserted before a higher value is inserted. +INSERT INTO tp VALUES (41, "One hundred one"); +} +INSERT INTO tp VALUES (97, "Ninety seven"); +if (!$no_delete) +{ +INSERT INTO tp VALUES (111, "One hundred eleven"); +} +if (!$no_update) +{ +INSERT INTO tp VALUES (101, "One hundred one"); +} +SET INSERT_ID = 13; +INSERT INTO t (b) VALUES ("Thirteen"); +if ($no_update) +{ +SET INSERT_ID = 17; +INSERT INTO t (b) VALUES ("Twenty five"); +} +SET INSERT_ID = 21; +INSERT INTO t (b) VALUES ("Twenty one"); +if (!$no_update) +{ +SET INSERT_ID = 25; +INSERT INTO t (b) VALUES ("Twenty five"); +} +if (!$no_delete) +{ +SET INSERT_ID = 55; +INSERT INTO t (b) VALUES ("Fifty five"); +DELETE FROM tp WHERE a = 111; +DELETE FROM t WHERE a = 55; +} +if (!$no_update) +{ +UPDATE tp SET a = 41 WHERE a = 101; +UPDATE t SET a = 17 WHERE a = 25; +} +-- disable_query_log +-- disable_result_log +ANALYZE TABLE tp; +-- enable_result_log +-- enable_query_log +SELECT PARTITION_NAME, IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='test' AND TABLE_NAME = 'tp'; +SELECT IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA ='test' AND TABLE_NAME = 't'; +ALTER TABLE tp EXCHANGE PARTITION p1 WITH TABLE t; +-- disable_query_log +-- disable_result_log +ANALYZE TABLE tp; +-- enable_result_log +-- enable_query_log +SELECT PARTITION_NAME, IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='test' AND TABLE_NAME = 'tp'; +SELECT IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_ROWS FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA ='test' AND TABLE_NAME = 't'; +SELECT * FROM tp ORDER BY a; +SELECT * FROM t ORDER BY a; +SHOW CREATE TABLE tp; +SHOW CREATE TABLE t; +DROP TABLE tp, t; + +# set a DEBUG_SYNC after open table and before verifying is done +# Test that one can read from the table but not write, test that one can both +# read and write to the partition +# Verify that one must close the other instances of the table before the rename +# takes place (i.e. no need for LOCK_open) +# Test that it is not possible to drop, create, truncate either the tables or +# partition +# Test that it waits for ongoing transactions + +if ($no_keys) +{ +eval CREATE TABLE t +(a INT, + b VARCHAR(55)) +ENGINE = $engine; +eval CREATE TABLE tp +(a INT, + b VARCHAR(55)) +ENGINE = $engine +PARTITION BY RANGE (a) +(PARTITION p0 VALUES LESS THAN (100), + PARTITION p1 VALUES LESS THAN MAXVALUE); +eval CREATE TABLE tsp +(a INT, + b VARCHAR(55)) +ENGINE = $engine +PARTITION BY RANGE (a) +SUBPARTITION BY HASH(a) +(PARTITION p0 VALUES LESS THAN (100) + (SUBPARTITION sp0, + SUBPARTITION sp1), + PARTITION p1 VALUES LESS THAN MAXVALUE + (SUBPARTITION sp2, + SUBPARTITION sp3)); +} +if (!$no_keys) +{ +eval CREATE TABLE t +(a INT, + b VARCHAR(55), + PRIMARY KEY (a)) +ENGINE = $engine; +eval CREATE TABLE tp +(a INT, + b VARCHAR(55), + PRIMARY KEY (a)) +ENGINE = $engine +PARTITION BY RANGE (a) +(PARTITION p0 VALUES LESS THAN (100), + PARTITION p1 VALUES LESS THAN MAXVALUE); +eval CREATE TABLE tsp +(a INT, + b VARCHAR(55), + PRIMARY KEY (a)) +ENGINE = $engine +PARTITION BY RANGE (a) +SUBPARTITION BY HASH(a) +(PARTITION p0 VALUES LESS THAN (100) + (SUBPARTITION sp0, + SUBPARTITION sp1), + PARTITION p1 VALUES LESS THAN MAXVALUE + (SUBPARTITION sp2, + SUBPARTITION sp3)); +} + +INSERT INTO t VALUES (1, "First value"), (3, "Three"), (5, "Five"), (99, "End of values"); +INSERT INTO tp VALUES (2, "First value"), (10, "Ten"), (50, "Fifty"), (200, "Two hundred, end of values"), (61, "Sixty one"), (62, "Sixty two"), (63, "Sixty three"), (64, "Sixty four"), (161, "161"), (162, "162"), (163, "163"), (164, "164"); +INSERT INTO tsp VALUES (2, "First value"), (10, "Ten"), (50, "Fifty"), (200, "Two hundred, end of values"), (61, "Sixty one"), (62, "Sixty two"), (63, "Sixty three"), (64, "Sixty four"), (161, "161"), (162, "162"), (163, "163"), (164, "164"); +--sorted_result +SELECT * FROM t; +--sorted_result +SELECT * FROM tp; + +--echo # Start by testing read/write locking +SET AUTOCOMMIT = 1; + +connect(con1, localhost, root,,); +SET DEBUG_SYNC= 'swap_partition_after_compare_tables SIGNAL swap_in_progress WAIT_FOR goto_verification'; +SET DEBUG_SYNC= 'swap_partition_first_row_read SIGNAL swap_in_progress WAIT_FOR goto_wait'; +SET DEBUG_SYNC= 'swap_partition_after_wait SIGNAL swap_in_progress WAIT_FOR goto_rename'; +SET DEBUG_SYNC= 'swap_partition_before_rename SIGNAL swap_in_progress WAIT_FOR test_done'; +send ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t; + +connection default; +SET DEBUG_SYNC= 'now WAIT_FOR swap_in_progress'; +--echo # select from t and select/update/delete/insert from tp should work +SELECT * FROM t WHERE a = 99; +SELECT * FROM tp WHERE a = 61; +--echo # any write (update/delete/insert) into t or tp should fail +SET SESSION lock_wait_timeout=1; +if (!$no_update) +{ +--error ER_LOCK_WAIT_TIMEOUT +UPDATE tp SET a = 53, b = concat("Fifty three, was ", b) WHERE a = 63; +} +--error ER_LOCK_WAIT_TIMEOUT +INSERT INTO tp VALUES (63, "Sixty three, new"), (59, "To be deleted"); +if (!$no_delete) +{ +--error ER_LOCK_WAIT_TIMEOUT +DELETE FROM tp WHERE a = 59; +} +if (!$no_update) +{ +--error ER_LOCK_WAIT_TIMEOUT +UPDATE t SET a = 53, b = "Fifty three, was three" WHERE a = 3; +} +--error ER_LOCK_WAIT_TIMEOUT +INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted"); +if (!$no_delete) +{ +--error ER_LOCK_WAIT_TIMEOUT +DELETE FROM t WHERE a = 3; +} +--error ER_LOCK_WAIT_TIMEOUT +eval ALTER TABLE t ENGINE = $engine; +--error ER_LOCK_WAIT_TIMEOUT +eval ALTER TABLE tp ENGINE = $engine; +SHOW CREATE TABLE t; +SHOW CREATE TABLE tp; +SET DEBUG_SYNC= 'now SIGNAL goto_verification'; +SET DEBUG_SYNC= 'now WAIT_FOR swap_in_progress'; +--echo # select from t and select/update/delete/insert from tp should work +SELECT * FROM t WHERE a = 99; +SELECT * FROM tp WHERE a = 61; +if (!$no_update) +{ +--error ER_LOCK_WAIT_TIMEOUT +UPDATE tp SET a = 43, b = concat("Fifty three, was ", b) WHERE a = 63; +} +--error ER_LOCK_WAIT_TIMEOUT +INSERT INTO tp VALUES (63, "Sixty three, new 2"), (59, "To be deleted"); +if (!$no_delete) +{ +--error ER_LOCK_WAIT_TIMEOUT +DELETE FROM tp WHERE a = 59; +} +--echo # any write (update/delete/insert) into t should fail +if (!$no_update) +{ +--error ER_LOCK_WAIT_TIMEOUT +UPDATE t SET a = 53, b = "Fifty three, was three" WHERE a = 3; +} +--error ER_LOCK_WAIT_TIMEOUT +INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted"); +if (!$no_delete) +{ +--error ER_LOCK_WAIT_TIMEOUT +DELETE FROM t WHERE a = 3; +} +--error ER_LOCK_WAIT_TIMEOUT +eval ALTER TABLE t ENGINE = $engine; +--error ER_LOCK_WAIT_TIMEOUT +eval ALTER TABLE tp ENGINE = $engine; +SHOW CREATE TABLE t; +SHOW CREATE TABLE tp; +SET DEBUG_SYNC= 'now SIGNAL goto_wait'; +SET DEBUG_SYNC= 'now WAIT_FOR swap_in_progress'; +--echo # Both tables should now be under exclusive lock, even SHOW should fail +--error ER_LOCK_WAIT_TIMEOUT +SELECT * FROM t WHERE a = 99; +--error ER_LOCK_WAIT_TIMEOUT +SELECT * FROM tp WHERE a = 61; +if (!$no_update) +{ +--error ER_LOCK_WAIT_TIMEOUT +UPDATE tp SET a = 53, b = concat("Fifty three, was ", b) WHERE a = 63; +} +--error ER_LOCK_WAIT_TIMEOUT +INSERT INTO tp VALUES (63, "Sixty three, new 2"), (59, "To be deleted"); +if (!$no_delete) +{ +--error ER_LOCK_WAIT_TIMEOUT +DELETE FROM tp WHERE a = 59; +} +if (!$no_update) +{ +--error ER_LOCK_WAIT_TIMEOUT +UPDATE t SET a = 53, b = "Fifty three, was three" WHERE a = 3; +} +--error ER_LOCK_WAIT_TIMEOUT +INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted"); +if (!$no_delete) +{ +--error ER_LOCK_WAIT_TIMEOUT +DELETE FROM t WHERE a = 3; +} +--error ER_LOCK_WAIT_TIMEOUT +SHOW CREATE TABLE t; +--error ER_LOCK_WAIT_TIMEOUT +SHOW CREATE TABLE tp; +--error ER_LOCK_WAIT_TIMEOUT +eval ALTER TABLE t ENGINE = $engine; +--error ER_LOCK_WAIT_TIMEOUT +eval ALTER TABLE tp ENGINE = $engine; +SET DEBUG_SYNC= 'now SIGNAL goto_rename'; +SET DEBUG_SYNC= 'now WAIT_FOR swap_in_progress'; +--echo # Both tables should now be under exclusive lock +--error ER_LOCK_WAIT_TIMEOUT +SELECT * FROM t WHERE a = 99; +--error ER_LOCK_WAIT_TIMEOUT +SELECT * FROM tp WHERE a = 61; +if (!$no_update) +{ +--error ER_LOCK_WAIT_TIMEOUT +UPDATE tp SET a = 53, b = concat("Fifty three, was ", b) WHERE a = 63; +} +--error ER_LOCK_WAIT_TIMEOUT +INSERT INTO tp VALUES (63, "Sixty three, new 2"), (59, "To be deleted"); +if (!$no_delete) +{ +--error ER_LOCK_WAIT_TIMEOUT +DELETE FROM tp WHERE a = 59; +} +if (!$no_update) +{ +--error ER_LOCK_WAIT_TIMEOUT +UPDATE t SET a = 53, b = "Fifty three, was three" WHERE a = 3; +} +--error ER_LOCK_WAIT_TIMEOUT +INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted"); +if (!$no_delete) +{ +--error ER_LOCK_WAIT_TIMEOUT +DELETE FROM t WHERE a = 3; +} +--error ER_LOCK_WAIT_TIMEOUT +eval ALTER TABLE t ENGINE = $engine; +--error ER_LOCK_WAIT_TIMEOUT +eval ALTER TABLE tp ENGINE = $engine; +--error ER_LOCK_WAIT_TIMEOUT +SHOW CREATE TABLE t; +--error ER_LOCK_WAIT_TIMEOUT +SHOW CREATE TABLE tp; + +SET DEBUG_SYNC= 'now SIGNAL test_done'; + +connection con1; +--reap +connection default; +--echo # Tables should now be as normal +SHOW CREATE TABLE t; +SHOW CREATE TABLE tp; +SELECT * FROM tp WHERE a = 99; +SELECT * FROM t WHERE a = 61; +if (!$no_update) +{ +UPDATE t SET a = 53, b = "Fifty three, was sixty three" WHERE a = 63; +} +INSERT INTO t VALUES (63, "Sixty three, new"), (59, "To be deleted"); +if (!$no_delete) +{ +DELETE FROM t WHERE a = 59; +} +if (!$no_update) +{ +UPDATE tp SET a = 53, b = "Fifty three, was three" WHERE a = 3; +} +INSERT INTO tp VALUES (63, "Sixty three, new"), (59, "To be deleted"); +if (!$no_delete) +{ +DELETE FROM tp WHERE a = 3; +} +eval ALTER TABLE t ENGINE = $engine; +eval ALTER TABLE tp ENGINE = $engine; + +disconnect con1; +connection default; +SET DEBUG_SYNC= 'RESET'; +SHOW CREATE TABLE t; +SHOW CREATE TABLE tp; +--sorted_result +SELECT * FROM t; +--sorted_result +SELECT * FROM tp; + +DROP TABLE t, tp, tsp; diff --git a/mysql-test/suite/parts/inc/partition_fail.inc b/mysql-test/suite/parts/inc/partition_fail.inc new file mode 100644 index 00000000..bbe5924e --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_fail.inc @@ -0,0 +1,43 @@ +# Include file to decrease test code duplication + +--eval $create_statement +--eval $insert_statement +--let $dbug_flag= `select @@session.debug_dbug` +--echo # $dbug_flag: BEFORE failure +--replace_result #p# #P# #sp# #SP# +--let $DATADIR= `select @@datadir` +--list_files $DATADIR/test +SHOW CREATE TABLE t1; +--sorted_result +SELECT * FROM t1; +--disable_abort_on_error +--eval $fail_statement +--enable_abort_on_error +--echo # $dbug_flag: AFTER failure +--replace_result #p# #P# #sp# #SP# +--list_files $DATADIR/test +SHOW CREATE TABLE t1; +--sorted_result +SELECT * FROM t1; +DROP TABLE t1; + +--eval $create_statement +--eval $insert_statement +--echo # $dbug_flag: BEFORE failure (under LOCK TABLE) +--replace_result #p# #P# #sp# #SP# +--list_files $DATADIR/test +SHOW CREATE TABLE t1; +--sorted_result +SELECT * FROM t1; +LOCK TABLE t1 WRITE; +--disable_abort_on_error +--eval $fail_statement +--enable_abort_on_error +--echo # $dbug_flag: AFTER failure (under LOCK TABLE) +--replace_result #p# #P# #sp# #SP# +--list_files $DATADIR/test +SHOW CREATE TABLE t1; +--sorted_result +SELECT * FROM t1; +UNLOCK TABLES; +DROP TABLE t1; diff --git a/mysql-test/suite/parts/inc/partition_fail_add.inc b/mysql-test/suite/parts/inc/partition_fail_add.inc new file mode 100644 index 00000000..a7b8dd8a --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_fail_add.inc @@ -0,0 +1,34 @@ +# To be used with partition mgm commands like +# ALTER TABLE t1 ADD PARTITION (LIST/RANGE PARTITIONING). +--echo # Error recovery testing ADD PARTITION +SET @save_dbug=@@debug_dbug; +SET SESSION debug_dbug="+d,fail_add_partition_1"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,fail_add_partition_2"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,fail_add_partition_3"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,fail_add_partition_4"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,fail_add_partition_5"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,fail_add_partition_6"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,fail_add_partition_7"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,fail_add_partition_8"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,fail_add_partition_9"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,fail_add_partition_10"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; diff --git a/mysql-test/suite/parts/inc/partition_fail_change.inc b/mysql-test/suite/parts/inc/partition_fail_change.inc new file mode 100644 index 00000000..c10d5fec --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_fail_change.inc @@ -0,0 +1,41 @@ +# To be used with partition mgm commands like +# ALTER TABLE t1 COALESCE/REBUILD/REORGANIZE PARTITION. +--echo # Error recovery change partition (REORGANIZE/REBUILD/COALESCE +--echo # or ADD HASH PARTITION). +SET @save_dbug=@@debug_dbug; +SET SESSION debug_dbug="+d,fail_change_partition_1"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,fail_change_partition_2"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,fail_change_partition_3"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,fail_change_partition_4"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,fail_change_partition_5"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,fail_change_partition_6"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,fail_change_partition_7"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,fail_change_partition_8"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,fail_change_partition_9"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,fail_change_partition_10"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,fail_change_partition_11"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,fail_change_partition_12"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; diff --git a/mysql-test/suite/parts/inc/partition_fail_drop.inc b/mysql-test/suite/parts/inc/partition_fail_drop.inc new file mode 100644 index 00000000..df1d28b0 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_fail_drop.inc @@ -0,0 +1,31 @@ +# To be used with partition mgm commands like +# ALTER TABLE t1 DROP PARTITION. +--echo # Error recovery DROP PARTITION +SET @save_dbug=@@debug_dbug; +SET SESSION debug_dbug="+d,fail_drop_partition_1"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,fail_drop_partition_2"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,fail_drop_partition_3"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,fail_drop_partition_4"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,fail_drop_partition_5"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,fail_drop_partition_6"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,fail_drop_partition_7"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,fail_drop_partition_8"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,fail_drop_partition_9"; +--source suite/parts/inc/partition_fail.inc +SET SESSION debug_dbug=@save_dbug; diff --git a/mysql-test/suite/parts/inc/partition_fail_exchange.inc b/mysql-test/suite/parts/inc/partition_fail_exchange.inc new file mode 100644 index 00000000..33d7bbd1 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_fail_exchange.inc @@ -0,0 +1,28 @@ +SET @save_dbug=@@debug_dbug; +SET SESSION debug_dbug="+d,exchange_partition_fail_1"; +--source suite/parts/inc/partition_fail_t2.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,exchange_partition_fail_2"; +--source suite/parts/inc/partition_fail_t2.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,exchange_partition_fail_3"; +--source suite/parts/inc/partition_fail_t2.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,exchange_partition_fail_4"; +--source suite/parts/inc/partition_fail_t2.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,exchange_partition_fail_5"; +--source suite/parts/inc/partition_fail_t2.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,exchange_partition_fail_6"; +--source suite/parts/inc/partition_fail_t2.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,exchange_partition_fail_7"; +--source suite/parts/inc/partition_fail_t2.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,exchange_partition_fail_8"; +--source suite/parts/inc/partition_fail_t2.inc +SET SESSION debug_dbug=@save_dbug; +SET SESSION debug_dbug="+d,exchange_partition_fail_9"; +--source suite/parts/inc/partition_fail_t2.inc +SET SESSION debug_dbug=@save_dbug; diff --git a/mysql-test/suite/parts/inc/partition_fail_t2.inc b/mysql-test/suite/parts/inc/partition_fail_t2.inc new file mode 100644 index 00000000..301fb005 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_fail_t2.inc @@ -0,0 +1,41 @@ +# Include file to test failure with error injection. +# To be used with WL#4445: EXCHANGE PARTITION WITH TABLE. +--eval $create_statement2 +--eval $insert_statement2 +--eval $create_statement +--eval $insert_statement +--let $dbug_flag= `select @@session.debug_dbug` +--echo # $dbug_flag: BEFORE failure +--replace_result #p# #P# +if (!$DATADIR) +{ + --let $DATADIR= `SELECT @@datadir;` +} +--list_files $DATADIR/test +SHOW CREATE TABLE t1; +--sorted_result +SELECT * FROM t1; +SHOW CREATE TABLE t2; +--sorted_result +SELECT * FROM t2; +# accept all errors +--disable_abort_on_error +--replace_regex /#sql-exchange-[0-9a-f_\-]*/#sql-exchange/i +--eval $fail_statement +--enable_abort_on_error +--echo # $dbug_flag: AFTER failure +--replace_result #p# #P# +--list_files $DATADIR/test +SHOW CREATE TABLE t1; +--sorted_result +SELECT * FROM t1; +DROP TABLE t1; +--error 0, ER_NO_SUCH_TABLE +SHOW CREATE TABLE t2; +--sorted_result +--error 0, ER_NO_SUCH_TABLE +SELECT * FROM t2; +# TODO: everything fails with ER_NO_SUCH_TABLE +# but DROP TABLE fails with ER_BAD_TABLE_ERROR! Why? +--error 0, ER_BAD_TABLE_ERROR +DROP TABLE t2; diff --git a/mysql-test/suite/parts/inc/partition_float.inc b/mysql-test/suite/parts/inc/partition_float.inc new file mode 100644 index 00000000..b9c6af84 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_float.inc @@ -0,0 +1,42 @@ +eval create table t1 (a float not null, primary key(a)) engine=$engine +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +insert into t1 values (-3.402823466E+38), (3.402823466E+38), (-1.5), (-1), (0), (1), (1.5); +select * from t1; +select * from t1 where a=1.5; +delete from t1 where a=1.5; +select * from t1; +drop table t1; + +eval create table t2 (a float not null, primary key(a)) engine=$engine +partition by key (a) partitions 10; +show create table t2; +insert into t2 values (-3.402823466E+38), (-3.402823466E+37), (-123.456), (0), (1234546.789), (123.456), (1.5); +select * from t2; +#result set is empty: Not a bug with float!! +select * from t2 where a=123.456; +delete from t2 where a=123.456; +select * from t2; +select * from t2 where a=1.5; +delete from t2 where a=1.5; +select * from t2; +delete from t2; +let $count=$maxrows; +--echo $maxrows*3 inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t2 values ($count); +eval insert into t2 values ($count+0.33); +eval insert into t2 values ($count+0.75); +dec $count; +} +commit; +--enable_query_log +select count(*) from t2; +drop table t2; diff --git a/mysql-test/suite/parts/inc/partition_int.inc b/mysql-test/suite/parts/inc/partition_int.inc new file mode 100644 index 00000000..f457bb53 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_int.inc @@ -0,0 +1,52 @@ +eval create table t1 (a int unsigned not null, primary key(a)) engine=$engine +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +insert into t1 values (4294967295), (4294967294), (4294967293), (4294967292), (1), (2), (65535); +--sorted_result +select * from t1; +select * from t1 where a=4294967293; +delete from t1 where a=4294967293; +--sorted_result +select * from t1; +drop table t1; + +eval create table t2 (a int unsigned not null, primary key(a)) engine=$engine +partition by key (a) partitions 8; +show create table t2; +insert into t2 values (4294967295), (4294967294), (4294967293), (4294967292); +--sorted_result +select * from t2; +select * from t2 where a=4294967293; +delete from t2 where a=4294967293; +--sorted_result +select * from t2; +delete from t2; +let $count=$maxrows; +--echo $count inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t2 values ($count); +dec $count; +} +commit; +--enable_query_log +select count(*) from t2; +drop table t2; + +eval create table t3 (a int not null, primary key(a)) engine=$engine +partition by key (a) partitions 7; +show create table t3; +insert into t3 values (2147483647), (2147483646), (2147483645), (2147483644), (-2147483648), (-2147483647), (1), (-1), (0); +--sorted_result +select * from t3; +select * from t3 where a=2147483645; +delete from t3 where a=2147483645; +--sorted_result +select * from t3; +drop table t3; diff --git a/mysql-test/suite/parts/inc/partition_key_16col.inc b/mysql-test/suite/parts/inc/partition_key_16col.inc new file mode 100644 index 00000000..988dc455 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_key_16col.inc @@ -0,0 +1,15 @@ +eval create table t1 (a date not null, b varchar(50) not null, c varchar(50) not null, d enum('m', 'w') not null, e int not null, f decimal (18,2) not null, g bigint not null, h tinyint not null, a1 date not null, b1 varchar(50) not null, c1 varchar(50) not null, d1 enum('m', 'w') not null, e1 int not null, f1 decimal (18,2) not null, g1 bigint not null, h1 tinyint not null, i char(255), primary key(a,b,c,d,e,f,g,h,a1,b1,c1,d1,e1,f1,g1,h1)) engine=$engine +partition by key(a,b,c,d,e,f,g,h,a1,b1,c1,d1,e1,f1,g1,h1) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +insert into t1 values +('1975-01-01', 'abcde', 'abcde','m', 1234, 123.45, 32412341234, 113,'1975-01-01', 'abcde', 'abcde','m', 1234, 123.45, 32412341234, 113, 'tbhth nrzh ztfghgfh fzh ftzhj fztjh'), +('1983-12-31', 'cdef', 'srtbvsr', 'w', 45634, 13452.56, 3452346456, 127,'1983-12-31', 'cdef', 'srtbvsr', 'w', 45634, 13452.56, 3452346456, 127, 'liuugbzvdmrlti b itiortudirtfgtibm dfi'), +('1980-10-14', 'fgbbd', 'dtzndtz', 'w', 67856, 5463354.67, 3567845333, 124,'1980-10-14', 'fgbbd', 'dtzndtz', 'w', 67856, 5463354.67, 3567845333, 124, 'd,f söierugsig msireg siug ei5ggth lrutluitgzeöjrtnb.rkjthuekuhzrkuthgjdnffjmbr'), +('2000-06-15', 'jukg','zikhuk','m', 45675, 6465754.13, 435242623462, 18, '2000-06-15', 'jukg','zikhuk','m', 45675, 6465754.13, 435242623462, 18, 'pib mdotkbm.m'); +select * from t1; +select * from t1 where a<19851231; +drop table t1; diff --git a/mysql-test/suite/parts/inc/partition_key_32col.inc b/mysql-test/suite/parts/inc/partition_key_32col.inc new file mode 100644 index 00000000..0acedefa --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_key_32col.inc @@ -0,0 +1,35 @@ +--error ER_TOO_MANY_PARTITION_FUNC_FIELDS_ERROR +eval create table t1 (a date not null, b varchar(50) not null, c varchar(50) not null, d enum('m', 'w') not null, e int not null, f decimal (18,2) not null, g bigint not null, h tinyint not null, a1 date not null, b1 varchar(50) not null, c1 varchar(50) not null, d1 enum('m', 'w') not null, e1 int not null, f1 decimal (18,2) not null, g1 bigint not null, h1 tinyint not null, a2 date not null, b2 varchar(50) not null, c2 varchar(50) not null, d2 enum('m', 'w') not null, e2 int not null, f2 decimal (18,2) not null, g2 bigint not null, h2 tinyint not null, a3 date not null, b3 varchar(50) not null, c3 varchar(50) not null, d3 enum('m', 'w') not null, e3 int not null, f3 decimal (18,2) not null, g3 bigint not null, h3 tinyint not null, i char(255), primary key(a,b,c,d,e,f,g,h,a1,b1,c1,d1,e1,f1,g1,h1,a2,b2,c2,d2,e2,f2,g2,h2,a3,b3,c3,d3,e3,f3,g3,h3,a4)) engine=$engine +partition by key(a,b,c,d,e,f,g,h,a1,b1,c1,d1,e1,f1,g1,h1,a2,b2,c2,d2,e2,f2,g2,h2,a3,b3,c3,d3,e3,f3,g3,h3,a4) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); + +eval create table t1 (a date not null, b varchar(50) not null, c varchar(50) not null, d enum('m', 'w') not null, e int not null, f decimal (18,2) not null, g bigint not null, h tinyint not null, a1 date not null, b1 varchar(50) not null, c1 varchar(50) not null, d1 enum('m', 'w') not null, e1 int not null, f1 decimal (18,2) not null, g1 bigint not null, h1 tinyint not null, a2 date not null, b2 varchar(50) not null, c2 varchar(50) not null, d2 enum('m', 'w') not null, e2 int not null, f2 decimal (18,2) not null, g2 bigint not null, h2 tinyint not null, a3 date not null, b3 varchar(50) not null, c3 varchar(50) not null, d3 enum('m', 'w') not null, e3 int not null, f3 decimal (18,2) not null, g3 bigint not null, h3 tinyint not null, i char(255), primary key(a,b,c,d,e,f,g,h,a1,b1,c1,d1,e1,f1,g1,h1,a2,b2,c2,d2,e2,f2,g2,h2,a3,b3,c3,d3,e3,f3,g3,h3)) engine=$engine +partition by key(a,b,c,d,e,f,g,h,a1,b1,c1,d1,e1,f1,g1,h1,a2,b2,c2,d2,e2,f2,g2,h2,a3,b3,c3,d3,e3,f3,g3,h3) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +drop table t1; + +eval create table t1 (a date not null, b varchar(50) not null, c varchar(50) not null, d enum('m', 'w') not null, e int not null, f decimal (18,2) not null, g bigint not null, h tinyint not null, a1 date not null, b1 varchar(50) not null, c1 varchar(50) not null, d1 enum('m', 'w') not null, e1 int not null, f1 decimal (18,2) not null, g1 bigint not null, h1 tinyint not null, a2 date not null, b2 varchar(50) not null, c2 varchar(50) not null, d2 enum('m', 'w') not null, e2 int not null, f2 decimal (18,2) not null, g2 bigint not null, h2 tinyint not null, a3 date not null, b3 varchar(50) not null, c3 varchar(50) not null, d3 enum('m', 'w') not null, e3 int not null, f3 decimal (18,2) not null, g3 bigint not null, h3 tinyint not null, i char(255), primary key(a,b,c,d,e,f,g,h,a1,b1,c1,d1,e1,f1,g1,h1)) engine=$engine +partition by key(a,b,c,d,e,f,g,h) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); + +#--disable_abort_on error +show create table t1; +insert into t1 values +('1975-01-01', 'abcde', 'abcde','m', 1234, 123.45, 32412341234, 113,'1975-01-01', 'abcde', 'abcde','m', 1234, 123.45, 32412341234, 113,'1975-01-01', 'abcde', 'abcde','m', 1234, 123.45, 32412341234, 113, '1975-01-01', 'abcde', 'abcde','m', 1234, 123.45, 32412341234, 113, 'tbhth nrzh ztfghgfh fzh ftzhj fztjh'), +('1983-12-31', 'cdef', 'srtbvsr', 'w', 45634, 13452.56, 3452346456, 127,'1983-12-31', 'cdef', 'srtbvsr', 'w', 45634, 13452.56, 3452346456, 127, '1983-12-31', 'cdef', 'srtbvsr', 'w', 45634, 13452.56, 3452346456, 127, '1983-12-31', 'cdef', 'srtbvsr', 'w', 45634, 13452.56, 3452346456, 127, 'liuugbzvdmrlti b itiortudirtfgtibm dfi'), +('1980-10-14', 'fgbbd', 'dtzndtz', 'w', 67856, 5463354.67, 3567845333, 124, '1980-10-14', 'fgbbd', 'dtzndtz', 'w', 67856, 5463354.67, 3567845333, 124, '1980-10-14', 'fgbbd', 'dtzndtz', 'w', 67856, 5463354.67, 3567845333, 124, '1980-10-14', 'fgbbd', 'dtzndtz', 'w', 67856, 5463354.67, 3567845333, 124, 'd,f söierugsig msireg siug ei5ggth lrutluitgzeöjrtnb.rkjthuekuhzrkuthgjdnffjmbr'), +('2000-06-15', 'jukg','zikhuk','m', 45675, 6465754.13, 435242623462, 18, '2000-06-15', 'jukg','zikhuk','m', 45675, 6465754.13, 435242623462, 18, '2000-06-15', 'jukg','zikhuk','m', 45675, 6465754.13, 435242623462, 18, '2000-06-15', 'jukg','zikhuk','m', 45675, 6465754.13, 435242623462, 18, 'pib mdotkbm.m'); +select * from t1; +select * from t1 where a<19851231; +drop table t1; +--enable_abort_on_error + diff --git a/mysql-test/suite/parts/inc/partition_key_4col.inc b/mysql-test/suite/parts/inc/partition_key_4col.inc new file mode 100644 index 00000000..a94ab581 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_key_4col.inc @@ -0,0 +1,16 @@ +eval create table t1 (a date not null, b varchar(50) not null, c varchar(50) not null, d enum('m', 'w'), primary key(a,b,c,d)) engine=$engine +partition by key (a,b,c,d) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +insert into t1 values +('1975-01-01', 'abcde', 'abcde','m'), +('1983-12-31', 'cdef', 'srtbvsr', 'w'), +('1980-10-14', 'fgbbd', 'dtzndtz', 'w'), +('2000-06-15', 'jukg','zikhuk','m'); +select * from t1; +select * from t1 where a<19851231; +drop table t1; + diff --git a/mysql-test/suite/parts/inc/partition_key_8col.inc b/mysql-test/suite/parts/inc/partition_key_8col.inc new file mode 100644 index 00000000..fcbab7c3 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_key_8col.inc @@ -0,0 +1,15 @@ +eval create table t1 (a date not null, b varchar(50) not null, c varchar(50) not null, d enum('m', 'w') not null, e int not null, f decimal (18,2) not null, g bigint not null, h tinyint not null, i char(255), primary key(a,b,c,d,e,f,g,h)) engine=$engine +partition by key(a,b,c,d,e,f,g,h) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +insert into t1 values +('1975-01-01', 'abcde', 'abcde','m', 1234, 123.45, 32412341234, 113, 'tbhth nrzh ztfghgfh fzh ftzhj fztjh'), +('1983-12-31', 'cdef', 'srtbvsr', 'w', 45634, 13452.56, 3452346456, 127, 'liuugbzvdmrlti b itiortudirtfgtibm dfi'), +('1980-10-14', 'fgbbd', 'dtzndtz', 'w', 67856, 5463354.67, 3567845333, 124, 'd,f söierugsig msireg siug ei5ggth lrutluitgzeöjrtnb.rkjthuekuhzrkuthgjdnffjmbr'), +('2000-06-15', 'jukg','zikhuk','m', 45675, 6465754.13, 435242623462, 18, 'pib mdotkbm.m' ); +select * from t1; +select * from t1 where a<19851231; +drop table t1; diff --git a/mysql-test/suite/parts/inc/partition_layout.inc b/mysql-test/suite/parts/inc/partition_layout.inc new file mode 100644 index 00000000..c1ab14f9 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_layout.inc @@ -0,0 +1,15 @@ +# inc/partition_layout.inc +# +# Print partitioning related information about the table t1 +# + +eval SHOW CREATE TABLE t1; + +# Optional (most probably issues with separators and case sensitivity) +# listing of files belonging to the table t1 +if ($ls) +{ + let $MYSQLD_DATADIR= `select @@datadir`; + --replace_result $MYSQLD_DATADIR MYSQLD_DATADIR #p# #P# #sp# #SP# + --list_files $MYSQLD_DATADIR/test t1* +} diff --git a/mysql-test/suite/parts/inc/partition_layout_check1.inc b/mysql-test/suite/parts/inc/partition_layout_check1.inc new file mode 100644 index 00000000..76df4c1a --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_layout_check1.inc @@ -0,0 +1,77 @@ +################################################################################ +# inc/partition_layout_check1.inc # +# # +# Purpose: # +# Store the SHOW CREATE TABLE output and the list of files belonging to # +# this table + print this into the protocol # +# This script is only usefule when sourced within the partitioning tests. # +# # +# Attention: The routine inc/partition_layout_check2.inc is very similar # +# to this one. So if something has to be changed here it # +# might be necessary to do it also there # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-03-05 # +# Change Author: pcrews # +# Change Date: 2008-04-15 # +# Change: Added --replace_result to account for Windows' use of '\r' # +################################################################################ + +if ($no_debug) +{ +--disable_query_log +} +# Clean the table holding the definition of t1 +DELETE FROM t0_definition; + +# Get the MySQL Servers datadir without ending slash +let $MYSQLD_DATADIR= `select LEFT(@@datadir, LENGTH(@@datadir)-1)`; +#echo MYSQLD_DATADIR: $MYSQLD_DATADIR; + +# Save the current definition of the table t1 +# - SHOW CREATE TABLE t1 is at least currently most probably more reliable than +# the corresponding SELECT on the INFORMATION_SCHEMA +let $show_create= `SHOW CREATE TABLE t1`; +if ($do_file_tests) +{ + # List the files belonging to the table t1 + let $ls_file= $MYSQLD_DATADIR/test/tmp2; + --list_files_write_file $ls_file $MYSQLD_DATADIR/test t1* + --chmod 0644 $ls_file + if ($with_directories) + { + --list_files_append_file $ls_file $MYSQLTEST_VARDIR/mysql-test-data-dir t1* + --list_files_append_file $ls_file $MYSQLTEST_VARDIR/mysql-test-idx-dir t1* + } + eval SET @aux = load_file('$ls_file'); + + # clean up + --remove_file $ls_file +} +if (!$do_file_tests) +{ + SET @aux = '--- not determined ---'; +} + +# Insert the current definition of the table t1 into t0_definition +eval INSERT INTO t0_definition SET state = 'old', + create_command = "$show_create", + file_list = @aux; + +# Print the create table statement into the protocol +# Added the concat to avoid changing the result files +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR '\r' '' +SELECT concat('SHOW CREATE TABLE t1;\nTable\tCreate Table\n',create_command,'\n') as `create_command` FROM t0_definition WHERE state = 'old'; +if ($do_file_tests) +{ + # We stored the list of files, therefore printing the content makes sense + if ($ls) + { + # Print the list of files into the protocol + replace_result $MYSQLD_DATADIR MYSQLD_DATADIR $MYSQLTEST_VARDIR MYSQLTEST_VARDIR #p# #P# #sp# #SP# part_n part_N; + SELECT file_list AS "unified filelist" + FROM t0_definition WHERE state = 'old'; + } +} +--enable_query_log diff --git a/mysql-test/suite/parts/inc/partition_layout_check2.inc b/mysql-test/suite/parts/inc/partition_layout_check2.inc new file mode 100644 index 00000000..23e4a9e1 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_layout_check2.inc @@ -0,0 +1,83 @@ +################################################################################ +# inc/partition_layout_check2.inc # +# # +# Purpose: # +# Store the SHOW CREATE TABLE output and the list of files belonging to # +# this table + Check if the layout of the table was not modified # +# since the call of inc/partition_layout_check1.inc # +# This script is only usefule when sourced within the partitioning tests. # +# # +# Attention: The routine inc/partition_layout_check1.inc is very similar # +# to this one. So if something has to be changed here it # +# might be necessary to do it also there # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-03-05 # +################################################################################ + +if ($no_debug) +{ +--disable_query_log +} +# Clean the table holding the definition of t1 +DELETE FROM t0_definition WHERE state = 'new'; + + +# Get the MySQL Servers datadir without ending slash +let $MYSQLD_DATADIR= `select LEFT(@@datadir, LENGTH(@@datadir)-1)`; +#echo MYSQLD_DATADIR: $MYSQLD_DATADIR; + +# Save the current definition of the table t1 +let $show_create= `SHOW CREATE TABLE t1`; + +if ($do_file_tests) +{ + # List the files belonging to the table t1 + let $ls_file= $MYSQLD_DATADIR/test/tmp2; + --list_files_write_file $ls_file $MYSQLD_DATADIR/test t1* + --chmod 0644 $ls_file + if ($with_directories) + { + --list_files_append_file $ls_file $MYSQLTEST_VARDIR/mysql-test-data-dir t1* + --list_files_append_file $ls_file $MYSQLTEST_VARDIR/mysql-test-idx-dir t1* + } + eval SET @aux = load_file('$ls_file'); + + # clean up + --remove_file $ls_file +} +if (!$do_file_tests) +{ + SET @aux = '--- not determined ---'; +} + +# Insert the current definition of the table t1 into t0_definition +eval INSERT INTO t0_definition SET state = 'new', + create_command = "$show_create", + file_list = @aux; + +# Print the old and new table layout, if they differ +SELECT COUNT(*) <> 1 INTO @aux +FROM t0_definition tab1, t0_definition tab2 +WHERE tab1.state = 'old' AND tab2.state = 'new' + AND tab1.create_command = tab2.create_command + AND tab1.file_list = tab2.file_list; +let $run= `SELECT @aux`; +if ($run) +{ + --vertical_results + --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR #p# #P# #sp# #SP# + SELECT state, + REPLACE(create_command,'\n',' ') AS "Table definition", + REPLACE(file_list ,'\n',' ') AS "File list" + FROM t0_definition WHERE state in ('old','new'); + --horizontal_results + --echo # check layout success: 0 +} +let $run= `SELECT @aux = 0`; +if ($run) +{ + --echo # check layout success: 1 +} +--enable_query_log diff --git a/mysql-test/suite/parts/inc/partition_mediumint.inc b/mysql-test/suite/parts/inc/partition_mediumint.inc new file mode 100644 index 00000000..564abe33 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_mediumint.inc @@ -0,0 +1,52 @@ +eval create table t1 (a mediumint unsigned not null, primary key(a)) engine=$engine +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +insert into t1 values (16777215), (16777214), (16777213), (16777212), (1), (2), (65535); +--sorted_result +select * from t1; +select * from t1 where a=16777213; +delete from t1 where a=16777213; +--sorted_result +select * from t1; +drop table t1; + +eval create table t2 (a mediumint unsigned not null, primary key(a)) engine=$engine +partition by key (a) partitions 8; +show create table t2; +insert into t2 values (16777215), (16777214), (16777213), (16777212); +--sorted_result +select * from t2; +select * from t2 where a=16777213; +delete from t2 where a=16777213; +--sorted_result +select * from t2; +delete from t2; +let $count=$maxrows; +--echo $maxrows inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t2 values ($count); +dec $count; +} +commit; +--enable_query_log +select count(*) from t2; +drop table t2; + +eval create table t3 (a mediumint not null, primary key(a)) engine=$engine +partition by key (a) partitions 7; +show create table t3; +insert into t3 values (8388607), (8388606), (8388605), (8388604), (-8388608), (-8388607), (1), (-1), (0); +--sorted_result +select * from t3; +select * from t3 where a=8388605; +delete from t3 where a=8388605; +--sorted_result +select * from t3; +drop table t3; diff --git a/mysql-test/suite/parts/inc/partition_methods1.inc b/mysql-test/suite/parts/inc/partition_methods1.inc new file mode 100644 index 00000000..54cf050f --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_methods1.inc @@ -0,0 +1,375 @@ +################################################################################ +# inc/partition_methods1.inc # +# # +# Purpose: # +# Create and check partitioned tables # +# The partitioning function use the column f_int1 # +# # +# For all partitioning methods # +# PARTITION BY HASH/KEY/LIST/RANGE # +# PARTITION BY RANGE/LIST ... SUBPARTITION BY HASH/KEY ... # +# do # +# 1. Create the partitioned table # +# 2 Insert the content of the table t0_template into t1 # +# 3. Execute inc/partition_check.inc # +# 4. Drop the table t1 # +# done # +# # +# The parameter # +# $unique -- PRIMARY KEY or UNIQUE INDEXes to be created within the # +# CREATE TABLE STATEMENT # +# has to be set before sourcing this routine. # +# Example: # +# let $unique= , UNIQUE INDEX uidx1 (f_int1); # +# inc/partition_method1s.inc # +# # +# Attention: The routine inc/partition_methods2.inc is very similar # +# to this one. So if something has to be changed here it # +# might be necessary to do it also there # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-03-05 # +# Change Author: HH # +# Change Date: 2006-05-12 # +# Change: Introduced DATA/INDEX DIRECTORY # +################################################################################ + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +let $partitioning= ; +#----------- PARTITION BY HASH +if ($with_partitioning) +{ +let $partitioning= PARTITION BY HASH(f_int1) PARTITIONS 2; +if ($with_directories) +{ +let $partitioning= +PARTITION BY HASH(f_int1) PARTITIONS 2 +(PARTITION p1 +$data_directory +$index_directory, +PARTITION p2 +$data_directory +$index_directory); +} +} +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; +--source suite/parts/inc/partition_check_drop.inc + +#----------- PARTITION BY KEY +if ($with_partitioning) +{ +let $partitioning= +PARTITION BY KEY(f_int1) PARTITIONS 5; +if ($with_directories) +{ +let $partitioning= +PARTITION BY KEY(f_int1) PARTITIONS 5 +(PARTITION p1 +$data_directory +$index_directory, +PARTITION p2 +$data_directory +$index_directory, +PARTITION p3 +$data_directory +$index_directory, +PARTITION p4 +$data_directory +$index_directory, +PARTITION p5 +$data_directory +$index_directory); +} +} +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; +--source suite/parts/inc/partition_check_drop.inc + +#----------- PARTITION BY LIST +if ($with_partitioning) +{ +let $partitioning= +PARTITION BY LIST(MOD(f_int1,4)) +(PARTITION part_3 VALUES IN (-3), + PARTITION part_2 VALUES IN (-2), + PARTITION part_1 VALUES IN (-1), + PARTITION part_N VALUES IN (NULL), + PARTITION part0 VALUES IN (0), + PARTITION part1 VALUES IN (1), + PARTITION part2 VALUES IN (2), + PARTITION part3 VALUES IN (3)); +if ($with_directories) +{ +let $partitioning= +PARTITION BY LIST(MOD(f_int1,4)) +(PARTITION part_3 VALUES IN (-3) +$data_directory $index_directory, + PARTITION part_2 VALUES IN (-2) +$data_directory $index_directory, + PARTITION part_1 VALUES IN (-1) +$data_directory $index_directory, + PARTITION part_N VALUES IN (NULL) +$data_directory $index_directory, + PARTITION part0 VALUES IN (0) +$data_directory $index_directory, + PARTITION part1 VALUES IN (1) +$data_directory $index_directory, + PARTITION part2 VALUES IN (2) +$data_directory $index_directory, + PARTITION part3 VALUES IN (3) +$data_directory $index_directory); +} +} +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; +--source suite/parts/inc/partition_check_drop.inc + +#----------- PARTITION BY RANGE +if ($with_partitioning) +{ +let $partitioning= PARTITION BY RANGE(f_int1) +(PARTITION parta VALUES LESS THAN (0), +PARTITION partb VALUES LESS THAN ($max_row_div4), +PARTITION partc VALUES LESS THAN ($max_row_div2), +PARTITION partd VALUES LESS THAN ($max_row_div2 + $max_row_div4), +PARTITION parte VALUES LESS THAN ($max_row), +PARTITION partf VALUES LESS THAN $MAX_VALUE); +if ($with_directories) +{ +let $partitioning= PARTITION BY RANGE(f_int1) +(PARTITION parta VALUES LESS THAN (0) +$data_directory +$index_directory, +PARTITION partb VALUES LESS THAN ($max_row_div4) +$data_directory +$index_directory, +PARTITION partc VALUES LESS THAN ($max_row_div2) +$data_directory +$index_directory, +PARTITION partd VALUES LESS THAN ($max_row_div2 + $max_row_div4) +$data_directory +$index_directory, +PARTITION parte VALUES LESS THAN ($max_row) +$data_directory +$index_directory, +PARTITION partf VALUES LESS THAN $MAX_VALUE +$data_directory +$index_directory); +} +} +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; +--source suite/parts/inc/partition_check_drop.inc + +#----------- PARTITION BY RANGE -- SUBPARTITION BY HASH +if ($with_partitioning) +{ +let $partitioning= +PARTITION BY RANGE(f_int1 DIV 2) SUBPARTITION BY HASH(f_int1) SUBPARTITIONS 2 +(PARTITION parta VALUES LESS THAN (0), +PARTITION partb VALUES LESS THAN ($max_row_div4), +PARTITION partc VALUES LESS THAN ($max_row_div2), +PARTITION partd VALUES LESS THAN $MAX_VALUE); +if ($with_directories) +{ +let $partitioning= +PARTITION BY RANGE(f_int1 DIV 2) SUBPARTITION BY HASH(f_int1) SUBPARTITIONS 2 +(PARTITION parta VALUES LESS THAN (0) +$data_directory +$index_directory, +PARTITION partb VALUES LESS THAN ($max_row_div4) +$data_directory +$index_directory, +PARTITION partc VALUES LESS THAN ($max_row_div2) +$data_directory +$index_directory, +PARTITION partd VALUES LESS THAN $MAX_VALUE +$data_directory +$index_directory); +} +} +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; +--source suite/parts/inc/partition_check_drop.inc + +#----------- PARTITION BY RANGE -- SUBPARTITION BY KEY +if ($with_partitioning) +{ +let $partitioning= PARTITION BY RANGE(f_int1) SUBPARTITION BY KEY(f_int1) +(PARTITION part1 VALUES LESS THAN (0) +(SUBPARTITION subpart11, SUBPARTITION subpart12), +PARTITION part2 VALUES LESS THAN ($max_row_div4) +(SUBPARTITION subpart21, SUBPARTITION subpart22), +PARTITION part3 VALUES LESS THAN ($max_row_div2) +(SUBPARTITION subpart31, SUBPARTITION subpart32), +PARTITION part4 VALUES LESS THAN $MAX_VALUE +(SUBPARTITION subpart41, SUBPARTITION subpart42)); +if ($with_directories) +{ +let $partitioning= PARTITION BY RANGE(f_int1) SUBPARTITION BY KEY(f_int1) +(PARTITION part1 VALUES LESS THAN (0) +(SUBPARTITION subpart11 $data_directory $index_directory, + SUBPARTITION subpart12 $data_directory $index_directory), +PARTITION part2 VALUES LESS THAN ($max_row_div4) +(SUBPARTITION subpart21 $data_directory $index_directory, + SUBPARTITION subpart22 $data_directory $index_directory), +PARTITION part3 VALUES LESS THAN ($max_row_div2) +(SUBPARTITION subpart31 $data_directory $index_directory, + SUBPARTITION subpart32 $data_directory $index_directory), +PARTITION part4 VALUES LESS THAN $MAX_VALUE +(SUBPARTITION subpart41 $data_directory $index_directory, + SUBPARTITION subpart42 $data_directory $index_directory)); +} +} +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; +--source suite/parts/inc/partition_check_drop.inc + +#----------- PARTITION BY LIST -- SUBPARTITION BY HASH +if ($with_partitioning) +{ +let $partitioning= +PARTITION BY LIST(ABS(MOD(f_int1,3))) SUBPARTITION BY HASH(f_int1 + 1) +(PARTITION part1 VALUES IN (0) + (SUBPARTITION sp11, + SUBPARTITION sp12), + PARTITION part2 VALUES IN (1) + (SUBPARTITION sp21, + SUBPARTITION sp22), + PARTITION part3 VALUES IN (2) + (SUBPARTITION sp31, + SUBPARTITION sp32), + PARTITION part4 VALUES IN (NULL) + (SUBPARTITION sp41, + SUBPARTITION sp42)); +if ($with_directories) +{ +let $partitioning= +PARTITION BY LIST(ABS(MOD(f_int1,3))) SUBPARTITION BY HASH(f_int1 + 1) +(PARTITION part1 VALUES IN (0) + $data_directory + $index_directory + (SUBPARTITION sp11 + $data_directory + $index_directory, + SUBPARTITION sp12 + $data_directory + $index_directory), + PARTITION part2 VALUES IN (1) + $data_directory + $index_directory + (SUBPARTITION sp21 + $data_directory + $index_directory, + SUBPARTITION sp22 + $data_directory + $index_directory), + PARTITION part3 VALUES IN (2) + $data_directory + $index_directory + (SUBPARTITION sp31, + SUBPARTITION sp32), + PARTITION part4 VALUES IN (NULL) + $data_directory + $index_directory + (SUBPARTITION sp41 + $data_directory + $index_directory, + SUBPARTITION sp42 + $data_directory + $index_directory)); +} +} +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; +--source suite/parts/inc/partition_check_drop.inc + +#----------- PARTITION BY LIST -- SUBPARTITION BY KEY +if ($with_partitioning) +{ +let $partitioning= +PARTITION BY LIST(ABS(MOD(f_int1,2))) +SUBPARTITION BY KEY(f_int1) SUBPARTITIONS $sub_part_no +(PARTITION part1 VALUES IN (0), + PARTITION part2 VALUES IN (1), + PARTITION part3 VALUES IN (NULL)); +if ($with_directories) +{ +let $partitioning= +PARTITION BY LIST(ABS(MOD(f_int1,2))) +SUBPARTITION BY KEY(f_int1) SUBPARTITIONS $sub_part_no +(PARTITION part1 VALUES IN (0) + $data_directory + $index_directory, + PARTITION part2 VALUES IN (1) + $data_directory + $index_directory, + PARTITION part3 VALUES IN (NULL) + $data_directory + $index_directory); +} +} +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; +--source suite/parts/inc/partition_check_drop.inc diff --git a/mysql-test/suite/parts/inc/partition_methods2.inc b/mysql-test/suite/parts/inc/partition_methods2.inc new file mode 100644 index 00000000..8af6a2cb --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_methods2.inc @@ -0,0 +1,359 @@ +################################################################################ +# inc/partition_methods2.inc # +# # +# Purpose: # +# Create and check partitioned tables # +# The partitioning function uses the columns f_int1 and f_int2 # +# For all partitioning methods # +# PARTITION BY HASH/KEY/LIST/RANGE # +# PARTITION BY RANGE/LIST ... SUBPARTITION BY HASH/KEY ... # +# do # +# 1. Create the partitioned table # +# 2 Insert the content of the table t0_template into t1 # +# 3. Execute inc/partition_check.inc # +# 4. Drop the table t1 # +# done # +# # +# The parameter # +# $unique -- PRIMARY KEY or UNIQUE INDEXes to be created within the # +# CREATE TABLE STATEMENT # +# has to be set before sourcing this routine. # +# Example: # +# let $unique= , UNIQUE INDEX uidx1 (f_int1); # +# inc/partition_methods2.inc # +# # +# Attention: The routine inc/partition_methods1.inc is very similar # +# to this one. So if something has to be changed here it # +# might be necessary to do it also there # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-03-05 # +# Change Author: # +# Change Date: # +# Change: # +################################################################################ + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +let $partitioning= ; +#----------- PARTITION BY HASH +if ($with_partitioning) +{ +let $partitioning= PARTITION BY HASH(f_int1 + f_int2) PARTITIONS 2; +if ($with_directories) +{ +let $partitioning= +PARTITION BY HASH(f_int1 + f_int2) PARTITIONS 2 +(PARTITION p1 +$data_directory +$index_directory, +PARTITION p2 +$data_directory +$index_directory); +} +} +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; + +#----------- PARTITION BY KEY +if ($with_partitioning) +{ +let $partitioning= PARTITION BY KEY(f_int1,f_int2) PARTITIONS 5; +if ($with_directories) +{ +let $partitioning= +PARTITION BY KEY(f_int1,f_int2) PARTITIONS 5 +(PARTITION p1 +$data_directory +$index_directory, +PARTITION p2 +$data_directory +$index_directory, +PARTITION p3 +$data_directory +$index_directory, +PARTITION p4 +$data_directory +$index_directory, +PARTITION p5 +$data_directory +$index_directory); +} +} +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; + +#----------- PARTITION BY LIST +if ($with_partitioning) +{ +let $partitioning= PARTITION BY LIST(MOD(f_int1 + f_int2,4)) +(PARTITION part_3 VALUES IN (-3), + PARTITION part_2 VALUES IN (-2), + PARTITION part_1 VALUES IN (-1), + PARTITION part_N VALUES IN (NULL), + PARTITION part0 VALUES IN (0), + PARTITION part1 VALUES IN (1), + PARTITION part2 VALUES IN (2), + PARTITION part3 VALUES IN (3)); +if ($with_directories) +{ +let $partitioning= +PARTITION BY LIST(MOD(f_int1 + f_int2,4)) +(PARTITION part_3 VALUES IN (-3) +$data_directory $index_directory, + PARTITION part_2 VALUES IN (-2) +$data_directory $index_directory, + PARTITION part_1 VALUES IN (-1) +$data_directory $index_directory, + PARTITION part_N VALUES IN (NULL) +$data_directory $index_directory, + PARTITION part0 VALUES IN (0) +$data_directory $index_directory, + PARTITION part1 VALUES IN (1) +$data_directory $index_directory, + PARTITION part2 VALUES IN (2) +$data_directory $index_directory, + PARTITION part3 VALUES IN (3) +$data_directory $index_directory); +} +} +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; + +#----------- PARTITION BY RANGE +if ($with_partitioning) +{ +let $partitioning= PARTITION BY RANGE((f_int1 + f_int2) DIV 2) +(PARTITION parta VALUES LESS THAN (0), +PARTITION partb VALUES LESS THAN ($max_row_div4), +PARTITION partc VALUES LESS THAN ($max_row_div2), +PARTITION partd VALUES LESS THAN ($max_row_div2 + $max_row_div4), +PARTITION parte VALUES LESS THAN ($max_row), +PARTITION partf VALUES LESS THAN $MAX_VALUE); +if ($with_directories) +{ +let $partitioning= PARTITION BY RANGE((f_int1 + f_int2) DIV 2) +(PARTITION parta VALUES LESS THAN (0) +$data_directory +$index_directory, +PARTITION partb VALUES LESS THAN ($max_row_div4) +$data_directory +$index_directory, +PARTITION partc VALUES LESS THAN ($max_row_div2) +$data_directory +$index_directory, +PARTITION partd VALUES LESS THAN ($max_row_div2 + $max_row_div4) +$data_directory +$index_directory, +PARTITION parte VALUES LESS THAN ($max_row) +$data_directory +$index_directory, +PARTITION partf VALUES LESS THAN $MAX_VALUE +$data_directory +$index_directory); +} +} +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; + +#----------- PARTITION BY RANGE -- SUBPARTITION BY HASH +if ($with_partitioning) +{ +let $partitioning= +PARTITION BY RANGE(f_int1) SUBPARTITION BY HASH(f_int2) SUBPARTITIONS 2 +(PARTITION parta VALUES LESS THAN (0), +PARTITION partb VALUES LESS THAN ($max_row_div4), +PARTITION partc VALUES LESS THAN ($max_row_div2), +PARTITION partd VALUES LESS THAN $MAX_VALUE); +if ($with_directories) +{ +let $partitioning= +PARTITION BY RANGE(f_int1) SUBPARTITION BY HASH(f_int2) SUBPARTITIONS 2 +(PARTITION parta VALUES LESS THAN (0) +$data_directory +$index_directory, +PARTITION partb VALUES LESS THAN ($max_row_div4) +$data_directory +$index_directory, +PARTITION partc VALUES LESS THAN ($max_row_div2) +$data_directory +$index_directory, +PARTITION partd VALUES LESS THAN $MAX_VALUE +$data_directory +$index_directory); +} +} +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; + +#----------- PARTITION BY RANGE -- SUBPARTITION BY KEY +if ($with_partitioning) +{ +let $partitioning= PARTITION BY RANGE(f_int1) SUBPARTITION BY KEY(f_int2) +(PARTITION part1 VALUES LESS THAN (0) +(SUBPARTITION subpart11, SUBPARTITION subpart12), +PARTITION part2 VALUES LESS THAN ($max_row_div4) +(SUBPARTITION subpart21, SUBPARTITION subpart22), +PARTITION part3 VALUES LESS THAN ($max_row_div2) +(SUBPARTITION subpart31, SUBPARTITION subpart32), +PARTITION part4 VALUES LESS THAN $MAX_VALUE +(SUBPARTITION subpart41, SUBPARTITION subpart42)); +if ($with_directories) +{ +let $partitioning= PARTITION BY RANGE(f_int1) SUBPARTITION BY KEY(f_int2) +(PARTITION part1 VALUES LESS THAN (0) +(SUBPARTITION subpart11 $data_directory $index_directory, + SUBPARTITION subpart12 $data_directory $index_directory), +PARTITION part2 VALUES LESS THAN ($max_row_div4) +(SUBPARTITION subpart21 $data_directory $index_directory, + SUBPARTITION subpart22 $data_directory $index_directory), +PARTITION part3 VALUES LESS THAN ($max_row_div2) +(SUBPARTITION subpart31 $data_directory $index_directory, + SUBPARTITION subpart32 $data_directory $index_directory), +PARTITION part4 VALUES LESS THAN $MAX_VALUE +(SUBPARTITION subpart41 $data_directory $index_directory, + SUBPARTITION subpart42 $data_directory $index_directory)); +} +} +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; + +#----------- PARTITION BY LIST -- SUBPARTITION BY HASH +if ($with_partitioning) +{ +let $partitioning= PARTITION BY LIST(ABS(MOD(f_int1,3))) SUBPARTITION BY HASH(f_int2 + 1) +(PARTITION part1 VALUES IN (0) + (SUBPARTITION sp11, SUBPARTITION sp12), + PARTITION part2 VALUES IN (1) + (SUBPARTITION sp21, SUBPARTITION sp22), + PARTITION part3 VALUES IN (2) + (SUBPARTITION sp31, SUBPARTITION sp32), + PARTITION part4 VALUES IN (NULL) + (SUBPARTITION sp41, SUBPARTITION sp42)); +if ($with_directories) +{ +let $partitioning= +PARTITION BY LIST(ABS(MOD(f_int1,3))) SUBPARTITION BY HASH(f_int2 + 1) +(PARTITION part1 VALUES IN (0) + $data_directory + $index_directory + (SUBPARTITION sp11 + $data_directory + $index_directory, + SUBPARTITION sp12 + $data_directory + $index_directory), + PARTITION part2 VALUES IN (1) + $data_directory + $index_directory + (SUBPARTITION sp21 + $data_directory + $index_directory, + SUBPARTITION sp22 + $data_directory + $index_directory), + PARTITION part3 VALUES IN (2) + $data_directory + $index_directory + (SUBPARTITION sp31, + SUBPARTITION sp32), + PARTITION part4 VALUES IN (NULL) + $data_directory + $index_directory + (SUBPARTITION sp41 + $data_directory + $index_directory, + SUBPARTITION sp42 + $data_directory + $index_directory)); +} +} +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; + +#----------- PARTITION BY LIST -- SUBPARTITION BY KEY +if ($with_partitioning) +{ +let $partitioning= +PARTITION BY LIST(ABS(MOD(f_int1,2))) +SUBPARTITION BY KEY(f_int2) SUBPARTITIONS $sub_part_no +(PARTITION part1 VALUES IN (0), + PARTITION part2 VALUES IN (1), + PARTITION part3 VALUES IN (NULL)); +if ($with_directories) +{ +let $partitioning= +PARTITION BY LIST(ABS(MOD(f_int1,2))) +SUBPARTITION BY KEY(f_int2) SUBPARTITIONS $sub_part_no +(PARTITION part1 VALUES IN (0) + $data_directory + $index_directory, + PARTITION part2 VALUES IN (1) + $data_directory + $index_directory, + PARTITION part3 VALUES IN (NULL) + $data_directory + $index_directory); +} +} +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval CREATE TABLE t1 ( +$column_list +$unique +) +$partitioning; +eval $insert_all; +--source suite/parts/inc/partition_check.inc +DROP TABLE t1; diff --git a/mysql-test/suite/parts/inc/partition_mgm.inc b/mysql-test/suite/parts/inc/partition_mgm.inc new file mode 100644 index 00000000..dcfdb544 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_mgm.inc @@ -0,0 +1,641 @@ +################################################################################ +# inc/partition_mgm.inc # +# # +# Purpose: # +# Test of partition management functions including different Upper/Lower # +# case names of databases, tables and partitions # +# # +# # +# Uses following variables: # +# engine Use specified storage engine # +# can_only_key Storage engine only able to use HASH/KEY (not range/list) # +# part_optA-D Extra partitioning options (E.g. INDEX/DATA DIR) # +# # +# no_truncate No support for truncate partition # +#------------------------------------------------------------------------------# +# Original Author: mattiasj # +# Original Date: 2008-06-27 # +################################################################################ +--source include/default_charset.inc +--enable_abort_on_error + +let $old_db= `SELECT DATABASE()`; +--echo # Creating database MySQL_TEST_DB +CREATE DATABASE MySQL_Test_DB; +USE MySQL_Test_DB; +--echo # 1.0 KEY partitioning mgm +--echo # Creating KEY partitioned table +eval CREATE TABLE TableA (a INT) +ENGINE = $engine +PARTITION BY KEY (a) +(PARTITION parta $part_optA, + PARTITION partB $part_optB, + PARTITION Partc $part_optC, + PARTITION PartD $part_optD); +INSERT INTO TableA VALUES (1), (2), (7), (8), (9), (10); +INSERT INTO TableA VALUES (3), (4), (5), (6), (11), (12); +--sorted_result +SELECT * FROM TableA; + +--echo # Test of ADD/COALESCE PARTITIONS +--echo # expecting duplicate partition name +--error ER_SAME_NAME_PARTITION +ALTER TABLE TableA ADD PARTITION +(PARTITION partA, + PARTITION Parta, + PARTITION PartA); +ALTER TABLE TableA ADD PARTITION +(PARTITION partE, + PARTITION Partf, + PARTITION PartG); +--sorted_result +SELECT * FROM TableA; +SHOW CREATE TABLE TableA; +ALTER TABLE TableA COALESCE PARTITION 4; +--sorted_result +SELECT * FROM TableA; +SHOW CREATE TABLE TableA; + +-- disable_query_log +-- disable_result_log +ANALYZE TABLE TableA; +-- enable_result_log +-- enable_query_log + +--echo # Test of EXCHANGE PARTITION WITH TABLE +if (!$native_partitioning) +{ +SELECT PARTITION_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='MySQL_Test_DB' AND TABLE_NAME = 'TableA'; +CREATE TABLE TableB LIKE TableA; +ALTER TABLE TableB REMOVE PARTITIONING; +ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB; +--sorted_result +SELECT * FROM TableA; +SHOW CREATE TABLE TableA; +--sorted_result +SELECT * FROM TableB; +SHOW CREATE TABLE TableB; +SELECT PARTITION_NAME, IF(TABLE_ROWS, 'YES', 'NO') AS HAVE_TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_SCHEMA ='MySQL_Test_DB' AND TABLE_NAME = 'TableA'; +ALTER TABLE TableA EXCHANGE PARTITION parta WITH TABLE TableB; +INSERT INTO TableB VALUES (11); +--error ER_ROW_DOES_NOT_MATCH_PARTITION +ALTER TABLE TableA EXCHANGE PARTITION Partc WITH TABLE TableB; +DROP TABLE TableB; +--sorted_result +SELECT * FROM TableA; +SHOW CREATE TABLE TableA; +} + +--echo # Test of REORGANIZE PARTITIONS +--echo # Should not work on HASH/KEY +--error ER_REORG_HASH_ONLY_ON_SAME_NO +eval ALTER TABLE TableA REORGANIZE PARTITION parta,partB,Partc INTO +(PARTITION PARTA $part_optA, + PARTITION partc $part_optC); +--error ER_CONSECUTIVE_REORG_PARTITIONS +eval ALTER TABLE TableA REORGANIZE PARTITION parta,Partc INTO +(PARTITION partB $part_optA, + PARTITION parta $part_optC); +eval ALTER TABLE TableA REORGANIZE PARTITION parta,partB INTO +(PARTITION partB $part_optA COMMENT="Previusly named parta", + PARTITION parta $part_optB COMMENT="Previusly named partB"); +if ($fixed_bug20129) +{ +ALTER TABLE TableA ANALYZE PARTITION parta, partB, Partc; +ALTER TABLE TableA CHECK PARTITION parta, partB, Partc; +ALTER TABLE TableA OPTIMIZE PARTITION parta, partB, Partc; +ALTER TABLE TableA REPAIR PARTITION parta, partB, Partc; +} +--sorted_result +SELECT * FROM TableA; +SHOW CREATE TABLE TableA; + +--echo # Test of RENAME TABLE +RENAME TABLE TableA to TableB; +--sorted_result +SELECT * FROM TableB; +RENAME TABLE TableB to TableA; +--sorted_result +SELECT * FROM TableA; + +--echo # Checking name comparision Upper vs Lower case +--echo # Error if lower_case_table_names != 0 +let $lower_case_table_names= `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME = 'lower_case_table_names'`; +--echo # lower_case_table_names: $lower_case_table_names +if ($lower_case_table_names) +{ +--error ER_TABLE_EXISTS_ERROR +eval CREATE TABLE tablea (a INT) +ENGINE = $engine +PARTITION BY KEY (a) +(PARTITION parta $part_optA, + PARTITION partB $part_optB, + PARTITION Partc $part_optC, + PARTITION PartD $part_optD); +SHOW TABLES; +--error ER_TABLE_EXISTS_ERROR +RENAME TABLE TableA to tablea; +--error ER_TABLE_EXISTS_ERROR +RENAME TABLE tablea to TableA; +--sorted_result +SELECT * FROM tablea; +SHOW CREATE TABLE tablea; +} +if (!$lower_case_table_names) +{ +eval CREATE TABLE tablea (a INT) +ENGINE = $engine +PARTITION BY KEY (a) +(PARTITION parta $part_optA, + PARTITION partB $part_optB, + PARTITION Partc $part_optC, + PARTITION PartD $part_optD); +INSERT INTO tablea VALUES (1), (2), (7), (8), (9), (10); +SHOW TABLES; +RENAME TABLE TableA to tableA; +--sorted_result +SELECT * FROM tablea; +--sorted_result +SELECT * FROM tableA; +RENAME TABLE tableA to TableA; +SHOW CREATE TABLE tablea; +DROP TABLE tablea; +} + +--echo # Test of REMOVE PARTITIONING +ALTER TABLE TableA REMOVE PARTITIONING; +--sorted_result +SELECT * FROM TableA; +SHOW CREATE TABLE TableA; + +--echo # Cleaning up after KEY PARTITIONING test +DROP TABLE TableA; + +if (!$can_only_key) +{ +--echo # 2.0 HASH partitioning mgm +--echo # expecting duplicate partition name +--error ER_SAME_NAME_PARTITION +eval CREATE TABLE TableA (a INT) +ENGINE = $engine +PARTITION BY HASH (a) +(PARTITION parta $part_optA, + PARTITION partA $part_optB, + PARTITION Parta $part_optC, + PARTITION PartA $part_optD); + +--echo # Creating Hash partitioned table +eval CREATE TABLE TableA (a INT) +ENGINE = $engine +PARTITION BY HASH (a) +(PARTITION parta $part_optA, + PARTITION partB $part_optB, + PARTITION Partc $part_optC, + PARTITION PartD $part_optD); +INSERT INTO TableA VALUES (1), (2), (7), (8), (9), (10); +INSERT INTO TableA VALUES (3), (4), (5), (6), (11), (12); +--sorted_result +SELECT * FROM TableA; + +--echo # Test of ADD/COALESCE PARTITIONS +--echo # expecting duplicate partition name +--error ER_SAME_NAME_PARTITION +ALTER TABLE TableA ADD PARTITION +(PARTITION partA, + PARTITION Parta, + PARTITION PartA); +ALTER TABLE TableA ADD PARTITION +(PARTITION partE, + PARTITION Partf, + PARTITION PartG); +--sorted_result +SELECT * FROM TableA; +SHOW CREATE TABLE TableA; +ALTER TABLE TableA COALESCE PARTITION 4; +--sorted_result +SELECT * FROM TableA; +SHOW CREATE TABLE TableA; + +--echo # Test of REORGANIZE PARTITIONS +--echo # Should not work on HASH/KEY +--error ER_REORG_HASH_ONLY_ON_SAME_NO +eval ALTER TABLE TableA REORGANIZE PARTITION parta,partB,Partc INTO +(PARTITION PARTA $part_optA, + PARTITION partc $part_optC); +--error ER_CONSECUTIVE_REORG_PARTITIONS +eval ALTER TABLE TableA REORGANIZE PARTITION parta,Partc INTO +(PARTITION partB $part_optA, + PARTITION parta $part_optC); +eval ALTER TABLE TableA REORGANIZE PARTITION parta,partB INTO +(PARTITION partB $part_optA COMMENT="Previusly named parta", + PARTITION parta $part_optB COMMENT="Previusly named partB"); +if ($fixed_bug20129) +{ +ALTER TABLE TableA ANALYZE PARTITION parta, partB, Partc; +ALTER TABLE TableA CHECK PARTITION parta, partB, Partc; +ALTER TABLE TableA OPTIMIZE PARTITION parta, partB, Partc; +ALTER TABLE TableA REPAIR PARTITION parta, partB, Partc; +} +--sorted_result +SELECT * FROM TableA; +SHOW CREATE TABLE TableA; + +--echo # Test of RENAME TABLE +RENAME TABLE TableA to TableB; +--sorted_result +SELECT * FROM TableB; +RENAME TABLE TableB to TableA; +--sorted_result +SELECT * FROM TableA; + +--echo # Checking name comparision Upper vs Lower case +--echo # Error if lower_case_table_names != 0 +let $lower_case_table_names= `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME = 'lower_case_table_names'`; +--echo # lower_case_table_names: $lower_case_table_names +if ($lower_case_table_names) +{ +--error ER_TABLE_EXISTS_ERROR +eval CREATE TABLE tablea (a INT) +ENGINE = $engine +PARTITION BY HASH (a) +(PARTITION parta $part_optA, + PARTITION partB $part_optB, + PARTITION Partc $part_optC, + PARTITION PartD $part_optD); +SHOW TABLES; +--error ER_TABLE_EXISTS_ERROR +RENAME TABLE TableA to tablea; +--error ER_TABLE_EXISTS_ERROR +RENAME TABLE tablea to TableA; +--sorted_result +SELECT * FROM tablea; +SHOW CREATE TABLE tablea; +} +if (!$lower_case_table_names) +{ +eval CREATE TABLE tablea (a INT) +ENGINE = $engine +PARTITION BY HASH (a) +(PARTITION parta $part_optA, + PARTITION partB $part_optB, + PARTITION Partc $part_optC, + PARTITION PartD $part_optD); +INSERT INTO tablea VALUES (1), (2), (7), (8), (9), (10); +SHOW TABLES; +RENAME TABLE TableA to tableA; +--sorted_result +SELECT * FROM tablea; +--sorted_result +SELECT * FROM tableA; +RENAME TABLE tableA to TableA; +SHOW CREATE TABLE tablea; +DROP TABLE tablea; +} + +--echo # Test of REMOVE PARTITIONING +ALTER TABLE TableA REMOVE PARTITIONING; +--sorted_result +SELECT * FROM TableA; +SHOW CREATE TABLE TableA; + +--echo # Cleaning up after HASH PARTITIONING test +DROP TABLE TableA; + + +--echo # 3.0 RANGE partitioning mgm +--echo # Creating RANGE partitioned table +eval CREATE TABLE TableA (a INT) +ENGINE = $engine +PARTITION BY RANGE (a) +(PARTITION parta VALUES LESS THAN (4) $part_optA, + PARTITION partB VALUES LESS THAN (7) $part_optB, + PARTITION Partc VALUES LESS THAN (10) $part_optC, + PARTITION PartD VALUES LESS THAN (13) $part_optD); +INSERT INTO TableA VALUES (1), (2), (7), (8), (9), (10); +INSERT INTO TableA VALUES (3), (4), (5), (6), (11), (12); +--sorted_result +SELECT * FROM TableA; + +--echo # Test of ADD/DROP PARTITIONS +--echo # expecting duplicate partition name +--error ER_SAME_NAME_PARTITION +ALTER TABLE TableA ADD PARTITION +(PARTITION partA VALUES LESS THAN (MAXVALUE)); +ALTER TABLE TableA ADD PARTITION +(PARTITION partE VALUES LESS THAN (16), + PARTITION Partf VALUES LESS THAN (19), + PARTITION PartG VALUES LESS THAN (22)); +--sorted_result +SELECT * FROM TableA; +SHOW CREATE TABLE TableA; +ALTER TABLE TableA DROP PARTITION partE, PartG; +ALTER TABLE TableA DROP PARTITION Partf; +ALTER TABLE TableA ADD PARTITION +(PARTITION PartE VALUES LESS THAN (MAXVALUE)); +--sorted_result +SELECT * FROM TableA; +SHOW CREATE TABLE TableA; + +--echo # Test of REORGANIZE PARTITIONS +--echo # Error since it must reorganize a consecutive range +--error ER_CONSECUTIVE_REORG_PARTITIONS +eval ALTER TABLE TableA REORGANIZE PARTITION parta,Partc INTO +(PARTITION partB VALUES LESS THAN (3) $part_optA, + PARTITION parta VALUES LESS THAN (11) $part_optC); +eval ALTER TABLE TableA REORGANIZE PARTITION partB,Partc,PartD,PartE INTO +(PARTITION partD VALUES LESS THAN (8) $part_optB + COMMENT="Previously partB and partly Partc", + PARTITION partB VALUES LESS THAN (11) $part_optC + COMMENT="Previously partly Partc and partly PartD", + PARTITION partC VALUES LESS THAN (MAXVALUE) $part_optD + COMMENT="Previously partly PartD"); +if ($fixed_bug20129) +{ +ALTER TABLE TableA ANALYZE PARTITION parta, partB, Partc; +ALTER TABLE TableA CHECK PARTITION parta, partB, Partc; +ALTER TABLE TableA OPTIMIZE PARTITION parta, partB, Partc; +ALTER TABLE TableA REPAIR PARTITION parta, partB, Partc; +} +--sorted_result +SELECT * FROM TableA; +SHOW CREATE TABLE TableA; + +--echo # Test of RENAME TABLE +RENAME TABLE TableA to TableB; +--sorted_result +SELECT * FROM TableB; +RENAME TABLE TableB to TableA; +--sorted_result +SELECT * FROM TableA; + +--echo # Checking name comparision Upper vs Lower case +--echo # Error if lower_case_table_names != 0 +let $lower_case_table_names= `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME = 'lower_case_table_names'`; +--echo # lower_case_table_names: $lower_case_table_names +if ($lower_case_table_names) +{ +--error ER_TABLE_EXISTS_ERROR +eval CREATE TABLE tablea (a INT) +ENGINE = $engine +PARTITION BY RANGE (a) +(PARTITION parta VALUES LESS THAN (4) $part_optA, + PARTITION partB VALUES LESS THAN (7) $part_optB, + PARTITION Partc VALUES LESS THAN (10) $part_optC, + PARTITION PartD VALUES LESS THAN (13) $part_optD); +SHOW TABLES; +--error ER_TABLE_EXISTS_ERROR +RENAME TABLE TableA to tablea; +--error ER_TABLE_EXISTS_ERROR +RENAME TABLE tablea to TableA; +--sorted_result +SELECT * FROM tablea; +SHOW CREATE TABLE tablea; +} +if (!$lower_case_table_names) +{ +eval CREATE TABLE tablea (a INT) +ENGINE = $engine +PARTITION BY RANGE (a) +(PARTITION parta VALUES LESS THAN (4) $part_optA, + PARTITION partB VALUES LESS THAN (7) $part_optB, + PARTITION Partc VALUES LESS THAN (10) $part_optC, + PARTITION PartD VALUES LESS THAN (13) $part_optD); +INSERT INTO tablea VALUES (1), (2), (7), (8), (9), (10); +SHOW TABLES; +RENAME TABLE TableA to tableA; +--sorted_result +SELECT * FROM tablea; +--sorted_result +SELECT * FROM tableA; +RENAME TABLE tableA to TableA; +SHOW CREATE TABLE tablea; +DROP TABLE tablea; +} + +--echo # Test of REMOVE PARTITIONING +ALTER TABLE TableA REMOVE PARTITIONING; +--sorted_result +SELECT * FROM TableA; +SHOW CREATE TABLE TableA; + +--echo # Cleaning up after RANGE PARTITIONING test +DROP TABLE TableA; + +--echo # 4.0 LIST partitioning mgm +--echo # Creating LIST partitioned table +eval CREATE TABLE TableA (a INT) +ENGINE = $engine +PARTITION BY LIST (a) +(PARTITION parta VALUES IN (1,8,9) $part_optA, + PARTITION partB VALUES IN (2,10,11) $part_optB, + PARTITION Partc VALUES IN (3,4,7) $part_optC, + PARTITION PartD VALUES IN (5,6,12) $part_optD); +INSERT INTO TableA VALUES (1), (2), (7), (8), (9), (10); +INSERT INTO TableA VALUES (3), (4), (5), (6), (11), (12); +--sorted_result +SELECT * FROM TableA; + +--echo # Test of ADD/DROP PARTITIONS +--echo # expecting duplicate partition name +--error ER_SAME_NAME_PARTITION +ALTER TABLE TableA ADD PARTITION +(PARTITION partA VALUES IN (0)); +ALTER TABLE TableA ADD PARTITION +(PARTITION partE VALUES IN (16), + PARTITION Partf VALUES IN (19), + PARTITION PartG VALUES IN (22)); +--sorted_result +SELECT * FROM TableA; +SHOW CREATE TABLE TableA; +ALTER TABLE TableA DROP PARTITION partE, PartG; +ALTER TABLE TableA DROP PARTITION Partf; +ALTER TABLE TableA ADD PARTITION +(PARTITION PartE VALUES IN (13)); +--sorted_result +SELECT * FROM TableA; +SHOW CREATE TABLE TableA; + +--echo # Test of REORGANIZE PARTITIONS +--error ER_CONSECUTIVE_REORG_PARTITIONS +eval ALTER TABLE TableA REORGANIZE PARTITION parta,Partc INTO +(PARTITION Partc VALUES IN (1,7) $part_optA + COMMENT = "Mix 1 of old parta and Partc", + PARTITION partF VALUES IN (3,9) $part_optC + COMMENT = "Mix 2 of old parta and Partc", + PARTITION parta VALUES IN (4,8) $part_optC + COMMENT = "Mix 3 of old parta and Partc"); +eval ALTER TABLE TableA REORGANIZE PARTITION parta,partB,Partc INTO +(PARTITION Partc VALUES IN (1,7) $part_optA + COMMENT = "Mix 1 of old parta and Partc", + PARTITION parta VALUES IN (3,9) $part_optC + COMMENT = "Mix 2 of old parta and Partc", + PARTITION partB VALUES IN (4,8) $part_optC + COMMENT = "Mix 3 of old parta and Partc"); +if ($fixed_bug20129) +{ +ALTER TABLE TableA ANALYZE PARTITION parta, partB, Partc; +ALTER TABLE TableA CHECK PARTITION parta, partB, Partc; +ALTER TABLE TableA OPTIMIZE PARTITION parta, partB, Partc; +ALTER TABLE TableA REPAIR PARTITION parta, partB, Partc; +} +--sorted_result +SELECT * FROM TableA; +SHOW CREATE TABLE TableA; + +--echo # Test of RENAME TABLE +RENAME TABLE TableA to TableB; +--sorted_result +SELECT * FROM TableB; +RENAME TABLE TableB to TableA; +--sorted_result +SELECT * FROM TableA; + +--echo # Checking name comparision Upper vs Lower case +--echo # Error if lower_case_table_names != 0 +let $lower_case_table_names= `SELECT VARIABLE_VALUE FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_NAME = 'lower_case_table_names'`; +--echo # lower_case_table_names: $lower_case_table_names +if ($lower_case_table_names) +{ +--error ER_TABLE_EXISTS_ERROR +eval CREATE TABLE tablea (a INT) +ENGINE = $engine +PARTITION BY LIST (a) +(PARTITION parta VALUES IN (1,8,9) $part_optA, + PARTITION partB VALUES IN (2,10,11) $part_optB, + PARTITION Partc VALUES IN (3,4,7) $part_optC, + PARTITION PartD VALUES IN (5,6,12) $part_optD); +SHOW TABLES; +--error ER_TABLE_EXISTS_ERROR +RENAME TABLE TableA to tablea; +--error ER_TABLE_EXISTS_ERROR +RENAME TABLE tablea to TableA; +--sorted_result +SELECT * FROM tablea; +SHOW CREATE TABLE tablea; +} +if (!$lower_case_table_names) +{ +eval CREATE TABLE tablea (a INT) +ENGINE = $engine +PARTITION BY LIST (a) +(PARTITION parta VALUES IN (1,8,9) $part_optA, + PARTITION partB VALUES IN (2,10,11) $part_optB, + PARTITION Partc VALUES IN (3,4,7) $part_optC, + PARTITION PartD VALUES IN (5,6,12) $part_optD); +INSERT INTO tablea VALUES (1), (2), (7), (8), (9), (10); +SHOW TABLES; +RENAME TABLE TableA to tableA; +--sorted_result +SELECT * FROM tablea; +--sorted_result +SELECT * FROM tableA; +RENAME TABLE tableA to TableA; +SHOW CREATE TABLE tablea; +DROP TABLE tablea; +} + +--echo # Test of REMOVE PARTITIONING +ALTER TABLE TableA REMOVE PARTITIONING; +--sorted_result +SELECT * FROM TableA; +SHOW CREATE TABLE TableA; + +--echo # Cleaning up after LIST PARTITIONING test +DROP TABLE TableA; +} +# End of $can_only_key + +if ($no_truncate) +{ +--echo # Verify that TRUNCATE PARTITION gives error +eval CREATE TABLE t1 +(a BIGINT AUTO_INCREMENT PRIMARY KEY, + b VARCHAR(255)) +ENGINE = $engine +PARTITION BY KEY (a) +(PARTITION LT1000, + PARTITION LT2000, + PARTITION MAX); +INSERT INTO t1 VALUES (NULL, "First"), (NULL, "Second"), (999, "Last in LT1000"), (NULL, "First in LT2000"), (NULL, "Second in LT2000"), (1999, "Last in LT2000"), (NULL, "First in MAX"), (NULL, "Second in MAX"); +--error ER_PARTITION_MGMT_ON_NONPARTITIONED, ER_ILLEGAL_HA +ALTER TABLE t1 TRUNCATE PARTITION MAX; +--sorted_result +SELECT * FROM t1; +} +if (!$no_truncate) +{ +--echo # Testing TRUNCATE PARTITION +eval CREATE TABLE t1 +(a BIGINT AUTO_INCREMENT PRIMARY KEY, + b VARCHAR(255)) +ENGINE = $engine +PARTITION BY RANGE (a) +(PARTITION LT1000 VALUES LESS THAN (1000), + PARTITION LT2000 VALUES LESS THAN (2000), + PARTITION MAX VALUES LESS THAN MAXVALUE); +INSERT INTO t1 VALUES (NULL, "First"), (NULL, "Second"), (999, "Last in LT1000"), (NULL, "First in LT2000"), (NULL, "Second in LT2000"), (1999, "Last in LT2000"), (NULL, "First in MAX"), (NULL, "Second in MAX"); +SHOW CREATE TABLE t1; +SELECT * FROM t1 ORDER BY a; +ALTER TABLE t1 ANALYZE PARTITION MAX; +--echo # Truncate without FLUSH +ALTER TABLE t1 TRUNCATE PARTITION MAX; +INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (1)"); +SELECT * FROM t1 WHERE a >= 2000; +--echo # Truncate with FLUSH after +ALTER TABLE t1 TRUNCATE PARTITION MAX; +FLUSH TABLES; +INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (2)"); +SELECT * FROM t1 WHERE a >= 2000; +--echo # Truncate with FLUSH before +FLUSH TABLES; +ALTER TABLE t1 TRUNCATE PARTITION MAX; +INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (3)"); +SELECT * FROM t1 WHERE a >= 2000; +--echo # Truncate with FLUSH after INSERT +FLUSH TABLES; +ALTER TABLE t1 TRUNCATE PARTITION MAX; +INSERT INTO t1 VALUES (NULL, "First after TRUNCATE MAX (4)"); +SELECT * FROM t1 WHERE a >= 2000; +--echo # Truncate without FLUSH +ALTER TABLE t1 TRUNCATE PARTITION LT1000; +INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (1)"); +SELECT * FROM t1 ORDER BY a; +--echo # Truncate with FLUSH after +ALTER TABLE t1 TRUNCATE PARTITION LT1000; +FLUSH TABLES; +INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (2)"); +SELECT * FROM t1 ORDER BY a; +--echo # Truncate with FLUSH before +FLUSH TABLES; +ALTER TABLE t1 TRUNCATE PARTITION LT1000; +INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (3)"); +SELECT * FROM t1 ORDER BY a; +--echo # Truncate with FLUSH after INSERT +FLUSH TABLES; +ALTER TABLE t1 TRUNCATE PARTITION LT1000; +INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT1000 (4)"); +SELECT * FROM t1 ORDER BY a; +--echo # Truncate without FLUSH +ALTER TABLE t1 TRUNCATE PARTITION LT2000; +INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (1)"); +SELECT * FROM t1 ORDER BY a; +--echo # Truncate with FLUSH after +ALTER TABLE t1 TRUNCATE PARTITION LT2000; +FLUSH TABLES; +INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (2)"); +SELECT * FROM t1 ORDER BY a; +--echo # Truncate with FLUSH before +FLUSH TABLES; +ALTER TABLE t1 TRUNCATE PARTITION LT2000; +INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (3)"); +SELECT * FROM t1 ORDER BY a; +--echo # Truncate with FLUSH after INSERT +FLUSH TABLES; +ALTER TABLE t1 TRUNCATE PARTITION LT2000; +INSERT INTO t1 VALUES (NULL, "First after TRUNCATE LT2000 (4)"); +SELECT * FROM t1 ORDER BY a; +DROP TABLE t1; +} +--echo # Cleaning up before exit +eval USE $old_db; +DROP DATABASE MySQL_Test_DB; diff --git a/mysql-test/suite/parts/inc/partition_mgm_crash.inc b/mysql-test/suite/parts/inc/partition_mgm_crash.inc new file mode 100644 index 00000000..6607d5cd --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_mgm_crash.inc @@ -0,0 +1,52 @@ +# collection of tests which crashes the server and checks recovery. +# also using error injection to test recovery of failures. +# uses $DATADIR and $engine + +--echo # +--echo # Bug#53676: Unexpected errors and possible table corruption on +--echo # ADD PARTITION and LOCK TABLE +--echo # Bug#53770: Server crash at handler.cc:2076 on LOAD DATA +--echo # after timed out COALESCE PARTITION +--echo # Extended crash recovery testing of fast_alter_partition_table. +call mtr.add_suppression("Attempting backtrace. You can use the following information to find out"); +flush tables; +let $create_statement= CREATE TABLE t1 (a INT, b VARCHAR(64)) +ENGINE = $engine +PARTITION BY LIST (a) +(PARTITION p0 VALUES IN (0,1,2,3,4,5,6,7,8,9), + PARTITION p10 VALUES IN (11,12,13,14,15,16,17,18,19)); +let $insert_statement= INSERT INTO t1 VALUES (1, "Original from partition p0"), (2, "Original from partition p0"), (3, "Original from partition p0"), (4, "Original from partition p0"), (11, "Original from partition p1"), (12, "Original from partition p1"), (13, "Original from partition p1"), (14, "Original from partition p1"); + +let $crash_statement= ALTER TABLE t1 ADD PARTITION +(PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29)); +if ($do_crash) +{ +--source suite/parts/inc/partition_crash_add.inc +} +let $fail_statement= $crash_statement; +if ($do_fail) +{ +--source suite/parts/inc/partition_fail_add.inc +} +let $crash_statement= ALTER TABLE t1 DROP PARTITION p10; +if ($do_crash) +{ +--source suite/parts/inc/partition_crash_drop.inc +} +let $fail_statement= $crash_statement; +if ($do_fail) +{ +--source suite/parts/inc/partition_fail_drop.inc +} +let $crash_statement= ALTER TABLE t1 REORGANIZE PARTITION p10 INTO +(PARTITION p10 VALUES IN (10,11,12,13,14,15,16,17,18,19), + PARTITION p20 VALUES IN (20,21,22,23,24,25,26,27,28,29)); +if ($do_crash) +{ +--source suite/parts/inc/partition_crash_change.inc +} +let $fail_statement= $crash_statement; +if ($do_fail) +{ +--source suite/parts/inc/partition_fail_change.inc +}
\ No newline at end of file diff --git a/mysql-test/suite/parts/inc/partition_set.inc b/mysql-test/suite/parts/inc/partition_set.inc new file mode 100644 index 00000000..8b8c3c9d --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_set.inc @@ -0,0 +1,35 @@ +--echo ---- Partitioning and set data type + +eval create table t1 (a set('A','B','C','D','E','F','G','H','I','J','K','L') not null, primary key(a)) engine=$engine +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +insert into t1 values ('A,B'),('C,D'),('E,L'),('G,H,K'); +select * from t1 order by a; +select * from t1 where a='A,B'; +update t1 set a='A,B,C' where a='E,L'; +select * from t1 order by a; +delete from t1 where a='A,B'; +select * from t1 order by a; +drop table t1; + +eval create table t2 (a set ( +'1','2','3','4','5','6','7','8','9','0', +'A','B','C','D','E','F','G','H','I','J','K','L', +'M','N','O','P','Q','R','S','T','U','V','W','X', +'Y','Z' +) not null, primary key(a)) engine=$engine +partition by key (a) partitions 27; +show create table t2; +insert into t2 values ('A'),('B'),('C'),('D'),('E'),('F'),('G'),('H'),('I'),('K'),('L'),('M'),('N'),('O'),('P'),('Q'),('S'),('T'),('U'),('V'),('X'),('Y'),('Z'); +insert into t2 values ('A,B'),('B,C'),('C,D'),('D,E'),('E,F'),('F,G'),('G,H'),('H,I'),('I,J'),('K,L'),('L,M'),('M,N'),('N,O'),('O,P'),('P,Q'),('Q,R'),('S,T'),('T,U'),('U,V'),('V,W'),('X,Y'),('Y,Z'),('Z,A'); +insert into t2 values ('A,B,C'),('B,C,D'),('C,D,E'),('D,E,F'),('E,F,G'),('F,G,H'),('G,H,I'),('H,I,J'),('I,J,K'),('K,L,M'),('L,M,N'),('M,N,O'),('N,O,P'),('O,P,Q'),('P,Q,R'),('Q,R,S'),('S,T,U'),('T,U,V'),('U,V,W'),('V,W,X'),('X,Y,Z'),('Y,Z,A'),('Z,A,B'); +insert into t2 values ('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9'),('0'); +insert into t2 values ('1,2'),('2,3'),('3,4'),('4,5'),('5,6'),('6,7'),('7,8'),('8,9'),('9,0'),('0,1'); +insert into t2 values ('1,2,3'),('2,3,4'),('3,4,5'),('4,5,6'),('5,6,7'),('6,7,8'),('7,8,9'),('8,9,0'),('9,0,1'),('0,1,2'); +select count(*) from t2; +select * from t2 order by a; +drop table t2; diff --git a/mysql-test/suite/parts/inc/partition_smallint.inc b/mysql-test/suite/parts/inc/partition_smallint.inc new file mode 100644 index 00000000..0908e7e6 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_smallint.inc @@ -0,0 +1,52 @@ +eval create table t1 (a smallint unsigned not null, primary key(a)) engine=$engine +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +insert into t1 values (65535), (65534), (65533), (65532), (1), (2), (256); +--sorted_result +select * from t1; +select * from t1 where a=65533; +delete from t1 where a=65533; +--sorted_result +select * from t1; +drop table t1; + +eval create table t2 (a smallint unsigned not null, primary key(a)) engine=$engine +partition by key (a) partitions 8; +show create table t2; +insert into t2 values (65535), (65534), (65533), (65532); +--sorted_result +select * from t2; +select * from t2 where a=65533; +delete from t2 where a=65533; +--sorted_result +select * from t2; +delete from t2; +let $count=$maxrows; +--echo $count inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t2 values ($count); +dec $count; +} +commit; +--enable_query_log +select count(*) from t2; +drop table t2; + +eval create table t3 (a smallint not null, primary key(a)) engine=$engine +partition by key (a) partitions 7; +show create table t3; +insert into t3 values (32767), (32766), (32765), (32764), (-32768), (-32767), (1), (-1), (0); +--sorted_result +select * from t3; +select * from t3 where a=32765; +delete from t3 where a=32765; +--sorted_result +select * from t3; +drop table t3; diff --git a/mysql-test/suite/parts/inc/partition_supported_sql_funcs.inc b/mysql-test/suite/parts/inc/partition_supported_sql_funcs.inc new file mode 100644 index 00000000..867bff4e --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_supported_sql_funcs.inc @@ -0,0 +1,285 @@ +################################################################################ +# t/partition_supported_sql_funcs.inc # +# # +# Purpose: # +# Tests frame for allowed sql functions # +# # +# # +#------------------------------------------------------------------------------# +# Original Author: HH # +# Original Date: 2006-11-22 # +# Change Author: MattiasJ # +# Change Date: 2008-05-15 # +################################################################################ +--echo ------------------------------------------------------------------------- +--echo --- $sqlfunc in partition with coltype $coltype +--echo ------------------------------------------------------------------------- +--disable_abort_on_error +--disable_warnings +drop table if exists t1 ; +drop table if exists t2 ; +drop table if exists t3 ; +drop table if exists t4 ; +drop table if exists t5 ; +drop table if exists t6 ; +--enable_warnings +--enable_abort_on_error + +let $part_t1= partition by range($sqlfunc) +(partition p0 values less than (15), + partition p1 values less than maxvalue); + +let $part_t2= partition by list($sqlfunc) +(partition p0 values in (0,1,2,3,4,5,6,7,8,9,10), + partition p1 values in (11,12,13,14,15,16,17,18,19,20), + partition p2 values in (21,22,23,24,25,26,27,28,29,30), + partition p3 values in (31,32,33,34,35,36,37,38,39,40), + partition p4 values in (41,42,43,44,45,46,47,48,49,50), + partition p5 values in (51,52,53,54,55,56,57,58,59,60) +); + +let $part_t3= partition by hash($sqlfunc); + +let $part_t4= partition by range(colint) +subpartition by hash($sqlfunc) subpartitions 2 +(partition p0 values less than (15), + partition p1 values less than maxvalue); + +let $part_t5= partition by list(colint) +subpartition by hash($sqlfunc) subpartitions 2 +(partition p0 values in (1,2,3,4,5,6,7,8,9,10), + partition p1 values in (11,12,13,14,15,16,17,18,19,20), + partition p2 values in (21,22,23,24,25,26,27,28,29,30), + partition p3 values in (31,32,33,34,35,36,37,38,39,40), + partition p4 values in (41,42,43,44,45,46,47,48,49,50), + partition p5 values in (51,52,53,54,55,56,57,58,59,60) +); +if ($max_8_partitions) +{ +let $part_t5= partition by list(colint) +subpartition by hash($sqlfunc) subpartitions 2 +(partition p0 values in (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15), + partition p1 values in (16,17,18,19,20,21,22,23,24,25,26,27,28,29,30), + partition p2 values in (31,32,33,34,35,36,37,38,39,40,41,42,43,44,45), + partition p3 values in (46,47,48,49,50,51,52,53,54,55,56,57,58,59,60) +); +} + +let $part_t6= partition by range(colint) +(partition p0 values less than ($valsqlfunc), + partition p1 values less than maxvalue); + +let $part_t55_altered= partition by list(colint) +subpartition by hash($sqlfunc) subpartitions 5 +(partition p0 values in (1,2,3,4,5,6,7,8,9,10), + partition p1 values in (11,12,13,14,15,16,17,18,19,20), + partition p2 values in (21,22,23,24,25,26,27,28,29,30), + partition p3 values in (31,32,33,34,35,36,37,38,39,40), + partition p4 values in (41,42,43,44,45,46,47,48,49,50), + partition p5 values in (51,52,53,54,55,56,57,58,59,60) +); +if ($max_8_partitions) +{ +let $part_t55_altered= partition by list(colint) +subpartition by hash($sqlfunc) subpartitions 4 +(partition p0 values in (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30), + partition p1 values in (31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60) +); +} +--echo ------------------------------------------------------------------------- +--echo --- Create tables with $sqlfunc +--echo ------------------------------------------------------------------------- +eval create table t1 (col1 $coltype) engine=$engine +$part_t1; + +eval create table t2 (col1 $coltype) engine=$engine +$part_t2; + +eval create table t3 (col1 $coltype) engine=$engine +$part_t3; + +eval create table t4 (colint int, col1 $coltype) engine=$engine +$part_t4; + +eval create table t5 (colint int, col1 $coltype) engine=$engine +$part_t5; + +eval create table t6 (colint int, col1 $coltype) engine=$engine +$part_t6; + +--echo ------------------------------------------------------------------------- +--echo --- Access tables with $sqlfunc +--echo ------------------------------------------------------------------------- + +begin; +eval insert into t1 values ($val1); +eval insert into t1 values ($val2); + +eval insert into t2 values ($val1); +eval insert into t2 values ($val2); +eval insert into t2 values ($val3); + +eval insert into t3 values ($val1); +eval insert into t3 values ($val2); +eval insert into t3 values ($val3); +commit; + +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval load data infile '$MYSQLTEST_VARDIR/std_data/parts/$infile' into table t4; +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval load data infile '$MYSQLTEST_VARDIR/std_data/parts/$infile' into table t5; +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +eval load data infile '$MYSQLTEST_VARDIR/std_data/parts/$infile' into table t6; + +eval select $sqlfunc from t1 order by col1; + +select * from t1 order by col1; +select * from t2 order by col1; +select * from t3 order by col1; +select * from t4 order by colint; +select * from t5 order by colint; +select * from t6 order by colint; + +if ($do_long_tests) +{ + begin; + eval update t1 set col1=$val4 where col1=$val1; + eval update t2 set col1=$val4 where col1=$val1; + eval update t3 set col1=$val4 where col1=$val1; + eval update t4 set col1=$val4 where col1=$val1; + eval update t5 set col1=$val4 where col1=$val1; + eval update t6 set col1=$val4 where col1=$val1; + commit; + + select * from t1 order by col1; + select * from t2 order by col1; + select * from t3 order by col1; + select * from t4 order by colint; + select * from t5 order by colint; + select * from t6 order by colint; +} + +--echo ------------------------------------------------------------------------- +--echo --- Alter tables with $sqlfunc +--echo ------------------------------------------------------------------------- + +--disable_abort_on_error +--disable_warnings +drop table if exists t11 ; +drop table if exists t22 ; +drop table if exists t33 ; +drop table if exists t44 ; +drop table if exists t55 ; +drop table if exists t66 ; +--enable_warnings +--enable_abort_on_error + +eval create table t11 engine=$engine as select * from t1; +eval create table t22 engine=$engine as select * from t2; +eval create table t33 engine=$engine as select * from t3; +eval create table t44 engine=$engine as select * from t4; +eval create table t55 engine=$engine as select * from t5; +eval create table t66 engine=$engine as select * from t6; +eval alter table t11 +$part_t1; +eval alter table t22 +$part_t2; +eval alter table t33 +$part_t3; +eval alter table t44 +$part_t4; +eval alter table t55 +$part_t5; +eval alter table t66 +$part_t6; + +select * from t11 order by col1; +select * from t22 order by col1; +select * from t33 order by col1; +select * from t44 order by colint; +select * from t55 order by colint; +select * from t66 order by colint; + +if ($do_long_tests) +{ + --echo --------------------------- + --echo ---- some alter table begin + --echo --------------------------- + if (!$no_reorg_partition) + { + eval alter table t11 + reorganize partition p0,p1 into + (partition s1 values less than maxvalue); + select * from t11 order by col1; + + eval alter table t11 + reorganize partition s1 into + (partition p0 values less than (15), + partition p1 values less than maxvalue); + select * from t11 order by col1; + } + +eval alter table t55 +$part_t55_altered; + show create table t55; + select * from t55 order by colint; + + if (!$no_reorg_partition) + { + eval alter table t66 + reorganize partition p0,p1 into + (partition s1 values less than maxvalue); + select * from t66 order by colint; + + eval alter table t66 + reorganize partition s1 into + (partition p0 values less than ($valsqlfunc), + partition p1 values less than maxvalue); + select * from t66 order by colint; + + eval alter table t66 + reorganize partition p0,p1 into + (partition s1 values less than maxvalue); + select * from t66 order by colint; + + eval alter table t66 + reorganize partition s1 into + (partition p0 values less than ($valsqlfunc), + partition p1 values less than maxvalue); + select * from t66 order by colint; + } + + let $t1=t1; + let $t2=t2; + let $t3=t3; + let $t4=t4; + let $t5=t5; + let $t6=t6; + --source suite/parts/inc/part_supported_sql_funcs_delete.inc + + let $t1=t11; + let $t2=t22; + let $t3=t33; + let $t4=t44; + let $t5=t55; + let $t6=t66; + --source suite/parts/inc/part_supported_sql_funcs_delete.inc + --echo ------------------------- + --echo ---- some alter table end + --echo ------------------------- +} +--disable_warnings +drop table if exists t1 ; +drop table if exists t2 ; +drop table if exists t3 ; +drop table if exists t4 ; +drop table if exists t5 ; +drop table if exists t6 ; +drop table if exists t11 ; +drop table if exists t22 ; +drop table if exists t33 ; +drop table if exists t44 ; +drop table if exists t55 ; +drop table if exists t66 ; +--enable_warnings + diff --git a/mysql-test/suite/parts/inc/partition_syntax.inc b/mysql-test/suite/parts/inc/partition_syntax.inc new file mode 100644 index 00000000..e7eea733 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_syntax.inc @@ -0,0 +1,748 @@ +################################################################################ +# inc/partition_syntax.inc # +# # +# Purpose: # +# Tests around Create partitioned tables syntax # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-03-05 # +# Change Author: # +# Change Date: # +# Change: # +################################################################################ + +# FIXME Implement testcases, where it is checked that all create and +# alter table statements +# - with missing mandatory parameters are rejected +# - with optional parameters are accepted +# - with wrong combinations of optional parameters are rejected +# - ............ + +--echo +--echo #======================================================================== +--echo # 1. Any PRIMARY KEYs or UNIQUE INDEXes must contain the columns used +--echo # within the partitioning functions +--echo #======================================================================== +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings +# +--echo #------------------------------------------------------------------------ +--echo # 1.1 column of partitioning function not included in PRIMARY KEY +--echo # PARTITION BY HASH/KEY/LIST/RANGE +--echo #------------------------------------------------------------------------ +#----------- PARTITION BY HASH +--error ER_UNIQUE_KEY_NEED_ALL_FIELDS_IN_PF +eval CREATE TABLE t1 ( +$column_list, +PRIMARY KEY (f_int2) +) +PARTITION BY HASH(f_int1) PARTITIONS 2; +--error ER_UNIQUE_KEY_NEED_ALL_FIELDS_IN_PF +eval CREATE TABLE t1 ( +$column_list, +PRIMARY KEY (f_int2) +) +PARTITION BY HASH(f_int1 + f_int2) PARTITIONS 2; +#----------- PARTITION BY KEY +--error ER_UNIQUE_KEY_NEED_ALL_FIELDS_IN_PF +eval CREATE TABLE t1 ( +$column_list, +PRIMARY KEY (f_int2) +) +PARTITION BY KEY(f_int1) PARTITIONS 2; +--error ER_UNIQUE_KEY_NEED_ALL_FIELDS_IN_PF +eval CREATE TABLE t1 ( +$column_list, +PRIMARY KEY (f_int2) +) +PARTITION BY KEY(f_int1,f_int2) PARTITIONS 2; +#----------- PARTITION BY LIST +--error ER_UNIQUE_KEY_NEED_ALL_FIELDS_IN_PF +eval CREATE TABLE t1 ( +$column_list, +PRIMARY KEY (f_int2) +) +PARTITION BY LIST(f_int1) +(PARTITION part1 VALUES IN (1)); +--error ER_UNIQUE_KEY_NEED_ALL_FIELDS_IN_PF +eval CREATE TABLE t1 ( +$column_list, +PRIMARY KEY (f_int2) +) +PARTITION BY LIST(f_int1 + f_int2) +(PARTITION part1 VALUES IN (1)); +#----------- PARTITION BY RANGE +--error ER_UNIQUE_KEY_NEED_ALL_FIELDS_IN_PF +eval CREATE TABLE t1 ( +$column_list, +PRIMARY KEY (f_int2) +) +PARTITION BY RANGE(f_int1) +(PARTITION part1 VALUES LESS THAN (1)); +--error ER_UNIQUE_KEY_NEED_ALL_FIELDS_IN_PF +eval CREATE TABLE t1 ( +$column_list, +PRIMARY KEY (f_int2) +) +PARTITION BY RANGE(f_int1 + f_int2) +(PARTITION part1 VALUES LESS THAN (1)); + +# +--echo #------------------------------------------------------------------------ +--echo # 1.2 column of partitioning function not included in UNIQUE INDEX +--echo # PARTITION BY HASH/KEY/LIST/RANGE +--echo # Variant a) Without additional PRIMARY KEY +--echo # Variant b) With correct additional PRIMARY KEY +--echo # Variant 1) one column in partitioning function +--echo # Variant 2) two columns in partitioning function +--echo #------------------------------------------------------------------------ +# Note: If the CREATE TABLE statement contains no PRIMARY KEY but +# UNIQUE INDEXes the MySQL layer tells the storage to use +# the first UNIQUE INDEX as PRIMARY KEY. + +let $unique_index= UNIQUE INDEX (f_int2); + +#----------- PARTITION BY HASH +let $partition_scheme= PARTITION BY HASH(f_int1) PARTITIONS 2; +--source suite/parts/inc/partition_syntax_2.inc +let $partition_scheme= PARTITION BY HASH(f_int1 + f_int2) PARTITIONS 2; +--source suite/parts/inc/partition_syntax_2.inc +#----------- PARTITION BY KEY +let $partition_scheme= PARTITION BY KEY(f_int1) PARTITIONS 2; +--source suite/parts/inc/partition_syntax_2.inc +let $partition_scheme= PARTITION BY KEY(f_int1,f_int2) PARTITIONS 2; +--source suite/parts/inc/partition_syntax_2.inc +#----------- PARTITION BY LIST +let $partition_scheme= PARTITION BY LIST(MOD(f_int1,3)) + (PARTITION partN VALUES IN (NULL), + PARTITION part0 VALUES IN (0), + PARTITION part1 VALUES IN (1), + PARTITION part2 VALUES IN (2)); +--source suite/parts/inc/partition_syntax_2.inc +let $partition_scheme= PARTITION BY LIST(MOD(f_int1 + f_int2,3)) + (PARTITION partN VALUES IN (NULL), + PARTITION part0 VALUES IN (0), + PARTITION part1 VALUES IN (1), + PARTITION part2 VALUES IN (2)); +--source suite/parts/inc/partition_syntax_2.inc +#----------- PARTITION BY RANGE +let $partition_scheme= PARTITION BY RANGE(f_int1) + (PARTITION part1 VALUES LESS THAN (1), + PARTITION part2 VALUES LESS THAN (2147483646)); +--source suite/parts/inc/partition_syntax_2.inc +let $partition_scheme= PARTITION BY RANGE(f_int1 + f_int2) + (PARTITION part1 VALUES LESS THAN (1), + PARTITION part2 VALUES LESS THAN (2147483646)); +--source suite/parts/inc/partition_syntax_2.inc + +# +--echo #------------------------------------------------------------------------ +--echo # 1.3 column of subpartitioning function not included in PRIMARY KEY +--echo # PARTITION BY RANGE/LIST -- SUBPARTITION BY HASH/KEY +--echo #------------------------------------------------------------------------ + +#----------- PARTITION BY RANGE -- SUBPARTITION BY HASH +--error ER_UNIQUE_KEY_NEED_ALL_FIELDS_IN_PF +eval CREATE TABLE t1 ( +$column_list, +PRIMARY KEY (f_int2) +) +PARTITION BY RANGE(f_int2) SUBPARTITION BY HASH(f_int1) +(PARTITION part1 VALUES LESS THAN (1) + (SUBPARTITION subpart1)); +#----------- PARTITION BY RANGE -- SUBPARTITION BY KEY +--error ER_UNIQUE_KEY_NEED_ALL_FIELDS_IN_PF +eval CREATE TABLE t1 ( +$column_list, +PRIMARY KEY (f_int2) +) +PARTITION BY RANGE(f_int2) SUBPARTITION BY KEY(f_int1) +(PARTITION part1 VALUES LESS THAN (1) + (SUBPARTITION subpart1)); +#----------- PARTITION BY LIST -- SUBPARTITION BY HASH +--error ER_UNIQUE_KEY_NEED_ALL_FIELDS_IN_PF +eval CREATE TABLE t1 ( +$column_list, +PRIMARY KEY (f_int2) +) +PARTITION BY LIST(f_int2) SUBPARTITION BY HASH(f_int1) +(PARTITION part1 VALUES IN (1) + (SUBPARTITION subpart1)); +#----------- PARTITION BY LIST -- SUBPARTITION BY KEY +--error ER_UNIQUE_KEY_NEED_ALL_FIELDS_IN_PF +eval CREATE TABLE t1 ( +$column_list, +PRIMARY KEY (f_int2) +) +PARTITION BY LIST(f_int2) SUBPARTITION BY KEY(f_int1) +(PARTITION part1 VALUES IN (1) + (SUBPARTITION subpart1)); + +# +--echo #------------------------------------------------------------------------ +--echo # 1.4 column of subpartitioning function not included in UNIQUE INDEX +--echo # PARTITION BY RANGE/LIST -- SUBPARTITION BY HASH/KEY +--echo # Variant a) Without additional PRIMARY KEY +--echo # Variant b) With correct additional PRIMARY KEY +--echo #------------------------------------------------------------------------ +let $partition_scheme= PARTITION BY RANGE(f_int2) +SUBPARTITION BY HASH(f_int1) SUBPARTITIONS 3 + (PARTITION part1 VALUES LESS THAN (1), + PARTITION part2 VALUES LESS THAN (2147483646)); +--source suite/parts/inc/partition_syntax_2.inc +#----------- PARTITION BY RANGE -- SUBPARTITION BY KEY +let $partition_scheme= PARTITION BY RANGE(f_int2) +SUBPARTITION BY KEY(f_int1) SUBPARTITIONS 3 + (PARTITION part1 VALUES LESS THAN (1), + PARTITION part2 VALUES LESS THAN (2147483646)); +--source suite/parts/inc/partition_syntax_2.inc +#----------- PARTITION BY LIST -- SUBPARTITION BY HASH +let $partition_scheme= PARTITION BY LIST(MOD(f_int2,3)) +SUBPARTITION BY HASH(f_int1) SUBPARTITIONS 2 + (PARTITION partN VALUES IN (NULL), + PARTITION part0 VALUES IN (0), + PARTITION part1 VALUES IN (1), + PARTITION part2 VALUES IN (2)); +--source suite/parts/inc/partition_syntax_2.inc +#----------- PARTITION BY LIST -- SUBPARTITION BY KEY +let $partition_scheme= PARTITION BY LIST(MOD(f_int2,3)) +SUBPARTITION BY KEY(f_int1) SUBPARTITIONS 2 + (PARTITION partN VALUES IN (NULL), + PARTITION part0 VALUES IN (0), + PARTITION part1 VALUES IN (1), + PARTITION part2 VALUES IN (2)); +--source suite/parts/inc/partition_syntax_2.inc + +--echo +--echo #======================================================================== +--echo # 2 Some properties around subpartitioning +--echo #======================================================================== +--echo #------------------------------------------------------------------------ +--echo # 2.1 Subpartioned table without subpartitioning rule must be rejected +--echo #------------------------------------------------------------------------ +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings +# Bug#15961 Partitions: Creation of subpart. table without subpart. rule not rejected +--error ER_SUBPARTITION_ERROR +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY RANGE(f_int1) +( PARTITION part1 VALUES LESS THAN (1000) (SUBPARTITION subpart11)); +--echo #------------------------------------------------------------------------ +--echo # 2.2 Every partition must have the same number of subpartitions. +--echo # This is a limitation of MySQL 5.1, which could be removed in +--echo # later releases. +--echo #------------------------------------------------------------------------ +--error ER_PARSE_ERROR +eval CREATE TABLE t1 ( +$column_list, +PRIMARY KEY (f_int1) +) +PARTITION BY RANGE(f_int1) SUBPARTITION BY KEY(f_int1) +( + PARTITION part1 VALUES LESS THAN (0) + (SUBPARTITION subpart1), + PARTITION part2 VALUES LESS THAN ($max_row_div4) + (SUBPARTITION subpart1, SUBPARTITION subpart2)); + +--echo +--echo #======================================================================== +--echo # 3 VALUES clauses +--echo #======================================================================== +--echo #------------------------------------------------------------------------ +--echo # 3.1 The constants in VALUES IN clauses must differ +--echo #------------------------------------------------------------------------ +--error ER_MULTIPLE_DEF_CONST_IN_LIST_PART_ERROR +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY LIST(MOD(f_int1,2)) +( PARTITION part1 VALUES IN (-1), + PARTITION part2 VALUES IN (0), + PARTITION part3 VALUES IN (-1)); +# constant followed by the same constant +--error ER_RANGE_NOT_INCREASING_ERROR +CREATE TABLE t1 (f1 BIGINT, f2 BIGINT) +PARTITION BY RANGE(f1) +(PARTITION part1 VALUES LESS THAN (0), +PARTITION part2 VALUES LESS THAN (0), +PARTITION part3 VALUES LESS THAN (10000)); + +--echo #------------------------------------------------------------------------ +--echo # 3.2 The constants in VALUES LESS must be in increasing order +--echo #------------------------------------------------------------------------ +# constant followed somewhere by the smaller constant +--error ER_RANGE_NOT_INCREASING_ERROR +CREATE TABLE t1 (f1 BIGINT, f2 BIGINT) +PARTITION BY RANGE(f1) +(PARTITION part1 VALUES LESS THAN (0), +PARTITION part2 VALUES LESS THAN (-1), +PARTITION part3 VALUES LESS THAN (10000)); + +--echo #------------------------------------------------------------------------ +--echo # 3.3 LIST partitions must be defined with VALUES IN +--echo #------------------------------------------------------------------------ +--error ER_PARTITION_WRONG_VALUES_ERROR +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY LIST(MOD(f_int1,2)) +( PARTITION part1 VALUES LESS THAN (-1), + PARTITION part2 VALUES LESS THAN (0), + PARTITION part3 VALUES LESS THAN (1000)); + +--echo #------------------------------------------------------------------------ +--echo # 3.4 RANGE partitions must be defined with VALUES LESS THAN +--echo #------------------------------------------------------------------------ +--error ER_PARTITION_WRONG_VALUES_ERROR +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY RANGE(f_int1) +( PARTITION part1 VALUES IN (-1), + PARTITION part2 VALUES IN (0), + PARTITION part3 VALUES IN (1000)); + +--echo #------------------------------------------------------------------------ +--echo # 3.5 Use of NULL in VALUES clauses +--echo #------------------------------------------------------------------------ +--echo # 3.5.1 NULL in RANGE partitioning clause +--echo # 3.5.1.1 VALUE LESS THAN (NULL) is not allowed +--error ER_NULL_IN_VALUES_LESS_THAN +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY RANGE(f_int1) +( PARTITION part1 VALUES LESS THAN (NULL), + PARTITION part2 VALUES LESS THAN (1000)); +--echo # 3.5.1.2 VALUE LESS THAN (NULL) is not allowed +--error ER_NULL_IN_VALUES_LESS_THAN +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY RANGE(f_int1) +( PARTITION part1 VALUES LESS THAN (NULL), + PARTITION part2 VALUES LESS THAN (1000)); +--echo # 3.5.2 NULL in LIST partitioning clause +--echo # 3.5.2.1 VALUE IN (NULL) +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY LIST(MOD(f_int1,2)) +( PARTITION part1 VALUES IN (NULL), + PARTITION part2 VALUES IN (0), + PARTITION part3 VALUES IN (1)); +DROP TABLE t1; +--echo # 3.5.2.2 VALUE IN (NULL) +# Attention: It is intended that there is no partition with +# VALUES IN (0), because there was a time where NULL was treated as zero +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY LIST(MOD(f_int1,2)) +( PARTITION part1 VALUES IN (NULL), + PARTITION part3 VALUES IN (1)); +--source suite/parts/inc/partition_layout_check1.inc +DROP TABLE t1; +--echo # 3.5.3 Reveal that IN (...NULL) is not mapped to IN(0) +# Bug#15447: Partitions: NULL is treated as zero +# We would get a clash here if such a mapping would be done. +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY LIST(MOD(f_int1,2)) +( PARTITION part1 VALUES IN (NULL), + PARTITION part2 VALUES IN (0), + PARTITION part3 VALUES IN (1)); +--source suite/parts/inc/partition_layout_check1.inc +DROP TABLE t1; + +# FIXME Implement some non integer constant tests + + +--echo +--echo #======================================================================== +--echo # 4. Check assigning the number of partitions and subpartitions +--echo # with and without named partitions/subpartitions +--echo #======================================================================== +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings +--echo #------------------------------------------------------------------------ +--echo # 4.1 (positive) without partition/subpartition number assignment +--echo #------------------------------------------------------------------------ +--echo # 4.1.1 no partition number, no named partitions +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY HASH(f_int1); +--source suite/parts/inc/partition_layout_check1.inc +DROP TABLE t1; +--echo # 4.1.2 no partition number, named partitions +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY HASH(f_int1) (PARTITION part1, PARTITION part2); +--source suite/parts/inc/partition_layout_check1.inc +DROP TABLE t1; +# Attention: Several combinations are impossible +# If subpartitioning exists +# - partitioning algorithm must be RANGE or LIST +# This implies the assignment of named partitions. +# - subpartitioning algorithm must be HASH or KEY +--echo # 4.1.3 variations on no partition/subpartition number, named partitions, +--echo # different subpartitions are/are not named +# +# Partition name -- "properties" +# part1 -- first/non last +# part2 -- non first/non last +# part3 -- non first/ last +# +# Testpattern: +# named subpartitions in +# Partition part1 part2 part3 +# N N N +# N N Y +# N Y N +# N Y Y +# Y N N +# Y N Y +# Y Y N +# Y Y Y +--disable_query_log +let $part01= CREATE TABLE t1 ( ; +let $part02= ) +PARTITION BY RANGE(f_int1) SUBPARTITION BY HASH(f_int1); +# +eval SET @aux = '(PARTITION part1 VALUES LESS THAN ($max_row_div2),'; +let $part1_N= `SELECT @AUX`; +eval SET @aux = '(PARTITION part1 VALUES LESS THAN ($max_row_div2) +(SUBPARTITION subpart11 , SUBPARTITION subpart12 ),'; +let $part1_Y= `SELECT @AUX`; +# +eval SET @aux = 'PARTITION part2 VALUES LESS THAN ($max_row),'; +let $part2_N= `SELECT @AUX`; +eval SET @aux = 'PARTITION part2 VALUES LESS THAN ($max_row) +(SUBPARTITION subpart21 , SUBPARTITION subpart22 ),'; +let $part2_Y= `SELECT @AUX`; +# +eval SET @aux = 'PARTITION part3 VALUES LESS THAN $MAX_VALUE)'; +let $part3_N= `SELECT @AUX`; +eval SET @aux = 'PARTITION part3 VALUES LESS THAN $MAX_VALUE +(SUBPARTITION subpart31 , SUBPARTITION subpart32 ))'; +let $part3_Y= `SELECT @AUX`; +--enable_query_log + +eval $part01 $column_list $part02 $part1_N $part2_N $part3_N ; +DROP TABLE t1; +# Bug#15407 Partitions: crash if subpartition +--error ER_PARSE_ERROR +eval $part01 $column_list $part02 $part1_N $part2_N $part3_Y ; +--error ER_PARSE_ERROR +eval $part01 $column_list $part02 $part1_N $part2_Y $part3_N ; +--error ER_PARSE_ERROR +eval $part01 $column_list $part02 $part1_N $part2_Y $part3_Y ; +--error ER_PARSE_ERROR +eval $part01 $column_list $part02 $part1_Y $part2_N $part3_N ; +--error ER_PARSE_ERROR +eval $part01 $column_list $part02 $part1_Y $part2_N $part3_Y ; +--error ER_PARSE_ERROR +eval $part01 $column_list $part02 $part1_Y $part2_Y $part3_N ; +eval $part01 $column_list $part02 $part1_Y $part2_Y $part3_Y ; +--source suite/parts/inc/partition_layout_check1.inc +DROP TABLE t1; + +--echo #------------------------------------------------------------------------ +--echo # 4.2 partition/subpartition numbers good and bad values and notations +--echo #------------------------------------------------------------------------ +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings +--echo # 4.2.1 partition/subpartition numbers INTEGER notation +# mleich: "positive/negative" is my private judgement. It need not to +# correspond with the server response. +# (positive) number = 2 +let $part_number= 2; +--source suite/parts/inc/partition_syntax_1.inc +# (positive) special case number = 1 +let $part_number= 1; +--source suite/parts/inc/partition_syntax_1.inc +# (negative) 0 is non sense +let $part_number= 0; +--source suite/parts/inc/partition_syntax_1.inc +# (negative) -1 is non sense +let $part_number= -1; +--source suite/parts/inc/partition_syntax_1.inc +# (negative) 1000000 is too huge +let $part_number= 1000000; +--source suite/parts/inc/partition_syntax_1.inc + +--echo # 4.2.2 partition/subpartition numbers DECIMAL notation +# (positive) number = 2.0 +let $part_number= 2.0; +--source suite/parts/inc/partition_syntax_1.inc +# (negative) -2.0 is non sense +let $part_number= -2.0; +--source suite/parts/inc/partition_syntax_1.inc +# (negative) case number = 0.0 is non sense +let $part_number= 0.0; +--source suite/parts/inc/partition_syntax_1.inc +# Bug#15890 Partitions: Strange interpretation of partition number +# (negative) number = 1.6 is non sense +let $part_number= 1.6; +--source suite/parts/inc/partition_syntax_1.inc +# (negative) number is too huge +let $part_number= 999999999999999999999999999999.999999999999999999999999999999; +--source suite/parts/inc/partition_syntax_1.inc +# (negative) number is nearly zero +let $part_number= 0.000000000000000000000000000001; +--source suite/parts/inc/partition_syntax_1.inc + +--echo # 4.2.3 partition/subpartition numbers FLOAT notation +##### FLOAT notation +# (positive) number = 2.0E+0 +let $part_number= 2.0E+0; +--source suite/parts/inc/partition_syntax_1.inc +# Bug#15890 Partitions: Strange interpretation of partition number +# (positive) number = 0.2E+1 +let $part_number= 0.2E+1; +--source suite/parts/inc/partition_syntax_1.inc +# (negative) -2.0E+0 is non sense +let $part_number= -2.0E+0; +--source suite/parts/inc/partition_syntax_1.inc +# Bug#15890 Partitions: Strange interpretation of partition number +# (negative) 0.16E+1 is non sense +let $part_number= 0.16E+1; +--source suite/parts/inc/partition_syntax_1.inc +# (negative) 0.0E+300 is zero +let $part_number= 0.0E+300; +--source suite/parts/inc/partition_syntax_1.inc +# Bug#15890 Partitions: Strange interpretation of partition number +# (negative) 1E+300 is too huge +let $part_number= 1E+300; +--source suite/parts/inc/partition_syntax_1.inc +# (negative) 1E-300 is nearly zero +let $part_number= 1E-300; +--source suite/parts/inc/partition_syntax_1.inc + +--echo # 4.2.4 partition/subpartition numbers STRING notation +##### STRING notation +# (negative?) case number = '2' +let $part_number= '2'; +--source suite/parts/inc/partition_syntax_1.inc +# (negative?) case number = '2.0' +let $part_number= '2.0'; +--source suite/parts/inc/partition_syntax_1.inc +# (negative?) case number = '0.2E+1' +let $part_number= '0.2E+1'; +--source suite/parts/inc/partition_syntax_1.inc +# (negative) Strings starts with digit, but 'A' follows +let $part_number= '2A'; +--source suite/parts/inc/partition_syntax_1.inc +# (negative) Strings starts with 'A', but digit follows +let $part_number= 'A2'; +--source suite/parts/inc/partition_syntax_1.inc +# (negative) empty string +let $part_number= ''; +--source suite/parts/inc/partition_syntax_1.inc +# (negative) string without any digits +let $part_number= 'GARBAGE'; +--source suite/parts/inc/partition_syntax_1.inc + +--echo # 4.2.5 partition/subpartition numbers other notations +# (negative) Strings starts with digit, but 'A' follows +let $part_number= 2A; +--source suite/parts/inc/partition_syntax_1.inc +# (negative) Strings starts with 'A', but digit follows +let $part_number= A2; +--source suite/parts/inc/partition_syntax_1.inc +# (negative) string without any digits +let $part_number= GARBAGE; +--source suite/parts/inc/partition_syntax_1.inc + +# (negative?) double quotes +let $part_number= "2"; +--source suite/parts/inc/partition_syntax_1.inc +# (negative) Strings starts with digit, but 'A' follows +let $part_number= "2A"; +--source suite/parts/inc/partition_syntax_1.inc +# (negative) Strings starts with 'A', but digit follows +let $part_number= "A2"; +--source suite/parts/inc/partition_syntax_1.inc +# (negative) string without any digits +let $part_number= "GARBAGE"; +--source suite/parts/inc/partition_syntax_1.inc + +--echo # 4.2.6 (negative) partition/subpartition numbers per @variables +SET @aux = 5; +--error ER_PARSE_ERROR +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY HASH(f_int1) PARTITIONS @aux; +--error ER_PARSE_ERROR +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY RANGE(f_int1) SUBPARTITION BY HASH(f_int1) +SUBPARTITIONS @aux = 5 +(PARTITION part1 VALUES LESS THAN ($max_row_div2), + PARTITION part2 VALUES LESS THAN $MAX_VALUE); + + +--echo #------------------------------------------------------------------------ +--echo # 4.3 Mixups of assigned partition/subpartition numbers and names +--echo #------------------------------------------------------------------------ +--echo # 4.3.1 (positive) number of partition/subpartition +--echo # = number of named partition/subpartition +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY HASH(f_int1) PARTITIONS 2 ( PARTITION part1, PARTITION part2 ) ; +--source suite/parts/inc/partition_layout_check1.inc +DROP TABLE t1; +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY RANGE(f_int1) PARTITIONS 2 +SUBPARTITION BY HASH(f_int1) SUBPARTITIONS 2 +( PARTITION part1 VALUES LESS THAN (1000) + (SUBPARTITION subpart11, SUBPARTITION subpart12), + PARTITION part2 VALUES LESS THAN $MAX_VALUE + (SUBPARTITION subpart21, SUBPARTITION subpart22) +); +--source suite/parts/inc/partition_layout_check1.inc +DROP TABLE t1; +--echo # 4.3.2 (positive) number of partition/subpartition , +--echo # 0 (= no) named partition/subpartition +--echo # already checked above +--echo # 4.3.3 (negative) number of partitions/subpartitions +--echo # > number of named partitions/subpartitions +--error ER_PARSE_ERROR +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY HASH(f_int1) PARTITIONS 2 ( PARTITION part1 ) ; +# Wrong number of named subpartitions in first partition +--error ER_PARSE_ERROR +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY RANGE(f_int1) +SUBPARTITION BY HASH(f_int1) SUBPARTITIONS 2 +( PARTITION part1 VALUES LESS THAN (1000) + (SUBPARTITION subpart11 ), + PARTITION part2 VALUES LESS THAN $MAX_VALUE + (SUBPARTITION subpart21, SUBPARTITION subpart22) +); +# Wrong number of named subpartitions in non first/non last partition +--error ER_PARSE_ERROR +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY RANGE(f_int1) +SUBPARTITION BY HASH(f_int1) SUBPARTITIONS 2 +( PARTITION part1 VALUES LESS THAN (1000) + (SUBPARTITION subpart11, SUBPARTITION subpart12), + PARTITION part2 VALUES LESS THAN (2000) + (SUBPARTITION subpart21 ), + PARTITION part3 VALUES LESS THAN $MAX_VALUE + (SUBPARTITION subpart31, SUBPARTITION subpart32) +); +# Wrong number of named subpartitions in last partition +--error ER_PARSE_ERROR +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY RANGE(f_int1) PARTITIONS 2 +SUBPARTITION BY HASH(f_int1) SUBPARTITIONS 2 +( PARTITION part1 VALUES LESS THAN (1000) + (SUBPARTITION subpart11, SUBPARTITION subpart12), + PARTITION part2 VALUES LESS THAN $MAX_VALUE + (SUBPARTITION subpart21 ) +); +--echo # 4.3.4 (negative) number of partitions < number of named partitions +--error ER_PARSE_ERROR +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY HASH(f_int1) PARTITIONS 1 ( PARTITION part1, PARTITION part2 ) ; +# Wrong number of named subpartitions in first partition +--error ER_PARSE_ERROR +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY RANGE(f_int1) +SUBPARTITION BY HASH(f_int1) SUBPARTITIONS 1 +( PARTITION part1 VALUES LESS THAN (1000) + (SUBPARTITION subpart11, SUBPARTITION subpart12), + PARTITION part2 VALUES LESS THAN $MAX_VALUE + (SUBPARTITION subpart21, SUBPARTITION subpart22) +); +# Wrong number of named subpartitions in non first/non last partition +--error ER_PARSE_ERROR +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY RANGE(f_int1) +SUBPARTITION BY HASH(f_int1) SUBPARTITIONS 1 +( PARTITION part1 VALUES LESS THAN (1000) + (SUBPARTITION subpart11, SUBPARTITION subpart12), + PARTITION part2 VALUES LESS THAN (2000) + (SUBPARTITION subpart21 ), + PARTITION part3 VALUES LESS THAN $MAX_VALUE + (SUBPARTITION subpart31, SUBPARTITION subpart32) +); +# Wrong number of named subpartitions in last partition +--error ER_PARSE_ERROR +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY RANGE(f_int1) +SUBPARTITION BY HASH(f_int1) SUBPARTITIONS 1 +( PARTITION part1 VALUES LESS THAN (1000) + (SUBPARTITION subpart11, SUBPARTITION subpart12), + PARTITION part2 VALUES LESS THAN $MAX_VALUE + (SUBPARTITION subpart21, SUBPARTITION subpart22) +); + + +--echo +--echo #======================================================================== +--echo # 5. Checks of logical partition/subpartition name +--echo # file name clashes during CREATE TABLE +--echo #======================================================================== +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +--echo #------------------------------------------------------------------------ +--echo # 5.1 (negative) A partition/subpartition name used more than once +--echo #------------------------------------------------------------------------ +--echo # 5.1.1 duplicate partition name +--error ER_SAME_NAME_PARTITION +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY HASH(f_int1) (PARTITION part1, PARTITION part1); +# +--echo # 5.1.2 duplicate subpartition name +# Bug#15408 Partitions: subpartition names are not unique +--error ER_SAME_NAME_PARTITION +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY RANGE(f_int1) +SUBPARTITION BY HASH(f_int1) +( PARTITION part1 VALUES LESS THAN (1000) + (SUBPARTITION subpart11, SUBPARTITION subpart11) +); + +# FIXME Implement testcases with filename problems +# existing file of other table --- partition/subpartition file name +# partition/subpartition file name --- file of the same table + diff --git a/mysql-test/suite/parts/inc/partition_syntax_1.inc b/mysql-test/suite/parts/inc/partition_syntax_1.inc new file mode 100644 index 00000000..a7168b6a --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_syntax_1.inc @@ -0,0 +1,85 @@ +################################################################################ +# inc/partition_syntax_1.inc # +# # +# Purpose: # +# Auxiliary script, only useful when sourced by inc/partition_syntax.inc # +# # +# Try to create a table with number of partitions/subpartitions # +# = $part_number. Print the layout of the table and drop it. # +# # +# The parameter $part_number must be set before sourcing this script. # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-03-05 # +# Change Author: mleich # +# Change Date: 2007-10-08 # +# Change: Fix for # +# Bug#31481 test suite parts: Many tests fail because of # +# changed server error codes # +################################################################################ + +--disable_abort_on_error +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY HASH(f_int1) PARTITIONS $part_number; +--enable_abort_on_error +--disable_query_log +eval SET @my_errno= $mysql_errno ; +let $run= `SELECT @my_errno = 0`; +# Expected error codes are +# 0, ER_PARSE_ERROR (Reason: assign -1 partitions), ER_TOO_MANY_PARTITIONS_ERROR +# and ER_NO_PARTS_ERROR +if (`SELECT @my_errno NOT IN (0,$ER_PARSE_ERROR,$ER_TOO_MANY_PARTITIONS_ERROR, + $ER_NO_PARTS_ERROR)`) +{ + --echo # The last command got an unexepected error response. + --echo # Expected/handled SQL codes are 0,$ER_PARSE_ERROR,$ER_TOO_MANY_PARTITIONS_ERROR,$ER_NO_PARTS_ERROR + SELECT '# SQL code we got was: ' AS "", @my_errno AS ""; + --echo # Sorry, have to abort. + exit; + --echo +} +--enable_query_log +# +# If this operation was successfull, print layout + drop this table +if ($run) +{ + --source suite/parts/inc/partition_layout_check1.inc + eval DROP TABLE t1; +} +#### Try to create a table with the given subpartition number +--disable_abort_on_error +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY RANGE(f_int1) SUBPARTITION BY HASH(f_int1) +SUBPARTITIONS $part_number +(PARTITION part1 VALUES LESS THAN ($max_row_div2), + PARTITION part2 VALUES LESS THAN $MAX_VALUE); +--enable_abort_on_error +--disable_query_log +eval SET @my_errno= $mysql_errno ; +let $run= `SELECT @my_errno = 0`; +# Expected error codes are +# 0, ER_PARSE_ERROR (Reason: assign -1 partitions), ER_TOO_MANY_PARTITIONS_ERROR +# and ER_NO_PARTS_ERROR +if (`SELECT @my_errno NOT IN (0,$ER_PARSE_ERROR,$ER_TOO_MANY_PARTITIONS_ERROR, + $ER_NO_PARTS_ERROR)`) +{ + --echo # The last command got an unexepected error response. + --echo # Expected/handled SQL codes are 0,$ER_PARSE_ERROR,$ER_TOO_MANY_PARTITIONS_ERROR,$ER_NO_PARTS_ERROR + SELECT '# SQL code we got was: ' AS "", @my_errno AS ""; + --echo # Sorry, have to abort. + exit; + --echo +} +--enable_query_log +# +# If this operation was successfull, print layout + drop this table +if ($run) +{ + --source suite/parts/inc/partition_layout_check1.inc + eval DROP TABLE t1; +} diff --git a/mysql-test/suite/parts/inc/partition_syntax_2.inc b/mysql-test/suite/parts/inc/partition_syntax_2.inc new file mode 100644 index 00000000..f7e201bb --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_syntax_2.inc @@ -0,0 +1,26 @@ +################################################################################ +# inc/partition_syntax_2.inc # +# # +# Purpose: # +# Auxiliary script, only useful when sourced by inc/partition_syntax.inc. # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-05-11 # +# Change Author: # +# Change Date: # +# Change: # +################################################################################ + + --error ER_UNIQUE_KEY_NEED_ALL_FIELDS_IN_PF + eval CREATE TABLE t1 ( + $column_list, + $unique_index + ) + $partition_scheme; + --error ER_UNIQUE_KEY_NEED_ALL_FIELDS_IN_PF + eval CREATE TABLE t1 ( + $column_list, + PRIMARY KEY(f_int1,f_int2), $unique_index + ) + $partition_scheme; diff --git a/mysql-test/suite/parts/inc/partition_text.inc b/mysql-test/suite/parts/inc/partition_text.inc new file mode 100644 index 00000000..f7660277 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_text.inc @@ -0,0 +1,45 @@ +--echo ---- Partitioning and text data type + +--error ER_BLOB_FIELD_IN_PART_FUNC_ERROR +eval create table t1 (a text not null, primary key(a(767))) engine=$engine +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); + +#show create table t1; +#insert into t1 values (repeat('a',1000)), ('b'), (repeat('a',500)), (repeat('b',64)); +#select * from t1; +#select * from t1 where a='b'; +#update t1 set a='bb' where a='b'; +#delete from t1 where a='bb'; +#select * from t1; +#drop table t1; + +--error ER_BLOB_FIELD_IN_PART_FUNC_ERROR +eval create table t2 (a tinytext not null, primary key(a(767))) engine=$engine +partition by key (a) partitions 30; + +--error ER_BLOB_FIELD_IN_PART_FUNC_ERROR +eval create table t2 (a mediumtext not null, primary key(a(767))) engine=$engine +partition by key (a) partitions 30; + +--error ER_BLOB_FIELD_IN_PART_FUNC_ERROR +eval create table t2 (a longtext not null, primary key(a(767))) engine=$engine +partition by key (a) partitions 30; + +#show create table t2; +#let $count=30; +#let $letter=0; +#--echo $count inserts; +#--disable_query_log +#while ($count) +#{ +#eval insert into t2 values (repeat(char(ascii('a')+$letter),$count*$count)); +#dec $count; +#inc $letter; +#} +#select count(*) from t2; +#select * from t2; +#drop table t2; diff --git a/mysql-test/suite/parts/inc/partition_time.inc b/mysql-test/suite/parts/inc/partition_time.inc new file mode 100644 index 00000000..674fe546 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_time.inc @@ -0,0 +1,85 @@ +eval create table t1 (a time not null, primary key(a)) engine=$engine +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +insert into t1 values ('21:21:21'), ('12:10:30'), ('03:03:03'), ('23:59'); +select * from t1; +select * from t1 where a=030303; +delete from t1 where a=030303; +select * from t1; +drop table t1; + +eval create table t2 (a time not null, primary key(a)) engine=$engine +partition by key (a) partitions 12; +show create table t2; +insert into t2 values ('0:1:1'), ('10:11:12'), ('13:14:15'), ('14:15:16'); +select * from t2; +select * from t2 where a='13:14:15'; +delete from t2 where a='13:14:15'; +select * from t2; +delete from t2; +let $count=59; +--echo $count inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t2 values (000100+$count); +dec $count; +} +commit; +--enable_query_log +select count(*) from t2; +select * from t2; +drop table t2; + +eval create table t3 (a time not null, primary key(a)) engine=$engine +partition by range (second(a)) subpartition by key (a) +subpartitions 3 ( +partition quarter1 values less than (16), +partition quarter2 values less than (31), +partition quarter3 values less than (46), +partition quarter4 values less than (61) +); +show create table t3; +let $count=59; +--echo $count inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t3 values (100000+$count); +dec $count; +} +commit; +--enable_query_log +select count(*) from t3; +select * from t3; +drop table t3; + +eval create table t4 (a time not null, primary key(a)) engine=$engine +partition by list (second(a)) subpartition by key (a) +subpartitions 3 ( +partition quarter1 values in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15), +partition quarter2 values in (16,17,18,19,20,21,22,23,24,25,26,27,28,29,30), +partition quarter3 values in (31,32,33,34,35,36,37,38,39,40,41,42,43,44,45), +partition quarter4 values in (46,47,48,49,50,51,52,53,54,55,56,57,58,59,60) +); +show create table t4; +let $count=59; +--echo $count inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t4 values (100000+$count); +dec $count; +} +commit; +--enable_query_log +select count(*) from t4; +select * from t4; +drop table t4; diff --git a/mysql-test/suite/parts/inc/partition_timestamp.inc b/mysql-test/suite/parts/inc/partition_timestamp.inc new file mode 100644 index 00000000..fb1bf391 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_timestamp.inc @@ -0,0 +1,92 @@ +eval create table t1 (a timestamp not null DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, primary key(a)) engine=$engine +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +insert into t1 values ('1975-01-01 21:21:21'), ('2020-12-31 12:10:30'), ('1980-10-14 03:03'), ('2000-06-15 23:59'); +select * from t1; +select * from t1 where a=19801014030300; +delete from t1 where a=19801014030300; +select * from t1; +drop table t1; + +eval create table t2 (a timestamp not null DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, primary key(a)) engine=$engine +partition by key (a) partitions 12; +show create table t2; +insert into t2 values ('1975-01-01 0:1:1'), ('2020-12-31 10:11:12'), ('1980-10-14 13:14:15'), ('2000-06-15 14:15:16'); +select * from t2; +select * from t2 where a='1980-10-14 13:14:15'; +delete from t2 where a='1980-10-14 13:14:15'; +select * from t2; +delete from t2; +let $count=59; +--echo $count inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t2 values (19710101000000+$count); +dec $count; +} +commit; +--enable_query_log +select count(*) from t2; +select * from t2; +drop table t2; + +################################################################################ +# The following 2 tests are no longer valid after bug #42849 has been fixed: +# it is not possible to use a timezone-dependent (such as month(timestamp_col) +# or just a timestamp_col in a numeric context) anymore. +################################################################################ + +# eval create table t3 (a timestamp not null, primary key(a)) engine=$engine +# partition by range (month(a)) subpartition by key (a) +# subpartitions 3 ( +# partition quarter1 values less than (4), +# partition quarter2 values less than (7), +# partition quarter3 values less than (10), +# partition quarter4 values less than (13) +# ); +# show create table t3; +# let $count=12; +# --echo $count inserts; +# --disable_query_log +# SET TIME_ZONE= '+03:00'; +# begin; +# while ($count) +# { +# eval insert into t3 values (date_add('1970-01-01 00:00:00',interval $count-1 month)); +# dec $count; +# } +# commit; +# --enable_query_log +# select count(*) from t3; +# select * from t3; +# drop table t3; + +# eval create table t4 (a timestamp not null, primary key(a)) engine=$engine +# partition by list (month(a)) subpartition by key (a) +# subpartitions 3 ( +# partition quarter1 values in (0,1,2,3), +# partition quarter2 values in (4,5,6), +# partition quarter3 values in (7,8,9), +# partition quarter4 values in (10,11,12) +# ); +# show create table t4; +# let $count=12; +# --echo $count inserts; +# --disable_query_log +# begin; +# while ($count) +# { +# eval insert into t4 values (date_add('1970-01-01 00:00:00',interval $count-1 month)); +# dec $count; +# } +# commit; +# --enable_query_log +# select count(*) from t4; +# select * from t4; +# drop table t4; diff --git a/mysql-test/suite/parts/inc/partition_tinyint.inc b/mysql-test/suite/parts/inc/partition_tinyint.inc new file mode 100644 index 00000000..9b77c7b3 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_tinyint.inc @@ -0,0 +1,52 @@ +eval create table t1 (a tinyint unsigned not null, primary key(a)) engine=$engine +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +insert into t1 values (255), (254), (253), (252), (1), (2), (128); +--sorted_result +select * from t1; +select * from t1 where a=253; +delete from t1 where a=253; +--sorted_result +select * from t1; +drop table t1; + +eval create table t2 (a tinyint unsigned not null, primary key(a)) engine=$engine +partition by key (a) partitions 8; +show create table t2; +insert into t2 values (255), (254), (253), (252); +--sorted_result +select * from t2; +select * from t2 where a=253; +delete from t2 where a=253; +--sorted_result +select * from t2; +delete from t2; +let $count=255; +--echo 255 inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t2 values ($count); +dec $count; +} +commit; +--enable_query_log +select count(*) from t2; +drop table t2; + +eval create table t3 (a tinyint not null, primary key(a)) engine=$engine +partition by key (a) partitions 7; +show create table t3; +insert into t3 values (127), (126), (125), (124), (-128), (-127), (1), (-1), (0); +--sorted_result +select * from t3; +select * from t3 where a=125; +delete from t3 where a=125; +--sorted_result +select * from t3; +drop table t3; diff --git a/mysql-test/suite/parts/inc/partition_trigg1.inc b/mysql-test/suite/parts/inc/partition_trigg1.inc new file mode 100644 index 00000000..7bb5aa16 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_trigg1.inc @@ -0,0 +1,115 @@ +################################################################################ +# inc/partition_trigg1.inc # +# # +# Purpose: # +# Auxiliary script, only useful when sourced by inc/partition_check.inc. # +# One trigger uses new values (--> event UPDATE, INSERT only) # +# One trigger uses old values (--> event UPDATE, DELETE only) # +# # +# 1. Create a trigger # +# 2. Execute a statement, which activates the trigger # +# 3. Check the results of the trigger activity # +# 4. Revert the modifications # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-03-05 # +# Change Author: # +# Change Date: # +# Change: # +################################################################################ + +# Test for operations, which have new values (INSERT+UPDATE, but not DELETE) +if ($no_debug) +{ + --disable_query_log +} +eval SELECT INSTR('$statement','DELETE') = 0 INTO @aux; +let $run1= `SELECT @aux`; +--enable_query_log +if ($run1) +{ + # Insert three records which are only needed for UPDATE TRIGGER test + eval INSERT INTO $tab_has_trigg(f_int1,f_int2,f_char1,f_char2,f_charbig) + SELECT -f_int1,-f_int1,CAST(-f_int1 AS CHAR),CAST(-f_int1 AS CHAR), + 'just inserted' FROM t0_template + WHERE f_int1 BETWEEN @max_row_div2 - 1 AND @max_row_div2 + 1; + delimiter |; + eval CREATE TRIGGER trg_1 $event ON $tab_has_trigg FOR EACH ROW + BEGIN + UPDATE $tab_in_trigg SET f_int1 = -f_int1, f_int2 = -f_int2, + f_charbig = 'updated by trigger' + WHERE f_int1 = new.f_int1; + END| + delimiter ;| + + eval $statement; + + # Check of preceding statement via Select + if ($no_debug) + { + --disable_query_log + } + eval SELECT '# check trigger-$num success: ' AS "", COUNT(*) = 3 AS "" + FROM $tab_in_trigg + WHERE f_int1 = f_int2 AND CAST(f_char1 AS SIGNED INT) = -f_int1; + --enable_query_log + + DROP TRIGGER trg_1; + + # Revert the changes + eval UPDATE $tab_in_trigg SET f_int1 = CAST(f_char1 AS SIGNED INT), + f_int2 = CAST(f_char1 AS SIGNED INT), + f_charbig = 'just inserted' + WHERE f_int1 <> CAST(f_char1 AS SIGNED INT); + eval DELETE FROM $tab_has_trigg + WHERE ABS(f_int1) BETWEEN @max_row_div2 - 1 AND @max_row_div2 + 1; + inc $num; +} + +# Test for operations, which have old values (UPDATE+DELETE, but not INSERT) +if ($no_debug) +{ + --disable_query_log +} +eval SELECT INSTR('$statement','INSERT') = 0 INTO @aux; +let $run1= `SELECT @aux`; +--enable_query_log +if ($run1) +{ + # Insert three records which are only needed for UPDATE/DELETE TRIGGER test + eval INSERT INTO $tab_has_trigg(f_int1,f_int2,f_char1,f_char2,f_charbig) + SELECT -f_int1,-f_int1,CAST(-f_int1 AS CHAR),CAST(-f_int1 AS CHAR), + 'just inserted' FROM t0_template + WHERE f_int1 BETWEEN @max_row_div2 - 1 AND @max_row_div2 + 1; + + delimiter |; + eval CREATE TRIGGER trg_1 $event ON $tab_has_trigg FOR EACH ROW + BEGIN + UPDATE $tab_in_trigg SET f_int1 = -f_int1, f_int2 = -f_int2, + f_charbig = 'updated by trigger' + WHERE f_int1 = - old.f_int1; + END| + delimiter ;| + + eval $statement; + + # Check of preceding statement via Select + if ($no_debug) + { + --disable_query_log + } + eval SELECT '# check trigger-$num success: ' AS "", COUNT(*) = 3 AS "" + FROM $tab_in_trigg + WHERE f_int1 = f_int2 AND CAST(f_char1 AS SIGNED INT) = -f_int1; + --enable_query_log + DROP TRIGGER trg_1; + # Revert the changes + eval UPDATE $tab_in_trigg SET f_int1 = CAST(f_char1 AS SIGNED INT), + f_int2 = CAST(f_char1 AS SIGNED INT), + f_charbig = 'just inserted' + WHERE f_int1 <> CAST(f_char1 AS SIGNED INT); + eval DELETE FROM $tab_has_trigg + WHERE ABS(f_int1) BETWEEN @max_row_div2 - 1 AND @max_row_div2 + 1; + inc $num; +} diff --git a/mysql-test/suite/parts/inc/partition_trigg2.inc b/mysql-test/suite/parts/inc/partition_trigg2.inc new file mode 100644 index 00000000..2849ca21 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_trigg2.inc @@ -0,0 +1,45 @@ +################################################################################ +# inc/partition_trigg2.inc # +# # +# Purpose: # +# Auxiliary script, only useful when sourced by inc/partition_check.inc. # +# The trigger uses new values (--> event UPDATE, INSERT only) # +# # +# 1. Create a trigger # +# 2. Execute a statement, which activates the trigger # +# 3. Check the results of the trigger activity # +# 4. Revert the modifications # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-03-05 # +# Change Author: # +# Change Date: # +# Change: # +################################################################################ + +delimiter |; +eval CREATE TRIGGER trg_2 $event ON t1 FOR EACH ROW +BEGIN + SET new.f_int1 = $source.f_int1 + @max_row, + new.f_int2 = $source.f_int2 - @max_row, + new.f_charbig = '####updated per update trigger####'; +END| +delimiter ;| +eval $statement; +# Check of preceding statement via Select +if ($no_debug) +{ + --disable_query_log +} +eval SELECT '# check trigger-$num success: ' AS "", COUNT(*) = 0 AS "" FROM t1 +WHERE f_int1 - CAST(f_char1 AS SIGNED INT) NOT IN (@max_row, 2 * @max_row) + OR f_int2 - CAST(f_char1 AS SIGNED INT) NOT IN (-@max_row, - 2 * @max_row) + OR f_charbig <> '####updated per update trigger####'; +--enable_query_log +DROP TRIGGER trg_2; +# Revert the changes +eval UPDATE t1 SET f_int1 = CAST(f_char1 AS SIGNED INT), + f_int2 = CAST(f_char1 AS SIGNED INT), + f_charbig = CONCAT('===',f_char1,'==='); +inc $num; diff --git a/mysql-test/suite/parts/inc/partition_trigg3.inc b/mysql-test/suite/parts/inc/partition_trigg3.inc new file mode 100644 index 00000000..34dbf4e2 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_trigg3.inc @@ -0,0 +1,69 @@ +################################################################################ +# inc/partition_trigg3.inc # +# # +# Purpose: # +# Auxiliary script, only useful when sourced by inc/partition_check.inc. # +# The trigger uses new values (--> event UPDATE, INSERT only) # +# # +# 1. Create a trigger # +# 2. Execute a statement, which activates the trigger # +# 3. Check the results of the trigger activity # +# 4. Revert the modifications # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-03-05 # +# Change Author: # +# Change Date: # +# Change: # +################################################################################ + +delimiter |; +# Original version of the trigger +# eval CREATE TRIGGER trg_3 $event ON t1 FOR EACH ROW +# BEGIN +# SET @counter = 1; +# SET @my_max1 = 0, @my_max2 = 0; +# SELECT MAX(f_int1), MIN(f_int2) INTO @my_max1,@my_min2 FROM t1; +# SET new.f_int1 = @my_max1 + @counter, +# new.f_int2 = @my_min2 - @counter, +# new.f_charbig = '####updated per insert trigger####'; +# SET @counter = @counter + 1; +# END| +# +# Bug/currently undocumented limitation: +# 17704: Triggers: MAX, Insert select with several rows, strange error +# "A trigger can not access (not even read data) the table it's defined for." +# +eval CREATE TRIGGER trg_3 $event ON t1 FOR EACH ROW +BEGIN + SET new.f_int1 = @my_max1 + @counter, + new.f_int2 = @my_min2 - @counter, + new.f_charbig = '####updated per insert trigger####'; + SET @counter = @counter + 1; +END| +delimiter ;| +# Additional statements because of Bug(limitation)#17704 +SET @counter = 1; +# Bug#18730 Partitions: crash on SELECT MIN(<unique column>) +SELECT MAX(f_int1), MIN(f_int2) INTO @my_max1,@my_min2 FROM t1; +# Additional statements end +eval $statement; +DROP TRIGGER trg_3; +# Check of preceding statement via Select +if ($no_debug) +{ + --disable_query_log +} +# We insert records around max_row_div2 ! +eval SELECT '# check trigger-$num success: ' AS "", COUNT(*) = 3 AS "" FROM t1 +WHERE f_int1 = CAST(f_char1 AS SIGNED INT) + @max_row_div2 + 2 + AND f_int2 = - CAST(f_char1 AS SIGNED INT) + @max_row_div2 - 1 + AND f_charbig = '####updated per insert trigger####'; +--enable_query_log +# Revert the changes +eval DELETE FROM t1 +WHERE f_int1 <> CAST(f_char1 AS SIGNED INT) + AND f_int2 <> CAST(f_char1 AS SIGNED INT) + AND f_charbig = '####updated per insert trigger####'; +inc $num; diff --git a/mysql-test/suite/parts/inc/partition_value.inc b/mysql-test/suite/parts/inc/partition_value.inc new file mode 100644 index 00000000..79c4d6b8 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_value.inc @@ -0,0 +1,163 @@ +################################################################################ +# inc/partition_value.inc # +# # +# Purpose: # +# Tests around "exotic" values calculated by the partitioning function # +# # +#------------------------------------------------------------------------------# +# Original Author: mleich # +# Original Date: 2006-04-11 # +# Change Author: # +# Change Date: # +# Change: # +################################################################################ + + +--echo +--echo This test relies on the CAST() function for partitioning, which +--echo is not allowed. Not deleting it yet, as it may have some useful +--echo bits in it. See Bug #30581, "partition_value tests use disallowed +--echo CAST() function" +--echo + +--disable_parsing + +--echo +--echo #======================================================================== +--echo # Calculation of "exotic" results within the partition function +--echo # outside of SIGNED BIGINT value range, 0, NULL +--echo # column used in partitioning function has type CHAR +--echo #======================================================================== +--echo # 1. HASH(<check value>) +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings +# +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY HASH(CAST(f_char1 AS SIGNED INTEGER) * CAST(5.0E+18 AS SIGNED INTEGER)) PARTITIONS 8; +let $my_val= 2147483646; +eval INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +VALUES($my_val,$my_val,'$my_val','$my_val','#$my_val#'); +eval SELECT COUNT(*) = 1 FROM t1 WHERE f_char1 = '$my_val'; +let $my_val= -2147483646; +eval INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +VALUES($my_val,$my_val,'$my_val','$my_val','#$my_val#'); +eval SELECT COUNT(*) = 1 FROM t1 WHERE f_char1 = '$my_val'; +let $my_val= 0; +eval INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +VALUES($my_val,$my_val,'$my_val','$my_val','#$my_val#'); +eval SELECT COUNT(*) = 1 FROM t1 WHERE f_char1 = '$my_val'; +# let $my_val= NULL; +eval INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +VALUES(NULL,NULL,NULL,NULL,NULL); +eval SELECT COUNT(*) = 1 FROM t1 WHERE f_char1 IS NULL; +DROP TABLE t1; +# +--echo # 2. RANGE(<check value>) +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY RANGE(CAST(f_char1 AS SIGNED INTEGER) * CAST(5.0E+18 AS SIGNED INTEGER)) +(PARTITION p0 VALUES LESS THAN (0), + PARTITION p1 VALUES LESS THAN (1000000), + PARTITION p2 VALUES LESS THAN MAXVALUE); +let $my_val= 2147483646; +eval INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +VALUES($my_val,$my_val,'$my_val','$my_val','#$my_val#'); +eval SELECT COUNT(*) = 1 FROM t1 WHERE f_char1 = '$my_val'; +let $my_val= -2147483646; +eval INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +VALUES($my_val,$my_val,'$my_val','$my_val','#$my_val#'); +eval SELECT COUNT(*) = 1 FROM t1 WHERE f_char1 = '$my_val'; +let $my_val= 0; +eval INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +VALUES($my_val,$my_val,'$my_val','$my_val','#$my_val#'); +eval SELECT COUNT(*) = 1 FROM t1 WHERE f_char1 = '$my_val'; +# let $my_val= NULL; +eval INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +VALUES(NULL,NULL,NULL,NULL,NULL); +eval SELECT COUNT(*) = 1 FROM t1 WHERE f_char1 IS NULL; +DROP TABLE t1; +--echo # 3. LIST(<check value>) +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY LIST(CAST(f_char1 AS SIGNED INTEGER) * CAST(5.0E+18 AS SIGNED INTEGER)) +(PARTITION p0 VALUES IN (0), + PARTITION p1 VALUES IN (NULL), + PARTITION p2 VALUES IN (CAST( 2147483646 AS SIGNED INTEGER) * CAST(5.0E+18 AS SIGNED INTEGER)), + PARTITION p3 VALUES IN (CAST(-2147483646 AS SIGNED INTEGER) * CAST(5.0E+18 AS SIGNED INTEGER))); +let $my_val= 2147483646; +eval INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +VALUES($my_val,$my_val,'$my_val','$my_val','#$my_val#'); +eval SELECT COUNT(*) = 1 FROM t1 WHERE f_char1 = '$my_val'; +let $my_val= -2147483646; +eval INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +VALUES($my_val,$my_val,'$my_val','$my_val','#$my_val#'); +eval SELECT COUNT(*) = 1 FROM t1 WHERE f_char1 = '$my_val'; +let $my_val= 0; +eval INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +VALUES($my_val,$my_val,'$my_val','$my_val','#$my_val#'); +eval SELECT COUNT(*) = 1 FROM t1 WHERE f_char1 = '$my_val'; +# let $my_val= NULL; +eval INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +VALUES(NULL,NULL,NULL,NULL,NULL); +eval SELECT COUNT(*) = 1 FROM t1 WHERE f_char1 IS NULL; +DROP TABLE t1; +# +--echo # 4. Partition by RANGE(...) subpartition by HASH(<check value>) +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY RANGE(CAST(f_char1 AS SIGNED INTEGER)) +SUBPARTITION BY HASH(CAST(f_char2 AS SIGNED INTEGER) * CAST(5.0E+18 AS SIGNED INTEGER)) SUBPARTITIONS 4 +(PARTITION p0 VALUES LESS THAN (0), + PARTITION p1 VALUES LESS THAN MAXVALUE); +let $my_val= 2147483646; +eval INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +VALUES($my_val,$my_val,'1','$my_val','#$my_val#'); +eval SELECT COUNT(*) = 1 FROM t1 WHERE f_char2 = '$my_val'; +let $my_val= -2147483646; +eval INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +VALUES($my_val,$my_val,'-1','$my_val','#$my_val#'); +eval SELECT COUNT(*) = 1 FROM t1 WHERE f_char2 = '$my_val'; +let $my_val= 0; +eval INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +VALUES($my_val,$my_val,'$my_val','$my_val','#$my_val#'); +eval SELECT COUNT(*) = 1 FROM t1 WHERE f_char2 = '$my_val'; +# let $my_val= NULL; +eval INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +VALUES(NULL,NULL,NULL,NULL,NULL); +eval SELECT COUNT(*) = 1 FROM t1 WHERE f_char2 IS NULL; +DROP TABLE t1; +# +--echo # 5. Partition by LIST(...) subpartition by HASH(<check value>) +eval CREATE TABLE t1 ( +$column_list +) +PARTITION BY LIST(CAST(f_char1 AS SIGNED INTEGER)) +SUBPARTITION BY HASH(CAST(f_char2 AS SIGNED INTEGER) * CAST(5.0E+18 AS SIGNED INTEGER)) SUBPARTITIONS 4 +(PARTITION p0 VALUES IN (NULL), + PARTITION p1 VALUES IN (1)); +let $my_val= 2147483646; +eval INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +VALUES($my_val,$my_val,'1','$my_val','#$my_val#'); +eval SELECT COUNT(*) = 1 FROM t1 WHERE f_char2 = '$my_val'; +let $my_val= -2147483646; +eval INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +VALUES($my_val,$my_val,'1','$my_val','#$my_val#'); +eval SELECT COUNT(*) = 1 FROM t1 WHERE f_char2 = '$my_val'; +let $my_val= 0; +eval INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +VALUES($my_val,$my_val,'1','$my_val','#$my_val#'); +eval SELECT COUNT(*) = 1 FROM t1 WHERE f_char2 = '$my_val'; +# let $my_val= NULL; +eval INSERT INTO t1(f_int1,f_int2,f_char1,f_char2,f_charbig) +VALUES(NULL,NULL,NULL,NULL,NULL); +eval SELECT COUNT(*) = 1 FROM t1 WHERE f_char2 IS NULL; +DROP TABLE t1; +# + +--enable_parsing diff --git a/mysql-test/suite/parts/inc/partition_varbinary.inc b/mysql-test/suite/parts/inc/partition_varbinary.inc new file mode 100644 index 00000000..292407cd --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_varbinary.inc @@ -0,0 +1,98 @@ +--echo ---- Partitioning and varbinary data type + +eval create table t1 (a varbinary(767) not null, primary key(a)) engine=$engine +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +insert into t1 values (repeat('a',767)), ('b'), (repeat('a',500)), (repeat('b',64)); +--sorted_result +select * from t1; +select * from t1 where a='b'; +update t1 set a='bb' where a='b'; +delete from t1 where a='bb'; +--sorted_result +select * from t1; +drop table t1; + +eval create table t2 (a varbinary(767) not null, primary key(a)) engine=$engine +partition by key (a) partitions 30; +show create table t2; +let $count=26; +let $letter=0; +--echo $count inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t2 values (repeat(char(ascii('a')+$letter),$count*$count)); +dec $count; +inc $letter; +} +commit; +--enable_query_log +select count(*) from t2; +--sorted_result +select * from t2; +drop table t2; + + +if (0) +{ +eval create table t3 (a varbinary(767) not null, primary key(a)) engine=$engine +partition by range (ascii(a)) subpartition by key (a) subpartitions 4 ( +partition pa16 values less than (16), +partition pa32 values less than (32), +partition pa64 values less than (64), +partition pa128 values less than (128), +partition pa256 values less than (256) +); +show create table t3; +let $count=26; +let $letter=0; +--echo $count inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t3 values (repeat(char(ascii('a')+$letter),$count+54)); +dec $count; +inc $letter; +} +commit; +--enable_query_log +select count(*) from t3; +select hex(a) from t3; +drop table t3; + +eval create table t4 (a varbinary(767) not null, primary key(a)) engine=$engine +partition by list (ascii(a)) subpartition by key (a) subpartitions 4 ( +partition pa16 values in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16), +partition pa32 values in (17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32), +partition pa64 values in (33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64), +partition pa128 values in (65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128), +partition pa256 values in (129,130,131,132,133,134,135,136,137,138,139,140 +,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256) +); +show create table t4; +let $count=26; +let $letter=0; +--echo $count inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t4 values (repeat(char(ascii('a')+$letter),$count+54)); +dec $count; +inc $letter; +} +commit; +--enable_query_log +select count(*) from t4; +select hex(a) from t4; +drop table t4; +} +#if (0) + diff --git a/mysql-test/suite/parts/inc/partition_varchar.inc b/mysql-test/suite/parts/inc/partition_varchar.inc new file mode 100644 index 00000000..257c122d --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_varchar.inc @@ -0,0 +1,97 @@ +--echo ---- Partitioning and varchar data type + +eval create table t1 (a varchar(767) not null, primary key(a)) engine=$engine +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +insert into t1 values (repeat('a',767)), ('b'), (repeat('a',500)), (repeat('b',64)); +--sorted_result +select * from t1; +select * from t1 where a='b'; +update t1 set a='bb' where a='b'; +delete from t1 where a='bb'; +--sorted_result +select * from t1; +drop table t1; + +eval create table t2 (a varchar(767) not null, primary key(a)) engine=$engine +partition by key (a) partitions 27; +show create table t2; +let $count=26; +let $letter=0; +--echo $count inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t2 values (repeat(char(ascii('a')+$letter),$count*$count)); +dec $count; +inc $letter; +} +commit; +--enable_query_log +select count(*) from t2; +--sorted_result +select * from t2; +drop table t2; + +if (0) +{ +eval create table t3 (a varchar(767) not null, primary key(a)) engine=$engine +partition by range (ascii(a)) subpartition by key (a) subpartitions 4 ( +partition pa16 values less than (16), +partition pa32 values less than (32), +partition pa64 values less than (64), +partition pa128 values less than (128), +partition pa256 values less than (256) +); +show create table t3; +let $count=26; +let $letter=0; +--echo $count inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t3 values (repeat(char(ascii('a')+$letter),$count+54)); +dec $count; +inc $letter; +} +commit; +--enable_query_log +select count(*) from t3; +select * from t3; +drop table t3; + +eval create table t4 (a varchar(767) not null, primary key(a)) engine=$engine +partition by list (ascii(a)) subpartition by key (a) subpartitions 4 ( +partition pa16 values in (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16), +partition pa32 values in (17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32), +partition pa64 values in (33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64), +partition pa128 values in (65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128), +partition pa256 values in (129,130,131,132,133,134,135,136,137,138,139,140 +,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256) +); +show create table t4; +let $count=26; +let $letter=0; +--echo $count inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert into t4 values (repeat(char(ascii('a')+$letter),$count+54)); +dec $count; +inc $letter; +} +commit; +--enable_query_log +select count(*) from t4; +select * from t4; +drop table t4; +} +#if (0) + diff --git a/mysql-test/suite/parts/inc/partition_year.inc b/mysql-test/suite/parts/inc/partition_year.inc new file mode 100644 index 00000000..ff221d05 --- /dev/null +++ b/mysql-test/suite/parts/inc/partition_year.inc @@ -0,0 +1,38 @@ +eval create table t1 (a year not null, primary key(a)) engine=$engine +partition by key (a) ( +partition pa1 max_rows=20 min_rows=2, +partition pa2 max_rows=30 min_rows=3, +partition pa3 max_rows=30 min_rows=4, +partition pa4 max_rows=40 min_rows=2); +show create table t1; +insert into t1 values ('1975'), (2020), ('1980'), ('2000'); +select * from t1; +select * from t1 where a=1980; +delete from t1 where a=1980; +select * from t1; +drop table t1; + +eval create table t2 (a year not null, primary key(a)) engine=$engine +partition by key (a) partitions 12; +show create table t2; +insert into t2 values ('1975'), ('2020'), ('1980'), ('2000'); +select * from t2; +select * from t2 where a='1980'; +delete from t2 where a='1980'; +select * from t2; +delete from t2; +let $count=255; +--echo $count inserts; +--disable_query_log +begin; +while ($count) +{ +eval insert ignore into t2 values (1901+$count); +dec $count; +} +commit; +--enable_query_log +select count(*) from t2; +select * from t2; +drop table t2; + |