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
# force the use of materialization
50
set @@optimizer_switch=no_semijoin;
52
--echo /********************************************************************
53
--echo * Simple tests.
54
--echo ********************************************************************/
55
--echo # non-indexed nullable fields
58
select * from t1 where a1 in (select b1 from t2 where b1 > '0');
59
select * from t1 where a1 in (select b1 from t2 where b1 > '0');
63
select * from t1 where a1 in (select b1 from t2 where b1 > '0' group by b1);
64
select * from t1 where a1 in (select b1 from t2 where b1 > '0' group by b1);
68
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, b2 from t2 where b1 > '0' group by b1, b2);
73
select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1);
74
select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1);
79
select * from t1i where a1 in (select b1 from t2i where b1 > '0');
80
select * from t1i where a1 in (select b1 from t2i where b1 > '0');
84
select * from t1i where a1 in (select b1 from t2i where b1 > '0' group by b1);
85
select * from t1i where a1 in (select b1 from t2i where b1 > '0' group by b1);
89
select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0');
90
select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0');
94
select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0' group by b1, b2);
95
select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0' group by b1, b2);
99
select * from t1i where (a1, a2) in (select b1, min(b2) from t2i where b1 > '0' group by b1);
100
select * from t1i where (a1, a2) in (select b1, min(b2) from t2i where b1 > '0' group by b1);
102
# materialize the result of ORDER BY
106
select * from t1 where (a1, a2) in (select b1, b2 from t2 order by b1, b2);
107
select * from t1 where (a1, a2) in (select b1, b2 from t2 order by b1, b2);
111
select * from t1i where (a1, a2) in (select b1, b2 from t2i order by b1, b2);
112
select * from t1i where (a1, a2) in (select b1, b2 from t2i order by b1, b2);
114
# nested subqueries, views
118
where (a1, a2) in (select b1, b2 from t2 where b1 > '0') and
119
(a1, a2) in (select c1, c2 from t3
120
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
122
where (a1, a2) in (select b1, b2 from t2 where b1 > '0') and
123
(a1, a2) in (select c1, c2 from t3
124
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
129
where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and
130
(a1, a2) in (select c1, c2 from t3i
131
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
133
where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and
134
(a1, a2) in (select c1, c2 from t3i
135
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
140
where (a1, a2) in (select b1, b2 from t2
141
where b2 in (select c2 from t3 where c2 LIKE '%02') or
142
b2 in (select c2 from t3 where c2 LIKE '%03')) and
143
(a1, a2) in (select c1, c2 from t3
144
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
146
where (a1, a2) in (select b1, b2 from t2
147
where b2 in (select c2 from t3 where c2 LIKE '%02') or
148
b2 in (select c2 from t3 where c2 LIKE '%03')) and
149
(a1, a2) in (select c1, c2 from t3
150
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
152
# as above with correlated innermost subquery
156
where (a1, a2) in (select b1, b2 from t2
157
where b2 in (select c2 from t3 t3a where c1 = a1) or
158
b2 in (select c2 from t3 t3b where c2 LIKE '%03')) and
159
(a1, a2) in (select c1, c2 from t3 t3c
160
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
162
where (a1, a2) in (select b1, b2 from t2
163
where b2 in (select c2 from t3 t3a where c1 = a1) or
164
b2 in (select c2 from t3 t3b where c2 LIKE '%03')) and
165
(a1, a2) in (select c1, c2 from t3 t3c
166
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
169
# multiple levels of nesting subqueries, unions
173
where (a1, a2) in (select b1, b2 from t2
174
where b2 in (select c2 from t3 where c2 LIKE '%02') or
175
b2 in (select c2 from t3 where c2 LIKE '%03')
177
(a1, a2) in (select c1, c2 from t3
178
where (c1, c2) in (select b1, b2 from t2i where b2 > '0')))
181
where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and
182
(a1, a2) in (select c1, c2 from t3i
183
where (c1, c2) in (select b1, b2 from t2i where b2 > '0')));
186
where (a1, a2) in (select b1, b2 from t2
187
where b2 in (select c2 from t3 where c2 LIKE '%02') or
188
b2 in (select c2 from t3 where c2 LIKE '%03')
190
(a1, a2) in (select c1, c2 from t3
191
where (c1, c2) in (select b1, b2 from t2i where b2 > '0')))
194
where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and
195
(a1, a2) in (select c1, c2 from t3i
196
where (c1, c2) in (select b1, b2 from t2i where b2 > '0')));
199
# UNION of subqueries as a subquery (thus it is not computed via materialization)
203
where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and
204
(a1, a2) in (select c1, c2 from t3
205
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
207
where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and
208
(a1, a2) in (select c1, c2 from t3
209
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
210
# as above, with a join conditon between the outer references
214
where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and
215
(c1, c2) in (select c1, c2 from t3
216
where (c1, c2) in (select b1, b2 from t2i where b2 > '0')) and
219
where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and
220
(c1, c2) in (select c1, c2 from t3
221
where (c1, c2) in (select b1, b2 from t2i where b2 > '0')) and
225
--echo /*********************************************************************
226
--echo * Negative tests, where materialization should not be applied.
227
--echo **********************************************************************/
228
--echo # UNION in a subquery
232
where c1 in (select a1 from t1 where a1 > '0' UNION select b1 from t2 where b1 < '9');
234
where c1 in (select a1 from t1 where a1 > '0' UNION select b1 from t2 where b1 < '9');
240
where (a1, a2) in (select b1, b2 from t2
241
where b2 in (select c2 from t3 t3a where c1 = a1) or
242
b2 in (select c2 from t3 t3b where c2 LIKE '%03')) and
243
(a1, a2) in (select c1, c2 from t3 t3c
244
where (c1, c2) in (select b1, b2 from t2i where b2 > '0' or b2 = a2));
246
DROP TABLE t1i, t2i, t3i;
248
# subquery has no tables
251
select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01');
252
select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01');
255
/******************************************************************************
256
* Subqueries in other uncovered clauses.
257
******************************************************************************/
260
select ((a1,a2) IN (select * from t2 where b2 > '0')) IS NULL from t1;
262
/* GROUP BY clause */
263
create temporary table columns (col int key) ENGINE=MyISAM;
264
insert into columns values (1), (2);
268
select * from t1 group by (select col from columns limit 1);
269
select * from t1 group by (select col from columns limit 1);
273
select * from t1 group by (a1 in (select col from columns));
274
select * from t1 group by (a1 in (select col from columns));
276
--echo /* ORDER BY clause */
279
select * from t1 order by (select col from columns limit 1);
280
select * from t1 order by (select col from columns limit 1);
284
/******************************************************************************
285
* Column types/sizes that affect materialization.
286
******************************************************************************/
289
Test that BLOBs are not materialized (except when arguments of some functions).
291
# force materialization to be always considered
292
set @@optimizer_switch=no_semijoin;
295
# BLOB == 16 (small blobs that could be stored in MEMORY tables)
297
set @suffix_len = @blob_len - @prefix_len;
299
create temporary table t1_16 (a1 blob, a2 blob) ENGINE=MyISAM;
300
create temporary table t2_16 (b1 blob, b2 blob) ENGINE=MyISAM;
301
create temporary table t3_16 (c1 blob, c2 blob) ENGINE=MyISAM;
303
insert into t1_16 values
304
(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
305
insert into t1_16 values
306
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
307
insert into t1_16 values
308
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
310
insert into t2_16 values
311
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
312
insert into t2_16 values
313
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
314
insert into t2_16 values
315
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
317
insert into t3_16 values
318
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
319
insert into t3_16 values
320
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
321
insert into t3_16 values
322
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
323
insert into t3_16 values
324
(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len)));
326
# single value transformer
327
explain extended select left(a1,7), left(a2,7)
329
where a1 in (select b1 from t2_16 where b1 > '0');
331
select left(a1,7), left(a2,7)
333
where a1 in (select b1 from t2_16 where b1 > '0');
335
# row value transformer
336
explain extended select left(a1,7), left(a2,7)
338
where (a1,a2) in (select b1, b2 from t2_16 where b1 > '0');
340
select left(a1,7), left(a2,7)
342
where (a1,a2) in (select b1, b2 from t2_16 where b1 > '0');
344
# string function with a blob argument, the return type may be != blob
345
explain extended select left(a1,7), left(a2,7)
347
where a1 in (select substring(b1,1,16) from t2_16 where b1 > '0');
349
select left(a1,7), left(a2,7)
351
where a1 in (select substring(b1,1,16) from t2_16 where b1 > '0');
353
# group_concat with a blob argument - depends on
354
# the variable group_concat_max_len, and
355
# convert_blob_length == max_len*collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB
356
explain extended select left(a1,7), left(a2,7)
358
where a1 in (select group_concat(b1) from t2_16 group by b2);
360
select left(a1,7), left(a2,7)
362
where a1 in (select group_concat(b1) from t2_16 group by b2);
364
set @@group_concat_max_len = 256; # anything < (CONVERT_IF_BIGGER_TO_BLOB = 512)
366
explain extended select left(a1,7), left(a2,7)
368
where a1 in (select group_concat(b1) from t2_16 group by b2);
370
select left(a1,7), left(a2,7)
372
where a1 in (select group_concat(b1) from t2_16 group by b2);
374
# BLOB column at the second (intermediate) level of nesting
377
where concat(a1,'x') IN
378
(select left(a1,8) from t1_16
380
(select t2_16.b1, t2_16.b2 from t2_16, t2
381
where t2.b2 = substring(t2_16.b2,1,6) and
382
t2.b1 IN (select c1 from t3 where c2 > '0')));
385
drop table t1_16, t2_16, t3_16;
388
# BLOB == 512 (CONVERT_IF_BIGGER_TO_BLOB == 512)
390
set @suffix_len = @blob_len - @prefix_len;
392
create temporary table t1_512 (a1 blob, a2 blob) ENGINE=MyISAM;
393
create temporary table t2_512 (b1 blob, b2 blob) ENGINE=MyISAM;
394
create temporary table t3_512 (c1 blob, c2 blob) ENGINE=MyISAM;
396
insert into t1_512 values
397
(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
398
insert into t1_512 values
399
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
400
insert into t1_512 values
401
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
403
insert into t2_512 values
404
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
405
insert into t2_512 values
406
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
407
insert into t2_512 values
408
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
410
insert into t3_512 values
411
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
412
insert into t3_512 values
413
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
414
insert into t3_512 values
415
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
416
insert into t3_512 values
417
(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len)));
419
# single value transformer
420
explain extended select left(a1,7), left(a2,7)
422
where a1 in (select b1 from t2_512 where b1 > '0');
424
select left(a1,7), left(a2,7)
426
where a1 in (select b1 from t2_512 where b1 > '0');
428
# row value transformer
429
explain extended select left(a1,7), left(a2,7)
431
where (a1,a2) in (select b1, b2 from t2_512 where b1 > '0');
433
select left(a1,7), left(a2,7)
435
where (a1,a2) in (select b1, b2 from t2_512 where b1 > '0');
437
# string function with a blob argument, the return type may be != blob
438
explain extended select left(a1,7), left(a2,7)
440
where a1 in (select substring(b1,1,512) from t2_512 where b1 > '0');
442
select left(a1,7), left(a2,7)
444
where a1 in (select substring(b1,1,512) from t2_512 where b1 > '0');
446
# group_concat with a blob argument - depends on
447
# the variable group_concat_max_len, and
448
# convert_blob_length == max_len*collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB
449
explain extended select left(a1,7), left(a2,7)
451
where a1 in (select group_concat(b1) from t2_512 group by b2);
453
select left(a1,7), left(a2,7)
455
where a1 in (select group_concat(b1) from t2_512 group by b2);
457
set @@group_concat_max_len = 256; # anything < (CONVERT_IF_BIGGER_TO_BLOB = 512)
459
explain extended select left(a1,7), left(a2,7)
461
where a1 in (select group_concat(b1) from t2_512 group by b2);
463
select left(a1,7), left(a2,7)
465
where a1 in (select group_concat(b1) from t2_512 group by b2);
467
drop table t1_512, t2_512, t3_512;
470
# BLOB == 1024 (group_concat_max_len == 1024)
471
set @blob_len = 1024;
472
set @suffix_len = @blob_len - @prefix_len;
474
create temporary table t1_1024 (a1 blob, a2 blob) ENGINE=MyISAM;
475
create temporary table t2_1024 (b1 blob, b2 blob) ENGINE=MyISAM;
476
create temporary table t3_1024 (c1 blob, c2 blob) ENGINE=MyISAM;
478
insert into t1_1024 values
479
(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
480
insert into t1_1024 values
481
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
482
insert into t1_1024 values
483
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
485
insert into t2_1024 values
486
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
487
insert into t2_1024 values
488
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
489
insert into t2_1024 values
490
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
492
insert into t3_1024 values
493
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
494
insert into t3_1024 values
495
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
496
insert into t3_1024 values
497
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
498
insert into t3_1024 values
499
(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len)));
501
# single value transformer
502
explain extended select left(a1,7), left(a2,7)
504
where a1 in (select b1 from t2_1024 where b1 > '0');
506
select left(a1,7), left(a2,7)
508
where a1 in (select b1 from t2_1024 where b1 > '0');
510
# row value transformer
511
explain extended select left(a1,7), left(a2,7)
513
where (a1,a2) in (select b1, b2 from t2_1024 where b1 > '0');
515
select left(a1,7), left(a2,7)
517
where (a1,a2) in (select b1, b2 from t2_1024 where b1 > '0');
519
# string function with a blob argument, the return type may be != blob
520
explain extended select left(a1,7), left(a2,7)
522
where a1 in (select substring(b1,1,1024) from t2_1024 where b1 > '0');
524
select left(a1,7), left(a2,7)
526
where a1 in (select substring(b1,1,1024) from t2_1024 where b1 > '0');
528
# group_concat with a blob argument - depends on
529
# the variable group_concat_max_len, and
530
# convert_blob_length == max_len*collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB
531
explain extended select left(a1,7), left(a2,7)
533
where a1 in (select group_concat(b1) from t2_1024 group by b2);
535
select left(a1,7), left(a2,7)
537
where a1 in (select group_concat(b1) from t2_1024 group by b2);
539
set @@group_concat_max_len = 256; # anything < (CONVERT_IF_BIGGER_TO_BLOB = 1024)
541
explain extended select left(a1,7), left(a2,7)
543
where a1 in (select group_concat(b1) from t2_1024 group by b2);
545
select left(a1,7), left(a2,7)
547
where a1 in (select group_concat(b1) from t2_1024 group by b2);
549
drop table t1_1024, t2_1024, t3_1024;
553
set @blob_len = 1025;
554
set @suffix_len = @blob_len - @prefix_len;
556
create temporary table t1_1025 (a1 blob, a2 blob) ENGINE=MyISAM;
557
create temporary table t2_1025 (b1 blob, b2 blob) ENGINE=MyISAM;
558
create temporary table t3_1025 (c1 blob, c2 blob) ENGINE=MyISAM;
560
insert into t1_1025 values
561
(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
562
insert into t1_1025 values
563
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
564
insert into t1_1025 values
565
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
567
insert into t2_1025 values
568
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
569
insert into t2_1025 values
570
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
571
insert into t2_1025 values
572
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
574
insert into t3_1025 values
575
(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
576
insert into t3_1025 values
577
(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
578
insert into t3_1025 values
579
(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
580
insert into t3_1025 values
581
(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len)));
583
# single value transformer
584
explain extended select left(a1,7), left(a2,7)
586
where a1 in (select b1 from t2_1025 where b1 > '0');
588
select left(a1,7), left(a2,7)
590
where a1 in (select b1 from t2_1025 where b1 > '0');
592
# row value transformer
593
explain extended select left(a1,7), left(a2,7)
595
where (a1,a2) in (select b1, b2 from t2_1025 where b1 > '0');
597
select left(a1,7), left(a2,7)
599
where (a1,a2) in (select b1, b2 from t2_1025 where b1 > '0');
601
# string function with a blob argument, the return type may be != blob
602
explain extended select left(a1,7), left(a2,7)
604
where a1 in (select substring(b1,1,1025) from t2_1025 where b1 > '0');
606
select left(a1,7), left(a2,7)
608
where a1 in (select substring(b1,1,1025) from t2_1025 where b1 > '0');
610
# group_concat with a blob argument - depends on
611
# the variable group_concat_max_len, and
612
# convert_blob_length == max_len*collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB
613
explain extended select left(a1,7), left(a2,7)
615
where a1 in (select group_concat(b1) from t2_1025 group by b2);
617
select left(a1,7), left(a2,7)
619
where a1 in (select group_concat(b1) from t2_1025 group by b2);
621
set @@group_concat_max_len = 256; # anything < (CONVERT_IF_BIGGER_TO_BLOB = 1025)
623
explain extended select left(a1,7), left(a2,7)
625
where a1 in (select group_concat(b1) from t2_1025 group by b2);
627
select left(a1,7), left(a2,7)
629
where a1 in (select group_concat(b1) from t2_1025 group by b2);
631
drop table t1_1025, t2_1025, t3_1025;
632
drop table t1, t2, t3;
634
/******************************************************************************
635
* Test the cache of the left operand of IN.
636
******************************************************************************/
637
set @@optimizer_switch=no_semijoin;
639
# Test that default values of Cached_item are not used for comparison
640
create temporary table t1 (s1 int) ENGINE=MyISAM;
641
create temporary table t2 (s2 int) ENGINE=MyISAM;
642
insert into t1 values (5),(1),(0);
643
insert into t2 values (0), (1);
644
select s2 from t2 where s2 in (select s1 from t1);
647
create temporary table t1 (a int not null, b int not null) ENGINE=MyISAM;
648
create temporary table t2 (c int not null, d int not null) ENGINE=MyISAM;
649
create temporary table t3 (e int not null) ENGINE=MyISAM;
651
# the first outer row has no matching inner row
652
insert into t1 values (1,10);
653
insert into t1 values (1,20);
654
insert into t1 values (2,10);
655
insert into t1 values (2,20);
656
insert into t1 values (2,30);
657
insert into t1 values (3,20);
658
insert into t1 values (4,40);
660
insert into t2 values (2,10);
661
insert into t2 values (2,20);
662
insert into t2 values (2,40);
663
insert into t2 values (3,20);
664
insert into t2 values (4,10);
665
insert into t2 values (5,10);
667
insert into t3 values (10);
668
insert into t3 values (10);
669
insert into t3 values (20);
670
insert into t3 values (30);
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
create index it1a on t1(a);
679
select a from t1 where a in (select c from t2 where d >= 20);
680
select a from t1 where a in (select c from t2 where d >= 20);
682
# the first outer row has a matching inner row
683
insert into t2 values (1,10);
686
select a from t1 where a in (select c from t2 where d >= 20);
687
select a from t1 where a in (select c from t2 where d >= 20);
689
# cacheing for IN predicates inside a having clause - here the cached
690
# items are changed to point to temporary tables.
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);
695
# create an index that can be used for the outer query GROUP BY
696
create index iab on t1(a, b);
698
select a from t1 group by a having a in (select c from t2 where d >= 20);
699
select a from t1 group by a having a in (select c from t2 where d >= 20);
702
select a from t1 group by a
703
having a in (select c from t2 where d >= some(select e from t3 where max(b)=e));
704
select a from t1 group by a
705
having a in (select c from t2 where d >= some(select e from t3 where max(b)=e));
708
where a in (select c from t2 where d >= some(select e from t3 where b=e));
710
where a in (select c from t2 where d >= some(select e from t3 where b=e));
712
drop table t1, t2, t3;