1
drop table if exists t1, t2, t3;
3
event_date date DEFAULT '0000-00-00' NOT NULL,
4
type int DEFAULT '0' NOT NULL,
5
event_id int 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 int DEFAULT '0' NOT NULL,
49
YEAR int DEFAULT '0' NOT NULL,
50
ISSUE int DEFAULT '0' NOT NULL,
51
CLOSED int 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 note The storage engine for the table doesn't support repair
87
id int NOT NULL auto_increment,
88
parent_id int DEFAULT '0' NOT NULL,
89
level int 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 NOT NULL auto_increment,
153
art varbinary(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 where; 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 where; 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 where; 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 where; 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 where; 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 where; 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 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 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 range i1 i1 4 NULL 3 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 range i1 i1 4 NULL 3 Using where; Using index; Using join buffer
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 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 NOT NULL AUTO_INCREMENT ,
309
line int NOT NULL default '0',
310
columnid int NOT NULL default '0',
311
owner int NOT NULL default '0',
312
ordinal int NOT NULL default '0',
313
showid int NOT NULL default '1',
314
tableid int NOT NULL default '1',
315
content int 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 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)) ENGINE=Myisam;
359
id int not null auto_increment,
360
name char(1) not null,
363
index uid_index (uid)) engine=myisam;
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 where; 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 where; 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 where; 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 where; 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 not null);
496
insert into t1(x) values (0x0ffffffffffffff0);
497
insert into t1(x) values (0x0ffffffffffffff1);
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 not null primary key) engine=innodb;
553
insert into t1(x) values (0x0ffffffffffffff0);
554
insert into t1(x) values (0x0ffffffffffffff1);
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);
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;
591
explain select * from t1 where a > -1 or a < -1;
592
id select_type table type possible_keys key key_len ref rows Extra
593
1 SIMPLE t1 index t1i t1i 9 NULL 2 Using where; Using index
594
select * from t1 where a > -1 or a < -1;
597
explain select * from t1 where a > -1;
598
id select_type table type possible_keys key key_len ref rows Extra
599
1 SIMPLE t1 index t1i t1i 9 NULL 2 Using where; Using index
600
select * from t1 where a > -1;
602
explain select * from t1 where a < -1;
603
id select_type table type possible_keys key key_len ref rows Extra
604
1 SIMPLE t1 index t1i t1i 9 NULL 2 Using where; Using index
605
select * from t1 where a < -1;
609
create table t1 (a char(10), b text, key (a));
610
INSERT INTO t1 (a) VALUES
611
('111'),('222'),('222'),('222'),('222'),('444'),('aaa'),('AAA'),('bbb');
612
explain select * from t1 where a='aaa';
613
id select_type table type possible_keys key key_len ref rows Extra
614
1 SIMPLE t1 ref a a 43 const 2 Using where
615
explain select * from t1 where a=binary 'aaa';
616
id select_type table type possible_keys key key_len ref rows Extra
617
1 SIMPLE t1 range a a 43 NULL 2 Using where; Using MRR
618
explain select * from t1 where a='aaa' collate utf8_bin;
619
id select_type table type possible_keys key key_len ref rows Extra
620
1 SIMPLE t1 range a a 43 NULL 2 Using where; Using MRR
623
`CLIENT` char(3) collate utf8_bin NOT NULL default '000',
624
`ARG1` char(3) collate utf8_bin NOT NULL default '',
625
`ARG2` char(3) collate utf8_bin NOT NULL default '',
626
`FUNCTION` varchar(10) collate utf8_bin NOT NULL default '',
627
`FUNCTINT` int NOT NULL default '0',
628
KEY `VERI_CLNT~2` (`ARG1`)
630
INSERT INTO t1 VALUES ('000',' 0',' 0','Text 001',0), ('000',' 0',' 1','Text 002',0),
631
('000',' 1',' 2','Text 003',0), ('000',' 2',' 3','Text 004',0),
632
('001',' 3',' 0','Text 017',0);
633
SELECT count(*) FROM t1 WHERE CLIENT='000' AND (ARG1 != ' 1' OR ARG1 != ' 2');
636
SELECT count(*) FROM t1 WHERE CLIENT='000' AND (ARG1 != ' 2' OR ARG1 != ' 1');
640
create table t1 (a int);
641
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
648
PRIMARY KEY (pk1,pk2,pk3,pk4)
650
insert into t2 select 1, A.a+10*B.a, 432, 44, 'fillerZ' from t1 A, t1 B;
651
INSERT INTO t2 VALUES (2621, 2635, 0, 0,'filler'), (2621, 2635, 1, 0,'filler'),
652
(2621, 2635, 10, 0,'filler'), (2621, 2635, 11, 0,'filler'),
653
(2621, 2635, 14, 0,'filler'), (2621, 2635, 1000015, 0,'filler');
655
WHERE ((((pk4 =0) AND (pk1 =2621) AND (pk2 =2635)))
656
OR ((pk4 =1) AND (((pk1 IN ( 7, 2, 1 ))) OR (pk1 =522)) AND ((pk2 IN ( 0, 2635))))
657
) AND (pk3 >=1000000);
658
pk1 pk2 pk3 pk4 filler
659
2621 2635 1000015 0 filler
661
create table t1(a char(2), key(a(1)));
662
insert into t1 values ('x'), ('xx');
663
explain select a from t1 where a > 'x';
664
id select_type table type possible_keys key key_len ref rows Extra
665
1 SIMPLE t1 range a a 7 NULL 1 Using where
666
select a from t1 where a > 'x';
671
OXID varchar(32) NOT NULL DEFAULT '',
672
OXPARENTID varchar(32) NOT NULL DEFAULT 'oxrootid',
673
OXLEFT int NOT NULL DEFAULT '0',
674
OXRIGHT int NOT NULL DEFAULT '0',
675
OXROOTID varchar(32) NOT NULL DEFAULT '',
679
KEY OXRIGHT (OXRIGHT),
680
KEY OXROOTID (OXROOTID)
682
INSERT INTO t1 VALUES
683
('d8c4177d09f8b11f5.52725521','oxrootid',1,40,'d8c4177d09f8b11f5.52725521'),
684
('d8c4177d151affab2.81582770','d8c4177d09f8b11f5.52725521',2,3,
685
'd8c4177d09f8b11f5.52725521'),
686
('d8c4177d206a333d2.74422679','d8c4177d09f8b11f5.52725521',4,5,
687
'd8c4177d09f8b11f5.52725521'),
688
('d8c4177d225791924.30714720','d8c4177d09f8b11f5.52725521',6,7,
689
'd8c4177d09f8b11f5.52725521'),
690
('d8c4177d2380fc201.39666693','d8c4177d09f8b11f5.52725521',8,9,
691
'd8c4177d09f8b11f5.52725521'),
692
('d8c4177d24ccef970.14957924','d8c4177d09f8b11f5.52725521',10,11,
693
'd8c4177d09f8b11f5.52725521');
695
SELECT s.oxid FROM t1 v, t1 s
696
WHERE s.oxrootid = 'd8c4177d09f8b11f5.52725521' AND
697
v.oxrootid ='d8c4177d09f8b11f5.52725521' AND
698
s.oxleft > v.oxleft AND s.oxleft < v.oxright;
699
id select_type table type possible_keys key key_len ref rows Extra
700
1 SIMPLE v ref OXLEFT,OXRIGHT,OXROOTID OXROOTID 130 const 5 Using where
701
1 SIMPLE s ALL OXLEFT NULL NULL NULL 6 Range checked for each record (index map: 0x4)
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;
707
d8c4177d151affab2.81582770
708
d8c4177d206a333d2.74422679
709
d8c4177d225791924.30714720
710
d8c4177d2380fc201.39666693
711
d8c4177d24ccef970.14957924
714
c1 char(10), c2 char(10), c3 char(10), c4 char(10),
715
c5 char(10), c6 char(10), c7 char(10), c8 char(10),
716
c9 char(10), c10 char(10), c11 char(10), c12 char(10),
717
c13 char(10), c14 char(10), c15 char(10), c16 char(10),
718
index(c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12,c13,c14,c15,c16)
720
insert into t1 (c1) values ('1'),('1'),('1'),('1');
721
select * from t1 where
722
c1 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
723
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
724
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
725
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
726
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
727
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
728
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
729
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
730
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
731
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
732
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
733
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
734
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
735
and c2 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
736
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
737
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
738
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
739
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
740
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
741
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
742
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
743
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
744
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
745
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
746
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
747
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
748
and c3 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
749
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
750
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
751
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
752
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
753
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
754
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
755
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
756
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
757
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
758
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
759
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
760
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
761
and c4 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
762
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
763
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
764
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
765
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
766
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
767
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
768
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
769
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
770
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
771
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
772
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
773
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
774
and c5 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
775
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
776
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
777
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
778
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
779
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
780
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
781
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
782
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
783
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
784
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
785
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
786
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
787
and c6 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
788
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
789
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
790
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
791
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
792
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
793
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
794
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
795
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
796
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
797
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
798
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
799
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
800
and c7 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
801
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
802
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
803
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
804
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
805
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
806
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
807
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
808
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
809
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
810
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
811
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
812
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
813
and c8 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
814
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
815
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
816
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
817
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
818
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
819
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
820
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
821
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
822
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
823
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
824
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
825
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
826
and c9 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
827
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
828
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
829
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
830
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
831
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
832
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
833
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
834
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
835
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
836
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
837
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
838
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC")
839
and c10 in ("abcdefgh", "123456789", "qwertyuio", "asddfgh",
840
"abcdefg1", "123456781", "qwertyui1", "asddfg1",
841
"abcdefg2", "123456782", "qwertyui2", "asddfg2",
842
"abcdefg3", "123456783", "qwertyui3", "asddfg3",
843
"abcdefg4", "123456784", "qwertyui4", "asddfg4",
844
"abcdefg5", "123456785", "qwertyui5", "asddfg5",
845
"abcdefg6", "123456786", "qwertyui6", "asddfg6",
846
"abcdefg7", "123456787", "qwertyui7", "asddfg7",
847
"abcdefg8", "123456788", "qwertyui8", "asddfg8",
848
"abcdefg9", "123456789", "qwertyui9", "asddfg9",
849
"abcdefgA", "12345678A", "qwertyuiA", "asddfgA",
850
"abcdefgB", "12345678B", "qwertyuiB", "asddfgB",
851
"abcdefgC", "12345678C", "qwertyuiC", "asddfgC");
852
c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16
856
id int NOT NULL auto_increment,
861
INSERT INTO t1 VALUES
862
(1,'B'), (2,'B'), (3,'B'), (4,'B'), (5,'B'), (6,'B'),
863
(7,'B'), (8,'B'), (9,'B'), (10,'B'), (11,'B'), (12,'B'),
864
(13,'B'), (14,'B'), (15,'B'), (16,'B'), (17,'B'), (18,'B'),
865
(19,'B'), (20,'B'), (21,'B'), (22,'B'), (23,'B'), (24,'B'),
866
(25,'A'), (26,'A'), (27,'A'), (28,'A'), (29,'A'), (30,'A'),
867
(31,'A'), (32,'A'), (33,'A'), (34,'A'), (35,'A'), (36,'A'),
868
(37,'A'), (38,'A'), (39,'A'), (40,'A'), (41,'A'), (42,'A'),
869
(43,'A'), (44,'A'), (45,'A'), (46,'A'), (47,'A'), (48,'A'),
870
(49,'A'), (50,'A'), (51,'A'), (52,'A'), (53,'C'), (54,'C'),
871
(55,'C'), (56,'C'), (57,'C'), (58,'C'), (59,'C'), (60,'C');
872
EXPLAIN SELECT * FROM t1 WHERE status <> 'A' AND status <> 'B';
873
id select_type table type possible_keys key key_len ref rows Extra
874
1 SIMPLE t1 range status status 83 NULL 28 Using where; Using index
875
EXPLAIN SELECT * FROM t1 WHERE status NOT IN ('A','B');
876
id select_type table type possible_keys key key_len ref rows Extra
877
1 SIMPLE t1 range status status 83 NULL 28 Using where; Using index
878
SELECT * FROM t1 WHERE status <> 'A' AND status <> 'B';
888
SELECT * FROM t1 WHERE status NOT IN ('A','B');
898
EXPLAIN SELECT status FROM t1 WHERE status <> 'A' AND status <> 'B';
899
id select_type table type possible_keys key key_len ref rows Extra
900
1 SIMPLE t1 range status status 83 NULL 28 Using where; Using index
901
EXPLAIN SELECT status FROM t1 WHERE status NOT IN ('A','B');
902
id select_type table type possible_keys key key_len ref rows Extra
903
1 SIMPLE t1 range status status 83 NULL 28 Using where; Using index
904
EXPLAIN SELECT * FROM t1 WHERE status NOT BETWEEN 'A' AND 'B';
905
id select_type table type possible_keys key key_len ref rows Extra
906
1 SIMPLE t1 range status status 83 NULL 18 Using where; Using index
907
EXPLAIN SELECT * FROM t1 WHERE status < 'A' OR status > 'B';
908
id select_type table type possible_keys key key_len ref rows Extra
909
1 SIMPLE t1 range status status 83 NULL 18 Using where; Using index
910
SELECT * FROM t1 WHERE status NOT BETWEEN 'A' AND 'B';
920
SELECT * FROM t1 WHERE status < 'A' OR status > 'B';
931
CREATE TABLE t1 (name varchar(15) NOT NULL, KEY idx(name));
932
INSERT INTO t1 VALUES ('Betty'), ('Anna');
937
DELETE FROM t1 WHERE name NOT LIKE 'A%a';
942
CREATE TABLE t1 (a int, KEY idx(a));
943
INSERT INTO t1 VALUES (NULL), (1), (2), (3);
950
DELETE FROM t1 WHERE NOT(a <=> 2);
955
create table t3 (a int);
956
insert into t3 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
957
create table t1 (a varchar(10), filler char(200), key(a));
958
insert into t1 values ('a','');
959
insert into t1 values ('a ','');
960
insert into t1 values ('a ', '');
961
insert into t1 select concat('a', 1000 + A.a + 10 * (B.a + 10 * C.a)), ''
962
from t3 A, t3 B, t3 C;
963
create table t2 (a varchar(10), filler char(200), key(a));
964
insert into t2 select * from t1;
965
explain select * from t1 where a between 'a' and 'a ';
966
id select_type table type possible_keys key key_len ref rows Extra
967
1 SIMPLE t1 ref a a 43 const # Using where
968
explain select * from t1 where a = 'a' or a='a ';
969
id select_type table type possible_keys key key_len ref rows Extra
970
1 SIMPLE t1 ref a a 43 const # Using where
971
explain select * from t2 where a between 'a' and 'a ';
972
id select_type table type possible_keys key key_len ref rows Extra
973
1 SIMPLE t2 ref a a 43 const # Using where
974
explain select * from t2 where a = 'a' or a='a ';
975
id select_type table type possible_keys key key_len ref rows Extra
976
1 SIMPLE t2 ref a a 43 const # Using where
977
update t1 set a='b' where a<>'a';
978
explain select * from t1 where a not between 'b' and 'b';
979
id select_type table type possible_keys key key_len ref rows Extra
980
1 SIMPLE t1 ALL a NULL NULL NULL # Using where
981
select a, hex(filler) from t1 where a not between 'b' and 'b';
988
id int NOT NULL DEFAULT '0',
989
b int NOT NULL DEFAULT '0',
990
c int NOT NULL DEFAULT '0',
991
INDEX idx1(b,c), INDEX idx2(c));
992
INSERT INTO t1(id) VALUES (1), (2), (3), (4), (5), (6), (7), (8);
993
INSERT INTO t1(b,c) VALUES (3,4), (3,4);
994
SELECT * FROM t1 WHERE b<=3 AND 3<=c;
998
SELECT * FROM t1 WHERE 3 BETWEEN b AND c;
1002
EXPLAIN SELECT * FROM t1 WHERE b<=3 AND 3<=c;
1003
id select_type table type possible_keys key key_len ref rows Extra
1004
1 SIMPLE t1 range idx1,idx2 idx2 4 NULL 2 Using where; Using MRR
1005
EXPLAIN SELECT * FROM t1 WHERE 3 BETWEEN b AND c;
1006
id select_type table type possible_keys key key_len ref rows Extra
1007
1 SIMPLE t1 range idx1,idx2 idx2 4 NULL 2 Using where; Using MRR
1008
SELECT * FROM t1 WHERE 0 < b OR 0 > c;
1012
SELECT * FROM t1 WHERE 0 NOT BETWEEN b AND c;
1016
EXPLAIN SELECT * FROM t1 WHERE 0 < b OR 0 > c;
1017
id select_type table type possible_keys key key_len ref rows Extra
1018
1 SIMPLE t1 ALL idx1,idx2 NULL NULL NULL 10 Using where
1019
EXPLAIN SELECT * FROM t1 WHERE 0 NOT BETWEEN b AND c;
1020
id select_type table type possible_keys key key_len ref rows Extra
1021
1 SIMPLE t1 ALL idx1,idx2 NULL NULL NULL 10 Using where
1024
item char(20) NOT NULL default '',
1025
started datetime NOT NULL default '0000-00-00 00:00:00',
1026
price decimal(16,3) NOT NULL default '0.000',
1027
PRIMARY KEY (item,started)
1029
INSERT INTO t1 VALUES
1030
('A1','2005-11-01 08:00:00',1000),
1031
('A1','2005-11-15 00:00:00',2000),
1032
('A1','2005-12-12 08:00:00',3000),
1033
('A2','2005-12-01 08:00:00',1000);
1034
EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
1035
id select_type table type possible_keys key key_len ref rows Extra
1036
1 SIMPLE t1 ref PRIMARY PRIMARY 82 const 2 Using where
1038
Warning 1292 Incorrect datetime value: '2005-12-01 24:00:00' for column 'started' at row 1
1039
Warning 1292 Incorrect datetime value: '2005-12-01 24:00:00' for column 'started' at row 1
1040
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
1042
A1 2005-11-01 08:00:00 1000.000
1043
A1 2005-11-15 00:00:00 2000.000
1045
Warning 1292 Incorrect datetime value: '2005-12-01 24:00:00' for column 'started' at row 1
1046
Warning 1292 Incorrect datetime value: '2005-12-01 24:00:00' for column 'started' at row 1
1047
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-02 00:00:00';
1049
A1 2005-11-01 08:00:00 1000.000
1050
A1 2005-11-15 00:00:00 2000.000
1051
DROP INDEX `PRIMARY` ON t1;
1052
EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
1053
id select_type table type possible_keys key key_len ref rows Extra
1054
1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where
1056
Warning 1292 Incorrect datetime value: '2005-12-01 24:00:00' for column 'started' at row 1
1057
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00';
1059
A1 2005-11-01 08:00:00 1000.000
1060
A1 2005-11-15 00:00:00 2000.000
1062
Warning 1292 Incorrect datetime value: '2005-12-01 24:00:00' for column 'started' at row 1
1063
SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-02 00:00:00';
1065
A1 2005-11-01 08:00:00 1000.000
1066
A1 2005-11-15 00:00:00 2000.000
1069
BUG#32198 "Comparison of DATE with DATETIME still not using indexes correctly"
1072
id int NOT NULL auto_increment,
1073
dateval date default NULL,
1075
KEY dateval (dateval)
1076
) AUTO_INCREMENT=173;
1077
INSERT INTO t1 VALUES
1078
(1,'2007-01-01'),(2,'2007-01-02'),(3,'2007-01-03'),(4,'2007-01-04'),
1079
(5,'2007-01-05'),(6,'2007-01-06'),(7,'2007-01-07'),(8,'2007-01-08'),
1080
(9,'2007-01-09'),(10,'2007-01-10'),(11,'2007-01-11');
1081
This must use range access:
1082
explain select * from t1 where dateval >= '2007-01-01 00:00:00' and dateval <= '2007-01-02 23:59:59';
1083
id select_type table type possible_keys key key_len ref rows Extra
1084
1 SIMPLE t1 index dateval PRIMARY 4 NULL 11 Using where
1087
a varchar(32), index (a)
1088
) DEFAULT COLLATE=utf8_bin;
1089
INSERT INTO t1 VALUES
1090
('B'), ('A'), ('A'), ('C'), ('B'), ('A'), ('A');
1091
SELECT a FROM t1 WHERE a='b' OR a='B';
1095
EXPLAIN SELECT a FROM t1 WHERE a='b' OR a='B';
1096
id select_type table type possible_keys key key_len ref rows Extra
1097
1 SIMPLE t1 range a a 131 NULL 3 Using where; Using index
1099
CREATE TABLE t1 (f1 int NOT NULL, PRIMARY KEY (f1));
1100
INSERT INTO t1 VALUES (127),(254),(0),(1),(255);
1101
SELECT COUNT(*) FROM t1 WHERE f1 < 256;
1104
SELECT COUNT(*) FROM t1 WHERE f1 < 256.0;
1107
SELECT COUNT(*) FROM t1 WHERE f1 < 255;
1110
SELECT COUNT(*) FROM t1 WHERE f1 < -1;
1113
SELECT COUNT(*) FROM t1 WHERE f1 > -1;
1117
CREATE TABLE t1 ( f1 int NOT NULL, PRIMARY KEY (f1));
1118
INSERT INTO t1 VALUES (127),(126),(0),(-128),(-127);
1119
SELECT COUNT(*) FROM t1 WHERE f1 < 128;
1122
SELECT COUNT(*) FROM t1 WHERE f1 < 128.0;
1125
SELECT COUNT(*) FROM t1 WHERE f1 < 127;
1128
SELECT COUNT(*) FROM t1 WHERE f1 > -129;
1131
SELECT COUNT(*) FROM t1 WHERE f1 > -129.0;
1134
SELECT COUNT(*) FROM t1 WHERE f1 > -128;
1138
create table t1 (a int);
1139
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
1140
create table t2 (a int, b int, filler char(100)) ENGINE=myisam;
1141
insert into t2 select A.a + 10 * (B.a + 10 * C.a), 10, 'filler' from t1 A,
1142
t1 B, t1 C where A.a < 5;
1143
insert into t2 select 1000, b, 'filler' from t2;
1144
alter table t2 add index (a,b);
1145
select 'In following EXPLAIN the access method should be ref, #rows~=500 (and not 2)' Z;
1147
In following EXPLAIN the access method should be ref, #rows~=500 (and not 2)
1148
explain select * from t2 where a=1000 and b<11;
1149
id select_type table type possible_keys key key_len ref rows Extra
1150
1 SIMPLE t2 ref a a 5 const 502 Using where
1153
CREATE TABLE t1 (c1 DECIMAL(10,0),INDEX(c1));
1154
INSERT INTO t1 VALUES (1),(2),(3);
1155
SELECT c1 FROM t1 WHERE c1 >= 'A' GROUP BY 1;
1161
Warning 1366 Incorrect decimal value: 'A' for column 'c1' at row 1
1162
Warning 1292 Truncated incorrect DOUBLE value: 'A'
1163
Warning 1292 Truncated incorrect DOUBLE value: 'A'
1164
Warning 1292 Truncated incorrect DOUBLE value: 'A'
1166
create table t1 (a int,b int,key (b),key (a),key (b,a));
1167
insert into t1(a,b) values (1,2),(3,4),(5,6),(7,8);
1168
create table t2 (c int);
1169
insert into t2(c) values (1),(5),(6),(7),(8);
1170
select 1 from (select c from t1,t2 where b >= 1 and a <=> c group by 1 limit 1) as d1;