MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
subquery_sj_innodb.inc
1 #
2 # DuplicateElimination strategy test
3 #
4 
5 -- disable_query_log
6 -- disable_result_log
7 SET GLOBAL innodb_stats_persistent=0;
8 -- enable_result_log
9 -- enable_query_log
10 
11 create table t0 (a int);
12 insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
13 
14 # First test simple cases: I20 order, no join buffering.
15 
16 create table t1 (
17  a int,
18  b int
19 ) engine=innodb;
20 insert into t1 values (1,1),(1,1),(2,2);
21 
22 create table t2 (
23  a int,
24  b int,
25  key(b)
26 ) engine=innodb;
27 insert into t2 select a, a/2 from t0;
28 
29 select * from t1;
30 select * from t2;
31 explain select * from t2 where b in (select a from t1);
32 select * from t2 where b in (select a from t1);
33 
34 # Try an InnoDB table with very long rowid
35 create table t3 (
36  a int,
37  b int,
38  key(b),
39  pk1 char(200), pk2 char(200), pk3 char(200),
40  primary key(pk1, pk2, pk3)
41 ) engine=innodb;
42 insert into t3 select a,a, a,a,a from t0;
43 
44 explain select * from t3 where b in (select a from t1);
45 select * from t3 where b in (select a from t1);
46 
47 # Test overflow to MyISAM:
48 set @save_max_heap_table_size= @@max_heap_table_size;
49 set max_heap_table_size=16384;
50 set @save_join_buffer_size = @@join_buffer_size;
51 set join_buffer_size= 8192;
52 
53 drop table t3;
54 create table t3 (
55  a int,
56  b int,
57  key(b),
58  pk1 char(200), pk2 char(200),
59  primary key(pk1, pk2)
60 ) engine=innodb;
61 insert into t3 select
62  A.a + 10*B.a, A.a + 10*B.a, A.a + 10*B.a, A.a + 10*B.a
63 from t0 A, t0 B where B.a <5;
64 
65 --replace_column 9 #
66 explain select * from t3 where b in (select a from t0);
67 --sorted_result
68 select * from t3 where b in (select A.a+B.a from t0 A, t0 B where B.a<5);
69 
70 set join_buffer_size= @save_join_buffer_size;
71 set max_heap_table_size= @save_max_heap_table_size;
72 
73 # O2I join orders, with shortcutting:
74 explain select * from t1 where a in (select b from t2);
75 select * from t1;
76 select * from t1 where a in (select b from t2);
77 
78 drop table t0, t1, t2, t3;
79 # (no need for anything in range/index_merge/DS-MRR)
80 
81 #
82 # BUG#34799: crash or/and memory overrun with dependant subquery and some joins
83 #
84 create table t1 (a int);
85 insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
86 
87 create table t2 (a char(200), b char(200), c char(200), primary key (a,b,c)) engine=innodb;
88 insert into t2 select concat(a, repeat('X',198)),repeat('B',200),repeat('B',200) from t1;
89 insert into t2 select concat(a, repeat('Y',198)),repeat('B',200),repeat('B',200) from t1;
90 alter table t2 add filler1 int;
91 
92 insert into t1 select A.a + 10*(B.a + 10*C.a) from t1 A, t1 B, t1 C;
93 
94 set @save_join_buffer_size=@@join_buffer_size;
95 --disable_warnings
96 set join_buffer_size=1;
97 --enable_warnings
98 
99 select * from t2 where filler1 in ( select a from t1);
100 set join_buffer_size=default;
101 
102 drop table t1, t2;
103 
104 
105 --echo
106 --echo BUG#42740: crash in optimize_semijoin_nests
107 --echo
108 create table t1 (c6 timestamp,key (c6)) engine=innodb;
109 create table t2 (c2 double) engine=innodb;
110 explain select 1 from t2 where c2 = any (select log10(null) from t1 where c6 <null) ;
111 drop table t1, t2;
112 
113 --echo #
114 --echo # BUG#42742: crash in setup_sj_materialization, Copy_field::set
115 --echo #
116 create table t3 ( c1 year) engine=innodb;
117 insert into t3 values (2135),(2142);
118 create table t2 (c1 tinytext,c2 text,c6 timestamp) engine=innodb;
119 -- echo # The following must not crash, EXPLAIN should show one SJ strategy, not a mix:
120 explain select 1 from t2 where
121  c2 in (select 1 from t3, t2) and
122  c1 in (select convert(c6,char(1)) from t2);
123 drop table t2, t3;
124 --echo #
125 --echo # BUG#57431: subquery returns wrong result (semijoin=on) with pred AND
126 --echo #
127 CREATE TABLE t1 (
128  i INT
129 ) ENGINE=InnoDB;
130 INSERT INTO t1 VALUES (2),(4);
131 
132 CREATE TABLE t2 (
133  i INT,
134  vc VARCHAR(1)
135 ) ENGINE=InnoDB;
136 INSERT INTO t2 VALUES (8,NULL);
137 
138 SELECT i
139 FROM t1
140 WHERE i IN (SELECT innr.i
141  FROM t2 LEFT JOIN t2 innr ON innr.vc)
142  AND i = 2;
143 
144 DROP TABLE t1, t2;
145 
146 -- disable_query_log
147 -- disable_result_log
148 SET GLOBAL innodb_stats_persistent=default;
149 -- enable_result_log
150 -- enable_query_log