Debian Codegraph @

mysql-test/suite/atomic/rename_combinations.test

raw
1 #
2 # This tests tries cover most of the recovery cases in
3 # DDL_LOG_RENAME_TABLE_ACTION and do_rename()
4 # This test does not intend to crash the server
5 # It's a complement to main.rename
6 #
7
8 create database test2;
9
10 --echo #
11 --echo # Testing rename error in different places
12 --echo #
13
14 create table t1 (a int);
15 create table t2 (b int);
16 create table t3 (c int);
17 create table t4 (d int);
18
19 insert into t1 values(1);
20 insert into t2 values(2);
21 insert into t3 values(3);
22 insert into t4 values(4);
23
24 create temporary table tmp1 (a int);
25 create temporary table tmp2 (b int);
26 create temporary table tmp3 (c int);
27 create temporary table tmp4 (d int);
28
29 insert into tmp1 values(11);
30 insert into tmp2 values(22);
31 insert into tmp3 values(33);
32 insert into tmp4 values(44);
33
34 --error ER_TABLE_EXISTS_ERROR
35 rename table t3 to t4, t1 to t5, t2 to t1, t5 to t2;
36 --error ER_TABLE_EXISTS_ERROR
37 rename table t1 to t5, t3 to t4, t2 to t1, t5 to t2;
38 --error ER_TABLE_EXISTS_ERROR
39 rename table t1 to t5, t2 to t1, t3 to t4, t5 to t2;
40 --error ER_TABLE_EXISTS_ERROR
41 rename table t1 to t5, t2 to t1, t5 to t2, t3 to t4;
42
43 --echo # Try failed rename using two databases
44 --error ER_NO_SUCH_TABLE
45 rename table test.t1 to test2.t5, test.t2 to test.t1, t5 to test.t2;
46
47 select t1.a+t2.b+t3.c+t4.d from t1,t2,t3,t4;
48 --error ER_NO_SUCH_TABLE
49 select * from t5;
50
51 --echo #
52 --echo # Testing rename error in different places with temporary tables
53 --echo #
54
55 --error ER_TABLE_EXISTS_ERROR
56 rename table tmp3 to tmp4, tmp1 to t5, tmp2 to tmp1, t5 to tmp1;
57 --error ER_TABLE_EXISTS_ERROR
58 rename table tmp1 to t5, tmp3 to tmp4, tmp2 to tmp1, t5 to tmp1;
59 --error ER_TABLE_EXISTS_ERROR
60 rename table tmp1 to t5, tmp2 to tmp1, tmp3 to tmp4, t5 to tmp1;
61 --error ER_TABLE_EXISTS_ERROR
62 rename table tmp1 to t5, tmp2 to tmp1, t5 to tmp1, tmp3 to tmp4;
63
64 select tmp1.a+tmp2.b+tmp3.c+tmp4.d from tmp1,tmp2,tmp3,tmp4;
65 --error ER_NO_SUCH_TABLE
66 select * from t5;
67
68 --echo #
69 --echo # Testing combinations of rename normal and temporary tables
70 --echo #
71
72 --error ER_TABLE_EXISTS_ERROR
73 rename table t1 to t5, t2 to t1, t5 to t2, tmp3 to tmp4, tmp1 to t5, tmp2 to tmp1, t5 to tmp1;
74 --error ER_TABLE_EXISTS_ERROR
75 rename table t1 to t5, t2 to t1, t5 to t2, tmp1 to t5, tmp3 to tmp4, tmp2 to tmp1, t5 to tmp1;
76 --error ER_TABLE_EXISTS_ERROR
77 rename table t1 to t5, t2 to t1, t5 to t2, tmp1 to t5, tmp2 to tmp1, tmp3 to tmp4, t5 to tmp1;
78 --error ER_TABLE_EXISTS_ERROR
79 rename table t1 to t5, t2 to t1, t5 to t2, tmp1 to t5, tmp2 to tmp1, t5 to tmp1, t3 to t4;
80
81 --error ER_NO_SUCH_TABLE
82 rename table t1 to t5, tmp2 to tmp5, t2 to t1, tmp2 to tmp1, t5 to t2, tmp5 to tmp1, t8 to t9;
83
84 select t1.a+t2.b+t3.c+t4.d from t1,t2,t3,t4;
85 select tmp1.a+tmp2.b+tmp3.c+tmp4.d from tmp1,tmp2,tmp3,tmp4;
86
87 drop table tmp1,tmp2,tmp3,tmp4;
88
89 --echo #
90 --echo # Similar tests with triggers
91 --echo #
92
93 delimiter |;
94 create trigger t1_trg before insert on t1 for each row
95 begin
96 if isnull(new.a) then
97 set new.a:= 10;
98 end if;
99 end|
100 create trigger t2_trg before insert on t2 for each row
101 begin
102 if isnull(new.b) then
103 set new.b:= 100;
104 end if;
105 end|
106 create trigger t3_trg before insert on t3 for each row
107 begin
108 if isnull(new.c) then
109 set new.c:= 1000;
110 end if;
111 end|
112
113 delimiter ;|
114
115 --error ER_TABLE_EXISTS_ERROR
116 rename table t3 to t4, t1 to t5, t2 to t1, t5 to t2;
117 --error ER_TABLE_EXISTS_ERROR
118 rename table t1 to t5, t3 to t4, t2 to t1, t5 to t2;
119 --error ER_TABLE_EXISTS_ERROR
120 rename table t1 to t5, t2 to t1, t3 to t4, t5 to t2;
121 --error ER_TABLE_EXISTS_ERROR
122 rename table t1 to t5, t2 to t1, t5 to t2, t3 to t4;
123
124 --echo # Test of move table between databases
125 --error ER_TRG_IN_WRONG_SCHEMA
126 rename table t4 to test2.t5, t2 to t4, test2.t5 to t2, t1 to test2.t6;
127
128 --replace_column 6 #
129 show triggers;
130
131 select t1.a+t2.b+t3.c+t4.d from t1,t2,t3,t4;
132 insert into t1 values(null);
133 insert into t2 values(null);
134 insert into t3 values(null);
135 select (select sum(t1.a) from t1)+ (select sum(t2.b) from t2) + (select sum(t3.c) from t3)+ (select sum(t4.d) from t4);
136
137 drop trigger t1_trg;
138 drop trigger t2_trg;
139 drop trigger t3_trg;
140
141 --echo #
142 --echo # Test with views
143 --echo #
144
145 create view v1 as select * from t1;
146 create view v2 as select * from t2;
147 create view v3 as select * from t3;
148 create view v4 as select * from t4;
149
150 --error ER_TABLE_EXISTS_ERROR
151 rename table v3 to v4, v1 to t5, v2 to v1, t5 to v2;
152 --error ER_TABLE_EXISTS_ERROR
153 rename table v1 to t5, v3 to v4, v2 to v1, t5 to v2;
154 --error ER_TABLE_EXISTS_ERROR
155 rename table v1 to t5, v2 to v1, v3 to v4, t5 to v2;
156 --error ER_TABLE_EXISTS_ERROR
157 rename table v1 to t5, v2 to v1, t5 to v2, v3 to v4;
158
159 --echo # Try failed rename using two databases
160 --error ER_FORBID_SCHEMA_CHANGE
161 rename table test.v1 to test.v5, test.v2 to test.v1, test.v3 to test2.v2, non_existing_view to another_non_existing_view;
162
163 select (select sum(v1.a) from v1)+ (select sum(v2.b) from v2) + (select sum(v3.c) from v3)+ (select sum(v4.d) from v4);
164
165 drop view v1,v2,v3,v4;
166
167 #
168 # Clean up
169 #
170 drop table t1, t2, t3, t4;
171 drop database test2;