summaryrefslogtreecommitdiffstats
path: root/mysql-test/main/alter_table_combinations.result
blob: cd47c78d40449a9887cb7af12becdea6beb436a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
set @save_default_engine= @@default_storage_engine;
#
# MDEV-25803 Inplace ALTER breaks MyISAM/Aria tables when order of keys is changed
#
create or replace table t1 (x int, y int, unique (y), unique (x), primary key(x)) engine myisam;
alter table t1 change x xx int, algorithm=inplace;
check table t1;
Table	Op	Msg_type	Msg_text
test.t1	check	status	OK
create or replace table t1 (x int, y int, unique (y), unique (x), primary key(x));
alter table t1 change x xx int, algorithm=inplace;
check table t1;
Table	Op	Msg_type	Msg_text
test.t1	check	status	OK
drop table t1;
#
# End of 10.3 tests
#
#
# MDEV-16290 ALTER TABLE ... RENAME COLUMN syntax
#
CREATE TABLE t1(a INT, b VARCHAR(30), c FLOAT);
SHOW CREATE TABLE t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `a` int(11) DEFAULT NULL,
  `b` varchar(30) DEFAULT NULL,
  `c` float DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
INSERT INTO t1 VALUES(1,'abcd',1.234);
CREATE TABLE t2(a INT, b VARCHAR(30), c FLOAT) ENGINE=MyIsam;
SHOW CREATE TABLE t2;
Table	Create Table
t2	CREATE TABLE `t2` (
  `a` int(11) DEFAULT NULL,
  `b` varchar(30) DEFAULT NULL,
  `c` float DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
INSERT INTO t2 VALUES(1,'abcd',1.234);
ALTER TABLE t1 RENAME COLUMN a TO a;
SHOW CREATE TABLE t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `a` int(11) DEFAULT NULL,
  `b` varchar(30) DEFAULT NULL,
  `c` float DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
ALTER TABLE t1 RENAME COLUMN a TO m;
ALTER TABLE t1 RENAME COLUMN a TO m;
ERROR 42S22: Unknown column 'a' in 't1'
ALTER TABLE t1 RENAME COLUMN IF EXISTS a TO m;
Warnings:
Note	1054	Unknown column 'a' in 't1'
SHOW CREATE TABLE t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `m` int(11) DEFAULT NULL,
  `b` varchar(30) DEFAULT NULL,
  `c` float DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
SELECT * FROM t1;
m	b	c
1	abcd	1.234
ALTER TABLE t1 RENAME COLUMN m TO x,
RENAME COLUMN b TO y,
RENAME COLUMN c TO z;
SHOW CREATE TABLE t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `x` int(11) DEFAULT NULL,
  `y` varchar(30) DEFAULT NULL,
  `z` float DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
SELECT * FROM t1;
x	y	z
1	abcd	1.234
ALTER TABLE t2 RENAME COLUMN a TO d, RENAME COLUMN b TO e, RENAME COLUMN c to f;
SHOW CREATE TABLE t2;
Table	Create Table
t2	CREATE TABLE `t2` (
  `d` int(11) DEFAULT NULL,
  `e` varchar(30) DEFAULT NULL,
  `f` float DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
SELECT * FROM t2;
d	e	f
1	abcd	1.234
ALTER TABLE t1 CHANGE COLUMN x a INT, RENAME COLUMN y TO b;
SHOW CREATE TABLE t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `a` int(11) DEFAULT NULL,
  `b` varchar(30) DEFAULT NULL,
  `z` float DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
ALTER TABLE t1 CHANGE COLUMN z c DOUBLE, RENAME COLUMN b to b;
SHOW CREATE TABLE t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `a` int(11) DEFAULT NULL,
  `b` varchar(30) DEFAULT NULL,
  `c` double DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
ALTER TABLE t1 CHANGE COLUMN a b int, RENAME COLUMN b TO c, CHANGE COLUMN c d FLOAT;
SHOW CREATE TABLE t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `b` int(11) DEFAULT NULL,
  `c` varchar(30) DEFAULT NULL,
  `d` float DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
ALTER TABLE t1 ADD COLUMN zz INT, RENAME COLUMN d TO f;
SHOW CREATE TABLE t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `b` int(11) DEFAULT NULL,
  `c` varchar(30) DEFAULT NULL,
  `f` float DEFAULT NULL,
  `zz` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
ALTER TABLE t1 DROP COLUMN zz, RENAME COLUMN c TO zz;
SHOW CREATE TABLE t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `b` int(11) DEFAULT NULL,
  `zz` varchar(30) DEFAULT NULL,
  `f` float DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
ALTER TABLE t1 RENAME COLUMN zz to c, DROP COLUMN f;
SHOW CREATE TABLE t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `b` int(11) DEFAULT NULL,
  `c` varchar(30) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
ALTER TABLE t1 ADD COLUMN d INT DEFAULT 5, RENAME COLUMN c TO b, DROP COLUMN b;
SHOW CREATE TABLE t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `b` varchar(30) DEFAULT NULL,
  `d` int(11) DEFAULT 5
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
ALTER TABLE t1 RENAME COLUMN b TO d, RENAME COLUMN d TO b;
SHOW CREATE TABLE t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `d` varchar(30) DEFAULT NULL,
  `b` int(11) DEFAULT 5
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
ALTER TABLE t1 ADD KEY(b);
SHOW CREATE TABLE t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `d` varchar(30) DEFAULT NULL,
  `b` int(11) DEFAULT 5,
  KEY `b` (`b`)
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
ALTER TABLE t1 RENAME COLUMN b TO bb;
SHOW CREATE TABLE t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `d` varchar(30) DEFAULT NULL,
  `bb` int(11) DEFAULT 5,
  KEY `b` (`bb`)
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
SELECT * FROM t1;
d	bb
abcd	5
CREATE TABLE t3(a int, b int, KEY(b));
ALTER TABLE t3 ADD CONSTRAINT FOREIGN KEY(b) REFERENCES t1(bb);
SHOW CREATE TABLE t3;
Table	Create Table
t3	CREATE TABLE `t3` (
  `a` int(11) DEFAULT NULL,
  `b` int(11) DEFAULT NULL,
  KEY `b` (`b`),
  CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`bb`)
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
ALTER TABLE t1 RENAME COLUMN bb TO b;
SHOW CREATE TABLE t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `d` varchar(30) DEFAULT NULL,
  `b` int(11) DEFAULT 5,
  KEY `b` (`b`)
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
ALTER TABLE t3 RENAME COLUMN b TO c;
SHOW CREATE TABLE t3;
Table	Create Table
t3	CREATE TABLE `t3` (
  `a` int(11) DEFAULT NULL,
  `c` int(11) DEFAULT NULL,
  KEY `b` (`c`),
  CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`c`) REFERENCES `t1` (`b`)
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
CREATE TABLE t4(a int);
ALTER TABLE t4 RENAME COLUMN a TO aa, ALGORITHM = INPLACE;
SHOW CREATE TABLE t4;
Table	Create Table
t4	CREATE TABLE `t4` (
  `aa` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
ALTER TABLE t4 RENAME COLUMN aa TO a, ALGORITHM = COPY;
SHOW CREATE TABLE t4;
Table	Create Table
t4	CREATE TABLE `t4` (
  `a` int(11) DEFAULT NULL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
DROP TABLE t4;
CREATE VIEW v1 AS SELECT d,e,f FROM t2;
CREATE TRIGGER trg1 BEFORE UPDATE on t2 FOR EACH ROW SET NEW.d=OLD.d + 10;
CREATE PROCEDURE sp1() INSERT INTO t2(d) VALUES(10);
ALTER TABLE t2 RENAME COLUMN d TO g;
SHOW CREATE TABLE t2;
Table	Create Table
t2	CREATE TABLE `t2` (
  `g` int(11) DEFAULT NULL,
  `e` varchar(30) DEFAULT NULL,
  `f` float DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
SHOW CREATE VIEW v1;
View	Create View	character_set_client	collation_connection
v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `test`.`t2`.`d` AS `d`,`test`.`t2`.`e` AS `e`,`test`.`t2`.`f` AS `f` from `t2`	latin1	latin1_swedish_ci
Warnings:
Warning	1356	View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
SELECT * FROM v1;
ERROR HY000: View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
UPDATE t2 SET f = f + 10;
ERROR 42S22: Unknown column 'd' in 'NEW'
CALL sp1();
ERROR 42S22: Unknown column 'd' in 'field list'
DROP TRIGGER trg1;
DROP PROCEDURE sp1;
CREATE TABLE t_gen(a INT, b DOUBLE GENERATED ALWAYS AS (SQRT(a)));
INSERT INTO t_gen(a) VALUES(4);
SELECT * FROM t_gen;
a	b
4	2
SHOW CREATE TABLE t_gen;
Table	Create Table
t_gen	CREATE TABLE `t_gen` (
  `a` int(11) DEFAULT NULL,
  `b` double GENERATED ALWAYS AS (sqrt(`a`)) VIRTUAL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
ALTER TABLE t_gen RENAME COLUMN a TO c, CHANGE COLUMN b b DOUBLE GENERATED ALWAYS AS (SQRT(c));
SELECT * FROM t_gen;
c	b
4	2
SHOW CREATE TABLE t_gen;
Table	Create Table
t_gen	CREATE TABLE `t_gen` (
  `c` int(11) DEFAULT NULL,
  `b` double GENERATED ALWAYS AS (sqrt(`c`)) VIRTUAL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
ALTER TABLE t_gen CHANGE COLUMN c x INT;
show create table t_gen;
Table	Create Table
t_gen	CREATE TABLE `t_gen` (
  `x` int(11) DEFAULT NULL,
  `b` double GENERATED ALWAYS AS (sqrt(`x`)) VIRTUAL
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
ALTER TABLE t_gen RENAME COLUMN x TO a;
DROP TABLE t_gen;
SHOW CREATE TABLE t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `d` varchar(30) DEFAULT NULL,
  `b` int(11) DEFAULT 5,
  KEY `b` (`b`)
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
ALTER TABLE t1 RENAME COLUMN b z;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'z' at line 1
ALTER TABLE t1 RENAME COLUMN FROM b TO z;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FROM b TO z' at line 1
ALTER TABLE t1 RENAME COLUMN b TO 1;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '1' at line 1
ALTER TABLE t1 RENAME COLUMN b TO e, RENAME COLUMN c TO e;
ERROR 42S22: Unknown column 'c' in 't1'
ALTER TABLE t1 ADD COLUMN z INT, RENAME COLUMN b TO z;
ERROR 42S21: Duplicate column name 'z'
ALTER TABLE t1 DROP COLUMN b, RENAME COLUMN b TO z;
ERROR 42S22: Unknown column 'b' in 't1'
ALTER TABLE t1 RENAME COLUMN b TO b, RENAME COLUMN b TO b;
ERROR 42S22: Unknown column 'b' in 't1'
ALTER TABLE t1 RENAME COLUMN b TO c3, DROP COLUMN c3;
ERROR 42000: Can't DROP COLUMN `c3`; check that it exists
ALTER TABLE t1 ADD COLUMN z INT, CHANGE COLUMN z y INT, DROP COLUMN y;
ERROR 42S22: Unknown column 'z' in 't1'
ALTER TABLE t1 ADD COLUMN z INT, RENAME COLUMN z TO y, DROP COLUMN y;
ERROR 42S22: Unknown column 'z' in 't1'
ALTER TABLE t1 RENAME COLUMN b TO `nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn`;
ERROR 42000: Incorrect column name 'nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn'
ALTER TABLE t1 CHANGE b `nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn` int;
ERROR 42000: Identifier name 'nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn' is too long
SHOW CREATE TABLE t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `d` varchar(30) DEFAULT NULL,
  `b` int(11) DEFAULT 5,
  KEY `b` (`b`)
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
SELECT * FROM t1;
d	b
abcd	5
DROP VIEW v1;
DROP TABLE t3,t1,t2;
#
# MDEV-25803 Inplace ALTER breaks MyISAM/Aria tables when order of keys is changed
#
create or replace table t1 (x int, y int, unique (y), unique (x), primary key(x)) engine myisam;
alter table t1 change x xx int, algorithm=inplace;
check table t1;
Table	Op	Msg_type	Msg_text
test.t1	check	status	OK
create or replace table t1 (x int, y int, unique (y), unique (x), primary key(x));
alter table t1 change x xx int, algorithm=inplace;
check table t1;
Table	Op	Msg_type	Msg_text
test.t1	check	status	OK
drop table t1;
#
# End of 10.5 tests
#
set @@default_storage_engine= @save_default_engine;