1
by brian
clean slate |
1 |
#
|
2 |
# test of left outer join |
|
3 |
#
|
|
4 |
||
5 |
--disable_warnings
|
|
6 |
drop table if exists t0,t1,t2,t3,t4,t5; |
|
7 |
--enable_warnings
|
|
8 |
||
9 |
CREATE TABLE t1 ( |
|
223
by Brian Aker
Cleanup int() work. |
10 |
grp int default NULL, |
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
11 |
a bigint default NULL, |
1
by brian
clean slate |
12 |
c char(10) NOT NULL default '' |
1063.9.10
by Stewart Smith
fix join_outer for MyISAM as temp only: 1x open table twice, 1x CREATE TEMP |
13 |
);
|
1
by brian
clean slate |
14 |
INSERT INTO t1 VALUES (1,1,'a'),(2,2,'b'),(2,3,'c'),(3,4,'E'),(3,5,'C'),(3,6,'D'),(NULL,NULL,''); |
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
15 |
create table t2 (id int, a bigint not null, c char(10), d int, primary key (a)); |
1
by brian
clean slate |
16 |
insert into t2 values (1,1,"a",1),(3,4,"A",4),(3,5,"B",5),(3,6,"C",6),(4,7,"D",7); |
17 |
||
18 |
select t1.*,t2.* from t1 JOIN t2 where t1.a=t2.a; |
|
19 |
select t1.*,t2.* from t1 left join t2 on (t1.a=t2.a) order by t1.grp,t1.a,t2.c; |
|
20 |
select t1.*,t2.* from { oj t2 left outer join t1 on (t1.a=t2.a) }; |
|
21 |
select t1.*,t2.* from t1 as t0,{ oj t2 left outer join t1 on (t1.a=t2.a) } WHERE t0.a=2; |
|
22 |
select t1.*,t2.* from t1 left join t2 using (a); |
|
23 |
select t1.*,t2.* from t1 left join t2 using (a) where t1.a=t2.a; |
|
24 |
select t1.*,t2.* from t1 left join t2 using (a,c); |
|
25 |
select t1.*,t2.* from t1 left join t2 using (c); |
|
26 |
select t1.*,t2.* from t1 natural left outer join t2; |
|
27 |
||
28 |
select t1.*,t2.* from t1 left join t2 on (t1.a=t2.a) where t2.id=3; |
|
29 |
select t1.*,t2.* from t1 left join t2 on (t1.a=t2.a) where t2.id is null; |
|
30 |
||
1063.9.10
by Stewart Smith
fix join_outer for MyISAM as temp only: 1x open table twice, 1x CREATE TEMP |
31 |
--replace_column 9 #
|
1
by brian
clean slate |
32 |
explain select t1.*,t2.* from t1,t2 where t1.a=t2.a and isnull(t2.a)=1; |
1063.9.10
by Stewart Smith
fix join_outer for MyISAM as temp only: 1x open table twice, 1x CREATE TEMP |
33 |
--replace_column 9 #
|
1
by brian
clean slate |
34 |
explain select t1.*,t2.* from t1 left join t2 on t1.a=t2.a where isnull(t2.a)=1; |
35 |
||
36 |
select t1.*,t2.*,t3.a from t1 left join t2 on (t1.a=t2.a) left join t1 as t3 on (t2.a=t3.a); |
|
37 |
||
38 |
# The next query should rearange the left joins to get this to work |
|
1731.3.1
by Lee Bieber
change tests to use enum values instead of error numbers |
39 |
--error ER_BAD_FIELD_ERROR
|
1
by brian
clean slate |
40 |
explain select t1.*,t2.*,t3.a from t1 left join t2 on (t3.a=t2.a) left join t1 as t3 on (t1.a=t3.a); |
1731.3.1
by Lee Bieber
change tests to use enum values instead of error numbers |
41 |
--error ER_BAD_FIELD_ERROR
|
1
by brian
clean slate |
42 |
select t1.*,t2.*,t3.a from t1 left join t2 on (t3.a=t2.a) left join t1 as t3 on (t1.a=t3.a); |
43 |
||
44 |
# The next query should give an error in MySQL |
|
1731.3.1
by Lee Bieber
change tests to use enum values instead of error numbers |
45 |
--error ER_BAD_FIELD_ERROR
|
1
by brian
clean slate |
46 |
select t1.*,t2.*,t3.a from t1 left join t2 on (t3.a=t2.a) left join t1 as t3 on (t2.a=t3.a); |
47 |
||
48 |
# Test of inner join |
|
49 |
select t1.*,t2.* from t1 inner join t2 using (a); |
|
50 |
select t1.*,t2.* from t1 inner join t2 on (t1.a=t2.a); |
|
51 |
select t1.*,t2.* from t1 natural join t2; |
|
52 |
||
53 |
drop table t1,t2; |
|
54 |
||
55 |
#
|
|
56 |
# Test of left join bug |
|
57 |
#
|
|
58 |
||
59 |
CREATE TABLE t1 ( |
|
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
60 |
usr_id INT NOT NULL, |
61 |
uniq_id INT NOT NULL AUTO_INCREMENT, |
|
62 |
start_num INT NOT NULL DEFAULT 1, |
|
63 |
increment INT NOT NULL DEFAULT 1, |
|
1
by brian
clean slate |
64 |
PRIMARY KEY (uniq_id), |
65 |
INDEX usr_uniq_idx (usr_id, uniq_id), |
|
66 |
INDEX uniq_usr_idx (uniq_id, usr_id) |
|
67 |
);
|
|
68 |
CREATE TABLE t2 ( |
|
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
69 |
id INT NOT NULL DEFAULT 0, |
70 |
usr2_id INT NOT NULL DEFAULT 0, |
|
71 |
max INT NOT NULL DEFAULT 0, |
|
72 |
c_amount INT NOT NULL DEFAULT 0, |
|
73 |
d_max INT NOT NULL DEFAULT 0, |
|
74 |
d_num INT NOT NULL DEFAULT 0, |
|
75 |
orig_time INT NOT NULL DEFAULT 0, |
|
76 |
c_time INT NOT NULL DEFAULT 0, |
|
1
by brian
clean slate |
77 |
active ENUM ("no","yes") NOT NULL, |
78 |
PRIMARY KEY (id,usr2_id), |
|
79 |
INDEX id_idx (id), |
|
80 |
INDEX usr2_idx (usr2_id) |
|
81 |
);
|
|
82 |
INSERT INTO t1 VALUES (3,NULL,0,50),(3,NULL,0,200),(3,NULL,0,25),(3,NULL,0,84676),(3,NULL,0,235),(3,NULL,0,10),(3,NULL,0,3098),(3,NULL,0,2947),(3,NULL,0,8987),(3,NULL,0,8347654),(3,NULL,0,20398),(3,NULL,0,8976),(3,NULL,0,500),(3,NULL,0,198); |
|
83 |
||
84 |
#1st select shows that one record is returned with null entries for the right |
|
85 |
#table, when selecting on an id that does not exist in the right table t2 |
|
86 |
SELECT t1.usr_id,t1.uniq_id,t1.increment, |
|
87 |
t2.usr2_id,t2.c_amount,t2.max |
|
88 |
FROM t1 |
|
89 |
LEFT JOIN t2 ON t2.id = t1.uniq_id |
|
90 |
WHERE t1.uniq_id = 4 |
|
91 |
ORDER BY t2.c_amount; |
|
92 |
||
93 |
# The same with RIGHT JOIN |
|
94 |
SELECT t1.usr_id,t1.uniq_id,t1.increment, |
|
95 |
t2.usr2_id,t2.c_amount,t2.max |
|
96 |
FROM t2 |
|
97 |
RIGHT JOIN t1 ON t2.id = t1.uniq_id |
|
98 |
WHERE t1.uniq_id = 4 |
|
99 |
ORDER BY t2.c_amount; |
|
100 |
||
101 |
INSERT INTO t2 VALUES (2,3,3000,6000,0,0,746584,837484,'yes'); |
|
102 |
--error ER_DUP_ENTRY
|
|
103 |
INSERT INTO t2 VALUES (2,3,3000,6000,0,0,746584,837484,'yes'); |
|
104 |
INSERT INTO t2 VALUES (7,3,1000,2000,0,0,746294,937484,'yes'); |
|
105 |
||
106 |
#3rd select should show that one record is returned with null entries for the |
|
107 |
# right table, when selecting on an id that does not exist in the right table |
|
108 |
# t2 but this select returns an empty set!!!! |
|
109 |
SELECT t1.usr_id,t1.uniq_id,t1.increment,t2.usr2_id,t2.c_amount,t2.max FROM t1 LEFT JOIN t2 ON t2.id = t1.uniq_id WHERE t1.uniq_id = 4 ORDER BY t2.c_amount; |
|
110 |
SELECT t1.usr_id,t1.uniq_id,t1.increment,t2.usr2_id,t2.c_amount,t2.max FROM t1 LEFT JOIN t2 ON t2.id = t1.uniq_id WHERE t1.uniq_id = 4 GROUP BY t2.c_amount; |
|
111 |
# Removing the ORDER BY works: |
|
112 |
SELECT t1.usr_id,t1.uniq_id,t1.increment,t2.usr2_id,t2.c_amount,t2.max FROM t1 LEFT JOIN t2 ON t2.id = t1.uniq_id WHERE t1.uniq_id = 4; |
|
113 |
||
114 |
drop table t1,t2; |
|
115 |
||
116 |
#
|
|
117 |
# Test of LEFT JOIN with const tables (failed for frankie@etsetb.upc.es) |
|
118 |
#
|
|
119 |
||
120 |
CREATE TABLE t1 ( |
|
223
by Brian Aker
Cleanup int() work. |
121 |
cod_asig int DEFAULT '0' NOT NULL, |
1
by brian
clean slate |
122 |
desc_larga_cat varchar(80) DEFAULT '' NOT NULL, |
123 |
desc_larga_cas varchar(80) DEFAULT '' NOT NULL, |
|
124 |
desc_corta_cat varchar(40) DEFAULT '' NOT NULL, |
|
125 |
desc_corta_cas varchar(40) DEFAULT '' NOT NULL, |
|
126 |
cred_total double(3,1) DEFAULT '0.0' NOT NULL, |
|
223
by Brian Aker
Cleanup int() work. |
127 |
pre_requisit int, |
128 |
co_requisit int, |
|
129 |
preco_requisit int, |
|
1
by brian
clean slate |
130 |
PRIMARY KEY (cod_asig) |
131 |
);
|
|
132 |
||
133 |
INSERT INTO t1 VALUES (10360,'asdfggfg','Introduccion a los Ordenadores I','asdfggfg','Introduccio Ordinadors I',6.0,NULL,NULL,NULL); |
|
134 |
INSERT INTO t1 VALUES (10361,'Components i Circuits Electronics I','Componentes y Circuitos Electronicos I','Components i Circuits Electronics I','Comp. i Circ. Electr. I',6.0,NULL,NULL,NULL); |
|
135 |
INSERT INTO t1 VALUES (10362,'Laboratori d`Ordinadors','Laboratorio de Ordenadores','Laboratori d`Ordinadors','Laboratori Ordinadors',4.5,NULL,NULL,NULL); |
|
136 |
INSERT INTO t1 VALUES (10363,'Tecniques de Comunicacio Oral i Escrita','Tecnicas de Comunicacion Oral y Escrita','Tecniques de Comunicacio Oral i Escrita','Tec. Com. Oral i Escrita',4.5,NULL,NULL,NULL); |
|
137 |
INSERT INTO t1 VALUES (11403,'Projecte Fi de Carrera','Proyecto Fin de Carrera','Projecte Fi de Carrera','PFC',9.0,NULL,NULL,NULL); |
|
138 |
INSERT INTO t1 VALUES (11404,'+lgebra lineal','Algebra lineal','+lgebra lineal','+lgebra lineal',15.0,NULL,NULL,NULL); |
|
139 |
INSERT INTO t1 VALUES (11405,'+lgebra lineal','Algebra lineal','+lgebra lineal','+lgebra lineal',18.0,NULL,NULL,NULL); |
|
140 |
INSERT INTO t1 VALUES (11406,'Calcul Infinitesimal','Cßlculo Infinitesimal','Calcul Infinitesimal','Calcul Infinitesimal',15.0,NULL,NULL,NULL); |
|
141 |
||
142 |
CREATE TABLE t2 ( |
|
223
by Brian Aker
Cleanup int() work. |
143 |
idAssignatura int DEFAULT '0' NOT NULL, |
144 |
Grup int DEFAULT '0' NOT NULL, |
|
396
by Brian Aker
Cleanup tiny and small int. |
145 |
Places int DEFAULT '0' NOT NULL, |
223
by Brian Aker
Cleanup int() work. |
146 |
PlacesOcupades int DEFAULT '0', |
1
by brian
clean slate |
147 |
PRIMARY KEY (idAssignatura,Grup) |
148 |
);
|
|
149 |
||
150 |
||
151 |
INSERT INTO t2 VALUES (10360,12,333,0); |
|
152 |
INSERT INTO t2 VALUES (10361,30,2,0); |
|
153 |
INSERT INTO t2 VALUES (10361,40,3,0); |
|
154 |
INSERT INTO t2 VALUES (10360,45,10,0); |
|
155 |
INSERT INTO t2 VALUES (10362,10,12,0); |
|
156 |
INSERT INTO t2 VALUES (10360,55,2,0); |
|
157 |
INSERT INTO t2 VALUES (10360,70,0,0); |
|
158 |
INSERT INTO t2 VALUES (10360,565656,0,0); |
|
159 |
INSERT INTO t2 VALUES (10360,32767,7,0); |
|
160 |
INSERT INTO t2 VALUES (10360,33,8,0); |
|
161 |
INSERT INTO t2 VALUES (10360,7887,85,0); |
|
162 |
INSERT INTO t2 VALUES (11405,88,8,0); |
|
163 |
INSERT INTO t2 VALUES (10360,0,55,0); |
|
164 |
INSERT INTO t2 VALUES (10360,99,0,0); |
|
165 |
INSERT INTO t2 VALUES (11411,30,10,0); |
|
166 |
INSERT INTO t2 VALUES (11404,0,0,0); |
|
167 |
INSERT INTO t2 VALUES (10362,11,111,0); |
|
168 |
INSERT INTO t2 VALUES (10363,33,333,0); |
|
169 |
INSERT INTO t2 VALUES (11412,55,0,0); |
|
170 |
INSERT INTO t2 VALUES (50003,66,6,0); |
|
171 |
INSERT INTO t2 VALUES (11403,5,0,0); |
|
172 |
INSERT INTO t2 VALUES (11406,11,11,0); |
|
173 |
INSERT INTO t2 VALUES (11410,11410,131,0); |
|
174 |
INSERT INTO t2 VALUES (11416,11416,32767,0); |
|
175 |
INSERT INTO t2 VALUES (11409,0,0,0); |
|
176 |
||
177 |
CREATE TABLE t3 ( |
|
223
by Brian Aker
Cleanup int() work. |
178 |
id int NOT NULL auto_increment, |
1
by brian
clean slate |
179 |
dni_pasaporte char(16) DEFAULT '' NOT NULL, |
223
by Brian Aker
Cleanup int() work. |
180 |
idPla int DEFAULT '0' NOT NULL, |
181 |
cod_asig int DEFAULT '0' NOT NULL, |
|
396
by Brian Aker
Cleanup tiny and small int. |
182 |
any int DEFAULT '0' NOT NULL, |
183 |
quatrimestre int DEFAULT '0' NOT NULL, |
|
1
by brian
clean slate |
184 |
estat char(1) DEFAULT 'M' NOT NULL, |
185 |
PRIMARY KEY (id), |
|
186 |
UNIQUE dni_pasaporte (dni_pasaporte,idPla), |
|
187 |
UNIQUE dni_pasaporte_2 (dni_pasaporte,idPla,cod_asig,any,quatrimestre) |
|
188 |
);
|
|
189 |
||
190 |
INSERT INTO t3 VALUES (1,'11111111',1,10362,98,1,'M'); |
|
191 |
||
192 |
CREATE TABLE t4 ( |
|
223
by Brian Aker
Cleanup int() work. |
193 |
id int NOT NULL auto_increment, |
194 |
papa int DEFAULT '0' NOT NULL, |
|
195 |
fill int DEFAULT '0' NOT NULL, |
|
196 |
idPla int DEFAULT '0' NOT NULL, |
|
1
by brian
clean slate |
197 |
PRIMARY KEY (id), |
198 |
KEY papa (idPla,papa), |
|
199 |
UNIQUE papa_2 (idPla,papa,fill) |
|
200 |
);
|
|
201 |
||
202 |
INSERT INTO t4 VALUES (1,-1,10360,1); |
|
203 |
INSERT INTO t4 VALUES (2,-1,10361,1); |
|
204 |
INSERT INTO t4 VALUES (3,-1,10362,1); |
|
205 |
||
206 |
SELECT DISTINCT fill,desc_larga_cat,cred_total,Grup,Places,PlacesOcupades FROM t4 LEFT JOIN t3 ON t3.cod_asig=fill AND estat='S' AND dni_pasaporte='11111111' AND t3.idPla=1 , t2,t1 WHERE fill=t1.cod_asig AND Places>PlacesOcupades AND fill=idAssignatura AND t4.idPla=1 AND papa=-1; |
|
207 |
||
208 |
SELECT DISTINCT fill,t3.idPla FROM t4 LEFT JOIN t3 ON t3.cod_asig=t4.fill AND t3.estat='S' AND t3.dni_pasaporte='1234' AND t3.idPla=1 ; |
|
209 |
||
210 |
INSERT INTO t3 VALUES (3,'1234',1,10360,98,1,'S'); |
|
211 |
SELECT DISTINCT fill,t3.idPla FROM t4 LEFT JOIN t3 ON t3.cod_asig=t4.fill AND t3.estat='S' AND t3.dni_pasaporte='1234' AND t3.idPla=1 ; |
|
212 |
||
213 |
drop table t1,t2,t3,test.t4; |
|
214 |
||
215 |
#
|
|
216 |
# Test of IS NULL on AUTO_INCREMENT with LEFT JOIN |
|
217 |
#
|
|
218 |
||
219 |
CREATE TABLE t1 ( |
|
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
220 |
id int NOT NULL auto_increment, |
1
by brian
clean slate |
221 |
name char(60) DEFAULT '' NOT NULL, |
222 |
PRIMARY KEY (id) |
|
223 |
);
|
|
224 |
INSERT INTO t1 VALUES (1,'Antonio Paz'); |
|
225 |
INSERT INTO t1 VALUES (2,'Lilliana Angelovska'); |
|
226 |
INSERT INTO t1 VALUES (3,'Thimble Smith'); |
|
227 |
||
228 |
CREATE TABLE t2 ( |
|
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
229 |
id int NOT NULL auto_increment, |
230 |
owner int DEFAULT '0' NOT NULL, |
|
1
by brian
clean slate |
231 |
name char(60), |
232 |
PRIMARY KEY (id) |
|
233 |
);
|
|
234 |
INSERT INTO t2 VALUES (1,1,'El Gato'); |
|
235 |
INSERT INTO t2 VALUES (2,1,'Perrito'); |
|
236 |
INSERT INTO t2 VALUES (3,3,'Happy'); |
|
237 |
||
238 |
select t1.name, t2.name, t2.id from t1 left join t2 on (t1.id = t2.owner); |
|
239 |
select t1.name, t2.name, t2.id from t1 left join t2 on (t1.id = t2.owner) where t2.id is null; |
|
240 |
explain select t1.name, t2.name, t2.id from t1 left join t2 on (t1.id = t2.owner) where t2.id is null; |
|
241 |
explain select t1.name, t2.name, t2.id from t1 left join t2 on (t1.id = t2.owner) where t2.name is null; |
|
242 |
select count(*) from t1 left join t2 on (t1.id = t2.owner); |
|
243 |
||
244 |
select t1.name, t2.name, t2.id from t2 right join t1 on (t1.id = t2.owner); |
|
245 |
select t1.name, t2.name, t2.id from t2 right join t1 on (t1.id = t2.owner) where t2.id is null; |
|
246 |
explain select t1.name, t2.name, t2.id from t2 right join t1 on (t1.id = t2.owner) where t2.id is null; |
|
247 |
explain select t1.name, t2.name, t2.id from t2 right join t1 on (t1.id = t2.owner) where t2.name is null; |
|
248 |
select count(*) from t2 right join t1 on (t1.id = t2.owner); |
|
249 |
||
250 |
select t1.name, t2.name, t2.id,t3.id from t2 right join t1 on (t1.id = t2.owner) left join t1 as t3 on t3.id=t2.owner; |
|
251 |
select t1.name, t2.name, t2.id,t3.id from t1 right join t2 on (t1.id = t2.owner) right join t1 as t3 on t3.id=t2.owner; |
|
252 |
select t1.name, t2.name, t2.id, t2.owner, t3.id from t1 left join t2 on (t1.id = t2.owner) right join t1 as t3 on t3.id=t2.owner; |
|
253 |
||
254 |
drop table t1,t2; |
|
255 |
||
256 |
create table t1 (id int not null, str char(10), index(str)); |
|
257 |
insert into t1 values (1, null), (2, null), (3, "foo"), (4, "bar"); |
|
258 |
select * from t1 where str is not null order by id; |
|
259 |
select * from t1 where str is null; |
|
260 |
drop table t1; |
|
261 |
||
262 |
#
|
|
263 |
# Test wrong LEFT JOIN query |
|
264 |
#
|
|
265 |
||
266 |
CREATE TABLE t1 ( |
|
223
by Brian Aker
Cleanup int() work. |
267 |
t1_id bigint NOT NULL auto_increment, |
1
by brian
clean slate |
268 |
PRIMARY KEY (t1_id) |
269 |
);
|
|
270 |
CREATE TABLE t2 ( |
|
223
by Brian Aker
Cleanup int() work. |
271 |
t2_id bigint NOT NULL auto_increment, |
1
by brian
clean slate |
272 |
PRIMARY KEY (t2_id) |
273 |
);
|
|
274 |
CREATE TABLE t3 ( |
|
223
by Brian Aker
Cleanup int() work. |
275 |
t3_id bigint NOT NULL auto_increment, |
1
by brian
clean slate |
276 |
PRIMARY KEY (t3_id) |
277 |
);
|
|
278 |
CREATE TABLE t4 ( |
|
223
by Brian Aker
Cleanup int() work. |
279 |
seq_0_id bigint DEFAULT '0' NOT NULL, |
280 |
seq_1_id bigint DEFAULT '0' NOT NULL, |
|
1
by brian
clean slate |
281 |
KEY seq_0_id (seq_0_id), |
282 |
KEY seq_1_id (seq_1_id) |
|
283 |
);
|
|
284 |
CREATE TABLE t5 ( |
|
223
by Brian Aker
Cleanup int() work. |
285 |
seq_0_id bigint DEFAULT '0' NOT NULL, |
286 |
seq_1_id bigint DEFAULT '0' NOT NULL, |
|
1
by brian
clean slate |
287 |
KEY seq_1_id (seq_1_id), |
288 |
KEY seq_0_id (seq_0_id) |
|
289 |
);
|
|
290 |
||
291 |
insert into t1 values (1); |
|
292 |
insert into t2 values (1); |
|
293 |
insert into t3 values (1); |
|
294 |
insert into t4 values (1,1); |
|
295 |
insert into t5 values (1,1); |
|
296 |
||
1731.3.1
by Lee Bieber
change tests to use enum values instead of error numbers |
297 |
--error ER_BAD_FIELD_ERROR
|
1
by brian
clean slate |
298 |
explain select * from t3 left join t4 on t4.seq_1_id = t2.t2_id left join t1 on t1.t1_id = t4.seq_0_id left join t5 on t5.seq_0_id = t1.t1_id left join t2 on t2.t2_id = t5.seq_1_id where t3.t3_id = 23; |
299 |
||
300 |
drop table t1,t2,t3,t4,t5; |
|
301 |
||
302 |
#
|
|
303 |
# Another LEFT JOIN problem |
|
304 |
# (The problem was that the result changed when we added ORDER BY) |
|
305 |
#
|
|
306 |
||
307 |
create table t1 (n int, m int, o int, key(n)); |
|
308 |
create table t2 (n int not null, m int, o int, primary key(n)); |
|
309 |
insert into t1 values (1, 2, 11), (1, 2, 7), (2, 2, 8), (1,2,9),(1,3,9); |
|
310 |
insert into t2 values (1, 2, 3),(2, 2, 8), (4,3,9),(3,2,10); |
|
311 |
select t1.*, t2.* from t1 left join t2 on t1.n = t2.n and |
|
312 |
t1.m = t2.m where t1.n = 1; |
|
313 |
select t1.*, t2.* from t1 left join t2 on t1.n = t2.n and |
|
314 |
t1.m = t2.m where t1.n = 1 order by t1.o; |
|
315 |
drop table t1,t2; |
|
316 |
||
317 |
# Test bug with NATURAL join: |
|
318 |
||
319 |
CREATE TABLE t1 (id1 INT NOT NULL PRIMARY KEY, dat1 CHAR(1), id2 INT); |
|
320 |
INSERT INTO t1 VALUES (1,'a',1); |
|
321 |
INSERT INTO t1 VALUES (2,'b',1); |
|
322 |
INSERT INTO t1 VALUES (3,'c',2); |
|
323 |
||
324 |
CREATE TABLE t2 (id2 INT NOT NULL PRIMARY KEY, dat2 CHAR(1)); |
|
325 |
INSERT INTO t2 VALUES (1,'x'); |
|
326 |
INSERT INTO t2 VALUES (2,'y'); |
|
327 |
INSERT INTO t2 VALUES (3,'z'); |
|
328 |
||
329 |
SELECT t2.id2 FROM t2 LEFT OUTER JOIN t1 ON t1.id2 = t2.id2 WHERE id1 IS NULL; |
|
330 |
SELECT t2.id2 FROM t2 NATURAL LEFT OUTER JOIN t1 WHERE id1 IS NULL; |
|
331 |
||
332 |
drop table t1,t2; |
|
333 |
||
334 |
create table t1 ( color varchar(20), name varchar(20) ); |
|
335 |
insert into t1 values ( 'red', 'apple' ); |
|
336 |
insert into t1 values ( 'yellow', 'banana' ); |
|
337 |
insert into t1 values ( 'green', 'lime' ); |
|
338 |
insert into t1 values ( 'black', 'grape' ); |
|
339 |
insert into t1 values ( 'blue', 'blueberry' ); |
|
340 |
create table t2 ( count int, color varchar(20) ); |
|
341 |
insert into t2 values (10, 'green'); |
|
342 |
insert into t2 values (5, 'black'); |
|
343 |
insert into t2 values (15, 'white'); |
|
344 |
insert into t2 values (7, 'green'); |
|
345 |
select * from t1; |
|
346 |
select * from t2; |
|
1718.2.1
by Lee Bieber
For the feature request (https://blueprints.launchpad.net/drizzle/+spec/limit-maximum-sort-size) |
347 |
--sorted_result
|
1
by brian
clean slate |
348 |
select * from t2 natural join t1; |
1718.2.1
by Lee Bieber
For the feature request (https://blueprints.launchpad.net/drizzle/+spec/limit-maximum-sort-size) |
349 |
--sorted_result
|
1
by brian
clean slate |
350 |
select t2.count, t1.name from t2 natural join t1; |
1718.2.1
by Lee Bieber
For the feature request (https://blueprints.launchpad.net/drizzle/+spec/limit-maximum-sort-size) |
351 |
--sorted_result
|
1
by brian
clean slate |
352 |
select t2.count, t1.name from t2 inner join t1 using (color); |
353 |
drop table t1; |
|
354 |
drop table t2; |
|
355 |
||
356 |
#
|
|
357 |
# Test of LEFT JOIN + GROUP FUNCTIONS within functions: |
|
358 |
#
|
|
359 |
||
360 |
CREATE TABLE t1 ( |
|
361 |
pcode varchar(8) DEFAULT '' NOT NULL |
|
362 |
);
|
|
363 |
INSERT INTO t1 VALUES ('kvw2000'),('kvw2001'),('kvw3000'),('kvw3001'),('kvw3002'),('kvw3500'),('kvw3501'),('kvw3502'),('kvw3800'),('kvw3801'),('kvw3802'),('kvw3900'),('kvw3901'),('kvw3902'),('kvw4000'),('kvw4001'),('kvw4002'),('kvw4200'),('kvw4500'),('kvw5000'),('kvw5001'),('kvw5500'),('kvw5510'),('kvw5600'),('kvw5601'),('kvw6000'),('klw1000'),('klw1020'),('klw1500'),('klw2000'),('klw2001'),('klw2002'),('kld2000'),('klw2500'),('kmw1000'),('kmw1500'),('kmw2000'),('kmw2001'),('kmw2100'),('kmw3000'),('kmw3200'); |
|
364 |
CREATE TABLE t2 ( |
|
365 |
pcode varchar(8) DEFAULT '' NOT NULL, |
|
366 |
KEY pcode (pcode) |
|
367 |
);
|
|
368 |
INSERT INTO t2 VALUES ('kvw2000'),('kvw2000'),('kvw2000'),('kvw2000'),('kvw2000'),('kvw2000'),('kvw2000'),('kvw2000'),('kvw2000'),('kvw2000'),('kvw2000'),('kvw2000'),('kvw2000'),('kvw2000'),('kvw2000'),('kvw2000'),('kvw2000'),('kvw2000'),('kvw2000'),('kvw2000'),('kvw2000'),('kvw2000'),('kvw2000'),('kvw2000'),('kvw2000'),('kvw2000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3000'),('kvw3500'),('kvw3500'),('kvw3500'),('kvw3500'),('kvw3500'),('kvw3500'),('kvw3500'),('kvw3500'),('kvw3500'),('kvw3500'),('kvw3500'),('kvw3500'),('kvw3500'),('kvw3500'),('kvw3500'),('kvw3500'),('kvw3500'),('kvw3500'),('kvw3500'),('kvw3500'),('kvw3500'),('kvw3500'),('kvw3500'),('kvw3500'),('kvw3500'),('kvw3500'),('kvw6000'),('kvw6000'),('kld2000'); |
|
369 |
||
370 |
SELECT t1.pcode, IF(ISNULL(t2.pcode), 0, COUNT(*)) AS count FROM t1 |
|
371 |
LEFT JOIN t2 ON t1.pcode = t2.pcode GROUP BY t1.pcode; |
|
372 |
SELECT SQL_BIG_RESULT t1.pcode, IF(ISNULL(t2.pcode), 0, COUNT(*)) AS count FROM t1 LEFT JOIN t2 ON t1.pcode = t2.pcode GROUP BY t1.pcode; |
|
373 |
drop table t1,t2; |
|
374 |
||
375 |
#
|
|
376 |
# Another left join problem |
|
377 |
#
|
|
378 |
||
379 |
CREATE TABLE t1 ( |
|
223
by Brian Aker
Cleanup int() work. |
380 |
id int, |
381 |
pid int, |
|
396
by Brian Aker
Cleanup tiny and small int. |
382 |
rep_del int, |
1
by brian
clean slate |
383 |
KEY id (id), |
384 |
KEY pid (pid) |
|
385 |
);
|
|
386 |
INSERT INTO t1 VALUES (1,NULL,NULL); |
|
387 |
INSERT INTO t1 VALUES (2,1,NULL); |
|
388 |
select * from t1 LEFT JOIN t1 t2 ON (t1.id=t2.pid) AND t2.rep_del IS NULL; |
|
389 |
create index rep_del ON t1(rep_del); |
|
390 |
select * from t1 LEFT JOIN t1 t2 ON (t1.id=t2.pid) AND t2.rep_del IS NULL; |
|
391 |
drop table t1; |
|
392 |
||
393 |
CREATE TABLE t1 ( |
|
223
by Brian Aker
Cleanup int() work. |
394 |
id int DEFAULT '0' NOT NULL, |
1
by brian
clean slate |
395 |
name tinytext DEFAULT '' NOT NULL, |
396 |
UNIQUE id (id) |
|
397 |
);
|
|
398 |
INSERT INTO t1 VALUES (1,'yes'),(2,'no'); |
|
399 |
CREATE TABLE t2 ( |
|
223
by Brian Aker
Cleanup int() work. |
400 |
id int DEFAULT '0' NOT NULL, |
401 |
idx int DEFAULT '0' NOT NULL, |
|
1
by brian
clean slate |
402 |
UNIQUE id (id,idx) |
403 |
);
|
|
404 |
INSERT INTO t2 VALUES (1,1); |
|
405 |
explain SELECT * from t1 left join t2 on t1.id=t2.id where t2.id IS NULL; |
|
406 |
SELECT * from t1 left join t2 on t1.id=t2.id where t2.id IS NULL; |
|
407 |
drop table t1,t2; |
|
408 |
||
409 |
#
|
|
410 |
# Test problem with using key_column= constant in ON and WHERE |
|
411 |
#
|
|
67
by Brian Aker
First pass for removing mediumint (3 byte INT type). |
412 |
create table t1 (bug_id bigint, reporter bigint); |
413 |
create table t2 (bug_id bigint, who bigint, index(who)); |
|
1
by brian
clean slate |
414 |
insert into t2 values (1,1),(1,2); |
415 |
insert into t1 values (1,1),(2,1); |
|
416 |
SELECT * FROM t1 LEFT JOIN t2 ON (t1.bug_id = t2.bug_id AND t2.who = 2) WHERE (t1.reporter = 2 OR t2.who = 2); |
|
417 |
drop table t1,t2; |
|
418 |
||
419 |
#
|
|
420 |
# Test problem with LEFT JOIN |
|
421 |
||
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
422 |
create table t1 (fooID int auto_increment, primary key (fooID)); |
423 |
create table t2 (fooID int not null, barID int not null, primary key (fooID,barID)); |
|
1
by brian
clean slate |
424 |
insert into t1 (fooID) values (10),(20),(30); |
425 |
insert into t2 values (10,1),(20,2),(30,3); |
|
426 |
explain select * from t2 left join t1 on t1.fooID = t2.fooID and t1.fooID = 30; |
|
427 |
select * from t2 left join t1 on t1.fooID = t2.fooID and t1.fooID = 30; |
|
428 |
select * from t2 left join t1 ignore index(primary) on t1.fooID = t2.fooID and t1.fooID = 30; |
|
429 |
drop table t1,t2; |
|
430 |
||
431 |
create table t1 (i int); |
|
432 |
create table t2 (i int); |
|
433 |
create table t3 (i int); |
|
434 |
insert into t1 values(1),(2); |
|
435 |
insert into t2 values(2),(3); |
|
436 |
insert into t3 values(2),(4); |
|
437 |
select * from t1 natural left join t2 natural left join t3; |
|
438 |
select * from t1 natural left join t2 where (t2.i is not null)=0; |
|
439 |
select * from t1 natural left join t2 where (t2.i is not null) is not null; |
|
440 |
select * from t1 natural left join t2 where (i is not null)=0; |
|
441 |
select * from t1 natural left join t2 where (i is not null) is not null; |
|
442 |
drop table t1,t2,t3; |
|
443 |
||
444 |
#
|
|
445 |
# Test of USING |
|
446 |
#
|
|
447 |
create table t1 (f1 integer,f2 integer,f3 integer); |
|
448 |
create table t2 (f2 integer,f4 integer); |
|
449 |
create table t3 (f3 integer,f5 integer); |
|
450 |
select * from t1 |
|
451 |
left outer join t2 using (f2) |
|
452 |
left outer join t3 using (f3); |
|
453 |
drop table t1,t2,t3; |
|
454 |
||
455 |
create table t1 (a1 int, a2 int); |
|
456 |
create table t2 (b1 int not null, b2 int); |
|
457 |
create table t3 (c1 int, c2 int); |
|
458 |
||
459 |
insert into t1 values (1,2), (2,2), (3,2); |
|
460 |
insert into t2 values (1,3), (2,3); |
|
461 |
insert into t3 values (2,4), (3,4); |
|
462 |
||
463 |
select * from t1 left join t2 on b1 = a1 left join t3 on c1 = a1 and b1 is null; |
|
464 |
explain select * from t1 left join t2 on b1 = a1 left join t3 on c1 = a1 and b1 is null; |
|
465 |
||
466 |
drop table t1, t2, t3; |
|
467 |
||
468 |
# Test for BUG#8711 '<=>' was considered to be a NULL-rejecting predicate. |
|
469 |
create table t1 ( |
|
223
by Brian Aker
Cleanup int() work. |
470 |
a int, |
1
by brian
clean slate |
471 |
b char(10), |
472 |
key (a) |
|
473 |
);
|
|
474 |
insert into t1 (a) values (1),(2),(3),(4); |
|
475 |
create table t2 (a int); |
|
476 |
||
477 |
select * from t1 left join t2 on t1.a=t2.a where not (t2.a <=> t1.a); |
|
478 |
select * from t1 left join t2 on t1.a=t2.a having not (t2.a <=> t1.a); |
|
479 |
drop table t1,t2; |
|
480 |
||
481 |
# Test for BUG#5088 |
|
482 |
||
483 |
create table t1 ( |
|
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
484 |
match_id int not null auto_increment, |
485 |
home int default '0', |
|
1
by brian
clean slate |
486 |
unique key match_id (match_id), |
487 |
key match_id_2 (match_id) |
|
488 |
);
|
|
489 |
||
490 |
insert into t1 values("1", "2"); |
|
491 |
||
492 |
create table t2 ( |
|
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
493 |
player_id int default '0', |
494 |
match_1_h int default '0', |
|
1
by brian
clean slate |
495 |
key player_id (player_id) |
496 |
);
|
|
497 |
||
498 |
insert into t2 values("1", "5"); |
|
499 |
insert into t2 values("2", "9"); |
|
500 |
insert into t2 values("3", "3"); |
|
501 |
insert into t2 values("4", "7"); |
|
502 |
insert into t2 values("5", "6"); |
|
503 |
insert into t2 values("6", "8"); |
|
504 |
insert into t2 values("7", "4"); |
|
505 |
insert into t2 values("8", "12"); |
|
506 |
insert into t2 values("9", "11"); |
|
507 |
insert into t2 values("10", "10"); |
|
508 |
||
509 |
explain select s.*, '*', m.*, (s.match_1_h - m.home) UUX from |
|
510 |
(t2 s left join t1 m on m.match_id = 1) |
|
511 |
order by m.match_id desc; |
|
512 |
||
513 |
explain select s.*, '*', m.*, (s.match_1_h - m.home) UUX from |
|
514 |
(t2 s left join t1 m on m.match_id = 1) |
|
515 |
order by UUX desc; |
|
516 |
||
517 |
select s.*, '*', m.*, (s.match_1_h - m.home) UUX from |
|
518 |
(t2 s left join t1 m on m.match_id = 1) |
|
519 |
order by UUX desc; |
|
520 |
||
521 |
explain select s.*, '*', m.*, (s.match_1_h - m.home) UUX from |
|
522 |
t2 s straight_join t1 m where m.match_id = 1 |
|
523 |
order by UUX desc; |
|
524 |
||
525 |
select s.*, '*', m.*, (s.match_1_h - m.home) UUX from |
|
526 |
t2 s straight_join t1 m where m.match_id = 1 |
|
527 |
order by UUX desc; |
|
528 |
||
529 |
drop table t1, t2; |
|
530 |
||
531 |
# Tests for bugs #6307 and 6460 |
|
532 |
||
533 |
create table t1 (a int, b int, unique index idx (a, b)); |
|
534 |
create table t2 (a int, b int, c int, unique index idx (a, b)); |
|
535 |
||
536 |
insert into t1 values (1, 10), (1,11), (2,10), (2,11); |
|
537 |
insert into t2 values (1,10,3); |
|
538 |
||
539 |
select t1.a, t1.b, t2.c from t1 left join t2 |
|
540 |
on t1.a=t2.a and t1.b=t2.b and t2.c=3 |
|
541 |
where t1.a=1 and t2.c is null; |
|
542 |
||
543 |
drop table t1, t2; |
|
544 |
||
1063.9.10
by Stewart Smith
fix join_outer for MyISAM as temp only: 1x open table twice, 1x CREATE TEMP |
545 |
CREATE TEMPORARY TABLE t1 ( |
223
by Brian Aker
Cleanup int() work. |
546 |
ts_id bigint default NULL, |
396
by Brian Aker
Cleanup tiny and small int. |
547 |
inst_id int default NULL, |
1
by brian
clean slate |
548 |
flag_name varchar(64) default NULL, |
549 |
flag_value text, |
|
550 |
UNIQUE KEY ts_id (ts_id,inst_id,flag_name) |
|
377.1.4
by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one |
551 |
) ENGINE=MyISAM; |
1
by brian
clean slate |
552 |
|
1063.9.10
by Stewart Smith
fix join_outer for MyISAM as temp only: 1x open table twice, 1x CREATE TEMP |
553 |
CREATE TEMPORARY TABLE t2 ( |
223
by Brian Aker
Cleanup int() work. |
554 |
ts_id bigint default NULL, |
396
by Brian Aker
Cleanup tiny and small int. |
555 |
inst_id int default NULL, |
1
by brian
clean slate |
556 |
flag_name varchar(64) default NULL, |
557 |
flag_value text, |
|
558 |
UNIQUE KEY ts_id (ts_id,inst_id,flag_name) |
|
377.1.4
by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one |
559 |
) ENGINE=MyISAM; |
1
by brian
clean slate |
560 |
|
561 |
INSERT INTO t1 VALUES |
|
562 |
(111056548820001, 0, 'flag1', NULL), |
|
563 |
(111056548820001, 0, 'flag2', NULL), |
|
564 |
(2, 0, 'other_flag', NULL); |
|
565 |
||
566 |
INSERT INTO t2 VALUES |
|
567 |
(111056548820001, 3, 'flag1', 'sss'); |
|
568 |
||
569 |
SELECT t1.flag_name,t2.flag_value |
|
570 |
FROM t1 LEFT JOIN t2 |
|
571 |
ON (t1.ts_id = t2.ts_id AND t1.flag_name = t2.flag_name AND |
|
572 |
t2.inst_id = 3) |
|
573 |
WHERE t1.inst_id = 0 AND t1.ts_id=111056548820001 AND |
|
574 |
t2.flag_value IS NULL; |
|
575 |
||
576 |
DROP TABLE t1,t2; |
|
577 |
||
578 |
CREATE TABLE t1 ( |
|
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
579 |
id int NOT NULL auto_increment, |
580 |
text_id int default NULL, |
|
1
by brian
clean slate |
581 |
PRIMARY KEY (id) |
582 |
);
|
|
583 |
||
584 |
INSERT INTO t1 VALUES("1", "0"); |
|
585 |
INSERT INTO t1 VALUES("2", "10"); |
|
586 |
||
587 |
CREATE TABLE t2 ( |
|
588 |
text_id char(3) NOT NULL default '', |
|
589 |
language_id char(3) NOT NULL default '', |
|
590 |
text_data text, |
|
591 |
PRIMARY KEY (text_id,language_id) |
|
592 |
);
|
|
593 |
||
594 |
INSERT INTO t2 VALUES("0", "EN", "0-EN"); |
|
595 |
INSERT INTO t2 VALUES("0", "SV", "0-SV"); |
|
596 |
INSERT INTO t2 VALUES("10", "EN", "10-EN"); |
|
597 |
INSERT INTO t2 VALUES("10", "SV", "10-SV"); |
|
598 |
SELECT t1.id, t1.text_id, t2.text_data |
|
599 |
FROM t1 LEFT JOIN t2 |
|
600 |
ON t1.text_id = t2.text_id |
|
601 |
AND t2.language_id = 'SV' |
|
602 |
WHERE (t1.id LIKE '%' OR t2.text_data LIKE '%'); |
|
603 |
||
604 |
DROP TABLE t1, t2; |
|
605 |
||
606 |
# Test for bug #5896 |
|
607 |
||
608 |
CREATE TABLE t0 (a0 int PRIMARY KEY); |
|
609 |
CREATE TABLE t1 (a1 int PRIMARY KEY); |
|
610 |
CREATE TABLE t2 (a2 int); |
|
611 |
CREATE TABLE t3 (a3 int); |
|
612 |
INSERT INTO t0 VALUES (1); |
|
613 |
INSERT INTO t1 VALUES (1); |
|
614 |
INSERT INTO t2 VALUES (1), (2); |
|
615 |
INSERT INTO t3 VALUES (1), (2); |
|
616 |
||
617 |
SELECT * FROM t1 LEFT JOIN t2 ON a1=0; |
|
618 |
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 ON a1=0; |
|
619 |
SELECT * FROM t1 LEFT JOIN (t2,t3) ON a1=0; |
|
620 |
EXPLAIN SELECT * FROM t1 LEFT JOIN (t2,t3) ON a1=0; |
|
621 |
SELECT * FROM t0, t1 LEFT JOIN (t2,t3) ON a1=0 WHERE a0=a1; |
|
622 |
EXPLAIN SELECT * FROM t0, t1 LEFT JOIN (t2,t3) ON a1=0 WHERE a0=a1; |
|
623 |
||
624 |
INSERT INTO t0 VALUES (0); |
|
625 |
INSERT INTO t1 VALUES (0); |
|
626 |
SELECT * FROM t0, t1 LEFT JOIN (t2,t3) ON a1=5 WHERE a0=a1 AND a0=1; |
|
627 |
EXPLAIN SELECT * FROM t0, t1 LEFT JOIN (t2,t3) ON a1=5 WHERE a0=a1 AND a0=1; |
|
628 |
||
629 |
# Test for BUG#4480 |
|
630 |
drop table t1,t2; |
|
631 |
create table t1 (a int, b int); |
|
632 |
insert into t1 values (1,1),(2,2),(3,3); |
|
633 |
create table t2 (a int, b int); |
|
634 |
insert into t2 values (1,1), (2,2); |
|
635 |
||
636 |
select * from t2 right join t1 on t2.a=t1.a; |
|
637 |
select straight_join * from t2 right join t1 on t2.a=t1.a; |
|
638 |
||
639 |
DROP TABLE t0,t1,t2,t3; |
|
640 |
||
641 |
#
|
|
642 |
# Test for bug #9017: left join mistakingly converted to inner join |
|
643 |
#
|
|
644 |
||
645 |
CREATE TABLE t1 (a int PRIMARY KEY, b int); |
|
646 |
CREATE TABLE t2 (a int PRIMARY KEY, b int); |
|
647 |
||
648 |
INSERT INTO t1 VALUES (1,1), (2,1), (3,1), (4,2); |
|
649 |
INSERT INTO t2 VALUES (1,2), (2,2); |
|
650 |
||
651 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.a; |
|
652 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.a WHERE t1.b=1; |
|
653 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.a |
|
654 |
WHERE t1.b=1 XOR (NOT ISNULL(t2.a) AND t2.b=1); |
|
655 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.a WHERE not(0+(t1.a=30 and t2.b=1)); |
|
656 |
||
657 |
DROP TABLE t1,t2; |
|
658 |
||
659 |
# Bug #8681: Bad warning message when group_concat() exceeds max length |
|
660 |
set group_concat_max_len=5; |
|
661 |
create table t1 (a int, b varchar(20)); |
|
662 |
create table t2 (a int, c varchar(20)); |
|
663 |
insert into t1 values (1,"aaaaaaaaaa"),(2,"bbbbbbbbbb"); |
|
664 |
insert into t2 values (1,"cccccccccc"),(2,"dddddddddd"); |
|
665 |
select group_concat(t1.b,t2.c) from t1 left join t2 using(a) group by t1.a; |
|
666 |
select group_concat(t1.b,t2.c) from t1 inner join t2 using(a) group by t1.a; |
|
667 |
select group_concat(t1.b,t2.c) from t1 left join t2 using(a) group by a; |
|
668 |
select group_concat(t1.b,t2.c) from t1 inner join t2 using(a) group by a; |
|
669 |
drop table t1, t2; |
|
670 |
set group_concat_max_len=default; |
|
671 |
||
672 |
# End of 4.1 tests |
|
673 |
||
674 |
#
|
|
675 |
# BUG#10162 - ON is merged with WHERE, left join is convered to a regular join |
|
676 |
#
|
|
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
677 |
create table t1 (gid int not null, x int not null, y int not null, art int not null, primary key (gid,x,y)); |
1
by brian
clean slate |
678 |
insert t1 values (1, -5, -8, 2), (1, 2, 2, 1), (1, 1, 1, 1); |
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
679 |
create table t2 (gid int not null, x int not null, y int not null, id int not null, primary key (gid,id,x,y), key id (id)); |
1
by brian
clean slate |
680 |
insert t2 values (1, -5, -8, 1), (1, 1, 1, 1), (1, 2, 2, 1); |
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
681 |
create table t3 ( set_id int not null, id int not null, name char(12) not null, primary key (id,set_id)); |
1
by brian
clean slate |
682 |
insert t3 values (0, 1, 'a'), (1, 1, 'b'), (0, 2, 'c'), (1, 2, 'd'), (1, 3, 'e'), (1, 4, 'f'), (1, 5, 'g'), (1, 6, 'h'); |
683 |
explain select name from t1 left join t2 on t1.x = t2.x and t1.y = t2.y |
|
684 |
left join t3 on t1.art = t3.id where t2.id =1 and t2.x = -5 and t2.y =-8 |
|
685 |
and t1.gid =1 and t2.gid =1 and t3.set_id =1; |
|
686 |
drop tables t1,t2,t3; |
|
687 |
||
688 |
#
|
|
689 |
# Test for bug #11285: false Item_equal on expression in outer join |
|
690 |
#
|
|
691 |
||
692 |
CREATE TABLE t1 (c11 int); |
|
693 |
CREATE TABLE t2 (c21 int); |
|
694 |
INSERT INTO t1 VALUES (30), (40), (50); |
|
695 |
INSERT INTO t2 VALUES (300), (400), (500); |
|
696 |
SELECT * FROM t1 LEFT JOIN t2 ON (c11=c21 AND c21=30) WHERE c11=40; |
|
697 |
DROP TABLE t1, t2; |
|
698 |
#
|
|
699 |
# Test for bugs |
|
700 |
# #12101: erroneously applied outer join elimination in case of WHERE NOT BETWEEN |
|
701 |
# #12102: erroneously missing outer join elimination in case of WHERE IN/IF |
|
702 |
#
|
|
703 |
||
704 |
CREATE TABLE t1 (a int PRIMARY KEY, b int); |
|
705 |
CREATE TABLE t2 (a int PRIMARY KEY, b int); |
|
706 |
||
707 |
INSERT INTO t1 VALUES (1,2), (2,1), (3,2), (4,3), (5,6), (6,5), (7,8), (8,7), (9,10); |
|
708 |
INSERT INTO t2 VALUES (3,0), (4,1), (6,4), (7,5); |
|
709 |
||
710 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.a WHERE t2.b <= t1.a AND t1.a <= t1.b; |
|
711 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.a WHERE t1.a BETWEEN t2.b AND t1.b; |
|
712 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.a WHERE NOT(t1.a NOT BETWEEN t2.b AND t1.b); |
|
713 |
||
714 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.a WHERE t2.b > t1.a OR t1.a > t1.b; |
|
715 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.a WHERE t1.a NOT BETWEEN t2.b AND t1.b; |
|
716 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.a WHERE NOT(t1.a BETWEEN t2.b AND t1.b); |
|
717 |
||
718 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.a WHERE t1.a = t2.a OR t2.b > t1.a OR t1.a > t1.b; |
|
719 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.a WHERE NOT(t1.a != t2.a AND t1.a BETWEEN t2.b AND t1.b); |
|
720 |
||
721 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.a WHERE t1.a = t2.a AND (t2.b > t1.a OR t1.a > t1.b); |
|
722 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.a WHERE NOT(t1.a != t2.a OR t1.a BETWEEN t2.b AND t1.b); |
|
723 |
||
724 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.a WHERE t1.a = t2.a OR t1.a = t2.b; |
|
725 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.a WHERE t1.a IN(t2.a, t2.b); |
|
726 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.a WHERE NOT(t1.a NOT IN(t2.a, t2.b)); |
|
727 |
||
728 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.a WHERE t1.a != t1.b AND t1.a != t2.b; |
|
729 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.a WHERE t1.a NOT IN(t1.b, t2.b); |
|
730 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.a WHERE NOT(t1.a IN(t1.b, t2.b)); |
|
731 |
||
732 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.a WHERE t2.a != t2.b OR (t1.a != t2.a AND t1.a != t2.b); |
|
733 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.a WHERE NOT(t2.a = t2.b AND t1.a IN(t2.a, t2.b)); |
|
734 |
||
735 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.a WHERE t2.a != t2.b AND t1.a != t1.b AND t1.a != t2.b; |
|
736 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.a WHERE NOT(t2.a = t2.b OR t1.a IN(t1.b, t2.b)); |
|
737 |
||
738 |
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.a WHERE t1.a = t2.a OR t1.a = t2.b; |
|
739 |
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.a WHERE t1.a IN(t2.a, t2.b); |
|
740 |
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.a WHERE t1.a > IF(t1.a = t2.b-2, t2.b, t2.b-1); |
|
741 |
||
742 |
DROP TABLE t1,t2; |
|
743 |
||
744 |
#
|
|
745 |
# Bug 19816: LEFT OUTER JOIN with constant ORed predicates in WHERE clause |
|
746 |
#
|
|
747 |
||
748 |
CREATE TABLE t1 (a int); |
|
749 |
CREATE TABLE t2 (b int); |
|
750 |
INSERT INTO t1 VALUES (1), (2), (3), (4); |
|
751 |
INSERT INTO t2 VALUES (2), (3); |
|
752 |
||
753 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (1=1); |
|
754 |
||
755 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (1 OR 1); |
|
756 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (0 OR 1); |
|
757 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (1=1 OR 2=2); |
|
758 |
SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.b WHERE (1=1 OR 1=0); |
|
759 |
||
760 |
DROP TABLE t1,t2; |
|
761 |
||
762 |
#
|
|
763 |
# Bug 26017: LEFT OUTER JOIN over two constant tables and |
|
764 |
# a case-insensitive comparison predicate field=const |
|
765 |
#
|
|
766 |
||
767 |
CREATE TABLE t1 ( |
|
383.1.30
by Brian Aker
Removal of latin character set. |
768 |
f1 varchar(16) collate utf8_swedish_ci PRIMARY KEY, |
769 |
f2 varchar(16) collate utf8_swedish_ci |
|
1
by brian
clean slate |
770 |
);
|
771 |
CREATE TABLE t2 ( |
|
383.1.30
by Brian Aker
Removal of latin character set. |
772 |
f1 varchar(16) collate utf8_swedish_ci PRIMARY KEY, |
773 |
f3 varchar(16) collate utf8_swedish_ci |
|
1
by brian
clean slate |
774 |
);
|
775 |
||
776 |
INSERT INTO t1 VALUES ('bla','blah'); |
|
777 |
INSERT INTO t2 VALUES ('bla','sheep'); |
|
778 |
||
779 |
SELECT * FROM t1 JOIN t2 USING(f1) WHERE f1='Bla'; |
|
780 |
SELECT * FROM t1 LEFT JOIN t2 USING(f1) WHERE f1='bla'; |
|
781 |
SELECT * FROM t1 LEFT JOIN t2 USING(f1) WHERE f1='Bla'; |
|
782 |
||
783 |
DROP TABLE t1,t2; |
|
784 |
||
785 |
#
|
|
786 |
# Bug 28188: 'not exists' optimization for outer joins |
|
787 |
#
|
|
788 |
||
789 |
CREATE TABLE t1 (id int PRIMARY KEY, a varchar(8)); |
|
790 |
CREATE TABLE t2 (id int NOT NULL, b int NOT NULL, INDEX idx(id)); |
|
791 |
INSERT INTO t1 VALUES |
|
792 |
(1,'aaaaaaa'), (5,'eeeeeee'), (4,'ddddddd'), (2,'bbbbbbb'), (3,'ccccccc'); |
|
793 |
INSERT INTO t2 VALUES |
|
794 |
(3,10), (2,20), (5,30), (3,20), (5,10), (3,40), (3,30), (2,10), (2,40); |
|
795 |
||
796 |
EXPLAIN
|
|
797 |
SELECT t1.id, a FROM t1 LEFT JOIN t2 ON t1.id=t2.id WHERE t2.b IS NULL; |
|
798 |
||
799 |
flush status; |
|
800 |
SELECT t1.id, a FROM t1 LEFT JOIN t2 ON t1.id=t2.id WHERE t2.b IS NULL; |
|
1273.16.1
by Brian Aker
More removal of show code. |
801 |
--replace_column 2 #
|
1
by brian
clean slate |
802 |
show status like 'Handler_read%'; |
803 |
||
804 |
DROP TABLE t1,t2; |
|
805 |
||
806 |
#
|
|
807 |
# Bug 28571: outer join with false on condition over constant tables |
|
808 |
#
|
|
809 |
||
810 |
CREATE TABLE t1 (c int PRIMARY KEY, e int NOT NULL); |
|
811 |
INSERT INTO t1 VALUES (1,0), (2,1); |
|
812 |
CREATE TABLE t2 (d int PRIMARY KEY); |
|
813 |
INSERT INTO t2 VALUES (1), (2), (3); |
|
814 |
||
815 |
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 ON e<>0 WHERE c=1 AND d IS NULL; |
|
816 |
SELECT * FROM t1 LEFT JOIN t2 ON e<>0 WHERE c=1 AND d IS NULL; |
|
817 |
SELECT * FROM t1 LEFT JOIN t2 ON e<>0 WHERE c=1 AND d<=>NULL; |
|
818 |
||
819 |
DROP TABLE t1,t2; |
|
820 |