mariadb/mysql-test/suite/innodb/include/import_begin.inc
Yuchen Pei 9b431d714f
MDEV-26137 Improve import tablespace workflow.
Allow ALTER TABLE ... IMPORT TABLESPACE without creating the table
followed by discarding the tablespace.

That is, assuming we want to import table t1 to t2, instead of

CREATE TABLE t2 LIKE t1;
ALTER TABLE t2 DISCARD TABLESPACE;
FLUSH TABLES t1 FOR EXPORT;
--copy_file $MYSQLD_DATADIR/test/t1.cfg $MYSQLD_DATADIR/test/t2.cfg
--copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/t2.ibd
UNLOCK TABLES;
ALTER TABLE t2 IMPORT TABLESPACE;

We can simply do

FLUSH TABLES t1 FOR EXPORT;
--copy_file $MYSQLD_DATADIR/test/t1.cfg $MYSQLD_DATADIR/test/t2.cfg
--copy_file $MYSQLD_DATADIR/test/t1.frm $MYSQLD_DATADIR/test/t2.frm
--copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/t2.ibd
UNLOCK TABLES;
ALTER TABLE t2 IMPORT TABLESPACE;

We achieve this by creating a "stub" table in the second scenario
while opening the table, where t2 does not exist but needs to import
from t1. The "stub" table is similar to a table that is created but
then instructed to discard its tablespace.

We include tests with various row formats, encryption, with indexes
and auto-increment.
2023-07-04 17:56:27 +10:00

32 lines
897 B
PHP

--source include/innodb_row_format.inc
--source include/innodb_row_format_2.inc
--source include/innodb_checksum_algorithm.inc
--echo #
--echo # MDEV-26137 ALTER TABLE IMPORT enhancement
--echo #
let $MYSQLD_DATADIR = `SELECT @@datadir`;
--disable_query_log
let $ROW_FORMAT_OPTION=;
if($MTR_COMBINATION_R_REDUNDANT) {
let $ROW_FORMAT_OPTION= ROW_FORMAT=REDUNDANT;
}
if($MTR_COMBINATION_R_COMPACT) {
let $ROW_FORMAT_OPTION= ROW_FORMAT=COMPACT;
}
if($MTR_COMBINATION_R_DYNAMIC) {
let $ROW_FORMAT_OPTION= ROW_FORMAT=DYNAMIC;
}
if($MTR_COMBINATION_R_COMPRESSED) {
let $ROW_FORMAT_OPTION= ROW_FORMAT=COMPRESSED;
}
let $CREATE_OPTIONS_REGEX= /ENGINE=InnoDB.*$ROW_FORMAT_OPTION/CREATE_OPTIONS/;
--enable_query_log
--replace_regex $CREATE_OPTIONS_REGEX
eval
CREATE TABLE t1(a INT PRIMARY KEY DEFAULT 42) ENGINE=InnoDB $ROW_FORMAT_OPTION;
INSERT INTO t1() VALUES();
FLUSH TABLES t1 FOR EXPORT;