2 # Nested Loops semi-join subquery evaluation tests
5 # This portion of the file vas developed when subquery materialization
6 # was rule-based; to preserve the intended test scenarios, we switch
7 # off cost-based choice for them.
8 set @old_opt_switch=@@optimizer_switch;
9 set optimizer_switch=
'subquery_materialization_cost_based=off';
12 drop
table if exists t0, t1, t2, t10, t11, t12;
16 # IN subquery optimization test
18 create
table t1 (a
int not null, b
int, primary key (a));
19 create
table t2 (a
int not null, primary key (a));
20 create
table t3 (a
int not null, b
int, primary key (a));
21 insert into t1 values (1,10), (2,20), (3,30), (4,40);
22 insert into t2 values (2), (3), (4), (5);
23 insert into t3 values (10,3), (20,4), (30,5);
24 select * from t2 where t2.a in (select a from t1);
25 explain extended select * from t2 where t2.a in (select a from t1);
26 select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
27 explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
28 select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
29 explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
30 drop
table t1, t2, t3;
34 insert into t1 values (1,10), (2,20), (3,30), (4,40);
35 # making table large enough
36 create
table t0(a
int);
37 insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
39 select rand()*100000+200,rand()*100000 from t0
A, t0 B, t0 C, t0 D;
41 insert into t2 values (2), (3), (4), (5);
42 insert into t3 values (10,3), (20,4), (30,5);
43 select * from t2 where t2.a in (select a from t1);
44 explain extended select * from t2 where t2.a in (select a from t1);
45 select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
46 explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
47 select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
48 explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a);
49 insert into t1 values (3,31);
50 select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
51 select * from t2 where t2.a in (select a from t1 where t1.b <> 30 and t1.b <> 31);
52 explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
53 drop
table t0, t1, t2, t3;
57 # 1. Subqueries that are converted into semi-joins
59 create
table t0 (a
int);
60 insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
62 create
table t1(a
int, b
int);
63 insert into t1 values (0,0),(1,1),(2,2);
64 create
table t2 as select * from t1;
66 create
table t11(a
int, b
int);
68 create
table t10 (pk
int, a
int, primary key(pk));
69 insert into t10 select a,a from t0;
70 create
table t12 like t10;
71 insert into t12 select * from t10;
74 --echo Flattened because of dependency, t10=func(t1)
75 explain select * from t1 where a in (select pk from t10);
76 select * from t1 where a in (select pk from t10);
78 --echo A confluent case of dependency
79 explain select * from t1 where a in (select a from t10 where pk=12);
80 select * from t1 where a in (select a from t10 where pk=12);
82 explain select * from t1 where a in (select a from t10 where pk=9);
83 select * from t1 where a in (select a from t10 where pk=9);
85 --echo An empty
table inside
86 explain select * from t1 where a in (select a from t11);
87 select * from t1 where a in (select a from t11);
89 explain select * from t1 where a in (select pk from t10) and b in (select pk from t10);
90 select * from t1 where a in (select pk from t10) and b in (select pk from t10);
92 --echo flattening a nested subquery
93 explain select * from t1 where a in (select pk from t10 where t10.a in (select pk from t12));
94 select * from t1 where a in (select pk from t10 where t10.a in (select pk from t12));
96 --echo flattening subquery w/ several tables
97 explain extended select * from t1 where a in (select t10.pk from t10, t12 where t12.pk=t10.a);
99 --echo subqueries within outer joins go into ON expr.
100 # TODO: psergey: check if case conversions like those are ok (it broke on windows)
101 --replace_result a A b B
103 select * from t1 left join (t2 A, t2 B) on ( A.a= t1.a and B.a in (select pk from t10));
105 # TODO: psergey: check if case conversions like those are ok (it broke on windows)
106 --echo t2 should be wrapped into OJ-nest, so we have
"t1 LJ (t2 J t10)"
107 --replace_result a A b B
109 select * from t1 left join t2 on (t2.a= t1.a and t2.a in (select pk from t10));
111 --echo we shouldn
't flatten if we're going
to get a join of >
MAX_TABLES.
112 explain select * from
113 t1 s00, t1 s01, t1 s02, t1 s03, t1 s04,t1 s05,t1 s06,t1 s07,t1 s08,t1 s09,
114 t1 s10, t1 s11, t1 s12, t1 s13, t1 s14,t1 s15,t1 s16,t1 s17,t1 s18,t1 s19,
115 t1 s20, t1 s21, t1 s22, t1 s23, t1 s24,t1 s25,t1 s26,t1 s27,t1 s28,t1 s29,
116 t1 s30, t1 s31, t1 s32, t1 s33, t1 s34,t1 s35,t1 s36,t1 s37,t1 s38,t1 s39,
117 t1 s40, t1 s41, t1 s42, t1 s43, t1 s44,t1 s45,t1 s46,t1 s47,t1 s48,t1 s49
121 t1 m00, t1 m01, t1 m02, t1 m03, t1 m04,t1 m05,t1 m06,t1 m07,t1 m08,t1 m09,
122 t1 m10, t1 m11, t1 m12, t1 m13, t1 m14,t1 m15,t1 m16,t1 m17,t1 m18,t1 m19
126 t1 left join t2 on (t2.a= t1.a and t2.a in (select pk from t10))
130 # Prepared statements
134 t1 left join t2 on (t2.a= t1.a and t2.a in (select pk from t10))
140 insert into t1 select (A.a + 10 * B.a),1 from t0 A, t0 B;
141 explain extended select * from t1 where a in (select pk from t10 where pk<3);
143 drop
table t0, t1, t2;
144 drop
table t10, t11, t12;
147 --echo #
Check that subqueries with outer joins or straight_join work
for
148 --echo # different permutations of
const and non-
const tables. (Ref. Bug#46692)
150 CREATE
TABLE t1 (
i INTEGER);
151 CREATE
TABLE t2 (
i INTEGER);
152 CREATE
TABLE t3 (
i INTEGER);
162 SELECT (SELECT COUNT(*) from t1) AS c1,
163 (SELECT COUNT(*) from t2) AS c2,
164 (SELECT COUNT(*) from t3) AS c3;
167 SELECT * FROM t1 WHERE (t1.
i) IN
168 (SELECT t3.
i FROM t2 INNER
JOIN t3 ON t2.
i=t3.
i);
172 eval PREPARE stmt FROM "$query";
175 DEALLOCATE PREPARE stmt;
178 SELECT * FROM t1 WHERE (t1.i) IN
179 (SELECT t3.i FROM t2 LEFT
JOIN t3 ON t2.i=t3.i);
183 eval PREPARE stmt FROM "$query";
186 DEALLOCATE PREPARE stmt;
189 SELECT * FROM t1 WHERE (t1.i) IN
190 (SELECT t3.i FROM t2 RIGHT
JOIN t3 ON t2.i=t3.i);
195 SELECT * FROM t1 WHERE (t1.i) IN
196 (SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
201 SELECT * FROM t1 WHERE (11) IN
202 (SELECT t3.i FROM t2 LEFT
JOIN t3 ON t2.i=t3.i);
207 SELECT * FROM t1 WHERE (11) IN
208 (SELECT t3.i FROM t2 LEFT
JOIN t3 ON t2.i=t3.i WHERE t1.i);
213 SELECT * FROM t1 WHERE (11) IN
214 (SELECT t3.i FROM t2 RIGHT
JOIN t3 ON t2.i=t3.i);
219 SELECT * FROM t1 WHERE (11) IN
220 (SELECT t3.i FROM t2 STRAIGHT_JOIN t3);
225 eval INSERT INTO t3 VALUES ($k);
229 eval INSERT INTO t2 VALUES ($j);
233 eval INSERT INTO t1 VALUES ($i);
235 DROP
TABLE t1, t2, t3;
237 # Test various IN and EXISTS queries with NULL values and UNKNOWN
239 create
table x1(k
int primary key, d1
int, d2
int);
240 create
table x2(k
int primary key, d1
int, d2
int);
242 insert into x1 values
248 insert into x2 values
254 # Q1 T=(10, 20) U=(21,30) F=(40)
257 where (d1, d2) in (select d1, d2
261 where (d1, d2) in (select d1, d2
265 where (d1, d2) in (select d1, d2
269 where (d1, d2) in (select d1, d2
272 # Q2 T=(10, 20) U=(30) F=(21, 40)
275 where d1 in (select d1
280 where d1 in (select d1
282 where x1.d2=x2.d2) is true;
285 where d1 in (select d1
287 where x1.d2=x2.d2) is false;
290 where d1 in (select d1
292 where x1.d2=x2.d2) is unknown;
294 # Q3 T=(10, 20) U=() F=(21, 30, 40)
299 where x1.d1=x2.d1 and x1.d2=x2.d2);
304 where x1.d1=x2.d1 and x1.d2=x2.d2) is true;
309 where x1.d1=x2.d1 and x1.d2=x2.d2) is false;
314 where x1.d1=x2.d1 and x1.d2=x2.d2) is unknown;
316 # Q4 T=(10, 20) F=(21, 30, 40)
319 where exists (select *
321 where x1.d1=x2.d1 and x1.d2=x2.d2);
328 # Test for the problem with using sj-materialization when subquery's select
329 # list element SCOL is covered by equality propagation and has preceding equal
330 # column PCOL which belongs to a table within the the semi-join nest: SJM-Scan
331 # process should unpack column value not to SCOL but rather to PCOL, as
332 # substitute_best_equal has made all conditions to refer to PCOL.
337 c datetime
default NULL,
342 INSERT INTO t1 VALUES
343 (406989,67,
'2006-02-23 17:08:46'), (150078,67,
'2005-10-26 11:17:45'),
344 (406993,67,
'2006-02-27 11:20:57'), (245655,67,
'2005-12-08 15:59:08'),
345 (406994,67,
'2006-02-27 11:26:46'), (256,67,NULL),
346 (398341,67,
'2006-02-20 04:48:44'), (254,67,NULL),(1120,67,NULL),
347 (406988,67,
'2006-02-23 17:07:22'), (255,67,NULL),
348 (398340,67,
'2006-02-20 04:38:53'),(406631,67,
'2006-02-23 10:49:42'),
349 (245653,67,
'2005-12-08 15:59:07'),(406992,67,
'2006-02-24 16:47:18'),
350 (245654,67,
'2005-12-08 15:59:08'),(406995,67,
'2006-02-28 11:55:00'),
351 (127261,67,
'2005-10-13 12:17:58'),(406991,67,
'2006-02-24 16:42:32'),
352 (245652,67,
'2005-12-08 15:58:27'),(398545,67,
'2006-02-20 04:53:13'),
353 (154504,67,
'2005-10-28 11:53:01'),(9199,67,NULL),(1,67,
'2006-02-23 15:01:35'),
354 (223456,67,NULL),(4101,67,NULL),(1133,67,NULL),
355 (406990,67,
'2006-02-23 18:01:45'),(148815,67,
'2005-10-25 15:34:17'),
356 (148812,67,
'2005-10-25 15:30:01'),(245651,67,
'2005-12-08 15:58:27'),
357 (154503,67,
'2005-10-28 11:52:38');
359 create
table t11 select * from t1 where b = 67 AND (c IS NULL OR c > NOW()) order by 3 asc;
360 create
table t12 select * from t1 where b = 67 AND (c IS NULL OR c > NOW()) order by 3 desc;
361 create
table t21 select * from t1 where b = 67 AND (c IS NULL OR c > '2005-12-08') order by 3 asc;
362 create
table t22 select * from t1 where b = 67 AND (c IS NULL OR c > '2005-12-08') order by 3 desc;
364 update t22 set c = '2005-12-08 15:58:27' where a = 255;
365 explain select t21.* from t21,t22 where t21.a = t22.a and
366 t22.a in (select t12.a from t11, t12 where t11.a in(255,256) and t11.a = t12.a and t11.c is null) and t22.c is null order by t21.a;
367 explain format=json select * from t1 where a in (select a from t11);
368 select t21.* from t21,t22 where t21.a = t22.a and
369 t22.a in (select t12.a from t11, t12 where t11.a in(255,256) and t11.a = t12.a and t11.c is null) and t22.c is null order by t21.a;
371 drop
table t1, t11, t12, t21, t22;
374 # Test sj-materialization re-execution. The test isn't meaningful (materialized
375 # table stays the same across all executions) because it's hard to create a
376 # dataset that would verify correct re-execution without hitting BUG#31480
378 create
table t1(a
int);
379 insert into t1 values (0),(1);
382 select (select max(Y.a) from t1 Y where a in (select a from t1 Z) and a < X.a) as subq from t1 X;
383 select (select max(Y.a) from t1 Y where a in (select a from t1 Z) and a < X.a) as subq from t1 X;
388 # Test confluent duplicate weedout
390 create
table t0 (a
int);
391 insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
392 create
table t1 as select * from t0;
393 insert into t1 select a+10 from t0;
394 insert into t0 values(2);
395 explain select * from t1 where 2 in (select a from t0);
396 select * from t1 where 2 in (select a from t0);
399 # FirstMatch referring to a derived table
401 let $query=select * from (select a from t0) x where a in (select a from t1);
402 --eval explain $query
403 --eval explain format=json $query
407 # LooseScan: Check if we can pick it together with range access
409 create
table t0 (a
int);
410 insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
412 create
table t1 (kp1
int, kp2
int, c
int, filler
char(100), key(kp1, kp2));
413 insert into t1 select A.a+10*(B.a+10*C.a), 0, 0,
'filler' from t0 A, t0 B, t0 C;
414 insert into t1 select * from t1 where kp1 < 20;
416 create
table t3 (a
int);
417 insert into t3 select A.a + 10*B.a from t0 A, t0 B;
419 explain select * from t3 where a in (select kp1 from t1 where kp1<20);
420 select * from t3 where a in (select kp1 from t1 where kp1<20);
422 explain select * from t3 where a in (select kp1 from t1 where kp1<20) and a<20;
423 select * from t3 where a in (select kp1 from t1 where kp1<20) and a<20;
425 create
table t4 (pk
int primary key);
426 insert into t4 select a from t3;
428 explain select * from t3 where a in
429 (select t1.kp1 from t1,t4 where kp1<20 and t4.pk=t1.c);
430 select * from t3 where a in
431 (select t1.kp1 from t1,t4 where kp1<20 and t4.pk=t1.c);
433 drop
table t1, t3, t4;
436 # Test if we handle duplicate elimination temptable overflowing to disk
438 create
table t1 (a
int);
439 insert into t1 values (0),(0),(0),(1),(1),(1),(2),(2),(2),(3),(3),(3);
441 set @save_max_heap_table_size=@@max_heap_table_size;
442 set @@max_heap_table_size= 16384;
445 --echo # non-duplicate row is inserted and one
test that overflows the
446 --echo #
heap table when a duplicate
record is inserted. Debugging showed
447 --echo # that these situations occurred with max_heap_table_size=16384
448 --echo # and optimizer_join_cache_level equals 1 and 0, respectively.
449 --echo # Finally execute a
test that does not overflow the
heap table.
451 select count(*) from t0 A, t0 B, t0 C
452 where C.a in (select a from t1 D);
454 select count(*) from t0 A, t0 B, t0 C
455 where C.a in (select a from t1 D);
456 show status like 'Created_tmp_disk_tables';
458 set @@max_heap_table_size= @save_max_heap_table_size;
460 select count(*) from t0 A, t0 B, t0 C
461 where C.a in (select a from t1 D);
462 show status like 'Created_tmp_disk_tables';
466 # Materialize + Scan + ref access to the subsequent table based on scanned
469 create
table t0 (a
int);
470 insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
471 create
table t2(a
int);
472 insert into t2 values (1),(2);
473 create
table t3 ( a
int , filler
char(100), key(a));
474 insert into t3 select A.a + 10*B.a,
'filler' from t0 A, t0 B;
475 explain select * from t3 where a in (select a from t2) and (a > 5 or a < 10);
476 select * from t3 where a in (select a from t2);
478 drop
table t0, t2, t3;
481 # DATETIME type checks
483 create
table t1 (a date);
484 insert into t1 values (
'2008-01-01'),(
'2008-01-01'),(
'2008-02-01'),(
'2008-02-01');
485 create
table t2 (a
int);
486 insert into t2 values (1),(2);
487 create
table t3 (a
char(10));
488 insert into t3 select * from t1;
489 insert into t3 values (1),(2);
490 explain select * from t2 where a in (select a from t1);
491 explain select * from t2 where a in (select a from t2);
492 explain select * from t2 where a in (select a from t3);
493 explain select * from t1 where a in (select a from t3);
494 drop
table t1, t2, t3;
495 create
table t1 (a decimal);
496 insert into t1 values (1),(2);
497 explain select * from t1 where a in (select a from t1);
501 # SJ-Materialization-scan for non-first table
503 create
table t1 (a
int);
504 insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
505 create
table t2 as select * from t1;
506 create
table t3 (a
int, b
int, filler
char(100), key(a));
507 insert into t3 select A.a + 10*B.a, A.a + 10*B.a,
'filler' from t1 A, t1 B, t1 C;
508 explain select * from t1, t3 where t3.a in (select a from t2) and (t3.a < 10 or t3.a >30) and t1.a =3;
509 explain format=json select * from t1, t3 where t3.a in (select a from t2) and (t3.a < 10 or t3.a >30) and t1.a =3;
512 # Verify that straight_join modifier in parent or child prevents flattening
514 explain select straight_join * from t1 A, t1 B where A.a in (select a from t2);
515 explain select * from t2 where a in (select straight_join A.a from t1 A, t1 B);
516 explain select * from t2 where a in (select straight_join A.a from t1 A, t1 B);
517 explain select straight_join * from t2 X, t2 Y
518 where X.a in (select straight_join A.a from t1 A, t1 B);
521 # SJ-Materialization scan + first table being system const table
523 create
table t0 (a
int, b
int);
524 insert into t0 values(1,1);
525 explain select * from t0, t3 where t3.a in (select a from t2) and (t3.a < 10 or t3.a >30);
526 create
table t4 as select a as x, a as y from t1;
527 explain select * from t0, t3 where (t3.a, t3.b) in (select x,y from t4) and (t3.a < 10 or t3.a >30);
528 drop
table t0,t1,t2,t3,t4;
531 # LooseScan with ref access
533 create
table t0 (a
int);
534 insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
535 create
table t1 (a
int, b
int, filler
char(100), key(a,b));
536 insert into t1 select A.a, B.a,
'filler' from t0 A, t0 B;
537 create
table t2 as select * from t1;
539 explain select * from t2 where a in (select b from t1 where a=3);
540 explain select * from t2 where (b,a) in (select a,b from t1 where a=3);
545 # Multi-column sj-materialization with lookups
547 create
table t1 (a
int, b
int);
548 insert into t1 select a,a from t0;
549 create
table t2 (a
int, b
int);
550 insert into t2 select A.a + 10*B.a, A.a + 10*B.a from t0 A, t0 B;
552 explain select * from t1 where (a,b) in (select a,b from t2);
554 drop
table t0, t1, t2;
558 # Primitive SJ-Materialization tests for DECIMAL and DATE
560 create
table t0 (a decimal(4,2));
561 insert into t0 values (10.24), (22.11);
562 create
table t1 as select * from t0;
563 insert into t1 select * from t0;
564 explain select * from t0 where a in (select a from t1);
565 select * from t0 where a in (select a from t1);
568 create
table t0(a date);
569 insert into t0 values (
'2008-01-01'),(
'2008-02-02');
570 create
table t1 as select * from t0;
571 insert into t1 select * from t0;
572 explain select * from t0 where a in (select a from t1);
573 select * from t0 where a in (select a from t1);
577 # Fix a trivial crash with SJ-Materialization lookup, multiple tables in the
578 # subquery, and a condition on some of inner tables but not others
580 create
table t0(a
int);
581 insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
582 create
table t1 as select a as a, a as b, a as c from t0 where a < 3;
583 create
table t2 as select a as a, a as b from t0 where a < 3;
584 insert into t2 select * from t2;
586 explain select * from t1 where (a,b,c) in (select X.a, Y.a, Z.a from t2 X, t2 Y, t2 Z where X.b=33);
592 # Test join buffering
594 set @save_join_buffer_size = @@join_buffer_size;
595 set join_buffer_size= 8192;
597 create
table t0 (a
int);
598 insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
600 create
table t1 (a
int, filler1 binary(200), filler2 binary(200));
601 insert into t1 select a,
'filler123456',
'filler123456' from t0;
602 insert into t1 select a+10,
'filler123456',
'filler123456' from t0;
604 create
table t2 as select * from t1;
605 insert into t1 select a+20,
'filler123456',
'filler123456' from t0;
607 insert into t1 values (2,
'duplicate ok',
'duplicate ok');
608 insert into t1 values (18,
'duplicate ok',
'duplicate ok');
610 insert into t2 values (3,
'duplicate ok',
'duplicate ok');
611 insert into t2 values (19,
'duplicate ok',
'duplicate ok');
614 a, mid(filler1, 1,10), length(filler1)=length(filler2) as Z
615 from t1 ot where a in (select a from t2 it);
618 a, mid(filler1, 1,10), length(filler1)=length(filler2) as Z
619 from t1 ot where a in (select a from t2 it);
622 a, mid(filler1, 1,10), length(filler1)=length(filler2)
623 from t2 ot where a in (select a from t1 it);
626 a, mid(filler1, 1,10), length(filler1)=length(filler2)
627 from t2 ot where a in (select a from t1 it);
629 # Now let the buffer overfill:
630 insert into t1 select a+20,
'filler123456',
'filler123456' from t0;
631 insert into t1 select a+20,
'filler123456',
'filler123456' from t0;
634 a, mid(filler1, 1,10), length(filler1)=length(filler2) as Z
635 from t1 ot where a in (select a from t2 it);
638 a, mid(filler1, 1,10), length(filler1)=length(filler2) as Z
639 from t1 ot where a in (select a from t2 it);
642 a, mid(filler1, 1,10), length(filler1)=length(filler2)
643 from t2 ot where a in (select a from t1 it);
646 a, mid(filler1, 1,10), length(filler1)=length(filler2)
647 from t2 ot where a in (select a from t1 it);
649 set @@join_buffer_size = @save_join_buffer_size;
652 # Check ref access to tables inside the OJ nest inside the SJ nest
653 create
table t1 (a
int, b
int, key(a));
654 create
table t2 (a
int, b
int, key(a));
655 create
table t3 (a
int, b
int, key(a));
657 insert into t1 select a,a from t0;
658 insert into t2 select a,a from t0;
659 insert into t3 select a,a from t0;
661 --echo t2 and t3 must be use
'ref', not
'ALL':
664 (select t2.a+t3.a from t1 left join (t2 join t3) on t2.a=t1.a and t3.a=t1.a);
666 drop
table t0, t1,t2,t3;
670 --echo
Test that neither MaterializeLookup strategy
for semijoin,
671 --echo nor subquery materialization is used when BLOBs are involved
672 --echo (except when arguments of some functions).
676 # BLOB == 16 (small blobs that could be stored in HEAP tables)
678 set @suffix_len = @blob_len - @prefix_len;
680 create
table t1_16 (a1 blob(16), a2 blob(16));
681 create
table t2_16 (b1 blob(16), b2 blob(16));
682 create
table t3_16 (c1 blob(16), c2 blob(16));
684 insert into t1_16 values
685 (concat(
'1 - 00', repeat(
'x', @suffix_len)), concat(
'2 - 00', repeat(
'x', @suffix_len)));
686 insert into t1_16 values
687 (concat(
'1 - 01', repeat(
'x', @suffix_len)), concat(
'2 - 01', repeat(
'x', @suffix_len)));
688 insert into t1_16 values
689 (concat(
'1 - 02', repeat(
'x', @suffix_len)), concat(
'2 - 02', repeat(
'x', @suffix_len)));
691 insert into t2_16 values
692 (concat(
'1 - 01', repeat(
'x', @suffix_len)), concat(
'2 - 01', repeat(
'x', @suffix_len)));
693 insert into t2_16 values
694 (concat(
'1 - 02', repeat(
'x', @suffix_len)), concat(
'2 - 02', repeat(
'x', @suffix_len)));
695 insert into t2_16 values
696 (concat(
'1 - 03', repeat(
'x', @suffix_len)), concat(
'2 - 03', repeat(
'x', @suffix_len)));
698 insert into t3_16 values
699 (concat(
'1 - 01', repeat(
'x', @suffix_len)), concat(
'2 - 01', repeat(
'x', @suffix_len)));
700 insert into t3_16 values
701 (concat(
'1 - 02', repeat(
'x', @suffix_len)), concat(
'2 - 02', repeat(
'x', @suffix_len)));
702 insert into t3_16 values
703 (concat(
'1 - 03', repeat(
'x', @suffix_len)), concat(
'2 - 03', repeat(
'x', @suffix_len)));
704 insert into t3_16 values
705 (concat(
'1 - 04', repeat(
'x', @suffix_len)), concat(
'2 - 04', repeat(
'x', @suffix_len)));
707 # single value transformer
708 explain extended select left(a1,7), left(a2,7)
710 where a1 in (select b1 from t2_16 where b1 > '0');
712 select left(a1,7), left(a2,7)
714 where a1 in (select b1 from t2_16 where b1 > '0');
716 # row value transformer
717 explain extended select left(a1,7), left(a2,7)
719 where (a1,a2) in (select b1, b2 from t2_16 where b1 > '0');
721 select left(a1,7), left(a2,7)
723 where (a1,a2) in (select b1, b2 from t2_16 where b1 > '0');
725 # string function with a blob argument, the return type may be != blob
726 explain extended select left(a1,7), left(a2,7)
728 where a1 in (select substring(b1,1,16) from t2_16 where b1 > '0');
730 select left(a1,7), left(a2,7)
732 where a1 in (select substring(b1,1,16) from t2_16 where b1 > '0');
734 # group_concat with a blob argument - depends on
735 # the variable group_concat_max_len, and
736 # convert_blob_length == max_len*collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB
737 explain extended select left(a1,7), left(a2,7)
739 where a1 in (select group_concat(b1) from t2_16
group by b2);
741 select left(a1,7), left(a2,7)
743 where a1 in (select group_concat(b1) from t2_16
group by b2);
745 set @@group_concat_max_len = 256;
# anything < (CONVERT_IF_BIGGER_TO_BLOB = 512)
747 explain extended select left(a1,7), left(a2,7)
749 where a1 in (select group_concat(b1) from t2_16
group by b2);
751 select left(a1,7), left(a2,7)
753 where a1 in (select group_concat(b1) from t2_16
group by b2);
755 # BLOB column at the second (intermediate) level of nesting
756 create
table t1 (a1
char(8), a2
char(8));
757 create
table t2 (b1
char(8), b2
char(8));
758 create
table t3 (c1
char(8), c2
char(8));
759 insert into t1 values (
'1 - 00',
'2 - 00');
760 insert into t1 values (
'1 - 01',
'2 - 01');
761 insert into t1 values (
'1 - 02',
'2 - 02');
762 insert into t2 values (
'1 - 01',
'2 - 01');
763 insert into t2 values (
'1 - 01',
'2 - 01');
764 insert into t2 values (
'1 - 02',
'2 - 02');
765 insert into t2 values (
'1 - 02',
'2 - 02');
766 insert into t2 values (
'1 - 03',
'2 - 03');
767 insert into t3 values (
'1 - 01',
'2 - 01');
768 insert into t3 values (
'1 - 02',
'2 - 02');
769 insert into t3 values (
'1 - 03',
'2 - 03');
770 insert into t3 values (
'1 - 04',
'2 - 04');
774 where concat(a1,
'x') IN
775 (select left(a1,8) from t1_16
777 (select t2_16.b1, t2_16.b2 from t2_16, t2
778 where t2.b2 = substring(t2_16.b2,1,6) and
779 t2.b1 IN (select c1 from t3 where c2 > '0')));
782 drop
table t1_16, t2_16, t3_16, t1, t2, t3;
785 # BLOB == 512 (CONVERT_IF_BIGGER_TO_BLOB == 512)
787 set @suffix_len = @blob_len - @prefix_len;
789 create
table t1_512 (a1 blob(512), a2 blob(512));
790 create
table t2_512 (b1 blob(512), b2 blob(512));
791 create
table t3_512 (c1 blob(512), c2 blob(512));
793 insert into t1_512 values
794 (concat(
'1 - 00', repeat(
'x', @suffix_len)), concat(
'2 - 00', repeat(
'x', @suffix_len)));
795 insert into t1_512 values
796 (concat(
'1 - 01', repeat(
'x', @suffix_len)), concat(
'2 - 01', repeat(
'x', @suffix_len)));
797 insert into t1_512 values
798 (concat(
'1 - 02', repeat(
'x', @suffix_len)), concat(
'2 - 02', repeat(
'x', @suffix_len)));
800 insert into t2_512 values
801 (concat(
'1 - 01', repeat(
'x', @suffix_len)), concat(
'2 - 01', repeat(
'x', @suffix_len)));
802 insert into t2_512 values
803 (concat(
'1 - 02', repeat(
'x', @suffix_len)), concat(
'2 - 02', repeat(
'x', @suffix_len)));
804 insert into t2_512 values
805 (concat(
'1 - 03', repeat(
'x', @suffix_len)), concat(
'2 - 03', repeat(
'x', @suffix_len)));
807 insert into t3_512 values
808 (concat(
'1 - 01', repeat(
'x', @suffix_len)), concat(
'2 - 01', repeat(
'x', @suffix_len)));
809 insert into t3_512 values
810 (concat(
'1 - 02', repeat(
'x', @suffix_len)), concat(
'2 - 02', repeat(
'x', @suffix_len)));
811 insert into t3_512 values
812 (concat(
'1 - 03', repeat(
'x', @suffix_len)), concat(
'2 - 03', repeat(
'x', @suffix_len)));
813 insert into t3_512 values
814 (concat(
'1 - 04', repeat(
'x', @suffix_len)), concat(
'2 - 04', repeat(
'x', @suffix_len)));
816 # single value transformer
817 explain extended select left(a1,7), left(a2,7)
819 where a1 in (select b1 from t2_512 where b1 > '0');
821 select left(a1,7), left(a2,7)
823 where a1 in (select b1 from t2_512 where b1 > '0');
825 # row value transformer
826 explain extended select left(a1,7), left(a2,7)
828 where (a1,a2) in (select b1, b2 from t2_512 where b1 > '0');
830 select left(a1,7), left(a2,7)
832 where (a1,a2) in (select b1, b2 from t2_512 where b1 > '0');
834 # string function with a blob argument, the return type may be != blob
835 explain extended select left(a1,7), left(a2,7)
837 where a1 in (select substring(b1,1,512) from t2_512 where b1 > '0');
839 select left(a1,7), left(a2,7)
841 where a1 in (select substring(b1,1,512) from t2_512 where b1 > '0');
843 # group_concat with a blob argument - depends on
844 # the variable group_concat_max_len, and
845 # convert_blob_length == max_len*collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB
846 explain extended select left(a1,7), left(a2,7)
848 where a1 in (select group_concat(b1) from t2_512
group by b2);
850 select left(a1,7), left(a2,7)
852 where a1 in (select group_concat(b1) from t2_512
group by b2);
854 set @@group_concat_max_len = 256;
# anything < (CONVERT_IF_BIGGER_TO_BLOB = 512)
856 explain extended select left(a1,7), left(a2,7)
858 where a1 in (select group_concat(b1) from t2_512
group by b2);
860 select left(a1,7), left(a2,7)
862 where a1 in (select group_concat(b1) from t2_512
group by b2);
864 drop
table t1_512, t2_512, t3_512;
867 # BLOB == 513 (CONVERT_IF_BIGGER_TO_BLOB < 513)
869 set @suffix_len = @blob_len - @prefix_len;
871 create
table t1_513 (a1 blob(513), a2 blob(513));
872 create
table t2_513 (b1 blob(513), b2 blob(513));
873 create
table t3_513 (c1 blob(513), c2 blob(513));
875 insert into t1_513 values
876 (concat(
'1 - 00', repeat(
'x', @suffix_len)), concat(
'2 - 00', repeat(
'x', @suffix_len)));
877 insert into t1_513 values
878 (concat(
'1 - 01', repeat(
'x', @suffix_len)), concat(
'2 - 01', repeat(
'x', @suffix_len)));
879 insert into t1_513 values
880 (concat(
'1 - 02', repeat(
'x', @suffix_len)), concat(
'2 - 02', repeat(
'x', @suffix_len)));
882 insert into t2_513 values
883 (concat(
'1 - 01', repeat(
'x', @suffix_len)), concat(
'2 - 01', repeat(
'x', @suffix_len)));
884 insert into t2_513 values
885 (concat(
'1 - 02', repeat(
'x', @suffix_len)), concat(
'2 - 02', repeat(
'x', @suffix_len)));
886 insert into t2_513 values
887 (concat(
'1 - 03', repeat(
'x', @suffix_len)), concat(
'2 - 03', repeat(
'x', @suffix_len)));
889 insert into t3_513 values
890 (concat(
'1 - 01', repeat(
'x', @suffix_len)), concat(
'2 - 01', repeat(
'x', @suffix_len)));
891 insert into t3_513 values
892 (concat(
'1 - 02', repeat(
'x', @suffix_len)), concat(
'2 - 02', repeat(
'x', @suffix_len)));
893 insert into t3_513 values
894 (concat(
'1 - 03', repeat(
'x', @suffix_len)), concat(
'2 - 03', repeat(
'x', @suffix_len)));
895 insert into t3_513 values
896 (concat(
'1 - 04', repeat(
'x', @suffix_len)), concat(
'2 - 04', repeat(
'x', @suffix_len)));
898 # single value transformer
899 explain extended select left(a1,7), left(a2,7)
901 where a1 in (select b1 from t2_513 where b1 > '0');
903 select left(a1,7), left(a2,7)
905 where a1 in (select b1 from t2_513 where b1 > '0');
907 # row value transformer
908 explain extended select left(a1,7), left(a2,7)
910 where (a1,a2) in (select b1, b2 from t2_513 where b1 > '0');
912 select left(a1,7), left(a2,7)
914 where (a1,a2) in (select b1, b2 from t2_513 where b1 > '0');
916 # string function with a blob argument, the return type may be != blob
917 explain extended select left(a1,7), left(a2,7)
919 where a1 in (select substring(b1,1,513) from t2_513 where b1 > '0');
921 select left(a1,7), left(a2,7)
923 where a1 in (select substring(b1,1,513) from t2_513 where b1 > '0');
925 # group_concat with a blob argument - depends on
926 # the variable group_concat_max_len, and
927 # convert_blob_length == max_len*collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB
928 explain extended select left(a1,7), left(a2,7)
930 where a1 in (select group_concat(b1) from t2_513
group by b2);
932 select left(a1,7), left(a2,7)
934 where a1 in (select group_concat(b1) from t2_513
group by b2);
936 drop
table t1_513, t2_513, t3_513;
939 # BLOB == 1024 (group_concat_max_len == 1024)
940 set @blob_len = 1024;
941 set @suffix_len = @blob_len - @prefix_len;
943 create
table t1_1024 (a1 blob(1024), a2 blob(1024));
944 create
table t2_1024 (b1 blob(1024), b2 blob(1024));
945 create
table t3_1024 (c1 blob(1024), c2 blob(1024));
947 insert into t1_1024 values
948 (concat(
'1 - 00', repeat(
'x', @suffix_len)), concat(
'2 - 00', repeat(
'x', @suffix_len)));
949 insert into t1_1024 values
950 (concat(
'1 - 01', repeat(
'x', @suffix_len)), concat(
'2 - 01', repeat(
'x', @suffix_len)));
951 insert into t1_1024 values
952 (concat(
'1 - 02', repeat(
'x', @suffix_len)), concat(
'2 - 02', repeat(
'x', @suffix_len)));
954 insert into t2_1024 values
955 (concat(
'1 - 01', repeat(
'x', @suffix_len)), concat(
'2 - 01', repeat(
'x', @suffix_len)));
956 insert into t2_1024 values
957 (concat(
'1 - 02', repeat(
'x', @suffix_len)), concat(
'2 - 02', repeat(
'x', @suffix_len)));
958 insert into t2_1024 values
959 (concat(
'1 - 03', repeat(
'x', @suffix_len)), concat(
'2 - 03', repeat(
'x', @suffix_len)));
961 insert into t3_1024 values
962 (concat(
'1 - 01', repeat(
'x', @suffix_len)), concat(
'2 - 01', repeat(
'x', @suffix_len)));
963 insert into t3_1024 values
964 (concat(
'1 - 02', repeat(
'x', @suffix_len)), concat(
'2 - 02', repeat(
'x', @suffix_len)));
965 insert into t3_1024 values
966 (concat(
'1 - 03', repeat(
'x', @suffix_len)), concat(
'2 - 03', repeat(
'x', @suffix_len)));
967 insert into t3_1024 values
968 (concat(
'1 - 04', repeat(
'x', @suffix_len)), concat(
'2 - 04', repeat(
'x', @suffix_len)));
970 # single value transformer
971 explain extended select left(a1,7), left(a2,7)
973 where a1 in (select b1 from t2_1024 where b1 > '0');
975 select left(a1,7), left(a2,7)
977 where a1 in (select b1 from t2_1024 where b1 > '0');
979 # row value transformer
980 explain extended select left(a1,7), left(a2,7)
982 where (a1,a2) in (select b1, b2 from t2_1024 where b1 > '0');
984 select left(a1,7), left(a2,7)
986 where (a1,a2) in (select b1, b2 from t2_1024 where b1 > '0');
988 # string function with a blob argument, the return type may be != blob
989 explain extended select left(a1,7), left(a2,7)
991 where a1 in (select substring(b1,1,1024) from t2_1024 where b1 > '0');
993 select left(a1,7), left(a2,7)
995 where a1 in (select substring(b1,1,1024) from t2_1024 where b1 > '0');
997 # group_concat with a blob argument - depends on
998 # the variable group_concat_max_len, and
999 # convert_blob_length == max_len*collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB
1000 explain extended select left(a1,7), left(a2,7)
1002 where a1 in (select group_concat(b1) from t2_1024
group by b2);
1004 select left(a1,7), left(a2,7)
1006 where a1 in (select group_concat(b1) from t2_1024
group by b2);
1008 set @@group_concat_max_len = 256;
# anything < (CONVERT_IF_BIGGER_TO_BLOB = 1024)
1010 explain extended select left(a1,7), left(a2,7)
1012 where a1 in (select group_concat(b1) from t2_1024
group by b2);
1014 select left(a1,7), left(a2,7)
1016 where a1 in (select group_concat(b1) from t2_1024
group by b2);
1018 drop
table t1_1024, t2_1024, t3_1024;
1022 set @blob_len = 1025;
1023 set @suffix_len = @blob_len - @prefix_len;
1025 create
table t1_1025 (a1 blob(1025), a2 blob(1025));
1026 create
table t2_1025 (b1 blob(1025), b2 blob(1025));
1027 create
table t3_1025 (c1 blob(1025), c2 blob(1025));
1029 insert into t1_1025 values
1030 (concat(
'1 - 00', repeat(
'x', @suffix_len)), concat(
'2 - 00', repeat(
'x', @suffix_len)));
1031 insert into t1_1025 values
1032 (concat(
'1 - 01', repeat(
'x', @suffix_len)), concat(
'2 - 01', repeat(
'x', @suffix_len)));
1033 insert into t1_1025 values
1034 (concat(
'1 - 02', repeat(
'x', @suffix_len)), concat(
'2 - 02', repeat(
'x', @suffix_len)));
1036 insert into t2_1025 values
1037 (concat(
'1 - 01', repeat(
'x', @suffix_len)), concat(
'2 - 01', repeat(
'x', @suffix_len)));
1038 insert into t2_1025 values
1039 (concat(
'1 - 02', repeat(
'x', @suffix_len)), concat(
'2 - 02', repeat(
'x', @suffix_len)));
1040 insert into t2_1025 values
1041 (concat(
'1 - 03', repeat(
'x', @suffix_len)), concat(
'2 - 03', repeat(
'x', @suffix_len)));
1043 insert into t3_1025 values
1044 (concat(
'1 - 01', repeat(
'x', @suffix_len)), concat(
'2 - 01', repeat(
'x', @suffix_len)));
1045 insert into t3_1025 values
1046 (concat(
'1 - 02', repeat(
'x', @suffix_len)), concat(
'2 - 02', repeat(
'x', @suffix_len)));
1047 insert into t3_1025 values
1048 (concat(
'1 - 03', repeat(
'x', @suffix_len)), concat(
'2 - 03', repeat(
'x', @suffix_len)));
1049 insert into t3_1025 values
1050 (concat(
'1 - 04', repeat(
'x', @suffix_len)), concat(
'2 - 04', repeat(
'x', @suffix_len)));
1052 # single value transformer
1053 explain extended select left(a1,7), left(a2,7)
1055 where a1 in (select b1 from t2_1025 where b1 > '0');
1057 select left(a1,7), left(a2,7)
1059 where a1 in (select b1 from t2_1025 where b1 > '0');
1061 # row value transformer
1062 explain extended select left(a1,7), left(a2,7)
1064 where (a1,a2) in (select b1, b2 from t2_1025 where b1 > '0');
1066 select left(a1,7), left(a2,7)
1068 where (a1,a2) in (select b1, b2 from t2_1025 where b1 > '0');
1070 # string function with a blob argument, the return type may be != blob
1071 explain extended select left(a1,7), left(a2,7)
1073 where a1 in (select substring(b1,1,1025) from t2_1025 where b1 > '0');
1075 select left(a1,7), left(a2,7)
1077 where a1 in (select substring(b1,1,1025) from t2_1025 where b1 > '0');
1079 # group_concat with a blob argument - depends on
1080 # the variable group_concat_max_len, and
1081 # convert_blob_length == max_len*collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB
1082 explain extended select left(a1,7), left(a2,7)
1084 where a1 in (select group_concat(b1) from t2_1025
group by b2);
1086 select left(a1,7), left(a2,7)
1088 where a1 in (select group_concat(b1) from t2_1025
group by b2);
1090 set @@group_concat_max_len = 256;
# anything < (CONVERT_IF_BIGGER_TO_BLOB = 1025)
1092 explain extended select left(a1,7), left(a2,7)
1094 where a1 in (select group_concat(b1) from t2_1025
group by b2);
1096 select left(a1,7), left(a2,7)
1098 where a1 in (select group_concat(b1) from t2_1025
group by b2);
1100 drop
table t1_1025, t2_1025, t3_1025;
1103 --echo # WL#5561: Enable semi join transformation with outer join.
1106 CREATE
TABLE ot1(a INT);
1107 CREATE
TABLE ot2(a INT);
1108 CREATE
TABLE ot3(a INT);
1109 CREATE
TABLE it1(a INT);
1110 CREATE
TABLE it2(a INT);
1111 CREATE
TABLE it3(a INT);
1113 INSERT INTO ot1 VALUES(0),(1),(2),(3),(4),(5),(6),(7);
1114 INSERT INTO ot2 VALUES(0),(2),(4),(6);
1115 INSERT INTO ot3 VALUES(0),(3),(6);
1116 INSERT INTO it1 VALUES(0),(1),(2),(3),(4),(5),(6),(7);
1117 INSERT INTO it2 VALUES(0),(2),(4),(6);
1118 INSERT INTO it3 VALUES(0),(3),(6);
1120 --echo #
Test cases, Subquery Pattern 1
1122 --echo # Example SQ1.1:
1126 FROM ot1 LEFT
JOIN ot2 ON ot1.a=ot2.a
1127 WHERE ot1.a IN (SELECT a FROM it3);
1128 eval explain $query;
1132 --echo # Example SQ1.2:
1136 FROM ot1 LEFT
JOIN ot2 ON ot1.a=ot2.a
1137 WHERE COALESCE(ot2.a,0) IN (SELECT a FROM it3);
1138 eval explain $query;
1142 --echo
# Example SQ1.3:
1146 FROM ot1 LEFT
JOIN ot2 ON ot1.a=ot2.a
1147 WHERE (ot1.a,ot2.a) IN (SELECT a, a FROM it3);
1148 eval explain $query;
1152 --echo
# More test cases
1156 FROM ot1 LEFT
JOIN ot2 ON ot1.a=ot2.a+0
1157 WHERE ot1.a IN (SELECT a FROM it3);
1161 FROM ot1 LEFT
JOIN ot2 ON ot1.a=ot2.a+0
1162 WHERE ot1.a IN (SELECT a+0 FROM it3);
1166 FROM ot1 LEFT
JOIN ot2 ON ot1.a=ot2.a+0
1167 WHERE COALESCE(ot2.a,0) IN (SELECT a FROM it3);
1171 FROM ot1 LEFT
JOIN ot2 ON ot1.a=ot2.a
1172 WHERE COALESCE(ot2.a,0) IN (SELECT a+0 FROM it3);
1176 FROM ot1 LEFT
JOIN ot2 ON ot1.a=ot2.a+0
1177 WHERE (ot1.a,ot2.a) IN (SELECT a, a FROM it3);
1181 FROM ot1 LEFT
JOIN ot2 ON ot1.a=ot2.a
1182 LEFT
JOIN ot3 ON ot1.a=ot3.a
1183 WHERE ot1.a IN (SELECT a FROM it3);
1187 FROM ot1 LEFT
JOIN ot2 ON ot1.a=ot2.a
1188 LEFT
JOIN ot3 ON ot1.a=ot3.a
1189 WHERE COALESCE(ot2.a,0) IN (SELECT a FROM it3);
1193 FROM ot1 LEFT
JOIN ot2 ON ot1.a=ot2.a
1194 LEFT
JOIN ot3 ON ot1.a=ot3.a
1195 WHERE COALESCE(ot3.a,0) IN (SELECT a FROM it3);
1199 FROM ot1 LEFT
JOIN ot2 ON ot1.a=ot2.a
1200 LEFT
JOIN ot3 ON ot2.a=ot3.a
1201 WHERE ot1.a IN (SELECT a FROM it3);
1205 FROM ot1 LEFT
JOIN ot2 ON ot1.a=ot2.a
1206 LEFT
JOIN ot3 ON ot2.a=ot3.a
1207 WHERE COALESCE(ot2.a,0) IN (SELECT a FROM it3);
1211 FROM ot1 LEFT
JOIN ot2 ON ot1.a=ot2.a
1212 LEFT
JOIN ot3 ON ot2.a=ot3.a
1213 WHERE COALESCE(ot3.a,0) IN (SELECT a FROM it3);
1215 --echo
# Test cases, Subquery Pattern 2
1217 --echo # Example SQ2.1:
1221 FROM ot1
JOIN ot2 ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it3);
1222 eval explain $query;
1226 --echo # Example SQ2.2:
1230 FROM ot1
JOIN ot2 ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it2)
1231 AND ot2.a IN (SELECT a FROM it3);
1232 eval explain $query;
1236 --echo # More
test cases
1240 FROM ot1
JOIN ot2 ON ot1.a=ot2.a+0 AND ot1.a IN (SELECT a FROM it3);
1244 FROM ot1
JOIN ot2 ON ot1.a=ot2.a AND ot1.a IN (SELECT a+0 FROM it3);
1248 FROM ot1
JOIN ot2 ON ot1.a=ot2.a+0 AND ot2.a IN (SELECT a FROM it3);
1252 FROM ot1
JOIN ot2 ON ot1.a=ot2.a AND ot2.a IN (SELECT a+0 FROM it3);
1256 FROM ot1
JOIN ot2 ON ot1.a=ot2.a AND ot1.a IN (SELECT a+0 FROM it2)
1257 AND ot2.a IN (SELECT a+0 FROM it3);
1261 FROM ot1
JOIN ot2 ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it3)
1262 JOIN ot3 ON ot2.a=ot3.a AND ot3.a IN (SELECT a FROM it3);
1264 --echo #
Test cases, Subquery Pattern 3
1266 --echo # Example SQ3.1:
1270 FROM ot1 LEFT
JOIN ot2 ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it3);
1271 eval explain $query;
1275 --echo # Example SQ3.2:
1279 FROM ot1 LEFT
JOIN ot2 ON ot1.a=ot2.a AND ot2.a IN (SELECT a FROM it2);
1280 eval explain $query;
1284 --echo # Example SQ3.3
1288 FROM ot1 LEFT
JOIN ot2 ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it1)
1289 AND ot2.a IN (SELECT a FROM it2);
1290 eval explain $query;
1294 --echo # Example SQ3.4
1298 FROM ot1 LEFT
JOIN ot2 ON ot1.a=ot2.a AND
1299 (ot1.a, ot2.a) IN (SELECT it1.a, it2.a
1300 FROM it1
JOIN it2 ON it1.a=it2.a);
1301 eval explain $query;
1305 --echo
# More test cases
1309 FROM ot1 LEFT
JOIN ot2 ON ot1.a=ot2.a+0 AND ot1.a IN (SELECT a FROM it3);
1313 FROM ot1 LEFT
JOIN ot2 ON ot1.a=ot2.a AND ot1.a IN (SELECT a+0 FROM it3);
1317 FROM ot1 LEFT
JOIN ot2 ON ot1.a=ot2.a+0 AND ot2.a IN (SELECT a FROM it2);
1321 FROM ot1 LEFT
JOIN ot2 ON ot1.a=ot2.a AND ot2.a IN (SELECT a+0 FROM it2);
1325 FROM ot1 LEFT
JOIN ot2 ON ot1.a=ot2.a+0 AND ot1.a IN (SELECT a+0 FROM it1)
1326 AND ot2.a IN (SELECT a+0 FROM it2);
1330 FROM ot1 LEFT
JOIN ot2 ON ot1.a=ot2.a+0 AND
1331 (ot1.a, ot2.a) IN (SELECT it1.a+0, it2.a+0
1332 FROM it1
JOIN it2 ON it1.a=it2.a);
1336 FROM ot1 LEFT
JOIN ot2 ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it3)
1337 LEFT
JOIN ot3 ON ot2.a=ot3.a AND ot3.a IN (SELECT a FROM it3);
1341 FROM ot1 LEFT
JOIN ot2 ON ot1.a=ot2.a+0 AND ot1.a IN (SELECT a FROM it3)
1342 LEFT
JOIN ot3 ON ot2.a=ot3.a+0 AND ot3.a IN (SELECT a FROM it3);
1344 --echo
# Test cases, Subquery Pattern 4
1346 --echo # Example SQ4.1:
1352 (ot2
JOIN ot3 ON ot2.a=ot3.a)
1353 ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it1);
1354 eval explain $query;
1358 --echo
# Example SQ4.2:
1364 (ot2
JOIN ot3 ON ot2.a=ot3.a)
1365 ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it1);
1366 eval explain $query;
1370 --echo
# Example SQ4.3:
1376 (ot2 LEFT
JOIN ot3 ON ot2.a=ot3.a)
1377 ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it1);
1378 eval explain $query;
1382 --echo
# Example SQ4.4:
1388 (ot2 LEFT
JOIN ot3 ON ot2.a=ot3.a)
1389 ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it1);
1390 eval explain $query;
1394 --echo
# More test cases
1400 (ot2
JOIN ot3 ON ot2.a=ot3.a+0)
1401 ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it1);
1407 (ot2
JOIN ot3 ON ot2.a=ot3.a)
1408 ON ot1.a=ot2.a+0 AND ot1.a IN (SELECT a FROM it1);
1414 (ot2
JOIN ot3 ON ot2.a=ot3.a)
1415 ON ot1.a=ot2.a AND ot1.a IN (SELECT a+0 FROM it1);
1421 (ot2
JOIN ot3 ON ot2.a=ot3.a+0)
1422 ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it1);
1428 (ot2
JOIN ot3 ON ot2.a=ot3.a)
1429 ON ot1.a=ot2.a+0 AND ot1.a IN (SELECT a FROM it1);
1435 (ot2
JOIN ot3 ON ot2.a=ot3.a)
1436 ON ot1.a=ot2.a AND ot1.a IN (SELECT a+0 FROM it1);
1442 (ot2 LEFT
JOIN ot3 ON ot2.a=ot3.a+0)
1443 ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it1);
1449 (ot2 LEFT
JOIN ot3 ON ot2.a=ot3.a)
1450 ON ot1.a=ot2.a+0 AND ot1.a IN (SELECT a FROM it1);
1456 (ot2 LEFT
JOIN ot3 ON ot2.a=ot3.a)
1457 ON ot1.a=ot2.a AND ot1.a IN (SELECT a+0 FROM it1);
1463 (ot2 LEFT
JOIN ot3 ON ot2.a=ot3.a+0)
1464 ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it1);
1470 (ot2 LEFT
JOIN ot3 ON ot2.a=ot3.a)
1471 ON ot1.a=ot2.a+0 AND ot1.a IN (SELECT a FROM it1);
1477 (ot2 LEFT
JOIN ot3 ON ot2.a=ot3.a)
1478 ON ot1.a=ot2.a AND ot1.a IN (SELECT a+0 FROM it1);
1484 (ot2 LEFT
JOIN ot3 ON ot2.a=ot3.a)
1485 ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it1)
1494 (ot2 LEFT
JOIN ot3 ON ot2.a=ot3.a
1495 LEFT
JOIN ot1 AS ot4 ON ot3.a=ot4.a)
1496 ON ot1.a=ot2.a AND ot1.a IN (SELECT a FROM it1);
1498 DROP
TABLE ot1,ot2,ot3,it1,it2,it3;
1501 a INTEGER DEFAULT NULL
1503 INSERT INTO t VALUES (1);
1506 a INTEGER DEFAULT NULL
1508 INSERT INTO t2 VALUES (1),(1);
1511 a INTEGER DEFAULT NULL
1513 INSERT INTO t4 VALUES (1),(1);
1516 a INTEGER DEFAULT NULL
1518 INSERT INTO v VALUES (1),(1);
1526 ON t3.a IN (SELECT a FROM t AS it)
1531 WHERE t1.a IN (SELECT * FROM v AS it2);
1532 eval explain $query;
1535 DROP
TABLE t,t2,t4,v;
1537 --echo
# End of WL#5561
1540 --echo # Bug#48868: Left outer join in subquery causes segmentation fault in
1541 --echo # make_join_select.
1543 CREATE
TABLE t1 (i INTEGER);
1544 INSERT INTO t1 VALUES (1);
1545 INSERT INTO t1 VALUES (2);
1546 CREATE
TABLE t2 (i INTEGER);
1547 INSERT INTO t2 VALUES(1);
1548 CREATE
TABLE t3 (i INTEGER);
1549 INSERT INTO t3 VALUES (1);
1550 INSERT INTO t3 VALUES (2);
1552 SELECT * FROM t1 WHERE (t1.i) IN
1553 (SELECT t2.i FROM t2 LEFT
JOIN t3 ON t2.i=t3.i);
1555 DROP
TABLE t1, t2, t3;
1558 --echo Bug
#37899: Wrongly checked optimization prerequisite caused failed
1563 `varchar_nokey` varchar(5)
1566 INSERT INTO t1 VALUES
1567 (1,
'qk'),(2,
'j'),(3,
'aew');
1571 WHERE varchar_nokey IN (
1580 --echo # BUG#41842: Semi-join materialization strategy crashes when the upper
query has HAVING
1584 pk
int(11) NOT NULL AUTO_INCREMENT,
1585 int_nokey
int(11) NOT NULL,
1586 time_key time NOT NULL,
1587 datetime_key datetime NOT NULL,
1588 datetime_nokey datetime NOT NULL,
1589 varchar_key varchar(1) NOT NULL,
1590 varchar_nokey varchar(1) NOT NULL,
1592 KEY time_key (time_key),
1593 KEY datetime_key (datetime_key),
1594 KEY varchar_key (varchar_key)
1596 INSERT INTO t1 VALUES
1597 (1,0,
'00:16:10',
'2008-09-03 14:25:40',
'2008-09-03 14:25:40',
'h',
'h'),
1598 (2,7,
'00:00:00',
'2001-01-13 00:00:00',
'2001-01-13 00:00:00',
'',
''),
1599 (3,0,
'00:00:00',
'0000-00-00 00:00:00',
'0000-00-00 00:00:00',
'x',
'x'),
1600 (4,2,
'16:29:24',
'2000-10-16 01:39:08',
'2000-10-16 01:39:08',
'w',
'w'),
1601 (5,1,
'09:23:32',
'0000-00-00 00:00:00',
'0000-00-00 00:00:00',
'p',
'p'),
1602 (6,3,
'00:00:00',
'2007-12-02 00:00:00',
'2007-12-02 00:00:00',
'o',
'o'),
1603 (7,3,
'00:00:00',
'2008-09-11 00:00:00',
'2008-09-11 00:00:00',
'',
''),
1604 (8,0,
'13:59:04',
'0000-00-00 00:00:00',
'0000-00-00 00:00:00',
's',
's'),
1605 (9,7,
'09:01:06',
'0000-00-00 00:00:00',
'0000-00-00 00:00:00',
'd',
'd'),
1606 (10,5,
'00:00:00',
'0000-00-00 00:00:00',
'0000-00-00 00:00:00',
'n',
'n'),
1607 (11,0,
'21:06:46',
'0000-00-00 00:00:00',
'0000-00-00 00:00:00',
'o',
'o'),
1608 (12,2,
'00:00:00',
'0000-00-00 00:00:00',
'0000-00-00 00:00:00',
'',
''),
1609 (13,6,
'14:45:34',
'2003-07-28 02:34:08',
'2003-07-28 02:34:08',
'w',
'w'),
1610 (14,1,
'15:04:12',
'0000-00-00 00:00:00',
'0000-00-00 00:00:00',
'o',
'o'),
1611 (15,0,
'00:00:00',
'0000-00-00 00:00:00',
'0000-00-00 00:00:00',
'x',
'x'),
1612 (16,0,
'15:55:23',
'2004-03-17 00:32:27',
'2004-03-17 00:32:27',
'p',
'p'),
1613 (17,1,
'16:30:00',
'2004-12-27 19:20:00',
'2004-12-27 19:20:00',
'd',
'd'),
1614 (18,0,
'00:00:00',
'0000-00-00 00:00:00',
'0000-00-00 00:00:00',
'h',
'h'),
1615 (19,0,
'14:13:26',
'2008-11-09 05:53:48',
'2008-11-09 05:53:48',
'o',
'o'),
1616 (20,0,
'00:00:00',
'2009-10-11 06:58:04',
'2009-10-11 06:58:04',
'k',
'k');
1619 pk
int(11) NOT NULL AUTO_INCREMENT,
1620 int_nokey
int(11) NOT NULL,
1621 time_key time NOT NULL,
1622 datetime_key datetime NOT NULL,
1623 datetime_nokey datetime NOT NULL,
1624 varchar_key varchar(1) NOT NULL,
1625 varchar_nokey varchar(1) NOT NULL,
1627 KEY time_key (time_key),
1628 KEY datetime_key (datetime_key),
1629 KEY varchar_key (varchar_key)
1631 INSERT INTO t2 VALUES
1632 (10,0,
'19:39:13',
'0000-00-00 00:00:00',
'0000-00-00 00:00:00',
'g',
'g'),
1633 (11,8,
'03:43:53',
'0000-00-00 00:00:00',
'0000-00-00 00:00:00',
'b',
'b');
1634 SELECT OUTR.datetime_nokey AS X FROM t1 AS OUTR
1636 OUTR.varchar_nokey IN (SELECT
1637 INNR . varchar_nokey AS Y
1640 INNR . datetime_key >= INNR . time_key OR
1641 INNR . pk = INNR . int_nokey
1643 AND OUTR . varchar_nokey <=
'w'
1644 HAVING X >
'2012-12-12';
1648 --echo Bug#46797
"Crash in fix_semijoin_strategies_for_picked_join_order
1649 --echo with semijoin=on"
1652 varchar_key varchar(1) DEFAULT NULL,
1653 KEY varchar_key (varchar_key)
1657 varchar_key varchar(1) DEFAULT NULL,
1658 KEY varchar_key (varchar_key)
1660 INSERT INTO t2 VALUES
1661 (NULL),(NULL),(NULL),(NULL),(
'a'),(
'a'),(
'a'),(
'b'),(
'b'),(
'b'),(
'b'),(
'c'),
1662 (
'c'),(
'c'),(
'c'),(
'c'),(
'c'),(
'c'),(
'd'),(
'd'),(
'd'),(
'd'),(
'd'),(
'd'),(
'e'),
1663 (
'e'),(
'e'),(
'e'),(
'e'),(
'e'),(
'f'),(
'f'),(
'f'),(
'g'),(
'g'),(
'h'),(
'h'),(
'h'),
1664 (
'h'),(
'i'),(
'j'),(
'j'),(
'j'),(
'k'),(
'k'),(
'l'),(
'l'),(
'm'),(
'm'),(
'm'),(
'm'),
1665 (
'n'),(
'n'),(
'n'),(
'o'),(
'o'),(
'o'),(
'p'),(
'p'),(
'p'),(
'q'),(
'q'),(
'q'),(
'r'),
1666 (
'r'),(
'r'),(
'r'),(
's'),(
's'),(
's'),(
's'),(
't'),(
't'),(
't'),(
't'),(
'u'),(
'u'),
1667 (
'u'),(
'u'),(
'v'),(
'v'),(
'v'),(
'v'),(
'w'),(
'w'),(
'w'),(
'w'),(
'w'),(
'w'),(
'x'),
1668 (
'x'),(
'x'),(
'y'),(
'y'),(
'y'),(
'y'),(
'z'),(
'z'),(
'z'),(
'z');
1671 varchar_key varchar(1) DEFAULT NULL,
1672 KEY varchar_key (varchar_key)
1673 ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
1674 INSERT INTO t3 VALUES
1675 (NULL),('c'),('d'),('e'),('f'),('h'),('j'),('k'),('k'),('m'),('m'),('m'),
1676 ('
n'),('o'),('r'),('t'),('t'),('u'),('w'),('y');
1678 SELECT varchar_key FROM t3
1679 WHERE (SELECT varchar_key FROM t3
1680 WHERE (varchar_key,varchar_key)
1681 IN (SELECT t1.varchar_key, t2 .varchar_key
1682 FROM t1 RIGHT
JOIN t2 ON t1.varchar_key
1686 DROP
TABLE t1, t2, t3;
1690 --echo # Bug#46556 Returning incorrect, empty results
for some IN subqueries
1691 --echo # w/semijoin=on
1703 VALUES (1,
'g',
'g'), (2,
'v',
'v'), (3,
't',
't'), (4,
'u',
'u'), (5,
'n',
'n');
1705 EXPLAIN EXTENDED SELECT vkey FROM t0 WHERE pk IN
1706 (SELECT t1.pk FROM t0 t1
JOIN t0 t2 ON t2.vkey = t1.vnokey);
1708 SELECT vkey FROM t0 WHERE pk IN
1709 (SELECT t1.pk FROM t0 t1
JOIN t0 t2 ON t2.vkey = t1.vnokey);
1713 --echo # End of bug#46556
1716 # The following test case fails when executed with subquery materialization
1717 # (Bug#54281). Hence, skip it if semijoin=off and materialization=on
1718 if (`select (locate(
'materialization', @@optimizer_switch) = 0) OR locate(
'semijoin=on', @@optimizer_switch) + locate(
'materialization=off', @@optimizer_switch) > 0`)
1722 --echo Bug#48834: Procedure with
view + subquery + semijoin=on
1723 --echo crashes on second call.
1726 CREATE
TABLE t1 ( t1field integer, primary key (t1field));
1727 CREATE
TABLE t2 ( t2field integer, primary key (t2field));
1730 SELECT t1field as v1field
1732 WHERE A.t1field IN (SELECT t1field FROM t2 );
1735 SELECT t2field as v2field
1737 WHERE A.t2field IN (SELECT t2field FROM t2 );
1740 CREATE PROCEDURE p1 ()
1744 WHERE v1field IN ( SELECT v2field as vf_inner FROM v2 );
1748 INSERT INTO t1 VALUES (1),(2),(3);
1749 INSERT INTO t2 VALUES (2),(3),(4);
1758 --echo
# End of BUG#48834
1763 --echo # Bug#46692
"Crash occurring on queries with nested FROM subqueries
1764 --echo # using materialization."
1767 pk INTEGER PRIMARY
KEY,
1769 KEY int_key(int_key)
1771 INSERT INTO t1 VALUES (10,186),(11,NULL),(12,2),(13,3),(14,0),(15,133),(16,1);
1774 pk INTEGER PRIMARY KEY,
1776 KEY int_key(int_key)
1778 INSERT INTO t2 VALUES (1,7),(2,2);
1780 SELECT * FROM t1 WHERE (140, 4) IN
1781 (SELECT t2.int_key, t2 .pk FROM t2 STRAIGHT_JOIN t1 ON t2.int_key);
1786 --echo # Bug#42353
"SELECT ... WHERE oe IN (SELECT w/ LEFT JOIN) query
1787 --echo # causes crash."
1790 pk INTEGER PRIMARY KEY,
1794 datetime_nokey DATETIME,
1795 varchar_nokey VARCHAR(1)
1803 pk INTEGER PRIMARY KEY,
1806 varchar_key VARCHAR(1),
1807 varchar_nokey VARCHAR(1),
1808 KEY date_key (date_key)
1811 SELECT date_key FROM t1
1812 WHERE (int_key, int_nokey)
1813 IN (SELECT t3.int_nokey, t3.pk
1814 FROM t2 LEFT
JOIN t3 ON (t2.date_nokey < t3.date_key)
1815 WHERE t3.varchar_key <= t3.varchar_nokey OR t3.int_nokey <= t3.pk
1817 AND (varchar_nokey <> 'f' OR NOT int_key < 7);
1821 --echo # Bug#45933
"Crash in optimize_semijoin_nests on JOIN in subquery
1822 --echo # + AND in outer query".
1824 INSERT INTO t1 VALUES (10,7,5,
'2009-06-16',
'2002-04-10 14:25:30',
'w'),
1825 (11,7,0,
'0000-00-00',
'0000-00-00 00:00:00',
's'),
1826 (12,4,0,
'2003-07-14',
'2006-09-14 04:01:02',
'y'),
1827 (13,0,4,
'2002-07-25',
'0000-00-00 00:00:00',
'c'),
1828 (14,1,8,
'2007-07-03',
'0000-00-00 00:00:00',
'q'),
1829 (15,6,5,
'2001-11-12',
'0000-00-00 00:00:00',
''),
1830 (16,2,9,
'0000-00-00',
'0000-00-00 00:00:00',
'j'),
1831 (29,9,1,
'0000-00-00',
'2003-08-11 00:00:00',
'm');
1832 INSERT INTO t3 VALUES (1,9,
'0000-00-00',
'b',
'b'),
1833 (2,2,
'2002-09-17',
'h',
'h');
1835 SELECT t1.varchar_nokey FROM t1
JOIN t3 ON t1.datetime_nokey
1836 WHERE t1.varchar_nokey
1837 IN (SELECT varchar_nokey FROM t1
1839 IN (SELECT t3.int_nokey
1840 FROM t3 LEFT
JOIN t1 ON t1.varchar_nokey
1841 WHERE t3.date_key BETWEEN
'2008-06-07' AND
'2006-06-26'
1845 DROP
TABLE t1, t2, t3;
1848 --echo # Bug#45219
"Crash on SELECT DISTINCT query containing a
1849 --echo # LEFT JOIN in subquery"
1853 pk INTEGER NOT NULL,
1854 int_nokey INTEGER NOT NULL,
1855 datetime_key DATETIME NOT NULL,
1856 varchar_key VARCHAR(1) NOT NULL,
1858 KEY datetime_key (datetime_key),
1859 KEY varchar_key (varchar_key)
1861 INSERT INTO t1 VALUES
1862 (1,9,
'0000-00-00 00:00:00',
'p'),(2,0,
'2002-02-09 07:38:13',
'v'),
1863 (3,8,
'2001-05-03 12:08:14',
't'),(4,3,
'0000-00-00 00:00:00',
'u'),
1864 (5,7,
'2009-07-28 03:43:30',
'n'),(6,0,
'2009-08-04 00:00:00',
'l'),
1865 (7,1,
'0000-00-00 00:00:00',
'h'),(8,9,
'0000-00-00 00:00:00',
'u'),
1866 (9,0,
'2005-08-02 17:16:54',
'n'),(10,9,
'2002-12-21 00:00:00',
'j'),
1867 (11,0,
'2005-08-15 12:37:35',
'k'),(12,5,
'0000-00-00 00:00:00',
'e'),
1868 (13,0,
'2006-03-10 00:00:00',
'i'),(14,8,
'2005-05-16 11:02:36',
'u'),
1869 (15,8,
'2008-11-02 00:00:00',
'n'),(16,5,
'2006-03-15 00:00:00',
'b'),
1870 (17,1,
'0000-00-00 00:00:00',
'x'),(18,7,
'0000-00-00 00:00:00',
''),
1871 (19,0,
'2008-12-17 20:15:40',
'q'),(20,9,
'0000-00-00 00:00:00',
'u');
1873 CREATE
TABLE t2 LIKE t1;
1874 INSERT INTO t2 VALUES
1875 (10,0,
'2006-07-07 07:26:28',
'q'),(11,5,
'2002-09-23 00:00:00',
'm'),
1876 (12,7,
'0000-00-00 00:00:00',
'j'),(13,1,
'2006-06-07 00:00:00',
'z'),
1877 (14,8,
'2000-09-16 12:15:34',
'a'),(15,2,
'2007-08-05 15:47:52',
''),
1878 (16,1,
'0000-00-00 00:00:00',
'e'),(17,8,
'2005-12-02 19:34:26',
't'),
1879 (18,5,
'0000-00-00 00:00:00',
'q'),(19,4,
'0000-00-00 00:00:00',
'b'),
1880 (20,5,
'2007-12-28 00:00:00',
'w'),(21,3,
'2004-08-02 11:48:43',
'm'),
1881 (22,0,
'0000-00-00 00:00:00',
'x'),(23,8,
'2004-04-19 12:18:43',
''),
1882 (24,0,
'2009-04-27 00:00:00',
'w'),(25,4,
'2006-10-20 14:52:15',
'x'),
1883 (26,0,
'0000-00-00 00:00:00',
'e'),(27,0,
'2002-03-22 11:48:37',
'e'),
1884 (28,2,
'0000-00-00 00:00:00',
'p'),(29,0,
'2001-01-04 03:55:07',
'x');
1886 CREATE
TABLE t3 LIKE t1;
1887 INSERT INTO t3 VALUES
1888 (10,8,
'2007-08-19 08:08:38',
'i'),(11,0,
'2000-05-21 03:51:51',
'');
1890 SELECT DISTINCT datetime_key FROM t1
1891 WHERE (int_nokey, pk)
1892 IN (SELECT t3.pk, t3.pk FROM t2 LEFT
JOIN t3 ON t3.varchar_key)
1895 DROP
TABLE t1, t2, t3;
1898 --echo # Bug#46550 Azalea returning duplicate results
for some IN subqueries
1899 --echo # w/ semijoin=on
1903 DROP
TABLE IF EXISTS t0, t1, t2;
1907 int_key
int(11) DEFAULT NULL,
1908 varchar_key varchar(1) DEFAULT NULL,
1909 varchar_nokey varchar(1) DEFAULT NULL,
1910 KEY int_key (int_key),
1911 KEY varchar_key (varchar_key,int_key)
1914 INSERT INTO t0 VALUES
1937 int_key
int(11) DEFAULT NULL,
1938 varchar_key varchar(1) DEFAULT NULL,
1939 varchar_nokey varchar(1) DEFAULT NULL,
1940 KEY int_key (int_key),
1941 KEY varchar_key (varchar_key,int_key)
1943 INSERT INTO t1 VALUES (7,NULL,NULL),(4,
'x',
'x');
1946 int_key
int(11) DEFAULT NULL,
1947 varchar_key varchar(1) DEFAULT NULL,
1948 varchar_nokey varchar(1) DEFAULT NULL,
1949 KEY int_key (int_key),
1950 KEY varchar_key (varchar_key,int_key)
1952 INSERT INTO t2 VALUES (123,NULL,NULL);
1956 WHERE varchar_nokey IN (
1957 SELECT t1 .varchar_key from t1
1961 WHERE t0.varchar_nokey IN (
1962 SELECT t1_1 .varchar_key
1963 FROM t1 AS t1_1
JOIN t1 AS t1_2 ON t1_1 .int_key
1969 WHERE t0.varchar_nokey IN (
1970 SELECT t1_1 .varchar_key
1971 FROM t1 AS t1_1
JOIN t1 AS t1_2 ON t1_1 .int_key
1976 WHERE t0.varchar_nokey IN (
1977 SELECT t1_1 .varchar_key
1978 FROM t1 AS t1_1
JOIN t1 AS t1_2 ON t1_1 .int_key
1984 WHERE t0.varchar_nokey IN (
1985 SELECT t1_1 .varchar_key
1986 FROM t1 AS t1_1
JOIN t1 AS t1_2 ON t1_1 .int_key
1989 DROP
TABLE t0, t1, t2;
1991 --echo # End of bug#46550
1996 --echo Bug #48073 Subquery on
char columns from
view crashes Mysql
2000 DROP
TABLE IF EXISTS t1, t2;
2001 DROP VIEW IF EXISTS v1;
2005 city VARCHAR(50) NOT NULL,
2006 country_id SMALLINT UNSIGNED NOT NULL
2009 INSERT INTO t1 VALUES
2017 country_id SMALLINT UNSIGNED NOT NULL,
2018 country VARCHAR(50) NOT NULL
2021 INSERT INTO t2 VALUES
2023 (3,
'American Samoa') ;
2026 SELECT country_id, country
2028 WHERE LEFT(country,1) =
"A"
2031 SELECT city, country_id
2036 WHERE LEFT(country, 1) =
"A"
2039 SELECT city, country_id
2049 --echo # End of bug#48073
2052 --echo Bug#49097 subquery with
view generates wrong result with
2057 DROP
TABLE IF EXISTS t1, t2;
2058 DROP VIEW IF EXISTS v1;
2062 city VARCHAR(50) NOT NULL,
2063 country_id SMALLINT UNSIGNED NOT NULL
2066 INSERT INTO t1 VALUES
2074 country_id SMALLINT UNSIGNED NOT NULL,
2075 country VARCHAR(50) NOT NULL
2078 INSERT INTO t2 VALUES
2080 (3,
'XAmerican Samoa') ;
2083 SELECT country_id, country
2085 WHERE LEFT(country,1) =
"A"
2088 SELECT city, country_id
2090 WHERE country_id IN (
2093 WHERE LEFT(country,1) =
"A"
2096 SELECT city, country_id
2098 WHERE country_id IN (
2105 SELECT city, country_id
2107 WHERE country_id IN (
2115 deallocate prepare stmt;
2119 --echo # End of Bug#49097
2122 --echo # Bug#49198 Wrong result
for second call of procedure
2123 --echo # with
view in subselect.
2126 CREATE
TABLE t1 (t1field integer, primary key (t1field));
2127 CREATE
TABLE t2 (t2field integer, primary key (t2field));
2128 CREATE
TABLE t3 (t3field integer, primary key (t3field));
2130 CREATE VIEW v2 AS SELECT * FROM t2;
2131 CREATE VIEW v3 AS SELECT * FROM t3;
2133 INSERT INTO t1 VALUES(1),(2);
2134 INSERT INTO t2 VALUES(1),(2);
2135 INSERT INTO t3 VALUES(1),(2);
2141 WHERE t1field IN (SELECT * FROM v2);
2152 WHERE t1field IN (SELECT * FROM v2)
2153 AND t1field IN (SELECT * FROM v3)
2159 DROP
TABLE t1, t2, t3;
2162 --echo # End of Bug#49198
2165 --echo # Bug#48623 Multiple subqueries are optimized incorrectly
2168 CREATE
TABLE ot(val VARCHAR(10));
2169 CREATE
TABLE it1(val VARCHAR(10));
2170 CREATE
TABLE it2(val VARCHAR(10));
2172 INSERT INTO ot VALUES(
'aaa'), (
'bbb'), (
'eee'), (
'mmm'), (
'ppp');
2173 INSERT INTO it1 VALUES(
'aaa'), (
'aaa'), (
'bbb'), (
'eee'), (
'mmm'), (
'ppp');
2174 INSERT INTO it2 VALUES(
'aaa'), (
'bbb'), (
'eee'), (
'mmm'), (
'ppp');
2179 WHERE ot.val IN (SELECT it1.val FROM it1
2180 WHERE it1.val LIKE
'a%' OR it1.val LIKE
'e%')
2181 AND ot.val IN (SELECT it2.val FROM it2
2182 WHERE it2.val LIKE
'a%' OR it2.val LIKE
'e%');
2186 WHERE ot.val IN (SELECT it1.val FROM it1
2187 WHERE it1.val LIKE
'a%' OR it1.val LIKE
'e%')
2188 AND ot.val IN (SELECT it2.val FROM it2
2189 WHERE it2.val LIKE
'a%' OR it2.val LIKE
'e%');
2195 --echo # End of Bug#48623
2198 --echo # Bug #51487 Assertion failure when semi-join flattening occurs
2199 --echo #
for a subquery in HAVING
2202 CREATE
TABLE t1 (a INT, b INT);
2203 INSERT INTO t1 VALUES (1,10),(2,11),(1,13);
2205 CREATE
TABLE t2 AS SELECT * FROM t1;
2206 CREATE
TABLE t3 AS SELECT * FROM t1;
2208 SELECT COUNT(*) FROM t1
2210 HAVING t1.a IN (SELECT t3.a FROM t3
2211 WHERE t3.b IN (SELECT b FROM t2 WHERE t2.a=t1.a));
2213 DROP
TABLE t1, t2, t3;
2215 --echo
# End of Bug#51487
2218 --echo # BUG#38075: Wrong result: rows matching a subquery with outer join not returned
2222 DROP
TABLE IF EXISTS ot1, it1, it2;
2226 int_key
int(11) NOT NULL,
2227 datetime_key datetime NOT NULL,
2228 KEY int_key (int_key),
2229 KEY datetime_key (datetime_key)
2231 INSERT INTO it2 VALUES
2232 (5,
'2002-04-10 14:25:30'), (0,
'0000-00-00 00:00:00'),
2233 (0,
'2006-09-14 04:01:02'), (4,
'0000-00-00 00:00:00'),
2234 (8,
'0000-00-00 00:00:00'), (5,
'0000-00-00 00:00:00'),
2235 (9,
'0000-00-00 00:00:00'), (8,
'2007-04-01 11:04:17'),
2236 (1,
'0000-00-00 00:00:00'), (7,
'2009-01-12 00:00:00'),
2237 (0,
'2009-06-05 00:00:00'), (3,
'2006-02-14 18:06:35'),
2238 (5,
'2006-02-21 07:08:16'), (0,
'0000-00-00 00:00:00'),
2239 (7,
'0000-00-00 00:00:00'), (0,
'0000-00-00 00:00:00'),
2240 (0,
'2007-02-13 00:00:00'), (1,
'0000-00-00 00:00:00'),
2241 (0,
'0000-00-00 00:00:00'), (1,
'2003-08-11 00:00:00');
2243 int_nokey
int(11) NOT NULL,
2244 int_key
int(11) NOT NULL,
2245 KEY int_key (int_key)
2247 INSERT INTO ot1 VALUES
2248 (5,0), (3,0), (0,2), (3,0), (1,3), (0,0), (1,7), (7,0), (1,7), (0,7),
2249 (0,9), (8,2), (4,4), (9,3), (0,9), (2,5), (0,5), (8,0), (5,8), (1,5);
2251 int_nokey
int(11) NOT NULL,
2252 int_key
int(11) NOT NULL,
2253 KEY int_key (int_key)
2255 INSERT INTO it1 VALUES
2258 SELECT int_key FROM ot1
2259 WHERE int_nokey IN (SELECT it2.int_key
2260 FROM it1 LEFT
JOIN it2 ON it2.datetime_key);
2262 SELECT int_key FROM ot1
2263 WHERE int_nokey IN (SELECT it2.int_key
2264 FROM it1 LEFT
JOIN it2 ON it2.datetime_key);
2265 DROP
TABLE ot1, it1, it2;
2267 --echo # End of BUG#38075
2270 --echo # BUG#50089: Second call of procedure with
view in subselect crashes server
2273 CREATE
TABLE t1(t1field INTEGER, PRIMARY KEY(t1field));
2276 SELECT t1field AS v1field
2278 WHERE a.t1field IN (SELECT t1field FROM t1);
2280 INSERT INTO t1 VALUES(1),(2);
2284 WHERE t1field IN (SELECT v1field FROM v1);
2289 WHERE t1field IN (SELECT v1field FROM v1);
2293 FROM t1 LEFT
JOIN t1 AS t2 ON t1.t1field IN (SELECT v1field FROM v1);
2298 WHERE t1field IN (SELECT v1field FROM v1);
2301 CREATE PROCEDURE p1()
2305 WHERE t1field IN (SELECT v1field FROM v1);
2316 WHERE t1field IN (SELECT v1field FROM v1);
2326 --echo
# End of BUG#50089
2329 --echo # Bug#45191: Incorrectly initialized semi-join led
to a wrong result.
2331 CREATE
TABLE STAFF (EMPNUM CHAR(3) NOT NULL,
2332 EMPNAME CHAR(20), GRADE DECIMAL(4), CITY CHAR(15));
2334 CREATE
TABLE PROJ (PNUM CHAR(3) NOT NULL,
2335 PNAME CHAR(20), PTYPE CHAR(6),
2339 CREATE
TABLE WORKS (EMPNUM CHAR(3) NOT NULL,
2340 PNUM CHAR(3) NOT NULL, HOURS DECIMAL(5));
2341 INSERT INTO STAFF VALUES (
'E1',
'Alice',12,
'Deale');
2342 INSERT INTO STAFF VALUES (
'E2',
'Betty',10,
'Vienna');
2343 INSERT INTO STAFF VALUES (
'E3',
'Carmen',13,
'Vienna');
2344 INSERT INTO STAFF VALUES (
'E4',
'Don',12,
'Deale');
2345 INSERT INTO STAFF VALUES (
'E5',
'Ed',13,
'Akron');
2347 INSERT INTO PROJ VALUES (
'P1',
'MXSS',
'Design',10000,
'Deale');
2348 INSERT INTO PROJ VALUES (
'P2',
'CALM',
'Code',30000,
'Vienna');
2349 INSERT INTO PROJ VALUES (
'P3',
'SDP',
'Test',30000,
'Tampa');
2350 INSERT INTO PROJ VALUES (
'P4',
'SDP',
'Design',20000,
'Deale');
2351 INSERT INTO PROJ VALUES (
'P5',
'IRM',
'Test',10000,
'Vienna');
2352 INSERT INTO PROJ VALUES (
'P6',
'PAYR',
'Design',50000,
'Deale');
2354 INSERT INTO WORKS VALUES (
'E1',
'P1',40);
2355 INSERT INTO WORKS VALUES (
'E1',
'P2',20);
2356 INSERT INTO WORKS VALUES (
'E1',
'P3',80);
2357 INSERT INTO WORKS VALUES (
'E1',
'P4',20);
2358 INSERT INTO WORKS VALUES (
'E1',
'P5',12);
2359 INSERT INTO WORKS VALUES (
'E1',
'P6',12);
2360 INSERT INTO WORKS VALUES (
'E2',
'P1',40);
2361 INSERT INTO WORKS VALUES (
'E2',
'P2',80);
2362 INSERT INTO WORKS VALUES (
'E3',
'P2',20);
2363 INSERT INTO WORKS VALUES (
'E4',
'P2',20);
2364 INSERT INTO WORKS VALUES (
'E4',
'P4',40);
2365 INSERT INTO WORKS VALUES (
'E4',
'P5',80);
2367 explain SELECT EMPNUM, EMPNAME
2370 (SELECT EMPNUM FROM WORKS
2372 (SELECT PNUM FROM PROJ));
2374 SELECT EMPNUM, EMPNAME
2377 (SELECT EMPNUM FROM WORKS
2379 (SELECT PNUM FROM PROJ));
2381 drop
table STAFF,WORKS,PROJ;
2383 --echo # End of bug#45191
2386 --echo # BUG#36896: Server crash on SELECT FROM DUAL
2388 create
table t1 (a
int);
2389 select 1 as res from dual where (1) in (select * from t1);
2393 --echo BUG
#40118 Crash when running Batched Key Access and requiring one match for each key
2395 create
table t0(a
int);
2396 insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
2397 create
table t1 (a
int, key(a));
2398 insert into t1 select * from t0;
2399 alter
table t1 add b
int not null, add filler char(200);
2400 insert into t1 select * from t1;
2401 insert into t1 select * from t1;
2403 select * from t0 where t0.a in (select t1.a from t1 where t1.b=0);
2407 --echo # BUG#32665 Query with dependent subquery is too slow
2410 idIndividual
int primary key
2412 insert into t1 values (1),(2);
2415 idContact
int primary key,
2419 insert into t2 values (1,1,1),(2,2,2),(3,3,3);
2422 idAddress
int primary key,
2424 postalStripped varchar(100)
2427 insert into t3 values (1,1,
'foo'), (2,2,
'bar');
2429 --echo The following must be converted
to a semi-join:
2430 explain extended SELECT a.idIndividual FROM t1 a
2431 WHERE a.idIndividual IN
2432 ( SELECT c.idObj FROM t3 cona
2433 INNER
JOIN t2 c ON c.idContact=cona.idContact
2434 WHERE cona.postalStripped=
'T2H3B2'
2436 drop
table t1,t2,t3;
2439 # Bug#11867 queries with ROW(,elems>) IN (SELECT DISTINCT <cols> FROM ...)
2442 CREATE
TABLE t1 (one
int, two
int, flag
char(1));
2443 CREATE
TABLE t2 (one
int, two
int, flag
char(1));
2444 INSERT INTO t1 VALUES(1,2,
'Y'),(2,3,
'Y'),(3,4,
'Y'),(5,6,
'N'),(7,8,
'N');
2445 INSERT INTO t2 VALUES(1,2,
'Y'),(2,3,
'Y'),(3,4,
'Y'),(5,6,
'N'),(7,8,
'N');
2448 WHERE ROW(one,two) IN (SELECT DISTINCT one,two FROM t2 WHERE flag = 'N');
2450 WHERE ROW(one,two) IN (SELECT DISTINCT one,two FROM t1 WHERE flag = 'N');
2452 insert into t2 values (null,null,'N');
2453 insert into t2 values (null,3,'0');
2454 insert into t2 values (null,5,'0');
2455 insert into t2 values (10,null,'0');
2456 insert into t1 values (10,3,'0');
2457 insert into t1 values (10,5,'0');
2458 insert into t1 values (10,10,'0');
2459 SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N') as '
test' from t1;
2460 SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N');
2461 SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N'
group by one,two) as '
test' from t1;
2462 SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0') as '
test' from t1;
2463 SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0'
group by one,two) as '
test' from t1;
2464 explain extended SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0') as '
test' from t1;
2465 explain extended SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N');
2466 explain extended SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0'
group by one,two) as '
test' from t1;
2471 # Bug#12392 where cond with IN predicate for rows and NULL values in table
2474 CREATE
TABLE t1 (a
char(5), b
char(5));
2475 INSERT INTO t1 VALUES (NULL,
'aaa'), (
'aaa',
'aaa');
2477 SELECT * FROM t1 WHERE (a,b) IN (('aaa','aaa'), ('aaa','bbb'));
2483 # Bug#30788 Inconsistent retrieval of char/varchar
2486 CREATE
TABLE t1 (a CHAR(1), b VARCHAR(10));
2487 INSERT INTO t1 VALUES (
'a',
'aa');
2488 INSERT INTO t1 VALUES (
'a',
'aaa');
2489 SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
2490 CREATE INDEX I1 ON t1 (a);
2491 CREATE INDEX I2 ON t1 (b);
2492 EXPLAIN SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
2493 SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);
2495 CREATE
TABLE t2 (a VARCHAR(1), b VARCHAR(10));
2496 INSERT INTO t2 SELECT * FROM t1;
2497 CREATE INDEX I1 ON t2 (a);
2498 CREATE INDEX I2 ON t2 (b);
2499 EXPLAIN SELECT a,b FROM t2 WHERE b IN (SELECT a FROM t2);
2500 SELECT a,b FROM t2 WHERE b IN (SELECT a FROM t2);
2502 SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1 WHERE LENGTH(a)<500);
2503 SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1 WHERE LENGTH(a)<500);
2509 --echo # BUG#45928
"Differing query results depending on MRR and
2510 --echo # engine_condition_pushdown settings"
2514 `pk` int(11) NOT NULL AUTO_INCREMENT,
2515 `time_nokey` time NOT NULL,
2516 `varchar_key` varchar(1) NOT NULL,
2517 `varchar_nokey` varchar(1) NOT NULL,
2519 KEY `varchar_key` (`varchar_key`)
2520 ) AUTO_INCREMENT=12 DEFAULT CHARSET=latin1;
2521 INSERT INTO `t1` VALUES (10,'00:00:00','i','i'),(11,'00:00:00','','');
2523 SELECT `time_nokey` G1 FROM t1 WHERE ( `varchar_nokey` , `varchar_key` ) IN (
2524 SELECT `varchar_nokey` , `varchar_nokey` ) AND `varchar_key` >= 'c' HAVING G1
ORDER
2530 --echo # BUG#45863
"Assertion failed: (fixed == 0), function fix_fields(),
2531 --echo # file item.cc, line 4448"
2538 varchar_nokey varchar(1) NOT NULL
2540 INSERT INTO C VALUES
2541 (
'k'),(
'a'),(
''),(
'u'),(
'e'),(
'v'),(
'i'),
2542 (
't'),(
'u'),(
'f'),(
'u'),(
'm'),(
'j'),(
'f'),
2543 (
'v'),(
'j'),(
'g'),(
'e'),(
'h'),(
'z');
2545 varchar_nokey varchar(1) NOT NULL
2547 INSERT INTO BB VALUES (
'i'),(
't');
2548 -- error ER_BAD_FIELD_ERROR
2549 SELECT varchar_nokey FROM C
2550 WHERE (varchar_nokey, OUTR) IN (SELECT varchar_nokey
2552 -- error ER_BAD_FIELD_ERROR
2553 SELECT varchar_nokey FROM C
2554 WHERE (varchar_nokey, OUTR) IN (SELECT varchar_nokey, varchar_nokey
2559 --echo # During work with BUG#45863 I had problems with a
query that was
2560 --echo # optimized differently in regular and prepared
mode.
2561 --echo # Because there was a bug in one of the selected strategies, I became
2562 --echo # aware of the problem. Adding an EXPLAIN
query to catch this.
2565 DROP
TABLE IF EXISTS t1, t2, t3;
2569 (EMPNUM CHAR(3) NOT NULL,
2575 (PNUM CHAR(3) NOT NULL,
2582 (EMPNUM CHAR(3) NOT NULL,
2583 PNUM CHAR(3) NOT NULL,
2586 INSERT INTO t1 VALUES (
'E1',
'Alice',12,
'Deale');
2587 INSERT INTO t1 VALUES (
'E2',
'Betty',10,
'Vienna');
2588 INSERT INTO t1 VALUES (
'E3',
'Carmen',13,
'Vienna');
2589 INSERT INTO t1 VALUES (
'E4',
'Don',12,
'Deale');
2590 INSERT INTO t1 VALUES (
'E5',
'Ed',13,
'Akron');
2592 INSERT INTO t2 VALUES (
'P1',
'MXSS',
'Design',10000,
'Deale');
2593 INSERT INTO t2 VALUES (
'P2',
'CALM',
'Code',30000,
'Vienna');
2594 INSERT INTO t2 VALUES (
'P3',
'SDP',
'Test',30000,
'Tampa');
2595 INSERT INTO t2 VALUES (
'P4',
'SDP',
'Design',20000,
'Deale');
2596 INSERT INTO t2 VALUES (
'P5',
'IRM',
'Test',10000,
'Vienna');
2597 INSERT INTO t2 VALUES (
'P6',
'PAYR',
'Design',50000,
'Deale');
2599 INSERT INTO t3 VALUES (
'E1',
'P1',40);
2600 INSERT INTO t3 VALUES (
'E1',
'P2',20);
2601 INSERT INTO t3 VALUES (
'E1',
'P3',80);
2602 INSERT INTO t3 VALUES (
'E1',
'P4',20);
2603 INSERT INTO t3 VALUES (
'E1',
'P5',12);
2604 INSERT INTO t3 VALUES (
'E1',
'P6',12);
2605 INSERT INTO t3 VALUES (
'E2',
'P1',40);
2606 INSERT INTO t3 VALUES (
'E2',
'P2',80);
2607 INSERT INTO t3 VALUES (
'E3',
'P2',20);
2608 INSERT INTO t3 VALUES (
'E4',
'P2',20);
2609 INSERT INTO t3 VALUES (
'E4',
'P4',40);
2610 INSERT INTO t3 VALUES (
'E4',
'P5',80);
2612 CREATE UNIQUE INDEX t1_IDX ON t1(EMPNUM);
2614 EXPLAIN SELECT EMPNAME
2622 WHERE PTYPE =
'Design'));
2624 PREPARE stmt FROM
"EXPLAIN SELECT EMPNAME
2632 WHERE PTYPE = 'Design'))";
2635 DEALLOCATE PREPARE stmt;
2637 DROP INDEX t1_IDX ON t1;
2638 CREATE INDEX t1_IDX ON t1(EMPNUM);
2640 EXPLAIN SELECT EMPNAME
2648 WHERE PTYPE =
'Design'));
2650 PREPARE stmt FROM
"EXPLAIN SELECT EMPNAME
2658 WHERE PTYPE = 'Design'))";
2661 DEALLOCATE PREPARE stmt;
2663 DROP INDEX t1_IDX ON t1;
2665 EXPLAIN SELECT EMPNAME
2673 WHERE PTYPE =
'Design'));
2675 PREPARE stmt FROM
"EXPLAIN SELECT EMPNAME
2683 WHERE PTYPE = 'Design'))";
2686 DEALLOCATE PREPARE stmt;
2688 DROP
TABLE t1, t2, t3;
2691 --echo # BUG#45221 Query SELECT pk FROM C WHERE pk IN (SELECT int_key) failing
2698 KEY i1_index (i1_key)
2701 INSERT INTO t1 VALUES (9,1,2), (9,2,1);
2709 INSERT INTO t2 VALUES (9,1);
2717 WHERE t1.i2 < t1.i3 XOR t2.i1 > 1
2718 ORDER BY t1.i2 desc);
2722 --echo # BUG#50361 Doublenested noncorrelated subquery with FirstMatch and join cache wrong result
2728 INSERT INTO t1 VALUES(10),(20);
2729 create
table t2 select * from t1;
2730 create
table t3 select * from t1;
2739 explain extended SELECT *
2749 INSERT INTO t1 VALUES(30),(40),(50),(60),(70),(80),(90);
2750 insert into t2 select * from t1;
2751 insert into t3 select * from t1;
2752 create
table t4 select * from t1;
2781 drop
table t1,t2,t3,t4;
2784 --echo # Bug#53236 Segfault in DTCollation::set(
DTCollation&)
2788 pk INTEGER AUTO_INCREMENT,
2789 col_varchar VARCHAR(1),
2794 INSERT INTO t1 (col_varchar)
2801 FROM ( t1 AS table1
JOIN t1 AS table2 ON (table1.col_varchar =
2802 table2.col_varchar) )
2803 WHERE ( 1, 2 ) IN ( SELECT SUBQUERY1_t1.pk AS SUBQUERY1_field1,
2804 SUBQUERY1_t1.pk AS SUBQUERY1_field2
2805 FROM ( t1 AS SUBQUERY1_t1
JOIN t1 AS SUBQUERY1_t2
2806 ON (SUBQUERY1_t2.col_varchar =
2807 SUBQUERY1_t1.col_varchar) ) )
2813 --echo # BUG#53298
"wrong result with semijoin (no semijoin strategy chosen)"
2816 create
table t1 (uid
int, fid
int);
2817 insert into t1 values (1,1), (3,1);
2819 create
table t2 (uid
int,
name varchar(128));
2820 insert into t2 values (1,
"A"), (2,
"B");
2822 create
table t3 (uid
int, fid
int,
index(uid));
2823 insert into t3 values (1,3), (1,3);
2825 create
table t4 (uid
int);
2826 insert into t4 values (3);
2828 explain select t2.uid from t2, t1
2829 where t1.uid in (select t4.uid from t4, t3 where t3.uid=1 and t4.uid=t3.fid)
2833 select t2.uid from t2, t1
2834 where t1.uid in (select t4.uid from t4, t3 where t3.uid=1 and t4.uid=t3.fid)
2837 drop
table t1,t2,t3,t4;
2841 # BUG#46548 IN-subqueries return 0 rows with materialization=on
2851 INSERT INTO t1 VALUES (1,
'o',
'ffff',
'ffff',
'ffoo'),(2,
'f',
'ffff',
'ffff',
'ffff');
2853 CREATE
TABLE t2 LIKE t1;
2854 INSERT INTO t2 VALUES (1,
'i',
'iiii',
'iiii',
'iiii'),(2,
'f',
'ffff',
'ffff',
'ffff');
2856 EXPLAIN SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0);
2857 SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0);
2858 SELECT pk FROM t1 WHERE (b,c,d) IN (SELECT b,c,d FROM t2 WHERE pk > 0);
2862 # Bug #44303 Assertion failures in Field_new_decimal::store_decimal
2863 # when executing materialized InsideOut semijoin
2865 CREATE
TABLE t1 (f1 INT, f2 DECIMAL(5,3)) ENGINE=MyISAM;
2866 INSERT INTO t1 (f1, f2) VALUES (1, 1.789);
2867 INSERT INTO t1 (f1, f2) VALUES (13, 1.454);
2868 INSERT INTO t1 (f1, f2) VALUES (10, 1.668);
2870 CREATE
TABLE t2 LIKE t1;
2871 INSERT INTO t2 VALUES (1, 1.789);
2872 INSERT INTO t2 VALUES (13, 1.454);
2874 EXPLAIN SELECT COUNT(*) FROM t1 WHERE (f1,f2) IN (SELECT f1,f2 FROM t2);
2875 SELECT COUNT(*) FROM t1 WHERE (f1,f2) IN (SELECT f1,f2 FROM t2);
2881 # Bug #27348: Assertion abort for a query with two subqueries to be flattened
2882 # Bug #35674: Range optimizer ignores conditions on inner tables in
2883 # semi-join IN subqueries
2886 ID
int(11) NOT NULL auto_increment,
2887 Name
char(35) NOT NULL
default '',
2888 Country
char(3) NOT NULL
default '',
2889 Population
int(11) NOT NULL
default '0',
2895 Code
char(3) NOT NULL
default '',
2896 Name
char(52) NOT NULL
default '',
2897 SurfaceArea
float(10,2) NOT NULL
default '0.00',
2898 Population
int(11) NOT NULL
default '0',
2899 Capital
int(11)
default NULL,
2901 UNIQUE INDEX (Name),
2905 Country
char(3) NOT NULL
default '',
2906 Language
char(30) NOT NULL
default '',
2907 Percentage
float(3,1) NOT NULL
default '0.0',
2908 PRIMARY KEY (Country, Language),
2913 INSERT INTO t1 VALUES
2914 (1,
'Kabul',
'AFG',1780000),(2,
'Qandahar',
'AFG',237500),
2915 (3,
'Herat',
'AFG',186800),(4,
'Mazar-e-Sharif',
'AFG',127800),
2916 (5,
'Amsterdam',
'NLD',731200),(6,
'Rotterdam',
'NLD',593321),
2917 (7,
'Haag',
'NLD',440900),(8,
'Utrecht',
'NLD',234323),
2918 (9,
'Eindhoven',
'NLD',201843),(10,
'Tilburg',
'NLD',193238),
2919 (11,
'Groningen',
'NLD',172701),(12,
'Breda',
'NLD',160398),
2920 (13,
'Apeldoorn',
'NLD',153491),(14,
'Nijmegen',
'NLD',152463),
2921 (15,
'Enschede',
'NLD',149544),(16,
'Haarlem',
'NLD',148772),
2922 (17,
'Almere',
'NLD',142465),(18,
'Arnhem',
'NLD',138020),
2923 (19,
'Zaanstad',
'NLD',135621),(20,
'´s-Hertogenbosch',
'NLD',129170),
2924 (21,
'Amersfoort',
'NLD',126270),(22,
'Maastricht',
'NLD',122087),
2925 (23,
'Dordrecht',
'NLD',119811),(24,
'Leiden',
'NLD',117196),
2926 (25,
'Haarlemmermeer',
'NLD',110722),(26,
'Zoetermeer',
'NLD',110214),
2927 (27,
'Emmen',
'NLD',105853),(28,
'Zwolle',
'NLD',105819),
2928 (29,
'Ede',
'NLD',101574),(30,
'Delft',
'NLD',95268);
2930 INSERT INTO t2 VALUES
2931 (
'AFG',
'Afghanistan',652090.00,22720000,1),
2932 (
'NLD',
'Netherlands',41526.00,15864000,5),
2933 (
'ANT',
'Netherlands Antilles',800.00,217000,33),
2934 (
'ALB',
'Albania',28748.00,3401200,34),
2935 (
'DZA',
'Algeria',2381741.00,31471000,35),
2936 (
'ASM',
'American Samoa',199.00,68000,54),
2937 (
'AND',
'Andorra',468.00,78000,55),
2938 (
'AGO',
'Angola',1246700.00,12878000,56),
2939 (
'AIA',
'Anguilla',96.00,8000,62),
2940 (
'ATG',
'Antigua and Barbuda',442.00,68000,63),
2941 (
'ARE',
'United Arab Emirates',83600.00,2441000,65),
2942 (
'ARG',
'Argentina',2780400.00,37032000,69),
2943 (
'ARM',
'Armenia',29800.00,3520000,126),
2944 (
'ABW',
'Aruba',193.00,103000,129),
2945 (
'AUS',
'Australia',7741220.00,18886000,135),
2946 (
'AZE',
'Azerbaijan',86600.00,7734000,144);
2948 INSERT INTO t3 VALUES
2949 (
'AFG',
'Pashto',52.4),(
'NLD',
'Dutch',95.6),
2950 (
'ANT',
'Papiamento',86.2),(
'ALB',
'Albaniana',97.9),
2951 (
'DZA',
'Arabic',86.0),(
'ASM',
'Samoan',90.6),
2952 (
'AND',
'Spanish',44.6),(
'AGO',
'Ovimbundu',37.2),
2953 (
'AIA',
'English',0.0),(
'ATG',
'Creole English',95.7),
2954 (
'ARE',
'Arabic',42.0),(
'ARG',
'Spanish',96.8),
2955 (
'ARM',
'Armenian',93.4),(
'ABW',
'Papiamento',76.7),
2956 (
'AUS',
'English',81.2),(
'AZE',
'Azerbaijani',89.0),
2957 (
'BHS',
'Creole English',89.7),(
'BHR',
'Arabic',67.7),
2958 (
'BGD',
'Bengali',97.7),(
'BRB',
'Bajan',95.1),
2959 (
'BEL',
'Dutch',59.2),(
'BLZ',
'English',50.8);
2964 WHERE t2.Code IN (SELECT Country FROM t1 WHERE Population > 5000000)
2966 t2.Code IN (SELECT Country FROM t3
2967 WHERE Language='English' AND Percentage > 10 AND
2968 t2.Population > 100000);
2969 --eval EXPLAIN $query
2970 --eval EXPLAIN FORMAT=JSON $query
2972 DROP
TABLE t1,t2,t3;
2975 # BUG#30993: Subqueries: LooseScan strategy produces wrong query results, with duplicates
2979 Code
char(3) NOT NULL DEFAULT
'',
2980 Name
char(52) NOT NULL DEFAULT
'',
2981 Continent
enum(
'Asia',
'Europe',
'North America',
'Africa',
'Oceania',
'Antarctica',
'South America') NOT NULL DEFAULT
'Asia',
2982 Region
char(26) NOT NULL DEFAULT
'',
2983 SurfaceArea
float(10,2) NOT NULL DEFAULT
'0.00',
2984 IndepYear smallint(6) DEFAULT NULL,
2985 Population
int(11) NOT NULL DEFAULT
'0',
2986 LifeExpectancy
float(3,1) DEFAULT NULL,
2987 GNP
float(10,2) DEFAULT NULL,
2988 GNPOld
float(10,2) DEFAULT NULL,
2989 LocalName
char(45) NOT NULL DEFAULT
'',
2990 GovernmentForm
char(45) NOT NULL DEFAULT
'',
2991 HeadOfState
char(60) DEFAULT NULL,
2992 Capital
int(11) DEFAULT NULL,
2993 Code2
char(2) NOT NULL DEFAULT
'',
2998 ID
int(11) NOT NULL AUTO_INCREMENT,
2999 Name
char(35) NOT NULL DEFAULT
'',
3000 CountryCode
char(3) NOT NULL DEFAULT
'',
3001 District
char(20) NOT NULL DEFAULT
'',
3002 Population
int(11) NOT NULL DEFAULT
'0',
3004 KEY CountryCode (CountryCode)
3009 insert into t2 (ID, Name, CountryCode, Population) values
3010 (1,'Kabul','AFG',1780000), (2,'Qandahar','AFG',237500), (3,'Herat','AFG',186800),
3011 (4,'Mazar-e-Sharif','AFG',127800), (33,'Willemstad','ANT',2345), (34,'Tirana','ALB',270000),
3012 (55,'Andorra la Vella','AND',21189), (61,'South Hill','AIA',961), (62,'The Valley','AIA',595),
3013 (63,'Saint John´s','ATG',24000), (64,'Dubai','ARE',669181), (65,'Abu Dhabi','ARE',398695),
3014 (66,'Sharja','ARE',320095), (67,'al-Ayn','ARE',225970), (68,'Ajman','ARE',114395),
3015 (126,'Yerevan','ARM',1248700), (127,'Gjumri','ARM',211700), (128,'Vanadzor','ARM',172700),
3016 (129,'Oranjestad','ABW',29034), (144,'Baku','AZE',1787800), (145,'Gäncä','AZE',299300),
3017 (146,'Sumqayit','AZE',283000), (147,'Mingäçevir','AZE',93900), (148,'Nassau','BHS',172000),
3018 (149,'al-Manama','BHR',148000), (150,'Dhaka','BGD',3612850), (151,'Chittagong','BGD',1392860),
3019 (152,'Khulna','BGD',663340), (153,'Rajshahi','BGD',294056), (154,'Narayanganj','BGD',202134),
3020 (155,'Rangpur','BGD',191398), (156,'Mymensingh','BGD',188713), (157,'Barisal','BGD',170232),
3021 (158,'Tungi','BGD',168702), (159,'Jessore','BGD',139710), (160,'Comilla','BGD',135313),
3022 (161,'Nawabganj','BGD',130577), (162,'Dinajpur','BGD',127815), (163,'Bogra','BGD',120170),
3023 (164,'Sylhet','BGD',117396), (165,'Brahmanbaria','BGD',109032), (166,'Tangail','BGD',106004),
3024 (167,'Jamalpur','BGD',103556), (168,'Pabna','BGD',103277), (169,'Naogaon','BGD',101266),
3025 (170,'Sirajganj','BGD',99669), (171,'Narsinghdi','BGD',98342), (172,'Saidpur','BGD',96777),
3026 (173,'Gazipur','BGD',96717), (174,'Bridgetown','BRB',6070), (175,'Antwerpen','BEL',446525),
3027 (176,'Gent','BEL',224180), (177,'Charleroi','BEL',200827), (178,'Liège','BEL',185639),
3028 (179,'Bruxelles [Brussel]','BEL',133859), (180,'Brugge','BEL',116246), (181,'Schaerbeek','BEL',105692),
3029 (182,'Namur','BEL',105419), (183,'Mons','BEL',90935), (184,'Belize City','BLZ',55810),
3030 (185,'Belmopan','BLZ',7105), (190,'Saint George','BMU',1800), (191,'Hamilton','BMU',1200),
3031 (192,'Thimphu','BTN',22000), (201,'Sarajevo','BIH',360000), (202,'Banja Luka','BIH',143079),
3032 (203,'Zenica','BIH',96027), (538,'Bandar Seri Begawan','BRN',21484), (539,'Sofija','BGR',1122302),
3033 (540,'Plovdiv','BGR',342584), (541,'Varna','BGR',299801), (542,'Burgas','BGR',195255),
3034 (543,'Ruse','BGR',166467), (544,'Stara Zagora','BGR',147939), (545,'Pleven','BGR',121952),
3035 (546,'Sliven','BGR',105530), (547,'Dobric','BGR',100399), (548,'Šumen','BGR',94686),
3036 (553,'George Town','CYM',19600), (584,'San José','CRI',339131), (1523,'Wien','AUT',1608144),
3037 (1524,'Graz','AUT',240967), (1525,'Linz','AUT',188022), (1526,'Salzburg','AUT',144247),
3038 (1527,'Innsbruck','AUT',111752), (1528,'Klagenfurt','AUT',91141), (1810,'Montréal','CAN',1016376),
3039 (1811,'Calgary','CAN',768082), (1812,'Toronto','CAN',688275), (1813,'North York','CAN',622632),
3040 (1814,'Winnipeg','CAN',618477), (1815,'Edmonton','CAN',616306), (1816,'Mississauga','CAN',608072),
3041 (1817,'Scarborough','CAN',594501), (1818,'Vancouver','CAN',514008), (1819,'Etobicoke','CAN',348845),
3042 (1820,'London','CAN',339917), (1821,'Hamilton','CAN',335614), (1822,'Ottawa','CAN',335277),
3043 (1823,'Laval','CAN',330393), (1824,'Surrey','CAN',304477), (1825,'Brampton','CAN',296711),
3044 (1826,'Windsor','CAN',207588), (1827,'Saskatoon','CAN',193647), (1828,'Kitchener','CAN',189959),
3045 (1829,'Markham','CAN',189098), (1830,'Regina','CAN',180400), (1831,'Burnaby','CAN',179209),
3046 (1832,'Québec','CAN',167264), (1833,'York','CAN',154980), (1834,'Richmond','CAN',148867),
3047 (1835,'Vaughan','CAN',147889), (1836,'Burlington','CAN',145150), (1837,'Oshawa','CAN',140173),
3048 (1838,'Oakville','CAN',139192), (1839,'Saint Catharines','CAN',136216), (1840,'Longueuil','CAN',127977),
3049 (1841,'Richmond Hill','CAN',116428), (1842,'Thunder Bay','CAN',115913), (1843,'Nepean','CAN',115100),
3050 (1844,'Cape Breton','CAN',114733), (1845,'East York','CAN',114034), (1846,'Halifax','CAN',113910),
3051 (1847,'Cambridge','CAN',109186), (1848,'Gloucester','CAN',107314), (1849,'Abbotsford','CAN',105403),
3052 (1850,'Guelph','CAN',103593), (1851,'Saint John´s','CAN',101936), (1852,'Coquitlam','CAN',101820),
3053 (1853,'Saanich','CAN',101388), (1854,'Gatineau','CAN',100702), (1855,'Delta','CAN',95411),
3054 (1856,'Sudbury','CAN',92686), (1857,'Kelowna','CAN',89442), (1858,'Barrie','CAN',89269),
3055 (1890,'Shanghai','CHN',9696300), (1891,'Peking','CHN',7472000), (1892,'Chongqing','CHN',6351600),
3056 (1893,'Tianjin','CHN',5286800), (1894,'Wuhan','CHN',4344600), (1895,'Harbin','CHN',4289800),
3057 (1896,'Shenyang','CHN',4265200), (1897,'Kanton [Guangzhou]','CHN',4256300), (1898,'Chengdu','CHN',3361500),
3058 (1899,'Nanking [Nanjing]','CHN',2870300), (1900,'Changchun','CHN',2812000), (1901,'Xi´an','CHN',2761400),
3059 (1902,'Dalian','CHN',2697000), (1903,'Qingdao','CHN',2596000), (1904,'Jinan','CHN',2278100),
3060 (1905,'Hangzhou','CHN',2190500), (1906,'Zhengzhou','CHN',2107200), (1907,'Shijiazhuang','CHN',2041500),
3061 (1908,'Taiyuan','CHN',1968400), (1909,'Kunming','CHN',1829500), (1910,'Changsha','CHN',1809800),
3062 (1911,'Nanchang','CHN',1691600), (1912,'Fuzhou','CHN',1593800), (1913,'Lanzhou','CHN',1565800),
3063 (1914,'Guiyang','CHN',1465200), (1915,'Ningbo','CHN',1371200), (1916,'Hefei','CHN',1369100),
3064 (1917,'Urumtši [Ürümqi]','CHN',1310100), (1918,'Anshan','CHN',1200000), (1919,'Fushun','CHN',1200000),
3065 (1920,'Nanning','CHN',1161800), (1921,'Zibo','CHN',1140000), (1922,'Qiqihar','CHN',1070000),
3066 (1923,'Jilin','CHN',1040000), (1924,'Tangshan','CHN',1040000), (1925,'Baotou','CHN',980000),
3067 (1926,'Shenzhen','CHN',950500), (1927,'Hohhot','CHN',916700), (1928,'Handan','CHN',840000),
3068 (1929,'Wuxi','CHN',830000), (1930,'Xuzhou','CHN',810000), (1931,'Datong','CHN',800000),
3069 (1932,'Yichun','CHN',800000), (1933,'Benxi','CHN',770000), (1934,'Luoyang','CHN',760000),
3070 (1935,'Suzhou','CHN',710000), (1936,'Xining','CHN',700200), (1937,'Huainan','CHN',700000),
3071 (1938,'Jixi','CHN',683885), (1939,'Daqing','CHN',660000), (1940,'Fuxin','CHN',640000),
3072 (1941,'Amoy [Xiamen]','CHN',627500), (1942,'Liuzhou','CHN',610000), (1943,'Shantou','CHN',580000),
3073 (1944,'Jinzhou','CHN',570000), (1945,'Mudanjiang','CHN',570000), (1946,'Yinchuan','CHN',544500),
3074 (1947,'Changzhou','CHN',530000), (1948,'Zhangjiakou','CHN',530000), (1949,'Dandong','CHN',520000),
3075 (1950,'Hegang','CHN',520000), (1951,'Kaifeng','CHN',510000), (1952,'Jiamusi','CHN',493409),
3076 (1953,'Liaoyang','CHN',492559), (1954,'Hengyang','CHN',487148), (1955,'Baoding','CHN',483155),
3077 (1956,'Hunjiang','CHN',482043), (1957,'Xinxiang','CHN',473762), (1958,'Huangshi','CHN',457601),
3078 (1959,'Haikou','CHN',454300), (1960,'Yantai','CHN',452127), (1961,'Bengbu','CHN',449245),
3079 (1962,'Xiangtan','CHN',441968), (1963,'Weifang','CHN',428522), (1964,'Wuhu','CHN',425740),
3080 (1965,'Pingxiang','CHN',425579), (1966,'Yingkou','CHN',421589), (1967,'Anyang','CHN',420332),
3081 (1968,'Panzhihua','CHN',415466), (1969,'Pingdingshan','CHN',410775), (1970,'Xiangfan','CHN',410407),
3082 (1971,'Zhuzhou','CHN',409924), (1972,'Jiaozuo','CHN',409100), (1973,'Wenzhou','CHN',401871),
3083 (1974,'Zhangjiang','CHN',400997), (1975,'Zigong','CHN',393184), (1976,'Shuangyashan','CHN',386081),
3084 (1977,'Zaozhuang','CHN',380846), (1978,'Yakeshi','CHN',377869), (1979,'Yichang','CHN',371601),
3085 (1980,'Zhenjiang','CHN',368316), (1981,'Huaibei','CHN',366549), (1982,'Qinhuangdao','CHN',364972),
3086 (1983,'Guilin','CHN',364130), (1984,'Liupanshui','CHN',363954), (1985,'Panjin','CHN',362773),
3087 (1986,'Yangquan','CHN',362268), (1987,'Jinxi','CHN',357052), (1988,'Liaoyuan','CHN',354141),
3088 (1989,'Lianyungang','CHN',354139), (1990,'Xianyang','CHN',352125), (1991,'Tai´an','CHN',350696),
3089 (1992,'Chifeng','CHN',350077), (1993,'Shaoguan','CHN',350043), (1994,'Nantong','CHN',343341),
3090 (1995,'Leshan','CHN',341128), (1996,'Baoji','CHN',337765), (1997,'Linyi','CHN',324720),
3091 (1998,'Tonghua','CHN',324600), (1999,'Siping','CHN',317223), (2000,'Changzhi','CHN',317144),
3092 (2001,'Tengzhou','CHN',315083), (2002,'Chaozhou','CHN',313469), (2003,'Yangzhou','CHN',312892),
3093 (2004,'Dongwan','CHN',308669), (2005,'Ma´anshan','CHN',305421), (2006,'Foshan','CHN',303160),
3094 (2007,'Yueyang','CHN',302800), (2008,'Xingtai','CHN',302789), (2009,'Changde','CHN',301276),
3095 (2010,'Shihezi','CHN',299676), (2011,'Yancheng','CHN',296831), (2012,'Jiujiang','CHN',291187),
3096 (2013,'Dongying','CHN',281728), (2014,'Shashi','CHN',281352), (2015,'Xintai','CHN',281248),
3097 (2016,'Jingdezhen','CHN',281183), (2017,'Tongchuan','CHN',280657), (2018,'Zhongshan','CHN',278829),
3098 (2019,'Shiyan','CHN',273786), (2020,'Tieli','CHN',265683), (2021,'Jining','CHN',265248),
3099 (2022,'Wuhai','CHN',264081), (2023,'Mianyang','CHN',262947), (2024,'Luzhou','CHN',262892),
3100 (2025,'Zunyi','CHN',261862), (2026,'Shizuishan','CHN',257862), (2027,'Neijiang','CHN',256012),
3101 (2028,'Tongliao','CHN',255129), (2029,'Tieling','CHN',254842), (2030,'Wafangdian','CHN',251733),
3102 (2031,'Anqing','CHN',250718), (2032,'Shaoyang','CHN',247227), (2033,'Laiwu','CHN',246833),
3103 (2034,'Chengde','CHN',246799), (2035,'Tianshui','CHN',244974), (2036,'Nanyang','CHN',243303),
3104 (2037,'Cangzhou','CHN',242708), (2038,'Yibin','CHN',241019), (2039,'Huaiyin','CHN',239675),
3105 (2040,'Dunhua','CHN',235100), (2041,'Yanji','CHN',230892), (2042,'Jiangmen','CHN',230587),
3106 (2043,'Tongling','CHN',228017), (2044,'Suihua','CHN',227881), (2045,'Gongziling','CHN',226569),
3107 (2046,'Xiantao','CHN',222884), (2047,'Chaoyang','CHN',222394), (2048,'Ganzhou','CHN',220129),
3108 (2049,'Huzhou','CHN',218071), (2050,'Baicheng','CHN',217987), (2051,'Shangzi','CHN',215373),
3109 (2052,'Yangjiang','CHN',215196), (2053,'Qitaihe','CHN',214957), (2054,'Gejiu','CHN',214294),
3110 (2055,'Jiangyin','CHN',213659), (2056,'Hebi','CHN',212976), (2057,'Jiaxing','CHN',211526),
3111 (2058,'Wuzhou','CHN',210452), (2059,'Meihekou','CHN',209038), (2060,'Xuchang','CHN',208815),
3112 (2061,'Liaocheng','CHN',207844), (2062,'Haicheng','CHN',205560), (2063,'Qianjiang','CHN',205504),
3113 (2064,'Baiyin','CHN',204970), (2065,'Bei´an','CHN',204899), (2066,'Yixing','CHN',200824),
3114 (2067,'Laizhou','CHN',198664), (2068,'Qaramay','CHN',197602), (2069,'Acheng','CHN',197595),
3115 (2070,'Dezhou','CHN',195485), (2071,'Nanping','CHN',195064), (2072,'Zhaoqing','CHN',194784),
3116 (2073,'Beipiao','CHN',194301), (2074,'Fengcheng','CHN',193784), (2075,'Fuyu','CHN',192981),
3117 (2076,'Xinyang','CHN',192509), (2077,'Dongtai','CHN',192247), (2078,'Yuci','CHN',191356),
3118 (2079,'Honghu','CHN',190772), (2080,'Ezhou','CHN',190123), (2081,'Heze','CHN',189293),
3119 (2082,'Daxian','CHN',188101), (2083,'Linfen','CHN',187309), (2084,'Tianmen','CHN',186332),
3120 (2085,'Yiyang','CHN',185818), (2086,'Quanzhou','CHN',185154), (2087,'Rizhao','CHN',185048),
3121 (2088,'Deyang','CHN',182488), (2089,'Guangyuan','CHN',182241), (2090,'Changshu','CHN',181805),
3122 (2091,'Zhangzhou','CHN',181424), (2092,'Hailar','CHN',180650), (2093,'Nanchong','CHN',180273),
3123 (2094,'Jiutai','CHN',180130), (2095,'Zhaodong','CHN',179976), (2096,'Shaoxing','CHN',179818),
3124 (2097,'Fuyang','CHN',179572), (2098,'Maoming','CHN',178683), (2099,'Qujing','CHN',178669),
3125 (2100,'Ghulja','CHN',177193), (2101,'Jiaohe','CHN',176367), (2102,'Puyang','CHN',175988),
3126 (2103,'Huadian','CHN',175873), (2104,'Jiangyou','CHN',175753), (2105,'Qashqar','CHN',174570),
3127 (2106,'Anshun','CHN',174142), (2107,'Fuling','CHN',173878), (2108,'Xinyu','CHN',173524),
3128 (2109,'Hanzhong','CHN',169930), (2110,'Danyang','CHN',169603), (2111,'Chenzhou','CHN',169400),
3129 (2112,'Xiaogan','CHN',166280), (2113,'Shangqiu','CHN',164880), (2114,'Zhuhai','CHN',164747),
3130 (2115,'Qingyuan','CHN',164641), (2116,'Aqsu','CHN',164092), (2117,'Jining','CHN',163552),
3131 (2118,'Xiaoshan','CHN',162930), (2119,'Zaoyang','CHN',162198), (2120,'Xinghua','CHN',161910),
3132 (2121,'Hami','CHN',161315), (2122,'Huizhou','CHN',161023), (2123,'Jinmen','CHN',160794),
3133 (2124,'Sanming','CHN',160691), (2125,'Ulanhot','CHN',159538), (2126,'Korla','CHN',159344),
3134 (2127,'Wanxian','CHN',156823), (2128,'Rui´an','CHN',156468), (2129,'Zhoushan','CHN',156317),
3135 (2130,'Liangcheng','CHN',156307), (2131,'Jiaozhou','CHN',153364), (2132,'Taizhou','CHN',152442),
3136 (2133,'Suzhou','CHN',151862), (2134,'Yichun','CHN',151585), (2135,'Taonan','CHN',150168),
3137 (2136,'Pingdu','CHN',150123), (2137,'Ji´an','CHN',148583), (2138,'Longkou','CHN',148362),
3138 (2139,'Langfang','CHN',148105), (2140,'Zhoukou','CHN',146288), (2141,'Suining','CHN',146086),
3139 (2142,'Yulin','CHN',144467), (2143,'Jinhua','CHN',144280), (2144,'Liu´an','CHN',144248),
3140 (2145,'Shuangcheng','CHN',142659), (2146,'Suizhou','CHN',142302), (2147,'Ankang','CHN',142170),
3141 (2148,'Weinan','CHN',140169), (2149,'Longjing','CHN',139417), (2150,'Da´an','CHN',138963),
3142 (2151,'Lengshuijiang','CHN',137994), (2152,'Laiyang','CHN',137080), (2153,'Xianning','CHN',136811),
3143 (2154,'Dali','CHN',136554), (2155,'Anda','CHN',136446), (2156,'Jincheng','CHN',136396),
3144 (2157,'Longyan','CHN',134481), (2158,'Xichang','CHN',134419), (2159,'Wendeng','CHN',133910),
3145 (2160,'Hailun','CHN',133565), (2161,'Binzhou','CHN',133555), (2162,'Linhe','CHN',133183),
3146 (2163,'Wuwei','CHN',133101), (2164,'Duyun','CHN',132971), (2165,'Mishan','CHN',132744),
3147 (2166,'Shangrao','CHN',132455), (2167,'Changji','CHN',132260), (2168,'Meixian','CHN',132156),
3148 (2169,'Yushu','CHN',131861), (2170,'Tiefa','CHN',131807), (2171,'Huai´an','CHN',131149),
3149 (2172,'Leiyang','CHN',130115), (2173,'Zalantun','CHN',130031), (2174,'Weihai','CHN',128888),
3150 (2175,'Loudi','CHN',128418), (2176,'Qingzhou','CHN',128258), (2177,'Qidong','CHN',126872),
3151 (2178,'Huaihua','CHN',126785), (2179,'Luohe','CHN',126438), (2180,'Chuzhou','CHN',125341),
3152 (2181,'Kaiyuan','CHN',124219), (2182,'Linqing','CHN',123958), (2183,'Chaohu','CHN',123676),
3153 (2184,'Laohekou','CHN',123366), (2185,'Dujiangyan','CHN',123357), (2186,'Zhumadian','CHN',123232),
3154 (2187,'Linchuan','CHN',121949), (2188,'Jiaonan','CHN',121397), (2189,'Sanmenxia','CHN',120523),
3155 (2190,'Heyuan','CHN',120101), (2191,'Manzhouli','CHN',120023), (2192,'Lhasa','CHN',120000),
3156 (2193,'Lianyuan','CHN',118858), (2194,'Kuytun','CHN',118553), (2195,'Puqi','CHN',117264),
3157 (2196,'Hongjiang','CHN',116188), (2197,'Qinzhou','CHN',114586), (2198,'Renqiu','CHN',114256),
3158 (2199,'Yuyao','CHN',114065), (2200,'Guigang','CHN',114025), (2201,'Kaili','CHN',113958),
3159 (2202,'Yan´an','CHN',113277), (2203,'Beihai','CHN',112673), (2204,'Xuangzhou','CHN',112673),
3160 (2205,'Quzhou','CHN',112373), (2206,'Yong´an','CHN',111762), (2207,'Zixing','CHN',110048),
3161 (2208,'Liyang','CHN',109520), (2209,'Yizheng','CHN',109268), (2210,'Yumen','CHN',109234),
3162 (2211,'Liling','CHN',108504), (2212,'Yuncheng','CHN',108359), (2213,'Shanwei','CHN',107847),
3163 (2214,'Cixi','CHN',107329), (2215,'Yuanjiang','CHN',107004), (2216,'Bozhou','CHN',106346),
3164 (2217,'Jinchang','CHN',105287), (2218,'Fu´an','CHN',105265), (2219,'Suqian','CHN',105021),
3165 (2220,'Shishou','CHN',104571), (2221,'Hengshui','CHN',104269), (2222,'Danjiangkou','CHN',103211),
3166 (2223,'Fujin','CHN',103104), (2224,'Sanya','CHN',102820), (2225,'Guangshui','CHN',102770),
3167 (2226,'Huangshan','CHN',102628), (2227,'Xingcheng','CHN',102384), (2228,'Zhucheng','CHN',102134),
3168 (2229,'Kunshan','CHN',102052), (2230,'Haining','CHN',100478), (2231,'Pingliang','CHN',99265),
3169 (2232,'Fuqing','CHN',99193), (2233,'Xinzhou','CHN',98667), (2234,'Jieyang','CHN',98531),
3170 (2235,'Zhangjiagang','CHN',97994), (2236,'Tong Xian','CHN',97168), (2237,'Ya´an','CHN',95900),
3171 (2238,'Jinzhou','CHN',95761), (2239,'Emeishan','CHN',94000), (2240,'Enshi','CHN',93056),
3172 (2241,'Bose','CHN',93009), (2242,'Yuzhou','CHN',92889), (2243,'Kaiyuan','CHN',91999),
3173 (2244,'Tumen','CHN',91471), (2245,'Putian','CHN',91030), (2246,'Linhai','CHN',90870),
3174 (2247,'Xilin Hot','CHN',90646), (2248,'Shaowu','CHN',90286), (2249,'Junan','CHN',90222),
3175 (2250,'Huaying','CHN',89400), (2251,'Pingyi','CHN',89373), (2252,'Huangyan','CHN',89288),
3176 (2413,'La Habana','CUB',2256000), (2414,'Santiago de Cuba','CUB',433180), (2415,'Camagüey','CUB',298726),
3177 (2416,'Holguín','CUB',249492), (2417,'Santa Clara','CUB',207350), (2418,'Guantánamo','CUB',205078),
3178 (2419,'Pinar del Río','CUB',142100), (2420,'Bayamo','CUB',141000), (2421,'Cienfuegos','CUB',132770),
3179 (2422,'Victoria de las Tunas','CUB',132350), (2423,'Matanzas','CUB',123273), (2424,'Manzanillo','CUB',109350),
3180 (2425,'Sancti-Spíritus','CUB',100751), (2426,'Ciego de Ávila','CUB',98505), (2430,'Nicosia','CYP',195000),
3181 (2431,'Limassol','CYP',154400), (3245,'Zürich','CHE',336800), (3246,'Geneve','CHE',173500),
3182 (3247,'Basel','CHE',166700), (3248,'Bern','CHE',122700), (3249,'Lausanne','CHE',114500),
3183 (3339,'Praha','CZE',1181126), (3340,'Brno','CZE',381862), (3341,'Ostrava','CZE',320041),
3184 (3342,'Plzen','CZE',166759), (3343,'Olomouc','CZE',102702), (3344,'Liberec','CZE',99155),
3185 (3345,'Ceské Budejovice','CZE',98186), (3346,'Hradec Králové','CZE',98080), (3347,'Ústí nad Labem','CZE',95491),
3186 (3348,'Pardubice','CZE',91309), (3520,'Minsk','BLR',1674000), (3521,'Gomel','BLR',475000),
3187 (3522,'Mogiljov','BLR',356000), (3523,'Vitebsk','BLR',340000), (3524,'Grodno','BLR',302000),
3188 (3525,'Brest','BLR',286000), (3526,'Bobruisk','BLR',221000), (3527,'Baranovitši','BLR',167000),
3189 (3528,'Borisov','BLR',151000), (3529,'Pinsk','BLR',130000), (3530,'Orša','BLR',124000),
3190 (3531,'Mozyr','BLR',110000), (3532,'Novopolotsk','BLR',106000), (3533,'Lida','BLR',101000),
3191 (3534,'Soligorsk','BLR',101000), (3535,'Molodetšno','BLR',97000);
3193 insert into t1 (Code, Name, Continent) values
3194 ('AFG','Afghanistan','Asia'), ('ANT','Netherlands Antilles','North America'),
3195 ('ALB','Albania','Europe'), ('AND','Andorra','Europe'),
3196 ('AIA','Anguilla','North America'), ('ATG','Antigua and Barbuda','North America'),
3197 ('ARE','United Arab Emirates','Asia'), ('ARM','Armenia','Asia'),
3198 ('ABW','Aruba','North America'), ('AZE','Azerbaijan','Asia'),
3199 ('BHS','Bahamas','North America'), ('BHR','Bahrain','Asia'),
3200 ('BGD','Bangladesh','Asia'), ('BRB','Barbados','North America'),
3201 ('BEL','Belgium','Europe'), ('BLZ','Belize','North America'),
3202 ('BMU','Bermuda','North America'), ('BTN','Bhutan','Asia'),
3203 ('BIH','Bosnia and Herzegovina','Europe'), ('BRN','Brunei','Asia'),
3204 ('BGR','Bulgaria','Europe'), ('CYM','Cayman Islands','North America'),
3205 ('CRI','Costa Rica','North America'), ('AUT','Austria','Europe'),
3206 ('CAN','Canada','North America'), ('CHN','China','Asia'),
3207 ('CUB','Cuba','North America'), ('CYP','Cyprus','Asia'),
3208 ('CHE','Switzerland','Europe'), ('CZE','Czech Republic','Europe'),
3209 ('BLR','Belarus','Europe');
3210 update t2 set population=6000000 where Name in ('Wien', 'Vancouver', 'Praha');
3213 --echo This must not use LooseScan:
3214 EXPLAIN SELECT Name FROM t1
3216 SELECT t2.CountryCode FROM t2 WHERE Population > 5000000);
3220 SELECT t2.CountryCode FROM t2 WHERE Population > 5000000);
3226 # BUG#35160 "Subquery optimization: table pullout is not reflected in EXPLAIN EXTENDED"
3228 create
table t0 (a
int);
3229 insert into t0 values (0),(1),(2),(3),(4);
3231 create
table t1 (a
int, b
int, key(a));
3232 insert into t1 select a,a from t0;
3234 create
table t2 (a
int, b
int, primary key(a));
3235 insert into t2 select * from t1;
3237 # Table t2 should be pulled out because t2.a=t0.a equality
3238 --echo Table t2, unlike
table t1, should be displayed as pulled out
3239 explain extended select * from t0
3240 where t0.a in ( select t1.a from t1,t2 where t2.a=t0.a and
3244 # BUG#46556 "Returning incorrect, empty results for some IN subqueries
3248 # The above query did not have a valid plan before the fix of BUG#46556.
3249 # Add some data that would cause wrong result with the old plan.
3250 update t1
set a=3, b=11 where a=4;
3251 update t2
set b=11 where a=3;
3253 # the query just below may exhibit BUG#49129:
3254 create temporary
table tmp select * from t0 where t0.a in
3255 (select t1.a from t1, t2 where t2.a=t0.a and t1.b=t2.b);
3256 # detect it and warn in result file if it's the case:
3257 create temporary
table tmp_as_ref (a
int);
3258 insert into tmp_as_ref values(0),(1),(2),(3); # correct desired result
3259 if (`select count(*) from tmp_as_ref left join tmp on tmp.a=tmp_as_ref.a
3260 where tmp.a is null`)
3263 --echo # The result below is wrong due
to Bug#49129
3267 drop
table t0, t1, t2, tmp, tmp_as_ref;
3270 # BUG#35767: Processing of uncorrelated subquery with semi-join cause wrong result and crash
3273 id int(11) NOT NULL,
3277 id int(11) NOT NULL,
3278 fid
int(11) NOT NULL,
3281 insert into t1 values(1);
3282 insert into t2 values(1,7503),(2,1);
3285 explain select count(*)
3287 where fid IN (select fid from t2 where (
id between 7502 and 8420) order by fid );
3292 # BUG#36137 "virtual longlong Item_in_subselect::val_int(): Assertion `0' failed."
3294 create
table t1 (a
int, b
int, key (a), key (b));
3295 insert into t1 values (2,4),(2,4),(2,4);
3298 t1.a in (select 1 from t1 where t1.a in (select 1 from t1)
group by t1.a);
3302 # BUG#36128: not in subquery causes crash in cleanup..
3304 create
table t1(a
int,b
int,key(a),key(b));
3305 insert into t1 values (1,1),(2,2),(3,3);
3307 where t1.a not in (select 1 from t1
3308 where t1.a in (select 1 from t1)
3313 # BUG#33743 "nested subqueries, unique index, wrong result"
3316 (EMPNUM CHAR(3) NOT NULL,
3322 (PNUM CHAR(3) NOT NULL,
3329 (EMPNUM CHAR(3) NOT NULL,
3330 PNUM CHAR(3) NOT NULL,
3333 INSERT INTO t1 VALUES (
'E1',
'Alice',12,
'Deale');
3334 INSERT INTO t1 VALUES (
'E2',
'Betty',10,
'Vienna');
3335 INSERT INTO t1 VALUES (
'E3',
'Carmen',13,
'Vienna');
3336 INSERT INTO t1 VALUES (
'E4',
'Don',12,
'Deale');
3337 INSERT INTO t1 VALUES (
'E5',
'Ed',13,
'Akron');
3339 INSERT INTO t2 VALUES (
'P1',
'MXSS',
'Design',10000,
'Deale');
3340 INSERT INTO t2 VALUES (
'P2',
'CALM',
'Code',30000,
'Vienna');
3341 INSERT INTO t2 VALUES (
'P3',
'SDP',
'Test',30000,
'Tampa');
3342 INSERT INTO t2 VALUES (
'P4',
'SDP',
'Design',20000,
'Deale');
3343 INSERT INTO t2 VALUES (
'P5',
'IRM',
'Test',10000,
'Vienna');
3344 INSERT INTO t2 VALUES (
'P6',
'PAYR',
'Design',50000,
'Deale');
3346 INSERT INTO t3 VALUES (
'E1',
'P1',40);
3347 INSERT INTO t3 VALUES (
'E1',
'P2',20);
3348 INSERT INTO t3 VALUES (
'E1',
'P3',80);
3349 INSERT INTO t3 VALUES (
'E1',
'P4',20);
3350 INSERT INTO t3 VALUES (
'E1',
'P5',12);
3351 INSERT INTO t3 VALUES (
'E1',
'P6',12);
3352 INSERT INTO t3 VALUES (
'E2',
'P1',40);
3353 INSERT INTO t3 VALUES (
'E2',
'P2',80);
3354 INSERT INTO t3 VALUES (
'E3',
'P2',20);
3355 INSERT INTO t3 VALUES (
'E4',
'P2',20);
3356 INSERT INTO t3 VALUES (
'E4',
'P4',40);
3357 INSERT INTO t3 VALUES (
'E4',
'P5',80);
3361 CREATE UNIQUE INDEX t1_IDX ON t1(EMPNUM);
3371 WHERE PTYPE =
'Design'));
3373 DROP INDEX t1_IDX ON t1;
3374 CREATE INDEX t1_IDX ON t1(EMPNUM);
3384 WHERE PTYPE =
'Design'));
3386 DROP INDEX t1_IDX ON t1;
3396 WHERE PTYPE =
'Design'));
3398 DROP
TABLE t1, t2, t3;
3401 # BUG#33245 "Crash on VIEW referencing FROM table in an IN clause"
3403 CREATE
TABLE t1 (f1 INT NOT NULL);
3404 CREATE VIEW v1 (a) AS SELECT f1 IN (SELECT f1 FROM t1) FROM t1;
3411 # BUG#35550 "Semi-join subquery in ON clause and no WHERE crashes the server"
3413 create
table t0 (a
int);
3414 insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
3416 create
table t1(a
int, b
int);
3417 insert into t1 values (0,0),(1,1),(2,2);
3418 create
table t2 as select * from t1;
3420 create
table t3 (pk
int, a
int, primary key(pk));
3421 insert into t3 select a,a from t0;
3424 select * from t1 left join t2 on (t2.a= t1.a and t2.a in (select pk from t3));
3426 drop
table t0, t1, t2, t3;
3430 # BUG#35468 "Slowdown and wrong result for uncorrelated subquery w/o where"
3433 create
table t0 (a
int);
3434 insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
3435 create
table t1 (a
int) as select A.a + 10 *(B.a + 10*C.a) as a from t0 A, t0 B, t0 C;
3436 create
table t2 (
id int, a
int, primary key(
id), key(a)) as select a as
id, a as a from t1;
3437 show create
table t2;
3440 insert into t3 select @a:=@a+1, t2.a from t2, t0;
3441 insert into t3 select @a:=@a+1, t2.a from t2, t0;
3442 insert into t3 select @a:=@a+1, t2.a from t2, t0;
3444 alter
table t3 add primary key(
id), add key(a);
3445 --echo The following must use loose
index scan over t3, key a:
3446 explain select count(a) from t2 where a in ( SELECT a FROM t3);
3447 select count(a) from t2 where a in ( SELECT a FROM t3);
3449 drop
table t0,t1,t2,t3;
3453 --echo # Bug#33062: subquery in stored routine cause crash
3455 CREATE
TABLE t1(a INT);
3456 CREATE
TABLE t2(c INT);
3460 CREATE PROCEDURE p1(v1
int)
3462 SELECT 1 FROM t1 WHERE a = v1 AND a IN (SELECT c FROM t2);
3466 CREATE PROCEDURE p2(v1
int)
3468 SELECT 1 FROM t1 WHERE a IN (SELECT c FROM t2);
3472 CREATE PROCEDURE p3(v1
int)
3476 t1 t01,t1 t02,t1 t03,t1 t04,t1 t05,t1 t06,t1 t07,t1 t08,
3477 t1 t09,t1 t10,t1 t11,t1 t12,t1 t13,t1 t14,t1 t15,t1 t16,
3478 t1 t17,t1 t18,t1 t19,t1 t20,t1 t21,t1 t22,t1 t23,t1 t24,
3479 t1 t25,t1 t26,t1 t27,t1 t28,t1 t29,t1 t30,t1 t31,t1 t32,
3480 t1 t33,t1 t34,t1 t35,t1 t36,t1 t37,t1 t38,t1 t39,t1 t40,
3481 t1 t41,t1 t42,t1 t43,t1 t44,t1 t45,t1 t46,t1 t47,t1 t48,
3482 t1 t49,t1 t50,t1 t51,t1 t52,t1 t53,t1 t54,t1 t55,t1 t56,
3483 t1 t57,t1 t58,t1 t59,t1 t60
3484 WHERE t01.a IN (SELECT c FROM t2);
3488 CREATE PROCEDURE p4(v1
int)
3492 t1 t01,t1 t02,t1 t03,t1 t04,t1 t05,t1 t06,t1 t07,t1 t08,
3493 t1 t09,t1 t10,t1 t11,t1 t12,t1 t13,t1 t14,t1 t15,t1 t16,
3494 t1 t17,t1 t18,t1 t19,t1 t20,t1 t21,t1 t22,t1 t23,t1 t24,
3495 t1 t25,t1 t26,t1 t27,t1 t28,t1 t29,t1 t30,t1 t31,t1 t32,
3496 t1 t33,t1 t34,t1 t35,t1 t36,t1 t37,t1 t38,t1 t39,t1 t40,
3497 t1 t41,t1 t42,t1 t43,t1 t44,t1 t45,t1 t46,t1 t47,t1 t48,
3498 t1 t49,t1 t50,t1 t51,t1 t52,t1 t53,t1 t54,t1 t55,t1 t56,
3499 t1 t57,t1 t58,t1 t59,t1 t60
3500 WHERE t01.a = v1 AND t01.a IN (SELECT c FROM t2);
3519 --echo # Bug#48213 Materialized subselect crashes
if using GEOMETRY
type
3538 INSERT INTO t1 VALUES (1,
'o',
'ffff',
'ffff',
'ffoo',
'ffff',
'ffff',
'ffff',
'ffff',
'ffff',
'ffff',GeomFromText(
'POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))')), (2,
'f',
'ffff',
'ffff',
'ffff',
'ffff',
'ffff',
'ffff',
'ffff',
'ffff',
'ffff',GeomFromText(
'POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))'));
3540 CREATE
TABLE t2 LIKE t1;
3541 INSERT INTO t2 VALUES (1,
'i',
'iiii',
'iiii',
'iiii',
'iiii',
'ffff',
'ffff',
'ffff',
'ffff',
'ffff',GeomFromText(
'POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))')), (2,
'f',
'ffff',
'ffff',
'ffff',
'ffff',
'ffff',
'ffff',
'ffff',
'ffff',
'ffff',GeomFromText(
'POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))'));
3543 # Test that materialization is skipped for semijoins where materialized
3544 # table would contain GEOMETRY or different kinds of BLOB/TEXT columns
3546 SELECT pk FROM t1 WHERE (a, b) IN (SELECT a, b FROM t2 WHERE pk > 0);
3547 eval EXPLAIN EXTENDED $query;
3551 SELECT pk FROM t1 WHERE (b, c) IN (SELECT b, c FROM t2 WHERE pk > 0);
3552 eval EXPLAIN EXTENDED $query;
3556 SELECT pk FROM t1 WHERE (b, d) IN (SELECT b, d FROM t2 WHERE pk > 0);
3557 eval EXPLAIN EXTENDED $query;
3561 SELECT pk FROM t1 WHERE (b, e) IN (SELECT b, e FROM t2 WHERE pk > 0);
3562 eval EXPLAIN EXTENDED $query;
3566 SELECT pk FROM t1 WHERE (b, f) IN (SELECT b, f FROM t2 WHERE pk > 0);
3567 eval EXPLAIN EXTENDED $query;
3571 SELECT pk FROM t1 WHERE (b, g) IN (SELECT b, g FROM t2 WHERE pk > 0);
3572 eval EXPLAIN EXTENDED $query;
3576 SELECT pk FROM t1 WHERE (b, h) IN (SELECT b, h FROM t2 WHERE pk > 0);
3577 eval EXPLAIN EXTENDED $query;
3581 SELECT pk FROM t1 WHERE (b, i) IN (SELECT b, i FROM t2 WHERE pk > 0);
3582 eval EXPLAIN EXTENDED $query;
3586 SELECT pk FROM t1 WHERE (b, j) IN (SELECT b, j FROM t2 WHERE pk > 0);
3587 eval EXPLAIN EXTENDED $query;
3591 SELECT pk FROM t1 WHERE (b, k) IN (SELECT b, k FROM t2 WHERE pk > 0);
3592 eval EXPLAIN EXTENDED $query;
3596 --echo
# End of Bug#48213
3599 --echo # BUG#53060: LooseScan semijoin strategy does not
return all rows
3602 CREATE
TABLE t1 (i INTEGER);
3603 INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
3604 CREATE
TABLE t2 (i INTEGER, j INTEGER, KEY k(i, j));
3605 INSERT INTO t2 VALUES (1, 0), (1, 1), (2, 0), (2, 1);
3608 SELECT * FROM t1 WHERE (i) IN (SELECT i FROM t2 where j > 0);
3609 SELECT * FROM t1 WHERE (i) IN (SELECT i FROM t2 where j > 0);
3613 --echo
# End of BUG#53060
3615 --echo # Bug#53305
"Duplicate weedout + join buffer (join cache --level=7,8) loses rows"
3618 create
table t1 (uid
int, fid
int,
index(uid));
3619 insert into t1 values
3620 (1,1), (1,2), (1,3), (1,4),
3621 (2,5), (2,6), (2,7), (2,8),
3622 (3,1), (3,2), (3,9);
3625 insert into t2 values
3626 (1,
"A"), (2,
"B"), (3,
"C"), (4,
"D"), (5,
"E"),
3627 (6,
"F"), (7,
"G"), (8,
"H"), (9,
"I");
3629 create
table t3 (uid
int, fid
int,
index(uid));
3630 insert into t3 values
3631 (1,1), (1,2), (1,3),(1,4),
3632 (2,5), (2,6), (2,7), (2,8),
3633 (3,1), (3,2), (3,9);
3636 insert into t4 values
3637 (1,
"A"), (2,
"B"), (3,
"C"), (4,
"D"), (5,
"E"),
3638 (6,
"F"), (7,
"G"), (8,
"H"), (9,
"I");
3640 explain select
name from t2, t1
3641 where t1.uid in (select t4.uid from t4, t3 where t3.uid=1 and t4.uid=t3.fid)
3645 select
name from t2, t1
3646 where t1.uid in (select t4.uid from t4, t3 where t3.uid=1 and t4.uid=t3.fid)
3649 drop
table t1,t2,t3,t4;
3652 --echo # Bug#43768 Prepared
query with nested subqueries core dump on second execution
3657 partner_id VARCHAR(35)
3660 INSERT INTO t1 VALUES
3661 (1,
'partner1'), (2,
'partner2'),
3662 (3,
'partner3'), (4,
'partner4');
3667 article_id VARCHAR(20),
3668 PRIMARY KEY(
id, t1_line_id)
3671 INSERT INTO t2 VALUES
3672 (1, 1,
'sup'), (2, 1,
'sup'),
3673 (2, 2,
'sup'), (2, 3,
'sup'),
3674 (2, 4,
'imp'), (3, 1,
'sup'),
3678 user_id VARCHAR(50),
3679 article_id VARCHAR(20) NOT NULL,
3680 PRIMARY KEY(user_id)
3683 INSERT INTO t3 VALUES(
'nicke',
'imp');
3686 SELECT t1.partner_id
3691 WHERE article_id IN (
3692 SELECT article_id FROM t3
3693 WHERE user_id =
'nicke'
3697 SELECT t1.partner_id
3702 WHERE article_id IN (
3703 SELECT article_id FROM t3
3704 WHERE user_id =
'nicke'
3709 'EXPLAIN SELECT t1.partner_id
3714 WHERE article_id IN (
3715 SELECT article_id FROM t3
3716 WHERE user_id = \'nicke\'
3723 'SELECT t1.partner_id
3728 WHERE article_id IN (
3729 SELECT article_id FROM t3
3730 WHERE user_id = \'nicke\'
3736 DROP
TABLE t1,t2,t3;
3738 --echo # End of Bug#43768
3741 --echo # Bug#53058 - semijoin execution of subquery with outerjoin yields wrong result
3743 CREATE
TABLE t1 (i INTEGER);
3744 CREATE
TABLE t2 (i INTEGER);
3745 CREATE
TABLE t3 (i INTEGER);
3746 INSERT INTO t1 VALUES (1), (2);
3747 INSERT INTO t2 VALUES (6);
3748 INSERT INTO t3 VALUES (1), (2);
3749 explain extended SELECT * FROM t1 WHERE (t1.i) IN
3750 (SELECT t3.i FROM t3 LEFT
JOIN t2 ON t2.i=t3.i);
3751 SELECT * FROM t1 WHERE (t1.i) IN
3752 (SELECT t3.i FROM t3 LEFT
JOIN t2 ON t2.i=t3.i);
3753 drop
table t1,t2,t3;
3756 --echo # BUG#49453: re-execution of prepared
statement with
view
3757 --echo # and semijoin crashes
3759 CREATE
TABLE t1 (city VARCHAR(50), country_id INT);
3760 CREATE
TABLE t2 (country_id INT, country VARCHAR(50));
3762 INSERT INTO t1 VALUES
3763 (
'Batna',2),(
'Bchar',2),(
'Skikda',2),(
'Tafuna',3),(
'Algeria',2) ;
3764 INSERT INTO t2 VALUES (2,
'Algeria'),(2,
'AlgeriaDup'),(3,
'XAmerican Samoa');
3767 SELECT country_id as vf_country_id
3769 WHERE LEFT(country,1) =
"A";
3772 SELECT city, country_id
3774 WHERE country_id IN (SELECT vf_country_id FROM v1);
3785 --echo # Bug#54437 Extra rows with LEFT
JOIN + semijoin (firstmatch
3786 --echo # and duplicates weedout)
3788 create
table t1 (a
int);
3789 create
table t2 (a
int);
3790 create
table t3 (a
int);
3791 insert into t1 values(1),(1);
3792 insert into t2 values(1),(1),(1),(1);
3793 insert into t3 values(2),(2);
3795 let $query=select * from t1 where t1.a in (select t2.a from t2 left join t3 on t2.a=t3.a);
3796 eval explain $query;
3799 drop
table t1,t2,t3;
3802 --echo # Bug#55955: crash in MEMORY engine with IN(LEFT
JOIN (
JOIN))
3804 CREATE
TABLE t1 (a INT);
3805 CREATE
TABLE t2 (a INT);
3806 CREATE
TABLE t3 (a INT);
3807 INSERT INTO t1 VALUES(1),(1);
3808 INSERT INTO t2 VALUES(1),(1);
3809 INSERT INTO t3 VALUES(2),(2);
3813 WHERE t1.a IN (SELECT t2.a
3814 FROM t2 LEFT
JOIN (t2 AS t2inner, t3) ON t2.a=t3.a);
3815 eval explain $query;
3818 DROP
TABLE t1,t2,t3;
3821 --echo # BUG#52329 - Wrong result: subquery materialization, IN,
3822 --echo # non-null field followed by nullable
3825 CREATE
TABLE t1 (a1 CHAR(8) NOT NULL, a2
char(8) NOT NULL);
3827 CREATE
TABLE t2a (b1
char(8), b2
char(8));
3828 CREATE
TABLE t2b (b1 CHAR(8), b2
char(8) NOT NULL);
3829 CREATE
TABLE t2c (b1 CHAR(8) NOT NULL, b2
char(8));
3831 INSERT INTO t1 VALUES (
'1 - 12',
'2 - 22');
3833 INSERT INTO t2a VALUES (
'1 - 11',
'2 - 21'),
3834 (
'1 - 11',
'2 - 21'),
3835 (
'1 - 12',
'2 - 22'),
3836 (
'1 - 12',
'2 - 22'),
3837 (
'1 - 13',
'2 - 23');
3839 INSERT INTO t2b SELECT * FROM t2a;
3840 INSERT INTO t2c SELECT * FROM t2a;
3844 SELECT b1, b2 FROM t2c WHERE b1 > '0' GROUP BY b1, b2);
3848 SELECT b1, b2 FROM t2a WHERE b1 > '0');
3853 SELECT b1, b2 FROM t2b WHERE b1 > '0');
3858 SELECT b1, b2 FROM t2c WHERE b1 > '0');
3861 DROP
TABLE t1,t2a,t2b,t2c;
3863 --echo
# End BUG#52329
3866 --echo # Bug#45174: Incorrectly applied equality propagation caused wrong
3867 --echo # result on a
query with a materialized semi-join.
3871 varchar_nokey varchar(1) NOT NULL
3874 INSERT INTO t1 VALUES
3875 (
'v'), (
'u'), (
'n'), (
'l'), (
'h'), (
'u'), (
'n'), (
'j'), (
'k'),
3876 (
'e'), (
'i'), (
'u'), (
'n'), (
'b'), (
'x'), (
''), (
'q'), (
'u');
3880 varchar_key varchar(1) NOT NULL,
3881 varchar_nokey varchar(1) NOT NULL,
3883 KEY varchar_key(varchar_key)
3886 INSERT INTO t2 VALUES
3887 (11,
'm',
'm'), (12,
'j',
'j'), (13,
'z',
'z'), (14,
'a',
'a'), (15,
'',
''),
3888 (16,
'e',
'e'), (17,
't',
't'), (19,
'b',
'b'), (20,
'w',
'w'), (21,
'm',
'm'),
3889 (23,
'',
''), (24,
'w',
'w'), (26,
'e',
'e'), (27,
'e',
'e'), (28,
'p',
'p');
3892 SELECT varchar_nokey
3894 WHERE (varchar_nokey, varchar_nokey) IN (SELECT varchar_key, varchar_nokey
3896 WHERE varchar_nokey < 'n' XOR pk);
3898 eval explain $query;
3902 --echo
# End of the test for bug#45174.
3905 --echo # Bug#50019: Wrong result
for IN-
query with materialization
3908 CREATE
TABLE t1(i INT);
3909 INSERT INTO t1 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
3910 CREATE
TABLE t2(i INT);
3911 INSERT INTO t2 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
3912 CREATE
TABLE t3(i INT);
3913 INSERT INTO t3 VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
3916 SELECT * FROM t1 WHERE t1.i IN (SELECT t2.i
3918 WHERE t2.i + t3.i = 5);
3920 eval explain $query;
3922 DROP
TABLE t1,t2,t3;
3924 --echo # End of the
test for bug#50019.
3927 --echo # Bug#52068: Optimizer generates invalid semijoin materialization
plan
3930 CREATE
TABLE ot1(a INTEGER);
3931 INSERT INTO ot1 VALUES(5), (8);
3932 CREATE
TABLE it2(a INTEGER);
3933 INSERT INTO it2 VALUES(9), (5), (1), (8);
3934 CREATE
TABLE it3(a INTEGER);
3935 INSERT INTO it3 VALUES(7), (1), (0), (5), (1), (4);
3936 CREATE
TABLE ot4(a INTEGER);
3937 INSERT INTO ot4 VALUES(1), (3), (5), (7), (9), (7), (3), (1);
3940 SELECT * FROM ot1,ot4
3941 WHERE (ot1.a,ot4.a) IN (SELECT it2.a,it3.a
3945 eval explain $query;
3947 DROP
TABLE IF EXISTS ot1, ot4, it2, it3;
3949 --echo
# End of the test for bug#52068.
3952 --echo # Bug#57623: subquery within before insert trigger causes crash (sj=on)
3955 CREATE
TABLE ot1(a INT);
3956 CREATE
TABLE ot2(a INT);
3957 CREATE
TABLE ot3(a INT);
3958 CREATE
TABLE it1(a INT);
3960 INSERT INTO ot1 VALUES(0),(1),(2),(3),(4),(5),(6),(7);
3961 INSERT INTO ot2 VALUES(0),(2),(4),(6);
3962 INSERT INTO ot3 VALUES(0),(3),(6);
3963 INSERT INTO it1 VALUES(0),(1),(2),(3),(4),(5),(6),(7);
3969 (ot2
JOIN ot3 on ot2.a=ot3.a)
3970 ON ot1.a=ot2.a AND ot1.a IN (SELECT a from it1);
3972 eval explain $query;
3975 eval prepare s from '$query';
3980 deallocate prepare s;
3982 DROP
TABLE ot1, ot2, ot3, it1;
3984 --echo
# End of the test for bug#57623.
3987 --echo # Bug#11766739: Crash in tmp_table_param::init() with semijoin=on
3990 CREATE
TABLE t1 (f1 INTEGER) ENGINE=MyISAM;
3991 CREATE
TABLE t2 (f1 INTEGER, f2 INTEGER) ENGINE=MyISAM;
3993 INSERT INTO t1 VALUES (1);
3994 INSERT INTO t2 VALUES (1,1), (2,1);
3998 WHERE f2 IN (SELECT t1.f1
3999 FROM t1 LEFT OUTER
JOIN (t2 AS b1
JOIN t2 AS b2 ON TRUE) ON TRUE);
4000 eval EXPLAIN $query;
4005 --echo # End of the
test for bug#11766739.
4008 --echo # Bug#11766642: crash in Item_field::register_field_in_read_map with
view
4010 CREATE
TABLE t1(a INT);
4011 CREATE VIEW v1 AS SELECT a FROM t1;
4013 INSERT INTO t1 VALUES (0),(1),(2);
4015 SELECT a FROM t1 WHERE a IN
4016 (SELECT a XOR a FROM v1)
4023 --echo # Bug#12546542 MISSING ROW WHEN USING OPTIMIZER_JOIN_CACHE_LEVEL>=3
4028 INSERT INTO t1 VALUES (
'v'),(
'we');
4030 col_varchar_1024_utf8 varchar(1024) CHARACTER SET utf8 DEFAULT NULL,
4034 INSERT INTO t2 VALUES (
'we',4,NULL),(
'v',1305673728,6);
4039 INSERT INTO t3 VALUES (4,4);
4043 WHERE f2 IN (SELECT a1.col_varchar_1024_utf8 AS f2
4044 FROM t2 AS a1 LEFT
JOIN t3 AS a2
4045 ON a1.col_int_key = a2.col_int_key
4046 WHERE a1.col_int BETWEEN 1 AND 10 OR a2.col_int IS NOT NULL);
4047 DROP
TABLE t1,t2,t3;
4050 --echo # BUG#12616344 - JCL: DIFFERENT RESULT SET AND DIFFERENT AMOUNT
4051 --echo # OF ROWS WHEN JCL>=3
4053 # duplicate of Bug#12546542 but still tested as query is different
4054 CREATE
TABLE t1 (col_int_nokey
int, col_int_key
int, col_varchar_key varchar(1));
4055 INSERT INTO t1 VALUES (0,4,
'c'),(1,6,
'u');
4056 CREATE
TABLE t2 (pk
int, col_int_nokey
int, col_varchar_nokey varchar(1));
4057 INSERT INTO t2 VALUES (1,4,
'b'),(94,6,
'u');
4058 CREATE
TABLE t3 (pk
int, col_int_nokey
int, col_varchar_key varchar(1));
4059 INSERT INTO t3 VALUES (1,4,
'j'),(2,6,
'v');
4060 SELECT table2.col_int_key
4061 from t3 as table1 join t1 as table2 on table2.col_int_nokey
4062 where table1.col_int_nokey in
4064 select subquery2_t2.col_int_nokey
4065 from t3 as subquery2_t1
4068 join t1 as subquery2_t3
4069 on subquery2_t3.col_int_key = subquery2_t2.col_int_nokey
4070 on subquery2_t3.col_varchar_key = subquery2_t2.col_varchar_nokey
4071 where subquery2_t1.col_varchar_key != table1.col_varchar_key
4072 or subquery2_t2.pk <= table1.pk
4075 DROP
TABLE t1,t2,t3;
4078 --echo # Bug#12608157: ASSERT IN FIELD_LONG::VAL_INT WHEN USING MEMORY ENGINE
4081 CREATE
TABLE t1 (i1
int);
4082 INSERT INTO t1 VALUES (1);
4084 CREATE
TABLE t2 (i1
int, i2
int) ENGINE=memory;
4085 INSERT INTO t2 VALUES (1, 2),(7, 3);
4087 SELECT GRANDPARENT1.i1
4088 FROM t2 AS GRANDPARENT1
4089 WHERE GRANDPARENT1.i2
4090 IN ( SELECT PARENT1.i2
4091 FROM t2 AS PARENT1
JOIN t1 AS PARENT2 ON (PARENT1.i1 = PARENT2.i1)
4093 GRANDPARENT1.i1 IN ( SELECT CHILD1.i1 FROM t2 AS CHILD1 )
4094 ORDER BY PARENT1.i1)
4095 ORDER BY GRANDPARENT1.i2 ;
4100 --echo # Bug#12640083: Same
query executed as WHERE subquery gives different
4101 --echo # results on IN()
compare
4106 col_varchar_1024_utf8_key varchar(1024) CHARACTER SET utf8 DEFAULT NULL,
4107 col_varchar_10_latin1_key varchar(10) DEFAULT NULL,
4109 KEY col_varchar_1024_utf8_key(col_varchar_1024_utf8_key(333)),
4110 KEY col_varchar_10_latin1_key(col_varchar_10_latin1_key)
4113 INSERT INTO t1 VALUES
4117 (4,
'abcd',
'abcd');
4120 pk
int NOT NULL AUTO_INCREMENT,
4125 SELECT alias1.col_varchar_10_latin1_key
4127 LEFT
JOIN t1 AS alias2
4129 ON alias2.col_varchar_10_latin1_key
4130 ON alias1.col_varchar_1024_utf8_key
4131 WHERE alias1.pk AND alias1.pk < 3 OR alias1.pk AND alias3.pk;
4136 WHERE col_varchar_10_latin1_key IN (
4137 SELECT alias1.col_varchar_10_latin1_key
4139 LEFT
JOIN t1 AS alias2
4141 ON alias2.col_varchar_10_latin1_key
4142 ON alias1.col_varchar_1024_utf8_key
4143 WHERE alias1.pk AND alias1.pk < 3 OR alias1.pk AND alias3.pk);
4145 eval EXPLAIN $query;
4148 DROP
TABLE t1, t2, t3;
4150 --echo
# End of the test for bug#12640083.
4153 --echo # Bug#12603200 - Assert in QUICK_INDEX_MERGE_SELECT::need_sorted_output
4158 col_int_key
int NOT NULL,
4159 col_varchar_nokey varchar(1) NOT NULL,
4160 col_varchar_key varchar(1) NOT NULL,
4162 KEY col_int_key(col_int_key),
4163 KEY col_varchar_key(col_varchar_key, col_int_key)
4166 INSERT INTO t1 VALUES
4186 col_int_key
int NOT NULL,
4187 col_varchar_key varchar(1) NOT NULL,
4189 KEY col_varchar_key(col_varchar_key, col_int_key)
4192 INSERT INTO t2(pk,col_int_key,col_varchar_key) VALUES
4215 SELECT outr.col_varchar_key AS x, outr.pk AS y
4217 WHERE outr.col_varchar_key IN (SELECT innr.col_varchar_key
4219 WHERE innr.col_varchar_key = 'a' OR innr.pk = 8)
4220 AND outr.col_varchar_nokey < 't'
4221 ORDER BY outr.col_varchar_key, outr.pk;
4223 -- disable_query_log
4224 -- disable_result_log
4227 -- enable_result_log
4230 eval EXPLAIN $query;
4235 --echo
# End of bug#12603200
4238 --echo # Bug#12603183: Segfault in hp_movelink
4242 col_varchar_key varchar(1) ,
4243 col_varchar_nokey varchar(1) ,
4244 KEY col_varchar_key(col_varchar_key)
4247 INSERT INTO t1 VALUES
4265 col_varchar_nokey varchar(1)
4268 INSERT INTO t2 VALUES
4272 SELECT grandparent1.col_varchar_nokey
4273 FROM t1 AS grandparent1 LEFT
JOIN t2 AS grandparent2 USING (col_varchar_nokey)
4274 WHERE (grandparent1.col_varchar_key) IN
4275 (SELECT parent1.col_varchar_nokey
4277 WHERE parent1.col_varchar_key IN
4278 (SELECT child1.col_varchar_nokey AS c1
4279 FROM t1 AS child1 LEFT
JOIN t2 AS child2
4280 ON (child1.col_varchar_key > child2.col_varchar_nokey)));
4282 eval EXPLAIN $query;
4288 --echo
# End of test for bug#12603183.
4291 --echo # Bug#12818569: Diff nr of rows returned when
using IN/ALL+subquery
4295 col_int_key INT NOT NULL,
4296 col_datetime_key DATETIME NOT NULL,
4297 col_varchar_key VARCHAR(1) NOT NULL,
4298 KEY col_int_key (col_int_key),
4299 KEY col_datetime_key(col_datetime_key),
4300 KEY col_varchar_key (col_varchar_key,col_int_key)
4303 INSERT INTO t1 VALUES
4304 (7,'2004-06-06 04:22:12','v'), (0,'2005-11-13 01:12:31','s'),
4305 (9,'2002-05-04 01:50:00','l'), (3,'2004-10-27 10:28:45','y'),
4306 (4,'2006-07-22 05:24:23','c'), (2,'2002-05-16 21:34:03','i'),
4307 (5,'2008-04-17 10:45:30','h'), (3,'2009-04-21 02:58:02','q'),
4308 (1,'2008-01-11 11:01:51','a'), (3,'1900-01-01 00:00:00','v'),
4309 (6,'2007-05-17 18:24:57','u'), (7,'2007-08-07 00:00:00','s'),
4310 (5,'2001-08-28 00:00:00','y'), (1,'2004-04-16 00:27:28','z'),
4311 (204,'2005-05-03 07:06:22','h'), (224,'2009-03-11 17:09:50','p'),
4312 (9,'2007-12-08 01:54:28','e'), (5,'2009-07-28 18:19:54','i'),
4313 (0,'2008-06-08 00:00:00','y'), (3,'2005-02-09 09:20:26','w');
4316 col_varchar_nokey VARCHAR(1) NOT NULL
4319 INSERT INTO t2 VALUES ('v'), ('y'), ('j'), ('c'), ('d'), ('r');
4321 -- disable_query_log
4322 -- disable_result_log
4325 -- enable_result_log
4329 SELECT col_varchar_key
4331 WHERE col_varchar_key IN (SELECT col_varchar_nokey
4333 ORDER BY col_datetime_key LIMIT 4;
4335 eval explain $query;
4340 --echo
# End of test for bug#12818569.
4343 --echo # Bug#12803439: Assert in replace_subcondition() on update
query
4346 CREATE
TABLE t1(a INTEGER);
4348 INSERT INTO t1 values(1), (2);
4350 CREATE
TABLE t2(a INTEGER);
4352 INSERT INTO t2 VALUES(1), (3);
4356 WHERE a IN (SELECT a
4358 HAVING a IN (SELECT a
4361 HAVING a IN (SELECT a
4366 --echo # End of
test for bug#12803439.
4369 --echo # Bug#12797534: Segfault in hp_movelink still exists
4373 g1 VARCHAR(1) NOT NULL
4376 INSERT INTO t1 VALUES (
'd'), (
's');
4380 col_int_key INT NOT NULL,
4381 col_varchar_key VARCHAR(1) NOT NULL,
4382 col_varchar_nokey VARCHAR(1) NOT NULL,
4384 KEY col_varchar_key(col_varchar_key, col_int_key)
4387 INSERT INTO t2 VALUES
4388 (1,4,'j','j'), (2,6,'v','v'), (3,3,'c','c'), (4,5,'m','m'),
4389 (5,3,'d','d'), (6,246,'d','d'), (7,2,'y','y'), (8,9,'t','t'),
4390 (9,3,'d','d'), (10,8,'s','s'), (11,1,'r','r'), (12,8,'m','m'),
4391 (13,8,'b','b'), (14,5,'x','x'), (15,7,'g','g'), (16,5,'p','p'),
4392 (17,1,'q','q'), (18,6,'w','w'), (19,2,'d','d'), (20,9,'e','e');
4395 pk INTEGER NOT NULL,
4399 INSERT INTO t3 VALUES (10);
4401 -- disable_query_log
4402 -- disable_result_log
4406 ANALYZE
TABLE grandparent1;
4407 ANALYZE
TABLE parent1;
4408 -- enable_result_log
4415 (SELECT grandparent1.col_varchar_nokey AS g1
4416 FROM t2 AS grandparent1
4417 WHERE grandparent1.col_varchar_key IN
4418 (SELECT parent1.col_varchar_nokey AS p1
4419 FROM t2 AS parent1 LEFT
JOIN t3 AS parent2 USING (pk)
4421 AND grandparent1.col_varchar_key IS NOT NULL
4424 eval EXPLAIN $query;
4427 DROP
TABLE t1, t2, t3;
4430 pk INTEGER AUTO_INCREMENT,
4431 col_int_key INTEGER ,
4432 col_varchar_key VARCHAR(1) ,
4433 col_varchar_nokey VARCHAR(1) ,
4435 KEY (col_varchar_key,col_int_key)
4437 INSERT INTO t1 (col_int_key,col_varchar_key,col_varchar_nokey) VALUES
4438 (0,'x','x'), (1,'j','j'), (1,'r','r'), (9,'v','v'), (5,'r','r');
4441 pk INTEGER AUTO_INCREMENT,
4442 col_int_key INTEGER ,
4443 col_varchar_key VARCHAR(1) ,
4444 col_varchar_nokey VARCHAR(1) ,
4447 KEY (col_varchar_key,col_int_key)
4448 ) AUTO_INCREMENT=10 ENGINE=INNODB;
4449 INSERT INTO t2 (col_int_key, col_varchar_key, col_varchar_nokey) VALUES
4450 (NULL,'x','x'), (NULL,'j','j'), (8,'c','c');
4453 SELECT outr.col_varchar_nokey AS x
4455 WHERE outr.col_varchar_nokey IN
4456 (SELECT innr.col_varchar_nokey AS y
4458 WHERE innr.col_int_key IS NULL)
4459 AND outr.col_varchar_nokey IS NOT NULL
4460 AND NOT col_varchar_key IS NULL;
4465 (SELECT outr.col_varchar_nokey AS x
4467 WHERE outr.col_varchar_nokey IN
4468 (SELECT innr.col_varchar_nokey AS y
4470 WHERE innr.col_int_key IS NULL)
4471 AND outr.col_varchar_nokey IS NOT NULL
4472 AND NOT col_varchar_key IS NULL);
4474 DROP
TABLE t1, t2, t3;
4476 --echo
# End of test for bug#12797534.
4479 --echo # Bug#12714094: Assert in optimize_semijoin_nests()
4484 col_varchar VARCHAR(10) DEFAULT NULL,
4488 INSERT INTO it VALUES (1, 'g');
4491 SELECT alias1.pk AS field1
4493 LEFT
JOIN it AS alias2
4494 ON alias1.col_varchar = alias2.col_varchar
4501 LEFT
JOIN it AS alias2
4502 ON alias1.col_varchar = alias2.col_varchar
4507 --echo
# End of test for bug#12714094
4510 --echo # Bug#12867557: Valgrind: conditional jump/move at key_cmp
4514 pk INTEGER AUTO_INCREMENT,
4515 col_int_key INTEGER,
4518 ) AUTO_INCREMENT=10;
4520 INSERT INTO t1 (col_int_key) VALUES (8);
4523 pk INTEGER AUTO_INCREMENT,
4524 col_int_key INTEGER,
4529 ) AUTO_INCREMENT=10;
4531 INSERT INTO t2 (col_int_key, col_time_key)
4533 (8, '22:55:23.019225'), (7, '10:19:31.050677'), (1, '14:40:36.038608'),
4534 (7, '04:37:47.062416'), (9, '19:34:06.054514'), (NULL,'20:35:33.022996'),
4535 (1, NULL), (9, '14:43:37.057393'), (2, '02:23:09.043438'),
4536 (9, '01:22:45.041064'), (2, '00:00:00'), (4, '00:13:25.038482'),
4537 (0, '03:47:16.042671'), (4, '01:41:48.007423'), (8, '00:00:00'),
4538 (NULL, '22:32:04.047407'), (NULL, '16:44:14.028443'), (0, '17:38:37.059754'),
4539 (NULL, '08:46:48.042388'), (8, '14:11:27.044095');
4542 SELECT DISTINCT grandparent1.col_time_key AS g1
4543 FROM t2 AS grandparent1
4544 WHERE grandparent1.col_int_key IN
4545 (SELECT parent1.col_int_key AS p1
4547 AND grandparent1.pk > 9;
4552 (SELECT grandparent1.col_time_key AS g1
4553 FROM t2 AS grandparent1
4554 WHERE grandparent1.col_int_key IN
4555 (SELECT parent1.col_int_key AS p1
4557 AND grandparent1.pk > 9);
4559 DROP
TABLE t0, t1, t2;
4561 --echo
# End of test for bug#12867557
4564 --echo # Bug#12711441: crash in fix_after_pullout
4569 col_int_nokey
int DEFAULT NULL,
4570 col_int_key
int DEFAULT NULL,
4571 col_time_key time DEFAULT NULL,
4572 col_varchar_key varchar(1) DEFAULT NULL,
4576 CREATE VIEW v1 AS SELECT * FROM t1;
4579 col_int_key
int DEFAULT NULL,
4580 col_varchar_key varchar(1) DEFAULT NULL,
4581 col_varchar_nokey varchar(1) DEFAULT NULL,
4582 KEY col_varchar_key(col_varchar_key, col_int_key)
4587 col_int_key INT DEFAULT NULL,
4592 col_int_nokey INT DEFAULT NULL,
4593 col_varchar_key varchar(1) DEFAULT NULL,
4594 col_varchar_nokey varchar(1) DEFAULT NULL,
4595 KEY col_varchar_key(col_varchar_key)
4599 SELECT alias1.col_time_key AS field1
4601 RIGHT
JOIN t3 AS alias2
4602 ON alias2.col_int_key = alias1.col_int_nokey
4603 WHERE alias1.pk >= SOME(
4604 SELECT SQ1_alias1.pk AS SQ1_field1
4605 FROM t3 AS SQ1_alias1
4606 INNER
JOIN (t2 AS SQ1_alias2
4607 INNER
JOIN t4 AS SQ1_alias3
4608 ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
4609 ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
4610 WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
4611 AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
4614 SELECT * FROM ts WHERE field1 IN (
4615 SELECT alias1.col_time_key AS field1
4617 RIGHT
JOIN t3 AS alias2
4618 ON alias2.col_int_key = alias1.col_int_nokey
4619 WHERE alias1.pk >= SOME(
4620 SELECT SQ1_alias1.pk AS SQ1_field1
4621 FROM t3 AS SQ1_alias1
4622 INNER
JOIN (t2 AS SQ1_alias2
4623 INNER
JOIN t4 AS SQ1_alias3
4624 ON SQ1_alias3.col_varchar_key = SQ1_alias2.col_varchar_nokey)
4625 ON SQ1_alias3.col_int_nokey = SQ1_alias2.col_int_key
4626 WHERE SQ1_alias2.col_varchar_key <= alias1.col_varchar_key
4627 AND SQ1_alias3.col_varchar_nokey <> alias1.col_varchar_key)
4630 DROP
TABLE t1, t2, t3, t4, ts;
4633 --echo # End of
test for bug#12711441.
4636 --echo # Bug#12664936: Same
query executed as where subquery ...
4640 col_varchar_key VARCHAR(1),
4641 KEY col_varchar_key (col_varchar_key)
4644 INSERT INTO t1 VALUES
4645 (
'o'), (
'w'), (
'm'), (
'q'),
4646 (
'f'), (
'p'), (
'j'), (
'c');
4649 col_int_nokey INTEGER,
4650 col_int_key INTEGER,
4651 col_varchar_key varchar(1),
4652 KEY col_int_key (col_int_key)
4655 INSERT INTO t2 VALUES
4656 (8,5,
'u'),(4,5,
'p'),(8,1,
'o'),(NULL,7,
'v'),
4657 (1,2,
'g'),(2,1,
'q'),(NULL,7,
'l'),(3,1,
'n');
4660 SELECT t2.col_int_nokey, t2.col_varchar_key
4661 FROM t1
JOIN t2 ON t2.col_varchar_key = t1.col_varchar_key
4662 WHERE t2.col_int_key = 1;
4667 WHERE (col_int_nokey, col_varchar_key) IN
4668 (SELECT t2.col_int_nokey, t2.col_varchar_key
4669 FROM t1
JOIN t2 ON t2.col_varchar_key = t1.col_varchar_key
4670 WHERE t2.col_int_key = 1
4673 eval EXPLAIN $query;
4676 DROP
TABLE t1, t2, t4;
4678 --echo
# End of test for bug#12664936.
4681 --echo # Bug#13340270: assertion
table->sort.record_pointers == __null
4686 col_int_key
int DEFAULT NULL,
4687 col_varchar_key varchar(1) DEFAULT NULL,
4688 col_varchar_nokey varchar(1) DEFAULT NULL,
4690 KEY col_int_key (col_int_key),
4691 KEY col_varchar_key (col_varchar_key, col_int_key)
4694 INSERT INTO t1 VALUES
4709 SELECT alias1.col_varchar_nokey AS field1
4710 FROM t1 AS alias1
JOIN t1 AS alias2
4711 ON alias2.col_int_key = alias1.pk OR
4712 alias2.col_int_key = alias1.col_int_key
4713 WHERE alias1.pk = 58 OR alias1.col_varchar_key = 'o'
4716 eval CREATE
TABLE t2
4720 -- disable_query_log
4721 -- disable_result_log
4724 -- enable_result_log
4727 eval EXPLAIN SELECT *
4729 WHERE (field1) IN ($query);
4733 WHERE (field1) IN ($query);
4737 --echo
# End of test for bug#13340270.
4740 --echo # Bug#13335319: Seg fault when analyzing FirstMatch semi-join strategy
4743 CREATE
TABLE ot1(a INTEGER);
4745 INSERT INTO ot1 VALUES(1), (2), (3);
4747 CREATE
TABLE ot2(a INTEGER);
4749 INSERT INTO ot2 VALUES(1), (2), (4), (6), (8), (10);
4751 CREATE
TABLE it1(a INTEGER);
4753 INSERT INTO it1 VALUES(1), (3), (5), (7);
4755 CREATE
TABLE it2(a INTEGER);
4757 INSERT INTO it2 VALUES(1), (3), (5), (7), (9);
4762 WHERE ot1.a IN (SELECT a FROM it1) AND
4763 ot2.a IN (SELECT a FROM it2);
4765 eval explain $query;
4768 DROP
TABLE ot1, ot2, it1, it2;
4770 --echo # End of
test for bug#13335319.
4773 --echo # Bug#13334882: Assertion keypart_map failed in MyIsam
function
4778 col_int_nokey INT NOT NULL,
4779 col_int_key INT NOT NULL,
4781 KEY col_int_key (col_int_key)
4784 INSERT INTO t1 VALUES
4799 col_int_nokey
int NOT NULL,
4800 col_int_key
int NOT NULL,
4802 KEY col_int_key (col_int_key)
4805 INSERT INTO t2 VALUES
4809 SELECT grandparent1.col_int_nokey AS g1
4810 FROM t1 AS grandparent1
4811 WHERE (grandparent1.col_int_nokey, grandparent1.col_int_key) IN
4812 (SELECT parent1.col_int_key AS p1,
4813 parent1.col_int_key AS p2
4815 LEFT
JOIN t2 AS parent2
4816 ON parent1.col_int_nokey = parent2.col_int_key
4818 AND grandparent1.col_int_key <> 3
4824 (SELECT grandparent1.col_int_nokey AS g1
4825 FROM t1 AS grandparent1
4826 WHERE (grandparent1.col_int_nokey, grandparent1.col_int_key) IN
4827 (SELECT parent1.col_int_key AS p1,
4828 parent1.col_int_key AS p2
4830 LEFT
JOIN t2 AS parent2
4831 ON parent1.col_int_nokey = parent2.col_int_key
4833 AND grandparent1.col_int_key <> 3
4836 eval explain $query;
4837 eval explain format=json $query;
4840 DROP
TABLE t1, t2, t3;
4842 --echo
# End of test for bug#13334882.
4845 --echo # Bug#13339643: Assertion on JOIN::flatten_subqueries on second execution
4850 col_varchar_nokey VARCHAR(1)
4853 INSERT INTO t1 VALUES
4857 CREATE
TABLE t2 LIKE t1;
4859 INSERT INTO t2 VALUES
4863 CREATE VIEW v_t2 AS SELECT * FROM t2;
4865 CREATE
TABLE t3 LIKE t1;
4867 INSERT INTO t3 VALUES
4872 SELECT alias1.col_varchar_nokey
4874 INNER
JOIN v_t2 AS alias2
4875 ON alias2.col_int_nokey = alias1.col_int_nokey AND
4876 'o' IN (SELECT col_varchar_nokey
4878 eval explain $query;
4881 eval PREPARE stmt FROM
"$query";
4885 DROP
TABLE t1, t2, t3;
4886 --echo # End of
test for bug#13339643.
4889 --echo # Bug#13424134: Wrong result on
JOIN + nested WHERE ... IN clauses
4894 col_int_nokey
int NOT NULL,
4895 col_int_key
int NOT NULL,
4897 KEY col_int_key (col_int_key)
4900 INSERT INTO t1 VALUES
4901 (10,1,7), (13,7,3), (18,0,1), (23,8,1);
4905 col_int_key
int NOT NULL,
4907 KEY col_int_key (col_int_key)
4910 INSERT INTO t2 VALUES (1,7);
4915 JOIN t1 AS t1b USING ( col_int_nokey )
4916 WHERE t1a.col_int_key IN (
4919 WHERE col_int_key IN (
4920 SELECT col_int_nokey
4925 eval EXPLAIN $query;
4928 ALTER
TABLE t1 ENGINE=Innodb;
4929 ALTER
TABLE t2 ENGINE=Innodb;
4935 --echo
# End of test for bug#13424134.
4938 --echo # Bug#13414014: Extra rows in result on semijoin
query with where ...
4949 INSERT INTO t1 VALUES
4950 (NULL,8,
'x',
'x'), (7,4,
'q',
'q'), (6,8,
'c',
'c');
4957 INSERT INTO t2 VALUES
4958 (
'c'), (NULL), (
'x'), (
'q');
4966 WHERE it.a = 'x' OR it.c > it.d
4970 eval explain $query;
4975 --echo
# End of test for bug#13414014.
4978 --echo # Bug#13545215: Missing rows on nested in-subquery with materialization
4983 col_varchar_key varchar(1),
4984 col_varchar_nokey varchar(1),
4985 KEY col_int_key (col_int_key),
4986 KEY col_varchar_key (col_varchar_key,col_int_key)
4989 INSERT INTO t1 VALUES
4990 (8,
'x',
'x'), (0,
'p',
'p'), (8,
'c',
'c');
4994 col_varchar_key varchar(1),
4995 col_varchar_nokey varchar(1),
4997 KEY col_varchar_key (col_varchar_key)
5000 INSERT INTO t2 VALUES
5001 (1,
'v',
'v'), (2,
'v',
'v'), (3,
'c',
'c'), (4,NULL,NULL),
5002 (5,
'x',
'x'), (6,
'i',
'i'), (7,
'e',
'e'), (8,
'p',
'p');
5008 INSERT INTO t3 VALUES (7);
5011 SELECT grandparent1.col_varchar_nokey
5012 FROM t1 AS grandparent1
JOIN t1 AS grandparent2 USING (col_int_key)
5013 WHERE grandparent1.col_varchar_key IN (
5014 SELECT col_varchar_nokey
5016 WHERE col_varchar_key IN (
5017 SELECT child1.col_varchar_nokey
5018 FROM t2 AS child1 LEFT
JOIN t3 AS child2
5019 ON child1.pk < child2.col_int_nokey
5023 eval explain $query;
5027 DROP
TABLE t1, t2, t3;
5029 --echo
# End of test for bug#13545215.
5032 --echo # BUG#13553211 - MISSING ROWS ON SELECT WITH IN-SUBQUERY AND
5033 --echo # MATERIALIZATION + SEMIJOIN ON
5036 col_int_key
int(11) DEFAULT NULL,
5037 col_varchar_key varchar(1) DEFAULT NULL,
5038 col_varchar_nokey varchar(1) DEFAULT NULL,
5039 KEY col_int_key (col_int_key),
5040 KEY col_varchar_key (col_varchar_key,col_int_key)
5043 INSERT INTO t1 VALUES (4,
'v',
'v');
5044 INSERT INTO t1 VALUES (62,
'v',
'v');
5045 INSERT INTO t1 VALUES (7,
'c',
'c');
5046 INSERT INTO t1 VALUES (1,NULL,NULL);
5050 alias1.col_varchar_nokey AS a1_nokey,
5051 alias1.col_varchar_key AS a1_key,
5052 alias2.col_varchar_nokey AS a2_nokey
5054 t1 AS alias1, t1 AS alias2
5056 (alias1.col_varchar_nokey,alias2.col_varchar_nokey)
5060 SQ2_alias2.col_varchar_nokey, SQ2_alias1.col_varchar_key
5062 t1 AS SQ2_alias1, t1 AS SQ2_alias2
5066 eval EXPLAIN $query;
5073 --echo # Bug#13541406: Wrong result with loosescan on select .. where .. in
5077 col_int_key INT NOT NULL,
5078 col_varchar_nokey VARCHAR(1) NOT NULL,
5079 KEY col_int_key (col_int_key)
5082 INSERT INTO t1 VALUES
5083 (7,'v'), (0,'s'), (9,'l'), (3,'y'), (4,'c'), (2,'i'), (5,'h'), (3,'q'),
5084 (1,'a'), (3,'v'), (6,'u'), (7,'s'), (5,'y'), (1,'z'), (204,'h'), (224,'p'),
5085 (9,'e'), (5,'i'), (0,'y'), (3,'w');
5089 col_int_key INT NOT NULL,
5090 col_varchar_key VARCHAR(1) NOT NULL,
5091 col_varchar_nokey VARCHAR(1) NOT NULL,
5093 KEY col_int_key (col_int_key),
5094 KEY col_varchar_key (col_varchar_key,col_int_key)
5097 INSERT INTO t2 VALUES
5098 (1,0,'j','j'), (2,8,'v','v'), (3,1,'c','c'), (4,8,'m','m'),
5099 (5,9,'d','d'), (6,24,'d','d'), (7,6,'y','y'), (8,1,'t','t'),
5100 (9,6,'d','d'), (10,2,'s','s'), (11,4,'r','r'), (12,8,'m','m'),
5101 (13,4,'b','b'), (14,4,'x','x'), (15,7,'g','g'), (16,4,'p','p'),
5102 (17,1,'q','q'), (18,9,'w','w'), (19,4,'d','d'), (20,8,'e','e');
5104 -- disable_query_log
5105 -- disable_result_log
5108 -- enable_result_log
5112 SELECT ot1.col_int_key AS field1
5113 FROM t2 AS ot1, t2 AS ot2
5114 WHERE (ot1.col_varchar_key, ot2.col_varchar_nokey) IN (
5115 SELECT it2.col_varchar_nokey, it1.col_varchar_key
5116 FROM t2 AS it1
JOIN t1 AS it2 ON it2.col_int_key = it1.pk);
5118 --echo
# This query should never use a LooseScan strategy
5120 eval explain $query;
5126 --echo # End of
test for bug#13541406.
5129 --echo # Bug#13576391: Missing rows on select with in-subquery and
5130 --echo # batched-key-access=on and semijoin
5134 col_int_nokey
int NOT NULL,
5135 col_varchar_key varchar(1) NOT NULL,
5136 KEY col_varchar_key (col_varchar_key)
5139 INSERT INTO t1 VALUES
5140 (1,'v'), (7,'s'), (4,'l'), (7,'y'), (0,'c'), (2,'i'), (9,'h'), (4,'q'),
5141 (0,'a'), (9,'v'), (1,'u'), (3,'s'), (8,'y'), (8,'z'), (18,'h'), (84,'p'),
5142 (6,'e'), (3,'i'), (6,'y'), (6,'w');
5145 col_int_nokey
int NOT NULL,
5146 col_varchar_nokey varchar(1) NOT NULL
5149 INSERT INTO t2 VALUES
5150 (4,'j'), (6,'v'), (3,'c'), (5,'m'), (3,'d'), (246,'d'), (2,'y'), (9,'t'),
5151 (3,'d'), (8,'s'), (1,'r'), (8,'m'), (8,'b'), (5,'x'), (7,'g'), (5,'p'),
5152 (1,'q'), (6,'w'), (2,'d'), (9,'e');
5154 -- disable_query_log
5155 -- disable_result_log
5158 -- enable_result_log
5162 SELECT col_varchar_nokey
5164 WHERE col_varchar_nokey IN (
5165 SELECT col_varchar_key
5167 WHERE it.col_int_nokey <= it.col_int_nokey
5168 AND NOT ot.col_int_nokey < 2
5170 ORDER BY col_varchar_nokey;
5172 eval explain $query;
5175 ALTER
TABLE t1 ENGINE=MyISAM;
5176 ALTER
TABLE t2 ENGINE=MyISAM;
5178 eval explain $query;
5181 ALTER
TABLE t1 ENGINE=Memory;
5182 ALTER
TABLE t2 ENGINE=Memory;
5184 eval explain $query;
5189 --echo
# End of test for bug#13576391.
5192 --echo # Bug #13589848
"MISSING ROW ON SELECT WITH NESTED IN CLAUSES WHEN LOOSESCAN=ON"
5196 col_varchar_key VARCHAR(1),
5197 col_varchar_nokey VARCHAR(1),
5198 KEY (col_varchar_key)
5201 INSERT INTO t1 VALUES (100,
'm',
'm'),
5202 (200,
'b',
'b'), (300,
'x',
'x');
5205 col_varchar_key VARCHAR(1),
5206 col_varchar_nokey VARCHAR(1),
5207 KEY (col_varchar_key)
5210 INSERT INTO t2 VALUES (
'b',
'b');
5213 col_varchar_key VARCHAR(1),
5214 col_varchar_nokey VARCHAR(1),
5215 KEY (col_varchar_key)
5218 INSERT INTO t3 VALUES (
'k',
'k');
5220 let $query=SELECT GP1.id
5221 FROM t1 AS GP1
JOIN t3 AS GP2
5222 ON GP2.col_varchar_key <> GP1.col_varchar_nokey
5223 WHERE (GP1.col_varchar_nokey, GP1.col_varchar_nokey)
5225 SELECT col_varchar_nokey, col_varchar_nokey
5227 WHERE col_varchar_nokey
5228 IN ( SELECT col_varchar_key
5229 FROM t2 LEFT
JOIN t3 USING (col_varchar_key) )
5233 eval EXPLAIN $query;
5236 DROP
TABLE t1,t2,t3;
5239 --echo # Bug #13596176: Missing row on select with nested in clause when
5240 --echo # matr=on and bnl=off + MyISAM
5244 int_key
int DEFAULT NULL,
5245 vc_key varchar(1) DEFAULT NULL,
5246 vc_nokey varchar(1) DEFAULT NULL,
5247 KEY int_key (int_key),
5248 KEY vc_key (vc_key, int_key)
5251 INSERT INTO t1 VALUES
5252 (8,'x','x'), (7,'d','d'), (1,'r','r'), (7,'f','f'),
5253 (9,'y','y'), (NULL,'u','u'), (1,'m','m'), (9,NULL,NULL),
5254 (2,'o','o'), (9,'w','w'), (2,'m','m'), (4,'q','q'),
5255 (0,NULL,NULL), (4,'d','d'), (8,'g','g'), (NULL,'x','x'),
5256 (NULL,'f','f'), (0,'p','p'), (NULL,'j','j'), (8,'c','c');
5259 int_key
int DEFAULT NULL,
5260 vc_key varchar(1) DEFAULT NULL,
5261 KEY int_key (int_key),
5262 KEY vc_key (vc_key, int_key)
5265 INSERT INTO t2 VALUES (8,'g');
5270 WHERE (vc_nokey, vc_key ) IN
5271 (SELECT vc_nokey, vc_nokey
5274 (SELECT child1.vc_key
5275 FROM t2 AS child1
JOIN t1 AS child2 USING (int_key)
5279 eval explain $query;
5284 --echo
# End of test for bug#13596176.
5287 --echo # BUG#11754478: MAX/MIN + SUBQUERY + AND FAILS TO RETURN ANY ROWS
5288 --echo # BUG#13599013: MAX/MIN + SUBQUERY IN WHERE CLAUSE MATCHING NO
5289 --echo # ROWS + INDEX DOES NOT RETURN NULL
5293 pk
int(11) PRIMARY KEY,
5295 KEY int_key (int_key)
5298 INSERT INTO t1 VALUES (1,0),(2,0),(3,2),(4,0),(5,3),(6,0);
5300 SELECT MIN(int_key) FROM t1 WHERE (4, 4) IN (SELECT 1, 2);
5301 SELECT MIN(int_key) FROM t1 WHERE (4, 4) IN (SELECT 4, 4);
5302 SELECT MIN(pk) FROM t1 WHERE pk IN (SELECT int_key FROM t1) AND pk = 6;
5306 --echo
# BUG#13726217: Crash in Item_ident::fix_after_pullout()
5308 CREATE
TABLE t1(a INTEGER) engine=innodb;
5309 INSERT INTO t1 VALUES (0);
5317 (SELECT elt(a, 0) AS b
5326 --echo # End of
test for bug#13726217.
5328 --echo # BUG#13773979: Missing rows on second execution of prepared
statement
5333 col_varchar_key VARCHAR(1)
5336 INSERT INTO t1 VALUES
5337 (1,7,
'v'), (7,0,
's'), (4,9,
'l'), (7,3,
'y'),
5338 (2,2,
'i'), (9,5,
'h'), (0,1,
'a'), (9,3,
'v');
5340 CREATE VIEW v1 AS SELECT * FROM t1;
5345 WHERE col_int_key IN (
5346 SELECT alias1.col_int_nokey AS field1
5348 WHERE alias1.col_varchar_key <
'v'
5351 eval prepare stmt FROM
"$query";
5355 DEALLOCATE PREPARE stmt;
5360 --echo # End of
test for bug#13773979.
5363 --echo # BUG#13685026 ASSERTION CUR_SJ_INNER_TABLES == 0 IN
5364 --echo # --OPTIMIZE_TABLE_ORDER::CHOOSE_TABLE_ORDER
5368 col_int_key INT(11) NOT NULL,
5369 col_datetime_key DATETIME NOT NULL,
5370 col_varchar_key VARCHAR(1) NOT NULL,
5371 col_varchar_nokey VARCHAR(1) NOT NULL,
5372 KEY col_int_key (col_int_key),
5373 KEY col_datetime_key (col_datetime_key),
5374 KEY col_varchar_key (col_varchar_key,col_int_key)
5377 INSERT INTO t1 VALUES (0,
'2002-02-13 17:30:06',
'j',
'j');
5378 INSERT INTO t1 VALUES (8,
'2008-09-27 00:34:58',
'v',
'v');
5381 col_int_key INT(11) NOT NULL,
5382 col_datetime_key DATETIME NOT NULL,
5383 col_varchar_key VARCHAR(1) NOT NULL,
5384 col_varchar_nokey VARCHAR(1) NOT NULL,
5385 KEY col_int_key (col_int_key),
5386 KEY col_datetime_key (col_datetime_key),
5387 KEY col_varchar_key (col_varchar_key,col_int_key)
5390 INSERT INTO t2 VALUES (7,
'2003-08-21 00:00:00',
'b',
'b');
5392 SET @old_depth=@@optimizer_search_depth;
5393 SET optimizer_search_depth=4;
5395 let $query=SELECT col_datetime_key
5397 WHERE col_datetime_key IN (
5398 SELECT alias1.col_datetime_key
5400 LEFT
JOIN t1 as alias3
5401 STRAIGHT_JOIN ( t2 AS alias4
5403 ON alias5.col_varchar_key <= alias4.col_varchar_nokey )
5404 ON alias5.col_int_key < alias4.col_int_key
5405 ON alias5.col_varchar_key = alias4.col_varchar_key
5408 eval EXPLAIN $query;
5412 SET @@optimizer_search_depth=@old_depth;
5415 --echo # BUG#13848789: SEGFAULT IN JOIN_READ_NEXT_SAME AT
5416 --echo # SQL/SQL_EXECUTOR.CC ON HAVING...IN...JOIN
5421 col_varchar_key VARCHAR(1),
5422 KEY col_int_key (col_int_key),
5423 KEY col_varchar_key (col_varchar_key)
5426 INSERT INTO t1 VALUES (8,
'x');
5429 col_varchar_key VARCHAR(1),
5430 KEY col_varchar_key (col_varchar_key)
5433 INSERT INTO t2 VALUES (
'x'), (
'y');
5435 let $query= SELECT MIN(col_int_key)
5438 SELECT t1_inner.col_int_key, MAX(t1_inner.col_int_key)
5439 FROM t1 as t1_inner
JOIN t2
5440 ON t2.col_varchar_key = t1_inner.col_varchar_key
5444 --eval explain $query
5449 --echo
# Bug#13838810: Segfault in evaluate_null_complemented_join_record
5453 col_int_nokey
int DEFAULT NULL,
5454 col_int_key
int DEFAULT NULL,
5455 col_varchar_key varchar(1) DEFAULT NULL,
5457 KEY col_int_key (col_int_key),
5458 KEY col_varchar_key (col_varchar_key,col_int_key)
5461 INSERT INTO t1 VALUES (10,NULL,8,'x');
5465 col_varchar_nokey varchar(1) DEFAULT NULL,
5469 INSERT INTO t2 VALUES (1,'x');
5473 col_varchar_key varchar(1) DEFAULT NULL,
5474 col_varchar_nokey varchar(1) DEFAULT NULL,
5476 KEY col_varchar_key (col_varchar_key)
5479 INSERT INTO t3 VALUES
5480 (1,'v','v'), (2,'v','v'), (3,'c','c'), (4,NULL,NULL);
5483 SELECT table1.pk,table2.pk, table3.pk
5485 LEFT
JOIN t1 AS table2
5486 LEFT
JOIN t1 AS table3
5487 ON table3.col_int_key = table2.col_int_key
5488 ON table3.pk = table2.col_int_nokey AND
5489 table1.col_varchar_nokey IN (
5490 SELECT subquery3_t1.col_varchar_nokey
5491 FROM t3 AS subquery3_t1
5492 LEFT
JOIN t1 AS subquery3_t2
5493 ON subquery3_t2.col_varchar_key = subquery3_t1.col_varchar_key
5494 WHERE subquery3_t2.col_int_nokey <> 9
5498 eval EXPLAIN $query;
5501 DROP
TABLE t1, t2, t3;
5503 --echo Extra
test case for specific
code coverage
5505 CREATE
TABLE t1(pk INTEGER);
5506 INSERT INTO t1 VALUES(1), (2);
5510 FROM t1 AS ot1 LEFT
JOIN t1 AS ot2
5511 ON ot1.pk=ot2.pk AND
5514 FROM t1 AS it1 LEFT
JOIN t1 AS it2 ON it1.pk=it2.pk);
5515 eval explain $query;
5520 --echo
# End of test for bug#13838810.
5523 --echo # BUG#13685026 ASSERTION CUR_SJ_INNER_TABLES == 0 IN
5524 --echo # --OPTIMIZE_TABLE_ORDER::CHOOSE_TABLE_ORDER
5528 col_int_key INT(11) NOT NULL,
5529 col_datetime_key DATETIME NOT NULL,
5530 col_varchar_key VARCHAR(1) NOT NULL,
5531 col_varchar_nokey VARCHAR(1) NOT NULL,
5532 KEY col_int_key (col_int_key),
5533 KEY col_datetime_key (col_datetime_key),
5534 KEY col_varchar_key (col_varchar_key,col_int_key)
5537 INSERT INTO t1 VALUES (0,
'2002-02-13 17:30:06',
'j',
'j');
5538 INSERT INTO t1 VALUES (8,
'2008-09-27 00:34:58',
'v',
'v');
5541 col_int_key INT(11) NOT NULL,
5542 col_datetime_key DATETIME NOT NULL,
5543 col_varchar_key VARCHAR(1) NOT NULL,
5544 col_varchar_nokey VARCHAR(1) NOT NULL,
5545 KEY col_int_key (col_int_key),
5546 KEY col_datetime_key (col_datetime_key),
5547 KEY col_varchar_key (col_varchar_key,col_int_key)
5550 INSERT INTO t2 VALUES (7,
'2003-08-21 00:00:00',
'b',
'b');
5552 SET @old_depth=@@optimizer_search_depth;
5553 SET optimizer_search_depth=4;
5555 let $query=SELECT col_datetime_key
5557 WHERE col_datetime_key IN (
5558 SELECT alias1.col_datetime_key
5560 LEFT
JOIN t1 as alias3
5561 STRAIGHT_JOIN ( t2 AS alias4
5563 ON alias5.col_varchar_key <= alias4.col_varchar_nokey )
5564 ON alias5.col_int_key < alias4.col_int_key
5565 ON alias5.col_varchar_key = alias4.col_varchar_key
5568 eval EXPLAIN $query;
5572 SET @@optimizer_search_depth=@old_depth;
5583 col_varchar_1 VARCHAR(1),
5584 col_varchar_2 VARCHAR(1)
5587 INSERT INTO t2 VALUES (
'x',
'x'), (
'c',
'c');
5590 SELECT alias2.col_varchar_2 AS field1
5594 LEFT JOIN t2 AS alias3
5596 (SELECT sq1_alias1.col_int,
5598 FROM t1 AS sq1_alias1 JOIN t1 AS sq1_alias2
5601 ON alias3.col_varchar_1 = alias2.col_varchar_2
5607 DEALLOCATE prepare stmt;
5611 --echo # End of
test for bug#13845930.
5614 --echo # Bug#13855925: Assert
'prebuilt->search_tuple->n_fields > 0'
5619 pk INTEGER AUTO_INCREMENT,
5622 col_varchar_key VARCHAR(1),
5623 col_varchar_nokey VARCHAR(1),
5625 KEY (col_varchar_key)
5629 col_int_key, col_int_nokey,
5630 col_varchar_key, col_varchar_nokey
5632 (4, 2, 'v','v'), (62, 150, 'v','v'), (7, NULL, 'c','c'), (1, 2, NULL, NULL),
5633 (0, 5, 'x','x'), (7, 3, 'i','i'), (7, 1, 'e','e'), (1, 4, 'p','p'),
5634 (7, NULL, 's','s'), (1, 2, 'j','j'), (5, 6, 'z','z'), (2, 6, 'c','c'),
5635 (0, 8, 'a','a'), (1, 2, 'q','q'), (8, 6, 'y','y'), (1, 8, NULL, NULL),
5636 (1, 3, 'r','r'), (9, 3, 'v','v'), (1, 9, NULL, NULL), (5, 6, 'r','r');
5639 pk INT AUTO_INCREMENT,
5644 ) AUTO_INCREMENT=10 ENGINE=INNODB;
5646 INSERT INTO t2 (col_int_key, col_int_nokey) VALUES
5647 (8, NULL), (7, 8), (1, 1), (7, 9), (9, 4), (NULL, 3), (1, 2), (9, NULL),
5648 (2, 2), (9, NULL), (2, 6), (4, 7), (0, 2), (4, 5), (8, 7), (NULL, 6),
5649 (NULL, 6), (0, 2), (NULL, 9), (8, 6);
5652 pk INT AUTO_INCREMENT,
5653 col_varchar_key VARCHAR(1),
5655 KEY (col_varchar_key)
5658 INSERT INTO t3 (col_varchar_key) VALUES
5659 ('c'), ('c'), ('q'), ('g'), ('e'), ('l'), (NULL), ('c'), ('h'), ('d'),
5660 ('c'), ('i'), ('t'), ('g'), ('q'), ('l'), ('n'), ('z'), ('n'), ('r'), ('p');
5662 -- disable_query_log
5663 -- disable_result_log
5667 -- enable_result_log
5671 SELECT table2.col_varchar_nokey AS field1
5673 INNER
JOIN (t1 AS table2
5674 STRAIGHT_JOIN t2 AS table3
5675 ON table3.col_int_key = table2.pk AND
5676 table3.col_int_nokey = ANY
5677 (SELECT subquery1_t2.col_int_nokey AS subquery1_field1
5678 FROM t2 AS subquery1_t1
5679 RIGHT OUTER
JOIN t1 AS subquery1_t2
5680 INNER
JOIN t1 AS subquery1_t3
5681 ON subquery1_t3.col_int_key = subquery1_t2.pk
5682 ON subquery1_t3.col_varchar_key=subquery1_t2.col_varchar_nokey
5683 WHERE subquery1_t1.pk > 1
5686 ON table3.col_int_key IN
5687 (SELECT subquery2_t1.col_int_key AS subquery2_field1
5688 FROM t2 AS subquery2_t1
5689 RIGHT OUTER
JOIN t3 AS subquery2_t2
5690 LEFT OUTER
JOIN t1 AS subquery2_t3
5691 ON subquery2_t3.col_varchar_key = subquery2_t2.col_varchar_key
5692 ON subquery2_t3.pk = subquery2_t2.pk
5696 explain SELECT * FROM v1;
5700 DROP
TABLE t1,t2,t3;
5702 --echo
# End of test for bug#13855925.
5705 --echo # Bug#13897959: Segfault in setup_semijoin_dups_elimination()
5709 col_datetime_key DATETIME DEFAULT NULL,
5710 KEY col_datetime_key (col_datetime_key)
5713 INSERT INTO t1 VALUES
5714 ('2001-04-18 00:00:00'), ('2008-12-18 19:39:55'),
5715 ('2000-08-01 12:19:39'), ('2004-09-25 21:29:06'),
5716 ('2009-09-20 09:11:48'), ('2004-03-27 09:32:04');
5719 col_date_nokey date DEFAULT NULL,
5720 col_time_key time DEFAULT NULL,
5721 col_datetime_key datetime DEFAULT NULL,
5722 col_varchar_key varchar(1) DEFAULT NULL,
5723 col_varchar_nokey varchar(1) DEFAULT NULL,
5724 KEY col_time_key (col_time_key),
5725 KEY col_datetime_key (col_datetime_key),
5726 KEY col_varchar_key(col_varchar_key)
5729 INSERT INTO t2 VALUES ('1900-01-01',NULL,'2001-11-04 19:07:55','x','x');
5731 SELECT grandparent1.col_varchar_nokey
5732 FROM t2 AS grandparent1 LEFT
JOIN t1 USING (col_datetime_key)
5733 WHERE grandparent1.col_varchar_nokey IN (
5734 SELECT col_varchar_nokey
5736 WHERE parent1.col_time_key > grandparent1.col_date_nokey
5741 --echo
# End of test for bug#13897959.
5744 --echo # Bug#13898625 ASSERT `(REMAINING_TABLES_AFTER != 0) ...
' IN
5745 --echo # BEST_EXTENSION_BY_LIMITED_SEARCH
5749 pk int(11) NOT NULL,
5752 col_varchar_key VARCHAR(1),
5753 col_varchar_nokey VARCHAR(1),
5755 KEY col_int_key (col_int_key),
5756 KEY col_varchar_key (col_varchar_key,col_int_key)
5759 INSERT INTO t1 VALUES (26,6,NULL,'f
','f
');
5760 INSERT INTO t1 VALUES (29,6,8,'c
','c
');
5766 col_varchar_key VARCHAR(1),
5767 col_varchar_nokey VARCHAR(1),
5769 KEY col_int_key (col_int_key),
5770 KEY col_varchar_key (col_varchar_key,col_int_key)
5773 INSERT INTO t2 VALUES (1,2,4,'v
','v
');
5774 INSERT INTO t2 VALUES (2,150,62,'v
','v
');
5775 INSERT INTO t2 VALUES (5,5,0,'x
','x
');
5776 INSERT INTO t2 VALUES (6,3,7,'i
','i
');
5777 INSERT INTO t2 VALUES (7,1,7,'e
','e
');
5779 CREATE VIEW view_c AS SELECT * FROM t2;
5782 SELECT SUM( alias1.col_varchar_key ) AS field1
5784 RIGHT JOIN t2 AS alias2
5785 INNER JOIN t1 AS alias3
5786 ON (alias3.col_varchar_key = alias2.col_varchar_key )
5788 SELECT sq1_alias1.col_varchar_nokey AS sq1_field1
5789 FROM t1 AS sq1_alias1
5791 WHERE alias3.pk IN (
5792 SELECT sq2_alias1.col_int_key AS sq2_field1
5793 FROM ( view_c AS sq2_alias1, t1 AS sq2_alias2 )
5797 eval PREPARE prep_stmt_7430 FROM '$query
';
5798 EXECUTE prep_stmt_7430;
5799 EXECUTE prep_stmt_7430;
5800 eval EXPLAIN $query;
5802 # Assertion sj_inner_tables == ((remaining_tables |
5803 # new_join_tab->table->map) & sj_inner_tables)
5806 SELECT SUM( alias1.col_varchar_key ) AS field1
5808 RIGHT JOIN t2 AS alias2
5809 INNER JOIN t1 AS alias3
5810 ON (alias3.col_varchar_key = alias2.col_varchar_key )
5812 SELECT sq1_alias1.col_varchar_nokey AS sq1_field1
5813 FROM t1 AS sq1_alias1
5815 WHERE alias3.pk IN (
5816 SELECT sq2_alias1.col_int_key AS sq2_field1
5817 FROM ( view_c AS sq2_alias1 , t1 AS sq2_alias2 )
5818 WHERE sq2_alias1.col_varchar_nokey <> alias2.col_varchar_key
5819 AND sq2_alias1.col_varchar_key < "l"
5823 eval PREPARE prep_stmt_7430 FROM '$query
';
5824 EXECUTE prep_stmt_7430;
5825 EXECUTE prep_stmt_7430;
5826 eval EXPLAIN $query;
5832 --echo # Bug#13902463 SEGFAULT IN BITMAP<64U>::MERGE OR ADD_KEY_FIELD
5833 --echo # ON SECOND EXEC OF PREP STMT
5840 col_varchar_key VARCHAR(1),
5841 col_varchar_nokey VARCHAR(1),
5842 KEY col_varchar_key (col_varchar_key)
5845 CREATE VIEW view_b AS SELECT * FROM t1;
5848 SELECT alias2.col_varchar_nokey AS field1
5850 INNER JOIN t1 AS alias2
5851 ON (alias1.col_varchar_key = alias2.col_varchar_nokey
5852 AND ( alias1.col_int_key ) IN (
5853 SELECT t1.col_int_nokey
5857 WHERE alias1.col_varchar_key IN (
5858 SELECT sq2_alias2.col_varchar_nokey AS sq2_field1
5859 FROM view_b AS sq2_alias1
5860 INNER JOIN t1 AS sq2_alias2
5861 ON (sq2_alias2.col_varchar_key = sq2_alias1.col_varchar_key )
5862 WHERE sq2_alias1.pk > alias2.pk
5866 eval PREPARE prep_stmt_20421 FROM '$query
';
5867 EXECUTE prep_stmt_20421;
5868 EXECUTE prep_stmt_20421;
5869 eval EXPLAIN $query;
5871 ALTER TABLE t1 DROP INDEX col_varchar_key;
5872 # Assertion join->best_read < double(1.79769313486231570815e+308L)
5873 eval PREPARE prep_stmt_20421 FROM '$query
';
5874 EXECUTE prep_stmt_20421;
5875 EXECUTE prep_stmt_20421;
5876 eval EXPLAIN $query;
5882 --echo # Bug#13907277: Segfault in evaluate_null_complemented_join_record
5887 col_varchar_nokey VARCHAR(1),
5888 col_varchar_key VARCHAR(1),
5891 INSERT INTO t1 VALUES (1, 'x
', 'x
');
5897 INSERT INTO t2 VALUES (1);
5901 col_int_nokey INTEGER,
5902 col_int_key INTEGER,
5903 col_varchar_nokey VARCHAR(1),
5906 INSERT INTO t3 VALUES (1, 6, 5, 'r
');
5909 SELECT outer_t1.pk, outer_t2.pk
5911 RIGHT JOIN t2 AS outer_t2
5912 ON outer_t1.col_int_nokey IN
5913 (SELECT inner_t1.col_int_nokey
5915 LEFT JOIN t1 AS inner_t2
5916 INNER JOIN t1 AS inner_t3
5917 ON inner_t3.pk = inner_t2.pk
5918 ON inner_t3.col_varchar_nokey = inner_t2.col_varchar_key
5921 eval explain $query;
5924 DROP TABLE t1, t2, t3;
5926 --echo # End of test for bug#13907277.
5929 --echo # Bug#13955713: Assert 'JOIN->
best_read < ...
' on second execution
5934 col_varchar_key VARCHAR(1),
5935 col_varchar_nokey VARCHAR(1)
5939 SELECT MIN(alias2.col_varchar_key) AS field1
5941 INNER JOIN (t1 AS alias2
5942 INNER JOIN t1 AS alias3
5944 (SELECT sq1_alias1.pk AS sq1_field2
5945 FROM t1 AS sq1_alias1
5947 (SELECT SUM(t1_sq1_alias1.pk) AS t1_sq1_field2
5948 FROM t1 AS t1_sq1_alias1
5952 ON alias3.col_varchar_nokey = alias2.col_varchar_key
5954 (SELECT sq2_alias1.pk AS sq2_field1
5955 FROM t1 AS sq2_alias1
5956 WHERE sq2_alias1.col_varchar_key < alias1.col_varchar_nokey
5963 DEALLOCATE PREPARE stmt;
5966 --echo # End of test for bug#13955713.
5969 --echo # Bug#13956813: Segfault in memcpy from Join_cache::write_record_data()
5974 col_varchar_key VARCHAR(1),
5975 col_varchar_nokey VARCHAR(1)
5980 col_varchar_key VARCHAR(1),
5981 col_varchar_nokey VARCHAR(1)
5984 INSERT INTO t2 VALUES
5985 (10,'j
','j
'), (11,'z
','z
'), (12,'c
','c
'), (13,'a
','a
'),
5986 (14,'q
','q
'), (15,'y
','y
'), (16,NULL,NULL), (17,'r
','r
'),
5987 (18,'v
','v
'), (19,NULL,NULL), (20,'r
','r
');
5992 col_varchar_key VARCHAR(1),
5993 KEY col_int_key (col_int_key)
5996 INSERT INTO t3 VALUES
5997 (15,NULL,'u
'), (16,1,'m
'), (17,9,NULL), (18,2,'o
'),
5998 (19,9,'w
'), (20,2,'m
'), (21,4,'q
'), (22,0,NULL),
5999 (23,4,'d
'), (24,8,'g
'), (25,NULL,'x
'), (26,NULL,'f
'),
6000 (27,0,'p
'), (28,NULL,'j
'), (29,8,'c
');
6002 CREATE VIEW view_inline_0 AS
6004 FROM t1 INNER JOIN t3
6007 CREATE VIEW view_inline_1 AS
6008 SELECT sq2_alias2.col_varchar_key AS sq2_field1,
6009 sq2_alias1.col_varchar_key AS sq2_field2
6010 FROM t3 AS sq2_alias1 LEFT OUTER JOIN t3 AS sq2_alias2
6011 ON sq2_alias1.pk = sq2_alias2.col_int_key;
6013 CREATE VIEW view_inline_2 AS
6014 SELECT 'p
', 'p
' UNION SELECT 'k
', 's
';
6017 SELECT SUM(alias1.col_varchar_nokey) AS field2
6019 LEFT JOIN (SELECT * FROM view_inline_0) AS alias1
6020 ON alias2.col_varchar_key = alias1.col_varchar_key AND
6021 (alias2.col_varchar_nokey, alias2.col_varchar_key) IN
6022 (SELECT * FROM view_inline_1
6024 WHERE (alias1.col_varchar_key, alias1.col_varchar_nokey) IN
6025 (SELECT * FROM view_inline_2
6028 eval explain $query;
6031 DROP VIEW view_inline_0, view_inline_1, view_inline_2;
6032 DROP TABLE t1, t2, t3;
6034 --echo # End of test for bug#13956813.
6037 --echo # Bug#13974177: Assert !(tab->table->regginfo.not_exists_optimize...
6041 pk INTEGER AUTO_INCREMENT,
6042 col_int_nokey INTEGER,
6043 col_int_key INTEGER,
6044 col_varchar_key VARCHAR(1),
6045 col_varchar_nokey VARCHAR(1),
6048 KEY (col_varchar_key, col_int_key)
6051 INSERT INTO t1(col_int_key, col_int_nokey, col_varchar_key, col_varchar_nokey)
6053 (0, 4, 'j
', 'j
'), (8, 6, 'v
', 'v
'), (1, 3, 'c
', 'c
'), (8, 5, 'm
', 'm
'),
6054 (9, 3, 'd
', 'd
'), (24, 246, 'd
', 'd
'), (6, 2, 'y
', 'y
'), (1, 9, 't
', 't
'),
6055 (6, 3, 'd
', 'd
'), (2, 8, 's
', 's
'), (4, 1, 'r
', 'r
'), (8, 8, 'm
', 'm
'),
6056 (4, 8, 'b
', 'b
'), (4, 5, 'x
', 'x
'), (7, 7, 'g
', 'g
'), (4, 5, 'p
', 'p
'),
6057 (1, 1, 'q
', 'q
'), (9, 6, 'w
', 'w
'), (4, 2, 'd
', 'd
'), (8, 9, 'e
', 'e
');
6060 pk INTEGER AUTO_INCREMENT,
6061 col_int_nokey INTEGER NOT NULL,
6062 col_time_key TIME NOT NULL,
6063 col_time_nokey TIME NOT NULL,
6068 INSERT INTO t2 (col_int_nokey, col_time_key, col_time_nokey) VALUES
6069 (7, '00:00:00
', '00:00:00
'), (0, '00:00:00
', '00:00:00
'),
6070 (9, '06:35:17
', '06:35:17
'), (3, '18:07:14
', '18:07:14
'),
6071 (4, '20:36:52
', '20:36:52
'), (2, '21:29:07
', '21:29:07
'),
6072 (5, '23:45:57
', '23:45:57
'), (3, '22:54:57
', '22:54:57
'),
6073 (1, '18:45:09
', '18:45:09
'), (3, '14:30:46
', '14:30:46
'),
6074 (6, '19:23:43
', '19:23:43
'), (7, '03:39:30
', '03:39:30
'),
6075 (5, '23:37:52
', '23:37:52
'), (1, '16:59:30
', '16:59:30
'),
6076 (204, '22:21:15
', '22:21:15
'), (224, '12:24:37
', '12:24:37
'),
6077 (9, '15:02:08
', '15:02:08
'), (5, '23:59:59
', '23:59:59
'),
6078 (0, '08:23:30
', '08:23:30
'), (3, '08:32:22
', '08:32:22
');
6080 -- disable_query_log
6081 -- disable_result_log
6084 -- enable_result_log
6088 SELECT ot1.col_int_key AS x
6091 ON ot2.col_varchar_nokey > ot1.col_varchar_key
6092 WHERE (ot1.col_int_nokey, ot1.pk) IN
6093 (SELECT it1.pk AS x,
6094 it1.col_int_nokey AS y
6097 ON it2.col_time_nokey = it1.col_time_key
6098 ) AND ot1.pk IS NULL
6101 eval explain $query;
6106 --echo # End of test for bug#13974177.
6109 --echo # Bug#13971022: Assert 'keyparts > 0
' failed in create_ref_for_key...
6115 col_varchar_key VARCHAR(1),
6117 KEY col_varchar_key (col_varchar_key,col_int_key)
6123 col_varchar_key VARCHAR(1),
6124 col_varchar_nokey VARCHAR(1),
6133 SELECT table1.pk AS field1
6134 FROM ( SELECT subquery1_t1. *
6135 FROM t2 AS subquery1_t1
6136 JOIN t2 AS subquery1_t2
6137 ON subquery1_t2.pk = subquery1_t1.pk) AS table1
6138 STRAIGHT_JOIN t2 AS table2
6139 ON table1.col_int_key IN (SELECT 7 FROM t3)
6140 WHERE table1.col_varchar_nokey IN
6141 (SELECT subquery3_t1.col_varchar_key AS subquery3_field1
6142 FROM t1 AS subquery3_t1
6146 eval explain $query;
6149 DROP TABLE t1, t2, t3;
6151 --echo # End of test for bug#13971022.
6154 --echo # Bug#13623473 "MISSING ROWS ON SELECT AND JOIN WITH
6155 --echo # TIME/DATETIME COMPARE" - Subquery part of test.
6158 SET TIMESTAMP=UNIX_TIMESTAMP('2012-01-31 10:14:35
');
6163 col_int_key INT NOT NULL,
6165 KEY col_int_key (col_int_key)
6168 INSERT INTO t1 VALUES (10,1,7), (11,7,0), (12,4,9), (13,7,3),
6169 (14,0,4), (15,2,2), (16,9,5), (17,4,3), (18,0,1), (19,9,3), (20,1,6),
6170 (21,3,7), (22,8,5), (23,8,1), (24,18,204), (25,84,224), (26,6,9),
6171 (27,3,5), (28,6,0), (29,6,3);
6174 col_int_nokey INT NOT NULL,
6175 col_datetime_key DATETIME NOT NULL,
6176 col_varchar_key VARCHAR(1) NOT NULL,
6177 KEY col_datetime_key (col_datetime_key),
6178 KEY col_varchar_key (col_varchar_key)
6181 INSERT INTO t2 VALUES (1,'2001-11-04 19:07:55
','k
');
6185 KEY col_time_key (col_time_key)
6188 INSERT INTO t3 VALUES ('21:22:34
'), ('10:50:38
'), ('00:21:38
'),
6189 ('04:08:02
'), ('16:25:11
'), ('10:14:58
'), ('19:47:59
'), ('11:14:24
'),
6190 ('00:00:00
'), ('00:00:00
'), ('15:57:25
'), ('07:05:51
'), ('19:22:21
'),
6191 ('03:53:16
'), ('09:16:38
'), ('15:37:26
'), ('00:00:00
'), ('05:03:03
'),
6192 ('02:59:24
'), ('00:01:58
');
6194 -- disable_query_log
6195 -- disable_result_log
6199 -- enable_result_log
6203 SELECT outr.col_int_nokey
6205 STRAIGHT_JOIN t3 AS outr2
6206 ON outr2.col_time_key > outr.col_datetime_key
6207 WHERE outr.col_int_nokey IN (
6210 WHERE innr.pk >= innr.col_int_nokey
6212 outr.col_int_nokey <= 6
6214 outr.col_varchar_key IS NULL
6216 eval EXPLAIN EXTENDED $query;
6220 DROP TABLE t1,t2,t3;
6222 SET TIMESTAMP = DEFAULT;
6224 --echo # End of test for bug#13623473.
6227 --echo # Bug#13980954: Missing data on left join + null value + where..in
6235 INSERT INTO t1 VALUES (8, 'x
'), (NULL, 'x
');
6242 INSERT INTO t2 VALUES
6243 (0, 'x
'), (7, 'i
'), (7, 'e
'), (1, 'p
'), (7, 's
'), (1, 'j
');
6246 SELECT t2.vc, t2.ik AS t2_ik, t1.ik AS t1_ik
6247 FROM t2 LEFT JOIN t1 ON t2.vc=t1.vc
6248 WHERE t2.vc IN (SELECT vc FROM t2 AS t3);
6250 eval explain format=json $query;
6255 --echo # End of test for bug#13980954.
6258 --echo # Bug#14048292: Segfault in Item_field::result_type on 2nd execution
6259 --echo # of prep stmt with join of view
6266 INSERT INTO t1 VALUES (0), (1);
6268 CREATE VIEW view_t1 AS SELECT * FROM t1;
6271 SELECT alias1.col_int
6273 LEFT JOIN view_t1 AS alias2
6274 ON alias1.col_int IN
6275 (SELECT sq1_alias1.col_int
6276 FROM t1 AS sq1_alias1
6279 eval explain $query;
6281 eval PREPARE stmt FROM "$query";
6285 DEALLOCATE PREPARE stmt;
6289 --echo # End of test for bug#14048292.
6292 --echo # Bug#14064201: Missing data on join of derived table + WHERE .. IN
6293 --echo # with two operands
6297 col_varchar_nokey VARCHAR(1)
6300 INSERT INTO t1 VALUES
6301 ('v
'), ('s
'), ('l
'), ('y
'), ('c
'), ('i
'), ('h
'), ('q
'), ('a
'), ('v
'),
6302 ('u
'), ('s
'), ('y
'), ('z
'), ('h
'), ('p
'), ('e
'), ('i
'), ('y
'), ('w
');
6305 col_varchar_key VARCHAR(1),
6306 col_varchar_nokey VARCHAR(1),
6307 KEY col_varchar_key(col_varchar_key)
6310 INSERT INTO t2 VALUES
6311 ('j
','j
'), ('v
','v
'), ('c
','c
'), ('m
','m
'), ('d
','d
'), ('d
','d
'), ('y
','y
');
6315 FROM (SELECT * FROM t2) AS derived1
6317 USING (col_varchar_nokey)
6318 WHERE (col_varchar_nokey, col_varchar_nokey) IN
6319 (SELECT col_varchar_nokey, col_varchar_key
6323 eval explain format=json $query;
6329 col_int_nokey int NOT NULL,
6330 col_int_key int NOT NULL,
6331 KEY col_int_key (col_int_key)
6334 INSERT INTO t1 VALUES
6335 (1,7), (7,0), (4,9), (7,3), (0,4), (2,2), (9,5), (4,3), (0,1), (9,3),
6336 (1,6), (3,7), (8,5), (8,1), (18,204), (84,224), (6,9), (3,5), (6,0), (6,3);
6339 col_int_nokey int NOT NULL,
6340 col_int_key int NOT NULL,
6341 KEY col_int_key (col_int_key)
6344 INSERT INTO t2 VALUES
6345 (4,0), (6,8), (3,1), (5,8), (3,9), (246,24), (2,6), (9,1), (3,6), (8,2),
6346 (1,4), (8,8), (8,4), (5,4), (7,7), (5,4), (1,1), (6,9), (2,4), (9,8);
6349 SELECT grandparent1.*
6350 FROM t1 AS grandparent1
6351 LEFT JOIN t1 USING (col_int_nokey)
6352 WHERE (col_int_nokey, col_int_nokey) IN
6353 (SELECT col_int_nokey, col_int_key
6357 eval explain format=json $query;
6365 col_datetime_key datetime,
6366 col_varchar_key varchar(1),
6367 col_varchar_nokey varchar(1),
6369 KEY col_int_key (col_int_key),
6370 KEY col_datetime_key (col_datetime_key),
6371 KEY col_varchar_key (col_varchar_key,col_int_key)
6374 INSERT INTO t1 VALUES
6375 (10,7,'2004-06-06 04:22:12
','v
','v
'), (11,0,'2005-11-13 01:12:31
','s
','s
'),
6376 (12,9,'2002-05-04 01:50:00
','l
','l
'), (13,3,'2004-10-27 10:28:45
','y
','y
'),
6377 (14,4,'2006-07-22 05:24:23
','c
','c
'), (15,2,'2002-05-16 21:34:03
','i
','i
'),
6378 (16,5,'2008-04-17 10:45:30
','h
','h
'), (17,3,'2009-04-21 02:58:02
','q
','q
'),
6379 (18,1,'2008-01-11 11:01:51
','a
','a
'), (19,3,'1900-01-01 00:00:00
','v
','v
'),
6380 (20,6,'2007-05-17 18:24:57
','u
','u
'), (21,7,'2007-08-07 00:00:00
','s
','s
'),
6381 (22,5,'2001-08-28 00:00:00
','y
','y
'), (23,1,'2004-04-16 00:27:28
','z
','z
'),
6382 (24,204,'2005-05-03 07:06:22
','h
','h
'), (25,224,'2009-03-11 17:09:50
','p
','p
'),
6383 (26,9,'2007-12-08 01:54:28
','e
','e
'), (27,5,'2009-07-28 18:19:54
','i
','i
'),
6384 (28,0,'2008-06-08 00:00:00
','y
','y
'), (29,3,'2005-02-09 09:20:26
','w
','w
');
6389 col_datetime_key datetime,
6390 col_varchar_key varchar(1),
6391 col_varchar_nokey varchar(1),
6393 KEY col_int_key (col_int_key),
6394 KEY col_datetime_key (col_datetime_key),
6395 KEY col_varchar_key (col_varchar_key,col_int_key)
6398 INSERT INTO t2 VALUES
6399 (1,0,'2002-02-13 17:30:06
','j
','j
'), (2,8,'2008-09-27 00:34:58
','v
','v
'),
6400 (3,1,'2007-05-28 00:00:00
','c
','c
'), (4,8,'2009-07-25 09:21:20
','m
','m
'),
6401 (5,9,'2002-01-16 00:00:00
','d
','d
'), (6,24,'2006-10-12 04:32:53
','d
','d
'),
6402 (7,6,'2001-02-15 03:08:38
','y
','y
'), (8,1,'2004-10-02 20:31:15
','t
','t
'),
6403 (9,6,'2002-08-20 22:48:00
','d
','d
'), (10,2,'1900-01-01 00:00:00
','s
','s
'),
6404 (11,4,'2005-08-15 00:00:00
','r
','r
'), (12,8,'1900-01-01 00:00:00
','m
','m
'),
6405 (13,4,'2008-05-16 08:09:06
','b
','b
'), (14,4,'2001-01-20 12:47:23
','x
','x
'),
6406 (15,7,'2008-07-02 00:00:00
','g
','g
'), (16,4,'1900-01-01 00:00:00
','p
','p
'),
6407 (17,1,'2002-12-08 11:34:58
','q
','q
'), (18,9,'1900-01-01 00:00:00
','w
','w
'),
6408 (19,4,'1900-01-01 00:00:00
','d
','d
'), (20,8,'2002-08-25 20:35:06
','e
','e
');
6410 SELECT alias1.col_datetime_key
6412 RIGHT JOIN t2 AS alias2
6414 ON alias3.pk = alias2.pk
6415 ON alias3.col_varchar_nokey = alias2.col_varchar_key OR
6416 alias2.col_varchar_nokey
6417 WHERE (alias2.col_varchar_key, alias2.col_varchar_key) IN
6418 (SELECT sq2_alias2.col_varchar_key, sq2_alias1.col_varchar_nokey
6419 FROM t1 AS sq2_alias1, t1 AS sq2_alias2
6420 WHERE sq2_alias2.col_int_key < 2);
6422 ALTER TABLE t1 DISABLE KEYS;
6423 ALTER TABLE t2 DISABLE KEYS;
6426 SELECT alias1.col_datetime_key
6428 RIGHT JOIN t2 AS alias2
6430 ON alias3.pk = alias2.pk
6431 ON alias3.col_varchar_nokey = alias2.col_varchar_key OR
6432 alias2.col_varchar_nokey
6433 WHERE (alias2.col_varchar_key, alias2.col_varchar_key) IN
6434 (SELECT sq2_alias2.col_varchar_key, sq2_alias1.col_varchar_nokey
6435 FROM t1 AS sq2_alias1, t1 AS sq2_alias2
6436 WHERE sq2_alias2.col_int_key < 2);
6438 eval explain format=json $query;
6443 --echo # End of test for bug#14064201.
6445 set @@optimizer_switch=@old_opt_switch;
6446 # New tests go here.
6448 --echo # End of 5.6 tests