2
# Hash semi-join regression tests
3
# (WL#1110: Subquery optimization: materialization)
7
drop table if exists t1, t2, t3, t1i, t2i, t3i;
10
create table t1 (a1 char(8), a2 char(8));
11
create table t2 (b1 char(8), b2 char(8));
12
create table t3 (c1 char(8), c2 char(8));
14
insert into t1 values ('1 - 00', '2 - 00');
15
insert into t1 values ('1 - 01', '2 - 01');
16
insert into t1 values ('1 - 02', '2 - 02');
18
insert into t2 values ('1 - 01', '2 - 01');
19
insert into t2 values ('1 - 01', '2 - 01');
20
insert into t2 values ('1 - 02', '2 - 02');
21
insert into t2 values ('1 - 02', '2 - 02');
22
insert into t2 values ('1 - 03', '2 - 03');
24
insert into t3 values ('1 - 01', '2 - 01');
25
insert into t3 values ('1 - 02', '2 - 02');
26
insert into t3 values ('1 - 03', '2 - 03');
27
insert into t3 values ('1 - 04', '2 - 04');
30
create table t1i (a1 char(8), a2 char(8));
31
create table t2i (b1 char(8), b2 char(8));
32
create table t3i (c1 char(8), c2 char(8));
33
create index it1i1 on t1i (a1);
34
create index it1i2 on t1i (a2);
35
create index it1i3 on t1i (a1, a2);
37
create index it2i1 on t2i (b1);
38
create index it2i2 on t2i (b2);
39
create index it2i3 on t2i (b1, b2);
41
create index it3i1 on t3i (c1);
42
create index it3i2 on t3i (c2);
43
create index it3i3 on t3i (c1, c2);
45
insert into t1i select * from t1;
46
insert into t2i select * from t2;
47
insert into t3i select * from t3;
49
# force the use of materialization
50
set @@optimizer_switch=no_semijoin;
52
/******************************************************************************
54
******************************************************************************/
55
# non-indexed nullable fields
57
select * from t1 where a1 in (select b1 from t2 where b1 > '0');
58
select * from t1 where a1 in (select b1 from t2 where b1 > '0');
61
select * from t1 where a1 in (select b1 from t2 where b1 > '0' group by b1);
62
select * from t1 where a1 in (select b1 from t2 where b1 > '0' group by b1);
65
select * from t1 where (a1, a2) in (select b1, b2 from t2 where b1 > '0' group by b1, b2);
66
select * from t1 where (a1, a2) in (select b1, b2 from t2 where b1 > '0' group by b1, b2);
69
select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1);
70
select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1);
74
select * from t1i where a1 in (select b1 from t2i where b1 > '0');
75
select * from t1i where a1 in (select b1 from t2i where b1 > '0');
78
select * from t1i where a1 in (select b1 from t2i where b1 > '0' group by b1);
79
select * from t1i where a1 in (select b1 from t2i where b1 > '0' group by b1);
82
select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0');
83
select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0');
86
select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0' group by b1, b2);
87
select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0' group by b1, b2);
90
select * from t1i where (a1, a2) in (select b1, min(b2) from t2i where b1 > '0' group by b1);
91
select * from t1i where (a1, a2) in (select b1, min(b2) from t2i where b1 > '0' group by b1);
93
# materialize the result of ORDER BY
96
select * from t1 where (a1, a2) in (select b1, b2 from t2 order by b1, b2);
97
select * from t1 where (a1, a2) in (select b1, b2 from t2 order by b1, b2);
100
select * from t1i where (a1, a2) in (select b1, b2 from t2i order by b1, b2);
101
select * from t1i where (a1, a2) in (select b1, b2 from t2i order by b1, b2);
103
# nested subqueries, views
106
where (a1, a2) in (select b1, b2 from t2 where b1 > '0') and
107
(a1, a2) in (select c1, c2 from t3
108
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
110
where (a1, a2) in (select b1, b2 from t2 where b1 > '0') and
111
(a1, a2) in (select c1, c2 from t3
112
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
116
where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and
117
(a1, a2) in (select c1, c2 from t3i
118
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
120
where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and
121
(a1, a2) in (select c1, c2 from t3i
122
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
126
where (a1, a2) in (select b1, b2 from t2
127
where b2 in (select c2 from t3 where c2 LIKE '%02') or
128
b2 in (select c2 from t3 where c2 LIKE '%03')) and
129
(a1, a2) in (select c1, c2 from t3
130
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
132
where (a1, a2) in (select b1, b2 from t2
133
where b2 in (select c2 from t3 where c2 LIKE '%02') or
134
b2 in (select c2 from t3 where c2 LIKE '%03')) and
135
(a1, a2) in (select c1, c2 from t3
136
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
138
# as above with correlated innermost subquery
141
where (a1, a2) in (select b1, b2 from t2
142
where b2 in (select c2 from t3 t3a where c1 = a1) or
143
b2 in (select c2 from t3 t3b where c2 LIKE '%03')) and
144
(a1, a2) in (select c1, c2 from t3 t3c
145
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
147
where (a1, a2) in (select b1, b2 from t2
148
where b2 in (select c2 from t3 t3a where c1 = a1) or
149
b2 in (select c2 from t3 t3b where c2 LIKE '%03')) and
150
(a1, a2) in (select c1, c2 from t3 t3c
151
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
154
# multiple levels of nesting subqueries, unions
157
where (a1, a2) in (select b1, b2 from t2
158
where b2 in (select c2 from t3 where c2 LIKE '%02') or
159
b2 in (select c2 from t3 where c2 LIKE '%03')
161
(a1, a2) in (select c1, c2 from t3
162
where (c1, c2) in (select b1, b2 from t2i where b2 > '0')))
165
where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and
166
(a1, a2) in (select c1, c2 from t3i
167
where (c1, c2) in (select b1, b2 from t2i where b2 > '0')));
170
where (a1, a2) in (select b1, b2 from t2
171
where b2 in (select c2 from t3 where c2 LIKE '%02') or
172
b2 in (select c2 from t3 where c2 LIKE '%03')
174
(a1, a2) in (select c1, c2 from t3
175
where (c1, c2) in (select b1, b2 from t2i where b2 > '0')))
178
where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and
179
(a1, a2) in (select c1, c2 from t3i
180
where (c1, c2) in (select b1, b2 from t2i where b2 > '0')));
183
# UNION of subqueries as a subquery (thus it is not computed via materialization)
186
where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and
187
(a1, a2) in (select c1, c2 from t3
188
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
190
where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and
191
(a1, a2) in (select c1, c2 from t3
192
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
193
# as above, with a join conditon between the outer references
196
where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and
197
(c1, c2) in (select c1, c2 from t3
198
where (c1, c2) in (select b1, b2 from t2i where b2 > '0')) and
201
where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and
202
(c1, c2) in (select c1, c2 from t3
203
where (c1, c2) in (select b1, b2 from t2i where b2 > '0')) and
207
/******************************************************************************
208
* Negative tests, where materialization should not be applied.
209
******************************************************************************/
210
# UNION in a subquery
213
where c1 in (select a1 from t1 where a1 > '0' UNION select b1 from t2 where b1 < '9');
215
where c1 in (select a1 from t1 where a1 > '0' UNION select b1 from t2 where b1 < '9');
220
where (a1, a2) in (select b1, b2 from t2
221
where b2 in (select c2 from t3 t3a where c1 = a1) or
222
b2 in (select c2 from t3 t3b where c2 LIKE '%03')) and
223
(a1, a2) in (select c1, c2 from t3 t3c
224
where (c1, c2) in (select b1, b2 from t2i where b2 > '0' or b2 = a2));
226
# subquery has no tables
228
select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01');
229
select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01');
231
select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01' from dual);
232
select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01' from dual);
235
/******************************************************************************
236
* Subqueries in other uncovered clauses.
237
******************************************************************************/
240
select ((a1,a2) IN (select * from t2 where b2 > '0')) IS NULL from t1;
242
/* GROUP BY clause */
243
create table columns (col int key);
244
insert into columns values (1), (2);
247
select * from t1 group by (select col from columns limit 1);
248
select * from t1 group by (select col from columns limit 1);
251
select * from t1 group by (a1 in (select col from columns));
252
select * from t1 group by (a1 in (select col from columns));
254
/* ORDER BY clause */
256
select * from t1 order by (select col from columns limit 1);
257
select * from t1 order by (select col from columns limit 1);
259
/******************************************************************************
260
* Column types/sizes that affect materialization.
261
******************************************************************************/
264
Test that BLOBs are not materialized (except when arguments of some functions).
266
# force materialization to be always considered
267
set @@optimizer_switch=no_semijoin;
270
# BLOB == 16 (small blobs that could be stored in HEAP tables)
272
set @suffix_len = @blob_len - @prefix_len;
274
create table t1_16 (a1 blob(16), a2 blob(16));
275
create table t2_16 (b1 blob(16), b2 blob(16));
276
create table t3_16 (c1 blob(16), c2 blob(16));
278
insert into t1_16 values
279
(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
280
insert into t1_16 values
281
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
282
insert into t1_16 values
283
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
285
insert into t2_16 values
286
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
287
insert into t2_16 values
288
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
289
insert into t2_16 values
290
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
292
insert into t3_16 values
293
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
294
insert into t3_16 values
295
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
296
insert into t3_16 values
297
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
298
insert into t3_16 values
299
(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len)));
301
# single value transformer
302
explain extended select left(a1,7), left(a2,7)
304
where a1 in (select b1 from t2_16 where b1 > '0');
306
select left(a1,7), left(a2,7)
308
where a1 in (select b1 from t2_16 where b1 > '0');
310
# row value transformer
311
explain extended select left(a1,7), left(a2,7)
313
where (a1,a2) in (select b1, b2 from t2_16 where b1 > '0');
315
select left(a1,7), left(a2,7)
317
where (a1,a2) in (select b1, b2 from t2_16 where b1 > '0');
319
# string function with a blob argument, the return type may be != blob
320
explain extended select left(a1,7), left(a2,7)
322
where a1 in (select substring(b1,1,16) from t2_16 where b1 > '0');
324
select left(a1,7), left(a2,7)
326
where a1 in (select substring(b1,1,16) from t2_16 where b1 > '0');
328
# group_concat with a blob argument - depends on
329
# the variable group_concat_max_len, and
330
# convert_blob_length == max_len*collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB
331
explain extended select left(a1,7), left(a2,7)
333
where a1 in (select group_concat(b1) from t2_16 group by b2);
335
select left(a1,7), left(a2,7)
337
where a1 in (select group_concat(b1) from t2_16 group by b2);
339
set @@group_concat_max_len = 256; # anything < (CONVERT_IF_BIGGER_TO_BLOB = 512)
341
explain extended select left(a1,7), left(a2,7)
343
where a1 in (select group_concat(b1) from t2_16 group by b2);
345
select left(a1,7), left(a2,7)
347
where a1 in (select group_concat(b1) from t2_16 group by b2);
349
# BLOB column at the second (intermediate) level of nesting
352
where concat(a1,'x') IN
353
(select left(a1,8) from t1_16
355
(select t2_16.b1, t2_16.b2 from t2_16, t2
356
where t2.b2 = substring(t2_16.b2,1,6) and
357
t2.b1 IN (select c1 from t3 where c2 > '0')));
360
drop table t1_16, t2_16, t3_16;
363
# BLOB == 512 (CONVERT_IF_BIGGER_TO_BLOB == 512)
365
set @suffix_len = @blob_len - @prefix_len;
367
create table t1_512 (a1 blob(512), a2 blob(512));
368
create table t2_512 (b1 blob(512), b2 blob(512));
369
create table t3_512 (c1 blob(512), c2 blob(512));
371
insert into t1_512 values
372
(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
373
insert into t1_512 values
374
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
375
insert into t1_512 values
376
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
378
insert into t2_512 values
379
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
380
insert into t2_512 values
381
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
382
insert into t2_512 values
383
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
385
insert into t3_512 values
386
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
387
insert into t3_512 values
388
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
389
insert into t3_512 values
390
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
391
insert into t3_512 values
392
(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len)));
394
# single value transformer
395
explain extended select left(a1,7), left(a2,7)
397
where a1 in (select b1 from t2_512 where b1 > '0');
399
select left(a1,7), left(a2,7)
401
where a1 in (select b1 from t2_512 where b1 > '0');
403
# row value transformer
404
explain extended select left(a1,7), left(a2,7)
406
where (a1,a2) in (select b1, b2 from t2_512 where b1 > '0');
408
select left(a1,7), left(a2,7)
410
where (a1,a2) in (select b1, b2 from t2_512 where b1 > '0');
412
# string function with a blob argument, the return type may be != blob
413
explain extended select left(a1,7), left(a2,7)
415
where a1 in (select substring(b1,1,512) from t2_512 where b1 > '0');
417
select left(a1,7), left(a2,7)
419
where a1 in (select substring(b1,1,512) from t2_512 where b1 > '0');
421
# group_concat with a blob argument - depends on
422
# the variable group_concat_max_len, and
423
# convert_blob_length == max_len*collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB
424
explain extended select left(a1,7), left(a2,7)
426
where a1 in (select group_concat(b1) from t2_512 group by b2);
428
select left(a1,7), left(a2,7)
430
where a1 in (select group_concat(b1) from t2_512 group by b2);
432
set @@group_concat_max_len = 256; # anything < (CONVERT_IF_BIGGER_TO_BLOB = 512)
434
explain extended select left(a1,7), left(a2,7)
436
where a1 in (select group_concat(b1) from t2_512 group by b2);
438
select left(a1,7), left(a2,7)
440
where a1 in (select group_concat(b1) from t2_512 group by b2);
442
drop table t1_512, t2_512, t3_512;
445
# BLOB == 1024 (group_concat_max_len == 1024)
446
set @blob_len = 1024;
447
set @suffix_len = @blob_len - @prefix_len;
449
create table t1_1024 (a1 blob(1024), a2 blob(1024));
450
create table t2_1024 (b1 blob(1024), b2 blob(1024));
451
create table t3_1024 (c1 blob(1024), c2 blob(1024));
453
insert into t1_1024 values
454
(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
455
insert into t1_1024 values
456
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
457
insert into t1_1024 values
458
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
460
insert into t2_1024 values
461
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
462
insert into t2_1024 values
463
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
464
insert into t2_1024 values
465
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
467
insert into t3_1024 values
468
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
469
insert into t3_1024 values
470
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
471
insert into t3_1024 values
472
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
473
insert into t3_1024 values
474
(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len)));
476
# single value transformer
477
explain extended select left(a1,7), left(a2,7)
479
where a1 in (select b1 from t2_1024 where b1 > '0');
481
select left(a1,7), left(a2,7)
483
where a1 in (select b1 from t2_1024 where b1 > '0');
485
# row value transformer
486
explain extended select left(a1,7), left(a2,7)
488
where (a1,a2) in (select b1, b2 from t2_1024 where b1 > '0');
490
select left(a1,7), left(a2,7)
492
where (a1,a2) in (select b1, b2 from t2_1024 where b1 > '0');
494
# string function with a blob argument, the return type may be != blob
495
explain extended select left(a1,7), left(a2,7)
497
where a1 in (select substring(b1,1,1024) from t2_1024 where b1 > '0');
499
select left(a1,7), left(a2,7)
501
where a1 in (select substring(b1,1,1024) from t2_1024 where b1 > '0');
503
# group_concat with a blob argument - depends on
504
# the variable group_concat_max_len, and
505
# convert_blob_length == max_len*collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB
506
explain extended select left(a1,7), left(a2,7)
508
where a1 in (select group_concat(b1) from t2_1024 group by b2);
510
select left(a1,7), left(a2,7)
512
where a1 in (select group_concat(b1) from t2_1024 group by b2);
514
set @@group_concat_max_len = 256; # anything < (CONVERT_IF_BIGGER_TO_BLOB = 1024)
516
explain extended select left(a1,7), left(a2,7)
518
where a1 in (select group_concat(b1) from t2_1024 group by b2);
520
select left(a1,7), left(a2,7)
522
where a1 in (select group_concat(b1) from t2_1024 group by b2);
524
drop table t1_1024, t2_1024, t3_1024;
528
set @blob_len = 1025;
529
set @suffix_len = @blob_len - @prefix_len;
531
create table t1_1025 (a1 blob(1025), a2 blob(1025));
532
create table t2_1025 (b1 blob(1025), b2 blob(1025));
533
create table t3_1025 (c1 blob(1025), c2 blob(1025));
535
insert into t1_1025 values
536
(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
537
insert into t1_1025 values
538
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
539
insert into t1_1025 values
540
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
542
insert into t2_1025 values
543
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
544
insert into t2_1025 values
545
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
546
insert into t2_1025 values
547
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
549
insert into t3_1025 values
550
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
551
insert into t3_1025 values
552
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
553
insert into t3_1025 values
554
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
555
insert into t3_1025 values
556
(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len)));
558
# single value transformer
559
explain extended select left(a1,7), left(a2,7)
561
where a1 in (select b1 from t2_1025 where b1 > '0');
563
select left(a1,7), left(a2,7)
565
where a1 in (select b1 from t2_1025 where b1 > '0');
567
# row value transformer
568
explain extended select left(a1,7), left(a2,7)
570
where (a1,a2) in (select b1, b2 from t2_1025 where b1 > '0');
572
select left(a1,7), left(a2,7)
574
where (a1,a2) in (select b1, b2 from t2_1025 where b1 > '0');
576
# string function with a blob argument, the return type may be != blob
577
explain extended select left(a1,7), left(a2,7)
579
where a1 in (select substring(b1,1,1025) from t2_1025 where b1 > '0');
581
select left(a1,7), left(a2,7)
583
where a1 in (select substring(b1,1,1025) from t2_1025 where b1 > '0');
585
# group_concat with a blob argument - depends on
586
# the variable group_concat_max_len, and
587
# convert_blob_length == max_len*collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB
588
explain extended select left(a1,7), left(a2,7)
590
where a1 in (select group_concat(b1) from t2_1025 group by b2);
592
select left(a1,7), left(a2,7)
594
where a1 in (select group_concat(b1) from t2_1025 group by b2);
596
set @@group_concat_max_len = 256; # anything < (CONVERT_IF_BIGGER_TO_BLOB = 1025)
598
explain extended select left(a1,7), left(a2,7)
600
where a1 in (select group_concat(b1) from t2_1025 group by b2);
602
select left(a1,7), left(a2,7)
604
where a1 in (select group_concat(b1) from t2_1025 group by b2);
606
drop table t1_1025, t2_1025, t3_1025;
608
# test for BIT fields
609
create table t1bit (a1 bit(3), a2 bit(3));
610
create table t2bit (b1 bit(3), b2 bit(3));
612
insert into t1bit values (b'000', b'100');
613
insert into t1bit values (b'001', b'101');
614
insert into t1bit values (b'010', b'110');
616
insert into t2bit values (b'001', b'101');
617
insert into t2bit values (b'010', b'110');
618
insert into t2bit values (b'110', b'111');
620
set @@optimizer_switch=no_semijoin;
622
explain extended select bin(a1), bin(a2)
624
where (a1, a2) in (select b1, b2 from t2bit);
626
select bin(a1), bin(a2)
628
where (a1, a2) in (select b1, b2 from t2bit);
630
drop table t1bit, t2bit;
632
# test mixture of BIT and BLOB
633
create table t1bb (a1 bit(3), a2 blob(3));
634
create table t2bb (b1 bit(3), b2 blob(3));
636
insert into t1bb values (b'000', '100');
637
insert into t1bb values (b'001', '101');
638
insert into t1bb values (b'010', '110');
640
insert into t2bb values (b'001', '101');
641
insert into t2bb values (b'010', '110');
642
insert into t2bb values (b'110', '111');
644
explain extended select bin(a1), a2
646
where (a1, a2) in (select b1, b2 from t2bb);
650
where (a1, a2) in (select b1, b2 from t2bb);
652
drop table t1bb, t2bb;
653
drop table t1, t2, t3, t1i, t2i, t3i, columns;
655
/******************************************************************************
656
* Test the cache of the left operand of IN.
657
******************************************************************************/
658
set @@optimizer_switch=no_semijoin;
660
# Test that default values of Cached_item are not used for comparison
661
create table t1 (s1 int);
662
create table t2 (s2 int);
663
insert into t1 values (5),(1),(0);
664
insert into t2 values (0), (1);
665
select s2 from t2 where s2 in (select s1 from t1);
668
create table t1 (a int not null, b int not null);
669
create table t2 (c int not null, d int not null);
670
create table t3 (e int not null);
672
# the first outer row has no matching inner row
673
insert into t1 values (1,10);
674
insert into t1 values (1,20);
675
insert into t1 values (2,10);
676
insert into t1 values (2,20);
677
insert into t1 values (2,30);
678
insert into t1 values (3,20);
679
insert into t1 values (4,40);
681
insert into t2 values (2,10);
682
insert into t2 values (2,20);
683
insert into t2 values (2,40);
684
insert into t2 values (3,20);
685
insert into t2 values (4,10);
686
insert into t2 values (5,10);
688
insert into t3 values (10);
689
insert into t3 values (10);
690
insert into t3 values (20);
691
insert into t3 values (30);
694
select a from t1 where a in (select c from t2 where d >= 20);
695
select a from t1 where a in (select c from t2 where d >= 20);
697
create index it1a on t1(a);
700
select a from t1 where a in (select c from t2 where d >= 20);
701
select a from t1 where a in (select c from t2 where d >= 20);
703
# the first outer row has a matching inner row
704
insert into t2 values (1,10);
707
select a from t1 where a in (select c from t2 where d >= 20);
708
select a from t1 where a in (select c from t2 where d >= 20);
710
# cacheing for IN predicates inside a having clause - here the cached
711
# items are changed to point to temporary tables.
713
select a from t1 group by a having a in (select c from t2 where d >= 20);
714
select a from t1 group by a having a in (select c from t2 where d >= 20);
716
# create an index that can be used for the outer query GROUP BY
717
create index iab on t1(a, b);
719
select a from t1 group by a having a in (select c from t2 where d >= 20);
720
select a from t1 group by a having a in (select c from t2 where d >= 20);
723
select a from t1 group by a
724
having a in (select c from t2 where d >= some(select e from t3 where max(b)=e));
725
select a from t1 group by a
726
having a in (select c from t2 where d >= some(select e from t3 where max(b)=e));
729
where a in (select c from t2 where d >= some(select e from t3 where b=e));
731
where a in (select c from t2 where d >= some(select e from t3 where b=e));
733
drop table t1, t2, t3;