~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/mysql-test/innodb-index.test

  • Committer: Toru Maesaka
  • Date: 2008-12-17 07:16:37 UTC
  • mto: (685.1.40 devel) (713.1.5 devel)
  • mto: This revision was merged to the branch mainline in revision 713.
  • Revision ID: dev@torum.net-20081217071637-7j9040w7lpms77r2
Removed my_time() and added error checking

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
-- source include/have_innodb.inc
 
2
 
 
3
create table t1(a int not null, b int, c char(10) not null, d varchar(20)) engine = innodb;
 
4
insert into t1 values (5,5,'oo','oo'),(4,4,'tr','tr'),(3,4,'ad','ad'),(2,3,'ak','ak');
 
5
commit;
 
6
--error ER_DUP_KEYNAME
 
7
alter table t1 add index b (b), add index b (b);
 
8
--error ER_DUP_FIELDNAME
 
9
alter table t1 add index (b,b);
 
10
alter table t1 add index d2 (d);
 
11
show create table t1;
 
12
explain select * from t1 force index(d2) order by d;
 
13
select * from t1 force index (d2) order by d;
 
14
--error ER_DUP_ENTRY
 
15
alter table t1 add unique index (b);
 
16
show create table t1;
 
17
alter table t1 add index (b);
 
18
show create table t1;
 
19
 
 
20
# Check how existing tables interfere with temporary tables.
 
21
CREATE TABLE `t1#1`(a INT PRIMARY KEY) ENGINE=InnoDB;
 
22
 
 
23
--error 156
 
24
alter table t1 add unique index (c), add index (d);
 
25
rename table `t1#1` to `t1#2`;
 
26
--error 156
 
27
alter table t1 add unique index (c), add index (d);
 
28
drop table `t1#2`;
 
29
 
 
30
alter table t1 add unique index (c), add index (d);
 
31
show create table t1;
 
32
explain select * from t1 force index(c) order by c;
 
33
alter table t1 add primary key (a), drop index c;
 
34
show create table t1;
 
35
--error ER_MULTIPLE_PRI_KEY
 
36
alter table t1 add primary key (c);
 
37
--error ER_DUP_ENTRY
 
38
alter table t1 drop primary key, add primary key (b);
 
39
create unique index c on t1 (c);
 
40
show create table t1;
 
41
explain select * from t1 force index(c) order by c;
 
42
select * from t1 force index(c) order by c;
 
43
alter table t1 drop index b, add index (b);
 
44
show create table t1;
 
45
insert into t1 values(6,1,'ggg','ggg');
 
46
select * from t1;
 
47
select * from t1 force index(b) order by b;
 
48
select * from t1 force index(c) order by c;
 
49
select * from t1 force index(d) order by d;
 
50
explain select * from t1 force index(b) order by b;
 
51
explain select * from t1 force index(c) order by c;
 
52
explain select * from t1 force index(d) order by d;
 
53
show create table t1;
 
54
drop table t1;
 
55
 
 
56
create table t1(a int not null, b int, c char(10), d varchar(20), primary key (a)) engine = innodb;
 
57
insert into t1 values (1,1,'ab','ab'),(2,2,'ac','ac'),(3,3,'ad','ad'),(4,4,'afe','afe');
 
58
commit;
 
59
alter table t1 add index (c(2));
 
60
show create table t1;
 
61
alter table t1 add unique index (d(10));
 
62
show create table t1;
 
63
insert into t1 values(5,1,'ggg','ggg');
 
64
select * from t1;
 
65
select * from t1 force index(c) order by c;
 
66
select * from t1 force index(d) order by d;
 
67
explain select * from t1 order by b;
 
68
explain select * from t1 force index(c) order by c;
 
69
explain select * from t1 force index(d) order by d;
 
70
show create table t1;
 
71
alter table t1 drop index d;
 
72
insert into t1 values(8,9,'fff','fff');
 
73
select * from t1;
 
74
select * from t1 force index(c) order by c;
 
75
explain select * from t1 order by b;
 
76
explain select * from t1 force index(c) order by c;
 
77
explain select * from t1 order by d;
 
78
show create table t1;
 
79
drop table t1;
 
80
 
 
81
create table t1(a int not null, b int, c char(10), d varchar(20), primary key (a)) engine = innodb;
 
82
insert into t1 values (1,1,'ab','ab'),(2,2,'ac','ac'),(3,2,'ad','ad'),(4,4,'afe','afe');
 
83
commit;
 
84
alter table t1 add unique index (b,c);
 
85
insert into t1 values(8,9,'fff','fff');
 
86
select * from t1;
 
87
select * from t1 force index(b) order by b;
 
88
explain select * from t1 force index(b) order by b;
 
89
show create table t1;
 
90
alter table t1 add index (b,c);
 
91
insert into t1 values(11,11,'kkk','kkk');
 
92
select * from t1;
 
93
select * from t1 force index(b) order by b;
 
94
explain select * from t1 force index(b) order by b;
 
95
show create table t1;
 
96
alter table t1 add unique index (c,d);
 
97
insert into t1 values(13,13,'yyy','aaa');
 
98
select * from t1;
 
99
select * from t1 force index(b) order by b;
 
100
select * from t1 force index(c) order by c;
 
101
explain select * from t1 force index(b) order by b;
 
102
explain select * from t1 force index(c) order by c;
 
103
show create table t1;
 
104
drop table t1;
 
105
 
 
106
create table t1(a int not null, b int not null, c int, primary key (a), key (b)) engine = innodb;
 
107
create table t3(a int not null, c int not null, d int, primary key (a), key (c)) engine = innodb;
 
108
create table t4(a int not null, d int not null, e int, primary key (a), key (d)) engine = innodb;
 
109
create table t2(a int not null, b int not null, c int not null, d int not null, e int,
 
110
foreign key (b) references t1(b) on delete cascade,
 
111
foreign key (c) references t3(c), foreign key (d) references t4(d))
 
112
engine = innodb;
 
113
--error ER_DROP_INDEX_FK
 
114
alter table t1 drop index b;
 
115
--error ER_DROP_INDEX_FK
 
116
alter table t3 drop index c;
 
117
--error ER_DROP_INDEX_FK
 
118
alter table t4 drop index d;
 
119
--error ER_DROP_INDEX_FK
 
120
alter table t2 drop index b;
 
121
--error ER_DROP_INDEX_FK
 
122
alter table t2 drop index b, drop index c, drop index d;
 
123
# Apparently, the following makes mysql_alter_table() drop index d.
 
124
create unique index dc on t2 (d,c);
 
125
create index dc on t1 (b,c);
 
126
# This should preserve the foreign key constraints.
 
127
alter table t2 add primary key (a);
 
128
insert into t1 values (1,1,1);
 
129
insert into t3 values (1,1,1);
 
130
insert into t4 values (1,1,1);
 
131
insert into t2 values (1,1,1,1,1);
 
132
commit;
 
133
alter table t4 add constraint dc foreign key (a) references t1(a);
 
134
show create table t4;
 
135
--replace_regex /'test\.#sql-[0-9a-f_]*'/'#sql-temporary'/
 
136
# a foreign key 'test/dc' already exists
 
137
--error ER_CANT_CREATE_TABLE
 
138
alter table t3 add constraint dc foreign key (a) references t1(a);
 
139
show create table t3;
 
140
alter table t2 drop index b, add index (b);
 
141
show create table t2;
 
142
--error ER_ROW_IS_REFERENCED_2
 
143
delete from t1;
 
144
--error ER_CANT_DROP_FIELD_OR_KEY
 
145
drop index dc on t4;
 
146
# there is no foreign key dc on t3
 
147
--replace_regex /'\.\/test\/#sql2-[0-9a-f-]*'/'#sql2-temporary'/
 
148
--error ER_ERROR_ON_RENAME
 
149
alter table t3 drop foreign key dc;
 
150
alter table t4 drop foreign key dc;
 
151
select * from t2;
 
152
delete from t1;
 
153
select * from t2;
 
154
 
 
155
drop table t2,t4,t3,t1;
 
156
 
 
157
-- let charset = utf8
 
158
-- source include/innodb-index.inc
 
159
 
 
160
create table t1(a int not null, b int) engine = innodb;
 
161
insert into t1 values (1,1),(1,1),(1,1),(1,1);
 
162
--error ER_DUP_ENTRY
 
163
alter table t1 add unique index (a);
 
164
--error ER_DUP_ENTRY
 
165
alter table t1 add unique index (b);
 
166
--error ER_DUP_ENTRY
 
167
alter table t1 add unique index (a), add unique index(b);
 
168
show create table t1;
 
169
drop table t1;
 
170
 
 
171
create table t1(a int not null, c int not null,b int, primary key(a), unique key(c), key(b)) engine = innodb;
 
172
alter table t1 drop index c, drop index b;
 
173
show create table t1;
 
174
drop table t1;
 
175
 
 
176
create table t1(a int not null, b int, primary key(a)) engine = innodb;
 
177
alter table t1 add index (b);
 
178
show create table t1;
 
179
drop table t1;
 
180
 
 
181
create table t1(a int not null, b int, c char(10), d varchar(20), primary key (a)) engine = innodb;
 
182
insert into t1 values (1,1,'ab','ab'),(2,2,'ac','ac'),(3,3,'ac','ac'),(4,4,'afe','afe'),(5,4,'affe','affe');
 
183
--error ER_DUP_ENTRY
 
184
alter table t1 add unique index (b), add unique index (c), add unique index (d);
 
185
--error ER_DUP_ENTRY
 
186
alter table t1 add unique index (c), add unique index (b), add index (d);
 
187
show create table t1;
 
188
drop table t1;
 
189
 
 
190
create table t1(a int not null, b int not null, c int, primary key (a), key(c)) engine=innodb;
 
191
insert into t1 values (5,1,5),(4,2,4),(3,3,3),(2,4,2),(1,5,1);
 
192
alter table t1 add unique index (b);
 
193
insert into t1 values (10,20,20),(11,19,19),(12,18,18),(13,17,17);
 
194
show create table t1;
 
195
check table t1;
 
196
explain select * from t1 force index(c) order by c;
 
197
explain select * from t1 order by a;
 
198
explain select * from t1 force index(b) order by b;
 
199
select * from t1 order by a;
 
200
select * from t1 force index(b) order by b;
 
201
select * from t1 force index(c) order by c;
 
202
drop table t1;
 
203
 
 
204
create table t1(a int not null, b int not null) engine=innodb;
 
205
insert into t1 values (1,1);
 
206
alter table t1 add primary key(b);
 
207
insert into t1 values (2,2);
 
208
show create table t1;
 
209
check table t1;
 
210
select * from t1;
 
211
explain select * from t1;
 
212
explain select * from t1 order by a;
 
213
explain select * from t1 order by b;
 
214
checksum table t1;
 
215
drop table t1;
 
216
 
 
217
create table t1(a int not null) engine=innodb;
 
218
insert into t1 values (1);
 
219
alter table t1 add primary key(a);
 
220
insert into t1 values (2);
 
221
show create table t1;
 
222
check table t1;
 
223
commit;
 
224
select * from t1;
 
225
explain select * from t1;
 
226
explain select * from t1 order by a;
 
227
drop table t1;
 
228
 
 
229
create table t2(d varchar(17) primary key) engine=innodb default charset=utf8;
 
230
create table t3(a int primary key) engine=innodb;
 
231
 
 
232
insert into t3 values(22),(44),(33),(55),(66);
 
233
 
 
234
insert into t2 values ('jejdkrun87'),('adfd72nh9k'),
 
235
('adfdpplkeock'),('adfdijnmnb78k'),('adfdijn0loKNHJik');
 
236
 
 
237
create table t1(a int, b blob, c text, d text not null)
 
238
engine=innodb default charset = utf8;
 
239
 
 
240
# r2667 The following test is disabled because MySQL behavior changed.
 
241
# r2667 The test was added with this comment:
 
242
# r2667 
 
243
# r2667 ------------------------------------------------------------------------
 
244
# r2667 r1699 | marko | 2007-08-10 19:53:19 +0300 (Fri, 10 Aug 2007) | 5 lines
 
245
# r2667 
 
246
# r2667 branches/zip: Add changes that accidentally omitted from r1698:
 
247
# r2667 
 
248
# r2667 innodb-index.test, innodb-index.result: Add a test for creating
 
249
# r2667 a PRIMARY KEY on a column that contains a NULL value.
 
250
# r2667 ------------------------------------------------------------------------
 
251
# r2667 
 
252
# r2667 but in BZR-r2667:
 
253
# r2667 http://bazaar.launchpad.net/~mysql/mysql-server/mysql-5.1/revision/davi%40mysql.com-20080617141221-8yre8ys9j4uw3xx5?start_revid=joerg%40mysql.com-20080630105418-7qoe5ehomgrcdb89
 
254
# r2667 MySQL changed the behavior to do full table copy when creating PRIMARY INDEX
 
255
# r2667 on a non-NULL column instead of calling ::add_index() which would fail (and
 
256
# r2667 this is what we were testing here). Before r2667 the code execution path was
 
257
# r2667 like this (when adding PRIMARY INDEX on a non-NULL column with ALTER TABLE):
 
258
# r2667 
 
259
# r2667 mysql_alter_table()
 
260
# r2667   compare_tables()  // would return ALTER_TABLE_INDEX_CHANGED
 
261
# r2667   ::add_index()  // would fail with "primary index cannot contain NULL"
 
262
# r2667 
 
263
# r2667 after r2667 the code execution path is the following:
 
264
# r2667 
 
265
# r2667 mysql_alter_table()
 
266
# r2667   compare_tables()  // returns ALTER_TABLE_DATA_CHANGED
 
267
# r2667   full copy is done, without calling ::add_index()
 
268
# r2667 
 
269
# r2667 To enable, remove "# r2667: " below.
 
270
# r2667 
 
271
# r2667: insert into t1 values (null,null,null,'null');
 
272
insert into t1
 
273
select a,left(repeat(d,100*a),65535),repeat(d,20*a),d from t2,t3;
 
274
drop table t2, t3;
 
275
select count(*) from t1 where a=44;
 
276
select a,
 
277
length(b),b=left(repeat(d,100*a),65535),length(c),c=repeat(d,20*a),d from t1;
 
278
# r2667: --error ER_PRIMARY_CANT_HAVE_NULL
 
279
# r2667: alter table t1 add primary key (a), add key (b(20));
 
280
# r2667: delete from t1 where d='null';
 
281
--error ER_DUP_ENTRY
 
282
alter table t1 add primary key (a), add key (b(20));
 
283
delete from t1 where a%2;
 
284
check table t1;
 
285
alter table t1 add primary key (a,b(255),c(255)), add key (b(767));
 
286
select count(*) from t1 where a=44;
 
287
select a,
 
288
length(b),b=left(repeat(d,100*a),65535),length(c),c=repeat(d,20*a),d from t1;
 
289
show create table t1;
 
290
check table t1;
 
291
explain select * from t1 where b like 'adfd%';
 
292
 
 
293
#
 
294
# Test locking
 
295
#
 
296
 
 
297
create table t2(a int, b varchar(255), primary key(a,b)) engine=innodb;
 
298
insert into t2 select a,left(b,255) from t1;
 
299
drop table t1;
 
300
rename table t2 to t1;
 
301
 
 
302
connect (a,localhost,root,,);
 
303
connect (b,localhost,root,,);
 
304
connection a;
 
305
set innodb_lock_wait_timeout=1;
 
306
begin;
 
307
# Obtain an IX lock on the table
 
308
select a from t1 limit 1 for update;
 
309
connection b;
 
310
set innodb_lock_wait_timeout=1;
 
311
# This would require an S lock on the table, conflicting with the IX lock.
 
312
--error ER_LOCK_WAIT_TIMEOUT
 
313
create index t1ba on t1 (b,a);
 
314
connection a;
 
315
commit;
 
316
begin;
 
317
# Obtain an IS lock on the table
 
318
select a from t1 limit 1 lock in share mode;
 
319
connection b;
 
320
# This will require an S lock on the table.  No conflict with the IS lock.
 
321
create index t1ba on t1 (b,a);
 
322
# This would require an X lock on the table, conflicting with the IS lock.
 
323
--error ER_LOCK_WAIT_TIMEOUT
 
324
drop index t1ba on t1;
 
325
connection a;
 
326
commit;
 
327
explain select a from t1 order by b;
 
328
--send
 
329
select a,sleep(2+a/100) from t1 order by b limit 3;
 
330
 
 
331
# The following DROP INDEX will succeed, altough the SELECT above has
 
332
# opened a read view.  However, during the execution of the SELECT,
 
333
# MySQL should hold a table lock that should block the execution
 
334
# of the DROP INDEX below.
 
335
 
 
336
connection b;
 
337
select sleep(1);
 
338
drop index t1ba on t1;
 
339
 
 
340
# After the index was dropped, subsequent SELECTs will use the same
 
341
# read view, but they should not be accessing the dropped index any more.
 
342
 
 
343
connection a;
 
344
reap;
 
345
explain select a from t1 order by b;
 
346
select a from t1 order by b limit 3;
 
347
commit;
 
348
 
 
349
connection default;
 
350
disconnect a;
 
351
disconnect b;
 
352
 
 
353
drop table t1;
 
354
 
 
355
let $per_table=`select @@innodb_file_per_table`;
 
356
let $format=`select @@innodb_file_format`;
 
357
set global innodb_file_per_table=on;
 
358
set global innodb_file_format='Barracuda';
 
359
# Test creating a table that could lead to undo log overflow.
 
360
# In the undo log, we write a 768-byte prefix (REC_MAX_INDEX_COL_LEN)
 
361
# of each externally stored column that appears as a column prefix in an index.
 
362
# For this test case, it would suffice to write 1 byte, though.
 
363
create table t1(a blob,b blob,c blob,d blob,e blob,f blob,g blob,h blob,
 
364
                i blob,j blob,k blob,l blob,m blob,n blob,o blob,p blob,
 
365
                q blob,r blob,s blob,t blob,u blob)
 
366
        engine=innodb row_format=dynamic;
 
367
create index t1a on t1 (a(1));
 
368
create index t1b on t1 (b(1));
 
369
create index t1c on t1 (c(1));
 
370
create index t1d on t1 (d(1));
 
371
create index t1e on t1 (e(1));
 
372
create index t1f on t1 (f(1));
 
373
create index t1g on t1 (g(1));
 
374
create index t1h on t1 (h(1));
 
375
create index t1i on t1 (i(1));
 
376
create index t1j on t1 (j(1));
 
377
create index t1k on t1 (k(1));
 
378
create index t1l on t1 (l(1));
 
379
create index t1m on t1 (m(1));
 
380
create index t1n on t1 (n(1));
 
381
create index t1o on t1 (o(1));
 
382
create index t1p on t1 (p(1));
 
383
create index t1q on t1 (q(1));
 
384
create index t1r on t1 (r(1));
 
385
create index t1s on t1 (s(1));
 
386
create index t1t on t1 (t(1));
 
387
--error 139
 
388
create index t1u on t1 (u(1));
 
389
--error 139
 
390
create index t1ut on t1 (u(1), t(1));
 
391
create index t1st on t1 (s(1), t(1));
 
392
show create table t1;
 
393
--error 139
 
394
create index t1u on t1 (u(1));
 
395
alter table t1 row_format=compact;
 
396
create index t1u on t1 (u(1));
 
397
 
 
398
drop table t1;
 
399
eval set global innodb_file_per_table=$per_table;
 
400
eval set global innodb_file_format=$format;
 
401
 
 
402
#
 
403
# Test to check whether CREATE INDEX handles implicit foreign key
 
404
# constraint modifications (Issue #70, Bug #38786)
 
405
#
 
406
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
 
407
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
 
408
 
 
409
CREATE TABLE t1(
 
410
  c1    BIGINT(12) NOT NULL,
 
411
  PRIMARY KEY (c1)
 
412
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
413
 
 
414
CREATE TABLE t2(
 
415
  c1    BIGINT(16) NOT NULL,
 
416
  c2    BIGINT(12) NOT NULL,
 
417
  c3    BIGINT(12) NOT NULL,
 
418
  PRIMARY KEY (c1)
 
419
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
420
 
 
421
ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca
 
422
 FOREIGN KEY (c3) REFERENCES t1(c1);
 
423
 
 
424
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
 
425
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
 
426
 
 
427
SHOW CREATE TABLE t2;
 
428
 
 
429
CREATE INDEX i_t2_c3_c2 ON t2(c3, c2);
 
430
 
 
431
SHOW CREATE TABLE t2;
 
432
 
 
433
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
 
434
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
 
435
 
 
436
--error ER_NO_REFERENCED_ROW_2
 
437
INSERT INTO t2 VALUES(0,0,0);
 
438
INSERT INTO t1 VALUES(0);
 
439
INSERT INTO t2 VALUES(0,0,0);
 
440
 
 
441
DROP TABLE t2;
 
442
 
 
443
CREATE TABLE t2(
 
444
  c1    BIGINT(16) NOT NULL,
 
445
  c2    BIGINT(12) NOT NULL,
 
446
  c3    BIGINT(12) NOT NULL,
 
447
  PRIMARY KEY (c1,c2,c3)
 
448
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
449
 
 
450
ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca
 
451
 FOREIGN KEY (c3) REFERENCES t1(c1);
 
452
 
 
453
SHOW CREATE TABLE t2;
 
454
 
 
455
CREATE INDEX i_t2_c3_c2 ON t2(c3, c2);
 
456
 
 
457
SHOW CREATE TABLE t2;
 
458
--error ER_NO_REFERENCED_ROW_2
 
459
INSERT INTO t2 VALUES(0,0,1);
 
460
INSERT INTO t2 VALUES(0,0,0);
 
461
--error ER_ROW_IS_REFERENCED_2
 
462
DELETE FROM t1;
 
463
DELETE FROM t2;
 
464
 
 
465
DROP TABLE t2;
 
466
DROP TABLE t1;
 
467
 
 
468
CREATE TABLE t1(
 
469
  c1    BIGINT(12) NOT NULL,
 
470
  c2    INT(4) NOT NULL,
 
471
  PRIMARY KEY (c2,c1)
 
472
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
473
 
 
474
CREATE TABLE t2(
 
475
  c1    BIGINT(16) NOT NULL,
 
476
  c2    BIGINT(12) NOT NULL,
 
477
  c3    BIGINT(12) NOT NULL,
 
478
  PRIMARY KEY (c1)
 
479
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
480
 
 
481
--replace_regex /'test\.#sql-[0-9_a-f-]*'/'#sql-temporary'/
 
482
--error ER_CANT_CREATE_TABLE
 
483
ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca
 
484
 FOREIGN KEY (c3,c2) REFERENCES t1(c1,c1);
 
485
--replace_regex /'test\.#sql-[0-9_a-f-]*'/'#sql-temporary'/
 
486
--error ER_CANT_CREATE_TABLE
 
487
ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca
 
488
 FOREIGN KEY (c3,c2) REFERENCES t1(c1,c2);
 
489
--replace_regex /'test\.#sql-[0-9_a-f-]*'/'#sql-temporary'/
 
490
--error ER_CANT_CREATE_TABLE
 
491
ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca
 
492
 FOREIGN KEY (c3,c2) REFERENCES t1(c2,c1);
 
493
ALTER TABLE t1 MODIFY COLUMN c2 BIGINT(12) NOT NULL;
 
494
--replace_regex /'test\.#sql-[0-9_a-f-]*'/'#sql-temporary'/
 
495
--error ER_CANT_CREATE_TABLE
 
496
ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca
 
497
 FOREIGN KEY (c3,c2) REFERENCES t1(c1,c2);
 
498
 
 
499
ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca
 
500
 FOREIGN KEY (c3,c2) REFERENCES t1(c2,c1);
 
501
SHOW CREATE TABLE t1;
 
502
SHOW CREATE TABLE t2;
 
503
CREATE INDEX i_t2_c2_c1 ON t2(c2, c1);
 
504
SHOW CREATE TABLE t2;
 
505
CREATE INDEX i_t2_c3_c1_c2 ON t2(c3, c1, c2);
 
506
SHOW CREATE TABLE t2;
 
507
CREATE INDEX i_t2_c3_c2 ON t2(c3, c2);
 
508
SHOW CREATE TABLE t2;
 
509
 
 
510
DROP TABLE t2;
 
511
DROP TABLE t1;