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 temporary table t2 (b1 char(8), b2 char(8)) ENGINE=MyISAM;
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 temporary table t1i (a1 char(8), a2 char(8)) ENGINE=MyISAM;
31
create table t2i (b1 char(8), b2 char(8));
32
create temporary 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
--echo /********************************************************************
50
--echo * Simple tests.
51
--echo ********************************************************************/
52
--echo # non-indexed nullable fields
55
select * from t1 where a1 in (select b1 from t2 where b1 > '0');
56
select * from t1 where a1 in (select b1 from t2 where b1 > '0');
60
select * from t1 where a1 in (select b1 from t2 where b1 > '0' group by b1);
61
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);
70
select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1);
71
select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1);
76
select * from t1i where a1 in (select b1 from t2i where b1 > '0');
77
select * from t1i where a1 in (select b1 from t2i where b1 > '0');
81
select * from t1i where a1 in (select b1 from t2i where b1 > '0' group by b1);
82
select * from t1i where a1 in (select b1 from t2i where b1 > '0' group by b1);
86
select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0');
87
select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0');
91
select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0' group by b1, b2);
92
select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0' group by b1, b2);
96
select * from t1i where (a1, a2) in (select b1, min(b2) from t2i where b1 > '0' group by b1);
97
select * from t1i where (a1, a2) in (select b1, min(b2) from t2i where b1 > '0' group by b1);
99
# materialize the result of ORDER BY
103
select * from t1 where (a1, a2) in (select b1, b2 from t2 order by b1, b2);
104
select * from t1 where (a1, a2) in (select b1, b2 from t2 order by b1, b2);
108
select * from t1i where (a1, a2) in (select b1, b2 from t2i order by b1, b2);
109
select * from t1i where (a1, a2) in (select b1, b2 from t2i order by b1, b2);
111
# nested subqueries, views
115
where (a1, a2) in (select b1, b2 from t2 where b1 > '0') and
116
(a1, a2) in (select c1, c2 from t3
117
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
119
where (a1, a2) in (select b1, b2 from t2 where b1 > '0') and
120
(a1, a2) in (select c1, c2 from t3
121
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
126
where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and
127
(a1, a2) in (select c1, c2 from t3i
128
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
130
where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and
131
(a1, a2) in (select c1, c2 from t3i
132
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
137
where (a1, a2) in (select b1, b2 from t2
138
where b2 in (select c2 from t3 where c2 LIKE '%02') or
139
b2 in (select c2 from t3 where c2 LIKE '%03')) and
140
(a1, a2) in (select c1, c2 from t3
141
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
143
where (a1, a2) in (select b1, b2 from t2
144
where b2 in (select c2 from t3 where c2 LIKE '%02') or
145
b2 in (select c2 from t3 where c2 LIKE '%03')) and
146
(a1, a2) in (select c1, c2 from t3
147
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
149
# as above with correlated innermost subquery
153
where (a1, a2) in (select b1, b2 from t2
154
where b2 in (select c2 from t3 t3a where c1 = a1) or
155
b2 in (select c2 from t3 t3b where c2 LIKE '%03')) and
156
(a1, a2) in (select c1, c2 from t3 t3c
157
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
159
where (a1, a2) in (select b1, b2 from t2
160
where b2 in (select c2 from t3 t3a where c1 = a1) or
161
b2 in (select c2 from t3 t3b where c2 LIKE '%03')) and
162
(a1, a2) in (select c1, c2 from t3 t3c
163
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
166
# multiple levels of nesting subqueries, unions
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
where (a1, a2) in (select b1, b2 from t2
184
where b2 in (select c2 from t3 where c2 LIKE '%02') or
185
b2 in (select c2 from t3 where c2 LIKE '%03')
187
(a1, a2) in (select c1, c2 from t3
188
where (c1, c2) in (select b1, b2 from t2i where b2 > '0')))
191
where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and
192
(a1, a2) in (select c1, c2 from t3i
193
where (c1, c2) in (select b1, b2 from t2i where b2 > '0')));
196
# UNION of subqueries as a subquery (thus it is not computed via materialization)
200
where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and
201
(a1, a2) in (select c1, c2 from t3
202
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
204
where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and
205
(a1, a2) in (select c1, c2 from t3
206
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
207
# as above, with a join conditon between the outer references
211
where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and
212
(c1, c2) in (select c1, c2 from t3
213
where (c1, c2) in (select b1, b2 from t2i where b2 > '0')) and
216
where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and
217
(c1, c2) in (select c1, c2 from t3
218
where (c1, c2) in (select b1, b2 from t2i where b2 > '0')) and
222
--echo /*********************************************************************
223
--echo * Negative tests, where materialization should not be applied.
224
--echo **********************************************************************/
225
--echo # UNION in a subquery
229
where c1 in (select a1 from t1 where a1 > '0' UNION select b1 from t2 where b1 < '9');
231
where c1 in (select a1 from t1 where a1 > '0' UNION select b1 from t2 where b1 < '9');
237
where (a1, a2) in (select b1, b2 from t2
238
where b2 in (select c2 from t3 t3a where c1 = a1) or
239
b2 in (select c2 from t3 t3b where c2 LIKE '%03')) and
240
(a1, a2) in (select c1, c2 from t3 t3c
241
where (c1, c2) in (select b1, b2 from t2i where b2 > '0' or b2 = a2));
243
DROP TABLE t1i, t2i, t3i;
245
# subquery has no tables
248
select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01');
249
select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01');
252
/******************************************************************************
253
* Subqueries in other uncovered clauses.
254
******************************************************************************/
257
select ((a1,a2) IN (select * from t2 where b2 > '0')) IS NULL from t1;
259
/* GROUP BY clause */
260
create temporary table columns (col int key) ENGINE=MyISAM;
261
insert into columns values (1), (2);
265
select * from t1 group by (select col from columns limit 1);
266
select * from t1 group by (select col from columns limit 1);
270
select * from t1 group by (a1 in (select col from columns));
271
select * from t1 group by (a1 in (select col from columns));
273
--echo /* ORDER BY clause */
276
select * from t1 order by (select col from columns limit 1);
277
select * from t1 order by (select col from columns limit 1);
281
/******************************************************************************
282
* Column types/sizes that affect materialization.
283
******************************************************************************/
286
Test that BLOBs are not materialized (except when arguments of some functions).
288
# force materialization to be always considered
291
# BLOB == 16 (small blobs that could be stored in MEMORY tables)
293
set @suffix_len = @blob_len - @prefix_len;
295
create temporary table t1_16 (a1 blob, a2 blob) ENGINE=MyISAM;
296
create temporary table t2_16 (b1 blob, b2 blob) ENGINE=MyISAM;
297
create temporary table t3_16 (c1 blob, c2 blob) ENGINE=MyISAM;
299
insert into t1_16 values
300
(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
301
insert into t1_16 values
302
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
303
insert into t1_16 values
304
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
306
insert into t2_16 values
307
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
308
insert into t2_16 values
309
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
310
insert into t2_16 values
311
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
313
insert into t3_16 values
314
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
315
insert into t3_16 values
316
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
317
insert into t3_16 values
318
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
319
insert into t3_16 values
320
(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len)));
322
# single value transformer
323
explain extended select left(a1,7), left(a2,7)
325
where a1 in (select b1 from t2_16 where b1 > '0');
327
select left(a1,7), left(a2,7)
329
where a1 in (select b1 from t2_16 where b1 > '0');
331
# row value transformer
332
explain extended select left(a1,7), left(a2,7)
334
where (a1,a2) in (select b1, b2 from t2_16 where b1 > '0');
336
select left(a1,7), left(a2,7)
338
where (a1,a2) in (select b1, b2 from t2_16 where b1 > '0');
340
# string function with a blob argument, the return type may be != blob
341
explain extended select left(a1,7), left(a2,7)
343
where a1 in (select substring(b1,1,16) from t2_16 where b1 > '0');
345
select left(a1,7), left(a2,7)
347
where a1 in (select substring(b1,1,16) from t2_16 where b1 > '0');
349
# group_concat with a blob argument - depends on
350
# the variable group_concat_max_len, and
351
# convert_blob_length == max_len*collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB
352
explain extended select left(a1,7), left(a2,7)
354
where a1 in (select group_concat(b1) from t2_16 group by b2);
356
select left(a1,7), left(a2,7)
358
where a1 in (select group_concat(b1) from t2_16 group by b2);
360
set @@group_concat_max_len = 256; # anything < (CONVERT_IF_BIGGER_TO_BLOB = 512)
362
explain extended select left(a1,7), left(a2,7)
364
where a1 in (select group_concat(b1) from t2_16 group by b2);
366
select left(a1,7), left(a2,7)
368
where a1 in (select group_concat(b1) from t2_16 group by b2);
370
# BLOB column at the second (intermediate) level of nesting
373
where concat(a1,'x') IN
374
(select left(a1,8) from t1_16
376
(select t2_16.b1, t2_16.b2 from t2_16, t2
377
where t2.b2 = substring(t2_16.b2,1,6) and
378
t2.b1 IN (select c1 from t3 where c2 > '0')));
381
drop table t1_16, t2_16, t3_16;
384
# BLOB == 512 (CONVERT_IF_BIGGER_TO_BLOB == 512)
386
set @suffix_len = @blob_len - @prefix_len;
388
create temporary table t1_512 (a1 blob, a2 blob) ENGINE=MyISAM;
389
create temporary table t2_512 (b1 blob, b2 blob) ENGINE=MyISAM;
390
create temporary table t3_512 (c1 blob, c2 blob) ENGINE=MyISAM;
392
insert into t1_512 values
393
(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
394
insert into t1_512 values
395
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
396
insert into t1_512 values
397
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
399
insert into t2_512 values
400
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
401
insert into t2_512 values
402
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
403
insert into t2_512 values
404
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
406
insert into t3_512 values
407
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
408
insert into t3_512 values
409
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
410
insert into t3_512 values
411
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
412
insert into t3_512 values
413
(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len)));
415
# single value transformer
416
explain extended select left(a1,7), left(a2,7)
418
where a1 in (select b1 from t2_512 where b1 > '0');
420
select left(a1,7), left(a2,7)
422
where a1 in (select b1 from t2_512 where b1 > '0');
424
# row value transformer
425
explain extended select left(a1,7), left(a2,7)
427
where (a1,a2) in (select b1, b2 from t2_512 where b1 > '0');
429
select left(a1,7), left(a2,7)
431
where (a1,a2) in (select b1, b2 from t2_512 where b1 > '0');
433
# string function with a blob argument, the return type may be != blob
434
explain extended select left(a1,7), left(a2,7)
436
where a1 in (select substring(b1,1,512) from t2_512 where b1 > '0');
438
select left(a1,7), left(a2,7)
440
where a1 in (select substring(b1,1,512) from t2_512 where b1 > '0');
442
# group_concat with a blob argument - depends on
443
# the variable group_concat_max_len, and
444
# convert_blob_length == max_len*collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB
445
explain extended select left(a1,7), left(a2,7)
447
where a1 in (select group_concat(b1) from t2_512 group by b2);
449
select left(a1,7), left(a2,7)
451
where a1 in (select group_concat(b1) from t2_512 group by b2);
453
set @@group_concat_max_len = 256; # anything < (CONVERT_IF_BIGGER_TO_BLOB = 512)
455
explain extended select left(a1,7), left(a2,7)
457
where a1 in (select group_concat(b1) from t2_512 group by b2);
459
select left(a1,7), left(a2,7)
461
where a1 in (select group_concat(b1) from t2_512 group by b2);
463
drop table t1_512, t2_512, t3_512;
466
# BLOB == 1024 (group_concat_max_len == 1024)
467
set @blob_len = 1024;
468
set @suffix_len = @blob_len - @prefix_len;
470
create temporary table t1_1024 (a1 blob, a2 blob) ENGINE=MyISAM;
471
create temporary table t2_1024 (b1 blob, b2 blob) ENGINE=MyISAM;
472
create temporary table t3_1024 (c1 blob, c2 blob) ENGINE=MyISAM;
474
insert into t1_1024 values
475
(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
476
insert into t1_1024 values
477
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
478
insert into t1_1024 values
479
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
481
insert into t2_1024 values
482
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
483
insert into t2_1024 values
484
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
485
insert into t2_1024 values
486
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
488
insert into t3_1024 values
489
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
490
insert into t3_1024 values
491
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
492
insert into t3_1024 values
493
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
494
insert into t3_1024 values
495
(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len)));
497
# single value transformer
498
explain extended select left(a1,7), left(a2,7)
500
where a1 in (select b1 from t2_1024 where b1 > '0');
502
select left(a1,7), left(a2,7)
504
where a1 in (select b1 from t2_1024 where b1 > '0');
506
# row value transformer
507
explain extended select left(a1,7), left(a2,7)
509
where (a1,a2) in (select b1, b2 from t2_1024 where b1 > '0');
511
select left(a1,7), left(a2,7)
513
where (a1,a2) in (select b1, b2 from t2_1024 where b1 > '0');
515
# string function with a blob argument, the return type may be != blob
516
explain extended select left(a1,7), left(a2,7)
518
where a1 in (select substring(b1,1,1024) from t2_1024 where b1 > '0');
520
select left(a1,7), left(a2,7)
522
where a1 in (select substring(b1,1,1024) from t2_1024 where b1 > '0');
524
# group_concat with a blob argument - depends on
525
# the variable group_concat_max_len, and
526
# convert_blob_length == max_len*collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB
527
explain extended select left(a1,7), left(a2,7)
529
where a1 in (select group_concat(b1) from t2_1024 group by b2);
531
select left(a1,7), left(a2,7)
533
where a1 in (select group_concat(b1) from t2_1024 group by b2);
535
set @@group_concat_max_len = 256; # anything < (CONVERT_IF_BIGGER_TO_BLOB = 1024)
537
explain extended select left(a1,7), left(a2,7)
539
where a1 in (select group_concat(b1) from t2_1024 group by b2);
541
select left(a1,7), left(a2,7)
543
where a1 in (select group_concat(b1) from t2_1024 group by b2);
545
drop table t1_1024, t2_1024, t3_1024;
549
set @blob_len = 1025;
550
set @suffix_len = @blob_len - @prefix_len;
552
create temporary table t1_1025 (a1 blob, a2 blob) ENGINE=MyISAM;
553
create temporary table t2_1025 (b1 blob, b2 blob) ENGINE=MyISAM;
554
create temporary table t3_1025 (c1 blob, c2 blob) ENGINE=MyISAM;
556
insert into t1_1025 values
557
(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
558
insert into t1_1025 values
559
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
560
insert into t1_1025 values
561
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
563
insert into t2_1025 values
564
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
565
insert into t2_1025 values
566
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
567
insert into t2_1025 values
568
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
570
insert into t3_1025 values
571
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
572
insert into t3_1025 values
573
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
574
insert into t3_1025 values
575
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
576
insert into t3_1025 values
577
(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len)));
579
# single value transformer
580
explain extended select left(a1,7), left(a2,7)
582
where a1 in (select b1 from t2_1025 where b1 > '0');
584
select left(a1,7), left(a2,7)
586
where a1 in (select b1 from t2_1025 where b1 > '0');
588
# row value transformer
589
explain extended select left(a1,7), left(a2,7)
591
where (a1,a2) in (select b1, b2 from t2_1025 where b1 > '0');
593
select left(a1,7), left(a2,7)
595
where (a1,a2) in (select b1, b2 from t2_1025 where b1 > '0');
597
# string function with a blob argument, the return type may be != blob
598
explain extended select left(a1,7), left(a2,7)
600
where a1 in (select substring(b1,1,1025) from t2_1025 where b1 > '0');
602
select left(a1,7), left(a2,7)
604
where a1 in (select substring(b1,1,1025) from t2_1025 where b1 > '0');
606
# group_concat with a blob argument - depends on
607
# the variable group_concat_max_len, and
608
# convert_blob_length == max_len*collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB
609
explain extended select left(a1,7), left(a2,7)
611
where a1 in (select group_concat(b1) from t2_1025 group by b2);
613
select left(a1,7), left(a2,7)
615
where a1 in (select group_concat(b1) from t2_1025 group by b2);
617
set @@group_concat_max_len = 256; # anything < (CONVERT_IF_BIGGER_TO_BLOB = 1025)
619
explain extended select left(a1,7), left(a2,7)
621
where a1 in (select group_concat(b1) from t2_1025 group by b2);
623
select left(a1,7), left(a2,7)
625
where a1 in (select group_concat(b1) from t2_1025 group by b2);
627
drop table t1_1025, t2_1025, t3_1025;
628
drop table t1, t2, t3;
630
/******************************************************************************
631
* Test the cache of the left operand of IN.
632
******************************************************************************/
633
# Test that default values of Cached_item are not used for comparison
634
create temporary table t1 (s1 int) ENGINE=MyISAM;
635
create temporary table t2 (s2 int) ENGINE=MyISAM;
636
insert into t1 values (5),(1),(0);
637
insert into t2 values (0), (1);
638
select s2 from t2 where s2 in (select s1 from t1);
641
create temporary table t1 (a int not null, b int not null) ENGINE=MyISAM;
642
create temporary table t2 (c int not null, d int not null) ENGINE=MyISAM;
643
create temporary table t3 (e int not null) ENGINE=MyISAM;
645
# the first outer row has no matching inner row
646
insert into t1 values (1,10);
647
insert into t1 values (1,20);
648
insert into t1 values (2,10);
649
insert into t1 values (2,20);
650
insert into t1 values (2,30);
651
insert into t1 values (3,20);
652
insert into t1 values (4,40);
654
insert into t2 values (2,10);
655
insert into t2 values (2,20);
656
insert into t2 values (2,40);
657
insert into t2 values (3,20);
658
insert into t2 values (4,10);
659
insert into t2 values (5,10);
661
insert into t3 values (10);
662
insert into t3 values (10);
663
insert into t3 values (20);
664
insert into t3 values (30);
667
select a from t1 where a in (select c from t2 where d >= 20);
668
select a from t1 where a in (select c from t2 where d >= 20);
670
create index it1a on t1(a);
673
select a from t1 where a in (select c from t2 where d >= 20);
674
select a from t1 where a in (select c from t2 where d >= 20);
676
# the first outer row has a matching inner row
677
insert into t2 values (1,10);
680
select a from t1 where a in (select c from t2 where d >= 20);
681
select a from t1 where a in (select c from t2 where d >= 20);
683
# cacheing for IN predicates inside a having clause - here the cached
684
# items are changed to point to temporary tables.
686
select a from t1 group by a having a in (select c from t2 where d >= 20);
687
select a from t1 group by a having a in (select c from t2 where d >= 20);
689
# create an index that can be used for the outer query GROUP BY
690
create index iab on t1(a, b);
692
select a from t1 group by a having a in (select c from t2 where d >= 20);
693
select a from t1 group by a having a in (select c from t2 where d >= 20);
696
select a from t1 group by a
697
having a in (select c from t2 where d >= some(select e from t3 where max(b)=e));
698
select a from t1 group by a
699
having a in (select c from t2 where d >= some(select e from t3 where max(b)=e));
702
where a in (select c from t2 where d >= some(select e from t3 where b=e));
704
where a in (select c from t2 where d >= some(select e from t3 where b=e));
706
drop table t1, t2, t3;