~clint-fewbar/ubuntu/natty/mysql-5.1/merge-5.1.49-2

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2010-08-04 13:18:27 UTC
  • mfrom: (1.2.2 upstream) (2.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20100804131827-4tjg88vr9dd49s3k
Tags: 5.1.49-1ubuntu1
* Merge from debian unstable:
  + debian/control:
     * Update maintainer according to spec.
     * Move section from "misc" to "database".
     * Added libmysqlclient16-dev an empty transitional package. 
     * Added mysql-client-core-5.1 package.
     * Suggest mailx for mysql-server-5.1
     * Add mysql-testsuite package so you can run the testsuite seperately.
  + debian/additions/my.cnf:
    * Remove language options. Error message files are located in a different directory in Mysql
      5.0. Setting the language option to use /usr/share/mysql/english breaks Mysql 5.0. Both 5.0
      and 5.1 use a different value that works. (LP: #316974)
  + Add apparmor profile:
    + debian/apparmor-profile: apparmor-profile
    + debian/rules, debian/mysql-server-5.1.files: install apparmor profile
    + debian/mysql-server-5.1.dirs: add etc/apparmor.d/fore-complain
    + debian/mysql-server-5.1.postrm: remove symlink in force-complain/ on purge.
    + debian/mysql-server-5.1.README.Debian: add apparmor documentation.
    + debian/additions/my.cnf: Add warning about apparmor. (LP: #201799)
    + debian/mysql-server-5.1.postinst: reload apparmor profiles
  * Convert the package from sysvinit to upstart:
    + debian/mysql-server-5.1.mysql.upstart: Add upstart script.
    + debian/mysql-server-5.1.mysql.init: Dropped, unused now with upstart.
    + debian/additions/mysqld_safe_syslog.cnf: Dropped, unused now with upstart.
    + debian/additons/my.cnf: Remove pid declaration and setup error logging to /var/log/mysql since
      we're not piping anything around logger anymore.
    + debian/rules, debian/mysql-server-5.1.logcheck.ignore.{paranoid,worstation},
      debian/mysql-server-5.1.logcheck.ignore.server: : Remove references to mysqld_safe
    + debian/patches/38_scripts_mysqld_safe.sh_signals.dpatch: Dropped
  * Added -fno-strict-aliasing to CFLAGS to get around mysql testsuite build failures.
  * Add Apport hook (LP: #354188):
    + debian/mysql-server-5.1.py: apport package hook
    + debian/rules: Make it installable
  * debian/mysql-server-5.1.mysql-server.logrotate: Check to see if mysql is running before
    running logrotate. (LP: #513135)
  * Make the testsuite installable. (LP: #530752)
    + debian/mysql-server-5.1.files, debian/rules: install apport package hook
  * debian/mysql-server-5.1.preinst: Set mysql user's home directory
    to /nonexistent to protect against having the /var/lib/mysql
    user-writeable. If an attacker can trick mysqld into creating
    dot files in the home directory, he could do .rhost-like attacks
    on the system. (LP: #293258)
  * debian/control: mysql-client-5.1 should depend on mysql-core-client-5.1.
    (LP: #590952) 

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    name    23      NULL    3       Using where; Using index
359
 
1       SIMPLE  t2      ref     fkey    fkey    5       test.t1.id      1       Using where; 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    fkey    5       NULL    5       Using index
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
 
# Masking (#) number in "rows" column of the following EXPLAIN output, as it may vary (bug#47746).
389
 
EXPLAIN SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
390
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
391
 
1       SIMPLE  t1      range   name    name    44      NULL    #       Using where; Using index for group-by
392
 
SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
393
 
name    dept
394
 
DROP TABLE t1;
395
 
drop table if exists t1;
396
 
show variables like 'innodb_rollback_on_timeout';
397
 
Variable_name   Value
398
 
innodb_rollback_on_timeout      OFF
399
 
create table t1 (a int unsigned not null primary key) engine = innodb;
400
 
insert into t1 values (1);
401
 
commit;
402
 
begin work;
403
 
insert into t1 values (2);
404
 
select * from t1;
405
 
a
406
 
1
407
 
2
408
 
begin work;
409
 
insert into t1 values (5);
410
 
select * from t1;
411
 
a
412
 
1
413
 
5
414
 
insert into t1 values (2);
415
 
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
416
 
select * from t1;
417
 
a
418
 
1
419
 
5
420
 
commit;
421
 
select * from t1;
422
 
a
423
 
1
424
 
2
425
 
commit;
426
 
select * from t1;
427
 
a
428
 
1
429
 
2
430
 
5
431
 
drop table t1;
432
 
set @save_qcache_size=@@global.query_cache_size;
433
 
set @save_qcache_type=@@global.query_cache_type;
434
 
set global query_cache_size=10*1024*1024;
435
 
set global query_cache_type=1;
436
 
drop table if exists `test`;
437
 
Warnings:
438
 
Note    1051    Unknown table 'test'
439
 
CREATE TABLE `test` (`test1` varchar(3) NOT NULL,
440
 
`test2` varchar(4) NOT NULL,PRIMARY KEY  (`test1`))
441
 
ENGINE=InnoDB DEFAULT CHARSET=latin1;
442
 
INSERT INTO `test` (`test1`, `test2`) VALUES ('tes', '5678');
443
 
select * from test;
444
 
test1   test2
445
 
tes     5678
446
 
INSERT INTO `test` (`test1`, `test2`) VALUES ('tes', '1234')
447
 
ON DUPLICATE KEY UPDATE `test2` = '1234';
448
 
select * from test;
449
 
test1   test2
450
 
tes     1234
451
 
flush tables;
452
 
select * from test;
453
 
test1   test2
454
 
tes     1234
455
 
drop table test;
456
 
set global query_cache_type=@save_qcache_type;
457
 
set global query_cache_size=@save_qcache_size;
458
 
drop table if exists t1;
459
 
show variables like 'innodb_rollback_on_timeout';
460
 
Variable_name   Value
461
 
innodb_rollback_on_timeout      OFF
462
 
create table t1 (a int unsigned not null primary key) engine = innodb;
463
 
insert into t1 values (1);
464
 
commit;
465
 
begin work;
466
 
insert into t1 values (2);
467
 
select * from t1;
468
 
a
469
 
1
470
 
2
471
 
begin work;
472
 
insert into t1 values (5);
473
 
select * from t1;
474
 
a
475
 
1
476
 
5
477
 
insert into t1 values (2);
478
 
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
479
 
select * from t1;
480
 
a
481
 
1
482
 
5
483
 
commit;
484
 
select * from t1;
485
 
a
486
 
1
487
 
2
488
 
commit;
489
 
select * from t1;
490
 
a
491
 
1
492
 
2
493
 
5
494
 
drop table t1;
495
 
create table t1(
496
 
id int auto_increment,
497
 
c char(1) not null,
498
 
counter int not null default 1,
499
 
primary key (id),
500
 
unique key (c)
501
 
) engine=innodb;
502
 
insert into t1 (id, c) values
503
 
(NULL, 'a'),
504
 
(NULL, 'a')
505
 
on duplicate key update id = values(id), counter = counter + 1;
506
 
select * from t1;
507
 
id      c       counter
508
 
2       a       2
509
 
insert into t1 (id, c) values
510
 
(NULL, 'b')
511
 
on duplicate key update id = values(id), counter = counter + 1;
512
 
select * from t1;
513
 
id      c       counter
514
 
2       a       2
515
 
3       b       1
516
 
truncate table t1;
517
 
insert into t1 (id, c) values (NULL, 'a');
518
 
select * from t1;
519
 
id      c       counter
520
 
1       a       1
521
 
insert into t1 (id, c) values (NULL, 'b'), (NULL, 'b')
522
 
on duplicate key update id = values(id), c = values(c), counter = counter + 1;
523
 
select * from t1;
524
 
id      c       counter
525
 
1       a       1
526
 
3       b       2
527
 
insert into t1 (id, c) values (NULL, 'a')
528
 
on duplicate key update id = values(id), c = values(c), counter = counter + 1;
529
 
select * from t1;
530
 
id      c       counter
531
 
3       b       2
532
 
4       a       2
533
 
drop table t1;
534
 
CREATE TABLE t1(
535
 
id int AUTO_INCREMENT PRIMARY KEY,
536
 
stat_id int NOT NULL,
537
 
acct_id int DEFAULT NULL,
538
 
INDEX idx1 (stat_id, acct_id),
539
 
INDEX idx2 (acct_id)
540
 
) ENGINE=MyISAM;
541
 
CREATE TABLE t2(
542
 
id int AUTO_INCREMENT PRIMARY KEY,
543
 
stat_id int NOT NULL,
544
 
acct_id int DEFAULT NULL,
545
 
INDEX idx1 (stat_id, acct_id),
546
 
INDEX idx2 (acct_id)
547
 
) ENGINE=InnoDB;
548
 
INSERT INTO t1(stat_id,acct_id) VALUES
549
 
(1,759), (2,831), (3,785), (4,854), (1,921),
550
 
(1,553), (2,589), (3,743), (2,827), (2,545),
551
 
(4,779), (4,783), (1,597), (1,785), (4,832),
552
 
(1,741), (1,833), (3,788), (2,973), (1,907);
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
 
INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
564
 
UPDATE t1 SET acct_id=785 
565
 
WHERE MOD(stat_id,2)=0 AND MOD(id,stat_id)=MOD(acct_id,stat_id);
566
 
OPTIMIZE TABLE t1;
567
 
Table   Op      Msg_type        Msg_text
568
 
test.t1 optimize        status  OK
569
 
SELECT COUNT(*) FROM t1;
570
 
COUNT(*)
571
 
40960
572
 
SELECT COUNT(*) FROM t1 WHERE acct_id=785;
573
 
COUNT(*)
574
 
8702
575
 
EXPLAIN SELECT COUNT(*) FROM t1 WHERE stat_id IN (1,3) AND acct_id=785;
576
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
577
 
1       SIMPLE  t1      range   idx1,idx2       idx1    9       NULL    2       Using where; Using index
578
 
INSERT INTO t2 SELECT * FROM t1;
579
 
OPTIMIZE TABLE t2;
580
 
Table   Op      Msg_type        Msg_text
581
 
test.t2 optimize        note    Table does not support optimize, doing recreate + analyze instead
582
 
test.t2 optimize        status  OK
583
 
EXPLAIN SELECT COUNT(*) FROM t2 WHERE stat_id IN (1,3) AND acct_id=785;
584
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
585
 
1       SIMPLE  t2      range   idx1,idx2       idx1    9       NULL    2       Using where; Using index
586
 
DROP TABLE t1,t2;
587
 
create table t1(a int) engine=innodb;
588
 
alter table t1 comment '123';
589
 
show create table t1;
590
 
Table   Create Table
591
 
t1      CREATE TABLE `t1` (
592
 
  `a` int(11) DEFAULT NULL
593
 
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='123'
594
 
drop table t1;
595
 
CREATE TABLE t1 (a CHAR(2), KEY (a)) ENGINE = InnoDB DEFAULT CHARSET=UTF8;
596
 
INSERT INTO t1 VALUES ('uk'),('bg');
597
 
SELECT * FROM t1 WHERE a = 'uk';
598
 
a
599
 
uk
600
 
DELETE FROM t1 WHERE a = 'uk';
601
 
SELECT * FROM t1 WHERE a = 'uk';
602
 
a
603
 
UPDATE t1 SET a = 'us' WHERE a = 'uk';
604
 
SELECT * FROM t1 WHERE a = 'uk';
605
 
a
606
 
CREATE TABLE t2 (a CHAR(2), KEY (a)) ENGINE = InnoDB;
607
 
INSERT INTO t2 VALUES ('uk'),('bg');
608
 
SELECT * FROM t2 WHERE a = 'uk';
609
 
a
610
 
uk
611
 
DELETE FROM t2 WHERE a = 'uk';
612
 
SELECT * FROM t2 WHERE a = 'uk';
613
 
a
614
 
INSERT INTO t2 VALUES ('uk');
615
 
UPDATE t2 SET a = 'us' WHERE a = 'uk';
616
 
SELECT * FROM t2 WHERE a = 'uk';
617
 
a
618
 
CREATE TABLE t3 (a CHAR(2), KEY (a)) ENGINE = MyISAM;
619
 
INSERT INTO t3 VALUES ('uk'),('bg');
620
 
SELECT * FROM t3 WHERE a = 'uk';
621
 
a
622
 
uk
623
 
DELETE FROM t3 WHERE a = 'uk';
624
 
SELECT * FROM t3 WHERE a = 'uk';
625
 
a
626
 
INSERT INTO t3 VALUES ('uk');
627
 
UPDATE t3 SET a = 'us' WHERE a = 'uk';
628
 
SELECT * FROM t3 WHERE a = 'uk';
629
 
a
630
 
DROP TABLE t1,t2,t3;
631
 
create table t1 (a int) engine=innodb;
632
 
select * from bug29807;
633
 
ERROR 42S02: Table 'test.bug29807' doesn't exist
634
 
drop table t1;
635
 
drop table bug29807;
636
 
ERROR 42S02: Unknown table 'bug29807'
637
 
create table bug29807 (a int);
638
 
drop table bug29807;
639
 
CREATE TABLE t1 (a INT) ENGINE=InnoDB;
640
 
CREATE TABLE t2 (a INT) ENGINE=InnoDB;
641
 
switch to connection c1
642
 
SET AUTOCOMMIT=0;
643
 
INSERT INTO t2 VALUES (1);
644
 
switch to connection c2
645
 
SET AUTOCOMMIT=0;
646
 
LOCK TABLES t1 READ, t2 READ;
647
 
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
648
 
switch to connection c1
649
 
COMMIT;
650
 
INSERT INTO t1 VALUES (1);
651
 
switch to connection default
652
 
SET AUTOCOMMIT=default;
653
 
DROP TABLE t1,t2;
654
 
CREATE TABLE t1 (
655
 
id int NOT NULL auto_increment PRIMARY KEY,
656
 
b int NOT NULL,
657
 
c datetime NOT NULL,
658
 
INDEX idx_b(b),
659
 
INDEX idx_c(c)
660
 
) ENGINE=InnoDB;
661
 
CREATE TABLE t2 (
662
 
b int NOT NULL auto_increment PRIMARY KEY,
663
 
c datetime NOT NULL
664
 
) ENGINE= MyISAM;
665
 
INSERT INTO t2(c) VALUES ('2007-01-01');
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 t2(c) SELECT c FROM t2;
675
 
INSERT INTO t2(c) SELECT c FROM t2;
676
 
INSERT INTO t1(b,c) SELECT b,c FROM t2;
677
 
UPDATE t2 SET c='2007-01-02';
678
 
INSERT INTO t1(b,c) SELECT b,c FROM t2;
679
 
UPDATE t2 SET c='2007-01-03';
680
 
INSERT INTO t1(b,c) SELECT b,c FROM t2;
681
 
set @@sort_buffer_size=8192;
682
 
Warnings:
683
 
Warning 1292    Truncated incorrect sort_buffer_size value: '8192'
684
 
SELECT COUNT(*) FROM t1;
685
 
COUNT(*)
686
 
3072
687
 
EXPLAIN 
688
 
SELECT COUNT(*) FROM t1 
689
 
WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
690
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
691
 
1       SIMPLE  t1      ALL     idx_b,idx_c     NULL    NULL    NULL    #       Using where
692
 
SELECT COUNT(*) FROM t1 
693
 
WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
694
 
COUNT(*)
695
 
3072
696
 
EXPLAIN 
697
 
SELECT COUNT(*) FROM t1 FORCE INDEX(idx_b, idx_c) 
698
 
WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
699
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
700
 
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
701
 
SELECT COUNT(*) FROM t1 FORCE INDEX(idx_b, idx_c)
702
 
WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
703
 
COUNT(*)
704
 
3072
705
 
set @@sort_buffer_size=default;
706
 
DROP TABLE t1,t2;
707
 
CREATE TABLE t1 (a int, b int);
708
 
insert into t1 values (1,1),(1,2);
709
 
CREATE TABLE t2 (primary key (a)) select * from t1;
710
 
ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
711
 
drop table if exists t2;
712
 
Warnings:
713
 
Note    1051    Unknown table 't2'
714
 
CREATE TEMPORARY TABLE t2 (primary key (a)) select * from t1;
715
 
ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
716
 
drop table if exists t2;
717
 
Warnings:
718
 
Note    1051    Unknown table 't2'
719
 
CREATE TABLE t2 (a int, b int, primary key (a));
720
 
BEGIN;
721
 
INSERT INTO t2 values(100,100);
722
 
CREATE TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
723
 
ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
724
 
SELECT * from t2;
725
 
a       b
726
 
100     100
727
 
ROLLBACK;
728
 
SELECT * from t2;
729
 
a       b
730
 
100     100
731
 
TRUNCATE table t2;
732
 
INSERT INTO t2 select * from t1;
733
 
ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
734
 
SELECT * from t2;
735
 
a       b
736
 
drop table t2;
737
 
CREATE TEMPORARY TABLE t2 (a int, b int, primary key (a));
738
 
BEGIN;
739
 
INSERT INTO t2 values(100,100);
740
 
CREATE TEMPORARY TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
741
 
ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
742
 
SELECT * from t2;
743
 
a       b
744
 
100     100
745
 
COMMIT;
746
 
BEGIN;
747
 
INSERT INTO t2 values(101,101);
748
 
CREATE TEMPORARY TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
749
 
ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
750
 
SELECT * from t2;
751
 
a       b
752
 
100     100
753
 
101     101
754
 
ROLLBACK;
755
 
SELECT * from t2;
756
 
a       b
757
 
100     100
758
 
TRUNCATE table t2;
759
 
INSERT INTO t2 select * from t1;
760
 
ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
761
 
SELECT * from t2;
762
 
a       b
763
 
drop table t1,t2;
764
 
create table t1(f1 varchar(800) binary not null, key(f1))
765
 
character set utf8 collate utf8_general_ci;
766
 
Warnings:
767
 
Warning 1071    Specified key was too long; max key length is 767 bytes
768
 
insert into t1 values('aaa');
769
 
drop table t1;
770
 
CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c FLOAT, KEY b(b)) ENGINE = INNODB;
771
 
INSERT INTO t1 VALUES (    1 , 1              , 1);
772
 
INSERT INTO t1 SELECT  a + 1 , MOD(a + 1 , 20), 1 FROM t1;
773
 
INSERT INTO t1 SELECT  a + 2 , MOD(a + 2 , 20), 1 FROM t1;
774
 
INSERT INTO t1 SELECT  a + 4 , MOD(a + 4 , 20), 1 FROM t1;
775
 
INSERT INTO t1 SELECT  a + 8 , MOD(a + 8 , 20), 1 FROM t1;
776
 
INSERT INTO t1 SELECT  a + 16, MOD(a + 16, 20), 1 FROM t1;
777
 
INSERT INTO t1 SELECT  a + 32, MOD(a + 32, 20), 1 FROM t1;
778
 
INSERT INTO t1 SELECT  a + 64, MOD(a + 64, 20), 1 FROM t1;
779
 
EXPLAIN SELECT b, SUM(c) FROM t1 GROUP BY b;
780
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
781
 
1       SIMPLE  t1      index   NULL    b       5       NULL    128     
782
 
EXPLAIN SELECT SQL_BIG_RESULT b, SUM(c) FROM t1 GROUP BY b;
783
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
784
 
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    128     Using filesort
785
 
DROP TABLE t1;
786
 
drop table if exists t1;
787
 
show variables like 'innodb_rollback_on_timeout';
788
 
Variable_name   Value
789
 
innodb_rollback_on_timeout      OFF
790
 
create table t1 (a int unsigned not null primary key) engine = innodb;
791
 
insert into t1 values (1);
792
 
commit;
793
 
begin work;
794
 
insert into t1 values (2);
795
 
select * from t1;
796
 
a
797
 
1
798
 
2
799
 
begin work;
800
 
insert into t1 values (5);
801
 
select * from t1;
802
 
a
803
 
1
804
 
5
805
 
insert into t1 values (2);
806
 
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
807
 
select * from t1;
808
 
a
809
 
1
810
 
5
811
 
commit;
812
 
select * from t1;
813
 
a
814
 
1
815
 
2
816
 
commit;
817
 
select * from t1;
818
 
a
819
 
1
820
 
2
821
 
5
822
 
drop table t1;
823
 
drop table if exists t1;
824
 
create table t1 (a int) engine=innodb;
825
 
alter table t1 alter a set default 1;
826
 
drop table t1;
827
 
 
828
 
Bug#24918 drop table and lock / inconsistent between 
829
 
perm and temp tables
830
 
 
831
 
Check transactional tables under LOCK TABLES
832
 
 
833
 
drop table if exists t24918, t24918_tmp, t24918_trans, t24918_trans_tmp, 
834
 
t24918_access;
835
 
create table t24918_access (id int);
836
 
create table t24918 (id int) engine=myisam;
837
 
create temporary table t24918_tmp (id int) engine=myisam;
838
 
create table t24918_trans (id int) engine=innodb;
839
 
create temporary table t24918_trans_tmp (id int) engine=innodb;
840
 
lock table t24918 write, t24918_tmp write, t24918_trans write, t24918_trans_tmp write;
841
 
drop table t24918;
842
 
select * from t24918_access;
843
 
ERROR HY000: Table 't24918_access' was not locked with LOCK TABLES
844
 
drop table t24918_trans;
845
 
select * from t24918_access;
846
 
ERROR HY000: Table 't24918_access' was not locked with LOCK TABLES
847
 
drop table t24918_trans_tmp;
848
 
select * from t24918_access;
849
 
ERROR HY000: Table 't24918_access' was not locked with LOCK TABLES
850
 
drop table t24918_tmp;
851
 
select * from t24918_access;
852
 
ERROR HY000: Table 't24918_access' was not locked with LOCK TABLES
853
 
unlock tables;
854
 
drop table t24918_access;
855
 
CREATE TABLE t1 (a int, b int, PRIMARY KEY (a), KEY bkey (b)) ENGINE=InnoDB;
856
 
INSERT INTO t1 VALUES (1,2),(3,2),(2,2),(4,2),(5,2),(6,2),(7,2),(8,2);
857
 
INSERT INTO t1 SELECT a + 8, 2 FROM t1;
858
 
INSERT INTO t1 SELECT a + 16, 1 FROM t1;
859
 
EXPLAIN SELECT * FROM t1 WHERE b=2 ORDER BY a;
860
 
id      1
861
 
select_type     SIMPLE
862
 
table   t1
863
 
type    ref
864
 
possible_keys   bkey
865
 
key     bkey
866
 
key_len 5
867
 
ref     const
868
 
rows    16
869
 
Extra   Using where; Using index
870
 
SELECT * FROM t1 WHERE b=2 ORDER BY a;
871
 
a       b
872
 
1       2
873
 
2       2
874
 
3       2
875
 
4       2
876
 
5       2
877
 
6       2
878
 
7       2
879
 
8       2
880
 
9       2
881
 
10      2
882
 
11      2
883
 
12      2
884
 
13      2
885
 
14      2
886
 
15      2
887
 
16      2
888
 
EXPLAIN SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY a;
889
 
id      1
890
 
select_type     SIMPLE
891
 
table   t1
892
 
type    range
893
 
possible_keys   bkey
894
 
key     bkey
895
 
key_len 5
896
 
ref     NULL
897
 
rows    16
898
 
Extra   Using where; Using index; Using filesort
899
 
SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY a;
900
 
a       b
901
 
1       2
902
 
2       2
903
 
3       2
904
 
4       2
905
 
5       2
906
 
6       2
907
 
7       2
908
 
8       2
909
 
9       2
910
 
10      2
911
 
11      2
912
 
12      2
913
 
13      2
914
 
14      2
915
 
15      2
916
 
16      2
917
 
17      1
918
 
18      1
919
 
19      1
920
 
20      1
921
 
21      1
922
 
22      1
923
 
23      1
924
 
24      1
925
 
25      1
926
 
26      1
927
 
27      1
928
 
28      1
929
 
29      1
930
 
30      1
931
 
31      1
932
 
32      1
933
 
EXPLAIN SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY b,a;
934
 
id      1
935
 
select_type     SIMPLE
936
 
table   t1
937
 
type    range
938
 
possible_keys   bkey
939
 
key     bkey
940
 
key_len 5
941
 
ref     NULL
942
 
rows    16
943
 
Extra   Using where; Using index
944
 
SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY b,a;
945
 
a       b
946
 
17      1
947
 
18      1
948
 
19      1
949
 
20      1
950
 
21      1
951
 
22      1
952
 
23      1
953
 
24      1
954
 
25      1
955
 
26      1
956
 
27      1
957
 
28      1
958
 
29      1
959
 
30      1
960
 
31      1
961
 
32      1
962
 
1       2
963
 
2       2
964
 
3       2
965
 
4       2
966
 
5       2
967
 
6       2
968
 
7       2
969
 
8       2
970
 
9       2
971
 
10      2
972
 
11      2
973
 
12      2
974
 
13      2
975
 
14      2
976
 
15      2
977
 
16      2
978
 
CREATE TABLE t2 (a int, b int, c int, PRIMARY KEY (a), KEY bkey (b,c))
979
 
ENGINE=InnoDB;
980
 
INSERT INTO t2 VALUES (1,1,1),(3,1,1),(2,1,1),(4,1,1);
981
 
INSERT INTO t2 SELECT a + 4, 1, 1 FROM t2;
982
 
INSERT INTO t2 SELECT a + 8, 1, 1 FROM t2;
983
 
EXPLAIN SELECT * FROM t2 WHERE b=1 ORDER BY a;
984
 
id      1
985
 
select_type     SIMPLE
986
 
table   t2
987
 
type    ref
988
 
possible_keys   bkey
989
 
key     bkey
990
 
key_len 5
991
 
ref     const
992
 
rows    8
993
 
Extra   Using where; Using index; Using filesort
994
 
SELECT * FROM t2 WHERE b=1 ORDER BY a;
995
 
a       b       c
996
 
1       1       1
997
 
2       1       1
998
 
3       1       1
999
 
4       1       1
1000
 
5       1       1
1001
 
6       1       1
1002
 
7       1       1
1003
 
8       1       1
1004
 
9       1       1
1005
 
10      1       1
1006
 
11      1       1
1007
 
12      1       1
1008
 
13      1       1
1009
 
14      1       1
1010
 
15      1       1
1011
 
16      1       1
1012
 
EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY a;
1013
 
id      1
1014
 
select_type     SIMPLE
1015
 
table   t2
1016
 
type    ref
1017
 
possible_keys   bkey
1018
 
key     bkey
1019
 
key_len 10
1020
 
ref     const,const
1021
 
rows    8
1022
 
Extra   Using where; Using index
1023
 
SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY a;
1024
 
a       b       c
1025
 
1       1       1
1026
 
2       1       1
1027
 
3       1       1
1028
 
4       1       1
1029
 
5       1       1
1030
 
6       1       1
1031
 
7       1       1
1032
 
8       1       1
1033
 
9       1       1
1034
 
10      1       1
1035
 
11      1       1
1036
 
12      1       1
1037
 
13      1       1
1038
 
14      1       1
1039
 
15      1       1
1040
 
16      1       1
1041
 
EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY b,c,a;
1042
 
id      1
1043
 
select_type     SIMPLE
1044
 
table   t2
1045
 
type    ref
1046
 
possible_keys   bkey
1047
 
key     bkey
1048
 
key_len 10
1049
 
ref     const,const
1050
 
rows    8
1051
 
Extra   Using where; Using index
1052
 
SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY b,c,a;
1053
 
a       b       c
1054
 
1       1       1
1055
 
2       1       1
1056
 
3       1       1
1057
 
4       1       1
1058
 
5       1       1
1059
 
6       1       1
1060
 
7       1       1
1061
 
8       1       1
1062
 
9       1       1
1063
 
10      1       1
1064
 
11      1       1
1065
 
12      1       1
1066
 
13      1       1
1067
 
14      1       1
1068
 
15      1       1
1069
 
16      1       1
1070
 
EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY c,a;
1071
 
id      1
1072
 
select_type     SIMPLE
1073
 
table   t2
1074
 
type    ref
1075
 
possible_keys   bkey
1076
 
key     bkey
1077
 
key_len 10
1078
 
ref     const,const
1079
 
rows    8
1080
 
Extra   Using where; Using index
1081
 
SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY c,a;
1082
 
a       b       c
1083
 
1       1       1
1084
 
2       1       1
1085
 
3       1       1
1086
 
4       1       1
1087
 
5       1       1
1088
 
6       1       1
1089
 
7       1       1
1090
 
8       1       1
1091
 
9       1       1
1092
 
10      1       1
1093
 
11      1       1
1094
 
12      1       1
1095
 
13      1       1
1096
 
14      1       1
1097
 
15      1       1
1098
 
16      1       1
1099
 
DROP TABLE t1,t2;
1100
 
CREATE TABLE t1 (a INT, PRIMARY KEY (a)) ENGINE=InnoDB;
1101
 
INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8);
1102
 
INSERT INTO t1 SELECT a + 8  FROM t1;
1103
 
INSERT INTO t1 SELECT a + 16 FROM t1;
1104
 
CREATE PROCEDURE p1 ()
1105
 
BEGIN
1106
 
DECLARE i INT DEFAULT 50;
1107
 
DECLARE cnt INT;
1108
 
START TRANSACTION;
1109
 
ALTER TABLE t1 ENGINE=InnoDB;
1110
 
COMMIT;
1111
 
START TRANSACTION;
1112
 
WHILE (i > 0) DO
1113
 
SET i = i - 1;
1114
 
SELECT COUNT(*) INTO cnt FROM t1 LOCK IN SHARE MODE;
1115
 
END WHILE;
1116
 
COMMIT;
1117
 
END;|
1118
 
CALL p1();
1119
 
CALL p1();
1120
 
CALL p1();
1121
 
DROP PROCEDURE p1;
1122
 
DROP TABLE t1;
1123
 
create table t1(a text) engine=innodb default charset=utf8;
1124
 
insert into t1 values('aaa');
1125
 
alter table t1 add index(a(1024));
1126
 
Warnings:
1127
 
Warning 1071    Specified key was too long; max key length is 767 bytes
1128
 
Warning 1071    Specified key was too long; max key length is 767 bytes
1129
 
show create table t1;
1130
 
Table   Create Table
1131
 
t1      CREATE TABLE `t1` (
1132
 
  `a` text,
1133
 
  KEY `a` (`a`(255))
1134
 
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1135
 
drop table t1;
1136
 
CREATE TABLE t1 (
1137
 
a INT,
1138
 
b INT,
1139
 
KEY (b)
1140
 
) ENGINE=InnoDB;
1141
 
INSERT INTO t1 VALUES (1,10), (2,10), (2,20), (3,30);
1142
 
START TRANSACTION;
1143
 
SELECT * FROM t1 WHERE b=20 FOR UPDATE;
1144
 
a       b
1145
 
2       20
1146
 
START TRANSACTION;
1147
 
SELECT * FROM t1 WHERE b=10 ORDER BY A FOR UPDATE;
1148
 
a       b
1149
 
1       10
1150
 
2       10
1151
 
ROLLBACK;
1152
 
ROLLBACK;
1153
 
DROP TABLE t1;
1154
 
CREATE TABLE t1(
1155
 
a INT, 
1156
 
b INT NOT NULL, 
1157
 
c INT NOT NULL, 
1158
 
d INT, 
1159
 
UNIQUE KEY (c,b)
1160
 
) engine=innodb;
1161
 
INSERT INTO t1 VALUES (1,1,1,50), (1,2,3,40), (2,1,3,4);
1162
 
EXPLAIN SELECT c,b,d FROM t1 GROUP BY c,b,d;
1163
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1164
 
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    3       Using filesort
1165
 
SELECT c,b,d FROM t1 GROUP BY c,b,d;
1166
 
c       b       d
1167
 
1       1       50
1168
 
3       1       4
1169
 
3       2       40
1170
 
EXPLAIN SELECT c,b,d FROM t1 GROUP BY c,b,d ORDER BY NULL;
1171
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1172
 
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    3       
1173
 
SELECT c,b,d FROM t1 GROUP BY c,b,d ORDER BY NULL;
1174
 
c       b       d
1175
 
1       1       50
1176
 
3       1       4
1177
 
3       2       40
1178
 
EXPLAIN SELECT c,b,d FROM t1 ORDER BY c,b,d;
1179
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1180
 
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    3       Using filesort
1181
 
SELECT c,b,d FROM t1 ORDER BY c,b,d;
1182
 
c       b       d
1183
 
1       1       50
1184
 
3       1       4
1185
 
3       2       40
1186
 
EXPLAIN SELECT c,b,d FROM t1 GROUP BY c,b;
1187
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1188
 
1       SIMPLE  t1      index   NULL    c       8       NULL    3       
1189
 
SELECT c,b,d FROM t1 GROUP BY c,b;
1190
 
c       b       d
1191
 
1       1       50
1192
 
3       1       4
1193
 
3       2       40
1194
 
EXPLAIN SELECT c,b   FROM t1 GROUP BY c,b;
1195
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1196
 
1       SIMPLE  t1      index   NULL    c       8       NULL    3       Using index
1197
 
SELECT c,b   FROM t1 GROUP BY c,b;
1198
 
c       b
1199
 
1       1
1200
 
3       1
1201
 
3       2
1202
 
DROP TABLE t1;
1203
 
CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a), INDEX b (b)) ENGINE=InnoDB;
1204
 
INSERT INTO t1(a,b) VALUES (1,1), (2,2), (3,2);
1205
 
EXPLAIN SELECT * FROM t1 WHERE b=2 ORDER BY a ASC;
1206
 
id      1
1207
 
select_type     SIMPLE
1208
 
table   t1
1209
 
type    ref
1210
 
possible_keys   b
1211
 
key     b
1212
 
key_len 5
1213
 
ref     const
1214
 
rows    1
1215
 
Extra   Using where; Using index
1216
 
SELECT * FROM t1 WHERE b=2 ORDER BY a ASC;
1217
 
a       b
1218
 
2       2
1219
 
3       2
1220
 
EXPLAIN SELECT * FROM t1 WHERE b=2 ORDER BY a DESC;
1221
 
id      1
1222
 
select_type     SIMPLE
1223
 
table   t1
1224
 
type    ref
1225
 
possible_keys   b
1226
 
key     b
1227
 
key_len 5
1228
 
ref     const
1229
 
rows    1
1230
 
Extra   Using where; Using index
1231
 
SELECT * FROM t1 WHERE b=2 ORDER BY a DESC;
1232
 
a       b
1233
 
3       2
1234
 
2       2
1235
 
EXPLAIN SELECT * FROM t1 ORDER BY b ASC, a ASC;
1236
 
id      1
1237
 
select_type     SIMPLE
1238
 
table   t1
1239
 
type    index
1240
 
possible_keys   NULL
1241
 
key     b
1242
 
key_len 5
1243
 
ref     NULL
1244
 
rows    3
1245
 
Extra   Using index
1246
 
SELECT * FROM t1 ORDER BY b ASC, a ASC;
1247
 
a       b
1248
 
1       1
1249
 
2       2
1250
 
3       2
1251
 
EXPLAIN SELECT * FROM t1 ORDER BY b DESC, a DESC;
1252
 
id      1
1253
 
select_type     SIMPLE
1254
 
table   t1
1255
 
type    index
1256
 
possible_keys   NULL
1257
 
key     b
1258
 
key_len 5
1259
 
ref     NULL
1260
 
rows    3
1261
 
Extra   Using index
1262
 
SELECT * FROM t1 ORDER BY b DESC, a DESC;
1263
 
a       b
1264
 
3       2
1265
 
2       2
1266
 
1       1
1267
 
EXPLAIN SELECT * FROM t1 ORDER BY b ASC, a DESC;
1268
 
id      1
1269
 
select_type     SIMPLE
1270
 
table   t1
1271
 
type    index
1272
 
possible_keys   NULL
1273
 
key     b
1274
 
key_len 5
1275
 
ref     NULL
1276
 
rows    3
1277
 
Extra   Using index; Using filesort
1278
 
SELECT * FROM t1 ORDER BY b ASC, a DESC;
1279
 
a       b
1280
 
1       1
1281
 
3       2
1282
 
2       2
1283
 
EXPLAIN SELECT * FROM t1 ORDER BY b DESC, a ASC;
1284
 
id      1
1285
 
select_type     SIMPLE
1286
 
table   t1
1287
 
type    index
1288
 
possible_keys   NULL
1289
 
key     b
1290
 
key_len 5
1291
 
ref     NULL
1292
 
rows    3
1293
 
Extra   Using index; Using filesort
1294
 
SELECT * FROM t1 ORDER BY b DESC, a ASC;
1295
 
a       b
1296
 
2       2
1297
 
3       2
1298
 
1       1
1299
 
DROP TABLE t1;
1300
 
 
1301
 
#
1302
 
# Bug#27610: ALTER TABLE ROW_FORMAT=... does not rebuild the table.
1303
 
#
1304
 
 
1305
 
# - prepare;
1306
 
 
1307
 
DROP TABLE IF EXISTS t1;
1308
 
 
1309
 
CREATE TABLE t1(c INT)
1310
 
ENGINE = InnoDB
1311
 
ROW_FORMAT = COMPACT;
1312
 
 
1313
 
# - initial check;
1314
 
 
1315
 
SELECT table_schema, table_name, row_format
1316
 
FROM INFORMATION_SCHEMA.TABLES
1317
 
WHERE table_schema = DATABASE() AND table_name = 't1';
1318
 
table_schema    table_name      row_format
1319
 
test    t1      Compact
1320
 
 
1321
 
# - change ROW_FORMAT and check;
1322
 
 
1323
 
ALTER TABLE t1 ROW_FORMAT = REDUNDANT;
1324
 
 
1325
 
SELECT table_schema, table_name, row_format
1326
 
FROM INFORMATION_SCHEMA.TABLES
1327
 
WHERE table_schema = DATABASE() AND table_name = 't1';
1328
 
table_schema    table_name      row_format
1329
 
test    t1      Redundant
1330
 
 
1331
 
# - that's it, cleanup.
1332
 
 
1333
 
DROP TABLE t1;
1334
 
create table t1(a char(10) not null, unique key aa(a(1)),
1335
 
b char(4) not null, unique key bb(b(4))) engine=innodb;
1336
 
desc t1;
1337
 
Field   Type    Null    Key     Default Extra
1338
 
a       char(10)        NO      UNI     NULL    
1339
 
b       char(4) NO      PRI     NULL    
1340
 
show create table t1;
1341
 
Table   Create Table
1342
 
t1      CREATE TABLE `t1` (
1343
 
  `a` char(10) NOT NULL,
1344
 
  `b` char(4) NOT NULL,
1345
 
  UNIQUE KEY `bb` (`b`),
1346
 
  UNIQUE KEY `aa` (`a`(1))
1347
 
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1348
 
drop table t1;
1349
 
CREATE TABLE t1 (id int, type char(6), d int, INDEX idx(id,d)) ENGINE=InnoDB;
1350
 
INSERT INTO t1 VALUES 
1351
 
(191, 'member', 1), (NULL, 'member', 3), (NULL, 'member', 4), (201, 'member', 2);
1352
 
EXPLAIN SELECT * FROM t1 WHERE id=191 OR id IS NULL ORDER BY d;
1353
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1354
 
1       SIMPLE  t1      ALL     idx     NULL    NULL    NULL    4       Using where; Using filesort
1355
 
SELECT * FROM t1 WHERE id=191 OR id IS NULL ORDER BY d;
1356
 
id      type    d
1357
 
191     member  1
1358
 
NULL    member  3
1359
 
NULL    member  4
1360
 
DROP TABLE t1;
1361
 
set @my_innodb_autoextend_increment=@@global.innodb_autoextend_increment;
1362
 
set global innodb_autoextend_increment=8;
1363
 
set global innodb_autoextend_increment=@my_innodb_autoextend_increment;
1364
 
set @my_innodb_commit_concurrency=@@global.innodb_commit_concurrency;
1365
 
set global innodb_commit_concurrency=0;
1366
 
set global innodb_commit_concurrency=@my_innodb_commit_concurrency;
1367
 
CREATE TABLE t1 (a int, b int, c int, PRIMARY KEY (a), KEY t1_b (b))
1368
 
ENGINE=InnoDB;
1369
 
INSERT INTO t1 (a,b,c) VALUES (1,1,1), (2,1,1), (3,1,1), (4,1,1);
1370
 
INSERT INTO t1 (a,b,c) SELECT a+4,b,c FROM t1;
1371
 
EXPLAIN SELECT a, b, c FROM t1 WHERE b = 1 ORDER BY a DESC LIMIT 5;
1372
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1373
 
1       SIMPLE  t1      index   t1_b    PRIMARY 4       NULL    8       Using where
1374
 
SELECT a, b, c FROM t1 WHERE b = 1 ORDER BY a DESC LIMIT 5;
1375
 
a       b       c
1376
 
8       1       1
1377
 
7       1       1
1378
 
6       1       1
1379
 
5       1       1
1380
 
4       1       1
1381
 
DROP TABLE t1;
1382
 
DROP TABLE IF EXISTS t1;
1383
 
CREATE TABLE t1 (a char(50)) ENGINE=InnoDB;
1384
 
CREATE INDEX i1 on t1 (a(3));
1385
 
SELECT * FROM t1 WHERE a = 'abcde';
1386
 
a
1387
 
DROP TABLE t1;
1388
 
#
1389
 
# BUG #26288: savepoint are not deleted on comit, if the transaction 
1390
 
# was otherwise empty
1391
 
#
1392
 
BEGIN;
1393
 
SAVEPOINT s1;
1394
 
COMMIT;
1395
 
RELEASE SAVEPOINT s1;
1396
 
ERROR 42000: SAVEPOINT s1 does not exist
1397
 
BEGIN;
1398
 
SAVEPOINT s2;
1399
 
COMMIT;
1400
 
ROLLBACK TO SAVEPOINT s2;
1401
 
ERROR 42000: SAVEPOINT s2 does not exist
1402
 
BEGIN;
1403
 
SAVEPOINT s3;
1404
 
ROLLBACK;
1405
 
RELEASE SAVEPOINT s3;
1406
 
ERROR 42000: SAVEPOINT s3 does not exist
1407
 
BEGIN;
1408
 
SAVEPOINT s4;
1409
 
ROLLBACK;
1410
 
ROLLBACK TO SAVEPOINT s4;
1411
 
ERROR 42000: SAVEPOINT s4 does not exist
1412
 
CREATE TABLE t1 (f1 INTEGER PRIMARY KEY COMMENT 'My ID#', f2 INTEGER DEFAULT NULL, f3 CHAR(10) DEFAULT 'My ID#', CONSTRAINT f2_ref FOREIGN KEY (f2) REFERENCES t1 (f1)) ENGINE=INNODB;
1413
 
SHOW CREATE TABLE t1;
1414
 
Table   Create Table
1415
 
t1      CREATE TABLE `t1` (
1416
 
  `f1` int(11) NOT NULL COMMENT 'My ID#',
1417
 
  `f2` int(11) DEFAULT NULL,
1418
 
  `f3` char(10) DEFAULT 'My ID#',
1419
 
  PRIMARY KEY (`f1`),
1420
 
  KEY `f2_ref` (`f2`),
1421
 
  CONSTRAINT `f2_ref` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`)
1422
 
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1423
 
DROP TABLE t1;
1424
 
#
1425
 
# Bug #36995: valgrind error in remove_const during subquery executions
1426
 
#
1427
 
create table t1 (a bit(1) not null,b int) engine=myisam;
1428
 
create table t2 (c int) engine=innodb;
1429
 
explain
1430
 
select b from t1 where a not in (select b from t1,t2 group by a) group by a;
1431
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1432
 
1       PRIMARY NULL    NULL    NULL    NULL    NULL    NULL    NULL    Impossible WHERE noticed after reading const tables
1433
 
2       DEPENDENT SUBQUERY      t1      system  NULL    NULL    NULL    NULL    0       const row not found
1434
 
2       DEPENDENT SUBQUERY      t2      ALL     NULL    NULL    NULL    NULL    1       
1435
 
DROP TABLE t1,t2;
1436
 
End of 5.0 tests
1437
 
CREATE TABLE `t2` (
1438
 
`k` int(11) NOT NULL auto_increment,
1439
 
`a` int(11) default NULL,
1440
 
`c` int(11) default NULL,
1441
 
PRIMARY KEY  (`k`),
1442
 
UNIQUE KEY `idx_1` (`a`)
1443
 
);
1444
 
insert into t2 ( a ) values ( 6 ) on duplicate key update c =
1445
 
ifnull( c,
1446
 
0 ) + 1;
1447
 
insert into t2 ( a ) values ( 7 ) on duplicate key update c =
1448
 
ifnull( c,
1449
 
0 ) + 1;
1450
 
select last_insert_id();
1451
 
last_insert_id()
1452
 
2
1453
 
select * from t2;
1454
 
k       a       c
1455
 
1       6       NULL
1456
 
2       7       NULL
1457
 
insert into t2 ( a ) values ( 6 ) on duplicate key update c =
1458
 
ifnull( c,
1459
 
0 ) + 1;
1460
 
select last_insert_id();
1461
 
last_insert_id()
1462
 
2
1463
 
select last_insert_id(0);
1464
 
last_insert_id(0)
1465
 
0
1466
 
insert into t2 ( a ) values ( 6 ) on duplicate key update c =
1467
 
ifnull( c,
1468
 
0 ) + 1;
1469
 
select last_insert_id();
1470
 
last_insert_id()
1471
 
0
1472
 
select * from t2;
1473
 
k       a       c
1474
 
1       6       2
1475
 
2       7       NULL
1476
 
insert ignore into t2 values (null,6,1),(10,8,1);
1477
 
select last_insert_id();
1478
 
last_insert_id()
1479
 
0
1480
 
insert ignore into t2 values (null,6,1),(null,8,1),(null,15,1),(null,20,1);
1481
 
select last_insert_id();
1482
 
last_insert_id()
1483
 
11
1484
 
select * from t2;
1485
 
k       a       c
1486
 
1       6       2
1487
 
2       7       NULL
1488
 
10      8       1
1489
 
11      15      1
1490
 
12      20      1
1491
 
insert into t2 ( a ) values ( 6 ) on duplicate key update c =
1492
 
ifnull( c,
1493
 
0 ) + 1, k=last_insert_id(k);
1494
 
select last_insert_id();
1495
 
last_insert_id()
1496
 
1
1497
 
select * from t2;
1498
 
k       a       c
1499
 
1       6       3
1500
 
2       7       NULL
1501
 
10      8       1
1502
 
11      15      1
1503
 
12      20      1
1504
 
drop table t2;
1505
 
drop table if exists t1, t2;
1506
 
create table t1 (i int);
1507
 
alter table t1 modify i int default 1;
1508
 
alter table t1 modify i int default 2, rename t2;
1509
 
lock table t2 write;
1510
 
alter table t2 modify i int default 3;
1511
 
unlock tables;
1512
 
lock table t2 write;
1513
 
alter table t2 modify i int default 4, rename t1;
1514
 
unlock tables;
1515
 
drop table t1;
1516
 
drop table if exists t1;
1517
 
create table t1 (i int);
1518
 
insert into t1 values ();
1519
 
lock table t1 write;
1520
 
alter table t1 modify i int default 1;
1521
 
insert into t1 values ();
1522
 
select * from t1;
1523
 
i
1524
 
NULL
1525
 
1
1526
 
alter table t1 change i c char(10) default "Two";
1527
 
insert into t1 values ();
1528
 
select * from t1;
1529
 
c
1530
 
NULL
1531
 
1
1532
 
Two
1533
 
unlock tables;
1534
 
select * from t1;
1535
 
c
1536
 
NULL
1537
 
1
1538
 
Two
1539
 
drop tables t1;
1540
 
create table t1(f1 varchar(5) unique, f2 timestamp NOT NULL DEFAULT
1541
 
CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);
1542
 
insert into t1(f1) values(1);
1543
 
select @a:=f2 from t1;
1544
 
@a:=f2
1545
 
#
1546
 
update t1 set f1=1;
1547
 
select @b:=f2 from t1;
1548
 
@b:=f2
1549
 
#
1550
 
select if(@a=@b,"ok","wrong");
1551
 
if(@a=@b,"ok","wrong")
1552
 
ok
1553
 
insert into t1(f1) values (1) on duplicate key update f1="1";
1554
 
select @b:=f2 from t1;
1555
 
@b:=f2
1556
 
#
1557
 
select if(@a=@b,"ok","wrong");
1558
 
if(@a=@b,"ok","wrong")
1559
 
ok
1560
 
insert into t1(f1) select f1 from t1 on duplicate key update f1="1";
1561
 
select @b:=f2 from t1;
1562
 
@b:=f2
1563
 
#
1564
 
select if(@a=@b,"ok","wrong");
1565
 
if(@a=@b,"ok","wrong")
1566
 
ok
1567
 
drop table t1;
1568
 
SET SESSION AUTOCOMMIT = 0;
1569
 
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
1570
 
set binlog_format=mixed;
1571
 
# Switch to connection con1
1572
 
CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(256))
1573
 
ENGINE = InnoDB;
1574
 
INSERT INTO t1 VALUES (1,2);
1575
 
# 1. test for locking:
1576
 
BEGIN;
1577
 
UPDATE t1 SET b = 12 WHERE a = 1;
1578
 
affected rows: 1
1579
 
info: Rows matched: 1  Changed: 1  Warnings: 0
1580
 
SELECT * FROM t1;
1581
 
a       b
1582
 
1       12
1583
 
# Switch to connection con2
1584
 
UPDATE t1 SET b = 21 WHERE a = 1;
1585
 
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
1586
 
# Switch to connection con1
1587
 
SELECT * FROM t1;
1588
 
a       b
1589
 
1       12
1590
 
ROLLBACK;
1591
 
# 2. test for serialized update:
1592
 
CREATE TABLE t2 (a INT);
1593
 
TRUNCATE t1;
1594
 
INSERT INTO t1 VALUES (1,'init');
1595
 
CREATE PROCEDURE p1()
1596
 
BEGIN
1597
 
UPDATE t1 SET b = CONCAT(b, '+con2')  WHERE a = 1;
1598
 
INSERT INTO t2 VALUES ();
1599
 
END|
1600
 
BEGIN;
1601
 
UPDATE t1 SET b = CONCAT(b, '+con1') WHERE a = 1;
1602
 
affected rows: 1
1603
 
info: Rows matched: 1  Changed: 1  Warnings: 0
1604
 
SELECT * FROM t1;
1605
 
a       b
1606
 
1       init+con1
1607
 
# Switch to connection con2
1608
 
CALL p1;;
1609
 
# Switch to connection con1
1610
 
SELECT * FROM t1;
1611
 
a       b
1612
 
1       init+con1
1613
 
COMMIT;
1614
 
SELECT * FROM t1;
1615
 
a       b
1616
 
1       init+con1
1617
 
# Switch to connection con2
1618
 
SELECT * FROM t1;
1619
 
a       b
1620
 
1       init+con1+con2
1621
 
# Switch to connection con1
1622
 
# 3. test for updated key column:
1623
 
TRUNCATE t1;
1624
 
TRUNCATE t2;
1625
 
INSERT INTO t1 VALUES (1,'init');
1626
 
BEGIN;
1627
 
UPDATE t1 SET a = 2, b = CONCAT(b, '+con1') WHERE a = 1;
1628
 
affected rows: 1
1629
 
info: Rows matched: 1  Changed: 1  Warnings: 0
1630
 
SELECT * FROM t1;
1631
 
a       b
1632
 
2       init+con1
1633
 
# Switch to connection con2
1634
 
CALL p1;;
1635
 
# Switch to connection con1
1636
 
SELECT * FROM t1;
1637
 
a       b
1638
 
2       init+con1
1639
 
COMMIT;
1640
 
SELECT * FROM t1;
1641
 
a       b
1642
 
2       init+con1
1643
 
# Switch to connection con2
1644
 
SELECT * FROM t1;
1645
 
a       b
1646
 
2       init+con1
1647
 
DROP PROCEDURE p1;
1648
 
DROP TABLE t1, t2;
1649
 
CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL, PRIMARY KEY (a,b)) engine=innodb;
1650
 
CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
1651
 
CONSTRAINT c2 FOREIGN KEY f2 (c) REFERENCES t1 (a,b) ON UPDATE NO ACTION) engine=innodb;
1652
 
ERROR 42000: Incorrect foreign key definition for 'f2': Key reference and table reference don't match
1653
 
CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
1654
 
CONSTRAINT c2 FOREIGN KEY (c) REFERENCES t1 (a,b) ON UPDATE NO ACTION) engine=innodb;
1655
 
ERROR 42000: Incorrect foreign key definition for 'c2': Key reference and table reference don't match
1656
 
CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
1657
 
CONSTRAINT c1 FOREIGN KEY c2 (c) REFERENCES t1 (a) ON DELETE NO ACTION,
1658
 
CONSTRAINT c2 FOREIGN KEY (c) REFERENCES t1 (a) ON UPDATE NO ACTION) engine=innodb;
1659
 
ALTER TABLE t2 DROP FOREIGN KEY c2;
1660
 
DROP TABLE t2;
1661
 
CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
1662
 
FOREIGN KEY (c) REFERENCES t1 (a,k) ON UPDATE NO ACTION) engine=innodb;
1663
 
ERROR 42000: Incorrect foreign key definition for 'foreign key without name': Key reference and table reference don't match
1664
 
CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
1665
 
FOREIGN KEY f1 (c) REFERENCES t1 (a,k) ON UPDATE NO ACTION) engine=innodb;
1666
 
ERROR 42000: Incorrect foreign key definition for 'f1': Key reference and table reference don't match
1667
 
CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
1668
 
CONSTRAINT c1 FOREIGN KEY f1 (c) REFERENCES t1 (a) ON DELETE NO ACTION,
1669
 
CONSTRAINT c2 FOREIGN KEY (c) REFERENCES t1 (a) ON UPDATE NO ACTION,
1670
 
FOREIGN KEY f3 (c) REFERENCES t1 (a) ON UPDATE NO ACTION,
1671
 
FOREIGN KEY (c) REFERENCES t1 (a) ON UPDATE NO ACTION) engine=innodb;
1672
 
SHOW CREATE TABLE t2;
1673
 
Table   Create Table
1674
 
t2      CREATE TABLE `t2` (
1675
 
  `c` int(11) NOT NULL,
1676
 
  `d` int(11) NOT NULL,
1677
 
  PRIMARY KEY (`c`,`d`),
1678
 
  CONSTRAINT `c1` FOREIGN KEY (`c`) REFERENCES `t1` (`a`) ON DELETE NO ACTION,
1679
 
  CONSTRAINT `c2` FOREIGN KEY (`c`) REFERENCES `t1` (`a`) ON UPDATE NO ACTION,
1680
 
  CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`c`) REFERENCES `t1` (`a`) ON UPDATE NO ACTION,
1681
 
  CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`c`) REFERENCES `t1` (`a`) ON UPDATE NO ACTION
1682
 
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1683
 
DROP TABLE t2;
1684
 
DROP TABLE t1;
1685
 
create table t1 (a int auto_increment primary key) engine=innodb;
1686
 
alter table t1 order by a;
1687
 
Warnings:
1688
 
Warning 1105    ORDER BY ignored as there is a user-defined clustered index in the table 't1'
1689
 
drop table t1;
1690
 
CREATE TABLE t1
1691
 
(vid integer NOT NULL,
1692
 
tid integer NOT NULL,
1693
 
idx integer NOT NULL,
1694
 
name varchar(128) NOT NULL,
1695
 
type varchar(128) NULL,
1696
 
PRIMARY KEY(idx, vid, tid),
1697
 
UNIQUE(vid, tid, name)
1698
 
) ENGINE=InnoDB;
1699
 
INSERT INTO t1 VALUES
1700
 
(1,1,1,'pk',NULL),(2,1,1,'pk',NULL),(3,1,1,'pk',NULL),(4,1,1,'c1',NULL),
1701
 
(5,1,1,'pk',NULL),(1,1,2,'c1',NULL),(2,1,2,'c1',NULL),(3,1,2,'c1',NULL),
1702
 
(4,1,2,'c2',NULL),(5,1,2,'c1',NULL),(2,1,3,'c2',NULL),(3,1,3,'c2',NULL),
1703
 
(4,1,3,'pk',NULL),(5,1,3,'c2',NULL),
1704
 
(2,1,4,'c_extra',NULL),(3,1,4,'c_extra',NULL);
1705
 
EXPLAIN SELECT * FROM t1 FORCE INDEX (PRIMARY) WHERE tid = 1 AND vid = 3 ORDER BY idx DESC;
1706
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1707
 
1       SIMPLE  t1      index   NULL    PRIMARY 12      NULL    16      Using where
1708
 
SELECT * FROM t1 FORCE INDEX (PRIMARY) WHERE tid = 1 AND vid = 3 ORDER BY idx DESC;
1709
 
vid     tid     idx     name    type
1710
 
3       1       4       c_extra NULL
1711
 
3       1       3       c2      NULL
1712
 
3       1       2       c1      NULL
1713
 
3       1       1       pk      NULL
1714
 
DROP TABLE t1;
1715
 
#
1716
 
# Bug #44290: explain crashes for subquery with distinct in
1717
 
#             SQL_SELECT::test_quick_select
1718
 
#             (reproduced only with InnoDB tables)
1719
 
#
1720
 
CREATE TABLE t1 (c1 INT, c2 INT, c3 INT, KEY (c3), KEY (c2, c3))
1721
 
ENGINE=InnoDB;
1722
 
INSERT INTO t1 VALUES (1,1,1), (1,1,1), (1,1,2), (1,1,1), (1,1,2);
1723
 
SELECT 1 FROM (SELECT COUNT(DISTINCT c1) 
1724
 
FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
1725
 
1
1726
 
1
1727
 
EXPLAIN 
1728
 
SELECT 1 FROM (SELECT COUNT(DISTINCT c1) 
1729
 
FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
1730
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1731
 
1       PRIMARY <derived2>      system  NULL    NULL    NULL    NULL    1       
1732
 
2       DERIVED t1      index   c3,c2   c2      10      NULL    5       
1733
 
DROP TABLE t1;
1734
 
CREATE TABLE t1 (c1 REAL, c2 REAL, c3 REAL, KEY (c3), KEY (c2, c3))
1735
 
ENGINE=InnoDB;
1736
 
INSERT INTO t1 VALUES (1,1,1), (1,1,1), (1,1,2), (1,1,1), (1,1,2);
1737
 
SELECT 1 FROM (SELECT COUNT(DISTINCT c1) 
1738
 
FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
1739
 
1
1740
 
1
1741
 
EXPLAIN 
1742
 
SELECT 1 FROM (SELECT COUNT(DISTINCT c1) 
1743
 
FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
1744
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1745
 
1       PRIMARY <derived2>      system  NULL    NULL    NULL    NULL    1       
1746
 
2       DERIVED t1      index   c3,c2   c2      18      NULL    5       
1747
 
DROP TABLE t1;
1748
 
CREATE TABLE t1 (c1 DECIMAL(12,2), c2 DECIMAL(12,2), c3 DECIMAL(12,2), 
1749
 
KEY (c3), KEY (c2, c3))
1750
 
ENGINE=InnoDB;
1751
 
INSERT INTO t1 VALUES (1,1,1), (1,1,1), (1,1,2), (1,1,1), (1,1,2);
1752
 
SELECT 1 FROM (SELECT COUNT(DISTINCT c1) 
1753
 
FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
1754
 
1
1755
 
1
1756
 
EXPLAIN 
1757
 
SELECT 1 FROM (SELECT COUNT(DISTINCT c1) 
1758
 
FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
1759
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1760
 
1       PRIMARY <derived2>      system  NULL    NULL    NULL    NULL    1       
1761
 
2       DERIVED t1      index   c3,c2   c2      14      NULL    5       
1762
 
DROP TABLE t1;
1763
 
End of 5.1 tests
1764
 
drop table if exists t1, t2, t3;
1765
 
create table t1(a int);
1766
 
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
1767
 
create table t2 (a int, b int, pk int, key(a,b), primary key(pk)) engine=innodb;
1768
 
insert into t2 select @a:=A.a+10*(B.a + 10*C.a),@a, @a from t1 A, t1 B, t1 C;
1769
 
this must use key 'a', not PRIMARY:
1770
 
explain select a from t2 where a=b;
1771
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1772
 
1       SIMPLE  t2      index   NULL    a       10      NULL    #       Using where; Using index
1773
 
drop table t1, t2;
1774
 
SET SESSION BINLOG_FORMAT=STATEMENT;
1775
 
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
1776
 
select @@session.sql_log_bin, @@session.binlog_format, @@session.tx_isolation;
1777
 
@@session.sql_log_bin   1
1778
 
@@session.binlog_format STATEMENT
1779
 
@@session.tx_isolation  READ-COMMITTED
1780
 
CREATE TABLE t1 ( a INT ) ENGINE=InnoDB;
1781
 
INSERT INTO t1 VALUES(1);
1782
 
DROP TABLE t1;
1783
 
DROP TABLE IF EXISTS t1;
1784
 
CREATE TABLE t1 (a char(50)) ENGINE=InnoDB;
1785
 
CREATE INDEX i1 on t1 (a(3));
1786
 
SELECT * FROM t1 WHERE a = 'abcde';
1787
 
a
1788
 
DROP TABLE t1;
1789
 
CREATE TABLE foo (a int, b int, c char(10),
1790
 
PRIMARY KEY (c(3)),
1791
 
KEY b (b)
1792
 
) engine=innodb;
1793
 
CREATE TABLE foo2 (a int, b int, c char(10),
1794
 
PRIMARY KEY (c),
1795
 
KEY b (b)
1796
 
) engine=innodb;
1797
 
CREATE TABLE bar (a int, b int, c char(10),
1798
 
PRIMARY KEY (c(3)),
1799
 
KEY b (b)
1800
 
) engine=myisam;
1801
 
INSERT INTO foo VALUES
1802
 
(1,2,'abcdefghij'), (2,3,''), (3,4,'klmnopqrst'),
1803
 
(4,5,'uvwxyz'), (5,6,'meotnsyglt'), (4,5,'asfdewe');
1804
 
INSERT INTO bar SELECT * FROM foo;
1805
 
INSERT INTO foo2 SELECT * FROM foo;
1806
 
EXPLAIN SELECT c FROM bar WHERE b>2;;
1807
 
id      1
1808
 
select_type     SIMPLE
1809
 
table   bar
1810
 
type    ALL
1811
 
possible_keys   b
1812
 
key     NULL
1813
 
key_len NULL
1814
 
ref     NULL
1815
 
rows    6
1816
 
Extra   Using where
1817
 
EXPLAIN SELECT c FROM foo WHERE b>2;;
1818
 
id      1
1819
 
select_type     SIMPLE
1820
 
table   foo
1821
 
type    ALL
1822
 
possible_keys   b
1823
 
key     NULL
1824
 
key_len NULL
1825
 
ref     NULL
1826
 
rows    6
1827
 
Extra   Using where
1828
 
EXPLAIN SELECT c FROM foo2 WHERE b>2;;
1829
 
id      1
1830
 
select_type     SIMPLE
1831
 
table   foo2
1832
 
type    range
1833
 
possible_keys   b
1834
 
key     b
1835
 
key_len 5
1836
 
ref     NULL
1837
 
rows    3
1838
 
Extra   Using where; Using index
1839
 
EXPLAIN SELECT c FROM bar WHERE c>2;;
1840
 
id      1
1841
 
select_type     SIMPLE
1842
 
table   bar
1843
 
type    ALL
1844
 
possible_keys   PRIMARY
1845
 
key     NULL
1846
 
key_len NULL
1847
 
ref     NULL
1848
 
rows    6
1849
 
Extra   Using where
1850
 
EXPLAIN SELECT c FROM foo WHERE c>2;;
1851
 
id      1
1852
 
select_type     SIMPLE
1853
 
table   foo
1854
 
type    ALL
1855
 
possible_keys   PRIMARY
1856
 
key     NULL
1857
 
key_len NULL
1858
 
ref     NULL
1859
 
rows    6
1860
 
Extra   Using where
1861
 
EXPLAIN SELECT c FROM foo2 WHERE c>2;;
1862
 
id      1
1863
 
select_type     SIMPLE
1864
 
table   foo2
1865
 
type    index
1866
 
possible_keys   PRIMARY
1867
 
key     b
1868
 
key_len 5
1869
 
ref     NULL
1870
 
rows    6
1871
 
Extra   Using where; Using index
1872
 
DROP TABLE foo, bar, foo2;
1873
 
DROP TABLE IF EXISTS t1,t3,t2;
1874
 
DROP FUNCTION IF EXISTS f1;
1875
 
CREATE FUNCTION f1() RETURNS VARCHAR(250)
1876
 
BEGIN
1877
 
return 'hhhhhhh' ;
1878
 
END|
1879
 
CREATE TABLE t1 (a VARCHAR(20), b VARCHAR(20), c VARCHAR(20)) ENGINE=INNODB;
1880
 
BEGIN WORK;
1881
 
CREATE TEMPORARY TABLE t2 (a VARCHAR(20), b VARCHAR(20), c varchar(20)) ENGINE=INNODB;
1882
 
CREATE TEMPORARY TABLE t3 LIKE t2;
1883
 
INSERT INTO t1 VALUES ('a','b',NULL),('c','d',NULL),('e','f',NULL);
1884
 
SET @stmt := CONCAT('INSERT INTO t2 SELECT tbl.a, tbl.b, f1()',' FROM t1 tbl');
1885
 
PREPARE stmt1 FROM @stmt;
1886
 
SET @stmt := CONCAT('INSERT INTO t3', ' SELECT * FROM t2');
1887
 
PREPARE stmt3 FROM @stmt;
1888
 
EXECUTE stmt1;
1889
 
COMMIT;
1890
 
DEALLOCATE PREPARE stmt1;
1891
 
DEALLOCATE PREPARE stmt3;
1892
 
DROP TABLE t1,t3,t2;
1893
 
DROP FUNCTION f1;
1894
 
DROP TABLE IF EXISTS t1,t2;
1895
 
CREATE TABLE t1 (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;
1896
 
CREATE TABLE t2 (id INT PRIMARY KEY,
1897
 
t1_id INT, INDEX par_ind (t1_id),
1898
 
FOREIGN KEY (t1_id) REFERENCES t1(id)) ENGINE=INNODB;
1899
 
INSERT INTO t1 VALUES (1),(2);
1900
 
INSERT INTO t2 VALUES (3,2);
1901
 
SET AUTOCOMMIT = 0;
1902
 
START TRANSACTION;
1903
 
TRUNCATE TABLE t1;
1904
 
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `t1` (`id`))
1905
 
SELECT * FROM t1;
1906
 
id
1907
 
1
1908
 
2
1909
 
COMMIT;
1910
 
SELECT * FROM t1;
1911
 
id
1912
 
1
1913
 
2
1914
 
START TRANSACTION;
1915
 
TRUNCATE TABLE t1;
1916
 
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `t1` (`id`))
1917
 
SELECT * FROM t1;
1918
 
id
1919
 
1
1920
 
2
1921
 
ROLLBACK;
1922
 
SELECT * FROM t1;
1923
 
id
1924
 
1
1925
 
2
1926
 
SET AUTOCOMMIT = 1;
1927
 
START TRANSACTION;
1928
 
SELECT * FROM t1;
1929
 
id
1930
 
1
1931
 
2
1932
 
COMMIT;
1933
 
TRUNCATE TABLE t1;
1934
 
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `t1` (`id`))
1935
 
SELECT * FROM t1;
1936
 
id
1937
 
1
1938
 
2
1939
 
DELETE FROM t2 WHERE id = 3;
1940
 
START TRANSACTION;
1941
 
SELECT * FROM t1;
1942
 
id
1943
 
1
1944
 
2
1945
 
TRUNCATE TABLE t1;
1946
 
ROLLBACK;
1947
 
SELECT * FROM t1;
1948
 
id
1949
 
TRUNCATE TABLE t2;
1950
 
DROP TABLE t2;
1951
 
DROP TABLE t1;
1952
 
#
1953
 
# Bug#40127 Multiple table DELETE IGNORE hangs on foreign key constraint violation on 5.0
1954
 
#
1955
 
CREATE TABLE t1 (
1956
 
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
1957
 
PRIMARY KEY (id)
1958
 
) ENGINE=InnoDB;
1959
 
CREATE TABLE t2 (
1960
 
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
1961
 
aid INT UNSIGNED NOT NULL,
1962
 
PRIMARY KEY (id),
1963
 
FOREIGN KEY (aid) REFERENCES t1 (id)
1964
 
) ENGINE=InnoDB;
1965
 
CREATE TABLE t3 (
1966
 
bid INT UNSIGNED NOT NULL,
1967
 
FOREIGN KEY (bid) REFERENCES t2 (id)
1968
 
) ENGINE=InnoDB;
1969
 
CREATE TABLE t4 (
1970
 
a INT
1971
 
) ENGINE=InnoDB;
1972
 
CREATE TABLE t5 (
1973
 
a INT
1974
 
) ENGINE=InnoDB;
1975
 
INSERT INTO t1 (id) VALUES (1);
1976
 
INSERT INTO t2 (id, aid) VALUES (1, 1),(2,1),(3,1),(4,1);
1977
 
INSERT INTO t3 (bid) VALUES (1);
1978
 
INSERT INTO t4 VALUES (1),(2),(3),(4),(5);
1979
 
INSERT INTO t5 VALUES (1);
1980
 
DELETE t5 FROM t4 LEFT JOIN t5 ON t4.a= t5.a;
1981
 
DELETE t2, t1 FROM t2 INNER JOIN t1 ON (t2.aid = t1.id) WHERE t2.id = 1;
1982
 
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t3`, CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`bid`) REFERENCES `t2` (`id`))
1983
 
DELETE t2, t1 FROM t2 INNER JOIN t1 ON (t2.aid = t1.id) WHERE t2.id = 1;
1984
 
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t3`, CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`bid`) REFERENCES `t2` (`id`))
1985
 
DELETE IGNORE t2, t1 FROM t2 INNER JOIN t1 ON (t2.aid = t1.id) WHERE t2.id = 1;
1986
 
DROP TABLE t3;
1987
 
DROP TABLE t2;
1988
 
DROP TABLE t1;
1989
 
DROP TABLES t4,t5;
1990
 
# Bug#40127 Multiple table DELETE IGNORE hangs on foreign key constraint violation on 5.0
1991
 
# Testing for any side effects of IGNORE on AFTER DELETE triggers used with
1992
 
# transactional tables.
1993
 
#
1994
 
CREATE TABLE t1 (i INT NOT NULL PRIMARY KEY) ENGINE=InnoDB;
1995
 
CREATE TABLE t2 (a VARCHAR(100)) ENGINE=InnoDB;
1996
 
CREATE TABLE t3 (i INT NOT NULL PRIMARY KEY) ENGINE=InnoDB;
1997
 
CREATE TABLE t4 (i INT NOT NULL PRIMARY KEY, t1i INT, 
1998
 
FOREIGN KEY (t1i) REFERENCES t1(i))
1999
 
ENGINE=InnoDB;
2000
 
CREATE TRIGGER trg AFTER DELETE ON t1 FOR EACH ROW
2001
 
BEGIN
2002
 
SET @b:='EXECUTED TRIGGER';
2003
 
INSERT INTO t2 VALUES (@b);
2004
 
SET @a:= error_happens_here;
2005
 
END||
2006
 
SET @b:="";
2007
 
SET @a:="";
2008
 
INSERT INTO t1 VALUES (1),(2),(3),(4);
2009
 
INSERT INTO t3 SELECT * FROM t1;
2010
 
** An error in a trigger causes rollback of the statement.
2011
 
DELETE t1 FROM t3 LEFT JOIN t1 ON t1.i=t3.i;
2012
 
ERROR 42S22: Unknown column 'error_happens_here' in 'field list'
2013
 
SELECT @a,@b;
2014
 
@a      @b
2015
 
        EXECUTED TRIGGER
2016
 
SELECT * FROM t2;
2017
 
a
2018
 
SELECT * FROM t1 LEFT JOIN t3 ON t1.i=t3.i;
2019
 
i       i
2020
 
1       1
2021
 
2       2
2022
 
3       3
2023
 
4       4
2024
 
** Same happens with the IGNORE option
2025
 
DELETE IGNORE t1 FROM t3 LEFT JOIN t1 ON t1.i=t3.i;
2026
 
ERROR 42S22: Unknown column 'error_happens_here' in 'field list'
2027
 
SELECT * FROM t2;
2028
 
a
2029
 
SELECT * FROM t1 LEFT JOIN t3 ON t1.i=t3.i;
2030
 
i       i
2031
 
1       1
2032
 
2       2
2033
 
3       3
2034
 
4       4
2035
 
**
2036
 
** The following is an attempt to demonstrate
2037
 
** error handling inside a row iteration.
2038
 
**
2039
 
DROP TRIGGER trg;
2040
 
TRUNCATE TABLE t1;
2041
 
TRUNCATE TABLE t2;
2042
 
TRUNCATE TABLE t3;
2043
 
INSERT INTO t1 VALUES (1),(2),(3),(4);
2044
 
INSERT INTO t3 VALUES (1),(2),(3),(4);
2045
 
INSERT INTO t4 VALUES (3,3),(4,4);
2046
 
CREATE TRIGGER trg AFTER DELETE ON t1 FOR EACH ROW
2047
 
BEGIN
2048
 
SET @b:= CONCAT('EXECUTED TRIGGER FOR ROW ',CAST(OLD.i AS CHAR));
2049
 
INSERT INTO t2 VALUES (@b);
2050
 
END||
2051
 
** DELETE is prevented by foreign key constrains but errors are silenced.
2052
 
** The AFTER trigger isn't fired.
2053
 
DELETE IGNORE t1 FROM t3 LEFT JOIN t1 ON t1.i=t3.i;
2054
 
** Tables are modified by best effort:
2055
 
SELECT * FROM t1 LEFT JOIN t3 ON t1.i=t3.i;
2056
 
i       i
2057
 
3       3
2058
 
4       4
2059
 
** The AFTER trigger was only executed on successful rows:
2060
 
SELECT * FROM t2;
2061
 
a
2062
 
EXECUTED TRIGGER FOR ROW 1
2063
 
EXECUTED TRIGGER FOR ROW 2
2064
 
DROP TRIGGER trg;
2065
 
**
2066
 
** Induce an error midway through an AFTER-trigger
2067
 
**
2068
 
TRUNCATE TABLE t4;
2069
 
TRUNCATE TABLE t1;
2070
 
TRUNCATE TABLE t3;
2071
 
INSERT INTO t1 VALUES (1),(2),(3),(4);
2072
 
INSERT INTO t3 VALUES (1),(2),(3),(4);
2073
 
CREATE TRIGGER trg AFTER DELETE ON t1 FOR EACH ROW
2074
 
BEGIN
2075
 
SET @a:= @a+1;
2076
 
IF @a > 2 THEN
2077
 
INSERT INTO t4 VALUES (5,5);
2078
 
END IF;
2079
 
END||
2080
 
SET @a:=0;
2081
 
** Errors in the trigger causes the statement to abort.
2082
 
DELETE IGNORE t1 FROM t3 LEFT JOIN t1 ON t1.i=t3.i;
2083
 
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`t1i`) REFERENCES `t1` (`i`))
2084
 
SELECT * FROM t1 LEFT JOIN t3 ON t1.i=t3.i;
2085
 
i       i
2086
 
1       1
2087
 
2       2
2088
 
3       3
2089
 
4       4
2090
 
SELECT * FROM t4;
2091
 
i       t1i
2092
 
DROP TRIGGER trg;
2093
 
DROP TABLE t4;
2094
 
DROP TABLE t1;
2095
 
DROP TABLE t2;
2096
 
DROP TABLE t3;
2097
 
CREATE TABLE t1 (a INT, b INT, KEY (a)) ENGINE = INNODB;
2098
 
CREATE TABLE t2 (a INT KEY, b INT, KEY (b)) ENGINE = INNODB;
2099
 
CREATE TABLE t3 (a INT, b INT KEY, KEY (a)) ENGINE = INNODB;
2100
 
CREATE TABLE t4 (a INT KEY, b INT, KEY (b)) ENGINE = INNODB;
2101
 
INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6);
2102
 
INSERT INTO t2 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
2103
 
INSERT INTO t3 VALUES (1, 101), (2, 102), (3, 103), (4, 104), (5, 105), (6, 106);
2104
 
INSERT INTO t4 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
2105
 
UPDATE t1, t2 SET t1.a = t1.a + 100, t2.b = t1.a + 10 
2106
 
WHERE t1.a BETWEEN 2 AND 4 AND t2.a = t1.b;
2107
 
SELECT * FROM t2;
2108
 
a       b
2109
 
1       1
2110
 
2       12
2111
 
3       13
2112
 
4       14
2113
 
5       5
2114
 
UPDATE t3, t4 SET t3.a = t3.a + 100, t4.b = t3.a + 10 
2115
 
WHERE t3.a BETWEEN 2 AND 4 AND t4.a = t3.b - 100;
2116
 
SELECT * FROM t4;
2117
 
a       b
2118
 
1       1
2119
 
2       12
2120
 
3       13
2121
 
4       14
2122
 
5       5
2123
 
DROP TABLE t1, t2, t3, t4;
2124
 
#
2125
 
# Bug#44886: SIGSEGV in test_if_skip_sort_order() -
2126
 
#            uninitialized variable used as subscript 
2127
 
#
2128
 
CREATE TABLE t1 (a INT, b INT, c INT, d INT, PRIMARY KEY (b), KEY (a,c))
2129
 
ENGINE=InnoDB;
2130
 
INSERT INTO t1 VALUES (1,1,1,0);
2131
 
CREATE TABLE t2 (a INT, b INT, e INT, KEY (e)) ENGINE=InnoDB;
2132
 
INSERT INTO t2 VALUES (1,1,2);
2133
 
CREATE TABLE t3 (a INT, b INT) ENGINE=MyISAM;
2134
 
INSERT INTO t3 VALUES (1, 1);
2135
 
SELECT * FROM t1, t2, t3
2136
 
WHERE t1.a = t3.a AND (t1.b = t3.b OR t1.d) AND t2.b = t1.b AND t2.e = 2
2137
 
GROUP BY t1.b;
2138
 
a       b       c       d       a       b       e       a       b
2139
 
1       1       1       0       1       1       2       1       1
2140
 
DROP TABLE t1, t2, t3;
2141
 
#
2142
 
# Bug #45828: Optimizer won't use partial primary key if another 
2143
 
# index can prevent filesort
2144
 
#
2145
 
CREATE TABLE `t1` (
2146
 
c1 int NOT NULL,
2147
 
c2 int NOT NULL,
2148
 
c3 int NOT NULL,
2149
 
PRIMARY KEY (c1,c2),
2150
 
KEY  (c3)
2151
 
) ENGINE=InnoDB;
2152
 
INSERT INTO t1 VALUES (5,2,1246276747);
2153
 
INSERT INTO t1 VALUES (2,1,1246281721);
2154
 
INSERT INTO t1 VALUES (7,3,1246281756);
2155
 
INSERT INTO t1 VALUES (4,2,1246282139);
2156
 
INSERT INTO t1 VALUES (3,1,1246282230);
2157
 
INSERT INTO t1 VALUES (1,0,1246282712);
2158
 
INSERT INTO t1 VALUES (8,3,1246282765);
2159
 
INSERT INTO t1 SELECT c1+10,c2+10,c3+10 FROM t1;
2160
 
INSERT INTO t1 SELECT c1+100,c2+100,c3+100 from t1;
2161
 
INSERT INTO t1 SELECT c1+1000,c2+1000,c3+1000 from t1;
2162
 
INSERT INTO t1 SELECT c1+10000,c2+10000,c3+10000 from t1;
2163
 
INSERT INTO t1 SELECT c1+100000,c2+100000,c3+100000 from t1;
2164
 
INSERT INTO t1 SELECT c1+1000000,c2+1000000,c3+1000000 from t1;
2165
 
SELECT * FROM t1 WHERE c1 = 99999999 AND c3 > 1 ORDER BY c3;
2166
 
c1      c2      c3
2167
 
EXPLAIN SELECT * FROM t1 WHERE c1 = 99999999 AND c3 > 1 ORDER BY c3;
2168
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2169
 
1       SIMPLE  t1      ref     PRIMARY,c3      PRIMARY 4       const   1       Using where; Using filesort
2170
 
EXPLAIN SELECT * FROM t1 FORCE INDEX (PRIMARY) WHERE c1 = 99999999 AND c3 > 1 ORDER BY c3;
2171
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2172
 
1       SIMPLE  t1      ref     PRIMARY PRIMARY 4       const   1       Using where; Using filesort
2173
 
CREATE TABLE t2 (
2174
 
c1 int NOT NULL,
2175
 
c2 int NOT NULL,
2176
 
c3 int NOT NULL,
2177
 
KEY (c1,c2),
2178
 
KEY (c3)
2179
 
) ENGINE=InnoDB;
2180
 
explain SELECT * FROM t2 WHERE c1 = 99999999 AND c3 > 1 ORDER BY c3;
2181
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2182
 
1       SIMPLE  t2      ref     c1,c3   c1      4       const   1       Using where; Using filesort
2183
 
DROP TABLE t1,t2;
2184
 
#
2185
 
# 36259: Optimizing with ORDER BY
2186
 
#
2187
 
CREATE TABLE t1 (
2188
 
a INT NOT NULL AUTO_INCREMENT,
2189
 
b INT NOT NULL,
2190
 
c INT NOT NULL,
2191
 
d VARCHAR(5),
2192
 
e INT NOT NULL,
2193
 
PRIMARY KEY (a), KEY i2 (b,c,d)
2194
 
) ENGINE=InnoDB;
2195
 
INSERT INTO t1 (b,c,d,e) VALUES (1,1,'a',1), (2,2,'b',2);
2196
 
INSERT INTO t1 (b,c,d,e) SELECT RAND()*10000, RAND()*10000, d, e FROM t1;
2197
 
INSERT INTO t1 (b,c,d,e) SELECT RAND()*10000, RAND()*10000, d, e FROM t1;
2198
 
INSERT INTO t1 (b,c,d,e) SELECT RAND()*10000, RAND()*10000, d, e FROM t1;
2199
 
INSERT INTO t1 (b,c,d,e) SELECT RAND()*10000, RAND()*10000, d, e FROM t1;
2200
 
INSERT INTO t1 (b,c,d,e) SELECT RAND()*10000, RAND()*10000, d, e FROM t1;
2201
 
INSERT INTO t1 (b,c,d,e) SELECT RAND()*10000, RAND()*10000, d, e FROM t1;
2202
 
EXPLAIN SELECT * FROM t1 WHERE b=1 AND c=1 ORDER BY a;
2203
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2204
 
1       SIMPLE  t1      ref     i2      i2      8       const,const     1       Using where; Using filesort
2205
 
EXPLAIN SELECT * FROM t1 FORCE INDEX(i2) WHERE b=1 and c=1 ORDER BY a;
2206
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2207
 
1       SIMPLE  t1      ref     i2      i2      8       const,const     1       Using where; Using filesort
2208
 
EXPLAIN SELECT * FROM t1 FORCE INDEX(PRIMARY) WHERE b=1 AND c=1 ORDER BY a;
2209
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2210
 
1       SIMPLE  t1      index   NULL    PRIMARY 4       NULL    128     Using where
2211
 
DROP TABLE t1;
2212
 
#
2213
 
# Bug #47963: Wrong results when index is used
2214
 
#
2215
 
CREATE TABLE t1(
2216
 
a VARCHAR(5) NOT NULL, 
2217
 
b VARCHAR(5) NOT NULL,
2218
 
c DATETIME NOT NULL,
2219
 
KEY (c) 
2220
 
) ENGINE=InnoDB;
2221
 
INSERT INTO t1 VALUES('TEST', 'TEST', '2009-10-09 00:00:00');
2222
 
SELECT * FROM t1 WHERE a = 'TEST' AND 
2223
 
c >= '2009-10-09 00:00:00' AND c <= '2009-10-09 00:00:00';
2224
 
a       b       c
2225
 
TEST    TEST    2009-10-09 00:00:00
2226
 
SELECT * FROM t1 WHERE a = 'TEST' AND 
2227
 
c >= '2009-10-09 00:00:00.0' AND c <= '2009-10-09 00:00:00.0';
2228
 
a       b       c
2229
 
TEST    TEST    2009-10-09 00:00:00
2230
 
SELECT * FROM t1 WHERE a = 'TEST' AND 
2231
 
c >= '2009-10-09 00:00:00.0' AND c <= '2009-10-09 00:00:00';
2232
 
a       b       c
2233
 
TEST    TEST    2009-10-09 00:00:00
2234
 
SELECT * FROM t1 WHERE a = 'TEST' AND 
2235
 
c >= '2009-10-09 00:00:00' AND c <= '2009-10-09 00:00:00.0';
2236
 
a       b       c
2237
 
TEST    TEST    2009-10-09 00:00:00
2238
 
SELECT * FROM t1 WHERE a = 'TEST' AND 
2239
 
c >= '2009-10-09 00:00:00.000' AND c <= '2009-10-09 00:00:00.000';
2240
 
a       b       c
2241
 
TEST    TEST    2009-10-09 00:00:00
2242
 
SELECT * FROM t1 WHERE a = 'TEST' AND 
2243
 
c >= '2009-10-09 00:00:00.00' AND c <= '2009-10-09 00:00:00.001';
2244
 
a       b       c
2245
 
TEST    TEST    2009-10-09 00:00:00
2246
 
SELECT * FROM t1 WHERE a = 'TEST' AND 
2247
 
c >= '2009-10-09 00:00:00.001' AND c <= '2009-10-09 00:00:00.00';
2248
 
a       b       c
2249
 
EXPLAIN SELECT * FROM t1 WHERE a = 'TEST' AND 
2250
 
c >= '2009-10-09 00:00:00.001' AND c <= '2009-10-09 00:00:00.00';
2251
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2252
 
1       SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    Impossible WHERE noticed after reading const tables
2253
 
DROP TABLE t1;
2254
 
#
2255
 
# Bug #46175: NULL read_view and consistent read assertion
2256
 
#
2257
 
CREATE TABLE t1(a CHAR(13),KEY(a)) ENGINE=innodb;
2258
 
CREATE TABLE t2(b DATETIME,KEY(b)) ENGINE=innodb;
2259
 
INSERT INTO t1 VALUES (),();
2260
 
INSERT INTO t2 VALUES (),();
2261
 
CREATE OR REPLACE VIEW v1 AS SELECT 1 FROM t2 
2262
 
WHERE b =(SELECT a FROM t1 LIMIT 1);
2263
 
CREATE PROCEDURE p1(num INT)
2264
 
BEGIN
2265
 
DECLARE i INT DEFAULT 0;
2266
 
REPEAT
2267
 
SHOW CREATE VIEW v1;
2268
 
SET i:=i+1;
2269
 
UNTIL i>num END REPEAT;
2270
 
END|
2271
 
# Should not crash
2272
 
# Should not crash
2273
 
DROP PROCEDURE p1;
2274
 
DROP VIEW v1;
2275
 
DROP TABLE t1,t2;
2276
 
#
2277
 
# Bug #49324: more valgrind errors in test_if_skip_sort_order
2278
 
#
2279
 
CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=innodb ;
2280
 
#should not cause valgrind warnings
2281
 
SELECT 1 FROM t1 JOIN t1 a USING(a) GROUP BY t1.a,t1.a;
2282
 
1
2283
 
DROP TABLE t1;
2284
 
#
2285
 
# Bug#50843: Filesort used instead of clustered index led to
2286
 
#            performance degradation.
2287
 
#
2288
 
create table t1(f1 int not null primary key, f2 int) engine=innodb;
2289
 
create table t2(f1 int not null, key (f1)) engine=innodb;
2290
 
insert into t1 values (1,1),(2,2),(3,3);
2291
 
insert into t2 values (1),(2),(3);
2292
 
explain select t1.* from t1 left join t2 using(f1) group by t1.f1;
2293
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2294
 
1       SIMPLE  t1      index   NULL    PRIMARY 4       NULL    3       
2295
 
1       SIMPLE  t2      ref     f1      f1      4       test.t1.f1      1       Using index
2296
 
drop table t1,t2;
2297
 
#
2298
 
#
2299
 
# Bug #39653: find_shortest_key in sql_select.cc does not consider
2300
 
#             clustered primary keys
2301
 
#
2302
 
CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c INT, d INT, e INT, f INT,
2303
 
KEY (b,c)) ENGINE=INNODB;
2304
 
INSERT INTO t1 VALUES (1,1,1,1,1,1), (2,2,2,2,2,2), (3,3,3,3,3,3),
2305
 
(4,4,4,4,4,4), (5,5,5,5,5,5), (6,6,6,6,6,6),
2306
 
(7,7,7,7,7,7), (8,8,8,8,8,8), (9,9,9,9,9,9),
2307
 
(11,11,11,11,11,11);
2308
 
EXPLAIN SELECT COUNT(*) FROM t1;
2309
 
id      1
2310
 
select_type     SIMPLE
2311
 
table   t1
2312
 
type    index
2313
 
possible_keys   NULL
2314
 
key     b
2315
 
key_len 10
2316
 
ref     NULL
2317
 
rows    10
2318
 
Extra   Using index
2319
 
DROP TABLE t1;
2320
 
#
2321
 
# Bug #49838: DROP INDEX and ADD UNIQUE INDEX for same index may
2322
 
#   corrupt definition at engine
2323
 
#
2324
 
CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL, KEY k (a,b)) 
2325
 
ENGINE=InnoDB;
2326
 
ALTER TABLE t1 DROP INDEX k, ADD UNIQUE INDEX k (a,b);
2327
 
SHOW INDEXES FROM t1;;
2328
 
Table   t1
2329
 
Non_unique      0
2330
 
Key_name        k
2331
 
Seq_in_index    1
2332
 
Column_name     a
2333
 
Collation       A
2334
 
Cardinality     0
2335
 
Sub_part        NULL
2336
 
Packed  NULL
2337
 
Null    
2338
 
Index_type      BTREE
2339
 
Comment 
2340
 
Table   t1
2341
 
Non_unique      0
2342
 
Key_name        k
2343
 
Seq_in_index    2
2344
 
Column_name     b
2345
 
Collation       A
2346
 
Cardinality     0
2347
 
Sub_part        NULL
2348
 
Packed  NULL
2349
 
Null    
2350
 
Index_type      BTREE
2351
 
Comment 
2352
 
DROP TABLE t1;
2353
 
#
2354
 
# Bug #47453: InnoDB incorrectly changes TIMESTAMP columns when 
2355
 
#  JOINed during an UPDATE
2356
 
#
2357
 
CREATE TABLE t1 (d INT) ENGINE=InnoDB;
2358
 
CREATE TABLE t2 (a INT, b INT, 
2359
 
c TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
2360
 
ON UPDATE CURRENT_TIMESTAMP) ENGINE=InnoDB;
2361
 
set up our data elements
2362
 
INSERT INTO t1 (d) VALUES (1);
2363
 
INSERT INTO t2 (a,b) VALUES (1,1);
2364
 
SELECT SECOND(c) INTO @bug47453 FROM t2;
2365
 
SELECT SECOND(c)-@bug47453 FROM t1 JOIN t2 ON d=a;
2366
 
SECOND(c)-@bug47453
2367
 
0
2368
 
UPDATE t1 JOIN t2 ON d=a SET b=1 WHERE a=1;
2369
 
SELECT SECOND(c)-@bug47453 FROM t1 JOIN t2 ON d=a;
2370
 
SECOND(c)-@bug47453
2371
 
0
2372
 
SELECT SLEEP(1);
2373
 
SLEEP(1)
2374
 
0
2375
 
UPDATE t1 JOIN t2 ON d=a SET b=1 WHERE a=1;
2376
 
#should be 0
2377
 
SELECT SECOND(c)-@bug47453 FROM t1 JOIN t2 ON d=a;
2378
 
SECOND(c)-@bug47453
2379
 
0
2380
 
DROP TABLE t1, t2;
2381
 
#
2382
 
# Bug #53334: wrong result for outer join with impossible ON condition
2383
 
# (see the same test case for MyISAM in join.test)
2384
 
#
2385
 
CREATE TABLE t1 (id INT PRIMARY KEY);
2386
 
CREATE TABLE t2 (id INT);
2387
 
INSERT INTO t1 VALUES (75);
2388
 
INSERT INTO t1 VALUES (79);
2389
 
INSERT INTO t1 VALUES (78);
2390
 
INSERT INTO t1 VALUES (77);
2391
 
REPLACE INTO t1 VALUES (76);
2392
 
REPLACE INTO t1 VALUES (76);
2393
 
INSERT INTO t1 VALUES (104);
2394
 
INSERT INTO t1 VALUES (103);
2395
 
INSERT INTO t1 VALUES (102);
2396
 
INSERT INTO t1 VALUES (101);
2397
 
INSERT INTO t1 VALUES (105);
2398
 
INSERT INTO t1 VALUES (106);
2399
 
INSERT INTO t1 VALUES (107);
2400
 
INSERT INTO t2 VALUES (107),(75),(1000);
2401
 
SELECT t1.id,t2.id FROM t2 LEFT JOIN t1 ON t1.id>=74 AND t1.id<=0
2402
 
WHERE t2.id=75 AND t1.id IS NULL;
2403
 
id      id
2404
 
NULL    75
2405
 
EXPLAIN SELECT t1.id,t2.id FROM t2 LEFT JOIN t1 ON t1.id>=74 AND t1.id<=0
2406
 
WHERE t2.id=75 AND t1.id IS NULL;
2407
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
2408
 
1       SIMPLE  t1      const   PRIMARY NULL    NULL    NULL    1       Impossible ON condition
2409
 
1       SIMPLE  t2      ALL     NULL    NULL    NULL    NULL    3       Using where
2410
 
DROP TABLE t1,t2;
2411
 
#
2412
 
# Bug #53830: !table || (!table->read_set || bitmap_is_set(table->read_set, field_index))
2413
 
#
2414
 
CREATE TABLE t1 (a INT, b INT, c INT, d INT,
2415
 
PRIMARY KEY(a,b,c), KEY(b,d))
2416
 
ENGINE=InnoDB;
2417
 
INSERT INTO t1 VALUES (0, 77, 1, 3);
2418
 
UPDATE t1 SET d = 0 WHERE b = 77 AND c = 25;
2419
 
DROP TABLE t1;
2420
 
End of 5.1 tests