1
drop table if exists t1, t2;
8
select NULL in (1,2,3);
11
select 1 in (1,NULL,3);
14
select 3 in (1,NULL,3);
17
select 10 in (1,NULL,3);
20
select 1.5 in (1.5,2.5,3.5);
23
select 10.5 in (1.5,2.5,3.5);
26
select NULL in (1.5,2.5,3.5);
29
select 1.5 in (1.5,NULL,3.5);
32
select 3.5 in (1.5,NULL,3.5);
35
select 10.5 in (1.5,NULL,3.5);
36
10.5 in (1.5,NULL,3.5)
38
CREATE TABLE t1 (a int, b int, c int);
39
insert into t1 values (1,2,3), (1,NULL,3);
40
select 1 in (a,b,c) from t1;
44
select 3 in (a,b,c) from t1;
48
select 10 in (a,b,c) from t1;
52
select NULL in (a,b,c) from t1;
57
CREATE TABLE t1 (a float, b float, c float);
58
insert into t1 values (1.5,2.5,3.5), (1.5,NULL,3.5);
59
select 1.5 in (a,b,c) from t1;
63
select 3.5 in (a,b,c) from t1;
67
select 10.5 in (a,b,c) from t1;
72
CREATE TABLE t1 (a varchar(10), b varchar(10), c varchar(10));
73
insert into t1 values ('A','BC','EFD'), ('A',NULL,'EFD');
74
select 'A' in (a,b,c) from t1;
78
select 'EFD' in (a,b,c) from t1;
82
select 'XSFGGHF' in (a,b,c) from t1;
87
CREATE TABLE t1 (field char(1));
88
INSERT INTO t1 VALUES ('A'),(NULL);
89
SELECT * from t1 WHERE field IN (NULL);
91
SELECT * from t1 WHERE field NOT IN (NULL);
93
SELECT * from t1 where field = field;
96
SELECT * from t1 where field <=> field;
100
DELETE FROM t1 WHERE field NOT IN (NULL);
106
create table t1 (id int primary key);
107
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9);
108
select * from t1 where id in (2,5,9);
119
insert into t1 values ('A','B','C');
120
insert into t1 values ('a','c','c');
121
select * from t1 where a in (b);
123
select * from t1 where a in (b,c);
125
select * from t1 where 'a' in (a,b,c);
129
select * from t1 where 'a' in (a);
133
select * from t1 where a in ('a');
137
select * from t1 where 'a' collate utf8_general_ci in (a,b,c);
141
select * from t1 where 'a' collate utf8_bin in (a,b,c);
144
select * from t1 where 'a' in (a,b,c collate utf8_bin);
147
explain extended select * from t1 where 'a' in (a,b,c collate utf8_bin);
148
id select_type table type possible_keys key key_len ref rows filtered Extra
149
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where
151
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t1`.`c` AS `c` from `test`.`t1` where ('a' in (`test`.`t1`.`a`,`test`.`t1`.`b`,(`test`.`t1`.`c` collate utf8_bin)))
153
create table t1 (a char(10) not null);
154
insert into t1 values ('a'),('b'),('c');
155
select a from t1 where a IN ('a','b','c') order by a;
161
select '1.0' in (1,2);
164
select 1 in ('1.0',2);
167
select 1 in (1,'2.0');
170
select 1 in ('1.0',2.0);
173
select 1 in (1.0,'2.0');
176
select 1 in ('1.1',2);
179
select 1 in ('1.1',2.0);
182
create table t1 (a char(2));
183
insert into t1 values ('aa'), ('bb');
184
select * from t1 where a in (NULL, 'aa');
188
create table t1 (id int, key(id));
189
insert into t1 values (1),(2),(3);
190
select count(*) from t1 where id not in (1);
193
select count(*) from t1 where id not in (1,2);
197
DROP TABLE IF EXISTS t1;
198
CREATE TABLE t1 SELECT 1 IN (2, NULL);
199
SELECT should return NULL.
205
CREATE TABLE t1 (a int PRIMARY KEY);
206
INSERT INTO t1 VALUES (44), (45), (46);
207
SELECT * FROM t1 WHERE a IN (45);
210
SELECT * FROM t1 WHERE a NOT IN (0, 45);
214
SELECT * FROM t1 WHERE a NOT IN (45);
219
create table t1 (a int) ENGINE=MYISAM;
220
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
221
create table t2 (a int, filler char(200), key(a)) ENGINE=MYISAM;
222
insert into t2 select C.a*2, 'no' from t1 A, t1 B, t1 C;
223
insert into t2 select C.a*2+1, 'yes' from t1 C;
225
select * from t2 where a NOT IN (0, 2,4,6,8,10,12,14,16,18);
226
id select_type table type possible_keys key key_len ref rows Extra
227
1 SIMPLE t2 range a a 5 NULL 12 Using where; Using MRR
228
select * from t2 where a NOT IN (0, 2,4,6,8,10,12,14,16,18);
240
explain select * from t2 force index(a) where a NOT IN (2,2,2,2,2,2);
241
id select_type table type possible_keys key key_len ref rows Extra
242
1 SIMPLE t2 range a a 5 NULL 912 Using where; Using MRR
243
explain select * from t2 force index(a) where a <> 2;
244
id select_type table type possible_keys key key_len ref rows Extra
245
1 SIMPLE t2 range a a 5 NULL 912 Using where; Using MRR
247
create table t2 (a datetime, filler char(200), key(a));
248
insert into t2 select '2006-04-25 10:00:00' + interval C.a minute,
249
'no' from t1 A, t1 B, t1 C where C.a % 2 = 0;
250
insert into t2 select '2006-04-25 10:00:00' + interval C.a*2+1 minute,
253
select * from t2 where a NOT IN (
254
'2006-04-25 10:00:00','2006-04-25 10:02:00','2006-04-25 10:04:00',
255
'2006-04-25 10:06:00', '2006-04-25 10:08:00');
256
id select_type table type possible_keys key key_len ref rows Extra
257
1 SIMPLE t2 range a a 9 NULL 20 Using where; Using MRR
258
select * from t2 where a NOT IN (
259
'2006-04-25 10:00:00','2006-04-25 10:02:00','2006-04-25 10:04:00',
260
'2006-04-25 10:06:00', '2006-04-25 10:08:00');
262
2006-04-25 10:01:00 yes
263
2006-04-25 10:03:00 yes
264
2006-04-25 10:05:00 yes
265
2006-04-25 10:07:00 yes
266
2006-04-25 10:09:00 yes
267
2006-04-25 10:11:00 yes
268
2006-04-25 10:13:00 yes
269
2006-04-25 10:15:00 yes
270
2006-04-25 10:17:00 yes
271
2006-04-25 10:19:00 yes
273
create table t2 (a varchar(10), filler char(200), key(a));
274
insert into t2 select 'foo', 'no' from t1 A, t1 B;
275
insert into t2 select 'barbar', 'no' from t1 A, t1 B;
276
insert into t2 select 'bazbazbaz', 'no' from t1 A, t1 B;
277
insert into t2 values ('fon', '1'), ('fop','1'), ('barbaq','1'),
278
('barbas','1'), ('bazbazbay', '1'),('zz','1');
279
explain select * from t2 where a not in('foo','barbar', 'bazbazbaz');
280
id select_type table type possible_keys key key_len ref rows Extra
281
1 SIMPLE t2 range a a 43 NULL 5 Using where; Using MRR
283
create table t2 (a decimal(10,5), filler char(200), key(a));
284
insert into t2 select 345.67890, 'no' from t1 A, t1 B;
285
insert into t2 select 43245.34, 'no' from t1 A, t1 B;
286
insert into t2 select 64224.56344, 'no' from t1 A, t1 B;
287
insert into t2 values (0, '1'), (22334.123,'1'), (33333,'1'),
288
(55555,'1'), (77777, '1');
290
select * from t2 where a not in (345.67890, 43245.34, 64224.56344);
291
id select_type table type possible_keys key key_len ref rows Extra
292
1 SIMPLE t2 range a a 7 NULL 4 Using where; Using MRR
293
select * from t2 where a not in (345.67890, 43245.34, 64224.56344);
301
create table t2 (a int, key(a), b int);
302
insert into t2 values (1,1),(2,2);
304
set @str="update t2 set b=1 where a not in (";
305
select count(*) from (
306
select @str:=concat(@str, @cnt:=@cnt+1, ",")
307
from t1 A, t1 B, t1 C, t1 D) Z;
310
set @str:=concat(@str, "10000)");
311
select substr(@str, 1, 50);
313
update t2 set b=1 where a not in (2,3,4,5,6,7,8,9,
321
insert into t1 values (1),(2);
322
select some_id from t1 where some_id not in(2,-1);
325
select some_id from t1 where some_id not in(-4,-1,-4);
329
select some_id from t1 where some_id not in(-4,-1,3423534,2342342);
333
select some_id from t1 where some_id not in('-1', '0');
338
CREATE TABLE t1 (a int, b int, PRIMARY KEY (a));
339
INSERT INTO t1 VALUES (1,1),(2,1),(3,1),(4,1),(5,1),(6,1);
340
CREATE TABLE t2 (a int, b int, PRIMARY KEY (a));
341
INSERT INTO t2 VALUES (3,2),(4,2),(100,100),(101,201),(102,102);
342
CREATE TABLE t3 (a int PRIMARY KEY);
343
INSERT INTO t3 VALUES (1),(2),(3),(4);
344
CREATE TABLE t4 (a int PRIMARY KEY,b int);
345
INSERT INTO t4 VALUES (1,1),(2,2),(1000,1000),(1001,1001),(1002,1002),
346
(1003,1003),(1004,1004);
347
EXPLAIN SELECT STRAIGHT_JOIN * FROM t3
350
JOIN t4 WHERE t4.a IN (t1.b, t2.b);
351
id select_type table type possible_keys key key_len ref rows Extra
352
1 SIMPLE t3 index PRIMARY PRIMARY 4 NULL 4 Using index
353
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t3.a 1
354
1 SIMPLE t2 ALL PRIMARY NULL NULL NULL 5 Using where; Using join buffer
355
1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 7 Range checked for each record (index map: 0x1)
356
SELECT STRAIGHT_JOIN * FROM t3
359
JOIN t4 WHERE t4.a IN (t1.b, t2.b);
365
EXPLAIN SELECT STRAIGHT_JOIN
366
(SELECT SUM(t4.a) FROM t4 WHERE t4.a IN (t1.b, t2.b))
368
WHERE t3.a=t1.a AND t3.a=t2.a;
369
id select_type table type possible_keys key key_len ref rows Extra
370
1 PRIMARY t3 index PRIMARY PRIMARY 4 NULL 4 Using index
371
1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t3.a 1
372
1 PRIMARY t2 ALL PRIMARY NULL NULL NULL 5 Using where; Using join buffer
373
2 DEPENDENT SUBQUERY t4 index NULL PRIMARY 4 NULL 7 Using where; Using index
375
(SELECT SUM(t4.a) FROM t4 WHERE t4.a IN (t1.b, t2.b))
377
WHERE t3.a=t1.a AND t3.a=t2.a;
378
(SELECT SUM(t4.a) FROM t4 WHERE t4.a IN (t1.b, t2.b))
381
DROP TABLE t1,t2,t3,t4;
382
CREATE TABLE t1(a BIGINT);
383
INSERT INTO t1 VALUES (0x0FFFFFFFFFFFFFFF);
384
SELECT * FROM t1 WHERE a=-1 OR a=-2 ;
386
SELECT * FROM t1 WHERE a IN (-1, -2);
388
CREATE TABLE t2 (a BIGINT);
389
insert into t2 values(13491727406643098568),
390
(0x0fffffefffffffff),
391
(0x0ffffffeffffffff),
392
(0x0fffffffefffffff),
393
(0x0ffffffffeffffff),
394
(0x0fffffffffefffff),
395
(0x0ffffffffffeffff),
396
(0x0fffffffffffefff),
397
(0x0ffffffffffffeff),
398
(0x0fffffffffffffef),
399
(0x0ffffffffffffffe),
400
(0x0fffffffffffffff),
401
(0x2000000000000000),
402
(0x2000000000000001),
403
(0x2000000000000002),
404
(0x2000000000000300),
405
(0x2000000000000400),
406
(0x2000000000000401),
407
(0x2000000000004001),
408
(0x2000000000040001),
409
(0x2000000000400001),
410
(0x2000000004000001),
411
(0x2000000040000001),
412
(0x2000000400000001),
413
(0x2000004000000001),
414
(0x2000040000000001);
415
SELECT HEX(a) FROM t2 WHERE a IN (0xBB3C3E98175D33C8, 42);
417
SELECT HEX(a) FROM t2 WHERE a IN
431
SELECT HEX(a) FROM t2 WHERE a IN
436
SELECT HEX(a) FROM t2 WHERE a IN
440
SELECT HEX(a) FROM t2 WHERE a IN
445
CREATE TABLE t3 (a BIGINT);
446
INSERT INTO t3 VALUES (9223372036854775551);
447
SELECT HEX(a) FROM t3 WHERE a IN (9223372036854775807, 42);
449
CREATE TABLE t4 (a DATE);
450
INSERT INTO t4 VALUES ('1972-02-06'), ('1972-07-29');
451
SELECT * FROM t4 WHERE a IN ('1972-02-06','19772-07-29');
455
Warning 1292 Incorrect date value: '19772-07-29' for column 'a' at row 1
456
DROP TABLE t1,t2,t3,t4;
457
CREATE TABLE t1 (id int not null);
458
INSERT INTO t1 VALUES (1),(2);
459
SELECT id FROM t1 WHERE id IN(4564, (SELECT IF(1=0,1,1/0)) );
462
Error 1365 Division by 0
463
Error 1365 Division by 0
466
create table t1(f1 char(1)) ENGINE=MYISAM;
467
insert into t1 values ('a'),('b'),('1');
468
select f1 from t1 where f1 in ('a',1);
472
select f1, case f1 when 'a' then '+' when 1 then '-' end from t1;
473
f1 case f1 when 'a' then '+' when 1 then '-' end
477
create index t1f1_idx on t1(f1);
478
select f1 from t1 where f1 in ('a',1);
482
explain select f1 from t1 where f1 in ('a',1);
483
id select_type table type possible_keys key key_len ref rows Extra
484
1 SIMPLE t1 index t1f1_idx t1f1_idx 7 NULL 3 Using where; Using index
485
select f1 from t1 where f1 in ('a','b');
489
explain select f1 from t1 where f1 in ('a','b');
490
id select_type table type possible_keys key key_len ref rows Extra
491
1 SIMPLE t1 index t1f1_idx t1f1_idx 7 NULL 3 Using where; Using index
492
select f1 from t1 where f1 in (2,1);
495
explain select f1 from t1 where f1 in (2,1);
496
id select_type table type possible_keys key key_len ref rows Extra
497
1 SIMPLE t1 index t1f1_idx t1f1_idx 7 NULL 3 Using where; Using index
498
create table t2(f2 int, index t2f2(f2)) ENGINE=MYISAM;
499
insert into t2 values(0),(1),(2);
500
select f2 from t2 where f2 in ('a',2);
505
Warning 1292 Truncated incorrect DOUBLE value: 'a'
506
Warning 1292 Truncated incorrect DOUBLE value: 'a'
507
Warning 1292 Truncated incorrect DOUBLE value: 'a'
508
explain select f2 from t2 where f2 in ('a',2);
509
id select_type table type possible_keys key key_len ref rows Extra
510
1 SIMPLE t2 index t2f2 t2f2 5 NULL 3 Using where; Using index
511
select f2 from t2 where f2 in ('a','b');
515
Warning 1292 Truncated incorrect DOUBLE value: 'a'
516
Warning 1292 Truncated incorrect DOUBLE value: 'b'
517
explain select f2 from t2 where f2 in ('a','b');
518
id select_type table type possible_keys key key_len ref rows Extra
519
1 SIMPLE t2 index t2f2 t2f2 5 NULL 3 Using where; Using index
521
Warning 1292 Truncated incorrect DOUBLE value: 'a'
522
Warning 1292 Truncated incorrect DOUBLE value: 'b'
523
select f2 from t2 where f2 in (1,'b');
528
Warning 1292 Truncated incorrect DOUBLE value: 'b'
529
Warning 1292 Truncated incorrect DOUBLE value: 'b'
530
explain select f2 from t2 where f2 in (1,'b');
531
id select_type table type possible_keys key key_len ref rows Extra
532
1 SIMPLE t2 index t2f2 t2f2 5 NULL 3 Using where; Using index
534
create table t1 (a time, key(a));
535
insert into t1 values (),(),(),(),(),(),(),(),(),();
536
select a from t1 where a not in (a,a,a) group by a;