~stewart/drizzle/embedded-innodb-create-select-transaction-arrgh

« back to all changes in this revision

Viewing changes to mysql-test/r/innodb_mysql.result

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
set global innodb_support_xa=default;
 
2
set session innodb_support_xa=default;
 
3
SET SESSION STORAGE_ENGINE = InnoDB;
 
4
drop table if exists t1,t2,t3,t1m,t1i,t2m,t2i,t4;
 
5
drop procedure if exists p1;
 
6
create table t1 (
 
7
c_id int(11) not null default '0',
 
8
org_id int(11) default null,
 
9
unique key contacts$c_id (c_id),
 
10
key contacts$org_id (org_id)
 
11
);
 
12
insert into t1 values
 
13
(2,null),(120,null),(141,null),(218,7), (128,1),
 
14
(151,2),(234,2),(236,2),(243,2),(255,2),(259,2),(232,3),(235,3),(238,3),
 
15
(246,3),(253,3),(269,3),(285,3),(291,3),(293,3),(131,4),(230,4),(231,4);
 
16
create table t2 (
 
17
slai_id int(11) not null default '0',
 
18
owner_tbl int(11) default null,
 
19
owner_id int(11) default null,
 
20
sla_id int(11) default null,
 
21
inc_web int(11) default null,
 
22
inc_email int(11) default null,
 
23
inc_chat int(11) default null,
 
24
inc_csr int(11) default null,
 
25
inc_total int(11) default null,
 
26
time_billed int(11) default null,
 
27
activedate timestamp null default null,
 
28
expiredate timestamp null default null,
 
29
state int(11) default null,
 
30
sla_set int(11) default null,
 
31
unique key t2$slai_id (slai_id),
 
32
key t2$owner_id (owner_id),
 
33
key t2$sla_id (sla_id)
 
34
);
 
35
insert into t2(slai_id, owner_tbl, owner_id, sla_id) values
 
36
(1,3,1,1), (3,3,10,2), (4,3,3,6), (5,3,2,5), (6,3,8,3), (7,3,9,7),
 
37
(8,3,6,8), (9,3,4,9), (10,3,5,10), (11,3,11,11), (12,3,7,12);
 
38
flush tables;
 
39
select si.slai_id
 
40
from t1 c join t2 si on
 
41
((si.owner_tbl = 3 and si.owner_id = c.org_id) or
 
42
( si.owner_tbl = 2 and si.owner_id = c.c_id))
 
43
where
 
44
c.c_id = 218 and expiredate is null;
 
45
slai_id
 
46
12
 
47
select * from t1 where org_id is null;
 
48
c_id    org_id
 
49
2       NULL
 
50
120     NULL
 
51
141     NULL
 
52
select si.slai_id
 
53
from t1 c join t2 si on
 
54
((si.owner_tbl = 3 and si.owner_id = c.org_id) or
 
55
( si.owner_tbl = 2 and si.owner_id = c.c_id))
 
56
where
 
57
c.c_id = 218 and expiredate is null;
 
58
slai_id
 
59
12
 
60
drop table t1, t2;
 
61
CREATE TABLE t1 (a int, b int, KEY b (b));
 
62
CREATE TABLE t2 (a int, b int, PRIMARY KEY  (a,b));
 
63
CREATE TABLE t3 (a int, b int, c int, PRIMARY KEY  (a),
 
64
UNIQUE KEY b (b,c), KEY a (a,b,c));
 
65
INSERT INTO t1 VALUES (1, 1);
 
66
INSERT INTO t1 SELECT a + 1, b + 1 FROM t1;
 
67
INSERT INTO t1 SELECT a + 2, b + 2 FROM t1;
 
68
INSERT INTO t2 VALUES (1,1),(1,2),(1,3),(1,4),(1,5),(1,6),(1,7),(1,8);
 
69
INSERT INTO t2 SELECT a + 1, b FROM t2;
 
70
DELETE FROM t2 WHERE a = 1 AND b < 2;
 
71
INSERT INTO t3 VALUES (1,1,1),(2,1,2);
 
72
INSERT INTO t3 SELECT a + 2, a + 2, 3 FROM t3;
 
73
INSERT INTO t3 SELECT a + 4, a + 4, 3 FROM t3;
 
74
SELECT STRAIGHT_JOIN SQL_NO_CACHE t1.b, t1.a FROM t1, t3, t2 WHERE
 
75
t3.a = t2.a AND t2.b = t1.a AND t3.b = 1 AND t3.c IN (1, 2)
 
76
ORDER BY t1.b LIMIT 2;
 
77
b       a
 
78
1       1
 
79
2       2
 
80
SELECT STRAIGHT_JOIN SQL_NO_CACHE t1.b, t1.a FROM t1, t3, t2 WHERE
 
81
t3.a = t2.a AND t2.b = t1.a AND t3.b = 1 AND t3.c IN (1, 2)
 
82
ORDER BY t1.b LIMIT 5;
 
83
b       a
 
84
1       1
 
85
2       2
 
86
2       2
 
87
3       3
 
88
3       3
 
89
DROP TABLE t1, t2, t3;
 
90
CREATE TABLE `t1` (`id1` INT) ;
 
91
INSERT INTO `t1` (`id1`) VALUES (1),(5),(2);
 
92
CREATE TABLE `t2` (
 
93
`id1` INT,
 
94
`id2` INT NOT NULL,
 
95
`id3` INT,
 
96
`id4` INT NOT NULL,
 
97
UNIQUE (`id2`,`id4`),
 
98
KEY (`id1`)
 
99
);
 
100
INSERT INTO `t2`(`id1`,`id2`,`id3`,`id4`) VALUES
 
101
(1,1,1,0),
 
102
(1,1,2,1),
 
103
(5,1,2,2),
 
104
(6,1,2,3),
 
105
(1,2,2,2),
 
106
(1,2,1,1);
 
107
SELECT `id1` FROM `t1` WHERE `id1` NOT IN (SELECT `id1` FROM `t2` WHERE `id2` = 1 AND `id3` = 2);
 
108
id1
 
109
2
 
110
DROP TABLE t1, t2;
 
111
create table t1 (c1 int) engine=innodb;
 
112
handler t1 open;
 
113
handler t1 read first;
 
114
c1
 
115
Before and after comparison
 
116
0
 
117
drop table t1;
 
118
CREATE TABLE t1(c1 TEXT, UNIQUE (c1(1)), cnt INT DEFAULT 1)
 
119
ENGINE=INNODB CHARACTER SET UTF8;
 
120
INSERT INTO t1 (c1) VALUES ('1a');
 
121
SELECT * FROM t1;
 
122
c1      cnt
 
123
1a      1
 
124
INSERT INTO t1 (c1) VALUES ('1b') ON DUPLICATE KEY UPDATE cnt=cnt+1;
 
125
SELECT * FROM t1;
 
126
c1      cnt
 
127
1a      2
 
128
DROP TABLE t1;
 
129
CREATE TABLE t1(c1 VARCHAR(2), UNIQUE (c1(1)), cnt INT DEFAULT 1)
 
130
ENGINE=INNODB CHARACTER SET UTF8;
 
131
INSERT INTO t1 (c1) VALUES ('1a');
 
132
SELECT * FROM t1;
 
133
c1      cnt
 
134
1a      1
 
135
INSERT INTO t1 (c1) VALUES ('1b') ON DUPLICATE KEY UPDATE cnt=cnt+1;
 
136
SELECT * FROM t1;
 
137
c1      cnt
 
138
1a      2
 
139
DROP TABLE t1;
 
140
CREATE TABLE t1(c1 CHAR(2), UNIQUE (c1(1)), cnt INT DEFAULT 1)
 
141
ENGINE=INNODB CHARACTER SET UTF8;
 
142
INSERT INTO t1 (c1) VALUES ('1a');
 
143
SELECT * FROM t1;
 
144
c1      cnt
 
145
1a      1
 
146
INSERT INTO t1 (c1) VALUES ('1b') ON DUPLICATE KEY UPDATE cnt=cnt+1;
 
147
SELECT * FROM t1;
 
148
c1      cnt
 
149
1a      2
 
150
DROP TABLE t1;
 
151
CREATE TABLE t1 (
 
152
a1 decimal(10,0) DEFAULT NULL,
 
153
a2 blob,
 
154
a3 time DEFAULT NULL,
 
155
a4 blob,
 
156
a5 char(175) DEFAULT NULL,
 
157
a6 timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
 
158
a7 tinyblob,
 
159
INDEX idx (a6,a7(239),a5)
 
160
) ENGINE=InnoDB;
 
161
EXPLAIN SELECT a4 FROM t1 WHERE
 
162
a6=NULL AND
 
163
a4='UNcT5pIde4I6c2SheTo4gt92OV1jgJCVkXmzyf325R1DwLURkbYHwhydANIZMbKTgdcR5xS';
 
164
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
165
1       SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    Impossible WHERE noticed after reading const tables
 
166
EXPLAIN SELECT t1.a4 FROM t1, t1 t WHERE
 
167
t.a6=t.a6 AND t1.a6=NULL AND
 
168
t1.a4='UNcT5pIde4I6c2SheTo4gt92OV1jgJCVkXmzyf325R1DwLURkbYHwhydANIZMbKTgdcR5xS';
 
169
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
170
1       SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    Impossible WHERE noticed after reading const tables
 
171
DROP TABLE t1;
 
172
create table t1m (a int) engine = MEMORY;
 
173
create table t1i (a int);
 
174
create table t2m (a int) engine = MEMORY;
 
175
create table t2i (a int);
 
176
insert into t2m values (5);
 
177
insert into t2i values (5);
 
178
select min(a) from t1i;
 
179
min(a)
 
180
NULL
 
181
select min(7) from t1i;
 
182
min(7)
 
183
NULL
 
184
select min(7) from DUAL;
 
185
min(7)
 
186
7
 
187
explain select min(7) from t2i join t1i;
 
188
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
189
1       SIMPLE  t2i     ALL     NULL    NULL    NULL    NULL    1       
 
190
1       SIMPLE  t1i     ALL     NULL    NULL    NULL    NULL    1       Using join buffer
 
191
select min(7) from t2i join t1i;
 
192
min(7)
 
193
NULL
 
194
select max(a) from t1i;
 
195
max(a)
 
196
NULL
 
197
select max(7) from t1i;
 
198
max(7)
 
199
NULL
 
200
select max(7) from DUAL;
 
201
max(7)
 
202
7
 
203
explain select max(7) from t2i join t1i;
 
204
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
205
1       SIMPLE  t2i     ALL     NULL    NULL    NULL    NULL    1       
 
206
1       SIMPLE  t1i     ALL     NULL    NULL    NULL    NULL    1       Using join buffer
 
207
select max(7) from t2i join t1i;
 
208
max(7)
 
209
NULL
 
210
select 1, min(a) from t1i where a=99;
 
211
1       min(a)
 
212
1       NULL
 
213
select 1, min(a) from t1i where 1=99;
 
214
1       min(a)
 
215
1       NULL
 
216
select 1, min(1) from t1i where a=99;
 
217
1       min(1)
 
218
1       NULL
 
219
select 1, min(1) from t1i where 1=99;
 
220
1       min(1)
 
221
1       NULL
 
222
select 1, max(a) from t1i where a=99;
 
223
1       max(a)
 
224
1       NULL
 
225
select 1, max(a) from t1i where 1=99;
 
226
1       max(a)
 
227
1       NULL
 
228
select 1, max(1) from t1i where a=99;
 
229
1       max(1)
 
230
1       NULL
 
231
select 1, max(1) from t1i where 1=99;
 
232
1       max(1)
 
233
1       NULL
 
234
explain select count(*), min(7), max(7) from t1m, t1i;
 
235
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
236
1       SIMPLE  t1m     system  NULL    NULL    NULL    NULL    0       const row not found
 
237
1       SIMPLE  t1i     ALL     NULL    NULL    NULL    NULL    1       
 
238
select count(*), min(7), max(7) from t1m, t1i;
 
239
count(*)        min(7)  max(7)
 
240
0       NULL    NULL
 
241
explain select count(*), min(7), max(7) from t1m, t2i;
 
242
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
243
1       SIMPLE  t1m     system  NULL    NULL    NULL    NULL    0       const row not found
 
244
1       SIMPLE  t2i     ALL     NULL    NULL    NULL    NULL    1       
 
245
select count(*), min(7), max(7) from t1m, t2i;
 
246
count(*)        min(7)  max(7)
 
247
0       NULL    NULL
 
248
explain select count(*), min(7), max(7) from t2m, t1i;
 
249
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
250
1       SIMPLE  t2m     system  NULL    NULL    NULL    NULL    1       
 
251
1       SIMPLE  t1i     ALL     NULL    NULL    NULL    NULL    1       
 
252
select count(*), min(7), max(7) from t2m, t1i;
 
253
count(*)        min(7)  max(7)
 
254
0       NULL    NULL
 
255
drop table t1m, t1i, t2m, t2i;
 
256
create table t1 (
 
257
a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' '
 
258
) ENGINE = MEMORY;
 
259
insert into t1 (a1, a2, b, c, d) values
 
260
('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
 
261
('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
 
262
('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
 
263
('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
 
264
('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
 
265
('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
 
266
('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
 
267
('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
 
268
('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
 
269
('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
 
270
('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
 
271
('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'),
 
272
('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'),
 
273
('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'),
 
274
('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'),
 
275
('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4'),
 
276
('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
 
277
('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
 
278
('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
 
279
('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
 
280
('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
 
281
('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
 
282
('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
 
283
('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
 
284
('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
 
285
('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
 
286
('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
 
287
('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'),
 
288
('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'),
 
289
('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'),
 
290
('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'),
 
291
('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4');
 
292
create table t4 (
 
293
pk_col int auto_increment primary key, a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' '
 
294
);
 
295
insert into t4 (a1, a2, b, c, d, dummy) select * from t1;
 
296
create index idx12672_0 on t4 (a1);
 
297
create index idx12672_1 on t4 (a1,a2,b,c);
 
298
create index idx12672_2 on t4 (a1,a2,b);
 
299
analyze table t4;
 
300
Table   Op      Msg_type        Msg_text
 
301
test.t4 analyze status  OK
 
302
select distinct a1 from t4 where pk_col not in (1,2,3,4);
 
303
a1
 
304
a
 
305
b
 
306
c
 
307
d
 
308
drop table t1,t4;
 
309
DROP TABLE IF EXISTS t2, t1;
 
310
CREATE TABLE t1 (i INT NOT NULL PRIMARY KEY) ENGINE= InnoDB;
 
311
CREATE TABLE t2 (
 
312
i INT NOT NULL,
 
313
FOREIGN KEY (i) REFERENCES t1 (i) ON DELETE NO ACTION
 
314
) ENGINE= InnoDB;
 
315
INSERT INTO t1 VALUES (1);
 
316
INSERT INTO t2 VALUES (1);
 
317
DELETE IGNORE FROM t1 WHERE i = 1;
 
318
Warnings:
 
319
Error   1451    Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`i`) REFERENCES `t1` (`i`) ON DELETE NO ACTION)
 
320
SELECT * FROM t1, t2;
 
321
i       i
 
322
1       1
 
323
DROP TABLE t2, t1;
 
324
End of 4.1 tests.
 
325
create table t1 (
 
326
a varchar(30), b varchar(30), primary key(a), key(b)
 
327
);
 
328
select distinct a from t1;
 
329
a
 
330
drop table t1;
 
331
create table t1(a int, key(a));
 
332
insert into t1 values(1);
 
333
select a, count(a) from t1 group by a with rollup;
 
334
a       count(a)
 
335
1       1
 
336
NULL    1
 
337
drop table t1;
 
338
create table t1 (f1 int, f2 char(1), primary key(f1,f2));
 
339
insert into t1 values ( 1,"e"),(2,"a"),( 3,"c"),(4,"d");
 
340
alter table t1 drop primary key, add primary key (f2, f1);
 
341
explain select distinct f1 a, f1 b from t1;
 
342
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
343
1       SIMPLE  t1      index   NULL    PRIMARY 5       NULL    4       Using index; Using temporary
 
344
explain select distinct f1, f2 from t1;
 
345
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
346
1       SIMPLE  t1      range   NULL    PRIMARY 5       NULL    3       Using index for group-by; Using temporary
 
347
drop table t1;
 
348
CREATE TABLE t1 (id int(11) NOT NULL PRIMARY KEY, name varchar(20),
 
349
INDEX (name));
 
350
CREATE TABLE t2 (id int(11) NOT NULL PRIMARY KEY, fkey int(11));
 
351
ALTER TABLE t2 ADD FOREIGN KEY (fkey) REFERENCES t2(id);
 
352
INSERT INTO t1 VALUES (1,'A1'),(2,'A2'),(3,'B');
 
353
INSERT INTO t2 VALUES (1,1),(2,2),(3,2),(4,3),(5,3);
 
354
EXPLAIN
 
355
SELECT COUNT(*) FROM t2 LEFT JOIN t1 ON t2.fkey = t1.id
 
356
WHERE t1.name LIKE 'A%';
 
357
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
358
1       SIMPLE  t1      index   PRIMARY,name    PRIMARY 4       NULL    3       Using where
 
359
1       SIMPLE  t2      ref     fkey    fkey    5       test.t1.id      1       Using index
 
360
EXPLAIN
 
361
SELECT COUNT(*) FROM t2 LEFT JOIN t1 ON t2.fkey = t1.id
 
362
WHERE t1.name LIKE 'A%' OR FALSE;
 
363
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
364
1       SIMPLE  t2      index   NULL    PRIMARY 4       NULL    5       
 
365
1       SIMPLE  t1      eq_ref  PRIMARY PRIMARY 4       test.t2.fkey    1       Using where
 
366
DROP TABLE t1,t2;
 
367
CREATE TABLE t1 (
 
368
id int NOT NULL,
 
369
name varchar(20) NOT NULL,
 
370
dept varchar(20) NOT NULL,
 
371
age tinyint(3) unsigned NOT NULL,
 
372
PRIMARY KEY (id),
 
373
INDEX (name,dept)
 
374
) ENGINE=InnoDB;
 
375
INSERT INTO t1(id, dept, age, name) VALUES
 
376
(3987, 'cs1', 10, 'rs1'), (3988, 'cs2', 20, 'rs1'), (3995, 'cs3', 10, 'rs2'),
 
377
(3996, 'cs4', 20, 'rs2'), (4003, 'cs5', 10, 'rs3'), (4004, 'cs6', 20, 'rs3'),
 
378
(4011, 'cs7', 10, 'rs4'), (4012, 'cs8', 20, 'rs4'), (4019, 'cs9', 10, 'rs5'),
 
379
(4020, 'cs10', 20, 'rs5'),(4027, 'cs11', 10, 'rs6'),(4028, 'cs12', 20, 'rs6');
 
380
EXPLAIN SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
 
381
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
382
1       SIMPLE  t1      range   name    name    44      NULL    2       Using where; Using index for group-by
 
383
SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
 
384
name    dept
 
385
rs5     cs10
 
386
rs5     cs9
 
387
DELETE FROM t1;
 
388
EXPLAIN SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
 
389
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
390
1       SIMPLE  t1      range   name    name    44      NULL    2       Using where; Using index for group-by
 
391
SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
 
392
name    dept
 
393
DROP TABLE t1;
 
394
drop table if exists t1;
 
395
show variables like 'innodb_rollback_on_timeout';
 
396
Variable_name   Value
 
397
innodb_rollback_on_timeout      OFF
 
398
create table t1 (a int unsigned not null primary key) engine = innodb;
 
399
insert into t1 values (1);
 
400
commit;
 
401
begin work;
 
402
insert into t1 values (2);
 
403
select * from t1;
 
404
a
 
405
1
 
406
2
 
407
begin work;
 
408
insert into t1 values (5);
 
409
select * from t1;
 
410
a
 
411
1
 
412
5
 
413
insert into t1 values (2);
 
414
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
 
415
select * from t1;
 
416
a
 
417
1
 
418
5
 
419
commit;
 
420
select * from t1;
 
421
a
 
422
1
 
423
2
 
424
commit;
 
425
select * from t1;
 
426
a
 
427
1
 
428
2
 
429
5
 
430
drop table t1;
 
431
set @save_qcache_size=@@global.query_cache_size;
 
432
set @save_qcache_type=@@global.query_cache_type;
 
433
set global query_cache_size=10*1024*1024;
 
434
set global query_cache_type=1;
 
435
drop table if exists `test`;
 
436
Warnings:
 
437
Note    1051    Unknown table 'test'
 
438
CREATE TABLE `test` (`test1` varchar(3) NOT NULL,
 
439
`test2` varchar(4) NOT NULL,PRIMARY KEY  (`test1`))
 
440
ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
441
INSERT INTO `test` (`test1`, `test2`) VALUES ('tes', '5678');
 
442
select * from test;
 
443
test1   test2
 
444
tes     5678
 
445
INSERT INTO `test` (`test1`, `test2`) VALUES ('tes', '1234')
 
446
ON DUPLICATE KEY UPDATE `test2` = '1234';
 
447
select * from test;
 
448
test1   test2
 
449
tes     1234
 
450
flush tables;
 
451
select * from test;
 
452
test1   test2
 
453
tes     1234
 
454
drop table test;
 
455
set global query_cache_type=@save_qcache_type;
 
456
set global query_cache_size=@save_qcache_size;
 
457
drop table if exists t1;
 
458
show variables like 'innodb_rollback_on_timeout';
 
459
Variable_name   Value
 
460
innodb_rollback_on_timeout      OFF
 
461
create table t1 (a int unsigned not null primary key) engine = innodb;
 
462
insert into t1 values (1);
 
463
commit;
 
464
begin work;
 
465
insert into t1 values (2);
 
466
select * from t1;
 
467
a
 
468
1
 
469
2
 
470
begin work;
 
471
insert into t1 values (5);
 
472
select * from t1;
 
473
a
 
474
1
 
475
5
 
476
insert into t1 values (2);
 
477
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
 
478
select * from t1;
 
479
a
 
480
1
 
481
5
 
482
commit;
 
483
select * from t1;
 
484
a
 
485
1
 
486
2
 
487
commit;
 
488
select * from t1;
 
489
a
 
490
1
 
491
2
 
492
5
 
493
drop table t1;
 
494
create table t1(
 
495
id int auto_increment,
 
496
c char(1) not null,
 
497
counter int not null default 1,
 
498
primary key (id),
 
499
unique key (c)
 
500
) engine=innodb;
 
501
insert into t1 (id, c) values
 
502
(NULL, 'a'),
 
503
(NULL, 'a')
 
504
on duplicate key update id = values(id), counter = counter + 1;
 
505
select * from t1;
 
506
id      c       counter
 
507
2       a       2
 
508
insert into t1 (id, c) values
 
509
(NULL, 'b')
 
510
on duplicate key update id = values(id), counter = counter + 1;
 
511
select * from t1;
 
512
id      c       counter
 
513
2       a       2
 
514
3       b       1
 
515
truncate table t1;
 
516
insert into t1 (id, c) values (NULL, 'a');
 
517
select * from t1;
 
518
id      c       counter
 
519
1       a       1
 
520
insert into t1 (id, c) values (NULL, 'b'), (NULL, 'b')
 
521
on duplicate key update id = values(id), c = values(c), counter = counter + 1;
 
522
select * from t1;
 
523
id      c       counter
 
524
1       a       1
 
525
3       b       2
 
526
insert into t1 (id, c) values (NULL, 'a')
 
527
on duplicate key update id = values(id), c = values(c), counter = counter + 1;
 
528
select * from t1;
 
529
id      c       counter
 
530
3       b       2
 
531
4       a       2
 
532
drop table t1;
 
533
CREATE TABLE t1(
 
534
id int AUTO_INCREMENT PRIMARY KEY,
 
535
stat_id int NOT NULL,
 
536
acct_id int DEFAULT NULL,
 
537
INDEX idx1 (stat_id, acct_id),
 
538
INDEX idx2 (acct_id)
 
539
) ENGINE=MyISAM;
 
540
CREATE TABLE t2(
 
541
id int AUTO_INCREMENT PRIMARY KEY,
 
542
stat_id int NOT NULL,
 
543
acct_id int DEFAULT NULL,
 
544
INDEX idx1 (stat_id, acct_id),
 
545
INDEX idx2 (acct_id)
 
546
) ENGINE=InnoDB;
 
547
INSERT INTO t1(stat_id,acct_id) VALUES
 
548
(1,759), (2,831), (3,785), (4,854), (1,921),
 
549
(1,553), (2,589), (3,743), (2,827), (2,545),
 
550
(4,779), (4,783), (1,597), (1,785), (4,832),
 
551
(1,741), (1,833), (3,788), (2,973), (1,907);
 
552
INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
 
553
INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
 
554
INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
 
555
INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
 
556
INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
 
557
INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
 
558
INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
 
559
INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
 
560
INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
 
561
INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
 
562
INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
 
563
UPDATE t1 SET acct_id=785 
 
564
WHERE MOD(stat_id,2)=0 AND MOD(id,stat_id)=MOD(acct_id,stat_id);
 
565
OPTIMIZE TABLE t1;
 
566
Table   Op      Msg_type        Msg_text
 
567
test.t1 optimize        status  OK
 
568
SELECT COUNT(*) FROM t1;
 
569
COUNT(*)
 
570
40960
 
571
SELECT COUNT(*) FROM t1 WHERE acct_id=785;
 
572
COUNT(*)
 
573
8702
 
574
EXPLAIN SELECT COUNT(*) FROM t1 WHERE stat_id IN (1,3) AND acct_id=785;
 
575
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
576
1       SIMPLE  t1      range   idx1,idx2       idx1    9       NULL    2       Using where; Using index
 
577
INSERT INTO t2 SELECT * FROM t1;
 
578
OPTIMIZE TABLE t2;
 
579
Table   Op      Msg_type        Msg_text
 
580
test.t2 optimize        status  OK
 
581
EXPLAIN SELECT COUNT(*) FROM t2 WHERE stat_id IN (1,3) AND acct_id=785;
 
582
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
583
1       SIMPLE  t2      range   idx1,idx2       idx1    9       NULL    2       Using where; Using index
 
584
DROP TABLE t1,t2;
 
585
create table t1(a int) engine=innodb;
 
586
alter table t1 comment '123';
 
587
show create table t1;
 
588
Table   Create Table
 
589
t1      CREATE TABLE `t1` (
 
590
  `a` int(11) DEFAULT NULL
 
591
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='123'
 
592
drop table t1;
 
593
CREATE TABLE t1 (a CHAR(2), KEY (a)) ENGINE = InnoDB DEFAULT CHARSET=UTF8;
 
594
INSERT INTO t1 VALUES ('uk'),('bg');
 
595
SELECT * FROM t1 WHERE a = 'uk';
 
596
a
 
597
uk
 
598
DELETE FROM t1 WHERE a = 'uk';
 
599
SELECT * FROM t1 WHERE a = 'uk';
 
600
a
 
601
UPDATE t1 SET a = 'us' WHERE a = 'uk';
 
602
SELECT * FROM t1 WHERE a = 'uk';
 
603
a
 
604
CREATE TABLE t2 (a CHAR(2), KEY (a)) ENGINE = InnoDB;
 
605
INSERT INTO t2 VALUES ('uk'),('bg');
 
606
SELECT * FROM t2 WHERE a = 'uk';
 
607
a
 
608
uk
 
609
DELETE FROM t2 WHERE a = 'uk';
 
610
SELECT * FROM t2 WHERE a = 'uk';
 
611
a
 
612
INSERT INTO t2 VALUES ('uk');
 
613
UPDATE t2 SET a = 'us' WHERE a = 'uk';
 
614
SELECT * FROM t2 WHERE a = 'uk';
 
615
a
 
616
CREATE TABLE t3 (a CHAR(2), KEY (a)) ENGINE = MyISAM;
 
617
INSERT INTO t3 VALUES ('uk'),('bg');
 
618
SELECT * FROM t3 WHERE a = 'uk';
 
619
a
 
620
uk
 
621
DELETE FROM t3 WHERE a = 'uk';
 
622
SELECT * FROM t3 WHERE a = 'uk';
 
623
a
 
624
INSERT INTO t3 VALUES ('uk');
 
625
UPDATE t3 SET a = 'us' WHERE a = 'uk';
 
626
SELECT * FROM t3 WHERE a = 'uk';
 
627
a
 
628
DROP TABLE t1,t2,t3;
 
629
create table t1 (a int) engine=innodb;
 
630
select * from bug29807;
 
631
ERROR 42S02: Table 'test.bug29807' doesn't exist
 
632
drop table t1;
 
633
drop table bug29807;
 
634
ERROR 42S02: Unknown table 'bug29807'
 
635
create table bug29807 (a int);
 
636
drop table bug29807;
 
637
CREATE TABLE t1 (a INT) ENGINE=InnoDB;
 
638
CREATE TABLE t2 (a INT) ENGINE=InnoDB;
 
639
switch to connection c1
 
640
SET AUTOCOMMIT=0;
 
641
INSERT INTO t2 VALUES (1);
 
642
switch to connection c2
 
643
SET AUTOCOMMIT=0;
 
644
LOCK TABLES t1 READ, t2 READ;
 
645
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
 
646
switch to connection c1
 
647
COMMIT;
 
648
INSERT INTO t1 VALUES (1);
 
649
switch to connection default
 
650
SET AUTOCOMMIT=default;
 
651
DROP TABLE t1,t2;
 
652
CREATE TABLE t1 (
 
653
id int NOT NULL auto_increment PRIMARY KEY,
 
654
b int NOT NULL,
 
655
c datetime NOT NULL,
 
656
INDEX idx_b(b),
 
657
INDEX idx_c(c)
 
658
) ENGINE=InnoDB;
 
659
CREATE TABLE t2 (
 
660
b int NOT NULL auto_increment PRIMARY KEY,
 
661
c datetime NOT NULL
 
662
) ENGINE= MyISAM;
 
663
INSERT INTO t2(c) VALUES ('2007-01-01');
 
664
INSERT INTO t2(c) SELECT c FROM t2;
 
665
INSERT INTO t2(c) SELECT c FROM t2;
 
666
INSERT INTO t2(c) SELECT c FROM t2;
 
667
INSERT INTO t2(c) SELECT c FROM t2;
 
668
INSERT INTO t2(c) SELECT c FROM t2;
 
669
INSERT INTO t2(c) SELECT c FROM t2;
 
670
INSERT INTO t2(c) SELECT c FROM t2;
 
671
INSERT INTO t2(c) SELECT c FROM t2;
 
672
INSERT INTO t2(c) SELECT c FROM t2;
 
673
INSERT INTO t2(c) SELECT c FROM t2;
 
674
INSERT INTO t1(b,c) SELECT b,c FROM t2;
 
675
UPDATE t2 SET c='2007-01-02';
 
676
INSERT INTO t1(b,c) SELECT b,c FROM t2;
 
677
UPDATE t2 SET c='2007-01-03';
 
678
INSERT INTO t1(b,c) SELECT b,c FROM t2;
 
679
set @@sort_buffer_size=8192;
 
680
Warnings:
 
681
Warning 1292    Truncated incorrect sort_buffer_size value: '8192'
 
682
SELECT COUNT(*) FROM t1;
 
683
COUNT(*)
 
684
3072
 
685
EXPLAIN 
 
686
SELECT COUNT(*) FROM t1 
 
687
WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
 
688
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
689
1       SIMPLE  t1      ALL     idx_b,idx_c     NULL    NULL    NULL    #       Using where
 
690
SELECT COUNT(*) FROM t1 
 
691
WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
 
692
COUNT(*)
 
693
3072
 
694
EXPLAIN 
 
695
SELECT COUNT(*) FROM t1 FORCE INDEX(idx_b, idx_c) 
 
696
WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
 
697
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
698
1       SIMPLE  t1      index_merge     idx_b,idx_c     idx_c,idx_b     8,4     NULL    #       Using sort_union(idx_c,idx_b); Using where
 
699
SELECT COUNT(*) FROM t1 FORCE INDEX(idx_b, idx_c)
 
700
WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
 
701
COUNT(*)
 
702
3072
 
703
set @@sort_buffer_size=default;
 
704
DROP TABLE t1,t2;
 
705
CREATE TABLE t1 (a int, b int);
 
706
insert into t1 values (1,1),(1,2);
 
707
CREATE TABLE t2 (primary key (a)) select * from t1;
 
708
ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
 
709
drop table if exists t2;
 
710
Warnings:
 
711
Note    1051    Unknown table 't2'
 
712
CREATE TEMPORARY TABLE t2 (primary key (a)) select * from t1;
 
713
ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
 
714
drop table if exists t2;
 
715
Warnings:
 
716
Note    1051    Unknown table 't2'
 
717
CREATE TABLE t2 (a int, b int, primary key (a));
 
718
BEGIN;
 
719
INSERT INTO t2 values(100,100);
 
720
CREATE TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
 
721
ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
 
722
SELECT * from t2;
 
723
a       b
 
724
100     100
 
725
ROLLBACK;
 
726
SELECT * from t2;
 
727
a       b
 
728
100     100
 
729
TRUNCATE table t2;
 
730
INSERT INTO t2 select * from t1;
 
731
ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
 
732
SELECT * from t2;
 
733
a       b
 
734
drop table t2;
 
735
CREATE TEMPORARY TABLE t2 (a int, b int, primary key (a));
 
736
BEGIN;
 
737
INSERT INTO t2 values(100,100);
 
738
CREATE TEMPORARY TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
 
739
ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
 
740
SELECT * from t2;
 
741
a       b
 
742
100     100
 
743
COMMIT;
 
744
BEGIN;
 
745
INSERT INTO t2 values(101,101);
 
746
CREATE TEMPORARY TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
 
747
ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
 
748
SELECT * from t2;
 
749
a       b
 
750
100     100
 
751
101     101
 
752
ROLLBACK;
 
753
SELECT * from t2;
 
754
a       b
 
755
100     100
 
756
TRUNCATE table t2;
 
757
INSERT INTO t2 select * from t1;
 
758
ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
 
759
SELECT * from t2;
 
760
a       b
 
761
drop table t1,t2;
 
762
create table t1(f1 varchar(800) binary not null, key(f1))
 
763
character set utf8 collate utf8_general_ci;
 
764
Warnings:
 
765
Warning 1071    Specified key was too long; max key length is 767 bytes
 
766
insert into t1 values('aaa');
 
767
drop table t1;
 
768
CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c FLOAT, KEY b(b)) ENGINE = INNODB;
 
769
INSERT INTO t1 VALUES (    1 , 1              , 1);
 
770
INSERT INTO t1 SELECT  a + 1 , MOD(a + 1 , 20), 1 FROM t1;
 
771
INSERT INTO t1 SELECT  a + 2 , MOD(a + 2 , 20), 1 FROM t1;
 
772
INSERT INTO t1 SELECT  a + 4 , MOD(a + 4 , 20), 1 FROM t1;
 
773
INSERT INTO t1 SELECT  a + 8 , MOD(a + 8 , 20), 1 FROM t1;
 
774
INSERT INTO t1 SELECT  a + 16, MOD(a + 16, 20), 1 FROM t1;
 
775
INSERT INTO t1 SELECT  a + 32, MOD(a + 32, 20), 1 FROM t1;
 
776
INSERT INTO t1 SELECT  a + 64, MOD(a + 64, 20), 1 FROM t1;
 
777
EXPLAIN SELECT b, SUM(c) FROM t1 GROUP BY b;
 
778
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
779
1       SIMPLE  t1      index   NULL    b       5       NULL    128     
 
780
EXPLAIN SELECT SQL_BIG_RESULT b, SUM(c) FROM t1 GROUP BY b;
 
781
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
782
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    128     Using filesort
 
783
DROP TABLE t1;
 
784
drop table if exists t1;
 
785
show variables like 'innodb_rollback_on_timeout';
 
786
Variable_name   Value
 
787
innodb_rollback_on_timeout      OFF
 
788
create table t1 (a int unsigned not null primary key) engine = innodb;
 
789
insert into t1 values (1);
 
790
commit;
 
791
begin work;
 
792
insert into t1 values (2);
 
793
select * from t1;
 
794
a
 
795
1
 
796
2
 
797
begin work;
 
798
insert into t1 values (5);
 
799
select * from t1;
 
800
a
 
801
1
 
802
5
 
803
insert into t1 values (2);
 
804
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
 
805
select * from t1;
 
806
a
 
807
1
 
808
5
 
809
commit;
 
810
select * from t1;
 
811
a
 
812
1
 
813
2
 
814
commit;
 
815
select * from t1;
 
816
a
 
817
1
 
818
2
 
819
5
 
820
drop table t1;
 
821
drop table if exists t1;
 
822
create table t1 (a int) engine=innodb;
 
823
alter table t1 alter a set default 1;
 
824
drop table t1;
 
825
 
 
826
Bug#24918 drop table and lock / inconsistent between 
 
827
perm and temp tables
 
828
 
 
829
Check transactional tables under LOCK TABLES
 
830
 
 
831
drop table if exists t24918, t24918_tmp, t24918_trans, t24918_trans_tmp, 
 
832
t24918_access;
 
833
create table t24918_access (id int);
 
834
create table t24918 (id int) engine=myisam;
 
835
create temporary table t24918_tmp (id int) engine=myisam;
 
836
create table t24918_trans (id int) engine=innodb;
 
837
create temporary table t24918_trans_tmp (id int) engine=innodb;
 
838
lock table t24918 write, t24918_tmp write, t24918_trans write, t24918_trans_tmp write;
 
839
drop table t24918;
 
840
select * from t24918_access;
 
841
ERROR HY000: Table 't24918_access' was not locked with LOCK TABLES
 
842
drop table t24918_trans;
 
843
select * from t24918_access;
 
844
ERROR HY000: Table 't24918_access' was not locked with LOCK TABLES
 
845
drop table t24918_trans_tmp;
 
846
select * from t24918_access;
 
847
ERROR HY000: Table 't24918_access' was not locked with LOCK TABLES
 
848
drop table t24918_tmp;
 
849
select * from t24918_access;
 
850
ERROR HY000: Table 't24918_access' was not locked with LOCK TABLES
 
851
unlock tables;
 
852
drop table t24918_access;
 
853
CREATE TABLE t1 (a int, b int, PRIMARY KEY (a), KEY bkey (b)) ENGINE=InnoDB;
 
854
INSERT INTO t1 VALUES (1,2),(3,2),(2,2),(4,2),(5,2),(6,2),(7,2),(8,2);
 
855
INSERT INTO t1 SELECT a + 8, 2 FROM t1;
 
856
INSERT INTO t1 SELECT a + 16, 1 FROM t1;
 
857
EXPLAIN SELECT * FROM t1 WHERE b=2 ORDER BY a;
 
858
id      1
 
859
select_type     SIMPLE
 
860
table   t1
 
861
type    ref
 
862
possible_keys   bkey
 
863
key     bkey
 
864
key_len 5
 
865
ref     const
 
866
rows    16
 
867
Extra   Using where; Using index
 
868
SELECT * FROM t1 WHERE b=2 ORDER BY a;
 
869
a       b
 
870
1       2
 
871
2       2
 
872
3       2
 
873
4       2
 
874
5       2
 
875
6       2
 
876
7       2
 
877
8       2
 
878
9       2
 
879
10      2
 
880
11      2
 
881
12      2
 
882
13      2
 
883
14      2
 
884
15      2
 
885
16      2
 
886
EXPLAIN SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY a;
 
887
id      1
 
888
select_type     SIMPLE
 
889
table   t1
 
890
type    index
 
891
possible_keys   bkey
 
892
key     PRIMARY
 
893
key_len 4
 
894
ref     NULL
 
895
rows    32
 
896
Extra   Using where
 
897
SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY a;
 
898
a       b
 
899
1       2
 
900
2       2
 
901
3       2
 
902
4       2
 
903
5       2
 
904
6       2
 
905
7       2
 
906
8       2
 
907
9       2
 
908
10      2
 
909
11      2
 
910
12      2
 
911
13      2
 
912
14      2
 
913
15      2
 
914
16      2
 
915
17      1
 
916
18      1
 
917
19      1
 
918
20      1
 
919
21      1
 
920
22      1
 
921
23      1
 
922
24      1
 
923
25      1
 
924
26      1
 
925
27      1
 
926
28      1
 
927
29      1
 
928
30      1
 
929
31      1
 
930
32      1
 
931
EXPLAIN SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY b,a;
 
932
id      1
 
933
select_type     SIMPLE
 
934
table   t1
 
935
type    range
 
936
possible_keys   bkey
 
937
key     bkey
 
938
key_len 5
 
939
ref     NULL
 
940
rows    16
 
941
Extra   Using where; Using index
 
942
SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY b,a;
 
943
a       b
 
944
17      1
 
945
18      1
 
946
19      1
 
947
20      1
 
948
21      1
 
949
22      1
 
950
23      1
 
951
24      1
 
952
25      1
 
953
26      1
 
954
27      1
 
955
28      1
 
956
29      1
 
957
30      1
 
958
31      1
 
959
32      1
 
960
1       2
 
961
2       2
 
962
3       2
 
963
4       2
 
964
5       2
 
965
6       2
 
966
7       2
 
967
8       2
 
968
9       2
 
969
10      2
 
970
11      2
 
971
12      2
 
972
13      2
 
973
14      2
 
974
15      2
 
975
16      2
 
976
CREATE TABLE t2 (a int, b int, c int, PRIMARY KEY (a), KEY bkey (b,c))
 
977
ENGINE=InnoDB;
 
978
INSERT INTO t2 VALUES (1,1,1),(3,1,1),(2,1,1),(4,1,1);
 
979
INSERT INTO t2 SELECT a + 4, 1, 1 FROM t2;
 
980
INSERT INTO t2 SELECT a + 8, 1, 1 FROM t2;
 
981
EXPLAIN SELECT * FROM t2 WHERE b=1 ORDER BY a;
 
982
id      1
 
983
select_type     SIMPLE
 
984
table   t2
 
985
type    index
 
986
possible_keys   bkey
 
987
key     PRIMARY
 
988
key_len 4
 
989
ref     NULL
 
990
rows    16
 
991
Extra   Using where; Using index
 
992
SELECT * FROM t2 WHERE b=1 ORDER BY a;
 
993
a       b       c
 
994
1       1       1
 
995
2       1       1
 
996
3       1       1
 
997
4       1       1
 
998
5       1       1
 
999
6       1       1
 
1000
7       1       1
 
1001
8       1       1
 
1002
9       1       1
 
1003
10      1       1
 
1004
11      1       1
 
1005
12      1       1
 
1006
13      1       1
 
1007
14      1       1
 
1008
15      1       1
 
1009
16      1       1
 
1010
EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY a;
 
1011
id      1
 
1012
select_type     SIMPLE
 
1013
table   t2
 
1014
type    ref
 
1015
possible_keys   bkey
 
1016
key     bkey
 
1017
key_len 10
 
1018
ref     const,const
 
1019
rows    8
 
1020
Extra   Using where; Using index
 
1021
SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY a;
 
1022
a       b       c
 
1023
1       1       1
 
1024
2       1       1
 
1025
3       1       1
 
1026
4       1       1
 
1027
5       1       1
 
1028
6       1       1
 
1029
7       1       1
 
1030
8       1       1
 
1031
9       1       1
 
1032
10      1       1
 
1033
11      1       1
 
1034
12      1       1
 
1035
13      1       1
 
1036
14      1       1
 
1037
15      1       1
 
1038
16      1       1
 
1039
EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY b,c,a;
 
1040
id      1
 
1041
select_type     SIMPLE
 
1042
table   t2
 
1043
type    ref
 
1044
possible_keys   bkey
 
1045
key     bkey
 
1046
key_len 10
 
1047
ref     const,const
 
1048
rows    8
 
1049
Extra   Using where; Using index
 
1050
SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY b,c,a;
 
1051
a       b       c
 
1052
1       1       1
 
1053
2       1       1
 
1054
3       1       1
 
1055
4       1       1
 
1056
5       1       1
 
1057
6       1       1
 
1058
7       1       1
 
1059
8       1       1
 
1060
9       1       1
 
1061
10      1       1
 
1062
11      1       1
 
1063
12      1       1
 
1064
13      1       1
 
1065
14      1       1
 
1066
15      1       1
 
1067
16      1       1
 
1068
EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY c,a;
 
1069
id      1
 
1070
select_type     SIMPLE
 
1071
table   t2
 
1072
type    ref
 
1073
possible_keys   bkey
 
1074
key     bkey
 
1075
key_len 10
 
1076
ref     const,const
 
1077
rows    8
 
1078
Extra   Using where; Using index
 
1079
SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY c,a;
 
1080
a       b       c
 
1081
1       1       1
 
1082
2       1       1
 
1083
3       1       1
 
1084
4       1       1
 
1085
5       1       1
 
1086
6       1       1
 
1087
7       1       1
 
1088
8       1       1
 
1089
9       1       1
 
1090
10      1       1
 
1091
11      1       1
 
1092
12      1       1
 
1093
13      1       1
 
1094
14      1       1
 
1095
15      1       1
 
1096
16      1       1
 
1097
DROP TABLE t1,t2;
 
1098
CREATE TABLE t1 (a INT, PRIMARY KEY (a)) ENGINE=InnoDB;
 
1099
INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8);
 
1100
INSERT INTO t1 SELECT a + 8  FROM t1;
 
1101
INSERT INTO t1 SELECT a + 16 FROM t1;
 
1102
CREATE PROCEDURE p1 ()
 
1103
BEGIN
 
1104
DECLARE i INT DEFAULT 50;
 
1105
DECLARE cnt INT;
 
1106
START TRANSACTION;
 
1107
ALTER TABLE t1 ENGINE=InnoDB;
 
1108
COMMIT;
 
1109
START TRANSACTION;
 
1110
WHILE (i > 0) DO
 
1111
SET i = i - 1;
 
1112
SELECT COUNT(*) INTO cnt FROM t1 LOCK IN SHARE MODE;
 
1113
END WHILE;
 
1114
COMMIT;
 
1115
END;|
 
1116
CALL p1();
 
1117
CALL p1();
 
1118
CALL p1();
 
1119
DROP PROCEDURE p1;
 
1120
DROP TABLE t1;
 
1121
create table t1(a text) engine=innodb default charset=utf8;
 
1122
insert into t1 values('aaa');
 
1123
alter table t1 add index(a(1024));
 
1124
Warnings:
 
1125
Warning 1071    Specified key was too long; max key length is 767 bytes
 
1126
Warning 1071    Specified key was too long; max key length is 767 bytes
 
1127
Warning 1071    Specified key was too long; max key length is 767 bytes
 
1128
show create table t1;
 
1129
Table   Create Table
 
1130
t1      CREATE TABLE `t1` (
 
1131
  `a` text,
 
1132
  KEY `a` (`a`(191))
 
1133
) ENGINE=InnoDB DEFAULT CHARSET=utf8
 
1134
drop table t1;
 
1135
CREATE TABLE t1 (
 
1136
a INT,
 
1137
b INT,
 
1138
KEY (b)
 
1139
) ENGINE=InnoDB;
 
1140
INSERT INTO t1 VALUES (1,10), (2,10), (2,20), (3,30);
 
1141
START TRANSACTION;
 
1142
SELECT * FROM t1 WHERE b=20 FOR UPDATE;
 
1143
a       b
 
1144
2       20
 
1145
START TRANSACTION;
 
1146
SELECT * FROM t1 WHERE b=10 ORDER BY A FOR UPDATE;
 
1147
a       b
 
1148
1       10
 
1149
2       10
 
1150
ROLLBACK;
 
1151
ROLLBACK;
 
1152
DROP TABLE t1;
 
1153
CREATE TABLE t1(
 
1154
a INT, 
 
1155
b INT NOT NULL, 
 
1156
c INT NOT NULL, 
 
1157
d INT, 
 
1158
UNIQUE KEY (c,b)
 
1159
) engine=innodb;
 
1160
INSERT INTO t1 VALUES (1,1,1,50), (1,2,3,40), (2,1,3,4);
 
1161
EXPLAIN SELECT c,b,d FROM t1 GROUP BY c,b,d;
 
1162
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
1163
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    3       Using filesort
 
1164
SELECT c,b,d FROM t1 GROUP BY c,b,d;
 
1165
c       b       d
 
1166
1       1       50
 
1167
3       1       4
 
1168
3       2       40
 
1169
EXPLAIN SELECT c,b,d FROM t1 GROUP BY c,b,d ORDER BY NULL;
 
1170
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
1171
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    3       
 
1172
SELECT c,b,d FROM t1 GROUP BY c,b,d ORDER BY NULL;
 
1173
c       b       d
 
1174
1       1       50
 
1175
3       1       4
 
1176
3       2       40
 
1177
EXPLAIN SELECT c,b,d FROM t1 ORDER BY c,b,d;
 
1178
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
1179
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    3       Using filesort
 
1180
SELECT c,b,d FROM t1 ORDER BY c,b,d;
 
1181
c       b       d
 
1182
1       1       50
 
1183
3       1       4
 
1184
3       2       40
 
1185
EXPLAIN SELECT c,b,d FROM t1 GROUP BY c,b;
 
1186
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
1187
1       SIMPLE  t1      index   NULL    c       8       NULL    3       
 
1188
SELECT c,b,d FROM t1 GROUP BY c,b;
 
1189
c       b       d
 
1190
1       1       50
 
1191
3       1       4
 
1192
3       2       40
 
1193
EXPLAIN SELECT c,b   FROM t1 GROUP BY c,b;
 
1194
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
1195
1       SIMPLE  t1      index   NULL    c       8       NULL    3       Using index
 
1196
SELECT c,b   FROM t1 GROUP BY c,b;
 
1197
c       b
 
1198
1       1
 
1199
3       1
 
1200
3       2
 
1201
DROP TABLE t1;
 
1202
CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a), INDEX b (b)) ENGINE=InnoDB;
 
1203
INSERT INTO t1(a,b) VALUES (1,1), (2,2), (3,2);
 
1204
EXPLAIN SELECT * FROM t1 WHERE b=2 ORDER BY a ASC;
 
1205
id      1
 
1206
select_type     SIMPLE
 
1207
table   t1
 
1208
type    ref
 
1209
possible_keys   b
 
1210
key     b
 
1211
key_len 5
 
1212
ref     const
 
1213
rows    1
 
1214
Extra   Using where; Using index
 
1215
SELECT * FROM t1 WHERE b=2 ORDER BY a ASC;
 
1216
a       b
 
1217
2       2
 
1218
3       2
 
1219
EXPLAIN SELECT * FROM t1 WHERE b=2 ORDER BY a DESC;
 
1220
id      1
 
1221
select_type     SIMPLE
 
1222
table   t1
 
1223
type    ref
 
1224
possible_keys   b
 
1225
key     b
 
1226
key_len 5
 
1227
ref     const
 
1228
rows    1
 
1229
Extra   Using where; Using index
 
1230
SELECT * FROM t1 WHERE b=2 ORDER BY a DESC;
 
1231
a       b
 
1232
3       2
 
1233
2       2
 
1234
EXPLAIN SELECT * FROM t1 ORDER BY b ASC, a ASC;
 
1235
id      1
 
1236
select_type     SIMPLE
 
1237
table   t1
 
1238
type    index
 
1239
possible_keys   NULL
 
1240
key     b
 
1241
key_len 5
 
1242
ref     NULL
 
1243
rows    3
 
1244
Extra   Using index
 
1245
SELECT * FROM t1 ORDER BY b ASC, a ASC;
 
1246
a       b
 
1247
1       1
 
1248
2       2
 
1249
3       2
 
1250
EXPLAIN SELECT * FROM t1 ORDER BY b DESC, a DESC;
 
1251
id      1
 
1252
select_type     SIMPLE
 
1253
table   t1
 
1254
type    index
 
1255
possible_keys   NULL
 
1256
key     b
 
1257
key_len 5
 
1258
ref     NULL
 
1259
rows    3
 
1260
Extra   Using index
 
1261
SELECT * FROM t1 ORDER BY b DESC, a DESC;
 
1262
a       b
 
1263
3       2
 
1264
2       2
 
1265
1       1
 
1266
EXPLAIN SELECT * FROM t1 ORDER BY b ASC, a DESC;
 
1267
id      1
 
1268
select_type     SIMPLE
 
1269
table   t1
 
1270
type    index
 
1271
possible_keys   NULL
 
1272
key     PRIMARY
 
1273
key_len 4
 
1274
ref     NULL
 
1275
rows    3
 
1276
Extra   Using filesort
 
1277
SELECT * FROM t1 ORDER BY b ASC, a DESC;
 
1278
a       b
 
1279
1       1
 
1280
3       2
 
1281
2       2
 
1282
EXPLAIN SELECT * FROM t1 ORDER BY b DESC, a ASC;
 
1283
id      1
 
1284
select_type     SIMPLE
 
1285
table   t1
 
1286
type    index
 
1287
possible_keys   NULL
 
1288
key     PRIMARY
 
1289
key_len 4
 
1290
ref     NULL
 
1291
rows    3
 
1292
Extra   Using filesort
 
1293
SELECT * FROM t1 ORDER BY b DESC, a ASC;
 
1294
a       b
 
1295
2       2
 
1296
3       2
 
1297
1       1
 
1298
DROP TABLE t1;
 
1299
 
 
1300
#
 
1301
# Bug#27610: ALTER TABLE ROW_FORMAT=... does not rebuild the table.
 
1302
#
 
1303
 
 
1304
# - prepare;
 
1305
 
 
1306
DROP TABLE IF EXISTS t1;
 
1307
 
 
1308
CREATE TABLE t1(c INT)
 
1309
ENGINE = InnoDB
 
1310
ROW_FORMAT = COMPACT;
 
1311
 
 
1312
# - initial check;
 
1313
 
 
1314
SELECT table_schema, table_name, row_format
 
1315
FROM INFORMATION_SCHEMA.TABLES
 
1316
WHERE table_schema = DATABASE() AND table_name = 't1';
 
1317
table_schema    table_name      row_format
 
1318
test    t1      Compact
 
1319
 
 
1320
# - change ROW_FORMAT and check;
 
1321
 
 
1322
ALTER TABLE t1 ROW_FORMAT = REDUNDANT;
 
1323
 
 
1324
SELECT table_schema, table_name, row_format
 
1325
FROM INFORMATION_SCHEMA.TABLES
 
1326
WHERE table_schema = DATABASE() AND table_name = 't1';
 
1327
table_schema    table_name      row_format
 
1328
test    t1      Redundant
 
1329
 
 
1330
# - that's it, cleanup.
 
1331
 
 
1332
DROP TABLE t1;
 
1333
create table t1(a char(10) not null, unique key aa(a(1)),
 
1334
b char(4) not null, unique key bb(b(4))) engine=innodb;
 
1335
desc t1;
 
1336
Field   Type    Null    Key     Default Extra
 
1337
a       char(10)        NO      UNI     NULL    
 
1338
b       char(4) NO      PRI     NULL    
 
1339
show create table t1;
 
1340
Table   Create Table
 
1341
t1      CREATE TABLE `t1` (
 
1342
  `a` char(10) NOT NULL,
 
1343
  `b` char(4) NOT NULL,
 
1344
  UNIQUE KEY `bb` (`b`),
 
1345
  UNIQUE KEY `aa` (`a`(1))
 
1346
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
1347
drop table t1;
 
1348
CREATE TABLE t1 (id int, type char(6), d int, INDEX idx(id,d)) ENGINE=InnoDB;
 
1349
INSERT INTO t1 VALUES 
 
1350
(191, 'member', 1), (NULL, 'member', 3), (NULL, 'member', 4), (201, 'member', 2);
 
1351
EXPLAIN SELECT * FROM t1 WHERE id=191 OR id IS NULL ORDER BY d;
 
1352
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
1353
1       SIMPLE  t1      ALL     idx     NULL    NULL    NULL    4       Using where; Using filesort
 
1354
SELECT * FROM t1 WHERE id=191 OR id IS NULL ORDER BY d;
 
1355
id      type    d
 
1356
191     member  1
 
1357
NULL    member  3
 
1358
NULL    member  4
 
1359
DROP TABLE t1;
 
1360
set @my_innodb_autoextend_increment=@@global.innodb_autoextend_increment;
 
1361
set global innodb_autoextend_increment=8;
 
1362
set global innodb_autoextend_increment=@my_innodb_autoextend_increment;
 
1363
set @my_innodb_commit_concurrency=@@global.innodb_commit_concurrency;
 
1364
set global innodb_commit_concurrency=0;
 
1365
set global innodb_commit_concurrency=@my_innodb_commit_concurrency;
 
1366
End of 5.0 tests
 
1367
CREATE TABLE `t2` (
 
1368
`k` int(11) NOT NULL auto_increment,
 
1369
`a` int(11) default NULL,
 
1370
`c` int(11) default NULL,
 
1371
PRIMARY KEY  (`k`),
 
1372
UNIQUE KEY `idx_1` (`a`)
 
1373
);
 
1374
insert into t2 ( a ) values ( 6 ) on duplicate key update c =
 
1375
ifnull( c,
 
1376
0 ) + 1;
 
1377
insert into t2 ( a ) values ( 7 ) on duplicate key update c =
 
1378
ifnull( c,
 
1379
0 ) + 1;
 
1380
select last_insert_id();
 
1381
last_insert_id()
 
1382
2
 
1383
select * from t2;
 
1384
k       a       c
 
1385
1       6       NULL
 
1386
2       7       NULL
 
1387
insert into t2 ( a ) values ( 6 ) on duplicate key update c =
 
1388
ifnull( c,
 
1389
0 ) + 1;
 
1390
select last_insert_id();
 
1391
last_insert_id()
 
1392
2
 
1393
select last_insert_id(0);
 
1394
last_insert_id(0)
 
1395
0
 
1396
insert into t2 ( a ) values ( 6 ) on duplicate key update c =
 
1397
ifnull( c,
 
1398
0 ) + 1;
 
1399
select last_insert_id();
 
1400
last_insert_id()
 
1401
0
 
1402
select * from t2;
 
1403
k       a       c
 
1404
1       6       2
 
1405
2       7       NULL
 
1406
insert ignore into t2 values (null,6,1),(10,8,1);
 
1407
select last_insert_id();
 
1408
last_insert_id()
 
1409
0
 
1410
insert ignore into t2 values (null,6,1),(null,8,1),(null,15,1),(null,20,1);
 
1411
select last_insert_id();
 
1412
last_insert_id()
 
1413
11
 
1414
select * from t2;
 
1415
k       a       c
 
1416
1       6       2
 
1417
2       7       NULL
 
1418
10      8       1
 
1419
11      15      1
 
1420
12      20      1
 
1421
insert into t2 ( a ) values ( 6 ) on duplicate key update c =
 
1422
ifnull( c,
 
1423
0 ) + 1, k=last_insert_id(k);
 
1424
select last_insert_id();
 
1425
last_insert_id()
 
1426
1
 
1427
select * from t2;
 
1428
k       a       c
 
1429
1       6       3
 
1430
2       7       NULL
 
1431
10      8       1
 
1432
11      15      1
 
1433
12      20      1
 
1434
drop table t2;
 
1435
drop table if exists t1, t2;
 
1436
create table t1 (i int);
 
1437
alter table t1 modify i int default 1;
 
1438
alter table t1 modify i int default 2, rename t2;
 
1439
lock table t2 write;
 
1440
alter table t2 modify i int default 3;
 
1441
unlock tables;
 
1442
lock table t2 write;
 
1443
alter table t2 modify i int default 4, rename t1;
 
1444
unlock tables;
 
1445
drop table t1;
 
1446
drop table if exists t1;
 
1447
create table t1 (i int);
 
1448
insert into t1 values ();
 
1449
lock table t1 write;
 
1450
alter table t1 modify i int default 1;
 
1451
insert into t1 values ();
 
1452
select * from t1;
 
1453
i
 
1454
NULL
 
1455
1
 
1456
alter table t1 change i c char(10) default "Two";
 
1457
insert into t1 values ();
 
1458
select * from t1;
 
1459
c
 
1460
NULL
 
1461
1
 
1462
Two
 
1463
unlock tables;
 
1464
select * from t1;
 
1465
c
 
1466
NULL
 
1467
1
 
1468
Two
 
1469
drop tables t1;
 
1470
create table t1(f1 varchar(5) unique, f2 timestamp NOT NULL DEFAULT
 
1471
CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);
 
1472
insert into t1(f1) values(1);
 
1473
select @a:=f2 from t1;
 
1474
@a:=f2
 
1475
#
 
1476
update t1 set f1=1;
 
1477
select @b:=f2 from t1;
 
1478
@b:=f2
 
1479
#
 
1480
select if(@a=@b,"ok","wrong");
 
1481
if(@a=@b,"ok","wrong")
 
1482
ok
 
1483
insert into t1(f1) values (1) on duplicate key update f1="1";
 
1484
select @b:=f2 from t1;
 
1485
@b:=f2
 
1486
#
 
1487
select if(@a=@b,"ok","wrong");
 
1488
if(@a=@b,"ok","wrong")
 
1489
ok
 
1490
insert into t1(f1) select f1 from t1 on duplicate key update f1="1";
 
1491
select @b:=f2 from t1;
 
1492
@b:=f2
 
1493
#
 
1494
select if(@a=@b,"ok","wrong");
 
1495
if(@a=@b,"ok","wrong")
 
1496
ok
 
1497
drop table t1;
 
1498
SET SESSION AUTOCOMMIT = 0;
 
1499
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
 
1500
# Switch to connection con1
 
1501
CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(256))
 
1502
ENGINE = InnoDB;
 
1503
INSERT INTO t1 VALUES (1,2);
 
1504
# 1. test for locking:
 
1505
BEGIN;
 
1506
UPDATE t1 SET b = 12 WHERE a = 1;
 
1507
affected rows: 1
 
1508
info: Rows matched: 1  Changed: 1  Warnings: 0
 
1509
SELECT * FROM t1;
 
1510
a       b
 
1511
1       12
 
1512
# Switch to connection con2
 
1513
UPDATE t1 SET b = 21 WHERE a = 1;
 
1514
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
 
1515
# Switch to connection con1
 
1516
SELECT * FROM t1;
 
1517
a       b
 
1518
1       12
 
1519
ROLLBACK;
 
1520
# 2. test for serialized update:
 
1521
CREATE TABLE t2 (a INT);
 
1522
TRUNCATE t1;
 
1523
INSERT INTO t1 VALUES (1,'init');
 
1524
CREATE PROCEDURE p1()
 
1525
BEGIN
 
1526
UPDATE t1 SET b = CONCAT(b, '+con2')  WHERE a = 1;
 
1527
INSERT INTO t2 VALUES ();
 
1528
END|
 
1529
BEGIN;
 
1530
UPDATE t1 SET b = CONCAT(b, '+con1') WHERE a = 1;
 
1531
affected rows: 1
 
1532
info: Rows matched: 1  Changed: 1  Warnings: 0
 
1533
SELECT * FROM t1;
 
1534
a       b
 
1535
1       init+con1
 
1536
# Switch to connection con2
 
1537
CALL p1;;
 
1538
# Switch to connection con1
 
1539
SELECT * FROM t1;
 
1540
a       b
 
1541
1       init+con1
 
1542
COMMIT;
 
1543
SELECT * FROM t1;
 
1544
a       b
 
1545
1       init+con1
 
1546
# Switch to connection con2
 
1547
SELECT * FROM t1;
 
1548
a       b
 
1549
1       init+con1+con2
 
1550
# Switch to connection con1
 
1551
# 3. test for updated key column:
 
1552
TRUNCATE t1;
 
1553
TRUNCATE t2;
 
1554
INSERT INTO t1 VALUES (1,'init');
 
1555
BEGIN;
 
1556
UPDATE t1 SET a = 2, b = CONCAT(b, '+con1') WHERE a = 1;
 
1557
affected rows: 1
 
1558
info: Rows matched: 1  Changed: 1  Warnings: 0
 
1559
SELECT * FROM t1;
 
1560
a       b
 
1561
2       init+con1
 
1562
# Switch to connection con2
 
1563
CALL p1;;
 
1564
# Switch to connection con1
 
1565
SELECT * FROM t1;
 
1566
a       b
 
1567
2       init+con1
 
1568
COMMIT;
 
1569
SELECT * FROM t1;
 
1570
a       b
 
1571
2       init+con1
 
1572
# Switch to connection con2
 
1573
SELECT * FROM t1;
 
1574
a       b
 
1575
2       init+con1
 
1576
DROP PROCEDURE p1;
 
1577
DROP TABLE t1, t2;
 
1578
CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL, PRIMARY KEY (a,b)) engine=innodb;
 
1579
CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
 
1580
CONSTRAINT c2 FOREIGN KEY f2 (c) REFERENCES t1 (a,b) ON UPDATE NO ACTION) engine=innodb;
 
1581
ERROR 42000: Incorrect foreign key definition for 'f2': Key reference and table reference don't match
 
1582
CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
 
1583
CONSTRAINT c2 FOREIGN KEY (c) REFERENCES t1 (a,b) ON UPDATE NO ACTION) engine=innodb;
 
1584
ERROR 42000: Incorrect foreign key definition for 'c2': Key reference and table reference don't match
 
1585
CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
 
1586
CONSTRAINT c1 FOREIGN KEY c2 (c) REFERENCES t1 (a) ON DELETE NO ACTION,
 
1587
CONSTRAINT c2 FOREIGN KEY (c) REFERENCES t1 (a) ON UPDATE NO ACTION) engine=innodb;
 
1588
ALTER TABLE t2 DROP FOREIGN KEY c2;
 
1589
DROP TABLE t2;
 
1590
CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
 
1591
FOREIGN KEY (c) REFERENCES t1 (a,k) ON UPDATE NO ACTION) engine=innodb;
 
1592
ERROR 42000: Incorrect foreign key definition for 'foreign key without name': Key reference and table reference don't match
 
1593
CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
 
1594
FOREIGN KEY f1 (c) REFERENCES t1 (a,k) ON UPDATE NO ACTION) engine=innodb;
 
1595
ERROR 42000: Incorrect foreign key definition for 'f1': Key reference and table reference don't match
 
1596
CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
 
1597
CONSTRAINT c1 FOREIGN KEY f1 (c) REFERENCES t1 (a) ON DELETE NO ACTION,
 
1598
CONSTRAINT c2 FOREIGN KEY (c) REFERENCES t1 (a) ON UPDATE NO ACTION,
 
1599
FOREIGN KEY f3 (c) REFERENCES t1 (a) ON UPDATE NO ACTION,
 
1600
FOREIGN KEY (c) REFERENCES t1 (a) ON UPDATE NO ACTION) engine=innodb;
 
1601
SHOW CREATE TABLE t2;
 
1602
Table   Create Table
 
1603
t2      CREATE TABLE `t2` (
 
1604
  `c` int(11) NOT NULL,
 
1605
  `d` int(11) NOT NULL,
 
1606
  PRIMARY KEY (`c`,`d`),
 
1607
  CONSTRAINT `c1` FOREIGN KEY (`c`) REFERENCES `t1` (`a`) ON DELETE NO ACTION,
 
1608
  CONSTRAINT `c2` FOREIGN KEY (`c`) REFERENCES `t1` (`a`) ON UPDATE NO ACTION,
 
1609
  CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`c`) REFERENCES `t1` (`a`) ON UPDATE NO ACTION,
 
1610
  CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`c`) REFERENCES `t1` (`a`) ON UPDATE NO ACTION
 
1611
) ENGINE=InnoDB DEFAULT CHARSET=latin1
 
1612
DROP TABLE t2;
 
1613
DROP TABLE t1;
 
1614
create table t1 (a int auto_increment primary key) engine=innodb;
 
1615
alter table t1 order by a;
 
1616
Warnings:
 
1617
Warning 1105    ORDER BY ignored as there is a user-defined clustered index in the table 't1'
 
1618
drop table t1;
 
1619
CREATE TABLE t1
 
1620
(vid integer NOT NULL,
 
1621
tid integer NOT NULL,
 
1622
idx integer NOT NULL,
 
1623
name varchar(128) NOT NULL,
 
1624
type varchar(128) NULL,
 
1625
PRIMARY KEY(idx, vid, tid),
 
1626
UNIQUE(vid, tid, name)
 
1627
) ENGINE=InnoDB;
 
1628
INSERT INTO t1 VALUES
 
1629
(1,1,1,'pk',NULL),(2,1,1,'pk',NULL),(3,1,1,'pk',NULL),(4,1,1,'c1',NULL),
 
1630
(5,1,1,'pk',NULL),(1,1,2,'c1',NULL),(2,1,2,'c1',NULL),(3,1,2,'c1',NULL),
 
1631
(4,1,2,'c2',NULL),(5,1,2,'c1',NULL),(2,1,3,'c2',NULL),(3,1,3,'c2',NULL),
 
1632
(4,1,3,'pk',NULL),(5,1,3,'c2',NULL),
 
1633
(2,1,4,'c_extra',NULL),(3,1,4,'c_extra',NULL);
 
1634
EXPLAIN SELECT * FROM t1 WHERE tid = 1 AND vid = 3 ORDER BY idx DESC;
 
1635
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
 
1636
1       SIMPLE  t1      index   vid     PRIMARY 12      NULL    16      Using where
 
1637
SELECT * FROM t1 WHERE tid = 1 AND vid = 3 ORDER BY idx DESC;
 
1638
vid     tid     idx     name    type
 
1639
3       1       4       c_extra NULL
 
1640
3       1       3       c2      NULL
 
1641
3       1       2       c1      NULL
 
1642
3       1       1       pk      NULL
 
1643
DROP TABLE t1;
 
1644
DROP TABLE IF EXISTS t1;
 
1645
DROP TABLE IF EXISTS t2;
 
1646
CREATE TABLE t1(id INT PRIMARY KEY)
 
1647
ENGINE=innodb;
 
1648
CREATE TABLE t2(
 
1649
t1_id INT PRIMARY KEY,
 
1650
CONSTRAINT fk1 FOREIGN KEY (t1_id) REFERENCES t1(id))
 
1651
ENGINE=innodb;
 
1652
 
 
1653
ALTER TABLE t1 CHANGE id id2 INT;
 
1654
 
 
1655
DROP TABLE t2;
 
1656
DROP TABLE t1;
 
1657
End of 5.1 tests