polardbxengine/mysql-test/suite/innodb/t/innodb-import-partition.test

368 lines
11 KiB
Plaintext

--source include/no_valgrind_without_big.inc
let $partitioning= 1;
--source suite/innodb/include/innodb_import.inc
let MYSQLD_DATADIR =`SELECT @@datadir`;
--echo #
--echo # DISCARD/IMPORT selected partitions only
--echo #
CREATE TABLE t1 (c1 INT) ENGINE = InnoDB
PARTITION BY HASH (c1) PARTITIONS 3;
INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6);
SELECT c1 FROM t1 ORDER BY c1;
FLUSH TABLES t1 FOR EXPORT;
SELECT * FROM t1 ORDER BY c1;
perl;
require 'include/innodb-util.inc';
ib_backup_tablespaces("test", "t1#P#p0", "t1#P#p1", "t1#P#p2");
EOF
UNLOCK TABLES;
DROP TABLE t1;
CREATE TABLE t1 (c1 INT) ENGINE = InnoDB
PARTITION BY HASH (c1) PARTITIONS 3;
INSERT INTO t1 VALUES (31), (32), (33);
ALTER TABLE t1 DISCARD PARTITION p0,p2 TABLESPACE;
perl;
require 'include/innodb-util.inc';
ib_discard_tablespaces("test", "t1#P#p0", "t1#P#p2");
ib_restore_tablespaces("test", "t1#P#p0", "t1#P#p2");
EOF
ALTER TABLE t1 IMPORT PARTITION p0, p2 TABLESPACE;
SELECT * FROM t1 ORDER BY c1;
ALTER TABLE t1 DISCARD PARTITION p1 TABLESPACE;
perl;
require 'include/innodb-util.inc';
ib_discard_tablespaces("test", "t1#P#p1");
ib_restore_tablespaces("test", "t1#P#p1");
EOF
ALTER TABLE t1 IMPORT PARTITION p1 TABLESPACE;
SELECT * FROM t1 ORDER BY c1;
INSERT INTO t1 VALUES (31), (32), (33);
SELECT * FROM t1 ORDER BY c1;
ALTER TABLE t1 DISCARD PARTITION all TABLESPACE;
perl;
require 'include/innodb-util.inc';
ib_discard_tablespaces("test", "t1#P#p0", "t1#P#p1", "t1#P#p2");
ib_restore_tablespaces("test", "t1#P#p0", "t1#P#p1", "t1#P#p2");
EOF
ALTER TABLE t1 IMPORT PARTITION p1 TABLESPACE;
SELECT * FROM t1 PARTITION (p1) ORDER BY c1;
INSERT INTO t1 PARTITION (p1) VALUES (61), (64);
FLUSH TABLES;
SELECT * FROM t1 PARTITION (p1) ORDER BY c1;
--error ER_TABLESPACE_DISCARDED
SELECT * FROM t1 ORDER BY c1;
--error ER_PARSE_ERROR
ALTER TABLE t1 DISCARD PARTITION TABLESPACE;
--error ER_PARSE_ERROR
ALTER TABLE t1 IMPORT PARTITION TABLESPACE;
--error ER_UNKNOWN_PARTITION
ALTER TABLE t1 DISCARD PARTITION pNonExisting TABLESPACE;
--error ER_UNKNOWN_PARTITION
ALTER TABLE t1 IMPORT PARTITION pNonExisting TABLESPACE;
ALTER TABLE t1 DISCARD PARTITION p1 TABLESPACE;
perl;
require 'include/innodb-util.inc';
ib_discard_tablespaces("test", "t1#P#p1");
ib_restore_tablespaces("test", "t1#P#p1");
EOF
ALTER TABLE t1 IMPORT PARTITION all TABLESPACE;
SELECT * FROM t1 ORDER BY c1;
DROP TABLE t1;
--echo #
--echo # DISCARD/IMPORT selected subpartitions only
--echo #
CREATE TABLE t1 (c1 INT) ENGINE = InnoDB
PARTITION BY RANGE (c1)
SUBPARTITION BY HASH (c1) SUBPARTITIONS 3
(PARTITION p0 VALUES LESS THAN (100),
PARTITION p1 VALUES LESS THAN MAXVALUE);
INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6);
INSERT INTO t1 VALUES (101),(102),(103),(104),(105),(106);
SELECT c1 FROM t1 ORDER BY c1;
FLUSH TABLES t1 FOR EXPORT;
SELECT * FROM t1 ORDER BY c1;
perl;
require 'include/innodb-util.inc';
ib_backup_tablespaces("test",
"t1#P#p0#SP#p0sp0", "t1#P#p0#SP#p0sp1", "t1#P#p0#SP#p0sp2",
"t1#P#p1#SP#p1sp0", "t1#P#p1#SP#p1sp1", "t1#P#p1#SP#p1sp2");
EOF
UNLOCK TABLES;
DROP TABLE t1;
CREATE TABLE t1 (c1 INT) ENGINE = InnoDB
PARTITION BY RANGE (c1)
SUBPARTITION BY HASH (c1) SUBPARTITIONS 3
(PARTITION p0 VALUES LESS THAN (100),
PARTITION p1 VALUES LESS THAN MAXVALUE);
INSERT INTO t1 VALUES (31), (32), (33);
INSERT INTO t1 VALUES (131), (132), (133);
ALTER TABLE t1 DISCARD PARTITION p0sp1,p1sp0 TABLESPACE;
perl;
require 'include/innodb-util.inc';
ib_discard_tablespaces("test", "t1#P#p0#SP#p0sp1", "t1#P#p1#SP#p1sp0");
ib_restore_tablespaces("test", "t1#P#p0#SP#p0sp1", "t1#P#p1#SP#p1sp0");
EOF
ALTER TABLE t1 IMPORT PARTITION p0sp1, p1sp0 TABLESPACE;
SELECT * FROM t1 ORDER BY c1;
ALTER TABLE t1 DISCARD PARTITION p1, p0sp2 TABLESPACE;
perl;
require 'include/innodb-util.inc';
ib_discard_tablespaces("test",
"t1#P#p0#SP#p0sp2",
"t1#P#p1#SP#p1sp0", "t1#P#p1#SP#p1sp1", "t1#P#p1#SP#p1sp2");
ib_restore_tablespaces("test",
"t1#P#p0#SP#p0sp2",
"t1#P#p1#SP#p1sp0", "t1#P#p1#SP#p1sp1", "t1#P#p1#SP#p1sp2");
EOF
ALTER TABLE t1 IMPORT PARTITION p0sp2, p1 TABLESPACE;
SELECT * FROM t1 ORDER BY c1;
INSERT INTO t1 VALUES (31), (32), (33);
SELECT * FROM t1 ORDER BY c1;
ALTER TABLE t1 DISCARD PARTITION all TABLESPACE;
perl;
require 'include/innodb-util.inc';
ib_discard_tablespaces("test",
"t1#P#p0#SP#p0sp0", "t1#P#p0#SP#p0sp1", "t1#P#p0#SP#p0sp2",
"t1#P#p1#SP#p1sp0", "t1#P#p1#SP#p1sp1", "t1#P#p1#SP#p1sp2");
ib_restore_tablespaces("test",
"t1#P#p0#SP#p0sp0", "t1#P#p0#SP#p0sp1", "t1#P#p0#SP#p0sp2",
"t1#P#p1#SP#p1sp0", "t1#P#p1#SP#p1sp1", "t1#P#p1#SP#p1sp2");
EOF
ALTER TABLE t1 IMPORT PARTITION p1sp2 TABLESPACE;
SELECT * FROM t1 PARTITION (p1sp2) ORDER BY c1;
INSERT INTO t1 PARTITION (p1sp2) VALUES (161), (164);
FLUSH TABLES;
SELECT * FROM t1 PARTITION (p1sp2) ORDER BY c1;
--error ER_TABLESPACE_DISCARDED
SELECT * FROM t1 ORDER BY c1;
ALTER TABLE t1 DISCARD PARTITION p1sp2 TABLESPACE;
perl;
require 'include/innodb-util.inc';
ib_discard_tablespaces("test", "t1#P#p1#SP#p1sp0", "t1#P#p1#SP#p1sp2");
ib_restore_tablespaces("test", "t1#P#p1#SP#p1sp2");
EOF
--replace_regex /#p#/#P#/ /#sp#/#SP#/
ALTER TABLE t1 DISCARD PARTITION all TABLESPACE;
perl;
require 'include/innodb-util.inc';
ib_discard_tablespaces("test",
"t1#P#p0#SP#p0sp0", "t1#P#p0#SP#p0sp1", "t1#P#p0#SP#p0sp2",
"t1#P#p1#SP#p1sp0", "t1#P#p1#SP#p1sp1", "t1#P#p1#SP#p1sp2");
ib_restore_tablespaces("test",
"t1#P#p0#SP#p0sp0", "t1#P#p0#SP#p0sp1",
"t1#P#p1#SP#p1sp0", "t1#P#p1#SP#p1sp1", "t1#P#p1#SP#p1sp2");
EOF
--echo # Removing p0sp2's .ibd file
--remove_file $MYSQLD_DATADIR/test/t1#P#p0#SP#p0sp2.ibd
--error ER_INTERNAL_ERROR
ALTER TABLE t1 IMPORT PARTITION all TABLESPACE;
perl;
require 'include/innodb-util.inc';
ib_restore_tablespaces("test", "t1#P#p0#SP#p0sp2");
EOF
--replace_regex /#p#/#P#/ /#sp#/#SP#/
--error ER_TABLESPACE_EXISTS
ALTER TABLE t1 IMPORT PARTITION all TABLESPACE;
ALTER TABLE t1 IMPORT PARTITION p0sp2 TABLESPACE;
--replace_regex /#p#/#P#/ /#sp#/#SP#/
ALTER TABLE t1 DISCARD PARTITION all TABLESPACE;
perl;
require 'include/innodb-util.inc';
ib_discard_tablespaces("test",
"t1#P#p0#SP#p0sp0", "t1#P#p0#SP#p0sp1", "t1#P#p0#SP#p0sp2",
"t1#P#p1#SP#p1sp0", "t1#P#p1#SP#p1sp1", "t1#P#p1#SP#p1sp2");
ib_restore_tablespaces("test",
"t1#P#p0#SP#p0sp0", "t1#P#p0#SP#p0sp1", "t1#P#p0#SP#p0sp2",
"t1#P#p1#SP#p1sp0", "t1#P#p1#SP#p1sp1", "t1#P#p1#SP#p1sp2");
EOF
ALTER TABLE t1 IMPORT PARTITION all TABLESPACE;
SELECT * FROM t1 ORDER BY c1;
DROP TABLE t1;
CREATE TABLE t1 (c1 INT) ENGINE = InnoDB;
--error ER_PARTITION_MGMT_ON_NONPARTITIONED
ALTER TABLE t1 DISCARD PARTITION pNonExisting TABLESPACE;
--error ER_PARTITION_MGMT_ON_NONPARTITIONED
ALTER TABLE t1 IMPORT PARTITION pNonExisting TABLESPACE;
--error ER_PARTITION_MGMT_ON_NONPARTITIONED
ALTER TABLE t1 IMPORT PARTITION all TABLESPACE;
DROP TABLE t1;
--echo # discard partition one by one
CREATE TABLE t1 (c1 INT) ENGINE = InnoDB
PARTITION BY RANGE (c1)
SUBPARTITION BY HASH (c1) SUBPARTITIONS 3
(PARTITION p0 VALUES LESS THAN (100),
PARTITION p1 VALUES LESS THAN MAXVALUE);
ALTER TABLE t1 DISCARD PARTITION p0sp0 TABLESPACE;
perl;
require 'include/innodb-util.inc';
ib_discard_tablespaces("test","t1#P#p0#SP#p0sp0");
ib_restore_tablespaces("test","t1#P#p0#SP#p0sp0");
EOF
ALTER TABLE t1 IMPORT PARTITION p0sp0 TABLESPACE;
SELECT * FROM t1 PARTITION (p0sp0) ORDER BY c1;
SELECT * FROM t1 ORDER BY c1;
ALTER TABLE t1 REBUILD PARTITION p0;
SELECT * FROM t1 PARTITION (p0sp0) ORDER BY c1;
ALTER TABLE t1 DISCARD PARTITION p1 TABLESPACE;
perl;
require 'include/innodb-util.inc';
ib_discard_tablespaces("test",
"t1#P#p1#SP#p1sp0", "t1#P#p1#SP#p1sp1", "t1#P#p1#SP#p1sp2");
ib_restore_tablespaces("test",
"t1#P#p1#SP#p1sp0", "t1#P#p1#SP#p1sp1", "t1#P#p1#SP#p1sp2");
EOF
ALTER TABLE t1 IMPORT PARTITION p1 TABLESPACE;
SELECT * FROM t1 PARTITION (p1) ORDER BY c1;
ALTER TABLE t1 OPTIMIZE PARTITION p1;
SELECT * FROM t1 PARTITION (p1) ORDER BY c1;
ALTER TABLE t1 CHECK PARTITION p1;
ALTER TABLE t1 ANALYZE PARTITION p1;
ALTER TABLE t1 REPAIR PARTITION p0sp0,p1;
SELECT * FROM t1 ORDER BY c1;
ALTER TABLE t1 DISCARD PARTITION p0sp0 TABLESPACE;
ALTER TABLE t1 DISCARD PARTITION p1 TABLESPACE;
ALTER TABLE t1 DISCARD PARTITION p0sp1 TABLESPACE;
ALTER TABLE t1 DISCARD PARTITION p0sp2 TABLESPACE;
perl;
require 'include/innodb-util.inc';
ib_discard_tablespaces("test",
"t1#P#p0#SP#p0sp0", "t1#P#p0#SP#p0sp1", "t1#P#p0#SP#p0sp2",
"t1#P#p1#SP#p1sp0", "t1#P#p1#SP#p1sp1", "t1#P#p1#SP#p1sp2");
ib_restore_tablespaces("test",
"t1#P#p0#SP#p0sp0", "t1#P#p0#SP#p0sp1", "t1#P#p0#SP#p0sp2",
"t1#P#p1#SP#p1sp0", "t1#P#p1#SP#p1sp1", "t1#P#p1#SP#p1sp2");
EOF
ALTER TABLE t1 IMPORT PARTITION all TABLESPACE;
SELECT * FROM t1 ORDER BY c1;
DROP TABLE t1;
# Test EXPORT/IMPORT with instant ADD COLUMN
CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY, b INT) PARTITION BY HASH (a) PARTITIONS 3;
INSERT INTO t1 VALUES(1, 1), (2, 2), (11, 11), (12, 12), (21, 21), (22, 22), (26, 26), (27, 27);
# Instant ADD COLUMN
ALTER TABLE t1 ADD COLUMN c INT DEFAULT 100;
SELECT * FROM t1;
INSERT INTO t1(a, b) VALUES(5, 5), (6, 6), (28, 28);
# Truncate one partition, so it's totally new
ALTER TABLE t1 TRUNCATE PARTITION p2;
SELECT * FROM t1;
# Another instant ADD COLUMN
ALTER TABLE t1 ADD COLUMN d INT DEFAULT 200;
# Truncate another partition, so it's totally new
ALTER TABLE t1 TRUNCATE PARTITION p1;
SELECT * FROM t1;
INSERT INTO t1(a, b) VALUES(3, 3), (4, 4);
SELECT * FROM t1;
CHECK TABLE t1;
FLUSH TABLES t1 FOR EXPORT;
SELECT * FROM t1;
perl;
require 'include/innodb-util.inc';
ib_backup_tablespaces("test", "t1#P#p0", "t1#P#p1", "t1#P#p2");
EOF
UNLOCK TABLES;
DROP TABLE t1;
CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY, b INT, c INT, d INT) PARTITION BY HASH (a) PARTITIONS 3;
ALTER TABLE t1 DISCARD PARTITION all TABLESPACE;
perl;
require 'include/innodb-util.inc';
ib_discard_tablespaces("test", "t1#P#p0", "t1#P#p1", "t1#P#p2");
ib_restore_tablespaces("test", "t1#P#p0", "t1#P#p1", "t1#P#p2");
EOF
ALTER TABLE t1 IMPORT PARTITION all TABLESPACE;
CHECK TABLE t1;
SELECT * FROM t1;
INSERT INTO t1(a, b) VALUES(8, 8), (9, 9), (13, 13), (14, 14), (23, 23), (24, 24);
SELECT * FROM t1;
UPDATE t1 SET c = 90 WHERE a < 10;
SELECT * FROM t1;
UPDATE t1 SET c = 110 WHERE a > 20;
SELECT * FROM t1;
CHECK TABLE t1;
DROP TABLE t1;
--disable_query_log
call mtr.add_suppression("Cannot calculate statistics for table .* because the \.ibd file is missing");
call mtr.add_suppression("Cannot delete tablespace .* in DISCARD TABLESPACE. Tablespace not found");
call mtr.add_suppression("Cannot delete tablespace .* because it is not found in the tablespace memory cache.");
call mtr.add_suppression("Trying to import a tablespace, but could not open the tablespace file");
call mtr.add_suppression("Operating system error number 2 in a file operation.");
call mtr.add_suppression("The error means the system cannot find the path specified.");
call mtr.add_suppression("Unable to import tablespace .* because it already exists. Please DISCARD the tablespace before IMPORT.");
call mtr.add_suppression("Missing \.ibd file for table .test...t1. .. Partition");
--enable_query_log
--remove_files_wildcard $MYSQLTEST_VARDIR/tmp t1*.ibd
--remove_files_wildcard $MYSQLTEST_VARDIR/tmp t1*.cfg