-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
to #54769172 support import tablespace if not exists
this change is pick from polardbx_57_develop https://code.alibaba-inc.com/polardbx/polardbx-engine/codereview/15696835
- Loading branch information
luoyanxin
authored and
jianhua.sjh
committed
Apr 24, 2024
1 parent
31feedb
commit a6d7022
Showing
13 changed files
with
192 additions
and
46 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
mysql-test/suite/innodb/include/import_tablespace_ifnotexists.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Export Table and Import from saved files .cfg and .ibd | ||
# Caller should create t1 table definition and populate table | ||
|
||
let $MYSQLD_DATADIR = `SELECT @@datadir`; | ||
|
||
if(!$source_db) { | ||
let $source_db = test; | ||
} | ||
|
||
if(!$dest_db) { | ||
let $dest_db = test; | ||
} | ||
|
||
eval FLUSH TABLES $source_db.t1 FOR EXPORT; | ||
|
||
--copy_file $MYSQLD_DATADIR/$source_db/t1.cfg $MYSQLD_DATADIR/t1.cfg_back | ||
--copy_file $MYSQLD_DATADIR/$source_db/t1.ibd $MYSQLD_DATADIR/t1.ibd_back | ||
|
||
UNLOCK TABLES; | ||
|
||
if($source_db != $dest_db) { | ||
eval USE $dest_db; | ||
let $create1 = query_get_value(SHOW CREATE TABLE $source_db.t1, Create Table, 1); | ||
eval $create1; | ||
} | ||
|
||
eval ALTER TABLE $dest_db.t1 DISCARD TABLESPACE; | ||
|
||
--move_file $MYSQLD_DATADIR/t1.cfg_back $MYSQLD_DATADIR/$dest_db/t1.cfg | ||
--move_file $MYSQLD_DATADIR/t1.ibd_back $MYSQLD_DATADIR/$dest_db/t1.ibd | ||
|
||
eval ALTER TABLE $dest_db.t1 IMPORT TABLESPACE; | ||
--error ER_TABLESPACE_EXISTS | ||
eval ALTER TABLE $dest_db.t1 IMPORT TABLESPACE; | ||
eval ALTER TABLE $dest_db.t1 IMPORT TABLESPACE IF NOT EXISTS; | ||
|
||
eval CHECK TABLE $dest_db.t1; | ||
eval SHOW CREATE TABLE $dest_db.t1; | ||
eval SELECT * FROM $dest_db.t1; | ||
|
||
|
||
if($source_db != $dest_db) { | ||
eval DROP TABLE $dest_db.t1; | ||
} |
32 changes: 32 additions & 0 deletions
32
mysql-test/suite/innodb/r/import-tablespace-ifnotexists.result
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# | ||
# ALTER TABLE ... IMPORT TABLESPACE IF NOT EXISTS | ||
# | ||
CREATE TABLE t1 (c1 VARCHAR(32), c2 VARCHAR(32), c3 VARCHAR(32), | ||
PRIMARY KEY (c1, c2, c3)) | ||
ENGINE=InnoDB CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; | ||
INSERT INTO t1 VALUES ('Test Data -1', 'Test Data -2', 'Test Data -3'); | ||
FLUSH TABLES test.t1 FOR EXPORT; | ||
UNLOCK TABLES; | ||
ALTER TABLE test.t1 DISCARD TABLESPACE; | ||
ALTER TABLE test.t1 IMPORT TABLESPACE; | ||
ALTER TABLE test.t1 IMPORT TABLESPACE; | ||
ERROR HY000: Tablespace 'test/t1' exists. | ||
ALTER TABLE test.t1 IMPORT TABLESPACE IF NOT EXISTS; | ||
Warnings: | ||
Warning 1813 InnoDB: Tablespace 'test/t1' exists. | ||
CHECK TABLE test.t1; | ||
Table Op Msg_type Msg_text | ||
test.t1 check status OK | ||
SHOW CREATE TABLE test.t1; | ||
Table Create Table | ||
t1 CREATE TABLE `t1` ( | ||
`c1` varchar(32) NOT NULL, | ||
`c2` varchar(32) NOT NULL, | ||
`c3` varchar(32) NOT NULL, | ||
PRIMARY KEY (`c1`,`c2`,`c3`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci | ||
SELECT * FROM test.t1; | ||
c1 c2 c3 | ||
Test Data -1 Test Data -2 Test Data -3 | ||
DROP TABLE t1; | ||
# Test End |
16 changes: 16 additions & 0 deletions
16
mysql-test/suite/innodb/t/import-tablespace-ifnotexists.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Test "ALTER TABLE ... IMPORT TABLESPACE IF NOT EXISTS" in InnoDB | ||
#--source include/have_innodb.inc | ||
|
||
--echo # | ||
--echo # ALTER TABLE ... IMPORT TABLESPACE IF NOT EXISTS | ||
--echo # | ||
|
||
CREATE TABLE t1 (c1 VARCHAR(32), c2 VARCHAR(32), c3 VARCHAR(32), | ||
PRIMARY KEY (c1, c2, c3)) | ||
ENGINE=InnoDB CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; | ||
|
||
INSERT INTO t1 VALUES ('Test Data -1', 'Test Data -2', 'Test Data -3'); | ||
|
||
--source suite/innodb/include/import_tablespace_ifnotexists.inc | ||
|
||
DROP TABLE t1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.