Debian Codegraph @

mysql-test/suite/innodb/t/alter_rename_existing.test

raw
1 --echo #
2 --echo # Show what happens during ALTER TABLE when an existing file
3 --echo # exists in the target location.
4 --echo #
5 --echo # Bug #19218794: IF TABLESPACE EXISTS, CAN'T CREATE TABLE,
6 --echo # BUT CAN ALTER ENGINE=INNODB
7 --echo #
8
9 --source include/have_innodb.inc
10
11 --disable_query_log
12 LET $MYSQLD_DATADIR = `select @@datadir`;
13 SET @old_innodb_file_per_table = @@innodb_file_per_table;
14 --enable_query_log
15
16 CREATE TABLE t1 (a SERIAL, b CHAR(10)) ENGINE=Memory;
17 INSERT INTO t1(b) VALUES('one'), ('two'), ('three');
18
19 --echo #
20 --echo # Create a file called MYSQLD_DATADIR/test/t1.ibd
21 --write_line "This is not t1.ibd" $MYSQLD_DATADIR/test/t1.ibd
22
23 --echo # Directory listing of test/*.ibd
24 --echo #
25 --list_files $MYSQLD_DATADIR/test/ *.ibd
26
27 --replace_regex /Error on rename of '.*' to '.*'/Error on rename of 'OLD_FILE_NAME' to 'NEW_FILE_NAME'/
28 --error ER_ERROR_ON_RENAME
29 ALTER TABLE t1 ENGINE = InnoDB;
30
31 --echo #
32 --echo # Move the file to InnoDB as t2
33 --echo #
34 ALTER TABLE t1 RENAME TO t2, ENGINE = INNODB;
35 SHOW CREATE TABLE t2;
36 SELECT * from t2;
37
38 --replace_regex /Error on rename of '.*' to '.*'/Error on rename of 'OLD_FILE_NAME' to 'NEW_FILE_NAME'/
39 --error ER_ERROR_ON_RENAME
40 ALTER TABLE t2 RENAME TO t1;
41
42 --echo #
43 --echo # Create another t1, but in the system tablespace.
44 --echo #
45 SET GLOBAL innodb_file_per_table=OFF;
46 CREATE TABLE t1 (a SERIAL, b CHAR(20)) ENGINE=InnoDB;
47 INSERT INTO t1(b) VALUES('one'), ('two'), ('three');
48 SHOW CREATE TABLE t1;
49 SELECT name, space=0 FROM information_schema.innodb_sys_tables WHERE name = 'test/t1';
50
51 --echo #
52 --echo # ALTER TABLE from system tablespace to system tablespace
53 --echo #
54 ALTER TABLE t1 ADD COLUMN c INT, ALGORITHM=INPLACE;
55 ALTER TABLE t1 ADD COLUMN d INT, ALGORITHM=COPY;
56
57 --echo #
58 --echo # Try to move t1 from the system tablespace to a file-per-table
59 --echo # while a blocking t1.ibd file exists.
60 --echo #
61 SET GLOBAL innodb_file_per_table=ON;
62 --replace_regex /#sql-ib[1-9][0-9]*/#sql-ib/
63 --error ER_TABLESPACE_EXISTS
64 ALTER TABLE t1 FORCE, ALGORITHM=INPLACE;
65 --replace_regex /Error on rename of '.*' to '.*'/Error on rename of 'OLD_FILE_NAME' to 'NEW_FILE_NAME'/
66 --error ER_ERROR_ON_RENAME
67 ALTER TABLE t1 FORCE, ALGORITHM=COPY;
68
69 --echo #
70 --echo # Delete the blocking file called MYSQLD_DATADIR/test/t1.ibd
71 --remove_file $MYSQLD_DATADIR/test/t1.ibd
72
73 --echo # Move t1 to file-per-table using ALGORITHM=INPLACE with no blocking t1.ibd.
74 --echo #
75 ALTER TABLE t1 FORCE, ALGORITHM=INPLACE;
76 SHOW CREATE TABLE t1;
77 SELECT name, space=0 FROM information_schema.innodb_sys_tables WHERE name = 'test/t1';
78
79 DROP TABLE t1;
80
81 --echo #
82 --echo # Rename t2.ibd to t1.ibd.
83 --echo #
84 ALTER TABLE t2 RENAME TO t1;
85 SELECT name, space=0 FROM information_schema.innodb_sys_tables WHERE name = 'test/t1';
86 SELECT * from t1;
87
88 DROP TABLE t1;
89
90 --disable_query_log
91 call mtr.add_suppression("\\[ERROR\\] InnoDB: Cannot rename '.*' to '.*' because the target file exists");
92 SET GLOBAL innodb_file_per_table = @old_innodb_file_per_table;
93 --enable_query_log