1
drop table if exists t1, t2, t3;
3
event_date date DEFAULT '0000-00-00' NOT NULL,
4
type int(11) DEFAULT '0' NOT NULL,
5
event_id int(11) DEFAULT '0' NOT NULL,
6
PRIMARY KEY (event_date,type,event_id)
8
INSERT INTO t1 VALUES ('1999-07-10',100100,24), ('1999-07-11',100100,25),
9
('1999-07-13',100600,0), ('1999-07-13',100600,4), ('1999-07-13',100600,26),
10
('1999-07-14',100600,10), ('1999-07-15',100600,16), ('1999-07-15',100800,45),
11
('1999-07-15',101000,47), ('1999-07-16',100800,46), ('1999-07-20',100600,5),
12
('1999-07-20',100600,27), ('1999-07-21',100600,11), ('1999-07-22',100600,17),
13
('1999-07-23',100100,39), ('1999-07-24',100100,39), ('1999-07-24',100500,40),
14
('1999-07-25',100100,39), ('1999-07-27',100600,1), ('1999-07-27',100600,6),
15
('1999-07-27',100600,28), ('1999-07-28',100600,12), ('1999-07-29',100500,41),
16
('1999-07-29',100600,18), ('1999-07-30',100500,41), ('1999-07-31',100500,41),
17
('1999-08-01',100700,34), ('1999-08-03',100600,7), ('1999-08-03',100600,29),
18
('1999-08-04',100600,13), ('1999-08-05',100500,42), ('1999-08-05',100600,19),
19
('1999-08-06',100500,42), ('1999-08-07',100500,42), ('1999-08-08',100500,42),
20
('1999-08-10',100600,2), ('1999-08-10',100600,9), ('1999-08-10',100600,30),
21
('1999-08-11',100600,14), ('1999-08-12',100600,20), ('1999-08-17',100500,8),
22
('1999-08-17',100600,31), ('1999-08-18',100600,15), ('1999-08-19',100600,22),
23
('1999-08-24',100600,3), ('1999-08-24',100600,32), ('1999-08-27',100500,43),
24
('1999-08-31',100600,33), ('1999-09-17',100100,37), ('1999-09-18',100100,37),
25
('1999-09-19',100100,37), ('2000-12-18',100700,38);
26
select event_date,type,event_id from t1 WHERE event_date >= "1999-07-01" AND event_date < "1999-07-15" AND (type=100600 OR type=100100) ORDER BY event_date;
27
event_date type event_id
34
explain select event_date,type,event_id from t1 WHERE type = 100601 and event_date >= "1999-07-01" AND event_date < "1999-07-15" AND (type=100600 OR type=100100) ORDER BY event_date;
35
id select_type table type possible_keys key key_len ref rows Extra
36
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
37
select event_date,type,event_id from t1 WHERE event_date >= "1999-07-01" AND event_date <= "1999-07-15" AND (type=100600 OR type=100100) or event_date >= "1999-07-01" AND event_date <= "1999-07-15" AND type=100099;
38
event_date type event_id
48
PAPER_ID smallint(6) DEFAULT '0' NOT NULL,
49
YEAR smallint(6) DEFAULT '0' NOT NULL,
50
ISSUE smallint(6) DEFAULT '0' NOT NULL,
51
CLOSED tinyint(4) DEFAULT '0' NOT NULL,
52
ISS_DATE date DEFAULT '0000-00-00' NOT NULL,
53
PRIMARY KEY (PAPER_ID,YEAR,ISSUE)
55
INSERT INTO t1 VALUES (3,1999,34,0,'1999-07-12'), (1,1999,111,0,'1999-03-23'),
56
(1,1999,222,0,'1999-03-23'), (3,1999,33,0,'1999-07-12'),
57
(3,1999,32,0,'1999-07-12'), (3,1999,31,0,'1999-07-12'),
58
(3,1999,30,0,'1999-07-12'), (3,1999,29,0,'1999-07-12'),
59
(3,1999,28,0,'1999-07-12'), (1,1999,40,1,'1999-05-01'),
60
(1,1999,41,1,'1999-05-01'), (1,1999,42,1,'1999-05-01'),
61
(1,1999,46,1,'1999-05-01'), (1,1999,47,1,'1999-05-01'),
62
(1,1999,48,1,'1999-05-01'), (1,1999,49,1,'1999-05-01'),
63
(1,1999,50,0,'1999-05-01'), (1,1999,51,0,'1999-05-01'),
64
(1,1999,200,0,'1999-06-28'), (1,1999,52,0,'1999-06-28'),
65
(1,1999,53,0,'1999-06-28'), (1,1999,54,0,'1999-06-28'),
66
(1,1999,55,0,'1999-06-28'), (1,1999,56,0,'1999-07-01'),
67
(1,1999,57,0,'1999-07-01'), (1,1999,58,0,'1999-07-01'),
68
(1,1999,59,0,'1999-07-01'), (1,1999,60,0,'1999-07-01'),
69
(3,1999,35,0,'1999-07-12');
70
select YEAR,ISSUE from t1 where PAPER_ID=3 and (YEAR>1999 or (YEAR=1999 and ISSUE>28)) order by YEAR,ISSUE;
80
Table Op Msg_type Msg_text
81
test.t1 check status OK
83
Table Op Msg_type Msg_text
84
test.t1 repair status OK
87
id int(11) NOT NULL auto_increment,
88
parent_id int(11) DEFAULT '0' NOT NULL,
89
level tinyint(4) DEFAULT '0' NOT NULL,
91
KEY parent_id (parent_id),
94
INSERT INTO t1 VALUES (1,0,0), (3,1,1), (4,1,1), (8,2,2), (9,2,2), (17,3,2),
95
(22,4,2), (24,4,2), (28,5,2), (29,5,2), (30,5,2), (31,6,2), (32,6,2), (33,6,2),
96
(203,7,2), (202,7,2), (20,3,2), (157,0,0), (193,5,2), (40,7,2), (2,1,1),
97
(15,2,2), (6,1,1), (34,6,2), (35,6,2), (16,3,2), (7,1,1), (36,7,2), (18,3,2),
98
(26,5,2), (27,5,2), (183,4,2), (38,7,2), (25,5,2), (37,7,2), (21,4,2),
99
(19,3,2), (5,1,1), (179,5,2);
100
SELECT * FROM t1 WHERE level = 1 AND parent_id = 1;
108
SELECT * FROM t1 WHERE level = 1 AND parent_id = 1 order by id;
118
Satellite varchar(25) not null,
119
SensorMode varchar(25) not null,
120
FullImageCornersUpperLeftLongitude double not null,
121
FullImageCornersUpperRightLongitude double not null,
122
FullImageCornersUpperRightLatitude double not null,
123
FullImageCornersLowerRightLatitude double not null,
124
index two (Satellite, SensorMode, FullImageCornersUpperLeftLongitude, FullImageCornersUpperRightLongitude, FullImageCornersUpperRightLatitude, FullImageCornersLowerRightLatitude));
125
insert into t1 values("OV-3","PAN1",91,-92,40,50);
126
insert into t1 values("OV-4","PAN1",91,-92,40,50);
127
select * from t1 where t1.Satellite = "OV-3" and t1.SensorMode = "PAN1" and t1.FullImageCornersUpperLeftLongitude > -90.000000 and t1.FullImageCornersUpperRightLongitude < -82.000000;
128
Satellite SensorMode FullImageCornersUpperLeftLongitude FullImageCornersUpperRightLongitude FullImageCornersUpperRightLatitude FullImageCornersLowerRightLatitude
129
OV-3 PAN1 91 -92 40 50
131
create table t1 ( aString char(100) not null default "", key aString (aString(10)) );
132
insert t1 (aString) values ( "believe in myself" ), ( "believe" ), ("baaa" ), ( "believe in love");
133
select * from t1 where aString < "believe in myself" order by aString;
138
select * from t1 where aString > "believe in love" order by aString;
141
alter table t1 drop key aString;
142
select * from t1 where aString < "believe in myself" order by aString;
147
select * from t1 where aString > "believe in love" order by aString;
152
t1ID int(10) unsigned NOT NULL auto_increment,
153
art binary(1) NOT NULL default '',
154
KNR char(5) NOT NULL default '',
155
RECHNR char(6) NOT NULL default '',
156
POSNR char(2) NOT NULL default '',
157
ARTNR char(10) NOT NULL default '',
158
TEX char(70) NOT NULL default '',
164
INSERT INTO t1 (art) VALUES ('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
165
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
166
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
167
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
168
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
169
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
170
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
171
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
172
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
173
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
174
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
175
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
176
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
177
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
178
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
179
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
180
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
181
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
182
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
183
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
184
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
185
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
186
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
187
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
188
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
189
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
190
('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),('j'),('J'),
191
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
192
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
193
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
194
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
195
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
196
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
197
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
198
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
199
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
200
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),
201
('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j'),('j');
202
select count(*) from t1 where upper(art) = 'J';
205
select count(*) from t1 where art = 'J' or art = 'j';
208
select count(*) from t1 where art = 'j' or art = 'J';
211
select count(*) from t1 where art = 'j';
214
select count(*) from t1 where art = 'J';
218
create table t1 (x int, y int, index(x), index(y));
219
insert into t1 (x) values (1),(2),(3),(4),(5),(6),(7),(8),(9);
221
explain select * from t1, t1 t2 where t1.y = 8 and t2.x between 7 and t1.y+0;
222
id select_type table type possible_keys key key_len ref rows Extra
223
1 SIMPLE t1 ref y y 5 const 1
224
1 SIMPLE t2 range x x 5 NULL 2 Using index condition; Using MRR; Using join buffer
225
explain select * from t1, t1 t2 where t1.y = 8 and t2.x >= 7 and t2.x <= t1.y+0;
226
id select_type table type possible_keys key key_len ref rows Extra
227
1 SIMPLE t1 ref y y 5 const 1
228
1 SIMPLE t2 range x x 5 NULL 2 Using index condition; Using MRR; Using join buffer
229
explain select * from t1, t1 t2 where t1.y = 2 and t2.x between t1.y-1 and t1.y+1;
230
id select_type table type possible_keys key key_len ref rows Extra
231
1 SIMPLE t1 ref y y 5 const 1
232
1 SIMPLE t2 range x x 5 NULL 3 Using index condition; Using MRR; Using join buffer
233
explain select * from t1, t1 t2 where t1.y = 2 and t2.x >= t1.y-1 and t2.x <= t1.y+1;
234
id select_type table type possible_keys key key_len ref rows Extra
235
1 SIMPLE t1 ref y y 5 const 1
236
1 SIMPLE t2 range x x 5 NULL 3 Using index condition; Using MRR; Using join buffer
237
explain select * from t1, t1 t2 where t1.y = 2 and t2.x between 0 and t1.y;
238
id select_type table type possible_keys key key_len ref rows Extra
239
1 SIMPLE t1 ref y y 5 const 1
240
1 SIMPLE t2 range x x 5 NULL 2 Using index condition; Using MRR; Using join buffer
241
explain select * from t1, t1 t2 where t1.y = 2 and t2.x >= 0 and t2.x <= t1.y;
242
id select_type table type possible_keys key key_len ref rows Extra
243
1 SIMPLE t1 ref y y 5 const 1
244
1 SIMPLE t2 range x x 5 NULL 2 Using index condition; Using MRR; Using join buffer
245
explain select count(*) from t1 where x in (1);
246
id select_type table type possible_keys key key_len ref rows Extra
247
1 SIMPLE t1 ref x x 5 const 1 Using index
248
explain select count(*) from t1 where x in (1,2);
249
id select_type table type possible_keys key key_len ref rows Extra
250
1 SIMPLE t1 index x x 5 NULL 9 Using where; Using index
252
CREATE TABLE t1 (key1 int(11) NOT NULL default '0', KEY i1 (key1));
253
INSERT INTO t1 VALUES (0),(0),(0),(0),(0),(1),(1);
254
CREATE TABLE t2 (keya int(11) NOT NULL default '0', KEY j1 (keya));
255
INSERT INTO t2 VALUES (0),(0),(1),(1),(2),(2);
256
explain select * from t1, t2 where (t1.key1 <t2.keya + 1) and t2.keya=3;
257
id select_type table type possible_keys key key_len ref rows Extra
258
1 SIMPLE t2 ref j1 j1 4 const 1 Using index
259
1 SIMPLE t1 index i1 i1 4 NULL 7 Using where; Using index; Using join buffer
260
explain select * from t1 force index(i1), t2 force index(j1) where
261
(t1.key1 <t2.keya + 1) and t2.keya=3;
262
id select_type table type possible_keys key key_len ref rows Extra
263
1 SIMPLE t2 ref j1 j1 4 const 1 Using index
264
1 SIMPLE t1 index i1 i1 4 NULL 7 Using where; Using index; Using join buffer
267
a int(11) default NULL,
268
b int(11) default NULL,
272
INSERT INTO t1 VALUES
273
(1,1),(2,1),(3,1),(4,1),(5,1),(6,1),(7,1),(8,1),(9,1),(10,2),(10,2),
274
(13,2),(14,2),(15,2),(16,2),(17,3),(17,3),(16,3),(17,3),(19,3),(20,3),
275
(21,4),(22,5),(23,5),(24,5),(25,5),(26,5),(30,5),(31,5),(32,5),(33,5),
276
(33,5),(33,5),(33,5),(33,5),(34,5),(35,5);
277
EXPLAIN SELECT * FROM t1 WHERE a IN(1,2) AND b=5;
278
id select_type table type possible_keys key key_len ref rows Extra
279
1 SIMPLE t1 range a,b a 5 NULL 2 Using index condition; Using where; Using MRR
280
SELECT * FROM t1 WHERE a IN(1,2) AND b=5;
283
CREATE TABLE t1 (a int, b int, c int, INDEX (c,a,b));
284
INSERT INTO t1 VALUES (1,0,0),(1,0,0),(1,0,0);
285
INSERT INTO t1 VALUES (0,1,0),(0,1,0),(0,1,0);
286
SELECT COUNT(*) FROM t1 WHERE (c=0 and a=1) or (c=0 and b=1);
289
SELECT COUNT(*) FROM t1 WHERE (c=0 and b=1) or (c=0 and a=1);
293
CREATE TABLE t1 ( a int not null, b int not null, INDEX ab(a,b) );
294
INSERT INTO t1 VALUES (47,1), (70,1), (15,1), (15, 4);
298
( b =1 AND a BETWEEN 14 AND 21 ) OR
299
( b =2 AND a BETWEEN 16 AND 18 ) OR
300
( b =3 AND a BETWEEN 15 AND 19 ) OR
301
(a BETWEEN 19 AND 47)
308
id int( 11 ) unsigned NOT NULL AUTO_INCREMENT ,
309
line int( 5 ) unsigned NOT NULL default '0',
310
columnid int( 3 ) unsigned NOT NULL default '0',
311
owner int( 3 ) unsigned NOT NULL default '0',
312
ordinal int( 3 ) unsigned NOT NULL default '0',
313
showid smallint( 6 ) unsigned NOT NULL default '1',
314
tableid int( 1 ) unsigned NOT NULL default '1',
315
content int( 5 ) unsigned NOT NULL default '188',
316
PRIMARY KEY ( owner, id ) ,
317
KEY menu( owner, showid, columnid ) ,
318
KEY `COLUMN` ( owner, columnid, line ) ,
319
KEY `LINES` ( owner, tableid, content, id ) ,
320
KEY recount( owner, line )
322
INSERT into t1 (owner,id,columnid,line) values (11,15,15,1),(11,13,13,5);
323
SELECT id, columnid, tableid, content, showid, line, ordinal FROM t1 WHERE owner=11 AND ((columnid IN ( 15, 13, 14 ) AND line IN ( 1, 2, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 31 )) OR (columnid IN ( 13, 14 ) AND line IN ( 15 ))) LIMIT 0 , 30;
324
id columnid tableid content showid line ordinal
328
create table t1 (id int(10) primary key);
329
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9);
330
select id from t1 where id in (2,5,9) ;
335
select id from t1 where id=2 or id=5 or id=9 ;
341
create table t1 ( id1 int not null, id2 int not null, idnull int null, c char(20), primary key (id1,id2));
342
insert into t1 values (0,1,NULL,"aaa"), (1,1,NULL,"aaa"), (2,1,NULL,"aaa"),
343
(3,1,NULL,"aaa"), (4,1,NULL,"aaa"), (5,1,NULL,"aaa"),
344
(6,1,NULL,"aaa"), (7,1,NULL,"aaa"), (8,1,NULL,"aaa"),
345
(9,1,NULL,"aaa"), (10,1,NULL,"aaa"), (11,1,NULL,"aaa"),
346
(12,1,NULL,"aaa"), (13,1,NULL,"aaa"), (14,1,NULL,"aaa"),
347
(15,1,NULL,"aaa"), (16,1,NULL,"aaa"), (17,1,NULL,"aaa"),
348
(18,1,NULL,"aaa"), (19,1,NULL,"aaa"), (20,1,NULL,"aaa");
349
select a.id1, b.idnull from t1 as a, t1 as b where a.id2=1 and a.id1=1 and b.id1=a.idnull order by b.id2 desc limit 1;
353
id int not null auto_increment,
354
name char(1) not null,
357
index uid_index (uid));
359
id int not null auto_increment,
360
name char(1) not null,
363
index uid_index (uid));
364
insert into t1(id, uid, name) values(1, 0, ' ');
365
insert into t1(uid, name) values(0, ' ');
366
insert into t2(uid, name) select uid, name from t1;
367
insert into t1(uid, name) select uid, name from t2;
368
insert into t2(uid, name) select uid, name from t1;
369
insert into t1(uid, name) select uid, name from t2;
370
insert into t2(uid, name) select uid, name from t1;
371
insert into t1(uid, name) select uid, name from t2;
372
insert into t2(uid, name) select uid, name from t1;
373
insert into t1(uid, name) select uid, name from t2;
374
insert into t2(uid, name) select uid, name from t1;
375
insert into t1(uid, name) select uid, name from t2;
376
insert into t2(uid, name) select uid, name from t1;
377
insert into t2(uid, name) select uid, name from t1;
378
insert into t2(uid, name) select uid, name from t1;
379
insert into t2(uid, name) select uid, name from t1;
380
insert into t1(uid, name) select uid, name from t2;
382
insert into t2(uid, name) values
409
insert into t1(uid, name) select uid, name from t2 order by uid;
411
insert into t2(id, uid, name) select id, uid, name from t1;
412
select count(*) from t1;
415
select count(*) from t2;
419
Table Op Msg_type Msg_text
420
test.t1 analyze status OK
421
test.t2 analyze status Table is already up to date
422
explain select * from t1, t2 where t1.uid=t2.uid AND t1.uid > 0;
423
id select_type table type possible_keys key key_len ref rows Extra
424
1 SIMPLE t1 range uid_index uid_index 4 NULL 112 Using index condition; Using MRR
425
1 SIMPLE t2 ref uid_index uid_index 4 test.t1.uid 38
426
explain select * from t1, t2 where t1.uid=t2.uid AND t2.uid > 0;
427
id select_type table type possible_keys key key_len ref rows Extra
428
1 SIMPLE t1 range uid_index uid_index 4 NULL 112 Using index condition; Using MRR
429
1 SIMPLE t2 ref uid_index uid_index 4 test.t1.uid 38
430
explain select * from t1, t2 where t1.uid=t2.uid AND t1.uid != 0;
431
id select_type table type possible_keys key key_len ref rows Extra
432
1 SIMPLE t1 range uid_index uid_index 4 NULL 113 Using index condition; Using MRR
433
1 SIMPLE t2 ref uid_index uid_index 4 test.t1.uid 38
434
explain select * from t1, t2 where t1.uid=t2.uid AND t2.uid != 0;
435
id select_type table type possible_keys key key_len ref rows Extra
436
1 SIMPLE t1 range uid_index uid_index 4 NULL 113 Using index condition; Using MRR
437
1 SIMPLE t2 ref uid_index uid_index 4 test.t1.uid 38
438
select * from t1, t2 where t1.uid=t2.uid AND t1.uid > 0;
439
id name uid id name uid
466
select * from t1, t2 where t1.uid=t2.uid AND t1.uid != 0;
467
id name uid id name uid
495
create table t1 (x bigint unsigned not null);
496
insert into t1(x) values (0xfffffffffffffff0);
497
insert into t1(x) values (0xfffffffffffffff1);
502
select count(*) from t1 where x>0;
505
select count(*) from t1 where x=0;
508
select count(*) from t1 where x<0;
511
select count(*) from t1 where x < -16;
514
select count(*) from t1 where x = -16;
517
select count(*) from t1 where x > -16;
520
select count(*) from t1 where x = 18446744073709551601;
523
create table t2 (x bigint not null);
524
insert into t2(x) values (-16);
525
insert into t2(x) values (-15);
530
select count(*) from t2 where x>0;
533
select count(*) from t2 where x=0;
536
select count(*) from t2 where x<0;
539
select count(*) from t2 where x < -16;
542
select count(*) from t2 where x = -16;
545
select count(*) from t2 where x > -16;
548
select count(*) from t2 where x = 18446744073709551601;
552
create table t1 (x bigint unsigned not null primary key) engine=innodb;
553
insert into t1(x) values (0xfffffffffffffff0);
554
insert into t1(x) values (0xfffffffffffffff1);
559
select count(*) from t1 where x>0;
562
select count(*) from t1 where x=0;
565
select count(*) from t1 where x<0;
568
select count(*) from t1 where x < -16;
571
select count(*) from t1 where x = -16;
574
select count(*) from t1 where x > -16;
577
select count(*) from t1 where x = 18446744073709551601;
581
create table t1 (a bigint unsigned);
582
create index t1i on t1(a);
583
insert into t1 select 18446744073709551615;
584
insert into t1 select 18446744073709551614;
585
explain select * from t1 where a <> -1;
586
id select_type table type possible_keys key key_len ref rows Extra
587
1 SIMPLE t1 index t1i t1i 9 NULL 2 Using where; Using index
588
select * from t1 where a <> -1;
592
explain select * from t1 where a > -1 or a < -1;
593
id select_type table type possible_keys key key_len ref rows Extra
594
1 SIMPLE t1 index t1i t1i 9 NULL 2 Using where; Using index
595
select * from t1 where a > -1 or a < -1;
599
explain select * from t1 where a > -1;
600
id select_type table type possible_keys key key_len ref rows Extra
601
1 SIMPLE t1 index t1i t1i 9 NULL 2 Using where; Using index
602
select * from t1 where a > -1;
606
explain select * from t1 where a < -1;
607
id select_type table type possible_keys key key_len ref rows Extra
608
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
609
select * from t1 where a < -1;
613
create table t1 (a char(10), b text, key (a)) character set latin1;
614
INSERT INTO t1 (a) VALUES
615
('111'),('222'),('222'),('222'),('222'),('444'),('aaa'),('AAA'),('bbb');
616
explain select * from t1 where a='aaa';
617
id select_type table type possible_keys key key_len ref rows Extra
618
1 SIMPLE t1 ref a a 11 const 2 Using index condition
619
explain select * from t1 where a=binary 'aaa';
620
id select_type table type possible_keys key key_len ref rows Extra
621
1 SIMPLE t1 range a a 11 NULL 2 Using index condition; Using MRR
622
explain select * from t1 where a='aaa' collate latin1_bin;
623
id select_type table type possible_keys key key_len ref rows Extra
624
1 SIMPLE t1 range a a 11 NULL 2 Using index condition; Using MRR
625
explain select * from t1 where a='aaa' collate latin1_german1_ci;
626
id select_type table type possible_keys key key_len ref rows Extra
627
1 SIMPLE t1 ALL a NULL NULL NULL 9 Using where
630
`CLIENT` char(3) character set latin1 collate latin1_bin NOT NULL default '000',
631
`ARG1` char(3) character set latin1 collate latin1_bin NOT NULL default '',
632
`ARG2` char(3) character set latin1 collate latin1_bin NOT NULL default '',
633
`FUNCTION` varchar(10) character set latin1 collate latin1_bin NOT NULL default '',
634
`FUNCTINT` int(11) NOT NULL default '0',
635
KEY `VERI_CLNT~2` (`ARG1`)
636
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
637
INSERT INTO t1 VALUES ('000',' 0',' 0','Text 001',0), ('000',' 0',' 1','Text 002',0),
638
('000',' 1',' 2','Text 003',0), ('000',' 2',' 3','Text 004',0),
639
('001',' 3',' 0','Text 017',0);
640
SELECT count(*) FROM t1 WHERE CLIENT='000' AND (ARG1 != ' 1' OR ARG1 != ' 2');
643
SELECT count(*) FROM t1 WHERE CLIENT='000' AND (ARG1 != ' 2' OR ARG1 != ' 1');
647
create table t1 (a int);
648
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
650
pk1 int(11) NOT NULL,
651
pk2 int(11) NOT NULL,
652
pk3 int(11) NOT NULL,
653
pk4 int(11) NOT NULL,
655
PRIMARY KEY (pk1,pk2,pk3,pk4)
656
) DEFAULT CHARSET=latin1;
657
insert into t2 select 1, A.a+10*B.a, 432, 44, 'fillerZ' from t1 A, t1 B;
658
INSERT INTO t2 VALUES (2621, 2635, 0, 0,'filler'), (2621, 2635, 1, 0,'filler'),
659
(2621, 2635, 10, 0,'filler'), (2621, 2635, 11, 0,'filler'),
660
(2621, 2635, 14, 0,'filler'), (2621, 2635, 1000015, 0,'filler');
662
WHERE ((((pk4 =0) AND (pk1 =2621) AND (pk2 =2635)))
663
OR ((pk4 =1) AND (((pk1 IN ( 7, 2, 1 ))) OR (pk1 =522)) AND ((pk2 IN ( 0, 2635))))
664
) AND (pk3 >=1000000);
665
pk1 pk2 pk3 pk4 filler
666
2621 2635 1000015 0 filler
668
create table t1(a char(2), key(a(1)));
669
insert into t1 values ('x'), ('xx');
670
explain select a from t1 where a > 'x';
671
id select_type table type possible_keys key key_len ref rows Extra
672
1 SIMPLE t1 range a a 2 NULL 2 Using where
673
select a from t1 where a > 'x';
678
OXID varchar(32) COLLATE latin1_german2_ci NOT NULL DEFAULT '',
679
OXPARENTID varchar(32) COLLATE latin1_german2_ci NOT NULL DEFAULT 'oxrootid',
680
OXLEFT int NOT NULL DEFAULT '0',
681
OXRIGHT int NOT NULL DEFAULT '0',
682
OXROOTID varchar(32) COLLATE latin1_german2_ci NOT NULL DEFAULT '',
686
KEY OXRIGHT (OXRIGHT),
687
KEY OXROOTID (OXROOTID)
688
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_german2_ci;
689
INSERT INTO t1 VALUES
690
('d8c4177d09f8b11f5.52725521','oxrootid',1,40,'d8c4177d09f8b11f5.52725521'),
691
('d8c4177d151affab2.81582770','d8c4177d09f8b11f5.52725521',2,3,
692
'd8c4177d09f8b11f5.52725521'),
693
('d8c4177d206a333d2.74422679','d8c4177d09f8b11f5.52725521',4,5,
694
'd8c4177d09f8b11f5.52725521'),
695
('d8c4177d225791924.30714720','d8c4177d09f8b11f5.52725521',6,7,
696
'd8c4177d09f8b11f5.52725521'),
697
('d8c4177d2380fc201.39666693','d8c4177d09f8b11f5.52725521',8,9,
698
'd8c4177d09f8b11f5.52725521'),
699
('d8c4177d24ccef970.14957924','d8c4177d09f8b11f5.52725521',10,11,
700
'd8c4177d09f8b11f5.52725521');
702
SELECT s.oxid FROM t1 v, t1 s
703
WHERE s.oxrootid = 'd8c4177d09f8b11f5.52725521' AND
704
v.oxrootid ='d8c4177d09f8b11f5.52725521' AND
705
s.oxleft > v.oxleft AND s.oxleft < v.oxright;
706
id select_type table type possible_keys key key_len ref rows Extra
707
1 SIMPLE v ref OXLEFT,OXRIGHT,OXROOTID OXROOTID 34 const 5 Using index condition
708
1 SIMPLE s ALL OXLEFT NULL NULL NULL 6 Range checked for each record (index map: 0x4)
709
SELECT s.oxid FROM t1 v, t1 s
710
WHERE s.oxrootid = 'd8c4177d09f8b11f5.52725521' AND
711
v.oxrootid ='d8c4177d09f8b11f5.52725521' AND
712
s.oxleft > v.oxleft AND s.oxleft < v.oxright;
714
d8c4177d151affab2.81582770
715
d8c4177d206a333d2.74422679
716
d8c4177d225791924.30714720
717
d8c4177d2380fc201.39666693
718
d8c4177d24ccef970.14957924
721
c1 char(10), c2 char(10), c3 char(10), c4 char(10),
722
c5 char(10), c6 char(10), c7 char(10), c8 char(10),
723
c9 char(10), c10 char(10), c11 char(10), c12 char(10),
724
c13 char(10), c14 char(10), c15 char(10), c16 char(10),
725
index(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12,c13,c14,c15,c16)
727
insert into t1 (c1) values ('1'),('1'),('1'),('1');
728
select * from t1 where
729
c1 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
730
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
731
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
732
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
733
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
734
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
735
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
736
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
737
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
738
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
739
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
740
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
741
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
742
and c2 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
743
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
744
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
745
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
746
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
747
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
748
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
749
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
750
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
751
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
752
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
753
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
754
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
755
and c3 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
756
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
757
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
758
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
759
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
760
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
761
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
762
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
763
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
764
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
765
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
766
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
767
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
768
and c4 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
769
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
770
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
771
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
772
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
773
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
774
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
775
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
776
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
777
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
778
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
779
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
780
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
781
and c5 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
782
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
783
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
784
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
785
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
786
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
787
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
788
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
789
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
790
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
791
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
792
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
793
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
794
and c6 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
795
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
796
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
797
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
798
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
799
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
800
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
801
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
802
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
803
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
804
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
805
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
806
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
807
and c7 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
808
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
809
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
810
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
811
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
812
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
813
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
814
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
815
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
816
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
817
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
818
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
819
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
820
and c8 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
821
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
822
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
823
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
824
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
825
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
826
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
827
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
828
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
829
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
830
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
831
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
832
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
833
and c9 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
834
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
835
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
836
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
837
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
838
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
839
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
840
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
841
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
842
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
843
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
844
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
845
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
846
and c10 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
847
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
848
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
849
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
850
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
851
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
852
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
853
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
854
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
855
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
856
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
857
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
858
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC");
859
c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16
863
id int(11) NOT NULL auto_increment,
868
INSERT INTO t1 VALUES
869
(1,'B'), (2,'B'), (3,'B'), (4,'B'), (5,'B'), (6,'B'),
870
(7,'B'), (8,'B'), (9,'B'), (10,'B'), (11,'B'), (12,'B'),
871
(13,'B'), (14,'B'), (15,'B'), (16,'B'), (17,'B'), (18,'B'),
872
(19,'B'), (20,'B'), (21,'B'), (22,'B'), (23,'B'), (24,'B'),
873
(25,'A'), (26,'A'), (27,'A'), (28,'A'), (29,'A'), (30,'A'),
874
(31,'A'), (32,'A'), (33,'A'), (34,'A'), (35,'A'), (36,'A'),
875
(37,'A'), (38,'A'), (39,'A'), (40,'A'), (41,'A'), (42,'A'),
876
(43,'A'), (44,'A'), (45,'A'), (46,'A'), (47,'A'), (48,'A'),
877
(49,'A'), (50,'A'), (51,'A'), (52,'A'), (53,'C'), (54,'C'),
878
(55,'C'), (56,'C'), (57,'C'), (58,'C'), (59,'C'), (60,'C');
879
EXPLAIN SELECT * FROM t1 WHERE status <> 'A' AND status <> 'B';
880
id select_type table type possible_keys key key_len ref rows Extra
881
1 SIMPLE t1 range status status 23 NULL 11 Using index condition; Using MRR
882
EXPLAIN SELECT * FROM t1 WHERE status NOT IN ('A','B');
883
id select_type table type possible_keys key key_len ref rows Extra
884
1 SIMPLE t1 range status status 23 NULL 11 Using index condition; Using MRR
885
SELECT * FROM t1 WHERE status <> 'A' AND status <> 'B';
895
SELECT * FROM t1 WHERE status NOT IN ('A','B');
905
EXPLAIN SELECT status FROM t1 WHERE status <> 'A' AND status <> 'B';
906
id select_type table type possible_keys key key_len ref rows Extra
907
1 SIMPLE t1 range status status 23 NULL 11 Using where; Using index
908
EXPLAIN SELECT status FROM t1 WHERE status NOT IN ('A','B');
909
id select_type table type possible_keys key key_len ref rows Extra
910
1 SIMPLE t1 range status status 23 NULL 11 Using where; Using index
911
EXPLAIN SELECT * FROM t1 WHERE status NOT BETWEEN 'A' AND 'B';
912
id select_type table type possible_keys key key_len ref rows Extra
913
1 SIMPLE t1 range status status 23 NULL 10 Using index condition; Using MRR
914
EXPLAIN SELECT * FROM t1 WHERE status < 'A' OR status > 'B';
915
id select_type table type possible_keys key key_len ref rows Extra
916
1 SIMPLE t1 range status status 23 NULL 10 Using index condition; Using MRR
917
SELECT * FROM t1 WHERE status NOT BETWEEN 'A' AND 'B';
927
SELECT * FROM t1 WHERE status < 'A' OR status > 'B';
938
CREATE TABLE t1 (a int, b int, primary key(a,b));
939
INSERT INTO t1 VALUES
940
(1,1),(1,2),(1,3),(2,1),(2,2),(2,3),(3,1),(3,2),(3,3),(4,1),(4,2),(4,3);
941
CREATE VIEW v1 as SELECT a,b FROM t1 WHERE b=3;
942
EXPLAIN SELECT a,b FROM t1 WHERE a < 2 and b=3;
943
id select_type table type possible_keys key key_len ref rows Extra
944
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 4 Using where; Using index
945
EXPLAIN SELECT a,b FROM v1 WHERE a < 2 and b=3;
946
id select_type table type possible_keys key key_len ref rows Extra
947
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 4 Using where; Using index
948
EXPLAIN SELECT a,b FROM t1 WHERE a < 2;
949
id select_type table type possible_keys key key_len ref rows Extra
950
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 4 Using where; Using index
951
EXPLAIN SELECT a,b FROM v1 WHERE a < 2;
952
id select_type table type possible_keys key key_len ref rows Extra
953
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 4 Using where; Using index
954
SELECT a,b FROM t1 WHERE a < 2 and b=3;
957
SELECT a,b FROM v1 WHERE a < 2 and b=3;
962
CREATE TABLE t1 (name varchar(15) NOT NULL, KEY idx(name));
963
INSERT INTO t1 VALUES ('Betty'), ('Anna');
968
DELETE FROM t1 WHERE name NOT LIKE 'A%a';
973
CREATE TABLE t1 (a int, KEY idx(a));
974
INSERT INTO t1 VALUES (NULL), (1), (2), (3);
981
DELETE FROM t1 WHERE NOT(a <=> 2);
986
create table t1 (a int, b int, primary key(a,b));
987
create view v1 as select a, b from t1;
988
INSERT INTO `t1` VALUES
989
(0,0),(1,0),(2,0),(3,0),(4,0),(5,1),(6,1),(7,1),(8,1),(9,1),(10,2),(11,2),(12,2)
990
,(13,2),(14,2),(15,3),(16,3),(17,3),(18,3),(19,3);
991
explain select * from t1 where a in (3,4) and b in (1,2,3);
992
id select_type table type possible_keys key key_len ref rows Extra
993
1 SIMPLE t1 range PRIMARY PRIMARY 8 NULL # Using where; Using index
994
explain select * from v1 where a in (3,4) and b in (1,2,3);
995
id select_type table type possible_keys key key_len ref rows Extra
996
1 SIMPLE t1 range PRIMARY PRIMARY 8 NULL # Using where; Using index
997
explain select * from t1 where a between 3 and 4 and b between 1 and 2;
998
id select_type table type possible_keys key key_len ref rows Extra
999
1 SIMPLE t1 range PRIMARY PRIMARY 8 NULL # Using where; Using index
1000
explain select * from v1 where a between 3 and 4 and b between 1 and 2;
1001
id select_type table type possible_keys key key_len ref rows Extra
1002
1 SIMPLE t1 range PRIMARY PRIMARY 8 NULL # Using where; Using index
1005
create table t3 (a int);
1006
insert into t3 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
1007
create table t1 (a varchar(10), filler char(200), key(a)) charset=binary;
1008
insert into t1 values ('a','');
1009
insert into t1 values ('a ','');
1010
insert into t1 values ('a ', '');
1011
insert into t1 select concat('a', 1000 + A.a + 10 * (B.a + 10 * C.a)), ''
1012
from t3 A, t3 B, t3 C;
1013
create table t2 (a varchar(10), filler char(200), key(a));
1014
insert into t2 select * from t1;
1015
explain select * from t1 where a between 'a' and 'a ';
1016
id select_type table type possible_keys key key_len ref rows Extra
1017
1 SIMPLE t1 range a a 13 NULL # Using index condition; Using MRR
1018
explain select * from t1 where a = 'a' or a='a ';
1019
id select_type table type possible_keys key key_len ref rows Extra
1020
1 SIMPLE t1 range a a 13 NULL # Using index condition; Using MRR
1021
explain select * from t2 where a between 'a' and 'a ';
1022
id select_type table type possible_keys key key_len ref rows Extra
1023
1 SIMPLE t2 ref a a 13 const # Using index condition
1024
explain select * from t2 where a = 'a' or a='a ';
1025
id select_type table type possible_keys key key_len ref rows Extra
1026
1 SIMPLE t2 ref a a 13 const # Using index condition
1027
update t1 set a='b' where a<>'a';
1028
explain select * from t1 where a not between 'b' and 'b';
1029
id select_type table type possible_keys key key_len ref rows Extra
1030
1 SIMPLE t1 range a a 13 NULL # Using index condition; Using MRR
1031
select a, hex(filler) from t1 where a not between 'b' and 'b';
1033
a 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1034
drop table t1,t2,t3;
1035
create table t1 (a int);
1036
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
1037
create table t2 (a int, key(a));
1038
insert into t2 select 2*(A.a + 10*(B.a + 10*C.a)) from t1 A, t1 B, t1 C;
1039
set @a="select * from t2 force index (a) where a NOT IN(0";
1040
select count(*) from (select @a:=concat(@a, ',', a) from t2 ) Z;
1043
set @a=concat(@a, ')');
1044
insert into t2 values (11),(13),(15);
1045
set @b= concat("explain ", @a);
1046
prepare stmt1 from @b;
1048
id select_type table type possible_keys key key_len ref rows Extra
1049
1 SIMPLE t2 index a a 5 NULL 1003 Using where; Using index
1050
prepare stmt1 from @a;
1058
id int NOT NULL DEFAULT '0',
1059
b int NOT NULL DEFAULT '0',
1060
c int NOT NULL DEFAULT '0',
1061
INDEX idx1(b,c), INDEX idx2(c));
1062
INSERT INTO t1(id) VALUES (1), (2), (3), (4), (5), (6), (7), (8);
1063
INSERT INTO t1(b,c) VALUES (3,4), (3,4);
1064
SELECT * FROM t1 WHERE b<=3 AND 3<=c;
1068
SELECT * FROM t1 WHERE 3 BETWEEN b AND c;
1072
EXPLAIN SELECT * FROM t1 WHERE b<=3 AND 3<=c;
1073
id select_type table type possible_keys key key_len ref rows Extra
1074
1 SIMPLE t1 range idx1,idx2 idx2 4 NULL 3 Using index condition; Using where; Using MRR
1075
EXPLAIN SELECT * FROM t1 WHERE 3 BETWEEN b AND c;
1076
id select_type table type possible_keys key key_len ref rows Extra
1077
1 SIMPLE t1 range idx1,idx2 idx2 4 NULL 3 Using where; Using MRR
1078
SELECT * FROM t1 WHERE 0 < b OR 0 > c;
1082
SELECT * FROM t1 WHERE 0 NOT BETWEEN b AND c;
1086
EXPLAIN SELECT * FROM t1 WHERE 0 < b OR 0 > c;
1087
id select_type table type possible_keys key key_len ref rows Extra
1088
1 SIMPLE t1 ALL idx1,idx2 NULL NULL NULL 10 Using where
1089
EXPLAIN SELECT * FROM t1 WHERE 0 NOT BETWEEN b AND c;
1090
id select_type table type possible_keys key key_len ref rows Extra
1091
1 SIMPLE t1 ALL idx1,idx2 NULL NULL NULL 10 Using where
1094
item char(20) NOT NULL default '',
1095
started datetime NOT NULL default '0000-00-00 00:00:00',
1096
price decimal(16,3) NOT NULL default '0.000',
1097
PRIMARY KEY (item,started)
1099
INSERT INTO t1 VALUES
1100
('A1','2005-11-01 08:00:00',1000),
1101
('A1','2005-11-15 00:00:00',2000),
1102
('A1','2005-12-12 08:00:00',3000),
1103
('A2','2005-12-01 08:00:00',1000);
1104
EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
1105
id select_type table type possible_keys key key_len ref rows Extra
1106
1 SIMPLE t1 ref PRIMARY PRIMARY 20 const 2 Using index condition
1108
Warning 1292 Incorrect datetime value: '2005-12-01 24:00:00' for column 'started' at row 1
1109
Warning 1292 Incorrect datetime value: '2005-12-01 24:00:00' for column 'started' at row 1
1110
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
1112
A1 2005-11-01 08:00:00 1000.000
1113
A1 2005-11-15 00:00:00 2000.000
1115
Warning 1292 Incorrect datetime value: '2005-12-01 24:00:00' for column 'started' at row 1
1116
Warning 1292 Incorrect datetime value: '2005-12-01 24:00:00' for column 'started' at row 1
1117
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-02 00:00:00';
1119
A1 2005-11-01 08:00:00 1000.000
1120
A1 2005-11-15 00:00:00 2000.000
1121
DROP INDEX `PRIMARY` ON t1;
1122
EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
1123
id select_type table type possible_keys key key_len ref rows Extra
1124
1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where
1126
Warning 1292 Incorrect datetime value: '2005-12-01 24:00:00' for column 'started' at row 1
1127
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
1129
A1 2005-11-01 08:00:00 1000.000
1130
A1 2005-11-15 00:00:00 2000.000
1132
Warning 1292 Incorrect datetime value: '2005-12-01 24:00:00' for column 'started' at row 1
1133
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-02 00:00:00';
1135
A1 2005-11-01 08:00:00 1000.000
1136
A1 2005-11-15 00:00:00 2000.000
1139
BUG#32198 "Comparison of DATE with DATETIME still not using indexes correctly"
1142
id int(11) NOT NULL auto_increment,
1143
dateval date default NULL,
1145
KEY dateval (dateval)
1146
) AUTO_INCREMENT=173;
1147
INSERT INTO t1 VALUES
1148
(1,'2007-01-01'),(2,'2007-01-02'),(3,'2007-01-03'),(4,'2007-01-04'),
1149
(5,'2007-01-05'),(6,'2007-01-06'),(7,'2007-01-07'),(8,'2007-01-08'),
1150
(9,'2007-01-09'),(10,'2007-01-10'),(11,'2007-01-11');
1151
This must use range access:
1152
explain select * from t1 where dateval >= '2007-01-01 00:00:00' and dateval <= '2007-01-02 23:59:59';
1153
id select_type table type possible_keys key key_len ref rows Extra
1154
1 SIMPLE t1 range dateval dateval 4 NULL 2 Using index condition; Using MRR
1157
a varchar(32), index (a)
1158
) DEFAULT CHARSET=latin1 COLLATE=latin1_bin;
1159
INSERT INTO t1 VALUES
1160
('B'), ('A'), ('A'), ('C'), ('B'), ('A'), ('A');
1161
SELECT a FROM t1 WHERE a='b' OR a='B';
1165
EXPLAIN SELECT a FROM t1 WHERE a='b' OR a='B';
1166
id select_type table type possible_keys key key_len ref rows Extra
1167
1 SIMPLE t1 range a a 35 NULL 3 Using where; Using index
1169
CREATE TABLE t1 (f1 TINYINT(11) UNSIGNED NOT NULL, PRIMARY KEY (f1));
1170
INSERT INTO t1 VALUES (127),(254),(0),(1),(255);
1171
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 256;
1174
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 256.0;
1177
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 255;
1180
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < -1;
1183
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 > -1;
1187
CREATE TABLE t1 ( f1 TINYINT(11) NOT NULL, PRIMARY KEY (f1));
1188
INSERT INTO t1 VALUES (127),(126),(0),(-128),(-127);
1189
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 128;
1192
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 128.0;
1195
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 < 127;
1198
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 > -129;
1201
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 > -129.0;
1204
SELECT SQL_NO_CACHE COUNT(*) FROM t1 WHERE f1 > -128;
1208
create table t1 (a int);
1209
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
1210
create table t2 (a int, b int, filler char(100));
1211
insert into t2 select A.a + 10 * (B.a + 10 * C.a), 10, 'filler' from t1 A,
1212
t1 B, t1 C where A.a < 5;
1213
insert into t2 select 1000, b, 'filler' from t2;
1214
alter table t2 add index (a,b);
1215
select 'In following EXPLAIN the access method should be ref, #rows~=500 (and not 2)' Z;
1217
In following EXPLAIN the access method should be ref, #rows~=500 (and not 2)
1218
explain select * from t2 where a=1000 and b<11;
1219
id select_type table type possible_keys key key_len ref rows Extra
1220
1 SIMPLE t2 ref a a 5 const 502 Using index condition
1223
CREATE TABLE t1 (c1 DECIMAL(10,0),INDEX(c1));
1224
INSERT INTO t1 VALUES (1),(2),(3);
1225
SELECT c1 FROM t1 WHERE c1 >= 'A' GROUP BY 1;
1231
Warning 1366 Incorrect decimal value: 'A' for column 'c1' at row 1
1232
Warning 1292 Truncated incorrect DOUBLE value: 'A'
1233
Warning 1292 Truncated incorrect DOUBLE value: 'A'
1234
Warning 1292 Truncated incorrect DOUBLE value: 'A'
1236
create table t1 (a int,b int,key (b),key (a),key (b,a));
1237
insert into t1(a,b) values (1,2),(3,4),(5,6),(7,8);
1238
create table t2 (c int);
1239
insert into t2(c) values (1),(5),(6),(7),(8);
1240
select 1 from (select c from t1,t2 where b >= 1 and a <=> c group by 1 limit 1) as d1;