~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/innobase/tests/r/innodb_mysql.result

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-10-02 14:17:48 UTC
  • mfrom: (1.1.1 upstream)
  • mto: (2.1.17 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20101002141748-m6vbfbfjhrw1153e
Tags: 2010.09.1802-1
* New upstream release.
* Removed pid-file argument hack.
* Updated GPL-2 address to be new address.
* Directly copy in drizzledump.1 since debian doesn't have sphinx 1.0 yet.
* Link to jquery from libjs-jquery. Add it as a depend.
* Add drizzled.8 symlink to the install files.

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