summaryrefslogtreecommitdiff
path: root/mysql-test/main/func_in.test
blob: 847c48d31a94ceddd54e86a55ed6d70fd8d2ec14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
#
# test of IN (NULL)
#

select 1 in (1,2,3);
select 10 in (1,2,3);
select NULL in (1,2,3);
select 1 in (1,NULL,3);
select 3 in (1,NULL,3);
select 10 in (1,NULL,3);
select 1.5 in (1.5,2.5,3.5);
select 10.5 in (1.5,2.5,3.5);
select NULL in (1.5,2.5,3.5);
select 1.5 in (1.5,NULL,3.5);
select 3.5 in (1.5,NULL,3.5);
select 10.5 in (1.5,NULL,3.5);

CREATE TABLE t1 (a int, b int, c int);
insert into t1 values (1,2,3), (1,NULL,3);
select 1 in (a,b,c) from t1;
select 3 in (a,b,c) from t1;
select 10 in (a,b,c) from t1;
select NULL in (a,b,c) from t1;
drop table t1;
CREATE TABLE t1 (a float, b float, c float);
insert into t1 values (1.5,2.5,3.5), (1.5,NULL,3.5);
select 1.5 in (a,b,c) from t1;
select 3.5 in (a,b,c) from t1;
select 10.5 in (a,b,c) from t1;
drop table t1;
CREATE TABLE t1 (a varchar(10), b varchar(10), c varchar(10));
insert into t1 values ('A','BC','EFD'), ('A',NULL,'EFD');
select 'A' in (a,b,c) from t1;
select 'EFD' in (a,b,c) from t1;
select 'XSFGGHF' in (a,b,c) from t1;
drop table t1;

CREATE TABLE t1 (field char(1));
INSERT INTO t1 VALUES ('A'),(NULL);
SELECT * from t1 WHERE field IN (NULL);
SELECT * from t1 WHERE field NOT IN (NULL);
SELECT * from t1 where field = field;
SELECT * from t1 where field <=> field;
DELETE FROM t1 WHERE field NOT IN (NULL);
SELECT * FROM t1;
drop table t1;

create table t1 (id int(10) primary key);
insert into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9);
select * from t1 where id in (2,5,9);
drop table t1;

create table t1 (
a char(1) character set latin1 collate latin1_general_ci,
b char(1) character set latin1 collate latin1_swedish_ci,
c char(1) character set latin1 collate latin1_danish_ci
);
insert into t1 values ('A','B','C');
insert into t1 values ('a','c','c');
--error 1267
select * from t1 where a in (b);
--error 1270
select * from t1 where a in (b,c);
--error 1271
select * from t1 where 'a' in (a,b,c);
select * from t1 where 'a' in (a);
select * from t1 where a in ('a');
select * from t1 where 'a' collate latin1_general_ci in (a,b,c);
select * from t1 where 'a' collate latin1_bin in (a,b,c);
select * from t1 where 'a' in (a,b,c collate latin1_bin);
explain extended select * from t1 where 'a' in (a,b,c collate latin1_bin);
drop table t1;

set names utf8;
create table t1 (a char(10) character set utf8 not null);
insert into t1 values ('bbbb'),(_koi8r'ÃÃÃÃ'),(_latin1'ÄÄÄÄ');
select a from t1 where a in ('bbbb',_koi8r'ÃÃÃÃ',_latin1'ÄÄÄÄ') order by a;
drop table t1;
# Bug#7834 Illegal mix of collations in IN operator
create table t1 (a char(10) character set latin1 not null);
insert into t1 values ('a'),('b'),('c');
select a from t1 where a IN ('a','b','c') order by a;
drop table t1;
set names latin1;

select '1.0' in (1,2);
select 1 in ('1.0',2);
select 1 in (1,'2.0');
select 1 in ('1.0',2.0);
select 1 in (1.0,'2.0');
select 1 in ('1.1',2);
select 1 in ('1.1',2.0);

# Test case for bug #6365

create table t1 (a char(2) character set binary);
insert into t1 values ('aa'), ('bb');
select * from t1 where a in (NULL, 'aa');
drop table t1;

# BUG#13419
create table t1 (id int, key(id));
insert into t1 values (1),(2),(3);
select count(*) from t1 where id not in (1);
select count(*) from t1 where id not in (1,2);
drop table t1;


#
# BUG#17047: CHAR() and IN() can return NULL without signaling NULL
# result
#
# The problem was in the IN() function that ignored maybe_null flags
# of all arguments except the first (the one _before_ the IN
# keyword, '1' in the test case below).
#
--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings

CREATE TABLE t1 SELECT 1 IN (2, NULL);
--echo SELECT should return NULL.
SELECT * FROM t1;

DROP TABLE t1;


--echo End of 4.1 tests


#
# Bug #11885: WHERE condition with NOT IN (one element)          
#             

CREATE TABLE t1 (a int PRIMARY KEY);
INSERT INTO t1 VALUES (44), (45), (46);

SELECT * FROM t1 WHERE a IN (45);
SELECT * FROM t1 WHERE a NOT IN (0, 45);
SELECT * FROM t1 WHERE a NOT IN (45);

CREATE VIEW v1 AS SELECT * FROM t1 WHERE a NOT IN (45);
SHOW CREATE VIEW v1;
SELECT * FROM v1; 

DROP VIEW v1;
DROP TABLE t1;

# BUG#15872: Excessive memory consumption of range analysis of NOT IN
create table t1 (a int);
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); 
create table t2 (a int, filler char(200), key(a));

insert into t2 select C.a*2,   'no'  from t1 A, t1 B, t1 C;
insert into t2 select C.a*2+1, 'yes' from t1 C;

explain 
select * from t2 where a NOT IN (0, 2,4,6,8,10,12,14,16,18);
select * from t2 where a NOT IN (0, 2,4,6,8,10,12,14,16,18);

explain select * from t2 force index(a) where a NOT IN (2,2,2,2,2,2);
explain select * from t2 force index(a) where a <> 2;

drop table t2;

#
# Repeat the test for DATETIME
#
create table t2 (a datetime, filler char(200), key(a));

insert into t2 select '2006-04-25 10:00:00' + interval C.a minute,
               'no'  from t1 A, t1 B, t1 C where C.a % 2 = 0;

insert into t2 select '2006-04-25 10:00:00' + interval C.a*2+1 minute,
               'yes' from t1 C;

explain 
select * from t2 where a NOT IN (
  '2006-04-25 10:00:00','2006-04-25 10:02:00','2006-04-25 10:04:00', 
  '2006-04-25 10:06:00', '2006-04-25 10:08:00');
select * from t2 where a NOT IN (
  '2006-04-25 10:00:00','2006-04-25 10:02:00','2006-04-25 10:04:00', 
  '2006-04-25 10:06:00', '2006-04-25 10:08:00');
drop table t2;

#
# Repeat the test for CHAR(N)
#
create table t2 (a varchar(10), filler char(200), key(a));

insert into t2 select 'foo', 'no' from t1 A, t1 B;
insert into t2 select 'barbar', 'no' from t1 A, t1 B;
insert into t2 select 'bazbazbaz', 'no' from t1 A, t1 B;

insert into t2 values ('fon', '1'), ('fop','1'), ('barbaq','1'), 
  ('barbas','1'), ('bazbazbay', '1'),('zz','1');

explain select * from t2 where a not in('foo','barbar', 'bazbazbaz');

drop table t2;

#
# Repeat for DECIMAL
#
create table t2 (a decimal(10,5), filler char(200), key(a));

insert into t2 select 345.67890, 'no' from t1 A, t1 B;
insert into t2 select 43245.34, 'no' from t1 A, t1 B;
insert into t2 select 64224.56344, 'no' from t1 A, t1 B;

insert into t2 values (0, '1'), (22334.123,'1'), (33333,'1'), 
  (55555,'1'), (77777, '1');

explain
select * from t2 where a not in (345.67890, 43245.34, 64224.56344);
select * from t2 where a not in (345.67890, 43245.34, 64224.56344);

drop table t2;

# Try a very big IN-list
create table t2 (a int, key(a), b int);
insert into t2 values (1,1),(2,2);

set @cnt= 1; 
set @str="update t2 set b=1 where a not in (";
select count(*) from (
  select @str:=concat(@str, @cnt:=@cnt+1, ",") 
  from t1 A, t1 B, t1 C, t1 D) Z;

set @str:=concat(@str, "10000)");
select substr(@str, 1, 50);
prepare s from @str;
execute s;
deallocate prepare s;
set @str=NULL;

drop table t2;
drop table t1;

# BUG#19618: Crash in range optimizer for 
#   "unsigned_keypart NOT IN(negative_number,...)" 
#   (introduced in fix BUG#15872) 
create table t1 (
  some_id smallint(5) unsigned,
  key (some_id)
);
insert into t1 values (1),(2);
select some_id from t1 where some_id not in(2,-1);
select some_id from t1 where some_id not in(-4,-1,-4);
select some_id from t1 where some_id not in(-4,-1,3423534,2342342);

#
# BUG#24261: crash when WHERE contains NOT IN ('<negative value>') for unsigned column type
#

select some_id from t1 where some_id not in('-1', '0');

drop table t1;

#
# BUG#20420: optimizer reports wrong keys on left join with IN
#
CREATE TABLE t1 (a int, b int, PRIMARY KEY (a));
INSERT INTO t1 VALUES (1,1),(2,1),(3,1),(4,1),(5,1),(6,1);

CREATE TABLE t2 (a int, b int, PRIMARY KEY (a));
INSERT INTO t2 VALUES (3,2),(4,2),(100,100),(101,201),(102,102);

CREATE TABLE t3 (a int PRIMARY KEY);
INSERT INTO t3 VALUES (1),(2),(3),(4);

CREATE TABLE t4 (a int PRIMARY KEY,b int);
INSERT INTO t4 VALUES (1,1),(2,2),(1000,1000),(1001,1001),(1002,1002),
       (1003,1003),(1004,1004);

EXPLAIN SELECT STRAIGHT_JOIN * FROM t3 
  JOIN t1 ON t3.a=t1.a 
  JOIN t2 ON t3.a=t2.a
  JOIN t4 WHERE t4.a IN (t1.b, t2.b);

SELECT STRAIGHT_JOIN * FROM t3 
  JOIN t1 ON t3.a=t1.a 
  JOIN t2 ON t3.a=t2.a
  JOIN t4 WHERE t4.a IN (t1.b, t2.b);

EXPLAIN SELECT STRAIGHT_JOIN 
   (SELECT SUM(t4.a) FROM t4 WHERE t4.a IN (t1.b, t2.b)) 
  FROM t3, t1, t2
  WHERE t3.a=t1.a AND t3.a=t2.a;

SELECT STRAIGHT_JOIN 
   (SELECT SUM(t4.a) FROM t4 WHERE t4.a IN (t1.b, t2.b)) 
  FROM t3, t1, t2
  WHERE t3.a=t1.a AND t3.a=t2.a;

DROP TABLE t1,t2,t3,t4;  

#
# BUG#19342: IN works incorrectly for BIGINT UNSIGNED values
#
CREATE TABLE t1(a BIGINT UNSIGNED);
INSERT INTO t1 VALUES (0xFFFFFFFFFFFFFFFF);

SELECT * FROM t1 WHERE a=-1 OR a=-2 ;
SELECT * FROM t1 WHERE a IN (-1, -2);

CREATE TABLE t2 (a BIGINT UNSIGNED);
insert into t2 values(13491727406643098568),
       (0x7fffffefffffffff),
       (0x7ffffffeffffffff),
       (0x7fffffffefffffff),
       (0x7ffffffffeffffff),
       (0x7fffffffffefffff),
       (0x7ffffffffffeffff),
       (0x7fffffffffffefff),
       (0x7ffffffffffffeff),
       (0x7fffffffffffffef),
       (0x7ffffffffffffffe),
       (0x7fffffffffffffff),
       (0x8000000000000000),
       (0x8000000000000001),
       (0x8000000000000002),
       (0x8000000000000300),
       (0x8000000000000400),
       (0x8000000000000401),
       (0x8000000000004001),
       (0x8000000000040001),
       (0x8000000000400001),
       (0x8000000004000001),
       (0x8000000040000001),
       (0x8000000400000001),
       (0x8000004000000001),
       (0x8000040000000001);

SELECT HEX(a) FROM t2 WHERE a IN 
  (CAST(0xBB3C3E98175D33C8 AS UNSIGNED),
   42);

SELECT HEX(a) FROM t2 WHERE a IN
  (CAST(0xBB3C3E98175D33C8 AS UNSIGNED),
   CAST(0x7fffffffffffffff AS UNSIGNED),
   CAST(0x8000000000000000 AS UNSIGNED),
   CAST(0x8000000000000400 AS UNSIGNED),
   CAST(0x8000000000000401 AS UNSIGNED),
   42);

SELECT HEX(a) FROM t2 WHERE a IN 
  (CAST(0x7fffffffffffffff AS UNSIGNED), 
   CAST(0x8000000000000001 AS UNSIGNED));
SELECT HEX(a) FROM t2 WHERE a IN 
  (CAST(0x7ffffffffffffffe AS UNSIGNED), 
   CAST(0x7fffffffffffffff AS UNSIGNED));
#view protocol generates additional warning
--disable_view_protocol
SELECT HEX(a) FROM t2 WHERE a IN 
  (0x7ffffffffffffffe, 
   0x7fffffffffffffff,
   'abc');

CREATE TABLE t3 (a BIGINT UNSIGNED);
INSERT INTO t3 VALUES (9223372036854775551);

SELECT HEX(a) FROM t3 WHERE a IN (9223372036854775807, 42);

CREATE TABLE t4 (a DATE);
INSERT INTO t4 VALUES ('1972-02-06'), ('1972-07-29');
SELECT * FROM t4 WHERE a IN ('1972-02-06','19772-07-29');

--enable_view_protocol

DROP TABLE t1,t2,t3,t4;

#
# BUG#27362: IN with a decimal expression that may return NULL
#

CREATE TABLE t1 (id int not null);
INSERT INTO t1 VALUES (1),(2);

SELECT id FROM t1 WHERE id IN(4564, (SELECT IF(1=0,1,1/0)) );

DROP TABLE t1;

--echo End of 5.0 tests


#
# Bug#18360: Type aggregation for IN and CASE may lead to a wrong result 
#
create table t1(f1 char(1));
insert into t1 values ('a'),('b'),('1');
select f1 from t1 where f1 in ('a',1);
select f1, case f1 when 'a' then '+' when 1 then '-' end from t1;
create index t1f1_idx on t1(f1);
select f1 from t1 where f1 in ('a',1);
explain select f1 from t1 where f1 in ('a',1);
select f1 from t1 where f1 in ('a','b');
explain select f1 from t1 where f1 in ('a','b');
select f1 from t1 where f1 in (2,1);
explain select f1 from t1 where f1 in (2,1);
create table t2(f2 int, index t2f2(f2));
insert into t2 values(0),(1),(2);
select f2 from t2 where f2 in ('a',2);
explain select f2 from t2 where f2 in ('a',2);
#view protocol generates additional warning
--disable_view_protocol
select f2 from t2 where f2 in ('a','b');
explain select f2 from t2 where f2 in ('a','b');
--enable_view_protocol
select f2 from t2 where f2 in (1,'b');
explain select f2 from t2 where f2 in (1,'b');
drop table t1, t2;

#
# Bug #31075: crash in get_func_mm_tree
#

create table t1 (a time, key(a));
insert into t1 values (),(),(),(),(),(),(),(),(),();
select a from t1 where a not in (a,a,a) group by a;
drop table t1;

#
# Bug #37761: IN handles NULL differently for table-subquery and value-list
#

create table t1 (id int);
select * from t1 where NOT id in (select null union all select 1);
select * from t1 where NOT id in (null, 1);
drop table t1;

#
# Bug #41363: crash of mysqld on windows with aggregate in case
#

CREATE TABLE t1(c0 INTEGER, c1 INTEGER, c2 INTEGER);
INSERT INTO t1 VALUES(1, 1, 1), (1, 1, 1);

SELECT CASE AVG (c0) WHEN c1 * c2 THEN 1 END FROM t1;
SELECT CASE c1 * c2 WHEN SUM(c0) THEN 1 WHEN AVG(c0) THEN 2 END FROM t1;
SELECT CASE c1 WHEN c1 + 1 THEN 1 END, ABS(AVG(c0)) FROM t1;

DROP TABLE t1;

#
# Bug #44399: crash with statement using TEXT columns, aggregates, GROUP BY, 
# and HAVING
#

CREATE TABLE t1(a TEXT, b INT, c INT UNSIGNED, d DECIMAL(12,2), e REAL);
INSERT INTO t1 VALUES('iynfj', 1, 1, 1, 1);
INSERT INTO t1 VALUES('innfj', 2, 2, 2, 2);
SELECT SUM( DISTINCT a ) FROM t1 GROUP BY a HAVING a IN ( AVG( 1 ), 1 + a);
SELECT SUM( DISTINCT b ) FROM t1 GROUP BY b HAVING b IN ( AVG( 1 ), 1 + b);
SELECT SUM( DISTINCT c ) FROM t1 GROUP BY c HAVING c IN ( AVG( 1 ), 1 + c);
SELECT SUM( DISTINCT d ) FROM t1 GROUP BY d HAVING d IN ( AVG( 1 ), 1 + d);
SELECT SUM( DISTINCT e ) FROM t1 GROUP BY e HAVING e IN ( AVG( 1 ), 1 + e);
SELECT SUM( DISTINCT e ) FROM t1 GROUP BY b,c,d HAVING (b,c,d) IN 
  ((AVG( 1 ), 1 + c, 1 + d), (AVG( 1 ), 2 + c, 2 + d));
DROP TABLE t1;

--echo #
--echo # Bug #44139: Table scan when NULL appears in IN clause
--echo #

--disable_warnings

CREATE TABLE t1 (
  c_int INT NOT NULL,
  c_decimal DECIMAL(5,2) NOT NULL,
  c_float FLOAT(5, 2) NOT NULL,
  c_bit BIT(10) NOT NULL,
  c_date DATE NOT NULL, 
  c_datetime DATETIME NOT NULL,
  c_timestamp TIMESTAMP NOT NULL,
  c_time TIME NOT NULL,
  c_year YEAR NOT NULL,
  c_char CHAR(10) NOT NULL,
  INDEX(c_int), INDEX(c_decimal), INDEX(c_float), INDEX(c_bit), INDEX(c_date),
  INDEX(c_datetime), INDEX(c_timestamp), INDEX(c_time), INDEX(c_year),
  INDEX(c_char));

INSERT IGNORE INTO t1 (c_int) VALUES (1), (2), (3), (4), (5);
INSERT IGNORE INTO t1 (c_int) SELECT 0 FROM t1;
INSERT IGNORE INTO t1 (c_int) SELECT 0 FROM t1;

--enable_warnings

EXPLAIN SELECT * FROM t1 WHERE c_int IN (1, 2, 3);
EXPLAIN SELECT * FROM t1 WHERE c_int IN (NULL, 1, 2, 3);

EXPLAIN SELECT * FROM t1 WHERE c_int IN (1, 2, 3);
EXPLAIN SELECT * FROM t1 WHERE c_int IN (1, NULL, 2, NULL, 3, NULL);
EXPLAIN SELECT * FROM t1 WHERE c_int IN (NULL);
EXPLAIN SELECT * FROM t1 WHERE c_int IN (NULL, NULL);

EXPLAIN SELECT * FROM t1 WHERE c_decimal IN (1, 2, 3);
EXPLAIN SELECT * FROM t1 WHERE c_decimal IN (NULL, 1, 2, 3);
EXPLAIN SELECT * FROM t1 WHERE c_decimal IN (NULL);
EXPLAIN SELECT * FROM t1 WHERE c_decimal IN (NULL, NULL);

EXPLAIN SELECT * FROM t1 WHERE c_float IN (1, 2, 3);
EXPLAIN SELECT * FROM t1 WHERE c_float IN (NULL, 1, 2, 3);
EXPLAIN SELECT * FROM t1 WHERE c_float IN (NULL);
EXPLAIN SELECT * FROM t1 WHERE c_float IN (NULL, NULL);

EXPLAIN SELECT * FROM t1 WHERE c_bit IN (1, 2, 3);
EXPLAIN SELECT * FROM t1 WHERE c_bit IN (NULL, 1, 2, 3);
EXPLAIN SELECT * FROM t1 WHERE c_bit IN (NULL);
EXPLAIN SELECT * FROM t1 WHERE c_bit IN (NULL, NULL);

EXPLAIN SELECT * FROM t1 WHERE c_date 
  IN ('2009-09-01', '2009-09-02', '2009-09-03');
EXPLAIN SELECT * FROM t1 WHERE c_date
  IN (NULL, '2009-09-01', '2009-09-02', '2009-09-03');
EXPLAIN SELECT * FROM t1 WHERE c_date IN (NULL);
EXPLAIN SELECT * FROM t1 WHERE c_date IN (NULL, NULL);

EXPLAIN SELECT * FROM t1 WHERE c_datetime
  IN ('2009-09-01 00:00:01', '2009-09-02 00:00:01', '2009-09-03 00:00:01');
EXPLAIN SELECT * FROM t1 WHERE c_datetime
  IN (NULL, '2009-09-01 00:00:01', '2009-09-02 00:00:01', '2009-09-03 00:00:01');
EXPLAIN SELECT * FROM t1 WHERE c_datetime IN (NULL);
EXPLAIN SELECT * FROM t1 WHERE c_datetime IN (NULL, NULL);

EXPLAIN SELECT * FROM t1 WHERE c_timestamp
  IN ('2009-09-01 00:00:01', '2009-09-01 00:00:02', '2009-09-01 00:00:03');
EXPLAIN SELECT * FROM t1 WHERE c_timestamp
  IN (NULL, '2009-09-01 00:00:01', '2009-09-01 00:00:02', '2009-09-01 00:00:03');
EXPLAIN SELECT * FROM t1 WHERE c_timestamp IN (NULL);
EXPLAIN SELECT * FROM t1 WHERE c_timestamp IN (NULL, NULL);

EXPLAIN SELECT * FROM t1 WHERE c_year IN (1, 2, 3);
EXPLAIN SELECT * FROM t1 WHERE c_year IN (NULL, 1, 2, 3);
EXPLAIN SELECT * FROM t1 WHERE c_year IN (NULL);
EXPLAIN SELECT * FROM t1 WHERE c_year IN (NULL, NULL);

EXPLAIN SELECT * FROM t1 WHERE c_char IN ('1', '2', '3');
EXPLAIN SELECT * FROM t1 WHERE c_char IN (NULL, '1', '2', '3');
EXPLAIN SELECT * FROM t1 WHERE c_char IN (NULL);
EXPLAIN SELECT * FROM t1 WHERE c_char IN (NULL, NULL);

DROP TABLE t1;

--echo #
--echo # Bug#54477: Crash on IN / CASE with NULL arguments
--echo #

CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1), (2);

SELECT 1 IN (NULL, a) FROM t1;

SELECT a IN (a, a) FROM t1 GROUP BY a WITH ROLLUP;

SELECT CASE a WHEN a THEN a END FROM t1 GROUP BY a WITH ROLLUP;

DROP TABLE t1;

--echo #
--echo # Bug #11766212  59270: NOT IN (YEAR( ... ), ... ) PRODUCES MANY VALGRIND WARNINGS
--echo #

SELECT 1 IN (YEAR(FROM_UNIXTIME(NULL)) ,1);

--echo #

--echo #
--echo # Bug#13012483: EXPLAIN EXTENDED, PREPARED STATEMENT, CRASH IN CHECK_SIMPLE_EQUALITY
--echo #

CREATE TABLE t1 (a INT);
PREPARE s FROM "SELECT 1 FROM t1 WHERE 1 < ALL (SELECT @a:= (1 IN (SELECT 1 FROM t1)) FROM t1)";
EXECUTE s;

DROP TABLE t1;

--echo # End of test  BUG#13012483

--echo #
--echo End of 5.1 tests

#
# lp:817966 int_column IN (string_constant)
#
# rather illogically, when BIGINT field is compared to a string,
# the string is converted to an integer, not to a double.
# When some other integer field (not BIGINT) is compared to a string,
# or when the BIGINT is not a field, but an expression, both
# operands are compared as doubles. The latter behavior is correct,
# according to the manual.
#
create table t1 (a bigint, b int);
insert t1 values (1,1),(2,2),(3,3);
select * from t1 where a in ('2.1');
select * from t1 where b in ('2.1');
select * from t1 where a='2.1'; 
select * from t1 where b='2.1'; 
select * from t1 where IF(1,a,a)='2.1'; 
drop table t1;

--echo #
--echo # End of 5.3 tests
--echo #

#
# Bug#26361149 MYSQL SERVER CRASHES AT: COL IN(IFNULL(CONST, COL), NAME_CONST('NAME', NULL))
#
create table t1 (a int);
insert t1 values (1),(2),(3);
select * from t1 where 1 in (a, name_const('a', null));
drop table t1;

--echo #
--echo # End of 5.5 tests
--echo #

--echo #
--echo # MDEV-10020 InnoDB NOT IN Query Crash When One Item Is NULL
--echo #
CREATE TABLE t1
(
  a INT(11),
  b VARCHAR(10),
  KEY (b)
);
INSERT INTO t1 VALUES (1,'x'),(2,'y'),(3,'z');
SELECT * FROM t1 WHERE b NOT IN (NULL, '', 'A');
DROP TABLE t1;

--echo #
--echo # End of 10.0 tests
--echo #

--echo #
--echo # MDEV-8755 Equal field propagation is not performed any longer for the IN list when multiple comparison types
--echo #
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(2);
--echo # Ok to propagate equalities into the left IN argument in case of a single comparison type
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=1 AND a IN (1,2,3);
--echo # Ok to propagate equalities into IN () list, even if multiple comparison types
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=1 AND 1 IN (1,a,'3');
--echo # Not Ok to propagate equalities into the left IN argument in case of multiple comparison types
EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=1 AND a IN (1,2,'3');
DROP TABLE t1;

--echo #
--echo # Start of 10.3 tests
--echo #

--echo #
--echo # MDEV-11514 IN with a mixture of TIME and DATETIME returns a wrong result
--echo #
#enable after fix MDEV-27871
--disable_view_protocol
SELECT TIME'10:20:30' IN (102030,TIME'10:20:31',TIMESTAMP'2001-01-01 10:20:32');
PREPARE stmt FROM "SELECT TIME'10:20:30' IN (102030,TIME'10:20:31',TIMESTAMP'2001-01-01 10:20:32')";
EXECUTE stmt;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
--enable_view_protocol

--echo #
--echo # MDEV-11497 Wrong result for (int_expr IN (mixture of signed and unsigned expressions))
--echo #
CREATE TABLE t1 (a BIGINT, b BIGINT UNSIGNED);
INSERT INTO t1 VALUES (-9223372036854775808,18446744073709551615);
SELECT * FROM t1 WHERE -1 IN (a,b);
PREPARE stmt FROM 'SELECT * FROM t1 WHERE -1 IN (a,b)';
EXECUTE stmt;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
DROP TABLE t1;

--echo #
--echo # MDEV-15340 Wrong result HOUR(case_expression_with_time_and_datetime)
--echo #

# This is to make sure that TIME_FUZZY_DATE is always passed to str_to_time(),
# so empty strings are compared as TIME'00:00:00' all around the code:
# when using Arg_comparator (e.g. in binary comparison operators), and
# when not using it (e.g. in IN predicate).

#view protocol generates additional warning
--disable_view_protocol
SELECT
  TIME'00:00:00'='' AS c1_true,
  TIME'00:00:00' IN ('', TIME'10:20:30') AS c2_true,
  TIME'00:00:00' NOT IN ('', TIME'10:20:30') AS c3_false;
--enable_view_protocol  

--echo #
--echo # End of 10.3 tests
--echo #

--echo #
--echo # Start of 10.4 tests
--echo #

--echo #
--echo # MDEV-16454 Bad results for IN with ROW
--echo #
SELECT (18446744073709551615,0) IN ((18446744073709551614,0),(-1,0));

SELECT '0x' IN (0);
SELECT '0x' IN (0,1);
SELECT ('0x',1) IN ((0,1));
SELECT ('0x',1) IN ((0,1),(1,1));

--echo #
--echo # End of 10.4 tests
--echo #

--echo #
--echo # MDEV-29662 same values in `IN` set vs equal comparison produces
--echo #            the different performance
--echo #
CREATE TABLE t1 (a INT, PRIMARY KEY(a));
INSERT INTO t1 VALUES (1),(2),(3);
SELECT * FROM t1 WHERE a IN (1,1);
--echo # 'const' access since 'a IN (1,1)' is converted to equality 'a=1'
EXPLAIN SELECT * FROM t1 WHERE a IN (1,1);
EXPLAIN SELECT * FROM t1 WHERE a = 1;
SELECT * FROM t1 WHERE a IN (1,1,2);
--echo # Conversion to equality is impossible due to different values
EXPLAIN SELECT * FROM t1 WHERE a IN (1,1,2);
SELECT * FROM t1 WHERE a IN (1,NULL,1);
--echo # Conversion to equality is impossible due to NULL in the IN list
EXPLAIN SELECT * FROM t1 WHERE a IN (1,NULL,1);

SELECT * FROM t1 WHERE a NOT IN (2,2,2,2,2,2);
EXPLAIN SELECT * FROM t1 WHERE a NOT IN (2,2,2,2,2,2);
EXPLAIN SELECT * FROM t1 WHERE a != 3;
SELECT * FROM t1 WHERE a NOT IN (3,3,1,1);
EXPLAIN SELECT * FROM t1 WHERE a NOT IN (3,3,1,1);
SELECT * FROM t1 WHERE a NOT IN (1,2,NULL,NULL);

--echo # No conversion is possible since elements are not constant
SELECT * FROM t1 WHERE a IN ((SELECT MAX(a) FROM t1), (SELECT MAX(a) FROM t1));
EXPLAIN SELECT * FROM t1 WHERE a IN 
  ((SELECT MAX(a) FROM t1), (SELECT MAX(a) FROM t1));

--echo # There must be no conversion here:
SELECT * FROM t1 WHERE a IN (3,2,3,3,1,2,3);

--echo # Prepared statement
PREPARE stmt FROM "SELECT * FROM t1 WHERE a IN (3,3,3)";
EXECUTE stmt;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

--echo # Conversion to equality since SELECT 2 is evaluated as const
--disable_warnings
SELECT * FROM t1 WHERE a IN ((SELECT 2), (SELECT 2));
EXPLAIN SELECT * FROM t1 WHERE a IN ((SELECT 2), (SELECT 2));
--enable_warnings

CREATE TABLE t2 (a INT, b VARCHAR(10), PRIMARY KEY(a,b));
INSERT INTO t2 VALUES (1,'abc'),(2,'def'),(3,'ghi');
SELECT * FROM t2 WHERE (a,b) IN ((1,'abc'),(1,'abc'));
--echo # 'const' access due to conversion to equality
EXPLAIN SELECT * FROM t2 WHERE (a,b) IN ((1,'abc'),(1,'abc'));
SELECT * FROM t2 WHERE (a,b) IN ((2,'def'),(2,'def'),(2,'XYZ'));
--echo # No conversion due to different values
EXPLAIN SELECT * FROM t2 WHERE (a,b) IN ((2,'def'),(2,'def'),(2,'XYZ'));
SELECT * FROM t2 WHERE (a,b) IN ((2,'def'),(2,'def'),(2,NULL));
--echo # No conversion due to NULL
EXPLAIN SELECT * FROM t2 WHERE (a,b) IN ((2,'def'),(2,'def'),(2,NULL));

SELECT * FROM t2 WHERE (a,b) NOT IN ((2,'def'),(2,'def'),(2,NULL));

SELECT * FROM t2 WHERE a IN (1,1,1,1);
EXPLAIN SELECT * FROM t2 WHERE a IN (1,1,1,1);
EXPLAIN SELECT * FROM t2 WHERE a = 1;

SELECT * FROM t2 WHERE b NOT IN ('abc','abc');
EXPLAIN SELECT * FROM t2 WHERE b NOT IN ('abc','abc');
EXPLAIN SELECT * FROM t2 WHERE b != 'abc';

--echo # Prepared statements
PREPARE stmt FROM "EXPLAIN SELECT * FROM t2 WHERE (a,b) IN ((1,'abc'),(1,'abc'))";
EXECUTE stmt;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

CREATE TABLE t3(a INT, PRIMARY KEY(a));
INSERT INTO t3 VALUES (1),(2),(3);
PREPARE stmt FROM "EXPLAIN SELECT * FROM t3 WHERE a IN (?,?,?)";
EXECUTE stmt USING 1,1,1;
EXECUTE stmt USING 2,3,4;
DEALLOCATE PREPARE stmt;
DROP TABLE t1, t2, t3;

--echo # Nested joins
CREATE TABLE t1 (a INT, b VARCHAR(10), PRIMARY KEY(a));
INSERT INTO t1 VALUES (1,'abc'),(2,'def'),(3,'ghi');
CREATE TABLE t2 (a INT, b VARCHAR(20), PRIMARY KEY(a));
INSERT INTO t2 (a) VALUES (2),(3);
CREATE TABLE t3 (a INT, PRIMARY KEY(a));
INSERT INTO t3 VALUES (1),(2),(3),(4);
CREATE TABLE t4 (a INT);
INSERT INTO t4 VALUES (2),(3);
--echo # Conversion to equalities
EXPLAIN SELECT * FROM (t1,t2) LEFT JOIN (t3,t4) ON t1.a IN (2,2,2)
    AND t3.a IN (1,1,1);
--echo # No conversion to equalities due to different values in IN()
EXPLAIN SELECT * FROM (t1,t2) LEFT JOIN (t3,t4) ON t1.a IN (2,3)
    AND t3.a IN (1,2);
--echo # Conversion to equalities
EXPLAIN SELECT * FROM t1 LEFT JOIN ((t2, t3) LEFT JOIN t4 ON t2.a = t4.a)
    ON t1.a = t2.a WHERE t1.a IN (2,2,2);
--echo # No conversion to equalities due to different values in IN()
EXPLAIN SELECT * FROM t1 LEFT JOIN ((t2, t3) LEFT JOIN t4 ON t2.a = t4.a)
    ON t1.a = t2.a WHERE t1.a IN (1,3);

--echo # View
CREATE VIEW v1 AS SELECT t1.*, t2.b AS t2_b FROM t1 LEFT JOIN t2
    ON t1.a = t2.a;
EXPLAIN SELECT * FROM v1 WHERE a IN (2,2,2);
EXPLAIN SELECT * FROM v1 WHERE a IN (1,2,3);

--echo # Stored procedures
CREATE PROCEDURE p1(pa INT, pb INT)
    EXPLAIN SELECT * FROM t1 WHERE a IN (pa, pb);
CALL p1(1,1);
CALL p1(2,1);

DROP TABLE t1, t2, t3, t4;
DROP VIEW v1;
DROP PROCEDURE p1;

--echo #
--echo # MDEV-29895 prepared view crash server (unit.conc_view)
--echo #

create table t1 (username varchar(12) not null, id int(11) not null);
create view v1 as select username from t1 where id = 0;
prepare stmt from "select username from v1 where username in (?, ?)";
execute stmt using "1", "1";
deallocate prepare stmt;
drop view v1;
drop table t1;

--echo #
--echo # End of 10.6 tests
--echo #