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)) ENGINE=MyISAM;
11
create table t2 (b1 char(8), b2 char(8)) ENGINE=MyISAM;
12
create table t3 (c1 char(8), c2 char(8)) ENGINE=MyISAM;
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)) ENGINE=MyISAM;
31
create table t2i (b1 char(8), b2 char(8)) ENGINE=MyISAM;
32
create table t3i (c1 char(8), c2 char(8)) ENGINE=MyISAM;
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');
232
/******************************************************************************
233
* Subqueries in other uncovered clauses.
234
******************************************************************************/
237
select ((a1,a2) IN (select * from t2 where b2 > '0')) IS NULL from t1;
239
/* GROUP BY clause */
240
create table columns (col int key) ENGINE=MyISAM;
241
insert into columns values (1), (2);
244
select * from t1 group by (select col from columns limit 1);
245
select * from t1 group by (select col from columns limit 1);
248
select * from t1 group by (a1 in (select col from columns));
249
select * from t1 group by (a1 in (select col from columns));
251
/* ORDER BY clause */
253
select * from t1 order by (select col from columns limit 1);
254
select * from t1 order by (select col from columns limit 1);
256
/******************************************************************************
257
* Column types/sizes that affect materialization.
258
******************************************************************************/
261
Test that BLOBs are not materialized (except when arguments of some functions).
263
# force materialization to be always considered
264
set @@optimizer_switch=no_semijoin;
267
# BLOB == 16 (small blobs that could be stored in HEAP tables)
269
set @suffix_len = @blob_len - @prefix_len;
271
create table t1_16 (a1 blob, a2 blob) ENGINE=MyISAM;
272
create table t2_16 (b1 blob, b2 blob) ENGINE=MyISAM;
273
create table t3_16 (c1 blob, c2 blob) ENGINE=MyISAM;
275
insert into t1_16 values
276
(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
277
insert into t1_16 values
278
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
279
insert into t1_16 values
280
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
282
insert into t2_16 values
283
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
284
insert into t2_16 values
285
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
286
insert into t2_16 values
287
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
289
insert into t3_16 values
290
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
291
insert into t3_16 values
292
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
293
insert into t3_16 values
294
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
295
insert into t3_16 values
296
(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len)));
298
# single value transformer
299
explain extended select left(a1,7), left(a2,7)
301
where a1 in (select b1 from t2_16 where b1 > '0');
303
select left(a1,7), left(a2,7)
305
where a1 in (select b1 from t2_16 where b1 > '0');
307
# row value transformer
308
explain extended select left(a1,7), left(a2,7)
310
where (a1,a2) in (select b1, b2 from t2_16 where b1 > '0');
312
select left(a1,7), left(a2,7)
314
where (a1,a2) in (select b1, b2 from t2_16 where b1 > '0');
316
# string function with a blob argument, the return type may be != blob
317
explain extended select left(a1,7), left(a2,7)
319
where a1 in (select substring(b1,1,16) from t2_16 where b1 > '0');
321
select left(a1,7), left(a2,7)
323
where a1 in (select substring(b1,1,16) from t2_16 where b1 > '0');
325
# group_concat with a blob argument - depends on
326
# the variable group_concat_max_len, and
327
# convert_blob_length == max_len*collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB
328
explain extended select left(a1,7), left(a2,7)
330
where a1 in (select group_concat(b1) from t2_16 group by b2);
332
select left(a1,7), left(a2,7)
334
where a1 in (select group_concat(b1) from t2_16 group by b2);
336
set @@group_concat_max_len = 256; # anything < (CONVERT_IF_BIGGER_TO_BLOB = 512)
338
explain extended select left(a1,7), left(a2,7)
340
where a1 in (select group_concat(b1) from t2_16 group by b2);
342
select left(a1,7), left(a2,7)
344
where a1 in (select group_concat(b1) from t2_16 group by b2);
346
# BLOB column at the second (intermediate) level of nesting
349
where concat(a1,'x') IN
350
(select left(a1,8) from t1_16
352
(select t2_16.b1, t2_16.b2 from t2_16, t2
353
where t2.b2 = substring(t2_16.b2,1,6) and
354
t2.b1 IN (select c1 from t3 where c2 > '0')));
357
drop table t1_16, t2_16, t3_16;
360
# BLOB == 512 (CONVERT_IF_BIGGER_TO_BLOB == 512)
362
set @suffix_len = @blob_len - @prefix_len;
364
create table t1_512 (a1 blob, a2 blob) ENGINE=MyISAM;
365
create table t2_512 (b1 blob, b2 blob) ENGINE=MyISAM;
366
create table t3_512 (c1 blob, c2 blob) ENGINE=MyISAM;
368
insert into t1_512 values
369
(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
370
insert into t1_512 values
371
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
372
insert into t1_512 values
373
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
375
insert into t2_512 values
376
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
377
insert into t2_512 values
378
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
379
insert into t2_512 values
380
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
382
insert into t3_512 values
383
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
384
insert into t3_512 values
385
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
386
insert into t3_512 values
387
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
388
insert into t3_512 values
389
(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len)));
391
# single value transformer
392
explain extended select left(a1,7), left(a2,7)
394
where a1 in (select b1 from t2_512 where b1 > '0');
396
select left(a1,7), left(a2,7)
398
where a1 in (select b1 from t2_512 where b1 > '0');
400
# row value transformer
401
explain extended select left(a1,7), left(a2,7)
403
where (a1,a2) in (select b1, b2 from t2_512 where b1 > '0');
405
select left(a1,7), left(a2,7)
407
where (a1,a2) in (select b1, b2 from t2_512 where b1 > '0');
409
# string function with a blob argument, the return type may be != blob
410
explain extended select left(a1,7), left(a2,7)
412
where a1 in (select substring(b1,1,512) from t2_512 where b1 > '0');
414
select left(a1,7), left(a2,7)
416
where a1 in (select substring(b1,1,512) from t2_512 where b1 > '0');
418
# group_concat with a blob argument - depends on
419
# the variable group_concat_max_len, and
420
# convert_blob_length == max_len*collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB
421
explain extended select left(a1,7), left(a2,7)
423
where a1 in (select group_concat(b1) from t2_512 group by b2);
425
select left(a1,7), left(a2,7)
427
where a1 in (select group_concat(b1) from t2_512 group by b2);
429
set @@group_concat_max_len = 256; # anything < (CONVERT_IF_BIGGER_TO_BLOB = 512)
431
explain extended select left(a1,7), left(a2,7)
433
where a1 in (select group_concat(b1) from t2_512 group by b2);
435
select left(a1,7), left(a2,7)
437
where a1 in (select group_concat(b1) from t2_512 group by b2);
439
drop table t1_512, t2_512, t3_512;
442
# BLOB == 1024 (group_concat_max_len == 1024)
443
set @blob_len = 1024;
444
set @suffix_len = @blob_len - @prefix_len;
446
create table t1_1024 (a1 blob, a2 blob) ENGINE=MyISAM;
447
create table t2_1024 (b1 blob, b2 blob) ENGINE=MyISAM;
448
create table t3_1024 (c1 blob, c2 blob) ENGINE=MyISAM;
450
insert into t1_1024 values
451
(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
452
insert into t1_1024 values
453
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
454
insert into t1_1024 values
455
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
457
insert into t2_1024 values
458
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
459
insert into t2_1024 values
460
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
461
insert into t2_1024 values
462
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
464
insert into t3_1024 values
465
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
466
insert into t3_1024 values
467
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
468
insert into t3_1024 values
469
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
470
insert into t3_1024 values
471
(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len)));
473
# single value transformer
474
explain extended select left(a1,7), left(a2,7)
476
where a1 in (select b1 from t2_1024 where b1 > '0');
478
select left(a1,7), left(a2,7)
480
where a1 in (select b1 from t2_1024 where b1 > '0');
482
# row value transformer
483
explain extended select left(a1,7), left(a2,7)
485
where (a1,a2) in (select b1, b2 from t2_1024 where b1 > '0');
487
select left(a1,7), left(a2,7)
489
where (a1,a2) in (select b1, b2 from t2_1024 where b1 > '0');
491
# string function with a blob argument, the return type may be != blob
492
explain extended select left(a1,7), left(a2,7)
494
where a1 in (select substring(b1,1,1024) from t2_1024 where b1 > '0');
496
select left(a1,7), left(a2,7)
498
where a1 in (select substring(b1,1,1024) from t2_1024 where b1 > '0');
500
# group_concat with a blob argument - depends on
501
# the variable group_concat_max_len, and
502
# convert_blob_length == max_len*collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB
503
explain extended select left(a1,7), left(a2,7)
505
where a1 in (select group_concat(b1) from t2_1024 group by b2);
507
select left(a1,7), left(a2,7)
509
where a1 in (select group_concat(b1) from t2_1024 group by b2);
511
set @@group_concat_max_len = 256; # anything < (CONVERT_IF_BIGGER_TO_BLOB = 1024)
513
explain extended select left(a1,7), left(a2,7)
515
where a1 in (select group_concat(b1) from t2_1024 group by b2);
517
select left(a1,7), left(a2,7)
519
where a1 in (select group_concat(b1) from t2_1024 group by b2);
521
drop table t1_1024, t2_1024, t3_1024;
525
set @blob_len = 1025;
526
set @suffix_len = @blob_len - @prefix_len;
528
create table t1_1025 (a1 blob, a2 blob) ENGINE=MyISAM;
529
create table t2_1025 (b1 blob, b2 blob) ENGINE=MyISAM;
530
create table t3_1025 (c1 blob, c2 blob) ENGINE=MyISAM;
532
insert into t1_1025 values
533
(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
534
insert into t1_1025 values
535
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
536
insert into t1_1025 values
537
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
539
insert into t2_1025 values
540
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
541
insert into t2_1025 values
542
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
543
insert into t2_1025 values
544
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
546
insert into t3_1025 values
547
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
548
insert into t3_1025 values
549
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
550
insert into t3_1025 values
551
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
552
insert into t3_1025 values
553
(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len)));
555
# single value transformer
556
explain extended select left(a1,7), left(a2,7)
558
where a1 in (select b1 from t2_1025 where b1 > '0');
560
select left(a1,7), left(a2,7)
562
where a1 in (select b1 from t2_1025 where b1 > '0');
564
# row value transformer
565
explain extended select left(a1,7), left(a2,7)
567
where (a1,a2) in (select b1, b2 from t2_1025 where b1 > '0');
569
select left(a1,7), left(a2,7)
571
where (a1,a2) in (select b1, b2 from t2_1025 where b1 > '0');
573
# string function with a blob argument, the return type may be != blob
574
explain extended select left(a1,7), left(a2,7)
576
where a1 in (select substring(b1,1,1025) from t2_1025 where b1 > '0');
578
select left(a1,7), left(a2,7)
580
where a1 in (select substring(b1,1,1025) from t2_1025 where b1 > '0');
582
# group_concat with a blob argument - depends on
583
# the variable group_concat_max_len, and
584
# convert_blob_length == max_len*collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB
585
explain extended select left(a1,7), left(a2,7)
587
where a1 in (select group_concat(b1) from t2_1025 group by b2);
589
select left(a1,7), left(a2,7)
591
where a1 in (select group_concat(b1) from t2_1025 group by b2);
593
set @@group_concat_max_len = 256; # anything < (CONVERT_IF_BIGGER_TO_BLOB = 1025)
595
explain extended select left(a1,7), left(a2,7)
597
where a1 in (select group_concat(b1) from t2_1025 group by b2);
599
select left(a1,7), left(a2,7)
601
where a1 in (select group_concat(b1) from t2_1025 group by b2);
603
drop table t1_1025, t2_1025, t3_1025;
604
drop table t1, t2, t3;
606
/******************************************************************************
607
* Test the cache of the left operand of IN.
608
******************************************************************************/
609
set @@optimizer_switch=no_semijoin;
611
# Test that default values of Cached_item are not used for comparison
612
create table t1 (s1 int) ENGINE=MyISAM;
613
create table t2 (s2 int) ENGINE=MyISAM;
614
insert into t1 values (5),(1),(0);
615
insert into t2 values (0), (1);
616
select s2 from t2 where s2 in (select s1 from t1);
619
create table t1 (a int not null, b int not null) ENGINE=MyISAM;
620
create table t2 (c int not null, d int not null) ENGINE=MyISAM;
621
create table t3 (e int not null) ENGINE=MyISAM;
623
# the first outer row has no matching inner row
624
insert into t1 values (1,10);
625
insert into t1 values (1,20);
626
insert into t1 values (2,10);
627
insert into t1 values (2,20);
628
insert into t1 values (2,30);
629
insert into t1 values (3,20);
630
insert into t1 values (4,40);
632
insert into t2 values (2,10);
633
insert into t2 values (2,20);
634
insert into t2 values (2,40);
635
insert into t2 values (3,20);
636
insert into t2 values (4,10);
637
insert into t2 values (5,10);
639
insert into t3 values (10);
640
insert into t3 values (10);
641
insert into t3 values (20);
642
insert into t3 values (30);
645
select a from t1 where a in (select c from t2 where d >= 20);
646
select a from t1 where a in (select c from t2 where d >= 20);
648
create index it1a on t1(a);
651
select a from t1 where a in (select c from t2 where d >= 20);
652
select a from t1 where a in (select c from t2 where d >= 20);
654
# the first outer row has a matching inner row
655
insert into t2 values (1,10);
658
select a from t1 where a in (select c from t2 where d >= 20);
659
select a from t1 where a in (select c from t2 where d >= 20);
661
# cacheing for IN predicates inside a having clause - here the cached
662
# items are changed to point to temporary tables.
664
select a from t1 group by a having a in (select c from t2 where d >= 20);
665
select a from t1 group by a having a in (select c from t2 where d >= 20);
667
# create an index that can be used for the outer query GROUP BY
668
create index iab on t1(a, b);
670
select a from t1 group by a having a in (select c from t2 where d >= 20);
671
select a from t1 group by a having a in (select c from t2 where d >= 20);
674
select a from t1 group by a
675
having a in (select c from t2 where d >= some(select e from t3 where max(b)=e));
676
select a from t1 group by a
677
having a in (select c from t2 where d >= some(select e from t3 where max(b)=e));
680
where a in (select c from t2 where d >= some(select e from t3 where b=e));
682
where a in (select c from t2 where d >= some(select e from t3 where b=e));
684
drop table t1, t2, t3;