summaryrefslogtreecommitdiff
path: root/mysql-test/main/func_debug.test
blob: 8dd01650ed36b1ff529df869691f165b1ff7ed45 (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
--source include/have_debug.inc

SET SESSION debug_dbug="+d,Item_func_in";
SET SESSION debug_dbug="+d,Predicant_to_list_comparator";

--echo # Constant predicant, compatible types, bisect
SELECT 1 IN (1,2);
SELECT 1 IN (1,2,NULL);
SELECT 1 NOT IN (1,2);
SELECT 1 NOT IN (1,2,NULL);

SELECT 1.0 IN (1.0,2.0);
SELECT 1.0 IN (1.0,2.0,NULL);
SELECT 1.0 NOT IN (1.0,2.0);
SELECT 1.0 NOT IN (1.0,2.0,NULL);

SELECT 1e0 IN (1e0,2e0);
SELECT 1e0 IN (1e0,2e0,NULL);
SELECT 1e0 NOT IN (1e0,2e0);
SELECT 1e0 NOT IN (1e0,2e0,NULL);

SELECT 'a' IN ('a','b');
SELECT 'a' IN ('a','b',NULL);
SELECT 'a' NOT IN ('a','b');
SELECT 'a' NOT IN ('a','b',NULL);

SELECT TIMESTAMP'2001-01-01 10:20:30' IN ('2001-01-01 10:20:30','2001-02-02 10:20:30');
SELECT TIMESTAMP'2001-01-01 10:20:30' IN ('2001-01-01 10:20:30','2001-02-02 10:20:30',NULL);
SELECT TIMESTAMP'2001-01-01 10:20:30' NOT IN ('2001-01-01 10:20:30','2001-02-02 10:20:30');
SELECT TIMESTAMP'2001-01-01 10:20:30' NOT IN ('2001-01-01 10:20:30','2001-02-02 10:20:30',NULL);

SELECT TIME'10:20:30' IN ('10:20:30','10:20:30');
SELECT TIME'10:20:30' IN ('10:20:30','10:20:30',NULL);
SELECT TIME'10:20:30' NOT IN ('10:20:30','10:20:30');
SELECT TIME'10:20:30' NOT IN ('10:20:30','10:20:30',NULL);

SELECT DATE'2001-01-01' IN ('2001-01-01','2001-02-02');
SELECT DATE'2001-01-01' IN ('2001-01-01','2001-02-02',NULL);
SELECT DATE'2001-01-01' NOT IN ('2001-01-01','2001-02-02');
SELECT DATE'2001-01-01' NOT IN ('2001-01-01','2001-02-02',NULL);


--echo # Column predicant, compatible types, bisect

# Special case: mixture of unsigned, signed and decimal
CREATE TABLE t1 (a INT UNSIGNED);
# a=1.0 is done as decimal, because decimal bits int
# a=1   is done as decimal as well, because of different unsigned flag
SELECT a IN (1.0, 1) FROM t1;
DROP TABLE t1;

CREATE TABLE t1 (a INT);
SELECT a IN (1,2,3) FROM t1;
SELECT a IN (1,2,3,NULL) FROM t1;
SELECT a IN (1.0, CAST(1 AS UNSIGNED)) FROM t1;
SELECT a IN (1.0, CAST(1 AS UNSIGNED),NULL) FROM t1;
SELECT a NOT IN (1,2,3) FROM t1;
SELECT a NOT IN (1,2,3,NULL) FROM t1;
SELECT a NOT IN (1.0, CAST(1 AS UNSIGNED)) FROM t1;
SELECT a NOT IN (1.0, CAST(1 AS UNSIGNED),NULL) FROM t1;
DROP TABLE t1;

CREATE TABLE t1 (a DOUBLE);
SELECT a IN (1e0,2,3.0) FROM t1;
SELECT a IN (1e0,2,3.0,NULL) FROM t1;
SELECT a NOT IN (1e0,2,3.0) FROM t1;
SELECT a NOT IN (1e0,2,3.0,NULL) FROM t1;
DROP TABLE t1;

CREATE TABLE t1 (a DECIMAL(10,1));
SELECT a IN (1,2.0,3.0) FROM t1;
SELECT a IN (1,2.0,3.0,NULL) FROM t1;
SELECT a NOT IN (1,2.0,3.0) FROM t1;
SELECT a NOT IN (1,2.0,3.0,NULL) FROM t1;
DROP TABLE t1;

CREATE TABLE t1 (a VARCHAR(10));
SELECT a IN ('a','b','c') FROM t1;
SELECT a IN ('a','b','c',NULL) FROM t1;
SELECT a NOT IN ('a','b','c') FROM t1;
SELECT a NOT IN ('a','b','c',NULL) FROM t1;
DROP TABLE t1;

CREATE TABLE t1 (a DATE);
SELECT a IN ('2001-01-01',DATE'2001-01-02',20010102,20010102.0,20010102e0) FROM t1;
SELECT a IN ('2001-01-01',DATE'2001-01-02',20010102,20010102.0,20010102e0,NULL) FROM t1;
SELECT a NOT IN ('2001-01-01',DATE'2001-01-02',20010102,20010102.0,20010102e0) FROM t1;
SELECT a NOT IN ('2001-01-01',DATE'2001-01-02',20010102,20010102.0,20010102e0,NULL) FROM t1;
DROP TABLE t1;

CREATE TABLE t1 (a TIME);
SELECT a IN ('10:20:30',TIME'10:20:30',102030,102030.0,102030e0) FROM t1;
SELECT a IN ('10:20:30',TIME'10:20:30',102030,102030.0,102030e0,NULL) FROM t1;
SELECT a NOT IN ('10:20:30',TIME'10:20:30',102030,102030.0,102030e0) FROM t1;
SELECT a NOT IN ('10:20:30',TIME'10:20:30',102030,102030.0,102030e0,NULL) FROM t1;
DROP TABLE t1;

CREATE TABLE t1 (a DATETIME);
SELECT a IN ('2001-01-01',TIMESTAMP'2001-01-01 10:20:30',DATE'2001-01-01',TIME'10:20:30',20010101102030,20010101102030.0,20010101102030e0) FROM t1;
SELECT a IN ('2001-01-01',TIMESTAMP'2001-01-01 10:20:30',DATE'2001-01-01',TIME'10:20:30',20010101102030,20010101102030.0,20010101102030e0,NULL) FROM t1;
SELECT a NOT IN ('2001-01-01',TIMESTAMP'2001-01-01 10:20:30',DATE'2001-01-01',TIME'10:20:30',20010101102030,20010101102030.0,20010101102030e0) FROM t1;
SELECT a NOT IN ('2001-01-01',TIMESTAMP'2001-01-01 10:20:30',DATE'2001-01-01',TIME'10:20:30',20010101102030,20010101102030.0,20010101102030e0,NULL) FROM t1;
DROP TABLE t1;

--echo # Constant predicant, compatible types, no bisect
--echo # Bisect is not used because of non-constant expressions in the list
CREATE TABLE t1 (a INT);
SELECT 1 IN (a,1,2,3) FROM t1;
SELECT 1 IN (a,1,2,3,NULL) FROM t1;
SELECT 1 NOT IN (a,1,2,3) FROM t1;
SELECT 1 NOT IN (a,1,2,3,NULL) FROM t1;
DROP TABLE t1;

CREATE TABLE t1 (a DOUBLE);
SELECT 1 IN (a,1e0,2e0,3e0) FROM t1;
SELECT 1 IN (a,1e0,2e0,3e0,NULL) FROM t1;
SELECT 1 NOT IN (a,1e0,2e0,3e0) FROM t1;
SELECT 1 NOT IN (a,1e0,2e0,3e0,NULL) FROM t1;
DROP TABLE t1;

CREATE TABLE t1 (a DECIMAL(10,1));
SELECT 1 IN (a,1.0,2.0,3.0) FROM t1;
SELECT 1 IN (a,1.0,2.0,3.0,NULL) FROM t1;
SELECT 1 NOT IN (a,1.0,2.0,3.0) FROM t1;
SELECT 1 NOT IN (a,1.0,2.0,3.0,NULL) FROM t1;
DROP TABLE t1;

CREATE TABLE t1 (a VARCHAR(10));
SELECT 'a' IN (a,'b','c') FROM t1;
SELECT 'a' IN (a,'b','c',NULL) FROM t1;
SELECT 'a' NOT IN (a,'b','c') FROM t1;
SELECT 'a' NOT IN (a,'b','c',NULL) FROM t1;
DROP TABLE t1;

CREATE TABLE t1 (a DATE);
SELECT DATE'2001-01-01' IN (a,'2001-01-01') FROM t1;
SELECT DATE'2001-01-01' IN (a,'2001-01-01',NULL) FROM t1;
SELECT DATE'2001-01-01' NOT IN (a,'2001-01-01') FROM t1;
SELECT DATE'2001-01-01' NOT IN (a,'2001-01-01',NULL) FROM t1;
DROP TABLE t1;

CREATE TABLE t1 (a TIME);
SELECT TIME'10:20:30' IN (a,'10:20:30') FROM t1;
SELECT TIME'10:20:30' IN (a,'10:20:30',NULL) FROM t1;
SELECT TIME'10:20:30' NOT IN (a,'10:20:30') FROM t1;
SELECT TIME'10:20:30' NOT IN (a,'10:20:30',NULL) FROM t1;
DROP TABLE t1;

CREATE TABLE t1 (a DATETIME);
SELECT TIMESTAMP'2001-01-01 10:20:30' IN (a,TIMESTAMP'2001-01-01 10:20:30') FROM t1;
SELECT TIMESTAMP'2001-01-01 10:20:30' IN (a,TIMESTAMP'2001-01-01 10:20:30',NULL) FROM t1;
SELECT TIMESTAMP'2001-01-01 10:20:30' NOT IN (a,TIMESTAMP'2001-01-01 10:20:30') FROM t1;
SELECT TIMESTAMP'2001-01-01 10:20:30' NOT IN (a,TIMESTAMP'2001-01-01 10:20:30',NULL) FROM t1;
DROP TABLE t1;


--echo # Constant predicant, incompatible types, no bisect
SELECT 1 IN (1,2e0);
SELECT 1 IN (1,2e0,NULL);
SELECT 1 NOT IN (1,2e0);
SELECT 1 NOT IN (1,2e0,NULL);

SELECT 1.0 IN (1.0,2e0);
SELECT 1.0 IN (1.0,2e0,NULL);
SELECT 1.0 NOT IN (1.0,2e0);
SELECT 1.0 NOT IN (1.0,2e0,NULL);

SELECT 1e0 IN (1.0,TIME'10:20:30');
SELECT 1e0 IN (1.0,TIME'10:20:30',NULL);
SELECT 1e0 NOT IN (1.0,TIME'10:20:30');
SELECT 1e0 NOT IN (1.0,TIME'10:20:30',NULL);

SELECT 'a' IN ('a',2);
SELECT 'a' IN ('a',2,NULL);
SELECT 'a' NOT IN ('a',2);
SELECT 'a' NOT IN ('a',2,NULL);

SELECT TIME'10:20:30' IN (1,TIME'10:20:30');
SELECT TIME'10:20:30' IN (1,TIME'10:20:30',NULL);
SELECT TIME'10:20:30' IN (102030, TIME'10:20:30',TIMESTAMP'2001-01-01 10:20:32');
SELECT TIME'10:20:30' IN (102030, TIME'10:20:30',TIMESTAMP'2001-01-01 10:20:32',NULL);
SELECT TIME'10:20:30' IN (102030, 102030, TIME'10:20:30',TIMESTAMP'2001-01-01 10:20:32');
SELECT TIME'10:20:30' IN (102030, 102030, TIME'10:20:30',TIMESTAMP'2001-01-01 10:20:32',NULL);
SELECT TIME'10:20:30' NOT IN (1,TIME'10:20:30');
SELECT TIME'10:20:30' NOT IN (1,TIME'10:20:30',NULL);
SELECT TIME'10:20:30' NOT IN (102030, TIME'10:20:30',TIMESTAMP'2001-01-01 10:20:32');
SELECT TIME'10:20:30' NOT IN (102030, TIME'10:20:30',TIMESTAMP'2001-01-01 10:20:32',NULL);
SELECT TIME'10:20:30' NOT IN (102030, 102030, TIME'10:20:30',TIMESTAMP'2001-01-01 10:20:32');
SELECT TIME'10:20:30' NOT IN (102030, 102030, TIME'10:20:30',TIMESTAMP'2001-01-01 10:20:32',NULL);

--echo # Column predicant, incompatible types, no bisect
CREATE TABLE t1 (a INT);
SELECT a IN (1,1e0) FROM t1;
SELECT a IN (1,1e0,NULL) FROM t1;
SELECT a IN (CAST(1 AS SIGNED), CAST(1 AS UNSIGNED)) FROM t1;
SELECT a IN (CAST(1 AS SIGNED), CAST(1 AS UNSIGNED),NULL) FROM t1;
SELECT a IN (CAST(1 AS DECIMAL),CAST(1 AS SIGNED), CAST(1 AS UNSIGNED)) FROM t1;
SELECT a IN (CAST(1 AS DECIMAL),CAST(1 AS SIGNED), CAST(1 AS UNSIGNED),NULL) FROM t1;
SELECT a NOT IN (1,1e0) FROM t1;
SELECT a NOT IN (1,1e0,NULL) FROM t1;
SELECT a NOT IN (CAST(1 AS SIGNED), CAST(1 AS UNSIGNED)) FROM t1;
SELECT a NOT IN (CAST(1 AS SIGNED), CAST(1 AS UNSIGNED),NULL) FROM t1;
SELECT a NOT IN (CAST(1 AS DECIMAL),CAST(1 AS SIGNED), CAST(1 AS UNSIGNED)) FROM t1;
SELECT a NOT IN (CAST(1 AS DECIMAL),CAST(1 AS SIGNED), CAST(1 AS UNSIGNED),NULL) FROM t1;

SELECT a IN (1,1.0) FROM t1;
SELECT a IN (1,1.0,NULL) FROM t1;
SELECT a NOT IN (1,1.0) FROM t1;
SELECT a NOT IN (1,1.0,NULL) FROM t1;

SELECT a IN (1,'1') FROM t1;
SELECT a IN (1,'1',NULL) FROM t1;
SELECT a NOT IN (1,'1') FROM t1;
SELECT a NOT IN (1,'1',NULL) FROM t1;

SELECT a IN (1,TIME'10:20:30') FROM t1;
SELECT a IN (1,TIME'10:20:30',NULL) FROM t1;
SELECT a NOT IN (1,TIME'10:20:30') FROM t1;
SELECT a NOT IN (1,TIME'10:20:30',NULL) FROM t1;
DROP TABLE t1;

CREATE TABLE t1 (a DECIMAL(10,0));
SELECT a IN (1,1e0) FROM t1;
SELECT a IN (1,1e0,NULL) FROM t1;
SELECT a NOT IN (1,1e0) FROM t1;
SELECT a NOT IN (1,1e0,NULL) FROM t1;

SELECT a IN (1,'1') FROM t1;
SELECT a IN (1,'1',NULL) FROM t1;
SELECT a NOT IN (1,'1') FROM t1;
SELECT a NOT IN (1,'1',NULL) FROM t1;

SELECT a IN (1,TIME'10:20:30') FROM t1;
SELECT a IN (1,TIME'10:20:30',NULL) FROM t1;
SELECT a NOT IN (1,TIME'10:20:30') FROM t1;
SELECT a NOT IN (1,TIME'10:20:30',NULL) FROM t1;
DROP TABLE t1;

CREATE TABLE t1 (a DOUBLE);
SELECT a IN (1,TIME'10:20:30') FROM t1;
SELECT a IN (1,TIME'10:20:30',NULL) FROM t1;
SELECT a NOT IN (1,TIME'10:20:30') FROM t1;
SELECT a NOT IN (1,TIME'10:20:30',NULL) FROM t1;

SELECT a IN (1,DATE'2001-01-01') FROM t1;
SELECT a IN (1,DATE'2001-01-01',NULL) FROM t1;
SELECT a NOT IN (1,DATE'2001-01-01') FROM t1;
SELECT a NOT IN (1,DATE'2001-01-01',NULL) FROM t1;

SELECT a IN (1,TIMESTAMP'2001-01-01 10:20:30') FROM t1;
SELECT a IN (1,TIMESTAMP'2001-01-01 10:20:30',NULL) FROM t1;
SELECT a NOT IN (1,TIMESTAMP'2001-01-01 10:20:30') FROM t1;
SELECT a NOT IN (1,TIMESTAMP'2001-01-01 10:20:30',NULL) FROM t1;
DROP TABLE t1;

CREATE TABLE t1 (a VARCHAR(10));
SELECT a IN ('a',1) FROM t1;
SELECT a IN ('a',TIME'10:20:30') FROM t1;
SELECT a NOT IN ('a',1) FROM t1;
SELECT a NOT IN ('a',TIME'10:20:30') FROM t1;
DROP TABLE t1;

CREATE TABLE t1 (a TIME);
SELECT a IN (102030, TIME'10:20:30',TIMESTAMP'2001-01-01 10:20:32') FROM t1;
SELECT a IN (102030, TIME'10:20:30',TIMESTAMP'2001-01-01 10:20:32',NULL) FROM t1;
SELECT a IN (102030, 102030, TIME'10:20:30',TIMESTAMP'2001-01-01 10:20:32') FROM t1;
SELECT a IN (102030, 102030, TIME'10:20:30',TIMESTAMP'2001-01-01 10:20:32',NULL) FROM t1;
SELECT a NOT IN (102030, TIME'10:20:30',TIMESTAMP'2001-01-01 10:20:32') FROM t1;
SELECT a NOT IN (102030, TIME'10:20:30',TIMESTAMP'2001-01-01 10:20:32',NULL) FROM t1;
SELECT a NOT IN (102030, 102030, TIME'10:20:30',TIMESTAMP'2001-01-01 10:20:32') FROM t1;
SELECT a NOT IN (102030, 102030, TIME'10:20:30',TIMESTAMP'2001-01-01 10:20:32',NULL) FROM t1;
DROP TABLE t1;

#
# ROW tests
#
# ROW has additional conditions when bisect is possible (see item_cmpfunc.h):
#
#  ((is_top_level_item && not_negated) ||             // 3
#  (arg0_can_not_be_null && list_does_not_have_nulls) // 4

# Testing all combinations of the condition components
#
# tli     - is_top_level_item
# nneg    - not_negated
# a0nnul  - arg0_can_not_be_null
# lnnul   - list_does_not_have_nulls
# cond3   - condition 3 is true?
# cond4   - condition 4 is true?
# bisect  - bisect is possible (cond3 orded with cond4)

# Note:
# - using an expression in SELECT list makes top_level_item() to be false
# - using an expression in WHERE clause makes top_leve_item() to be true

--echo # Not top level, negated: cond3 is false

#  tli nneg a0nnul  lnnul    cond3  cond4 bisect
#  ---  --- ------  -----    -----  ----- ------
#    0    0      0      0        0      0      0
#    0    0      0      1        0      0      0
#    0    0      1      0        0      0      0
#    0    0      1      1        0      1      1

# ROW with scalar elements
CREATE TABLE t1 (a INT);
SELECT ROW(a,a) NOT IN ((1,1),(2,NULL)) FROM t1;
SELECT ROW(a,a) NOT IN ((1,1),(2,2)) FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a INT NOT NULL, b INT);
SELECT ROW(a,a) NOT IN ((1,1),(2,NULL)) FROM t1;
SELECT ROW(a,a) NOT IN ((1,1),(2,2)) FROM t1;
DROP TABLE t1;

# ROW with a nested ROW
CREATE TABLE t1 (a INT);
SELECT ROW(a,(a,a)) NOT IN ((1,(1,1)),(2,(2,NULL))) FROM t1;
SELECT ROW(a,(a,a)) NOT IN ((1,(1,1)),(2,(2,2))) FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a INT NOT NULL);
SELECT ROW(a,(a,a)) NOT IN ((1,(1,1)),(2,(2,NULL))) FROM t1;
SELECT ROW(a,(a,a)) NOT IN ((1,(1,1)),(2,(2,2))) FROM t1;
DROP TABLE t1;

--echo # Not top level, not negated: cond3 is false

#  tli nneg a0nnul  lnnul    cond3  cond4 bisect
#  ---  --- ------  -----    -----  ----- ------
#    0    1      0      0        0      0      0
#    0    1      0      1        0      0      0
#    0    1      1      0        0      0      0
#    0    1      1      1        0      1      1

# ROW with scalar elements
CREATE TABLE t1 (a INT);
SELECT ROW(a,a) IN ((1,1),(2,NULL)) FROM t1;
SELECT ROW(a,a) IN ((1,1),(2,2)) FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a INT NOT NULL);
SELECT ROW(a,a) IN ((1,1),(2,NULL)) FROM t1;
SELECT ROW(a,a) IN ((1,1),(2,2)) FROM t1;
DROP TABLE t1;

# ROW with a nested ROW
CREATE TABLE t1 (a INT);
SELECT ROW(a,(a,a)) IN ((1,(1,1)),(2,(2,NULL))) FROM t1;
SELECT ROW(a,(a,a)) IN ((1,(1,1)),(2,(2,2))) FROM t1;
DROP TABLE t1;
CREATE TABLE t1 (a INT NOT NULL);
SELECT ROW(a,(a,a)) IN ((1,(1,1)),(2,(2,NULL))) FROM t1;
SELECT ROW(a,(a,a)) IN ((1,(1,1)),(2,(2,2))) FROM t1;
DROP TABLE t1;


--echo # Top level, negated: cond3 is false

#  tli nneg a0nnul  lnnul    cond3  cond4 bisect
#  ---  --- ------  -----    -----  ----- ------
#    1    0      0      0        0      0      0
#    1    0      0      1        0      0      0
#    1    0      1      0        0      0      0
#    1    0      1      1        0      1      1

# ROW with scalar elements
CREATE TABLE t1 (a INT);
SELECT 1 FROM t1 WHERE ROW(a,a) NOT IN ((1,1),(2,NULL));
SELECT 1 FROM t1 WHERE ROW(a,a) NOT IN ((1,1),(2,2));
DROP TABLE t1;
CREATE TABLE t1 (a INT NOT NULL);
SELECT 1 FROM t1 WHERE ROW(a,a) NOT IN ((1,1),(2,NULL));
SELECT 1 FROM t1 WHERE ROW(a,a) NOT IN ((1,1),(2,2));
DROP TABLE t1;

# ROW with a nested ROW
CREATE TABLE t1 (a INT);
SELECT 1 FROM t1 WHERE ROW(a,(a,a)) NOT IN ((1,(1,1)),(2,(2,NULL)));
SELECT 1 FROM t1 WHERE ROW(a,(a,a)) NOT IN ((1,(1,1)),(2,(2,2)));
DROP TABLE t1;
CREATE TABLE t1 (a INT NOT NULL);
SELECT 1 FROM t1 WHERE ROW(a,(a,a)) NOT IN ((1,(1,1)),(2,(2,NULL)));
SELECT 1 FROM t1 WHERE ROW(a,(a,a)) NOT IN ((1,(1,1)),(2,(2,2)));
DROP TABLE t1;

--echo # Top level, not negated: cond3 is true

#  tli nneg a0nnul  lnnul    cond3  cond4 bisect
#  ---  --- ------  -----    -----  ----- ------
#    1    1      0      0        1      0      1
#    1    1      0      1        1      1      1
#    1    1      1      0        1      0      1
#    1    1      1      1        1      1      1

# ROW with scalar elements
CREATE TABLE t1 (a INT);
SELECT 1 FROM t1 WHERE ROW(a,a) IN ((1,1),(2,NULL));
SELECT 1 FROM t1 WHERE ROW(a,a) IN ((1,1),(2,2));
DROP TABLE t1;
CREATE TABLE t1 (a INT NOT NULL);
SELECT 1 FROM t1 WHERE ROW(a,a) IN ((1,1),(2,NULL));
SELECT 1 FROM t1 WHERE ROW(a,a) IN ((1,1),(2,2));
DROP TABLE t1;

# ROW with a nested ROW
CREATE TABLE t1 (a INT);
SELECT 1 FROM t1 WHERE ROW(a,(a,a)) IN ((1,(1,1)),(2,(2,NULL)));
SELECT 1 FROM t1 WHERE ROW(a,(a,a)) IN ((1,(1,1)),(2,(2,2)));
DROP TABLE t1;
CREATE TABLE t1 (a INT NOT NULL);
SELECT 1 FROM t1 WHERE ROW(a,(a,a)) IN ((1,(1,1)),(2,(2,NULL)));
SELECT 1 FROM t1 WHERE ROW(a,(a,a)) IN ((1,(1,1)),(2,(2,2)));
DROP TABLE t1;

--echo #
--echo # MDEV-11514 IN with a mixture of TIME and DATETIME returns a wrong result
--echo #

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;

CREATE TABLE t1 (a VARCHAR(10));
INSERT INTO t1 VALUES ('A'),('B'),('A');
# Compatible types
SELECT a,NULL AS b FROM t1 GROUP BY a HAVING 'A' IN (b,'A');
SELECT a,NULL AS b FROM t1 GROUP BY a HAVING 'A' IN ('A',b);
SELECT a,NULL AS b FROM t1 GROUP BY a HAVING 'A' IN (b,a);
SELECT a,NULL AS b FROM t1 GROUP BY a HAVING 'A' IN (a,b);
# Incompatible types
SELECT a,NULL AS b FROM t1 GROUP BY a HAVING 'A' IN (b,'A',10);
SELECT a,NULL AS b FROM t1 GROUP BY a HAVING 'A' IN ('A',b,10);
SELECT a,NULL AS b FROM t1 GROUP BY a HAVING 'A' IN (b,a,10);
SELECT a,NULL AS b FROM t1 GROUP BY a HAVING 'A' IN (a,b,10);
DROP TABLE t1;

--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);
DROP TABLE t1;


--echo #
--echo # MDEV-11554 Wrong result for CASE on a mixture of signed and unsigned expressions
--echo #

CREATE TABLE t1 (a BIGINT, b BIGINT UNSIGNED);
INSERT INTO t1 VALUES (-9223372036854775808,18446744073709551615);
SELECT
  CASE -1
    WHEN -9223372036854775808 THEN 'one'
    WHEN 18446744073709551615 THEN 'two'
  END AS c;
DROP TABLE t1;

--echo #
--echo # MDEV-11555 CASE with a mixture of TIME and DATETIME returns a wrong result
--echo #
SELECT
  CASE TIME'10:20:30'
    WHEN 102030 THEN 'one'
    WHEN TIME'10:20:31' THEN 'two'
  END AS good,
  CASE TIME'10:20:30'
    WHEN 102030 THEN 'one'
    WHEN TIME'10:20:31' THEN 'two'
    WHEN TIMESTAMP'2001-01-01 10:20:32' THEN 'three'
  END AS was_bad_now_good;


SET SESSION debug_dbug="-d,Predicant_to_list_comparator";
SET SESSION debug_dbug="-d,Item_func_in";


--echo #
--echo # MDEV-19008 Slow EXPLAIN SELECT ... WHERE col IN (const1,const2,(subquery))
--echo #

SET SESSION debug_dbug="+d,Item_subselect";
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
EXPLAIN SELECT * FROM t1 WHERE a IN (1,2,(SELECT MAX(a) FROM t1));
SELECT * FROM t1 WHERE a IN (1,2,(SELECT MAX(a) FROM t1));
DROP TABLE t1;
SET SESSION debug_dbug="-d,Item_subselect";