1
by brian
clean slate |
1 |
# Initialise
|
2 |
--disable_warnings
|
|
3 |
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t11,t12;
|
|
4 |
--enable_warnings
|
|
5 |
select (select 2);
|
|
6 |
explain extended select (select 2);
|
|
7 |
SELECT (SELECT 1) UNION SELECT (SELECT 2);
|
|
8 |
explain extended SELECT (SELECT 1) UNION SELECT (SELECT 2);
|
|
9 |
SELECT (SELECT (SELECT 0 UNION SELECT 0));
|
|
10 |
explain extended SELECT (SELECT (SELECT 0 UNION SELECT 0));
|
|
11 |
-- error 1247
|
|
12 |
SELECT (SELECT 1 FROM (SELECT 1) as b HAVING a=1) as a;
|
|
13 |
-- error 1247
|
|
14 |
SELECT (SELECT 1 FROM (SELECT 1) as b HAVING b=1) as a,(SELECT 1 FROM (SELECT 1) as c HAVING a=1) as b;
|
|
15 |
SELECT (SELECT 1),MAX(1) FROM (SELECT 1) as a;
|
|
16 |
-- error 1247
|
|
17 |
SELECT (SELECT a) as a;
|
|
18 |
EXPLAIN EXTENDED SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
|
|
19 |
SELECT 1 FROM (SELECT 1 as a) as b HAVING (SELECT a)=1;
|
|
20 |
-- error 1054
|
|
21 |
SELECT (SELECT 1), a;
|
|
22 |
SELECT 1 as a FROM (SELECT 1) as b HAVING (SELECT a)=1;
|
|
23 |
-- error 1054
|
|
24 |
SELECT 1 FROM (SELECT (SELECT a) b) c;
|
|
25 |
SELECT * FROM (SELECT 1 as id) b WHERE id IN (SELECT * FROM (SELECT 1 as id) c ORDER BY id);
|
|
26 |
-- error 1241
|
|
27 |
SELECT * FROM (SELECT 1) a WHERE 1 IN (SELECT 1,1);
|
|
28 |
SELECT 1 IN (SELECT 1);
|
|
29 |
SELECT 1 FROM (SELECT 1 as a) b WHERE 1 IN (SELECT (SELECT a));
|
|
30 |
-- error ER_BAD_FIELD_ERROR
|
|
31 |
SELECT (SELECT 1) as a FROM (SELECT 1) b WHERE (SELECT a) IS NULL;
|
|
32 |
-- error ER_BAD_FIELD_ERROR
|
|
33 |
SELECT (SELECT 1) as a FROM (SELECT 1) b WHERE (SELECT a) IS NOT NULL;
|
|
34 |
SELECT (SELECT 1,2,3) = ROW(1,2,3);
|
|
35 |
SELECT (SELECT 1,2,3) = ROW(1,2,1);
|
|
36 |
SELECT (SELECT 1,2,3) < ROW(1,2,1);
|
|
37 |
SELECT (SELECT 1,2,3) > ROW(1,2,1);
|
|
38 |
SELECT (SELECT 1,2,3) = ROW(1,2,NULL);
|
|
39 |
SELECT ROW(1,2,3) = (SELECT 1,2,3);
|
|
40 |
SELECT ROW(1,2,3) = (SELECT 1,2,1);
|
|
41 |
SELECT ROW(1,2,3) < (SELECT 1,2,1);
|
|
42 |
SELECT ROW(1,2,3) > (SELECT 1,2,1);
|
|
43 |
SELECT ROW(1,2,3) = (SELECT 1,2,NULL);
|
|
44 |
SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'a');
|
|
45 |
SELECT (SELECT 1.5,2,'a') = ROW(1.5,2,'b');
|
|
46 |
SELECT (SELECT 1.5,2,'a') = ROW('1.5b',2,'b');
|
|
47 |
SELECT (SELECT 'b',2,'a') = ROW(1.5,2,'a');
|
|
48 |
SELECT (SELECT 1.5,2,'a') = ROW(1.5,'2','a');
|
|
49 |
SELECT (SELECT 1.5,'c','a') = ROW(1.5,2,'a');
|
|
50 |
||
51 |
-- error 1241 |
|
52 |
SELECT (SELECT * FROM (SELECT 'test' a,'test' b) a); |
|
53 |
||
54 |
SELECT 1 as a,(SELECT a+a) b,(SELECT b); |
|
55 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
56 |
create table t1 (a int) ENGINE=MyISAM; |
57 |
create table t2 (a int, b int) ENGINE=MyISAM; |
|
58 |
create table t3 (a int) ENGINE=MyISAM; |
|
59 |
create table t4 (a int not null, b int not null) ENGINE=MyISAM; |
|
1
by brian
clean slate |
60 |
insert into t1 values (2); |
61 |
insert into t2 values (1,7),(2,7); |
|
62 |
insert into t4 values (4,8),(3,8),(5,9); |
|
63 |
-- error 1247 |
|
64 |
select (select a from t1 where t1.a = a1) as a2, (select b from t2 where t2.b=a2) as a1; |
|
65 |
select (select a from t1 where t1.a=t2.a), a from t2; |
|
66 |
select (select a from t1 where t1.a=t2.b), a from t2; |
|
67 |
select (select a from t1), a, (select 1 union select 2 limit 1) from t2; |
|
68 |
select (select a from t3), a from t2; |
|
69 |
select * from t2 where t2.a=(select a from t1); |
|
70 |
insert into t3 values (6),(7),(3); |
|
71 |
select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1); |
|
72 |
(select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1)) union (select * from t4 order by a limit 2) limit 3; |
|
73 |
(select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1)) union (select * from t4 where t4.b=(select max(t2.a)*4 from t2) order by a); |
|
74 |
explain extended (select * from t2 where t2.b=(select a from t3 order by 1 desc limit 1)) union (select * from t4 where t4.b=(select max(t2.a)*4 from t2) order by a); |
|
75 |
select (select a from t3 where a<t2.a*4 order by 1 desc limit 1), a from t2; |
|
76 |
select (select t3.a from t3 where a<8 order by 1 desc limit 1), a from |
|
77 |
(select * from t2 where a>1) as tt; |
|
78 |
explain extended select (select t3.a from t3 where a<8 order by 1 desc limit 1), a from |
|
79 |
(select * from t2 where a>1) as tt; |
|
80 |
select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3) order by 1 desc limit 1); |
|
81 |
select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3 where t3.a > t1.a) order by 1 desc limit 1); |
|
82 |
select * from t1 where t1.a=(select t2.a from t2 where t2.b=(select max(a) from t3 where t3.a < t1.a) order by 1 desc limit 1); |
|
83 |
select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4; |
|
84 |
explain extended select b,(select avg(t2.a+(select min(t3.a) from t3 where t3.a >= t4.a)) from t2) from t4; |
|
85 |
select * from t3 where exists (select * from t2 where t2.b=t3.a); |
|
86 |
select * from t3 where not exists (select * from t2 where t2.b=t3.a); |
|
87 |
select * from t3 where a in (select b from t2); |
|
88 |
select * from t3 where a not in (select b from t2); |
|
89 |
select * from t3 where a = some (select b from t2); |
|
90 |
select * from t3 where a <> any (select b from t2); |
|
91 |
||
92 |
# Rewrite: select * from t3 where not exists (select b from t2 where a <> b); |
|
93 |
select * from t3 where a = all (select b from t2); |
|
94 |
||
95 |
select * from t3 where a <> all (select b from t2); |
|
96 |
insert into t2 values (100, 5); |
|
97 |
select * from t3 where a < any (select b from t2); |
|
98 |
select * from t3 where a < all (select b from t2); |
|
99 |
select * from t3 where a >= any (select b from t2); |
|
100 |
explain extended select * from t3 where a >= any (select b from t2); |
|
101 |
select * from t3 where a >= all (select b from t2); |
|
102 |
delete from t2 where a=100; |
|
103 |
-- error 1241 |
|
104 |
select * from t3 where a in (select a,b from t2); |
|
105 |
-- error 1241 |
|
106 |
select * from t3 where a in (select * from t2); |
|
107 |
insert into t4 values (12,7),(1,7),(10,9),(9,6),(7,6),(3,9),(1,10); |
|
108 |
# empty set |
|
109 |
select b,max(a) as ma from t4 group by b having b < (select max(t2.a) from t2 where t2.b=t4.b); |
|
110 |
insert into t2 values (2,10); |
|
111 |
select b,max(a) as ma from t4 group by b having ma < (select max(t2.a) from t2 where t2.b=t4.b); |
|
112 |
delete from t2 where a=2 and b=10; |
|
113 |
select b,max(a) as ma from t4 group by b having b >= (select max(t2.a) from t2 where t2.b=t4.b); |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
114 |
create table t5 (a int) ENGINE=MyISAM; |
1
by brian
clean slate |
115 |
select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; |
116 |
insert into t5 values (5); |
|
117 |
select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; |
|
118 |
insert into t5 values (2); |
|
119 |
select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; |
|
120 |
explain extended select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2; |
|
121 |
-- error 1242 |
|
122 |
select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2; |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
123 |
create table t6 (patient_uq int, clinic_uq int, index i1 (clinic_uq)) ENGINE=MyISAM; |
124 |
create table t7( uq int primary key, name char(25)) ENGINE=MyISAM; |
|
1
by brian
clean slate |
125 |
insert into t7 values(1,"Oblastnaia bolnitsa"),(2,"Bolnitsa Krasnogo Kresta"); |
126 |
insert into t6 values (1,1),(1,2),(2,2),(1,3); |
|
127 |
select * from t6 where exists (select * from t7 where uq = clinic_uq); |
|
128 |
explain extended select * from t6 where exists (select * from t7 where uq = clinic_uq); |
|
129 |
||
130 |
# not unique fields |
|
131 |
-- error 1052 |
|
132 |
select * from t1 where a= (select a from t2,t4 where t2.b=t4.b); |
|
133 |
||
134 |
# different tipes & group functions |
|
135 |
drop table t1,t2,t3; |
|
136 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
137 |
CREATE TABLE t3 (a varchar(20),b char(1) NOT NULL default '0') ENGINE=MyISAM; |
1
by brian
clean slate |
138 |
INSERT INTO t3 VALUES ('W','a'),('A','c'),('J','b'); |
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
139 |
CREATE TABLE t2 (a varchar(20),b int NOT NULL default '0') ENGINE=MyISAM; |
1
by brian
clean slate |
140 |
INSERT INTO t2 VALUES ('W','1'),('A','3'),('J','2'); |
873.1.1
by Jay Pipes
Fixes the Field_date class to not allow any invalid input at |
141 |
CREATE TABLE t1 (a varchar(20),b date NULL) ENGINE=MyISAM; |
1
by brian
clean slate |
142 |
INSERT INTO t1 VALUES ('W','1732-02-22'),('A','1735-10-30'),('J','1743-04-13'); |
143 |
SELECT * FROM t1 WHERE b = (SELECT MIN(b) FROM t1); |
|
144 |
SELECT * FROM t2 WHERE b = (SELECT MIN(b) FROM t2); |
|
145 |
SELECT * FROM t3 WHERE b = (SELECT MIN(b) FROM t3); |
|
146 |
||
147 |
CREATE TABLE `t8` ( |
|
383.1.28
by Brian Aker
Fix for CREATE TABLE/character sets. |
148 |
`pseudo` varchar(35) NOT NULL default '', |
149 |
`email` varchar(60) NOT NULL default '', |
|
1
by brian
clean slate |
150 |
PRIMARY KEY (`pseudo`), |
151 |
UNIQUE KEY `email` (`email`) |
|
377.1.4
by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one |
152 |
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC; |
1
by brian
clean slate |
153 |
|
154 |
INSERT INTO t8 (pseudo,email) VALUES ('joce','test'); |
|
155 |
INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1'); |
|
156 |
INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1'); |
|
157 |
EXPLAIN EXTENDED SELECT pseudo,(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce')) FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'); |
|
158 |
-- error 1241 |
|
159 |
SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM |
|
160 |
t8 WHERE pseudo='joce'); |
|
161 |
-- error 1241 |
|
162 |
SELECT pseudo FROM t8 WHERE pseudo=(SELECT * FROM t8 WHERE |
|
163 |
pseudo='joce'); |
|
164 |
SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'); |
|
165 |
-- error 1242 |
|
166 |
SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo LIKE '%joce%'); |
|
167 |
||
168 |
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8; |
|
169 |
||
170 |
#searchconthardwarefr3 forumconthardwarefr7 |
|
171 |
CREATE TABLE `t1` ( |
|
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
172 |
`topic` bigint NOT NULL default '0', |
873.1.1
by Jay Pipes
Fixes the Field_date class to not allow any invalid input at |
173 |
`date` date NULL, |
383.1.28
by Brian Aker
Fix for CREATE TABLE/character sets. |
174 |
`pseudo` varchar(35) NOT NULL default '', |
1
by brian
clean slate |
175 |
PRIMARY KEY (`pseudo`,`date`,`topic`), |
176 |
KEY `topic` (`topic`) |
|
177 |
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC; |
|
178 |
INSERT INTO t1 (topic,date,pseudo) VALUES |
|
179 |
('43506','2002-10-02','joce'),('40143','2002-08-03','joce'); |
|
180 |
EXPLAIN EXTENDED SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'; |
|
181 |
EXPLAIN EXTENDED SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'); |
|
182 |
SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'; |
|
183 |
SELECT (SELECT DISTINCT date FROM t1 WHERE date='2002-08-03'); |
|
184 |
SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION SELECT 1) UNION ALL SELECT 1; |
|
185 |
-- error 1242 |
|
186 |
SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION ALL SELECT 1) UNION SELECT 1; |
|
187 |
EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1=(SELECT 1 UNION SELECT 1); |
|
188 |
drop table t1; |
|
189 |
||
190 |
#forumconthardwarefr7 searchconthardwarefr7 |
|
191 |
CREATE TABLE `t1` ( |
|
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
192 |
`numeropost` bigint NOT NULL auto_increment, |
193 |
`maxnumrep` int NOT NULL default '0', |
|
1
by brian
clean slate |
194 |
PRIMARY KEY (`numeropost`), |
195 |
UNIQUE KEY `maxnumrep` (`maxnumrep`) |
|
196 |
) ENGINE=MyISAM ROW_FORMAT=FIXED; |
|
197 |
||
198 |
INSERT INTO t1 (numeropost,maxnumrep) VALUES (40143,1),(43506,2); |
|
199 |
||
200 |
CREATE TABLE `t2` ( |
|
201 |
`mot` varchar(30) NOT NULL default '', |
|
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
202 |
`topic` bigint NOT NULL default '0', |
873.1.1
by Jay Pipes
Fixes the Field_date class to not allow any invalid input at |
203 |
`date` date NULL, |
1
by brian
clean slate |
204 |
`pseudo` varchar(35) NOT NULL default '', |
205 |
PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`) |
|
206 |
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC; |
|
207 |
||
208 |
INSERT INTO t2 (mot,topic,date,pseudo) VALUES ('joce','40143','2002-10-22','joce'), ('joce','43506','2002-10-22','joce'); |
|
209 |
select numeropost as a FROM t1 GROUP BY (SELECT 1 FROM t1 HAVING a=1); |
|
210 |
SELECT numeropost,maxnumrep FROM t1 WHERE exists (SELECT 1 FROM t2 WHERE (mot='joce') AND date >= '2002-10-21' AND t1.numeropost = t2.topic) ORDER BY maxnumrep DESC LIMIT 0, 20; |
|
211 |
-- error 1054 |
|
212 |
SELECT (SELECT 1) as a FROM (SELECT 1 FROM t1 HAVING a=1) b; |
|
213 |
-- error 1054 |
|
214 |
SELECT 1 IN (SELECT 1 FROM t2 HAVING a); |
|
215 |
||
216 |
SELECT * from t2 where topic IN (SELECT topic FROM t2 GROUP BY topic); |
|
217 |
SELECT * from t2 where topic IN (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100); |
|
218 |
SELECT * from t2 where topic IN (SELECT SUM(topic) FROM t1); |
|
219 |
SELECT * from t2 where topic = any (SELECT topic FROM t2 GROUP BY topic); |
|
220 |
SELECT * from t2 where topic = any (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100); |
|
221 |
SELECT * from t2 where topic = any (SELECT SUM(topic) FROM t1); |
|
222 |
SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic); |
|
223 |
SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100); |
|
224 |
SELECT *, topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 4100) from t2; |
|
225 |
SELECT * from t2 where topic = all (SELECT SUM(topic) FROM t2); |
|
226 |
SELECT * from t2 where topic <> any (SELECT SUM(topic) FROM t2); |
|
227 |
SELECT * from t2 where topic IN (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000); |
|
228 |
SELECT * from t2 where topic = any (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000); |
|
229 |
SELECT * from t2 where topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000); |
|
230 |
SELECT *, topic = all (SELECT topic FROM t2 GROUP BY topic HAVING topic < 41000) from t2; |
|
231 |
drop table t1,t2; |
|
232 |
||
233 |
#forumconthardwarefr7 |
|
234 |
CREATE TABLE `t1` ( |
|
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
235 |
`numeropost` bigint NOT NULL auto_increment, |
236 |
`maxnumrep` int NOT NULL default '0', |
|
1
by brian
clean slate |
237 |
PRIMARY KEY (`numeropost`), |
238 |
UNIQUE KEY `maxnumrep` (`maxnumrep`) |
|
239 |
) ENGINE=MyISAM ROW_FORMAT=FIXED; |
|
240 |
||
241 |
INSERT INTO t1 (numeropost,maxnumrep) VALUES (1,0),(2,1); |
|
242 |
-- error 1242 |
|
243 |
select numeropost as a FROM t1 GROUP BY (SELECT 1 FROM t1 HAVING a=1); |
|
244 |
-- error 1242 |
|
245 |
select numeropost as a FROM t1 ORDER BY (SELECT 1 FROM t1 HAVING a=1); |
|
246 |
drop table t1; |
|
247 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
248 |
create table t1 (a int) ENGINE=MyISAM; |
1
by brian
clean slate |
249 |
insert into t1 values (1),(2),(3); |
250 |
(select * from t1) union (select * from t1) order by (select a from t1 limit 1); |
|
251 |
drop table t1; |
|
252 |
||
253 |
#iftest |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
254 |
CREATE TABLE t1 (field char(1) NOT NULL DEFAULT 'b') ENGINE=MyISAM; |
1
by brian
clean slate |
255 |
INSERT INTO t1 VALUES (); |
256 |
-- error 1242 |
|
257 |
SELECT field FROM t1 WHERE 1=(SELECT 1 UNION ALL SELECT 1 FROM (SELECT 1) a HAVING field='b'); |
|
258 |
drop table t1; |
|
259 |
||
260 |
# threadhardwarefr7 |
|
261 |
CREATE TABLE `t1` ( |
|
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
262 |
`numeropost` bigint NOT NULL default '0', |
263 |
`numreponse` int NOT NULL auto_increment, |
|
1
by brian
clean slate |
264 |
`pseudo` varchar(35) NOT NULL default '', |
265 |
PRIMARY KEY (`numeropost`,`numreponse`), |
|
266 |
UNIQUE KEY `numreponse` (`numreponse`), |
|
267 |
KEY `pseudo` (`pseudo`,`numeropost`) |
|
268 |
) ENGINE=MyISAM; |
|
269 |
-- error 1247 |
|
270 |
SELECT (SELECT numeropost FROM t1 HAVING numreponse=a),numreponse FROM (SELECT * FROM t1) as a; |
|
271 |
-- error 1054 |
|
272 |
SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=a) FROM (SELECT * FROM t1) as a; |
|
273 |
SELECT numreponse, (SELECT numeropost FROM t1 HAVING numreponse=1) FROM (SELECT * FROM t1) as a; |
|
274 |
INSERT INTO t1 (numeropost,numreponse,pseudo) VALUES (1,1,'joce'),(1,2,'joce'),(1,3,'test'); |
|
275 |
-- error 1242 |
|
276 |
EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT 1 FROM t1 WHERE numeropost='1'); |
|
277 |
EXPLAIN EXTENDED SELECT MAX(numreponse) FROM t1 WHERE numeropost='1'; |
|
278 |
EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT MAX(numreponse) FROM t1 WHERE numeropost='1'); |
|
279 |
drop table t1; |
|
280 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
281 |
CREATE TABLE t1 (a int) ENGINE=MyISAM; |
1
by brian
clean slate |
282 |
INSERT INTO t1 VALUES (1); |
283 |
SELECT 1 FROM (SELECT a FROM t1) b HAVING (SELECT b.a)=1; |
|
284 |
drop table t1; |
|
285 |
||
286 |
#update with subselects |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
287 |
create table t1 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM; |
288 |
create table t2 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM; |
|
1
by brian
clean slate |
289 |
insert into t1 values (0, 10),(1, 11),(2, 12); |
290 |
insert into t2 values (1, 21),(2, 22),(3, 23); |
|
291 |
select * from t1; |
|
292 |
-- error 1093 |
|
293 |
update t1 set b= (select b from t1); |
|
294 |
-- error 1242 |
|
295 |
update t1 set b= (select b from t2); |
|
296 |
update t1 set b= (select b from t2 where t1.a = t2.a); |
|
297 |
select * from t1; |
|
298 |
drop table t1, t2; |
|
299 |
||
300 |
#delete with subselects |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
301 |
create table t1 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM; |
302 |
create table t2 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM; |
|
1
by brian
clean slate |
303 |
insert into t1 values (0, 10),(1, 11),(2, 12); |
304 |
insert into t2 values (1, 21),(2, 12),(3, 23); |
|
305 |
select * from t1; |
|
306 |
select * from t1 where b = (select b from t2 where t1.a = t2.a); |
|
307 |
-- error 1093 |
|
308 |
delete from t1 where b = (select b from t1); |
|
309 |
-- error 1242 |
|
310 |
delete from t1 where b = (select b from t2); |
|
311 |
delete from t1 where b = (select b from t2 where t1.a = t2.a); |
|
312 |
select * from t1; |
|
313 |
drop table t1, t2; |
|
314 |
||
315 |
#multi-delete with subselects |
|
316 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
317 |
create table t11 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM; |
318 |
create table t12 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM; |
|
319 |
create table t2 (a int NOT NULL, b int, primary key (a)) ENGINE=MyISAM; |
|
1
by brian
clean slate |
320 |
insert into t11 values (0, 10),(1, 11),(2, 12); |
321 |
insert into t12 values (33, 10),(22, 11),(2, 12); |
|
322 |
insert into t2 values (1, 21),(2, 12),(3, 23); |
|
323 |
select * from t11; |
|
496.1.2
by Paul McCullagh
Changes to .test files to run both PBXT and InnoDB |
324 |
--sorted_result |
1
by brian
clean slate |
325 |
select * from t12; |
326 |
-- error 1093 |
|
327 |
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t12 where t11.a = t12.a); |
|
328 |
-- error 1242 |
|
329 |
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2); |
|
330 |
delete t11.*, t12.* from t11,t12 where t11.a = t12.a and t11.b = (select b from t2 where t11.a = t2.a); |
|
331 |
select * from t11; |
|
496.1.2
by Paul McCullagh
Changes to .test files to run both PBXT and InnoDB |
332 |
--sorted_result |
1
by brian
clean slate |
333 |
select * from t12; |
334 |
drop table t11, t12, t2; |
|
335 |
||
336 |
#insert with subselects |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
337 |
CREATE TABLE t1 (x int) ENGINE=MyISAM; |
338 |
create table t2 (a int) ENGINE=MyISAM; |
|
339 |
create table t3 (b int) ENGINE=MyISAM; |
|
1
by brian
clean slate |
340 |
insert into t2 values (1); |
341 |
insert into t3 values (1),(2); |
|
342 |
-- error 1093 |
|
343 |
INSERT INTO t1 (x) VALUES ((SELECT x FROM t1)); |
|
344 |
-- error 1242 |
|
345 |
INSERT INTO t1 (x) VALUES ((SELECT b FROM t3)); |
|
346 |
INSERT INTO t1 (x) VALUES ((SELECT a FROM t2)); |
|
347 |
select * from t1; |
|
348 |
insert into t2 values (1); |
|
349 |
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(a) FROM t2)); |
|
350 |
-- sleep 1 |
|
351 |
select * from t1; |
|
352 |
INSERT INTO t1 (x) select (SELECT SUM(a)+1 FROM t2) FROM t2; |
|
353 |
select * from t1; |
|
354 |
# After this, only data based on old t1 records should have been added. |
|
355 |
INSERT INTO t1 (x) select (SELECT SUM(x)+2 FROM t1) FROM t2; |
|
356 |
select * from t1; |
|
357 |
-- error 1054 |
|
358 |
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(x) FROM t2)); |
|
359 |
INSERT DELAYED INTO t1 (x) VALUES ((SELECT SUM(a) FROM t2)); |
|
360 |
-- sleep 1 |
|
361 |
select * from t1; |
|
362 |
# |
|
363 |
#TODO: should be uncommented after bug 380 fix pushed |
|
364 |
#INSERT INTO t1 (x) SELECT (SELECT SUM(a)+b FROM t2) from t3; |
|
365 |
#select * from t1; |
|
366 |
drop table t1, t2, t3; |
|
367 |
||
368 |
#replace with subselects |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
369 |
CREATE TABLE t1 (x int not null, y int, primary key (x)) ENGINE=MyISAM; |
370 |
create table t2 (a int) ENGINE=MyISAM; |
|
371 |
create table t3 (a int) ENGINE=MyISAM; |
|
1
by brian
clean slate |
372 |
insert into t2 values (1); |
373 |
insert into t3 values (1),(2); |
|
374 |
select * from t1; |
|
375 |
-- error 1093 |
|
376 |
replace into t1 (x, y) VALUES ((SELECT x FROM t1), (SELECT a+1 FROM t2)); |
|
377 |
-- error 1242 |
|
378 |
replace into t1 (x, y) VALUES ((SELECT a FROM t3), (SELECT a+1 FROM t2)); |
|
379 |
replace into t1 (x, y) VALUES ((SELECT a FROM t2), (SELECT a+1 FROM t2)); |
|
380 |
select * from t1; |
|
381 |
replace into t1 (x, y) VALUES ((SELECT a FROM t2), (SELECT a+2 FROM t2)); |
|
382 |
select * from t1; |
|
383 |
replace DELAYED into t1 (x, y) VALUES ((SELECT a+3 FROM t2), (SELECT a FROM t2)); |
|
384 |
-- sleep 1 |
|
496.1.2
by Paul McCullagh
Changes to .test files to run both PBXT and InnoDB |
385 |
--sorted_result |
1
by brian
clean slate |
386 |
select * from t1; |
387 |
replace DELAYED into t1 (x, y) VALUES ((SELECT a+3 FROM t2), (SELECT a+1 FROM t2)); |
|
388 |
-- sleep 1 |
|
389 |
select * from t1; |
|
390 |
replace LOW_PRIORITY into t1 (x, y) VALUES ((SELECT a+1 FROM t2), (SELECT a FROM t2)); |
|
496.1.2
by Paul McCullagh
Changes to .test files to run both PBXT and InnoDB |
391 |
--sorted_result |
1
by brian
clean slate |
392 |
select * from t1; |
393 |
drop table t1, t2, t3; |
|
394 |
||
395 |
-- error 1096 |
|
396 |
SELECT * FROM (SELECT 1) b WHERE 1 IN (SELECT *); |
|
397 |
||
377.1.4
by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one |
398 |
CREATE TABLE t2 (id int default NULL, KEY id (id)) ENGINE=MyISAM; |
1
by brian
clean slate |
399 |
INSERT INTO t2 VALUES (1),(2); |
400 |
SELECT * FROM t2 WHERE id IN (SELECT 1); |
|
401 |
EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1); |
|
402 |
SELECT * FROM t2 WHERE id IN (SELECT 1 UNION SELECT 3); |
|
403 |
SELECT * FROM t2 WHERE id IN (SELECT 1+(select 1)); |
|
404 |
EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1+(select 1)); |
|
405 |
EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1 UNION SELECT 3); |
|
406 |
SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 3); |
|
407 |
SELECT * FROM t2 WHERE id IN (SELECT 5 UNION SELECT 2); |
|
408 |
-- error 1093 |
|
409 |
INSERT INTO t2 VALUES ((SELECT * FROM t2)); |
|
410 |
-- error 1093 |
|
411 |
INSERT INTO t2 VALUES ((SELECT id FROM t2)); |
|
412 |
SELECT * FROM t2; |
|
377.1.4
by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one |
413 |
CREATE TABLE t1 (id int default NULL, KEY id (id)) ENGINE=MyISAM; |
1
by brian
clean slate |
414 |
INSERT INTO t1 values (1),(1); |
415 |
-- error 1242 |
|
416 |
UPDATE t2 SET id=(SELECT * FROM t1); |
|
417 |
drop table t2, t1; |
|
418 |
||
419 |
#NULL test |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
420 |
create table t1 (a int) ENGINE=MyISAM; |
1
by brian
clean slate |
421 |
insert into t1 values (1),(2),(3); |
422 |
select 1 IN (SELECT * from t1); |
|
423 |
select 10 IN (SELECT * from t1); |
|
424 |
select NULL IN (SELECT * from t1); |
|
425 |
update t1 set a=NULL where a=2; |
|
426 |
select 1 IN (SELECT * from t1); |
|
427 |
select 3 IN (SELECT * from t1); |
|
428 |
select 10 IN (SELECT * from t1); |
|
429 |
select 1 > ALL (SELECT * from t1); |
|
430 |
select 10 > ALL (SELECT * from t1); |
|
431 |
select 1 > ANY (SELECT * from t1); |
|
432 |
select 10 > ANY (SELECT * from t1); |
|
433 |
drop table t1; |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
434 |
create table t1 (a varchar(20)) ENGINE=MyISAM; |
1
by brian
clean slate |
435 |
insert into t1 values ('A'),('BC'),('DEF'); |
436 |
select 'A' IN (SELECT * from t1); |
|
437 |
select 'XYZS' IN (SELECT * from t1); |
|
438 |
select NULL IN (SELECT * from t1); |
|
439 |
update t1 set a=NULL where a='BC'; |
|
440 |
select 'A' IN (SELECT * from t1); |
|
441 |
select 'DEF' IN (SELECT * from t1); |
|
442 |
select 'XYZS' IN (SELECT * from t1); |
|
443 |
select 'A' > ALL (SELECT * from t1); |
|
444 |
select 'XYZS' > ALL (SELECT * from t1); |
|
445 |
select 'A' > ANY (SELECT * from t1); |
|
446 |
select 'XYZS' > ANY (SELECT * from t1); |
|
447 |
drop table t1; |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
448 |
create table t1 (a float) ENGINE=MyISAM; |
1
by brian
clean slate |
449 |
insert into t1 values (1.5),(2.5),(3.5); |
450 |
select 1.5 IN (SELECT * from t1); |
|
451 |
select 10.5 IN (SELECT * from t1); |
|
452 |
select NULL IN (SELECT * from t1); |
|
453 |
update t1 set a=NULL where a=2.5; |
|
454 |
select 1.5 IN (SELECT * from t1); |
|
455 |
select 3.5 IN (SELECT * from t1); |
|
456 |
select 10.5 IN (SELECT * from t1); |
|
457 |
select 1.5 > ALL (SELECT * from t1); |
|
458 |
select 10.5 > ALL (SELECT * from t1); |
|
459 |
select 1.5 > ANY (SELECT * from t1); |
|
460 |
select 10.5 > ANY (SELECT * from t1); |
|
461 |
explain extended select (select a+1) from t1; |
|
496.1.2
by Paul McCullagh
Changes to .test files to run both PBXT and InnoDB |
462 |
--sorted_result |
1
by brian
clean slate |
463 |
select (select a+1) from t1; |
464 |
drop table t1; |
|
465 |
||
466 |
# |
|
467 |
# Null with keys |
|
468 |
# |
|
469 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
470 |
CREATE TABLE t1 (a int NOT NULL default '0', PRIMARY KEY (a)) ENGINE=MyISAM; |
471 |
CREATE TABLE t2 (a int default '0', INDEX (a)) ENGINE=MyISAM; |
|
1
by brian
clean slate |
472 |
INSERT INTO t1 VALUES (1),(2),(3),(4); |
473 |
INSERT INTO t2 VALUES (1),(2),(3); |
|
474 |
SELECT t1.a, t1.a in (select t2.a from t2) FROM t1; |
|
475 |
explain extended SELECT t1.a, t1.a in (select t2.a from t2) FROM t1; |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
476 |
CREATE TABLE t3 (a int default '0') ENGINE=MyISAM; |
1
by brian
clean slate |
477 |
INSERT INTO t3 VALUES (1),(2),(3); |
478 |
SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1; |
|
479 |
explain extended SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1; |
|
480 |
drop table t1,t2,t3; |
|
481 |
||
482 |
#LIMIT is not supported now |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
483 |
#create table t1 (a float) ENGINE=MyISAM; |
383.1.14
by Brian Aker
Updated test. |
484 |
#-- error 1235 |
485 |
#select 10.5 IN (SELECT * from t1 LIMIT 1); |
|
486 |
#-- error 1235 |
|
487 |
#select 10.5 IN (SELECT * from t1 LIMIT 1 UNION SELECT 1.5); |
|
488 |
#drop table t1; |
|
489 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
490 |
#create table t1 (a int, b int, c varchar(10)) ENGINE=MyISAM; |
491 |
#create table t2 (a int) ENGINE=MyISAM; |
|
383.1.14
by Brian Aker
Updated test. |
492 |
#insert into t1 values (1,2,'a'),(2,3,'b'),(3,4,'c'); |
493 |
#insert into t2 values (1),(2),(NULL); |
|
494 |
#select a, (select a,b,c from t1 where t1.a=t2.a) = ROW(a,2,'a'),(select c from t1 where a=t2.a) from t2; |
|
495 |
#select a, (select a,b,c from t1 where t1.a=t2.a) = ROW(a,3,'b'),(select c from t1 where a=t2.a) from t2; |
|
496 |
#select a, (select a,b,c from t1 where t1.a=t2.a) = ROW(a,4,'c'),(select c from t1 where a=t2.a) from t2; |
|
497 |
#drop table t1,t2; |
|
498 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
499 |
#create table t1 (a int, b real, c varchar(10)) ENGINE=MyISAM; |
383.1.14
by Brian Aker
Updated test. |
500 |
#insert into t1 values (1, 1, 'a'), (2,2,'b'), (NULL, 2, 'b'); |
501 |
#select ROW(1, 1, 'a') IN (select a,b,c from t1); |
|
502 |
#select ROW(1, 2, 'a') IN (select a,b,c from t1); |
|
503 |
#select ROW(1, 1, 'a') IN (select b,a,c from t1); |
|
504 |
#select ROW(1, 1, 'a') IN (select a,b,c from t1 where a is not null); |
|
505 |
#select ROW(1, 2, 'a') IN (select a,b,c from t1 where a is not null); |
|
506 |
#select ROW(1, 1, 'a') IN (select b,a,c from t1 where a is not null); |
|
507 |
#select ROW(1, 1, 'a') IN (select a,b,c from t1 where c='b' or c='a'); |
|
508 |
#select ROW(1, 2, 'a') IN (select a,b,c from t1 where c='b' or c='a'); |
|
509 |
#select ROW(1, 1, 'a') IN (select b,a,c from t1 where c='b' or c='a'); |
|
510 |
#-- error 1235 |
|
511 |
#select ROW(1, 1, 'a') IN (select b,a,c from t1 limit 2); |
|
512 |
#drop table t1; |
|
1
by brian
clean slate |
513 |
|
514 |
#test of uncacheable subqueries |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
515 |
CREATE TABLE t1 (a int) ENGINE=MyISAM; |
1
by brian
clean slate |
516 |
EXPLAIN EXTENDED SELECT (SELECT RAND() FROM t1) FROM t1; |
517 |
EXPLAIN EXTENDED SELECT (SELECT BENCHMARK(1,1) FROM t1) FROM t1; |
|
518 |
drop table t1; |
|
519 |
||
520 |
||
521 |
CREATE TABLE `t1` ( |
|
383.1.28
by Brian Aker
Fix for CREATE TABLE/character sets. |
522 |
`mot` varchar(30) NOT NULL default '', |
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
523 |
`topic` bigint NOT NULL default '0', |
873.1.1
by Jay Pipes
Fixes the Field_date class to not allow any invalid input at |
524 |
`date` date NULL, |
383.1.28
by Brian Aker
Fix for CREATE TABLE/character sets. |
525 |
`pseudo` varchar(35) NOT NULL default '', |
1
by brian
clean slate |
526 |
PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`), |
527 |
KEY `pseudo` (`pseudo`,`date`,`topic`), |
|
528 |
KEY `topic` (`topic`) |
|
377.1.4
by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one |
529 |
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC; |
1
by brian
clean slate |
530 |
|
531 |
CREATE TABLE `t2` ( |
|
383.1.28
by Brian Aker
Fix for CREATE TABLE/character sets. |
532 |
`mot` varchar(30) NOT NULL default '', |
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
533 |
`topic` bigint NOT NULL default '0', |
873.1.1
by Jay Pipes
Fixes the Field_date class to not allow any invalid input at |
534 |
`date` date NULL, |
383.1.28
by Brian Aker
Fix for CREATE TABLE/character sets. |
535 |
`pseudo` varchar(35) NOT NULL default '', |
1
by brian
clean slate |
536 |
PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`), |
537 |
KEY `pseudo` (`pseudo`,`date`,`topic`), |
|
538 |
KEY `topic` (`topic`) |
|
377.1.4
by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one |
539 |
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC; |
1
by brian
clean slate |
540 |
|
541 |
CREATE TABLE `t3` ( |
|
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
542 |
`numeropost` bigint NOT NULL auto_increment, |
543 |
`maxnumrep` int NOT NULL default '0', |
|
1
by brian
clean slate |
544 |
PRIMARY KEY (`numeropost`), |
545 |
UNIQUE KEY `maxnumrep` (`maxnumrep`) |
|
377.1.4
by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one |
546 |
) ENGINE=MyISAM; |
1
by brian
clean slate |
547 |
INSERT INTO t1 (mot, topic, pseudo) VALUES ('joce','1','joce'),('test','2','test'); |
548 |
||
549 |
INSERT INTO t2 (mot, topic, pseudo) VALUES ('joce','1','joce'),('test','2','test'); |
|
550 |
||
551 |
INSERT INTO t3 VALUES (1,1); |
|
552 |
||
553 |
SELECT DISTINCT topic FROM t2 WHERE NOT EXISTS(SELECT * FROM t3 WHERE |
|
554 |
numeropost=topic); |
|
555 |
select * from t1; |
|
556 |
DELETE FROM t1 WHERE topic IN (SELECT DISTINCT topic FROM t2 WHERE NOT |
|
557 |
EXISTS(SELECT * FROM t3 WHERE numeropost=topic)); |
|
558 |
select * from t1; |
|
559 |
||
560 |
drop table t1, t2, t3; |
|
561 |
||
562 |
SELECT * FROM (SELECT 1 as a,(SELECT a)) a; |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
563 |
CREATE TABLE t1 ENGINE=MyISAM SELECT * FROM (SELECT 1 as a,(SELECT 1)) a; |
564 |
SHOW CREATE TABLE t1; |
|
565 |
drop table t1; |
|
566 |
CREATE TABLE t1 ENGINE=MyISAM SELECT * FROM (SELECT 1 as a,(SELECT a)) a; |
|
567 |
SHOW CREATE TABLE t1; |
|
568 |
drop table t1; |
|
569 |
CREATE TABLE t1 ENGINE=MyISAM SELECT * FROM (SELECT 1 as a,(SELECT a+0)) a; |
|
570 |
SHOW CREATE TABLE t1; |
|
571 |
drop table t1; |
|
572 |
CREATE TABLE t1 ENGINE=MyISAM SELECT (SELECT 1 as a UNION SELECT 1+1 limit 1,1) as a; |
|
1
by brian
clean slate |
573 |
select * from t1; |
574 |
SHOW CREATE TABLE t1; |
|
575 |
drop table t1; |
|
576 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
577 |
create table t1 (a int) ENGINE=MyISAM; |
1
by brian
clean slate |
578 |
insert into t1 values (1), (2), (3); |
579 |
explain extended select a,(select (select rand() from t1 limit 1) from t1 limit 1) |
|
580 |
from t1; |
|
581 |
drop table t1; |
|
582 |
||
583 |
# |
|
584 |
# error in IN |
|
585 |
# |
|
586 |
-- error 1146 |
|
587 |
select t1.Continent, t2.Name, t2.Population from t1 LEFT JOIN t2 ON t1.Code = t2.Country where t2.Population IN (select max(t2.Population) AS Population from t2, t1 where t2.Country = t1.Code group by Continent); |
|
588 |
||
589 |
# |
|
590 |
# complex subquery |
|
591 |
# |
|
592 |
||
593 |
CREATE TABLE t1 ( |
|
223
by Brian Aker
Cleanup int() work. |
594 |
ID int NOT NULL auto_increment, |
1
by brian
clean slate |
595 |
name char(35) NOT NULL default '', |
596 |
t2 char(3) NOT NULL default '', |
|
597 |
District char(20) NOT NULL default '', |
|
223
by Brian Aker
Cleanup int() work. |
598 |
Population int NOT NULL default '0', |
1
by brian
clean slate |
599 |
PRIMARY KEY (ID) |
600 |
) ENGINE=MyISAM; |
|
601 |
||
602 |
INSERT INTO t1 VALUES (130,'Sydney','AUS','New South Wales',3276207); |
|
603 |
INSERT INTO t1 VALUES (131,'Melbourne','AUS','Victoria',2865329); |
|
604 |
INSERT INTO t1 VALUES (132,'Brisbane','AUS','Queensland',1291117); |
|
605 |
||
606 |
CREATE TABLE t2 ( |
|
607 |
Code char(3) NOT NULL default '', |
|
608 |
Name char(52) NOT NULL default '', |
|
609 |
Continent enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL default 'Asia', |
|
610 |
Region char(26) NOT NULL default '', |
|
611 |
SurfaceArea float(10,2) NOT NULL default '0.00', |
|
396
by Brian Aker
Cleanup tiny and small int. |
612 |
IndepYear int default NULL, |
223
by Brian Aker
Cleanup int() work. |
613 |
Population int NOT NULL default '0', |
1
by brian
clean slate |
614 |
LifeExpectancy float(3,1) default NULL, |
615 |
GNP float(10,2) default NULL, |
|
616 |
GNPOld float(10,2) default NULL, |
|
617 |
LocalName char(45) NOT NULL default '', |
|
618 |
GovernmentForm char(45) NOT NULL default '', |
|
619 |
HeadOfState char(60) default NULL, |
|
223
by Brian Aker
Cleanup int() work. |
620 |
Capital int default NULL, |
1
by brian
clean slate |
621 |
Code2 char(2) NOT NULL default '', |
622 |
PRIMARY KEY (Code) |
|
623 |
) ENGINE=MyISAM; |
|
624 |
||
625 |
INSERT INTO t2 VALUES ('AUS','Australia','Oceania','Australia and New Zealand',7741220.00,1901,18886000,79.8,351182.00,392911.00,'Australia','Constitutional Monarchy, Federation','Elisabeth II',135,'AU'); |
|
626 |
INSERT INTO t2 VALUES ('AZE','Azerbaijan','Asia','Middle East',86600.00,1991,7734000,62.9,4127.00,4100.00,'Azärbaycan','Federal Republic','Heydär Äliyev',144,'AZ'); |
|
627 |
||
628 |
select t2.Continent, t1.Name, t1.Population from t2 LEFT JOIN t1 ON t2.Code = t1.t2 where t1.Population IN (select max(t1.Population) AS Population from t1, t2 where t1.t2 = t2.Code group by Continent); |
|
629 |
||
630 |
drop table t1, t2; |
|
631 |
||
632 |
# |
|
633 |
# constants in IN |
|
634 |
# |
|
635 |
CREATE TABLE `t1` ( |
|
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
636 |
`id` bigint NOT NULL auto_increment, |
383.1.28
by Brian Aker
Fix for CREATE TABLE/character sets. |
637 |
`pseudo` varchar(35) NOT NULL default '', |
1
by brian
clean slate |
638 |
PRIMARY KEY (`id`), |
639 |
UNIQUE KEY `pseudo` (`pseudo`) |
|
640 |
) ENGINE=MyISAM PACK_KEYS=1 ROW_FORMAT=DYNAMIC; |
|
641 |
INSERT INTO t1 (pseudo) VALUES ('test'); |
|
642 |
SELECT 0 IN (SELECT 1 FROM t1 a); |
|
643 |
EXPLAIN EXTENDED SELECT 0 IN (SELECT 1 FROM t1 a); |
|
644 |
INSERT INTO t1 (pseudo) VALUES ('test1'); |
|
645 |
SELECT 0 IN (SELECT 1 FROM t1 a); |
|
646 |
EXPLAIN EXTENDED SELECT 0 IN (SELECT 1 FROM t1 a); |
|
647 |
drop table t1; |
|
648 |
||
649 |
CREATE TABLE `t1` ( |
|
223
by Brian Aker
Cleanup int() work. |
650 |
`i` int NOT NULL default '0', |
1
by brian
clean slate |
651 |
PRIMARY KEY (`i`) |
377.1.4
by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one |
652 |
) ENGINE=MyISAM; |
1
by brian
clean slate |
653 |
|
654 |
INSERT INTO t1 VALUES (1); |
|
655 |
UPDATE t1 SET i=i+(SELECT MAX(i) FROM (SELECT 1) t) WHERE i=(SELECT MAX(i)); |
|
656 |
UPDATE t1 SET i=i+1 WHERE i=(SELECT MAX(i)); |
|
657 |
-- error 1054 |
|
658 |
UPDATE t1 SET t.i=i+(SELECT MAX(i) FROM (SELECT 1) t); |
|
659 |
select * from t1; |
|
660 |
drop table t1; |
|
661 |
||
662 |
# |
|
663 |
# Multi update test |
|
664 |
# |
|
665 |
CREATE TABLE t1 ( |
|
223
by Brian Aker
Cleanup int() work. |
666 |
id int default NULL |
377.1.4
by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one |
667 |
) ENGINE=MyISAM; |
1
by brian
clean slate |
668 |
INSERT INTO t1 VALUES (1),(1),(2),(2),(1),(3); |
669 |
CREATE TABLE t2 ( |
|
223
by Brian Aker
Cleanup int() work. |
670 |
id int default NULL, |
1
by brian
clean slate |
671 |
name varchar(15) default NULL |
377.1.4
by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one |
672 |
) ENGINE=MyISAM; |
1
by brian
clean slate |
673 |
|
674 |
INSERT INTO t2 VALUES (4,'vita'), (1,'vita'), (2,'vita'), (1,'vita'); |
|
675 |
update t1, t2 set t2.name='lenka' where t2.id in (select id from t1); |
|
676 |
select * from t2; |
|
677 |
drop table t1,t2; |
|
678 |
||
679 |
# |
|
680 |
# correct NULL in <CONSTANT> IN (SELECT ...) |
|
681 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
682 |
create table t1 (a int, unique index indexa (a)) ENGINE=MyISAM; |
1
by brian
clean slate |
683 |
insert into t1 values (-1), (-4), (-2), (NULL); |
684 |
select -10 IN (select a from t1 FORCE INDEX (indexa)); |
|
685 |
drop table t1; |
|
686 |
||
687 |
# |
|
688 |
# Test optimization for sub selects |
|
689 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
690 |
create table t1 (id int not null auto_increment primary key, salary int, key(salary)) ENGINE=MyISAM; |
1
by brian
clean slate |
691 |
insert into t1 (salary) values (100),(1000),(10000),(10),(500),(5000),(50000); |
692 |
explain extended SELECT id FROM t1 where salary = (SELECT MAX(salary) FROM t1); |
|
693 |
drop table t1; |
|
694 |
||
695 |
CREATE TABLE t1 ( |
|
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
696 |
ID int NOT NULL auto_increment, |
697 |
SUB_ID int NOT NULL default '0', |
|
698 |
REF_ID int default NULL, |
|
699 |
REF_SUB int default '0', |
|
1
by brian
clean slate |
700 |
PRIMARY KEY (ID,SUB_ID), |
701 |
UNIQUE KEY t1_PK (ID,SUB_ID), |
|
702 |
KEY t1_FK (REF_ID,REF_SUB), |
|
703 |
KEY t1_REFID (REF_ID) |
|
377.1.3
by Brian Aker
Remove a few character sets/fix some tests. |
704 |
) ENGINE=MyISAM; |
1
by brian
clean slate |
705 |
INSERT INTO t1 VALUES (1,0,NULL,NULL),(2,0,NULL,NULL); |
706 |
SELECT DISTINCT REF_ID FROM t1 WHERE ID= (SELECT DISTINCT REF_ID FROM t1 WHERE ID=2); |
|
707 |
DROP TABLE t1; |
|
708 |
||
709 |
# |
|
710 |
# uninterruptable update |
|
711 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
712 |
create table t1 (a int, b int) ENGINE=MyISAM; |
713 |
create table t2 (a int, b int) ENGINE=MyISAM; |
|
1
by brian
clean slate |
714 |
|
715 |
insert into t1 values (1,0), (2,0), (3,0); |
|
716 |
insert into t2 values (1,1), (2,1), (3,1), (2,2); |
|
717 |
||
718 |
update ignore t1 set b=(select b from t2 where t1.a=t2.a); |
|
719 |
select * from t1; |
|
720 |
||
721 |
drop table t1, t2; |
|
722 |
||
723 |
# |
|
724 |
# reduced subselect in ORDER BY & GROUP BY clauses |
|
725 |
# |
|
726 |
||
727 |
CREATE TABLE `t1` ( |
|
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
728 |
`id` bigint NOT NULL auto_increment, |
1
by brian
clean slate |
729 |
`pseudo` varchar(35) NOT NULL default '', |
730 |
`email` varchar(60) NOT NULL default '', |
|
731 |
PRIMARY KEY (`id`), |
|
732 |
UNIQUE KEY `email` (`email`), |
|
733 |
UNIQUE KEY `pseudo` (`pseudo`) |
|
377.1.4
by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one |
734 |
) ENGINE=MyISAM PACK_KEYS=1 ROW_FORMAT=DYNAMIC; |
1
by brian
clean slate |
735 |
INSERT INTO t1 (id,pseudo,email) VALUES (1,'test','test'),(2,'test1','test1'); |
736 |
SELECT pseudo as a, pseudo as b FROM t1 GROUP BY (SELECT a) ORDER BY (SELECT id*1); |
|
737 |
drop table if exists t1; |
|
738 |
||
739 |
(SELECT 1 as a) UNION (SELECT 1) ORDER BY (SELECT a+0); |
|
740 |
||
741 |
# |
|
742 |
# IN subselect optimization test |
|
743 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
744 |
create table t1 (a int not null, b int, primary key (a)) ENGINE=MyISAM; |
745 |
create table t2 (a int not null, primary key (a)) ENGINE=MyISAM; |
|
746 |
create table t3 (a int not null, b int, primary key (a)) ENGINE=MyISAM; |
|
1
by brian
clean slate |
747 |
insert into t1 values (1,10), (2,20), (3,30), (4,40); |
748 |
insert into t2 values (2), (3), (4), (5); |
|
749 |
insert into t3 values (10,3), (20,4), (30,5); |
|
750 |
select * from t2 where t2.a in (select a from t1); |
|
751 |
explain extended select * from t2 where t2.a in (select a from t1); |
|
752 |
select * from t2 where t2.a in (select a from t1 where t1.b <> 30); |
|
753 |
explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30); |
|
754 |
select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); |
|
755 |
explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); |
|
756 |
drop table t1, t2, t3; |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
757 |
create table t1 (a int, b int, index a (a,b)) ENGINE=MyISAM; |
758 |
create table t2 (a int, index a (a)) ENGINE=MyISAM; |
|
759 |
create table t3 (a int, b int, index a (a)) ENGINE=MyISAM; |
|
1
by brian
clean slate |
760 |
insert into t1 values (1,10), (2,20), (3,30), (4,40); |
761 |
disable_query_log; |
|
762 |
# making table large enough |
|
206.1.1
by Stewart Smith
cut 'make test' time in half. |
763 |
set autocommit=0; |
764 |
begin; |
|
1
by brian
clean slate |
765 |
let $1 = 10000; |
766 |
while ($1) |
|
767 |
{ |
|
768 |
eval insert into t1 values (rand()*100000+200,rand()*100000); |
|
769 |
dec $1; |
|
770 |
} |
|
206.1.1
by Stewart Smith
cut 'make test' time in half. |
771 |
commit; |
772 |
set autocommit=1; |
|
1
by brian
clean slate |
773 |
enable_query_log; |
774 |
insert into t2 values (2), (3), (4), (5); |
|
775 |
insert into t3 values (10,3), (20,4), (30,5); |
|
776 |
select * from t2 where t2.a in (select a from t1); |
|
777 |
explain extended select * from t2 where t2.a in (select a from t1); |
|
778 |
select * from t2 where t2.a in (select a from t1 where t1.b <> 30); |
|
779 |
explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30); |
|
780 |
select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); |
|
781 |
explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); |
|
782 |
insert into t1 values (3,31); |
|
783 |
select * from t2 where t2.a in (select a from t1 where t1.b <> 30); |
|
784 |
select * from t2 where t2.a in (select a from t1 where t1.b <> 30 and t1.b <> 31); |
|
785 |
explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30); |
|
786 |
drop table t1, t2, t3; |
|
787 |
||
788 |
# |
|
789 |
# alloc_group_fields() working |
|
790 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
791 |
create table t1 (a int, b int) ENGINE=MyISAM; |
792 |
create table t2 (a int, b int) ENGINE=MyISAM; |
|
793 |
create table t3 (a int, b int) ENGINE=MyISAM; |
|
1
by brian
clean slate |
794 |
insert into t1 values (0,100),(1,2), (1,3), (2,2), (2,7), (2,-1), (3,10); |
795 |
insert into t2 values (0,0), (1,1), (2,1), (3,1), (4,1); |
|
796 |
insert into t3 values (3,3), (2,2), (1,1); |
|
797 |
select a,(select count(distinct t1.b) as sum from t1,t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) from t3; |
|
798 |
drop table t1,t2,t3; |
|
799 |
||
800 |
# |
|
801 |
# aggregate functions in HAVING test |
|
802 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
803 |
create table t1 (s1 int) ENGINE=MyISAM; |
804 |
create table t2 (s1 int) ENGINE=MyISAM; |
|
1
by brian
clean slate |
805 |
insert into t1 values (1); |
806 |
insert into t2 values (1); |
|
807 |
select * from t1 where exists (select s1 from t2 having max(t2.s1)=t1.s1); |
|
808 |
drop table t1,t2; |
|
809 |
||
810 |
# |
|
811 |
# update subquery with wrong field (to force name resolving |
|
812 |
# in UPDATE name space) |
|
813 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
814 |
create table t1 (s1 int) ENGINE=MyISAM; |
815 |
create table t2 (s1 int) ENGINE=MyISAM; |
|
1
by brian
clean slate |
816 |
insert into t1 values (1); |
817 |
insert into t2 values (1); |
|
818 |
-- error 1054 |
|
819 |
update t1 set s1 = s1 + 1 where 1 = (select x.s1 as A from t2 WHERE t2.s1 > t1.s1 order by A); |
|
820 |
DROP TABLE t1, t2; |
|
821 |
||
822 |
# |
|
823 |
# collation test |
|
824 |
# |
|
383.1.10
by Brian Aker
More cleanup/test fixup around utf8 |
825 |
#CREATE TABLE t1 (s1 CHAR(5) COLLATE latin1_german1_ci, |
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
826 |
# s2 CHAR(5) COLLATE latin1_swedish_ci) ENGINE=MyISAM; |
383.1.10
by Brian Aker
More cleanup/test fixup around utf8 |
827 |
#INSERT INTO t1 VALUES ('z','?'); |
828 |
#-- error 1267 |
|
829 |
#select * from t1 where s1 > (select max(s2) from t1); |
|
830 |
#-- error 1267 |
|
831 |
#select * from t1 where s1 > any (select max(s2) from t1); |
|
832 |
#drop table t1; |
|
1
by brian
clean slate |
833 |
|
834 |
# |
|
835 |
# aggregate functions reinitialization |
|
836 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
837 |
create table t1(toid int,rd int) ENGINE=MyISAM; |
838 |
create table t2(userid int,pmnew int,pmtotal int) ENGINE=MyISAM; |
|
1
by brian
clean slate |
839 |
insert into t2 values(1,0,0),(2,0,0); |
840 |
insert into t1 values(1,0),(1,0),(1,0),(1,12),(1,15),(1,123),(1,12312),(1,12312),(1,123),(2,0),(2,0),(2,1),(2,2); |
|
841 |
select userid,pmtotal,pmnew, (select count(rd) from t1 where toid=t2.userid) calc_total, (select count(rd) from t1 where rd=0 and toid=t2.userid) calc_new from t2 where userid in (select distinct toid from t1); |
|
842 |
drop table t1, t2; |
|
843 |
||
844 |
# |
|
845 |
# row union |
|
846 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
847 |
create table t1 (s1 char(5)) ENGINE=MyISAM; |
1
by brian
clean slate |
848 |
-- error 1241 |
849 |
select (select 'a','b' from t1 union select 'a','b' from t1) from t1; |
|
850 |
insert into t1 values ('tttt'); |
|
851 |
select * from t1 where ('a','b')=(select 'a','b' from t1 union select 'a','b' from t1); |
|
852 |
explain extended (select * from t1); |
|
853 |
(select * from t1); |
|
854 |
drop table t1; |
|
855 |
||
856 |
# |
|
857 |
# IN optimisation test results |
|
858 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
859 |
create table t1 (s1 char(5), index s1(s1)) ENGINE=MyISAM; |
860 |
create table t2 (s1 char(5), index s1(s1)) ENGINE=MyISAM; |
|
1
by brian
clean slate |
861 |
insert into t1 values ('a1'),('a2'),('a3'); |
862 |
insert into t2 values ('a1'),('a2'); |
|
863 |
select s1, s1 NOT IN (SELECT s1 FROM t2) from t1; |
|
864 |
select s1, s1 = ANY (SELECT s1 FROM t2) from t1; |
|
865 |
select s1, s1 <> ALL (SELECT s1 FROM t2) from t1; |
|
866 |
select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1; |
|
867 |
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1; |
|
868 |
explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1; |
|
869 |
explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1; |
|
870 |
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1; |
|
871 |
drop table t1,t2; |
|
872 |
||
873 |
# |
|
874 |
# correct ALL optimisation |
|
875 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
876 |
create table t2 (a int, b int) ENGINE=MyISAM; |
877 |
create table t3 (a int) ENGINE=MyISAM; |
|
1
by brian
clean slate |
878 |
insert into t3 values (6),(7),(3); |
879 |
select * from t3 where a >= all (select b from t2); |
|
880 |
explain extended select * from t3 where a >= all (select b from t2); |
|
881 |
select * from t3 where a >= some (select b from t2); |
|
882 |
explain extended select * from t3 where a >= some (select b from t2); |
|
883 |
select * from t3 where a >= all (select b from t2 group by 1); |
|
884 |
explain extended select * from t3 where a >= all (select b from t2 group by 1); |
|
885 |
select * from t3 where a >= some (select b from t2 group by 1); |
|
886 |
explain extended select * from t3 where a >= some (select b from t2 group by 1); |
|
887 |
select * from t3 where NULL >= any (select b from t2); |
|
888 |
explain extended select * from t3 where NULL >= any (select b from t2); |
|
889 |
select * from t3 where NULL >= any (select b from t2 group by 1); |
|
890 |
explain extended select * from t3 where NULL >= any (select b from t2 group by 1); |
|
891 |
select * from t3 where NULL >= some (select b from t2); |
|
892 |
explain extended select * from t3 where NULL >= some (select b from t2); |
|
893 |
select * from t3 where NULL >= some (select b from t2 group by 1); |
|
894 |
explain extended select * from t3 where NULL >= some (select b from t2 group by 1); |
|
895 |
# |
|
896 |
# optimized static ALL/ANY with grouping |
|
897 |
# |
|
898 |
insert into t2 values (2,2), (2,1), (3,3), (3,1); |
|
899 |
select * from t3 where a > all (select max(b) from t2 group by a); |
|
900 |
explain extended select * from t3 where a > all (select max(b) from t2 group by a); |
|
901 |
drop table t2, t3; |
|
902 |
||
903 |
# |
|
904 |
# correct used_tables() |
|
905 |
# |
|
906 |
||
873.1.2
by Jay Pipes
Fixed Field_datetime to never accept any bad datetimes as a string. This broke |
907 |
CREATE TABLE `t1` ( `id` bigint NOT NULL auto_increment, `taskid` bigint NOT NULL default '0', `dbid` int NOT NULL default '0', `create_date` datetime, `last_update` datetime, PRIMARY KEY (`id`)) ENGINE=MyISAM AUTO_INCREMENT=3 ; |
1
by brian
clean slate |
908 |
INSERT INTO `t1` (`id`, `taskid`, `dbid`, `create_date`,`last_update`) VALUES (1, 1, 15, '2003-09-29 10:31:36', '2003-09-29 10:31:36'), (2, 1, 21, now(), now()); |
396
by Brian Aker
Cleanup tiny and small int. |
909 |
CREATE TABLE `t2` (`db_id` int NOT NULL auto_increment,`name` varchar(200) NOT NULL default '',`primary_uid` int NOT NULL default '0',`secondary_uid` int NOT NULL default '0',PRIMARY KEY (`db_id`),UNIQUE KEY `name_2` (`name`)) ENGINE=MyISAM AUTO_INCREMENT=2147483647; |
1
by brian
clean slate |
910 |
INSERT INTO `t2` (`db_id`, `name`, `primary_uid`, `secondary_uid`) VALUES (18, 'Not Set 1', 0, 0),(19, 'Valid', 1, 2),(20, 'Valid 2', 1, 2),(21, 'Should Not Return', 1, 2),(26, 'Not Set 2', 0, 0),(-1, 'ALL DB\'S', 0, 0); |
396
by Brian Aker
Cleanup tiny and small int. |
911 |
CREATE TABLE `t3` (`taskgenid` bigint NOT NULL auto_increment,`dbid` int NOT NULL default '0',`taskid` int NOT NULL default '0',`mon` int NOT NULL default '1',`tues` int NOT NULL default '1',`wed` int NOT NULL default '1',`thur` int NOT NULL default '1',`fri` int NOT NULL default '1',`sat` int NOT NULL default '0',`sun` int NOT NULL default '0',`how_often` int NOT NULL default '1',`userid` int NOT NULL default '0',`active` int NOT NULL default '1',PRIMARY KEY (`taskgenid`)) ENGINE=MyISAM AUTO_INCREMENT=2 ; |
1
by brian
clean slate |
912 |
INSERT INTO `t3` (`taskgenid`, `dbid`, `taskid`, `mon`, `tues`,`wed`, `thur`, `fri`, `sat`, `sun`, `how_often`, `userid`, `active`) VALUES (1,-1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1); |
396
by Brian Aker
Cleanup tiny and small int. |
913 |
CREATE TABLE `t4` (`task_id` int NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM; |
1
by brian
clean slate |
914 |
INSERT INTO `t4` (`task_id`, `description`) VALUES (1, 'Daily Check List'),(2, 'Weekly Status'); |
915 |
select dbid, name, (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') from t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND t4.task_id = taskid; |
|
916 |
SELECT dbid, name FROM t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND ((date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01')) AND t4.task_id = taskid; |
|
917 |
drop table t1,t2,t3,t4; |
|
918 |
||
919 |
# |
|
920 |
# cardinality check |
|
921 |
# |
|
377.1.4
by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one |
922 |
CREATE TABLE t1 (id int default NULL) ENGINE=MyISAM; |
1
by brian
clean slate |
923 |
INSERT INTO t1 VALUES (1),(5); |
377.1.4
by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one |
924 |
CREATE TABLE t2 (id int default NULL) ENGINE=MyISAM; |
1
by brian
clean slate |
925 |
INSERT INTO t2 VALUES (2),(6); |
926 |
-- error 1241 |
|
927 |
select * from t1 where (1,2,6) in (select * from t2); |
|
928 |
DROP TABLE t1,t2; |
|
929 |
||
930 |
# |
|
931 |
# optimized ALL/ANY with union |
|
932 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
933 |
create table t1 (s1 char) ENGINE=MyISAM; |
1
by brian
clean slate |
934 |
insert into t1 values ('e'); |
935 |
select * from t1 where 'f' > any (select s1 from t1); |
|
936 |
select * from t1 where 'f' > any (select s1 from t1 union select s1 from t1); |
|
937 |
explain extended select * from t1 where 'f' > any (select s1 from t1 union select s1 from t1); |
|
938 |
drop table t1; |
|
939 |
||
940 |
# |
|
941 |
# filesort in subquery (restoring join_tab) |
|
942 |
# |
|
377.1.4
by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one |
943 |
CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM; |
1
by brian
clean slate |
944 |
INSERT INTO t1 VALUES ('69294728265'),('18621828126'),('89356874041'),('95895001874'); |
377.1.4
by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one |
945 |
CREATE TABLE t2 (code char(5) NOT NULL default '',UNIQUE KEY code (code)) ENGINE=MyISAM; |
1
by brian
clean slate |
946 |
INSERT INTO t2 VALUES ('1'),('1226'),('1245'),('1862'),('18623'),('1874'),('1967'),('6'); |
947 |
select c.number as phone,(select p.code from t2 p where c.number like concat(p.code, '%') order by length(p.code) desc limit 1) as code from t1 c; |
|
948 |
drop table t1, t2; |
|
949 |
||
950 |
# |
|
951 |
# unresolved field error |
|
952 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
953 |
create table t1 (s1 int) ENGINE=MyISAM; |
954 |
create table t2 (s1 int) ENGINE=MyISAM; |
|
1
by brian
clean slate |
955 |
-- error 1054 |
956 |
select * from t1 where (select count(*) from t2 where t1.s2) = 1; |
|
957 |
-- error 1054 |
|
958 |
select * from t1 where (select count(*) from t2 group by t1.s2) = 1; |
|
959 |
-- error 1054 |
|
960 |
select count(*) from t2 group by t1.s2; |
|
961 |
drop table t1, t2; |
|
962 |
||
963 |
# |
|
964 |
# fix_fields() in add_ref_to_table_cond() |
|
965 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
966 |
CREATE TABLE t1(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC VARCHAR(20) DEFAULT NULL,PRIMARY KEY (COLA, COLB)) ENGINE=MyISAM; |
967 |
CREATE TABLE t2(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC CHAR(1) NOT NULL,PRIMARY KEY (COLA)) ENGINE=MyISAM; |
|
1
by brian
clean slate |
968 |
INSERT INTO t1 VALUES (1,1,'1A3240'), (1,2,'4W2365'); |
969 |
INSERT INTO t2 VALUES (100, 200, 'C'); |
|
970 |
SELECT DISTINCT COLC FROM t1 WHERE COLA = (SELECT COLA FROM t2 WHERE COLB = 200 AND COLC ='C' LIMIT 1); |
|
971 |
DROP TABLE t1, t2; |
|
972 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
973 |
CREATE TABLE t1 (a int) ENGINE=MyISAM; |
1
by brian
clean slate |
974 |
INSERT INTO t1 VALUES (1),(1),(1),(1),(1),(2),(3),(4),(5); |
975 |
SELECT DISTINCT (SELECT a) FROM t1 LIMIT 100; |
|
976 |
DROP TABLE t1; |
|
977 |
||
978 |
# |
|
979 |
# Bug 2479 |
|
980 |
# |
|
981 |
||
982 |
CREATE TABLE `t1` ( |
|
223
by Brian Aker
Cleanup int() work. |
983 |
`id` int NOT NULL auto_increment, |
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
984 |
`id_cns` int NOT NULL default '0', |
1
by brian
clean slate |
985 |
`tipo` enum('','UNO','DUE') NOT NULL default '', |
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
986 |
`anno_dep` int NOT NULL default '0', |
987 |
`particolare` bigint NOT NULL default '0', |
|
988 |
`generale` bigint NOT NULL default '0', |
|
989 |
`bis` int NOT NULL default '0', |
|
1
by brian
clean slate |
990 |
PRIMARY KEY (`id`), |
991 |
UNIQUE KEY `idx_cns_gen_anno` (`anno_dep`,`id_cns`,`generale`,`particolare`), |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
992 |
UNIQUE KEY `idx_cns_par_anno` (`id_cns`,`anno_dep`,`tipo`,`particolare`,`bis`)) |
993 |
ENGINE=MyISAM; |
|
1
by brian
clean slate |
994 |
INSERT INTO `t1` VALUES (1,16,'UNO',1987,2048,9681,0),(2,50,'UNO',1987,1536,13987,0),(3,16,'UNO',1987,2432,14594,0),(4,16,'UNO',1987,1792,13422,0),(5,16,'UNO',1987,1025,10240,0),(6,16,'UNO',1987,1026,7089,0); |
995 |
CREATE TABLE `t2` ( |
|
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
996 |
`id` int NOT NULL auto_increment, |
997 |
`max_anno_dep` int NOT NULL default '0', |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
998 |
PRIMARY KEY (`id`)) ENGINE=MyISAM; |
1
by brian
clean slate |
999 |
INSERT INTO `t2` VALUES (16,1987),(50,1990),(51,1990); |
1000 |
||
1001 |
SELECT cns.id, cns.max_anno_dep, cns.max_anno_dep = (SELECT s.anno_dep FROM t1 AS s WHERE s.id_cns = cns.id ORDER BY s.anno_dep DESC LIMIT 1) AS PIPPO FROM t2 AS cns; |
|
1002 |
||
1003 |
DROP TABLE t1, t2; |
|
1004 |
||
1005 |
# |
|
1006 |
# GLOBAL LIMIT |
|
1007 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1008 |
create table t1 (a int) ENGINE=MyISAM; |
1
by brian
clean slate |
1009 |
insert into t1 values (1), (2), (3); |
1010 |
SET SQL_SELECT_LIMIT=1; |
|
1011 |
select sum(a) from (select * from t1) as a; |
|
1012 |
select 2 in (select * from t1); |
|
1013 |
SET SQL_SELECT_LIMIT=default; |
|
1014 |
drop table t1; |
|
1015 |
||
1016 |
# |
|
1017 |
# Bug #3118: subselect + order by |
|
1018 |
# |
|
1019 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1020 |
CREATE TABLE t1 (a int, b int, INDEX (a)) ENGINE=MyISAM; |
1
by brian
clean slate |
1021 |
INSERT INTO t1 VALUES (1, 1), (1, 2), (1, 3); |
1022 |
SELECT * FROM t1 WHERE a = (SELECT MAX(a) FROM t1 WHERE a = 1) ORDER BY b; |
|
1023 |
DROP TABLE t1; |
|
1024 |
||
1025 |
# Item_cond fix field |
|
1026 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1027 |
create table t1(val varchar(10)) ENGINE=MyISAM; |
1
by brian
clean slate |
1028 |
insert into t1 values ('aaa'), ('bbb'),('eee'),('mmm'),('ppp'); |
1029 |
select count(*) from t1 as w1 where w1.val in (select w2.val from t1 as w2 where w2.val like 'm%') and w1.val in (select w3.val from t1 as w3 where w3.val like 'e%'); |
|
1030 |
drop table t1; |
|
1031 |
||
1032 |
# |
|
1033 |
# ref_or_null replacing with ref |
|
1034 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1035 |
create table t1 (id int not null, text varchar(20) not null default '', primary key (id)) ENGINE=MyISAM; |
1
by brian
clean slate |
1036 |
insert into t1 (id, text) values (1, 'text1'), (2, 'text2'), (3, 'text3'), (4, 'text4'), (5, 'text5'), (6, 'text6'), (7, 'text7'), (8, 'text8'), (9, 'text9'), (10, 'text10'), (11, 'text11'), (12, 'text12'); |
1037 |
select * from t1 where id not in (select id from t1 where id < 8); |
|
1038 |
select * from t1 as tt where not exists (select id from t1 where id < 8 and (id = tt.id or id is null) having id is not null); |
|
1039 |
explain extended select * from t1 where id not in (select id from t1 where id < 8); |
|
1040 |
explain extended select * from t1 as tt where not exists (select id from t1 where id < 8 and (id = tt.id or id is null) having id is not null); |
|
1041 |
insert into t1 (id, text) values (1000, 'text1000'), (1001, 'text1001'); |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1042 |
create table t2 (id int not null, text varchar(20) not null default '', primary key (id)) ENGINE=MyISAM; |
1
by brian
clean slate |
1043 |
insert into t2 (id, text) values (1, 'text1'), (2, 'text2'), (3, 'text3'), (4, 'text4'), (5, 'text5'), (6, 'text6'), (7, 'text7'), (8, 'text8'), (9, 'text9'), (10, 'text10'), (11, 'text1'), (12, 'text2'), (13, 'text3'), (14, 'text4'), (15, 'text5'), (16, 'text6'), (17, 'text7'), (18, 'text8'), (19, 'text9'), (20, 'text10'),(21, 'text1'), (22, 'text2'), (23, 'text3'), (24, 'text4'), (25, 'text5'), (26, 'text6'), (27, 'text7'), (28, 'text8'), (29, 'text9'), (30, 'text10'), (31, 'text1'), (32, 'text2'), (33, 'text3'), (34, 'text4'), (35, 'text5'), (36, 'text6'), (37, 'text7'), (38, 'text8'), (39, 'text9'), (40, 'text10'), (41, 'text1'), (42, 'text2'), (43, 'text3'), (44, 'text4'), (45, 'text5'), (46, 'text6'), (47, 'text7'), (48, 'text8'), (49, 'text9'), (50, 'text10'); |
1044 |
select * from t1 a left join t2 b on (a.id=b.id or b.id is null) join t1 c on (if(isnull(b.id), 1000, b.id)=c.id); |
|
1045 |
explain extended select * from t1 a left join t2 b on (a.id=b.id or b.id is null) join t1 c on (if(isnull(b.id), 1000, b.id)=c.id); |
|
1046 |
drop table t1,t2; |
|
1047 |
||
1048 |
# |
|
1049 |
# Static tables & rund() in subqueries |
|
1050 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1051 |
create table t1 (a int) ENGINE=MyISAM; |
1
by brian
clean slate |
1052 |
insert into t1 values (1); |
1053 |
explain select benchmark(1000, (select a from t1 where a=rand())); |
|
1054 |
drop table t1; |
|
1055 |
||
1056 |
# |
|
1057 |
# bug 3188 |
|
1058 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1059 |
create table t1(id int) ENGINE=MyISAM; |
1060 |
create table t2(id int) ENGINE=MyISAM; |
|
1061 |
create table t3(flag int) ENGINE=MyISAM; |
|
1
by brian
clean slate |
1062 |
-- error 1064 |
1063 |
select (select * from t3 where id not null) from t1, t2; |
|
1064 |
drop table t1,t2,t3; |
|
1065 |
||
1066 |
# |
|
1067 |
# aggregate functions (Bug #3505) |
|
1068 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1069 |
CREATE TABLE t1 (id INT) ENGINE=MyISAM; |
1070 |
CREATE TABLE t2 (id INT) ENGINE=MyISAM; |
|
1
by brian
clean slate |
1071 |
INSERT INTO t1 VALUES (1), (2); |
1072 |
INSERT INTO t2 VALUES (1); |
|
1073 |
SELECT t1.id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id); |
|
1074 |
SELECT id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id); |
|
1075 |
SELECT t1.id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id) ORDER BY t1.id; |
|
1076 |
SELECT id, ( SELECT COUNT(t.id) FROM t2 AS t WHERE t.id = t1.id ) AS c FROM t1 LEFT JOIN t2 USING (id) ORDER BY id; |
|
1077 |
DROP TABLE t1,t2; |
|
1078 |
||
1079 |
# |
|
1080 |
# ALL/ANY test |
|
1081 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1082 |
CREATE TABLE t1 ( a int, b int ) ENGINE=MyISAM; |
1
by brian
clean slate |
1083 |
INSERT INTO t1 VALUES (1,1),(2,2),(3,3); |
1084 |
SELECT a FROM t1 WHERE a > ANY ( SELECT a FROM t1 WHERE b = 2 ); |
|
1085 |
SELECT a FROM t1 WHERE a < ANY ( SELECT a FROM t1 WHERE b = 2 ); |
|
1086 |
SELECT a FROM t1 WHERE a = ANY ( SELECT a FROM t1 WHERE b = 2 ); |
|
1087 |
SELECT a FROM t1 WHERE a >= ANY ( SELECT a FROM t1 WHERE b = 2 ); |
|
1088 |
SELECT a FROM t1 WHERE a <= ANY ( SELECT a FROM t1 WHERE b = 2 ); |
|
1089 |
SELECT a FROM t1 WHERE a <> ANY ( SELECT a FROM t1 WHERE b = 2 ); |
|
1090 |
SELECT a FROM t1 WHERE a > ALL ( SELECT a FROM t1 WHERE b = 2 ); |
|
1091 |
SELECT a FROM t1 WHERE a < ALL ( SELECT a FROM t1 WHERE b = 2 ); |
|
1092 |
SELECT a FROM t1 WHERE a = ALL ( SELECT a FROM t1 WHERE b = 2 ); |
|
1093 |
SELECT a FROM t1 WHERE a >= ALL ( SELECT a FROM t1 WHERE b = 2 ); |
|
1094 |
SELECT a FROM t1 WHERE a <= ALL ( SELECT a FROM t1 WHERE b = 2 ); |
|
1095 |
SELECT a FROM t1 WHERE a <> ALL ( SELECT a FROM t1 WHERE b = 2 ); |
|
1096 |
# with index |
|
1097 |
ALTER TABLE t1 ADD INDEX (a); |
|
1098 |
SELECT a FROM t1 WHERE a > ANY ( SELECT a FROM t1 WHERE b = 2 ); |
|
1099 |
SELECT a FROM t1 WHERE a < ANY ( SELECT a FROM t1 WHERE b = 2 ); |
|
1100 |
SELECT a FROM t1 WHERE a = ANY ( SELECT a FROM t1 WHERE b = 2 ); |
|
1101 |
SELECT a FROM t1 WHERE a >= ANY ( SELECT a FROM t1 WHERE b = 2 ); |
|
1102 |
SELECT a FROM t1 WHERE a <= ANY ( SELECT a FROM t1 WHERE b = 2 ); |
|
1103 |
SELECT a FROM t1 WHERE a <> ANY ( SELECT a FROM t1 WHERE b = 2 ); |
|
1104 |
SELECT a FROM t1 WHERE a > ALL ( SELECT a FROM t1 WHERE b = 2 ); |
|
1105 |
SELECT a FROM t1 WHERE a < ALL ( SELECT a FROM t1 WHERE b = 2 ); |
|
1106 |
SELECT a FROM t1 WHERE a = ALL ( SELECT a FROM t1 WHERE b = 2 ); |
|
1107 |
SELECT a FROM t1 WHERE a >= ALL ( SELECT a FROM t1 WHERE b = 2 ); |
|
1108 |
SELECT a FROM t1 WHERE a <= ALL ( SELECT a FROM t1 WHERE b = 2 ); |
|
1109 |
SELECT a FROM t1 WHERE a <> ALL ( SELECT a FROM t1 WHERE b = 2 ); |
|
1110 |
# having clause test |
|
1111 |
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 HAVING a = 2); |
|
1112 |
SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 HAVING a = 2); |
|
1113 |
SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 HAVING a = 2); |
|
1114 |
SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 HAVING a = 2); |
|
1115 |
SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 HAVING a = 2); |
|
1116 |
SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 HAVING a = 2); |
|
1117 |
SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 HAVING a = 2); |
|
1118 |
SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 HAVING a = 2); |
|
1119 |
SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 HAVING a = 2); |
|
1120 |
SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 HAVING a = 2); |
|
1121 |
SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 HAVING a = 2); |
|
1122 |
SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 HAVING a = 2); |
|
1123 |
# union test |
|
1124 |
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2); |
|
1125 |
SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2); |
|
1126 |
SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2); |
|
1127 |
SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2); |
|
1128 |
SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2); |
|
1129 |
SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2); |
|
1130 |
SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2); |
|
1131 |
SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2); |
|
1132 |
SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2); |
|
1133 |
SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2); |
|
1134 |
SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2); |
|
1135 |
SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 WHERE b = 2 UNION SELECT a FROM t1 WHERE b = 2); |
|
1136 |
# union + having test |
|
1137 |
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2); |
|
1138 |
SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2); |
|
1139 |
SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2); |
|
1140 |
SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2); |
|
1141 |
SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2); |
|
1142 |
SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2); |
|
1143 |
SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2); |
|
1144 |
SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2); |
|
1145 |
SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2); |
|
1146 |
SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2); |
|
1147 |
SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2); |
|
1148 |
SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 HAVING a = 2 UNION SELECT a FROM t1 HAVING a = 2); |
|
1149 |
# row tests |
|
1150 |
# < > >= <= and = ALL/ <> ANY do not support row operation |
|
1151 |
-- error 1241 |
|
1152 |
SELECT a FROM t1 WHERE (1,2) > ANY (SELECT a FROM t1 WHERE b = 2); |
|
1153 |
-- error 1241 |
|
1154 |
SELECT a FROM t1 WHERE a > ANY (SELECT a,2 FROM t1 WHERE b = 2); |
|
1155 |
-- error 1241 |
|
1156 |
SELECT a FROM t1 WHERE (1,2) > ANY (SELECT a,2 FROM t1 WHERE b = 2); |
|
1157 |
-- error 1241 |
|
1158 |
SELECT a FROM t1 WHERE (1,2) > ALL (SELECT a FROM t1 WHERE b = 2); |
|
1159 |
-- error 1241 |
|
1160 |
SELECT a FROM t1 WHERE a > ALL (SELECT a,2 FROM t1 WHERE b = 2); |
|
1161 |
-- error 1241 |
|
1162 |
SELECT a FROM t1 WHERE (1,2) > ALL (SELECT a,2 FROM t1 WHERE b = 2); |
|
1163 |
-- error 1241 |
|
1164 |
SELECT a FROM t1 WHERE (1,2) = ALL (SELECT a,2 FROM t1 WHERE b = 2); |
|
1165 |
-- error 1241 |
|
1166 |
SELECT a FROM t1 WHERE (1,2) <> ANY (SELECT a,2 FROM t1 WHERE b = 2); |
|
1167 |
# following should be converted to IN |
|
1168 |
-- error 1241 |
|
1169 |
SELECT a FROM t1 WHERE (1,2) = ANY (SELECT a FROM t1 WHERE b = 2); |
|
1170 |
-- error 1241 |
|
1171 |
SELECT a FROM t1 WHERE a = ANY (SELECT a,2 FROM t1 WHERE b = 2); |
|
1172 |
SELECT a FROM t1 WHERE (1,2) = ANY (SELECT a,2 FROM t1 WHERE b = 2); |
|
1173 |
-- error 1241 |
|
1174 |
SELECT a FROM t1 WHERE (1,2) <> ALL (SELECT a FROM t1 WHERE b = 2); |
|
1175 |
-- error 1241 |
|
1176 |
SELECT a FROM t1 WHERE a <> ALL (SELECT a,2 FROM t1 WHERE b = 2); |
|
1177 |
SELECT a FROM t1 WHERE (1,2) <> ALL (SELECT a,2 FROM t1 WHERE b = 2); |
|
1178 |
SELECT a FROM t1 WHERE (a,1) = ANY (SELECT a,1 FROM t1 WHERE b = 2); |
|
1179 |
SELECT a FROM t1 WHERE (a,1) <> ALL (SELECT a,1 FROM t1 WHERE b = 2); |
|
1180 |
SELECT a FROM t1 WHERE (a,1) = ANY (SELECT a,1 FROM t1 HAVING a = 2); |
|
1181 |
SELECT a FROM t1 WHERE (a,1) <> ALL (SELECT a,1 FROM t1 HAVING a = 2); |
|
1182 |
SELECT a FROM t1 WHERE (a,1) = ANY (SELECT a,1 FROM t1 WHERE b = 2 UNION SELECT a,1 FROM t1 WHERE b = 2); |
|
1183 |
SELECT a FROM t1 WHERE (a,1) <> ALL (SELECT a,1 FROM t1 WHERE b = 2 UNION SELECT a,1 FROM t1 WHERE b = 2); |
|
1184 |
SELECT a FROM t1 WHERE (a,1) = ANY (SELECT a,1 FROM t1 HAVING a = 2 UNION SELECT a,1 FROM t1 HAVING a = 2); |
|
1185 |
SELECT a FROM t1 WHERE (a,1) <> ALL (SELECT a,1 FROM t1 HAVING a = 2 UNION SELECT a,1 FROM t1 HAVING a = 2); |
|
1186 |
# without optimisation |
|
1187 |
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = 2 group by a); |
|
1188 |
SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 WHERE b = 2 group by a); |
|
1189 |
SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 WHERE b = 2 group by a); |
|
1190 |
SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 WHERE b = 2 group by a); |
|
1191 |
SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 WHERE b = 2 group by a); |
|
1192 |
SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 WHERE b = 2 group by a); |
|
1193 |
SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 WHERE b = 2 group by a); |
|
1194 |
SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 WHERE b = 2 group by a); |
|
1195 |
SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 WHERE b = 2 group by a); |
|
1196 |
SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 WHERE b = 2 group by a); |
|
1197 |
SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 WHERE b = 2 group by a); |
|
1198 |
SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 WHERE b = 2 group by a); |
|
1199 |
# without optimisation + having |
|
1200 |
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 group by a HAVING a = 2); |
|
1201 |
SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 group by a HAVING a = 2); |
|
1202 |
SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 group by a HAVING a = 2); |
|
1203 |
SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 group by a HAVING a = 2); |
|
1204 |
SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 group by a HAVING a = 2); |
|
1205 |
SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 group by a HAVING a = 2); |
|
1206 |
SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 group by a HAVING a = 2); |
|
1207 |
SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 group by a HAVING a = 2); |
|
1208 |
SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 group by a HAVING a = 2); |
|
1209 |
SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 group by a HAVING a = 2); |
|
1210 |
SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 group by a HAVING a = 2); |
|
1211 |
SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 group by a HAVING a = 2); |
|
1212 |
# EXISTS in string contence |
|
1213 |
SELECT concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a > t1.a), '-') from t1 a; |
|
1214 |
SELECT concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a < t1.a), '-') from t1 a; |
|
1215 |
SELECT concat(EXISTS(SELECT a FROM t1 WHERE b = 2 and a.a = t1.a), '-') from t1 a; |
|
1216 |
DROP TABLE t1; |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1217 |
CREATE TABLE t1 ( a double, b double ) ENGINE=MyISAM; |
1
by brian
clean slate |
1218 |
INSERT INTO t1 VALUES (1,1),(2,2),(3,3); |
1219 |
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = 2e0); |
|
1220 |
SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 WHERE b = 2e0); |
|
1221 |
SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 WHERE b = 2e0); |
|
1222 |
SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 WHERE b = 2e0); |
|
1223 |
SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 WHERE b = 2e0); |
|
1224 |
SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 WHERE b = 2e0); |
|
1225 |
SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 WHERE b = 2e0); |
|
1226 |
SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 WHERE b = 2e0); |
|
1227 |
SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 WHERE b = 2e0); |
|
1228 |
SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 WHERE b = 2e0); |
|
1229 |
SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 WHERE b = 2e0); |
|
1230 |
SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 WHERE b = 2e0); |
|
1231 |
DROP TABLE t1; |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1232 |
CREATE TABLE t1 ( a char(1), b char(1)) ENGINE=MyISAM; |
1
by brian
clean slate |
1233 |
INSERT INTO t1 VALUES ('1','1'),('2','2'),('3','3'); |
1234 |
SELECT a FROM t1 WHERE a > ANY (SELECT a FROM t1 WHERE b = '2'); |
|
1235 |
SELECT a FROM t1 WHERE a < ANY (SELECT a FROM t1 WHERE b = '2'); |
|
1236 |
SELECT a FROM t1 WHERE a = ANY (SELECT a FROM t1 WHERE b = '2'); |
|
1237 |
SELECT a FROM t1 WHERE a >= ANY (SELECT a FROM t1 WHERE b = '2'); |
|
1238 |
SELECT a FROM t1 WHERE a <= ANY (SELECT a FROM t1 WHERE b = '2'); |
|
1239 |
SELECT a FROM t1 WHERE a <> ANY (SELECT a FROM t1 WHERE b = '2'); |
|
1240 |
SELECT a FROM t1 WHERE a > ALL (SELECT a FROM t1 WHERE b = '2'); |
|
1241 |
SELECT a FROM t1 WHERE a < ALL (SELECT a FROM t1 WHERE b = '2'); |
|
1242 |
SELECT a FROM t1 WHERE a = ALL (SELECT a FROM t1 WHERE b = '2'); |
|
1243 |
SELECT a FROM t1 WHERE a >= ALL (SELECT a FROM t1 WHERE b = '2'); |
|
1244 |
SELECT a FROM t1 WHERE a <= ALL (SELECT a FROM t1 WHERE b = '2'); |
|
1245 |
SELECT a FROM t1 WHERE a <> ALL (SELECT a FROM t1 WHERE b = '2'); |
|
1246 |
DROP TABLE t1; |
|
1247 |
||
1248 |
||
1249 |
# |
|
1250 |
# SELECT(EXISTS * ...)optimisation |
|
1251 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1252 |
create table t1 (a int, b int) ENGINE=MyISAM; |
1
by brian
clean slate |
1253 |
insert into t1 values (1,2),(3,4); |
1254 |
select * from t1 up where exists (select * from t1 where t1.a=up.a); |
|
1255 |
explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a); |
|
1256 |
drop table t1; |
|
1257 |
||
1258 |
# |
|
1259 |
# Bug #4102: subselect in HAVING |
|
1260 |
# |
|
1261 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1262 |
CREATE TABLE t1 (t1_a int) ENGINE=MyISAM; |
1
by brian
clean slate |
1263 |
INSERT INTO t1 VALUES (1); |
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1264 |
CREATE TABLE t2 (t2_a int, t2_b int, PRIMARY KEY (t2_a, t2_b)) ENGINE=MyISAM; |
1
by brian
clean slate |
1265 |
INSERT INTO t2 VALUES (1, 1), (1, 2); |
1266 |
SELECT * FROM t1, t2 table2 WHERE t1_a = 1 AND table2.t2_a = 1 |
|
1267 |
HAVING table2.t2_b = (SELECT MAX(t2_b) FROM t2 WHERE t2_a = table2.t2_a); |
|
1268 |
DROP TABLE t1, t2; |
|
1269 |
||
1270 |
# |
|
1271 |
# Test problem with NULL and derived tables (Bug #4097) |
|
1272 |
# |
|
1273 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1274 |
CREATE TABLE t1 (id int default NULL,name varchar(10) default NULL) ENGINE=MyISAM; |
1
by brian
clean slate |
1275 |
INSERT INTO t1 VALUES (1,'Tim'),(2,'Rebecca'),(3,NULL); |
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1276 |
CREATE TABLE t2 (id int default NULL, pet varchar(10) default NULL) ENGINE=MyISAM; |
1
by brian
clean slate |
1277 |
INSERT INTO t2 VALUES (1,'Fido'),(2,'Spot'),(3,'Felix'); |
1278 |
SELECT a.*, b.* FROM (SELECT * FROM t1) AS a JOIN t2 as b on a.id=b.id; |
|
1279 |
drop table t1,t2; |
|
1280 |
||
1281 |
# |
|
1282 |
# Aggregate function comparation with ALL/ANY/SOME subselect |
|
1283 |
# |
|
377.1.4
by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one |
1284 |
CREATE TABLE `t1` ( `a` int default NULL) ENGINE=MyISAM; |
1
by brian
clean slate |
1285 |
insert into t1 values (1); |
377.1.4
by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one |
1286 |
CREATE TABLE `t2` ( `b` int default NULL, `a` int default NULL) ENGINE=MyISAM; |
1
by brian
clean slate |
1287 |
insert into t2 values (1,2); |
1288 |
select t000.a, count(*) `C` FROM t1 t000 GROUP BY t000.a HAVING count(*) > ALL (SELECT count(*) FROM t2 t001 WHERE t001.a=1); |
|
1289 |
drop table t1,t2; |
|
1290 |
||
1291 |
# |
|
1292 |
# BUG#5003 - like in subselect |
|
1293 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1294 |
CREATE TABLE t1(`IZAVORGANG_ID` VARCHAR(11) COLLATE utf8_bin,`KUERZEL` VARCHAR(10) COLLATE utf8_bin,`IZAANALYSEART_ID` VARCHAR(11) COLLATE utf8_bin,`IZAPMKZ_ID` VARCHAR(11) COLLATE utf8_bin) ENGINE=MyISAM; |
1
by brian
clean slate |
1295 |
CREATE INDEX AK01IZAVORGANG ON t1(izaAnalyseart_id,Kuerzel); |
1296 |
INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000001','601','D0000000001','I0000000001'); |
|
1297 |
INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000002','602','D0000000001','I0000000001'); |
|
1298 |
INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000003','603','D0000000001','I0000000001'); |
|
1299 |
INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000004','101','D0000000001','I0000000001'); |
|
1300 |
SELECT `IZAVORGANG_ID` FROM t1 WHERE `KUERZEL` IN(SELECT MIN(`KUERZEL`)`Feld1` FROM t1 WHERE `KUERZEL` LIKE'601%'And`IZAANALYSEART_ID`='D0000000001'); |
|
1301 |
drop table t1; |
|
1302 |
||
1303 |
# |
|
1304 |
# Optimized IN with compound index |
|
1305 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1306 |
CREATE TABLE `t1` ( `aid` int NOT NULL default '0', `bid` int NOT NULL default '0', PRIMARY KEY (`aid`,`bid`)) ENGINE=MyISAM; |
1307 |
CREATE TABLE `t2` ( `aid` int NOT NULL default '0', `bid` int NOT NULL default '0', PRIMARY KEY (`aid`,`bid`)) ENGINE=MyISAM; |
|
1
by brian
clean slate |
1308 |
insert into t1 values (1,1),(1,2),(2,1),(2,2); |
1309 |
insert into t2 values (1,2),(2,2); |
|
1310 |
select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid); |
|
1311 |
alter table t2 drop primary key; |
|
1312 |
alter table t2 add key KEY1 (aid, bid); |
|
1313 |
select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid); |
|
1314 |
alter table t2 drop key KEY1; |
|
1315 |
alter table t2 add primary key (bid, aid); |
|
1316 |
select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid); |
|
1317 |
drop table t1,t2; |
|
1318 |
||
1319 |
# |
|
1320 |
# resolving fields of grouped outer SELECT |
|
1321 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1322 |
CREATE TABLE t1 (howmanyvalues bigint, avalue int) ENGINE=MyISAM; |
1
by brian
clean slate |
1323 |
INSERT INTO t1 VALUES (1, 1),(2, 1),(2, 2),(3, 1),(3, 2),(3, 3),(4, 1),(4, 2),(4, 3),(4, 4); |
1324 |
SELECT howmanyvalues, count(*) from t1 group by howmanyvalues; |
|
1325 |
SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.howmanyvalues) as mycount from t1 a group by a.howmanyvalues; |
|
1326 |
CREATE INDEX t1_howmanyvalues_idx ON t1 (howmanyvalues); |
|
1327 |
SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues+1 = a.howmanyvalues+1) as mycount from t1 a group by a.howmanyvalues; |
|
1328 |
SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.howmanyvalues) as mycount from t1 a group by a.howmanyvalues; |
|
1329 |
SELECT a.howmanyvalues, (SELECT count(*) from t1 b where b.howmanyvalues = a.avalue) as mycount from t1 a group by a.howmanyvalues; |
|
1330 |
drop table t1; |
|
1331 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1332 |
create table t1 (x int) ENGINE=MyISAM; |
1
by brian
clean slate |
1333 |
select (select b.x from t1 as b where b.x=a.x) from t1 as a where a.x=2 group by a.x; |
1334 |
drop table t1; |
|
1335 |
||
1336 |
# |
|
1337 |
# Test of correct maybe_null flag returning by subquwery for temporary table |
|
1338 |
# creation |
|
1339 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1340 |
CREATE TABLE `t1` ( `master` int NOT NULL default '0', `map` int NOT NULL default '0', `slave` int NOT NULL default '0', `access` int NOT NULL default '0', UNIQUE KEY `access_u` (`master`,`map`,`slave`)) ENGINE=MyISAM; |
1
by brian
clean slate |
1341 |
INSERT INTO `t1` VALUES (1,0,0,700),(1,1,1,400),(1,5,5,400),(1,12,12,400),(1,12,32,400),(4,12,32,400); |
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1342 |
CREATE TABLE `t2` ( `id` int NOT NULL default '0', `pid` int NOT NULL default '0', `map` int NOT NULL default '0', `level` int NOT NULL default '0', `title` varchar(255) default NULL, PRIMARY KEY (`id`,`pid`,`map`), KEY `level` (`level`), KEY `id` (`id`,`map`)) ENGINE=MyISAM ; |
1
by brian
clean slate |
1343 |
INSERT INTO `t2` VALUES (6,5,12,7,'a'),(12,0,0,7,'a'),(12,1,0,7,'a'),(12,5,5,7,'a'),(12,5,12,7,'a'); |
1344 |
-- error 1054 |
|
1345 |
SELECT b.sc FROM (SELECT (SELECT a.access FROM t1 a WHERE a.map = op.map AND a.slave = op.pid AND a.master = 1) ac FROM t2 op WHERE op.id = 12 AND op.map = 0) b; |
|
1346 |
SELECT b.ac FROM (SELECT (SELECT a.access FROM t1 a WHERE a.map = op.map AND a.slave = op.pid AND a.master = 1) ac FROM t2 op WHERE op.id = 12 AND op.map = 0) b; |
|
1347 |
drop tables t1,t2; |
|
1348 |
||
1349 |
# |
|
1350 |
# Subselect in non-select command just after connection |
|
1351 |
# |
|
1352 |
connect (root,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK); |
|
1353 |
connection root; |
|
1354 |
set @got_val= (SELECT 1 FROM (SELECT 'A' as my_col) as T1 ) ; |
|
1355 |
||
1356 |
# |
|
1357 |
# primary query with temporary table and subquery with groupping |
|
1358 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1359 |
create table t1 (a int, b int) ENGINE=MyISAM; |
1360 |
create table t2 (a int, b int) ENGINE=MyISAM; |
|
1
by brian
clean slate |
1361 |
insert into t1 values (1,1),(1,2),(1,3),(2,4),(2,5); |
1362 |
insert into t2 values (1,3),(2,1); |
|
1363 |
select distinct a,b, (select max(b) from t2 where t1.b=t2.a) from t1 order by t1.b; |
|
1364 |
drop table t1, t2; |
|
1365 |
||
1366 |
# |
|
1367 |
# Equal operation under row and empty subquery |
|
1368 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1369 |
create table t1 (s1 int,s2 int) ENGINE=MyISAM; |
1
by brian
clean slate |
1370 |
insert into t1 values (20,15); |
1371 |
select * from t1 where (('a',null) <=> (select 'a',s2 from t1 where s1 = 0)); |
|
1372 |
drop table t1; |
|
1373 |
||
1374 |
# |
|
1375 |
# ALL/ANY with NULL |
|
1376 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1377 |
create table t1 (s1 int) ENGINE=MyISAM; |
1
by brian
clean slate |
1378 |
insert into t1 values (1),(null); |
1379 |
select * from t1 where s1 < all (select s1 from t1); |
|
1380 |
select s1, s1 < all (select s1 from t1) from t1; |
|
1381 |
drop table t1; |
|
1382 |
||
1383 |
# |
|
1384 |
# reference on changable fields from subquery |
|
1385 |
# |
|
1386 |
CREATE TABLE t1 ( |
|
1387 |
Code char(3) NOT NULL default '', |
|
1388 |
Name char(52) NOT NULL default '', |
|
1389 |
Continent enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL default 'Asia', |
|
1390 |
Region char(26) NOT NULL default '', |
|
1391 |
SurfaceArea float(10,2) NOT NULL default '0.00', |
|
396
by Brian Aker
Cleanup tiny and small int. |
1392 |
IndepYear int default NULL, |
223
by Brian Aker
Cleanup int() work. |
1393 |
Population int NOT NULL default '0', |
1
by brian
clean slate |
1394 |
LifeExpectancy float(3,1) default NULL, |
1395 |
GNP float(10,2) default NULL, |
|
1396 |
GNPOld float(10,2) default NULL, |
|
1397 |
LocalName char(45) NOT NULL default '', |
|
1398 |
GovernmentForm char(45) NOT NULL default '', |
|
1399 |
HeadOfState char(60) default NULL, |
|
223
by Brian Aker
Cleanup int() work. |
1400 |
Capital int default NULL, |
1
by brian
clean slate |
1401 |
Code2 char(2) NOT NULL default '' |
1402 |
) ENGINE=MyISAM; |
|
1403 |
INSERT INTO t1 VALUES ('XXX','Xxxxx','Oceania','Xxxxxx',26.00,0,0,0,0,0,'Xxxxx','Xxxxx','Xxxxx',NULL,'XX'); |
|
1404 |
INSERT INTO t1 VALUES ('ASM','American Samoa','Oceania','Polynesia',199.00,0,68000,75.1,334.00,NULL,'Amerika Samoa','US Territory','George W. Bush',54,'AS'); |
|
1405 |
INSERT INTO t1 VALUES ('ATF','French Southern territories','Antarctica','Antarctica',7780.00,0,0,NULL,0.00,NULL,'Terres australes françaises','Nonmetropolitan Territory of France','Jacques Chirac',NULL,'TF'); |
|
1406 |
INSERT INTO t1 VALUES ('UMI','United States Minor Outlying Islands','Oceania','Micronesia/Caribbean',16.00,0,0,NULL,0.00,NULL,'United States Minor Outlying Islands','Dependent Territory of the US','George W. Bush',NULL,'UM'); |
|
1407 |
/*!40000 ALTER TABLE t1 ENABLE KEYS */; |
|
1408 |
SELECT DISTINCT Continent AS c FROM t1 outr WHERE |
|
1409 |
Code <> SOME ( SELECT Code FROM t1 WHERE Continent = outr.Continent AND |
|
1410 |
Population < 200); |
|
1411 |
drop table t1; |
|
1412 |
||
1413 |
# |
|
1414 |
# Test for BUG#7885: Server crash when 'any' subselect compared to |
|
1415 |
# non-existant field. |
|
1416 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1417 |
create table t1 (a1 int) ENGINE=MyISAM; |
1418 |
create table t2 (b1 int) ENGINE=MyISAM; |
|
1
by brian
clean slate |
1419 |
--error 1054 |
1420 |
select * from t1 where a2 > any(select b1 from t2); |
|
1421 |
select * from t1 where a1 > any(select b1 from t2); |
|
1422 |
drop table t1,t2; |
|
1423 |
||
1424 |
||
1425 |
# |
|
1426 |
# Comparison subquery with * and row |
|
1427 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1428 |
create table t1 (a integer, b integer) ENGINE=MyISAM; |
1
by brian
clean slate |
1429 |
select (select * from t1) = (select 1,2); |
1430 |
select (select 1,2) = (select * from t1); |
|
1431 |
# queries whih can be converted to IN |
|
1432 |
select row(1,2) = ANY (select * from t1); |
|
1433 |
select row(1,2) != ALL (select * from t1); |
|
1434 |
drop table t1; |
|
1435 |
||
1436 |
# |
|
1437 |
# Comparison subquery and row with nested rows |
|
1438 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1439 |
create table t1 (a integer, b integer) ENGINE=MyISAM; |
1
by brian
clean slate |
1440 |
-- error 1241 |
1441 |
select row(1,(2,2)) in (select * from t1 ); |
|
1442 |
-- error 1241 |
|
1443 |
select row(1,(2,2)) = (select * from t1 ); |
|
1444 |
-- error 1241 |
|
1445 |
select (select * from t1) = row(1,(2,2)); |
|
1446 |
drop table t1; |
|
1447 |
||
1448 |
# |
|
1449 |
# Forward reference detection |
|
1450 |
# |
|
1451 |
create table t1 (a integer); |
|
1452 |
insert into t1 values (1); |
|
1453 |
-- error 1247 |
|
1454 |
select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx ; |
|
1455 |
-- error 1247 |
|
1456 |
select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx; |
|
1457 |
select 1 as xx, 1 = ALL ( select 1 from t1 where 1 = xx ); |
|
1458 |
-- error 1247 |
|
1459 |
select 1 = ALL (select 1 from t1 where 1 = xx ), 1 as xx; |
|
1460 |
drop table t1; |
|
1461 |
||
1462 |
# |
|
1463 |
# Test for BUG#8218 |
|
1464 |
# |
|
1465 |
CREATE TABLE t1 ( |
|
223
by Brian Aker
Cleanup int() work. |
1466 |
categoryId int NOT NULL, |
1467 |
courseId int NOT NULL, |
|
1
by brian
clean slate |
1468 |
startDate datetime NOT NULL, |
1469 |
endDate datetime NOT NULL, |
|
1470 |
createDate datetime NOT NULL, |
|
1471 |
modifyDate timestamp NOT NULL, |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1472 |
attributes text NOT NULL) |
1473 |
engine=myisam; |
|
1474 |
||
1
by brian
clean slate |
1475 |
INSERT INTO t1 VALUES (1,41,'2004-02-09','2010-01-01','2004-02-09','2004-02-09',''), |
1476 |
(1,86,'2004-08-16','2004-08-16','2004-08-16','2004-08-16',''), |
|
1477 |
(1,87,'2004-08-16','2004-08-16','2004-08-16','2004-08-16',''), |
|
1478 |
(2,52,'2004-03-15','2004-10-01','2004-03-15','2004-09-17',''), |
|
1479 |
(2,53,'2004-03-16','2004-10-01','2004-03-16','2004-09-17',''), |
|
1480 |
(2,88,'2004-08-16','2004-08-16','2004-08-16','2004-08-16',''), |
|
1481 |
(2,89,'2004-08-16','2004-08-16','2004-08-16','2004-08-16',''), |
|
1482 |
(3,51,'2004-02-09','2010-01-01','2004-02-09','2004-02-09',''), |
|
1483 |
(5,12,'2004-02-18','2010-01-01','2004-02-18','2004-02-18',''); |
|
1484 |
||
1485 |
CREATE TABLE t2 ( |
|
223
by Brian Aker
Cleanup int() work. |
1486 |
userId int NOT NULL, |
1487 |
courseId int NOT NULL, |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1488 |
date datetime NOT NULL) |
1489 |
engine=myisam; |
|
1490 |
||
1
by brian
clean slate |
1491 |
INSERT INTO t2 VALUES (5141,71,'2003-11-18'), |
1492 |
(5141,72,'2003-11-25'),(5141,41,'2004-08-06'), |
|
1493 |
(5141,52,'2004-08-06'),(5141,53,'2004-08-06'), |
|
1494 |
(5141,12,'2004-08-06'),(5141,86,'2004-10-21'), |
|
1495 |
(5141,87,'2004-10-21'),(5141,88,'2004-10-21'), |
|
1496 |
(5141,89,'2004-10-22'),(5141,51,'2004-10-26'); |
|
1497 |
||
1498 |
||
1499 |
CREATE TABLE t3 ( |
|
223
by Brian Aker
Cleanup int() work. |
1500 |
groupId int NOT NULL, |
1501 |
parentId int NOT NULL, |
|
1
by brian
clean slate |
1502 |
startDate datetime NOT NULL, |
1503 |
endDate datetime NOT NULL, |
|
1504 |
createDate datetime NOT NULL, |
|
1505 |
modifyDate timestamp NOT NULL, |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1506 |
ordering int) |
1507 |
engine=myisam; |
|
1508 |
||
1
by brian
clean slate |
1509 |
INSERT INTO t3 VALUES (12,9,'1000-01-01','3999-12-31','2004-01-29','2004-01-29',NULL); |
1510 |
||
1511 |
CREATE TABLE t4 ( |
|
223
by Brian Aker
Cleanup int() work. |
1512 |
id int NOT NULL, |
1513 |
groupTypeId int NOT NULL, |
|
1
by brian
clean slate |
1514 |
groupKey varchar(50) NOT NULL, |
1515 |
name text, |
|
223
by Brian Aker
Cleanup int() work. |
1516 |
ordering int, |
1
by brian
clean slate |
1517 |
description text, |
1518 |
createDate datetime NOT NULL, |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1519 |
modifyDate timestamp NOT NULL) |
1520 |
engine=myisam; |
|
1521 |
||
1
by brian
clean slate |
1522 |
INSERT INTO t4 VALUES (9,5,'stationer','stationer',0,'Stationer','2004-01-29','2004-01-29'), |
1523 |
(12,5,'group2','group2',0,'group2','2004-01-29','2004-01-29'); |
|
1524 |
||
1525 |
CREATE TABLE t5 ( |
|
223
by Brian Aker
Cleanup int() work. |
1526 |
userId int NOT NULL, |
1527 |
groupId int NOT NULL, |
|
1
by brian
clean slate |
1528 |
createDate datetime NOT NULL, |
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1529 |
modifyDate timestamp NOT NULL) ENGINE=MyISAM; |
1530 |
||
1
by brian
clean slate |
1531 |
INSERT INTO t5 VALUES (5141,12,'2004-08-06','2004-08-06'); |
1532 |
||
1533 |
select |
|
1534 |
count(distinct t2.userid) pass, |
|
1535 |
groupstuff.*, |
|
1536 |
count(t2.courseid) crse, |
|
1537 |
t1.categoryid, |
|
1538 |
t2.courseid, |
|
1539 |
date_format(date, '%b%y') as colhead |
|
1540 |
from t2 |
|
1541 |
join t1 on t2.courseid=t1.courseid |
|
1542 |
join |
|
1543 |
( |
|
1544 |
select |
|
1545 |
t5.userid, |
|
1546 |
parentid, |
|
1547 |
parentgroup, |
|
1548 |
childid, |
|
1549 |
groupname, |
|
1550 |
grouptypeid |
|
1551 |
from t5 |
|
1552 |
join |
|
1553 |
( |
|
1554 |
select t4.id as parentid, |
|
1555 |
t4.name as parentgroup, |
|
1556 |
t4.id as childid, |
|
1557 |
t4.name as groupname, |
|
1558 |
t4.grouptypeid |
|
1559 |
from t4 |
|
1560 |
) as gin on t5.groupid=gin.childid |
|
1561 |
) as groupstuff on t2.userid = groupstuff.userid |
|
1562 |
group by |
|
1563 |
groupstuff.groupname, colhead , t2.courseid; |
|
1564 |
||
1565 |
drop table t1, t2, t3, t4, t5; |
|
1566 |
||
1567 |
# |
|
1568 |
# Transformation in left expression of subquery (BUG#8888) |
|
1569 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1570 |
create table t1 (a int) ENGINE=MyISAM; |
1
by brian
clean slate |
1571 |
insert into t1 values (1), (2), (3); |
1572 |
SELECT 1 FROM t1 WHERE (SELECT 1) in (SELECT 1); |
|
1573 |
drop table t1; |
|
1574 |
||
1575 |
# |
|
1576 |
# single row subqueries and row operations (code covarage improvement) |
|
1577 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1578 |
create table t1 (a int, b int) ENGINE=MyISAM; |
1
by brian
clean slate |
1579 |
insert into t1 values (1,2); |
1580 |
-- error 1241 |
|
1581 |
select 1 = (select * from t1); |
|
1582 |
-- error 1241 |
|
1583 |
select (select * from t1) = 1; |
|
1584 |
-- error 1241 |
|
1585 |
select (1,2) = (select a from t1); |
|
1586 |
-- error 1241 |
|
1587 |
select (select a from t1) = (1,2); |
|
1588 |
-- error 1241 |
|
1589 |
select (1,2,3) = (select * from t1); |
|
1590 |
-- error 1241 |
|
1591 |
select (select * from t1) = (1,2,3); |
|
1592 |
drop table t1; |
|
1593 |
||
1594 |
# |
|
1595 |
# Item_int_with_ref check (BUG#10020) |
|
1596 |
# |
|
383.1.10
by Brian Aker
More cleanup/test fixup around utf8 |
1597 |
#CREATE TABLE `t1` ( |
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
1598 |
# `itemid` bigint NOT NULL auto_increment, |
1599 |
# `sessionid` bigint default NULL, |
|
1600 |
# `time` int NOT NULL default '0', |
|
383.1.10
by Brian Aker
More cleanup/test fixup around utf8 |
1601 |
# `data` text collate latin1_general_ci NOT NULL, |
1602 |
# PRIMARY KEY (`itemid`) |
|
1603 |
#); |
|
1604 |
#INSERT INTO `t1` VALUES (1, 1, 1, ''); |
|
1605 |
#CREATE TABLE `t2` ( |
|
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
1606 |
# `sessionid` bigint NOT NULL auto_increment, |
1607 |
# `pid` int NOT NULL default '0', |
|
1608 |
# `date` int NOT NULL default '0', |
|
383.1.10
by Brian Aker
More cleanup/test fixup around utf8 |
1609 |
# `ip` varchar(15) collate latin1_general_ci NOT NULL default '', |
1610 |
# PRIMARY KEY (`sessionid`) |
|
1611 |
#); |
|
1612 |
#INSERT INTO `t2` VALUES (1, 1, 1, '10.10.10.1'); |
|
1613 |
#SELECT s.ip, count( e.itemid ) FROM `t1` e JOIN t2 s ON s.sessionid = e.sessionid WHERE e.sessionid = ( SELECT sessionid FROM t2 ORDER BY sessionid DESC LIMIT 1 ) GROUP BY s.ip HAVING count( e.itemid ) >0 LIMIT 0 , 30; |
|
1614 |
#drop tables t1,t2; |
|
1
by brian
clean slate |
1615 |
|
1616 |
# BUG#11821 : Select from subselect using aggregate function on an enum |
|
1617 |
# segfaults: |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1618 |
create table t1 (fld enum('0','1')) ENGINE=MyISAM; |
1
by brian
clean slate |
1619 |
insert into t1 values ('1'); |
1620 |
select * from (select max(fld) from t1) as foo; |
|
1621 |
drop table t1; |
|
1622 |
||
1623 |
# |
|
1624 |
# Bug #11867: queries with ROW(,elems>) IN (SELECT DISTINCT <cols> FROM ...) |
|
1625 |
# |
|
1626 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1627 |
CREATE TABLE t1 (one int, two int, flag char(1)) ENGINE=MyISAM; |
1628 |
CREATE TABLE t2 (one int, two int, flag char(1)) ENGINE=MyISAM; |
|
1
by brian
clean slate |
1629 |
INSERT INTO t1 VALUES(1,2,'Y'),(2,3,'Y'),(3,4,'Y'),(5,6,'N'),(7,8,'N'); |
1630 |
INSERT INTO t2 VALUES(1,2,'Y'),(2,3,'Y'),(3,4,'Y'),(5,6,'N'),(7,8,'N'); |
|
1631 |
||
1632 |
SELECT * FROM t1 |
|
1633 |
WHERE ROW(one,two) IN (SELECT DISTINCT one,two FROM t2 WHERE flag = 'N'); |
|
1634 |
SELECT * FROM t1 |
|
1635 |
WHERE ROW(one,two) IN (SELECT DISTINCT one,two FROM t1 WHERE flag = 'N'); |
|
1636 |
||
1637 |
insert into t2 values (null,null,'N'); |
|
1638 |
insert into t2 values (null,3,'0'); |
|
1639 |
insert into t2 values (null,5,'0'); |
|
1640 |
insert into t2 values (10,null,'0'); |
|
1641 |
insert into t1 values (10,3,'0'); |
|
1642 |
insert into t1 values (10,5,'0'); |
|
1643 |
insert into t1 values (10,10,'0'); |
|
1644 |
SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N') as 'test' from t1; |
|
1645 |
SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N'); |
|
1646 |
SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N' group by one,two) as 'test' from t1; |
|
1647 |
SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0') as 'test' from t1; |
|
1648 |
SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0' group by one,two) as 'test' from t1; |
|
1649 |
explain extended SELECT one,two,ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = '0') as 'test' from t1; |
|
1650 |
explain extended SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N'); |
|
1651 |
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; |
|
1652 |
DROP TABLE t1,t2; |
|
1653 |
||
1654 |
# |
|
1655 |
# Bug #12392: where cond with IN predicate for rows and NULL values in table |
|
1656 |
# |
|
1657 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1658 |
CREATE TABLE t1 (a char(5), b char(5)) ENGINE=MyISAM; |
1
by brian
clean slate |
1659 |
INSERT INTO t1 VALUES (NULL,'aaa'), ('aaa','aaa'); |
1660 |
||
1661 |
SELECT * FROM t1 WHERE (a,b) IN (('aaa','aaa'), ('aaa','bbb')); |
|
1662 |
||
1663 |
DROP TABLE t1; |
|
1664 |
||
1665 |
# |
|
1666 |
# Bug #11479: subquery over left join with an empty inner table |
|
1667 |
# |
|
1668 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1669 |
CREATE TABLE t1 (a int) ENGINE=MyISAM; |
1670 |
CREATE TABLE t2 (a int, b int) ENGINE=MyISAM; |
|
1671 |
CREATE TABLE t3 (b int NOT NULL) ENGINE=MyISAM; |
|
1
by brian
clean slate |
1672 |
INSERT INTO t1 VALUES (1), (2), (3), (4); |
1673 |
INSERT INTO t2 VALUES (1,10), (3,30); |
|
1674 |
||
1675 |
SELECT * FROM t2 LEFT JOIN t3 ON t2.b=t3.b |
|
1676 |
WHERE t3.b IS NOT NULL OR t2.a > 10; |
|
1677 |
SELECT * FROM t1 |
|
1678 |
WHERE t1.a NOT IN (SELECT a FROM t2 LEFT JOIN t3 ON t2.b=t3.b |
|
1679 |
WHERE t3.b IS NOT NULL OR t2.a > 10); |
|
1680 |
||
1681 |
DROP TABLE t1,t2,t3; |
|
1682 |
||
1683 |
# |
|
1684 |
# Bug#18503: Queries with a quantified subquery returning empty set may |
|
1685 |
# return a wrong result. |
|
1686 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1687 |
CREATE TABLE t1 (f1 INT) ENGINE=MyISAM; |
1688 |
CREATE TABLE t2 (f2 INT) ENGINE=MyISAM; |
|
1
by brian
clean slate |
1689 |
INSERT INTO t1 VALUES (1); |
1690 |
SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2); |
|
1691 |
SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2 WHERE 1=0); |
|
1692 |
INSERT INTO t2 VALUES (1); |
|
1693 |
INSERT INTO t2 VALUES (2); |
|
1694 |
SELECT * FROM t1 WHERE f1 > ALL (SELECT f2 FROM t2 WHERE f2=0); |
|
1695 |
DROP TABLE t1, t2; |
|
1696 |
||
1697 |
# BUG#20975 Wrong query results for subqueries within NOT |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1698 |
create table t1 (s1 char) ENGINE=MyISAM; |
1
by brian
clean slate |
1699 |
insert into t1 values (1),(2); |
1700 |
||
1701 |
select * from t1 where (s1 < any (select s1 from t1)); |
|
1702 |
select * from t1 where not (s1 < any (select s1 from t1)); |
|
1703 |
||
1704 |
select * from t1 where (s1 < ALL (select s1+1 from t1)); |
|
1705 |
select * from t1 where not(s1 < ALL (select s1+1 from t1)); |
|
1706 |
||
1707 |
select * from t1 where (s1+1 = ANY (select s1 from t1)); |
|
1708 |
select * from t1 where NOT(s1+1 = ANY (select s1 from t1)); |
|
1709 |
||
1710 |
select * from t1 where (s1 = ALL (select s1/s1 from t1)); |
|
1711 |
select * from t1 where NOT(s1 = ALL (select s1/s1 from t1)); |
|
1712 |
drop table t1; |
|
1713 |
||
1714 |
# |
|
1715 |
# Bug #16255: Subquery in where |
|
1716 |
# |
|
1717 |
create table t1 ( |
|
1718 |
retailerID varchar(8) NOT NULL, |
|
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
1719 |
statusID int NOT NULL, |
1
by brian
clean slate |
1720 |
changed datetime NOT NULL, |
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1721 |
UNIQUE KEY retailerID (retailerID, statusID, changed)) |
1722 |
ENGINE=MyISAM; |
|
1
by brian
clean slate |
1723 |
|
1724 |
INSERT INTO t1 VALUES("0026", "1", "2005-12-06 12:18:56"); |
|
1725 |
INSERT INTO t1 VALUES("0026", "2", "2006-01-06 12:25:53"); |
|
1726 |
INSERT INTO t1 VALUES("0037", "1", "2005-12-06 12:18:56"); |
|
1727 |
INSERT INTO t1 VALUES("0037", "2", "2006-01-06 12:25:53"); |
|
1728 |
INSERT INTO t1 VALUES("0048", "1", "2006-01-06 12:37:50"); |
|
1729 |
INSERT INTO t1 VALUES("0059", "1", "2006-01-06 12:37:50"); |
|
1730 |
||
1731 |
select * from t1 r1 |
|
1732 |
where (r1.retailerID,(r1.changed)) in |
|
1733 |
(SELECT r2.retailerId,(max(changed)) from t1 r2 |
|
1734 |
group by r2.retailerId); |
|
1735 |
drop table t1; |
|
1736 |
||
1737 |
# |
|
1738 |
# Bug #21180: Subselect with index for both WHERE and ORDER BY |
|
1739 |
# produces empty result |
|
1740 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1741 |
create table t1(a int, primary key (a)) ENGINE=MyISAM; |
1
by brian
clean slate |
1742 |
insert into t1 values (10); |
1743 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1744 |
create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b)) ENGINE=MyISAM; |
1
by brian
clean slate |
1745 |
insert into t2(a, c, b) values (1,10,'359'), (2,10,'35988'), (3,10,'35989'); |
1746 |
||
1747 |
explain SELECT t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r |
|
1748 |
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' |
|
1749 |
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; |
|
1750 |
SELECT t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r |
|
1751 |
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' |
|
1752 |
ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; |
|
1753 |
||
1754 |
explain SELECT t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r |
|
1755 |
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' |
|
1756 |
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; |
|
1757 |
SELECT t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r |
|
1758 |
ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' |
|
1759 |
ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; |
|
1760 |
||
1761 |
drop table t1,t2; |
|
1762 |
||
1763 |
# |
|
1764 |
# Bug #21853: assert failure for a grouping query with |
|
1765 |
# an ALL/ANY quantified subquery in HAVING |
|
1766 |
# |
|
1767 |
||
1768 |
CREATE TABLE t1 ( |
|
1769 |
field1 int NOT NULL, |
|
1770 |
field2 int NOT NULL, |
|
1771 |
field3 int NOT NULL, |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1772 |
PRIMARY KEY (field1,field2,field3)) |
1773 |
ENGINE=MyISAM; |
|
1774 |
||
1
by brian
clean slate |
1775 |
CREATE TABLE t2 ( |
1776 |
fieldA int NOT NULL, |
|
1777 |
fieldB int NOT NULL, |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1778 |
PRIMARY KEY (fieldA,fieldB)) |
1779 |
ENGINE=MyISAM; |
|
1
by brian
clean slate |
1780 |
|
1781 |
INSERT INTO t1 VALUES |
|
1782 |
(1,1,1), (1,1,2), (1,2,1), (1,2,2), (1,2,3), (1,3,1); |
|
1783 |
INSERT INTO t2 VALUES (1,1), (1,2), (1,3); |
|
1784 |
||
1785 |
SELECT field1, field2, COUNT(*) |
|
1786 |
FROM t1 GROUP BY field1, field2; |
|
1787 |
||
1788 |
SELECT field1, field2 |
|
1789 |
FROM t1 |
|
1790 |
GROUP BY field1, field2 |
|
1791 |
HAVING COUNT(*) >= ALL (SELECT fieldB |
|
1792 |
FROM t2 WHERE fieldA = field1); |
|
1793 |
SELECT field1, field2 |
|
1794 |
FROM t1 |
|
1795 |
GROUP BY field1, field2 |
|
1796 |
HAVING COUNT(*) < ANY (SELECT fieldB |
|
1797 |
FROM t2 WHERE fieldA = field1); |
|
1798 |
||
1799 |
DROP TABLE t1, t2; |
|
1800 |
||
1801 |
# |
|
1802 |
# Bug #23478: not top-level IN subquery returning a non-empty result set |
|
1803 |
# with possible NULL values by index access from the outer query |
|
1804 |
# |
|
1805 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1806 |
CREATE TABLE t1(a int, INDEX (a)) ENGINE=MyISAM; |
1
by brian
clean slate |
1807 |
INSERT INTO t1 VALUES (1), (3), (5), (7); |
1808 |
INSERT INTO t1 VALUES (NULL); |
|
1809 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1810 |
CREATE TABLE t2(a int) ENGINE=MyISAM; |
1
by brian
clean slate |
1811 |
INSERT INTO t2 VALUES (1),(2),(3); |
1812 |
||
1813 |
EXPLAIN SELECT a, a IN (SELECT a FROM t1) FROM t2; |
|
1814 |
SELECT a, a IN (SELECT a FROM t1) FROM t2; |
|
1815 |
||
1816 |
DROP TABLE t1,t2; |
|
1817 |
||
1818 |
# |
|
1819 |
# Bug #11302: getObject() returns a String for a sub-query of type datetime |
|
1820 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1821 |
CREATE TABLE t1 (a DATETIME) ENGINE=MyISAM; |
1
by brian
clean slate |
1822 |
INSERT INTO t1 VALUES ('1998-09-23'), ('2003-03-25'); |
1823 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1824 |
CREATE TABLE t2 ENGINE=MyISAM AS SELECT |
1
by brian
clean slate |
1825 |
(SELECT a FROM t1 WHERE a < '2000-01-01') AS sub_a |
1826 |
FROM t1 WHERE a > '2000-01-01'; |
|
1827 |
SHOW CREATE TABLE t2; |
|
1828 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1829 |
CREATE TABLE t3 ENGINE=MyISAM AS (SELECT a FROM t1 WHERE a < '2000-01-01') UNION (SELECT a FROM t1 WHERE a > '2000-01-01'); |
1
by brian
clean slate |
1830 |
SHOW CREATE TABLE t3; |
1831 |
||
1832 |
DROP TABLE t1,t2,t3; |
|
1833 |
||
1834 |
# |
|
1835 |
# Bug 24653: sorting by expressions containing subselects |
|
1836 |
# that return more than one row |
|
1837 |
# |
|
1838 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1839 |
CREATE TABLE t1 (a int) ENGINE=MyISAM; |
1
by brian
clean slate |
1840 |
INSERT INTO t1 VALUES (2), (4), (1), (3); |
1841 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1842 |
CREATE TABLE t2 (b int, c int) ENGINE=MyISAM; |
1
by brian
clean slate |
1843 |
INSERT INTO t2 VALUES |
1844 |
(2,1), (1,3), (2,1), (4,4), (2,2), (1,4); |
|
1845 |
||
1846 |
SELECT a FROM t1 ORDER BY (SELECT c FROM t2 WHERE b > 2 ); |
|
1847 |
--error 1242 |
|
1848 |
SELECT a FROM t1 ORDER BY (SELECT c FROM t2 WHERE b > 1); |
|
1849 |
SELECT a FROM t1 ORDER BY (SELECT c FROM t2 WHERE b > 2), a; |
|
1850 |
--error 1242 |
|
1851 |
SELECT a FROM t1 ORDER BY (SELECT c FROM t2 WHERE b > 1), a; |
|
1852 |
||
1853 |
SELECT b, MAX(c) FROM t2 GROUP BY b, (SELECT c FROM t2 WHERE b > 2); |
|
1854 |
--error 1242 |
|
1855 |
SELECT b, MAX(c) FROM t2 GROUP BY b, (SELECT c FROM t2 WHERE b > 1); |
|
1856 |
||
1857 |
||
1858 |
SELECT a FROM t1 GROUP BY a |
|
1859 |
HAVING IFNULL((SELECT b FROM t2 WHERE b > 2), |
|
1860 |
(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b)) > 3; |
|
1861 |
--error 1242 |
|
1862 |
SELECT a FROM t1 GROUP BY a |
|
1863 |
HAVING IFNULL((SELECT b FROM t2 WHERE b > 1), |
|
1864 |
(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b)) > 3; |
|
1865 |
||
1866 |
SELECT a FROM t1 GROUP BY a |
|
1867 |
HAVING IFNULL((SELECT b FROM t2 WHERE b > 4), |
|
1868 |
(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b)) > 3; |
|
1869 |
--error 1242 |
|
1870 |
SELECT a FROM t1 GROUP BY a |
|
1871 |
HAVING IFNULL((SELECT b FROM t2 WHERE b > 4), |
|
1872 |
(SELECT c FROM t2 WHERE c=a AND b > 1 ORDER BY b)) > 3; |
|
1873 |
||
1874 |
SELECT a FROM t1 |
|
1875 |
ORDER BY IFNULL((SELECT b FROM t2 WHERE b > 2), |
|
1876 |
(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b)); |
|
1877 |
--error 1242 |
|
1878 |
SELECT a FROM t1 |
|
1879 |
ORDER BY IFNULL((SELECT b FROM t2 WHERE b > 1), |
|
1880 |
(SELECT c FROM t2 WHERE c=a AND b > 1 ORDER BY b)); |
|
1881 |
||
1882 |
SELECT a FROM t1 |
|
1883 |
ORDER BY IFNULL((SELECT b FROM t2 WHERE b > 4), |
|
1884 |
(SELECT c FROM t2 WHERE c=a AND b > 2 ORDER BY b)); |
|
1885 |
--error 1242 |
|
1886 |
SELECT a FROM t1 |
|
1887 |
ORDER BY IFNULL((SELECT b FROM t2 WHERE b > 4), |
|
1888 |
(SELECT c FROM t2 WHERE c=a AND b > 1 ORDER BY b)); |
|
1889 |
||
1890 |
DROP TABLE t1,t2; |
|
1891 |
||
1892 |
# End of 4.1 tests |
|
1893 |
||
1894 |
# |
|
1895 |
#decimal-related tests |
|
1896 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1897 |
create table t1 (df decimal(5,1)) ENGINE=MyISAM; |
1
by brian
clean slate |
1898 |
insert into t1 values(1.1); |
1899 |
insert into t1 values(2.2); |
|
1900 |
||
1901 |
select * from t1 where df <= all (select avg(df) from t1 group by df); |
|
1902 |
select * from t1 where df >= all (select avg(df) from t1 group by df); |
|
1903 |
drop table t1; |
|
1904 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1905 |
create table t1 (df decimal(5,1)) ENGINE=MyISAM; |
1
by brian
clean slate |
1906 |
insert into t1 values(1.1); |
1907 |
select 1.1 * exists(select * from t1); |
|
1908 |
drop table t1; |
|
1909 |
||
1910 |
CREATE TABLE t1 ( |
|
223
by Brian Aker
Cleanup int() work. |
1911 |
grp int default NULL, |
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1912 |
a decimal(10,2) default NULL) ENGINE=MyISAM; |
1
by brian
clean slate |
1913 |
|
1914 |
insert into t1 values (1, 1), (2, 2), (2, 3), (3, 4), (3, 5), (3, 6), (NULL, NULL); |
|
1915 |
select * from t1; |
|
1916 |
select min(a) from t1 group by grp; |
|
1917 |
drop table t1; |
|
1918 |
||
1919 |
# |
|
1920 |
# Test for bug #9338: lame substitution of c1 instead of c2 |
|
1921 |
# |
|
1922 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1923 |
CREATE table t1 ( c1 integer ) ENGINE=MyISAM; |
1
by brian
clean slate |
1924 |
INSERT INTO t1 VALUES ( 1 ); |
1925 |
INSERT INTO t1 VALUES ( 2 ); |
|
1926 |
INSERT INTO t1 VALUES ( 3 ); |
|
1927 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1928 |
CREATE TABLE t2 ( c2 integer ) ENGINE=MyISAM; |
1
by brian
clean slate |
1929 |
INSERT INTO t2 VALUES ( 1 ); |
1930 |
INSERT INTO t2 VALUES ( 4 ); |
|
1931 |
INSERT INTO t2 VALUES ( 5 ); |
|
1932 |
||
1933 |
SELECT * FROM t1 LEFT JOIN t2 ON c1 = c2 WHERE c2 IN (1); |
|
1934 |
||
1935 |
SELECT * FROM t1 LEFT JOIN t2 ON c1 = c2 |
|
1936 |
WHERE c2 IN ( SELECT c2 FROM t2 WHERE c2 IN ( 1 ) ); |
|
1937 |
||
1938 |
DROP TABLE t1,t2; |
|
1939 |
||
1940 |
# |
|
1941 |
# Test for bug #9516: wrong evaluation of not_null_tables attribute in SQ |
|
1942 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1943 |
CREATE TABLE t1 ( c1 integer ) ENGINE=MyISAM; |
1
by brian
clean slate |
1944 |
INSERT INTO t1 VALUES ( 1 ); |
1945 |
INSERT INTO t1 VALUES ( 2 ); |
|
1946 |
INSERT INTO t1 VALUES ( 3 ); |
|
1947 |
INSERT INTO t1 VALUES ( 6 ); |
|
1948 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1949 |
CREATE TABLE t2 ( c2 integer ) ENGINE=MyISAM; |
1
by brian
clean slate |
1950 |
INSERT INTO t2 VALUES ( 1 ); |
1951 |
INSERT INTO t2 VALUES ( 4 ); |
|
1952 |
INSERT INTO t2 VALUES ( 5 ); |
|
1953 |
INSERT INTO t2 VALUES ( 6 ); |
|
1954 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1955 |
CREATE TABLE t3 ( c3 integer ) ENGINE=MyISAM; |
1
by brian
clean slate |
1956 |
INSERT INTO t3 VALUES ( 7 ); |
1957 |
INSERT INTO t3 VALUES ( 8 ); |
|
1958 |
||
1959 |
SELECT c1,c2 FROM t1 LEFT JOIN t2 ON c1 = c2 |
|
1960 |
WHERE EXISTS (SELECT c3 FROM t3 WHERE c2 IS NULL ); |
|
1961 |
||
1962 |
DROP TABLE t1,t2,t3; |
|
1963 |
||
1964 |
# |
|
1965 |
# Correct building of equal fields list (do not include outer |
|
1966 |
# fields) (BUG#6384) |
|
1967 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1968 |
CREATE TABLE t1 (EMPNUM CHAR(3)) ENGINE=MyISAM; |
1969 |
CREATE TABLE t2 (EMPNUM CHAR(3) ) ENGINE=MyISAM; |
|
1
by brian
clean slate |
1970 |
INSERT INTO t1 VALUES ('E1'),('E2'); |
1971 |
INSERT INTO t2 VALUES ('E1'); |
|
1972 |
DELETE FROM t1 |
|
1973 |
WHERE t1.EMPNUM NOT IN |
|
1974 |
(SELECT t2.EMPNUM |
|
1975 |
FROM t2 |
|
1976 |
WHERE t1.EMPNUM = t2.EMPNUM); |
|
1977 |
select * from t1; |
|
1978 |
DROP TABLE t1,t2; |
|
1979 |
||
1980 |
# |
|
1981 |
# Test for bug #11487: range access in a subquery |
|
1982 |
# |
|
1983 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1984 |
CREATE TABLE t1(select_id BIGINT, values_id BIGINT) ENGINE=MyISAM; |
1
by brian
clean slate |
1985 |
INSERT INTO t1 VALUES (1, 1); |
1986 |
CREATE TABLE t2 (select_id BIGINT, values_id BIGINT, |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
1987 |
PRIMARY KEY(select_id,values_id)) ENGINE=MyISAM; |
1
by brian
clean slate |
1988 |
INSERT INTO t2 VALUES (0, 1), (0, 2), (0, 3), (1, 5); |
1989 |
||
1990 |
SELECT values_id FROM t1 |
|
1991 |
WHERE values_id IN (SELECT values_id FROM t2 |
|
1992 |
WHERE select_id IN (1, 0)); |
|
1993 |
SELECT values_id FROM t1 |
|
1994 |
WHERE values_id IN (SELECT values_id FROM t2 |
|
1995 |
WHERE select_id BETWEEN 0 AND 1); |
|
1996 |
SELECT values_id FROM t1 |
|
1997 |
WHERE values_id IN (SELECT values_id FROM t2 |
|
1998 |
WHERE select_id = 0 OR select_id = 1); |
|
1999 |
||
2000 |
DROP TABLE t1, t2; |
|
2001 |
||
2002 |
# BUG#11821 : Select from subselect using aggregate function on an enum |
|
2003 |
# segfaults: |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2004 |
create table t1 (fld enum('0','1')) ENGINE=MyISAM; |
1
by brian
clean slate |
2005 |
insert into t1 values ('1'); |
2006 |
select * from (select max(fld) from t1) as foo; |
|
2007 |
drop table t1; |
|
2008 |
||
2009 |
# |
|
2010 |
# Test for bug #11762: subquery with an aggregate function in HAVING |
|
2011 |
# |
|
2012 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2013 |
CREATE TABLE t1 (a int, b int) ENGINE=MyISAM; |
2014 |
CREATE TABLE t2 (c int, d int) ENGINE=MyISAM; |
|
2015 |
CREATE TABLE t3 (e int) ENGINE=MyISAM; |
|
1
by brian
clean slate |
2016 |
|
2017 |
INSERT INTO t1 VALUES |
|
2018 |
(1,10), (2,10), (1,20), (2,20), (3,20), (2,30), (4,40); |
|
2019 |
INSERT INTO t2 VALUES |
|
2020 |
(2,10), (2,20), (4,10), (5,10), (3,20), (2,40); |
|
2021 |
INSERT INTO t3 VALUES (10), (30), (10), (20) ; |
|
2022 |
||
2023 |
SELECT a, MAX(b), MIN(b) FROM t1 GROUP BY a; |
|
2024 |
SELECT * FROM t2; |
|
2025 |
SELECT * FROM t3; |
|
2026 |
||
2027 |
SELECT a FROM t1 GROUP BY a |
|
2028 |
HAVING a IN (SELECT c FROM t2 WHERE MAX(b)>20); |
|
2029 |
SELECT a FROM t1 GROUP BY a |
|
2030 |
HAVING a IN (SELECT c FROM t2 WHERE MAX(b)<d); |
|
2031 |
SELECT a FROM t1 GROUP BY a |
|
2032 |
HAVING a IN (SELECT c FROM t2 WHERE MAX(b)>d); |
|
2033 |
SELECT a FROM t1 GROUP BY a |
|
2034 |
HAVING a IN (SELECT c FROM t2 |
|
2035 |
WHERE d >= SOME(SELECT e FROM t3 WHERE MAX(b)=e)); |
|
2036 |
SELECT a FROM t1 GROUP BY a |
|
2037 |
HAVING a IN (SELECT c FROM t2 |
|
2038 |
WHERE EXISTS(SELECT e FROM t3 WHERE MAX(b)=e AND e <= d)); |
|
2039 |
SELECT a FROM t1 GROUP BY a |
|
2040 |
HAVING a IN (SELECT c FROM t2 |
|
2041 |
WHERE d > SOME(SELECT e FROM t3 WHERE MAX(b)=e)); |
|
2042 |
SELECT a FROM t1 GROUP BY a |
|
2043 |
HAVING a IN (SELECT c FROM t2 |
|
2044 |
WHERE EXISTS(SELECT e FROM t3 WHERE MAX(b)=e AND e < d)); |
|
2045 |
SELECT a FROM t1 GROUP BY a |
|
2046 |
HAVING a IN (SELECT c FROM t2 |
|
2047 |
WHERE MIN(b) < d AND |
|
2048 |
EXISTS(SELECT e FROM t3 WHERE MAX(b)=e AND e <= d)); |
|
2049 |
||
2050 |
SELECT a, SUM(a) FROM t1 GROUP BY a; |
|
2051 |
||
2052 |
SELECT a FROM t1 |
|
2053 |
WHERE EXISTS(SELECT c FROM t2 GROUP BY c HAVING SUM(a) = c) GROUP BY a; |
|
2054 |
SELECT a FROM t1 GROUP BY a |
|
2055 |
HAVING EXISTS(SELECT c FROM t2 GROUP BY c HAVING SUM(a) = c); |
|
2056 |
||
2057 |
SELECT a FROM t1 |
|
2058 |
WHERE a < 3 AND |
|
2059 |
EXISTS(SELECT c FROM t2 GROUP BY c HAVING SUM(a) != c) GROUP BY a; |
|
2060 |
SELECT a FROM t1 |
|
2061 |
WHERE a < 3 AND |
|
2062 |
EXISTS(SELECT c FROM t2 GROUP BY c HAVING SUM(a) != c); |
|
2063 |
||
2064 |
SELECT t1.a FROM t1 GROUP BY t1.a |
|
2065 |
HAVING t1.a < ALL(SELECT t2.c FROM t2 GROUP BY t2.c |
|
2066 |
HAVING EXISTS(SELECT t3.e FROM t3 GROUP BY t3.e |
|
2067 |
HAVING SUM(t1.a+t2.c) < t3.e/4)); |
|
2068 |
SELECT t1.a FROM t1 GROUP BY t1.a |
|
2069 |
HAVING t1.a > ALL(SELECT t2.c FROM t2 |
|
2070 |
WHERE EXISTS(SELECT t3.e FROM t3 GROUP BY t3.e |
|
2071 |
HAVING SUM(t1.a+t2.c) < t3.e/4)); |
|
2072 |
-- error 1111 |
|
2073 |
SELECT t1.a FROM t1 GROUP BY t1.a |
|
2074 |
HAVING t1.a > ALL(SELECT t2.c FROM t2 |
|
2075 |
WHERE EXISTS(SELECT t3.e FROM t3 |
|
2076 |
WHERE SUM(t1.a+t2.c) < t3.e/4)); |
|
2077 |
-- error 1111 |
|
2078 |
SELECT t1.a from t1 GROUP BY t1.a HAVING AVG(SUM(t1.b)) > 20; |
|
2079 |
||
2080 |
SELECT t1.a FROM t1 GROUP BY t1.a |
|
2081 |
HAVING t1.a IN (SELECT t2.c FROM t2 GROUP BY t2.c |
|
2082 |
HAVING AVG(t2.c+SUM(t1.b)) > 20); |
|
2083 |
SELECT t1.a FROM t1 GROUP BY t1.a |
|
2084 |
HAVING t1.a IN (SELECT t2.c FROM t2 GROUP BY t2.c |
|
2085 |
HAVING AVG(SUM(t1.b)) > 20); |
|
2086 |
||
2087 |
SELECT t1.a, SUM(b) AS sum FROM t1 GROUP BY t1.a |
|
2088 |
HAVING t1.a IN (SELECT t2.c FROM t2 GROUP BY t2.c |
|
2089 |
HAVING t2.c+sum > 20); |
|
2090 |
||
2091 |
DROP TABLE t1,t2,t3; |
|
2092 |
||
2093 |
# |
|
2094 |
# Test for bug #16603: GROUP BY in a row subquery with a quantifier |
|
2095 |
# when an index is defined on the grouping field |
|
2096 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2097 |
CREATE TABLE t1 (a varchar(5), b varchar(10)) ENGINE=MyISAM; |
1
by brian
clean slate |
2098 |
INSERT INTO t1 VALUES |
2099 |
('AAA', 5), ('BBB', 4), ('BBB', 1), ('CCC', 2), |
|
2100 |
('CCC', 7), ('AAA', 2), ('AAA', 4), ('BBB', 3), ('AAA', 8); |
|
2101 |
||
2102 |
SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a); |
|
2103 |
EXPLAIN |
|
2104 |
SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a); |
|
2105 |
||
2106 |
ALTER TABLE t1 ADD INDEX(a); |
|
2107 |
||
2108 |
SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a); |
|
2109 |
EXPLAIN |
|
2110 |
SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a); |
|
2111 |
||
2112 |
DROP TABLE t1; |
|
2113 |
||
2114 |
# |
|
2115 |
# Bug#17366: Unchecked Item_int results in server crash |
|
2116 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2117 |
create table t1( f1 int,f2 int) ENGINE=MyISAM; |
1
by brian
clean slate |
2118 |
insert into t1 values (1,1),(2,2); |
2119 |
select tt.t from (select 'crash1' as t, f2 from t1) as tt left join t1 on tt.t = 'crash2' and tt.f2 = t1.f2 where tt.t = 'crash1'; |
|
2120 |
drop table t1; |
|
2121 |
||
2122 |
# |
|
2123 |
# Bug #18306: server crash on delete using subquery. |
|
2124 |
# |
|
2125 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2126 |
create table t1 (c int, key(c)) ENGINE=MyISAM; |
1
by brian
clean slate |
2127 |
insert into t1 values (1142477582), (1142455969); |
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2128 |
create table t2 (a int, b int) ENGINE=MyISAM; |
1
by brian
clean slate |
2129 |
insert into t2 values (2, 1), (1, 0); |
2130 |
delete from t1 where c <= 1140006215 and (select b from t2 where a = 2) = 1; |
|
2131 |
drop table t1, t2; |
|
2132 |
||
2133 |
# |
|
2134 |
# Bug#19077: A nested materialized derived table is used before being populated. |
|
2135 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2136 |
create table t1 (i int, j bigint) ENGINE=MyISAM; |
1
by brian
clean slate |
2137 |
insert into t1 values (1, 2), (2, 2), (3, 2); |
2138 |
select * from (select min(i) from t1 where j=(select * from (select min(j) from t1) t2)) t3; |
|
2139 |
drop table t1; |
|
2140 |
||
2141 |
# |
|
2142 |
# Bug#19700: subselect returning BIGINT always returned it as SIGNED |
|
2143 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2144 |
CREATE TABLE t1 (i BIGINT) ENGINE=MyISAM; |
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
2145 |
INSERT INTO t1 VALUES (10000000000000000); # > MAX SIGNED BIGINT 9323372036854775807 |
1
by brian
clean slate |
2146 |
INSERT INTO t1 VALUES (1); |
2147 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2148 |
CREATE TABLE t2 (i BIGINT) ENGINE=MyISAM; |
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
2149 |
INSERT INTO t2 VALUES (10000000000000000); # same as first table |
1
by brian
clean slate |
2150 |
INSERT INTO t2 VALUES (1); |
2151 |
||
2152 |
/* simple test */ |
|
2153 |
SELECT t1.i FROM t1 JOIN t2 ON t1.i = t2.i; |
|
2154 |
||
2155 |
/* subquery test */ |
|
2156 |
SELECT t1.i FROM t1 WHERE t1.i = (SELECT MAX(i) FROM t2); |
|
2157 |
||
2158 |
/* subquery test with cast*/ |
|
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
2159 |
SELECT t1.i FROM t1 WHERE t1.i = (SELECT MAX(i) FROM t2); |
1
by brian
clean slate |
2160 |
|
2161 |
DROP TABLE t1; |
|
2162 |
DROP TABLE t2; |
|
2163 |
||
2164 |
# |
|
2165 |
# Bug#20519: subselect with LIMIT M, N |
|
2166 |
# |
|
2167 |
||
2168 |
CREATE TABLE t1 ( |
|
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
2169 |
id bigint NOT NULL auto_increment, |
1
by brian
clean slate |
2170 |
name varchar(255) NOT NULL, |
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2171 |
PRIMARY KEY (id)) |
2172 |
ENGINE=MyISAM; |
|
2173 |
||
1
by brian
clean slate |
2174 |
INSERT INTO t1 VALUES |
2175 |
(1, 'Balazs'), (2, 'Joe'), (3, 'Frank'); |
|
2176 |
||
2177 |
CREATE TABLE t2 ( |
|
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
2178 |
id bigint NOT NULL auto_increment, |
2179 |
mid bigint NOT NULL, |
|
1
by brian
clean slate |
2180 |
date date NOT NULL, |
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2181 |
PRIMARY KEY (id)) |
2182 |
ENGINE=MyISAM; |
|
2183 |
||
1
by brian
clean slate |
2184 |
INSERT INTO t2 VALUES |
2185 |
(1, 1, '2006-03-30'), (2, 2, '2006-04-06'), (3, 3, '2006-04-13'), |
|
2186 |
(4, 2, '2006-04-20'), (5, 1, '2006-05-01'); |
|
2187 |
||
2188 |
SELECT *, |
|
2189 |
(SELECT date FROM t2 WHERE mid = t1.id |
|
2190 |
ORDER BY date DESC LIMIT 0, 1) AS date_last, |
|
2191 |
(SELECT date FROM t2 WHERE mid = t1.id |
|
2192 |
ORDER BY date DESC LIMIT 3, 1) AS date_next_to_last |
|
2193 |
FROM t1; |
|
2194 |
SELECT *, |
|
2195 |
(SELECT COUNT(*) FROM t2 WHERE mid = t1.id |
|
2196 |
ORDER BY date DESC LIMIT 1, 1) AS date_count |
|
2197 |
FROM t1; |
|
2198 |
SELECT *, |
|
2199 |
(SELECT date FROM t2 WHERE mid = t1.id |
|
2200 |
ORDER BY date DESC LIMIT 0, 1) AS date_last, |
|
2201 |
(SELECT date FROM t2 WHERE mid = t1.id |
|
2202 |
ORDER BY date DESC LIMIT 1, 1) AS date_next_to_last |
|
2203 |
FROM t1; |
|
2204 |
DROP TABLE t1,t2; |
|
2205 |
||
2206 |
# |
|
2207 |
# Bug#20869: subselect with range access by DESC |
|
2208 |
# |
|
2209 |
||
2210 |
CREATE TABLE t1 ( |
|
223
by Brian Aker
Cleanup int() work. |
2211 |
i1 int NOT NULL default '0', |
2212 |
i2 int NOT NULL default '0', |
|
873.1.2
by Jay Pipes
Fixed Field_datetime to never accept any bad datetimes as a string. This broke |
2213 |
t datetime, |
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2214 |
PRIMARY KEY (i1,i2,t)) |
2215 |
ENGINE=MyISAM; |
|
2216 |
||
1
by brian
clean slate |
2217 |
INSERT INTO t1 VALUES |
2218 |
(24,1,'2005-03-03 16:31:31'),(24,1,'2005-05-27 12:40:07'), |
|
2219 |
(24,1,'2005-05-27 12:40:08'),(24,1,'2005-05-27 12:40:10'), |
|
2220 |
(24,1,'2005-05-27 12:40:25'),(24,1,'2005-05-27 12:40:30'), |
|
2221 |
(24,2,'2005-03-03 13:43:05'),(24,2,'2005-03-03 16:23:31'), |
|
2222 |
(24,2,'2005-03-03 16:31:30'),(24,2,'2005-05-27 12:37:02'), |
|
2223 |
(24,2,'2005-05-27 12:40:06'); |
|
2224 |
||
2225 |
CREATE TABLE t2 ( |
|
223
by Brian Aker
Cleanup int() work. |
2226 |
i1 int NOT NULL default '0', |
2227 |
i2 int NOT NULL default '0', |
|
1
by brian
clean slate |
2228 |
t datetime default NULL, |
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2229 |
PRIMARY KEY (i1)) |
2230 |
ENGINE=MyISAM; |
|
2231 |
||
1
by brian
clean slate |
2232 |
INSERT INTO t2 VALUES (24,1,'2006-06-20 12:29:40'); |
2233 |
||
2234 |
EXPLAIN |
|
2235 |
SELECT * FROM t1,t2 |
|
2236 |
WHERE t1.t = (SELECT t1.t FROM t1 |
|
2237 |
WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1 |
|
2238 |
ORDER BY t1.t DESC LIMIT 1); |
|
2239 |
SELECT * FROM t1,t2 |
|
2240 |
WHERE t1.t = (SELECT t1.t FROM t1 |
|
2241 |
WHERE t1.t < t2.t AND t1.i2=1 AND t2.i1=t1.i1 |
|
2242 |
ORDER BY t1.t DESC LIMIT 1); |
|
2243 |
||
2244 |
DROP TABLE t1, t2; |
|
2245 |
||
2246 |
# |
|
2247 |
# Bug#14654 : Cannot select from the same table twice within a UNION |
|
2248 |
# statement |
|
2249 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2250 |
CREATE TABLE t1 (i INT) ENGINE=MyISAM; |
1
by brian
clean slate |
2251 |
|
2252 |
(SELECT i FROM t1) UNION (SELECT i FROM t1); |
|
2253 |
SELECT * FROM t1 WHERE NOT EXISTS |
|
2254 |
( |
|
2255 |
(SELECT i FROM t1) UNION |
|
2256 |
(SELECT i FROM t1) |
|
2257 |
); |
|
2258 |
||
2259 |
#TODO:not supported |
|
2260 |
--error ER_PARSE_ERROR |
|
2261 |
SELECT * FROM t1 |
|
2262 |
WHERE NOT EXISTS (((SELECT i FROM t1) UNION (SELECT i FROM t1))); |
|
2263 |
||
2264 |
#TODO:not supported |
|
2265 |
--error 1064 |
|
2266 |
explain select ((select t11.i from t1 t11) union (select t12.i from t1 t12)) |
|
2267 |
from t1; |
|
2268 |
||
2269 |
explain select * from t1 where not exists |
|
2270 |
((select t11.i from t1 t11) union (select t12.i from t1 t12)); |
|
2271 |
||
2272 |
DROP TABLE t1; |
|
2273 |
||
2274 |
# |
|
2275 |
# Bug #21540: Subqueries with no from and aggregate functions return |
|
2276 |
# wrong results |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2277 |
CREATE TABLE t1 (a INT, b INT) ENGINE=MyISAM; |
2278 |
CREATE TABLE t2 (a INT) ENGINE=MyISAM; |
|
1
by brian
clean slate |
2279 |
INSERT INTO t2 values (1); |
2280 |
INSERT INTO t1 VALUES (1,1),(1,2),(2,3),(3,4); |
|
2281 |
SELECT (SELECT COUNT(DISTINCT t1.b) from t2) FROM t1 GROUP BY t1.a; |
|
2282 |
SELECT (SELECT COUNT(DISTINCT t1.b) from t2 union select 1 from t2 where 12 < 3) |
|
2283 |
FROM t1 GROUP BY t1.a; |
|
2284 |
SELECT COUNT(DISTINCT t1.b), (SELECT COUNT(DISTINCT t1.b)) FROM t1 GROUP BY t1.a; |
|
2285 |
SELECT ( |
|
2286 |
SELECT ( |
|
2287 |
SELECT ( |
|
2288 |
SELECT COUNT(DISTINCT t1.b) |
|
2289 |
) |
|
2290 |
) |
|
2291 |
FROM t1 GROUP BY t1.a LIMIT 1) |
|
2292 |
FROM t1 t2 |
|
2293 |
GROUP BY t2.a; |
|
2294 |
DROP TABLE t1,t2; |
|
2295 |
||
2296 |
# |
|
2297 |
# Bug #21727: Correlated subquery that requires filesort: |
|
2298 |
# slow with big sort_buffer_size |
|
2299 |
# |
|
2300 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2301 |
CREATE TABLE t1 (a int, b int auto_increment, PRIMARY KEY (b)) ENGINE=MyISAM; |
1
by brian
clean slate |
2302 |
CREATE TABLE t2 (x int auto_increment, y int, z int, |
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2303 |
PRIMARY KEY (x), FOREIGN KEY (y) REFERENCES t1 (b)) ENGINE=MyISAM; |
1
by brian
clean slate |
2304 |
disable_query_log; |
206.1.1
by Stewart Smith
cut 'make test' time in half. |
2305 |
set autocommit=0; |
2306 |
begin; |
|
1
by brian
clean slate |
2307 |
let $1=3000; |
2308 |
while ($1) |
|
2309 |
{ |
|
2310 |
eval INSERT INTO t1(a) VALUES(RAND()*1000); |
|
2311 |
eval SELECT MAX(b) FROM t1 INTO @id; |
|
2312 |
let $2=10; |
|
2313 |
while ($2) |
|
2314 |
{ |
|
2315 |
eval INSERT INTO t2(y,z) VALUES(@id,RAND()*1000); |
|
2316 |
dec $2; |
|
2317 |
} |
|
2318 |
dec $1; |
|
2319 |
} |
|
206.1.1
by Stewart Smith
cut 'make test' time in half. |
2320 |
commit; |
2321 |
set autocommit=1; |
|
1
by brian
clean slate |
2322 |
enable_query_log; |
2323 |
||
2324 |
SET SESSION sort_buffer_size = 32 * 1024; |
|
2325 |
SELECT COUNT(*) |
|
2326 |
FROM (SELECT a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c |
|
2327 |
FROM t1) t; |
|
2328 |
||
2329 |
SET SESSION sort_buffer_size = 8 * 1024 * 1024; |
|
2330 |
SELECT COUNT(*) |
|
2331 |
FROM (SELECT a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c |
|
2332 |
FROM t1) t; |
|
2333 |
||
201
by Brian Aker
Convert default engine to Innodb |
2334 |
DROP TABLE t2,t1; |
1
by brian
clean slate |
2335 |
|
2336 |
# |
|
2337 |
# Bug #25219: EXIST subquery with UNION over a mix of |
|
2338 |
# correlated and uncorrelated selects |
|
2339 |
# |
|
2340 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2341 |
CREATE TABLE t1 (id char(4) PRIMARY KEY, c int) ENGINE=MyISAM; |
2342 |
CREATE TABLE t2 (c int) ENGINE=MyISAM; |
|
1
by brian
clean slate |
2343 |
|
2344 |
INSERT INTO t1 VALUES ('aa', 1); |
|
2345 |
INSERT INTO t2 VALUES (1); |
|
2346 |
||
2347 |
SELECT * FROM t1 |
|
2348 |
WHERE EXISTS (SELECT c FROM t2 WHERE c=1 |
|
2349 |
UNION |
|
2350 |
SELECT c from t2 WHERE c=t1.c); |
|
2351 |
||
2352 |
INSERT INTO t1 VALUES ('bb', 2), ('cc', 3), ('dd',1); |
|
2353 |
||
2354 |
SELECT * FROM t1 |
|
2355 |
WHERE EXISTS (SELECT c FROM t2 WHERE c=1 |
|
2356 |
UNION |
|
2357 |
SELECT c from t2 WHERE c=t1.c); |
|
2358 |
||
2359 |
INSERT INTO t2 VALUES (2); |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2360 |
CREATE TABLE t3 (c int) ENGINE=MyISAM; |
1
by brian
clean slate |
2361 |
INSERT INTO t3 VALUES (1); |
2362 |
||
2363 |
SELECT * FROM t1 |
|
2364 |
WHERE EXISTS (SELECT t2.c FROM t2 JOIN t3 ON t2.c=t3.c WHERE t2.c=1 |
|
2365 |
UNION |
|
2366 |
SELECT c from t2 WHERE c=t1.c); |
|
2367 |
||
2368 |
DROP TABLE t1,t2,t3; |
|
2369 |
||
2370 |
# |
|
2371 |
# Bug#21904 (parser problem when using IN with a double "(())") |
|
2372 |
# |
|
2373 |
||
2374 |
--disable_warnings |
|
2375 |
DROP TABLE IF EXISTS t1; |
|
2376 |
DROP TABLE IF EXISTS t2; |
|
2377 |
DROP TABLE IF EXISTS t1xt2; |
|
2378 |
--enable_warnings |
|
2379 |
||
2380 |
CREATE TABLE t1 ( |
|
223
by Brian Aker
Cleanup int() work. |
2381 |
id_1 int NOT NULL, |
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2382 |
t varchar(4) DEFAULT NULL) |
2383 |
ENGINE=MyISAM; |
|
1
by brian
clean slate |
2384 |
|
2385 |
CREATE TABLE t2 ( |
|
223
by Brian Aker
Cleanup int() work. |
2386 |
id_2 int NOT NULL, |
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2387 |
t varchar(4) DEFAULT NULL) |
2388 |
ENGINE=MyISAM; |
|
1
by brian
clean slate |
2389 |
|
2390 |
CREATE TABLE t1xt2 ( |
|
223
by Brian Aker
Cleanup int() work. |
2391 |
id_1 int NOT NULL, |
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2392 |
id_2 int NOT NULL) |
2393 |
ENGINE=MyISAM; |
|
1
by brian
clean slate |
2394 |
|
2395 |
INSERT INTO t1 VALUES (1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'); |
|
2396 |
||
2397 |
INSERT INTO t2 VALUES (2, 'bb'), (3, 'cc'), (4, 'dd'), (12, 'aa'); |
|
2398 |
||
2399 |
INSERT INTO t1xt2 VALUES (2, 2), (3, 3), (4, 4); |
|
2400 |
||
2401 |
# subselect returns 0 rows |
|
2402 |
||
2403 |
SELECT DISTINCT t1.id_1 FROM t1 WHERE |
|
2404 |
(12 IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)); |
|
2405 |
||
2406 |
SELECT DISTINCT t1.id_1 FROM t1 WHERE |
|
2407 |
(12 IN ((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1))); |
|
2408 |
||
2409 |
SELECT DISTINCT t1.id_1 FROM t1 WHERE |
|
2410 |
(12 IN (((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)))); |
|
2411 |
||
2412 |
SELECT DISTINCT t1.id_1 FROM t1 WHERE |
|
2413 |
(12 NOT IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)); |
|
2414 |
||
2415 |
SELECT DISTINCT t1.id_1 FROM t1 WHERE |
|
2416 |
(12 NOT IN ((SELECT t1xt2.id_2 FROM t1xt2 where t1.id_1 = t1xt2.id_1))); |
|
2417 |
||
2418 |
SELECT DISTINCT t1.id_1 FROM t1 WHERE |
|
2419 |
(12 NOT IN (((SELECT t1xt2.id_2 FROM t1xt2 where t1.id_1 = t1xt2.id_1)))); |
|
2420 |
||
2421 |
insert INTO t1xt2 VALUES (1, 12); |
|
2422 |
||
2423 |
# subselect returns 1 row |
|
2424 |
||
2425 |
SELECT DISTINCT t1.id_1 FROM t1 WHERE |
|
2426 |
(12 IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)); |
|
2427 |
||
2428 |
SELECT DISTINCT t1.id_1 FROM t1 WHERE |
|
2429 |
(12 IN ((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1))); |
|
2430 |
||
2431 |
SELECT DISTINCT t1.id_1 FROM t1 WHERE |
|
2432 |
(12 IN (((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)))); |
|
2433 |
||
2434 |
SELECT DISTINCT t1.id_1 FROM t1 WHERE |
|
2435 |
(12 NOT IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)); |
|
2436 |
||
2437 |
SELECT DISTINCT t1.id_1 FROM t1 WHERE |
|
2438 |
(12 NOT IN ((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1))); |
|
2439 |
||
2440 |
SELECT DISTINCT t1.id_1 FROM t1 WHERE |
|
2441 |
(12 NOT IN (((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)))); |
|
2442 |
||
2443 |
insert INTO t1xt2 VALUES (2, 12); |
|
2444 |
||
2445 |
# subselect returns more than 1 row |
|
2446 |
||
2447 |
SELECT DISTINCT t1.id_1 FROM t1 WHERE |
|
2448 |
(12 IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)); |
|
2449 |
||
2450 |
SELECT DISTINCT t1.id_1 FROM t1 WHERE |
|
2451 |
(12 IN ((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1))); |
|
2452 |
||
2453 |
SELECT DISTINCT t1.id_1 FROM t1 WHERE |
|
2454 |
(12 IN (((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)))); |
|
2455 |
||
2456 |
SELECT DISTINCT t1.id_1 FROM t1 WHERE |
|
2457 |
(12 NOT IN (SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)); |
|
2458 |
||
2459 |
SELECT DISTINCT t1.id_1 FROM t1 WHERE |
|
2460 |
(12 NOT IN ((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1))); |
|
2461 |
||
2462 |
SELECT DISTINCT t1.id_1 FROM t1 WHERE |
|
2463 |
(12 NOT IN (((SELECT t1xt2.id_2 FROM t1xt2 WHERE t1.id_1 = t1xt2.id_1)))); |
|
2464 |
||
2465 |
DROP TABLE t1; |
|
2466 |
DROP TABLE t2; |
|
2467 |
DROP TABLE t1xt2; |
|
2468 |
||
2469 |
# |
|
2470 |
# Bug #26728: derived table with concatanation of literals in select list |
|
2471 |
# |
|
2472 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2473 |
CREATE TABLE t1 (a int) ENGINE=MyISAM; |
1
by brian
clean slate |
2474 |
INSERT INTO t1 VALUES (3), (1), (2); |
2475 |
||
2476 |
SELECT 'this is ' 'a test.' AS col1, a AS col2 FROM t1; |
|
2477 |
SELECT * FROM (SELECT 'this is ' 'a test.' AS col1, a AS t2 FROM t1) t; |
|
2478 |
||
2479 |
DROP table t1; |
|
2480 |
||
2481 |
# |
|
2482 |
# Bug #27257: COUNT(*) aggregated in outer query |
|
2483 |
# |
|
2484 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2485 |
CREATE TABLE t1 (a int, b int) ENGINE=MyISAM; |
2486 |
CREATE TABLE t2 (m int, n int) ENGINE=MyISAM; |
|
1
by brian
clean slate |
2487 |
INSERT INTO t1 VALUES (2,2), (2,2), (3,3), (3,3), (3,3), (4,4); |
2488 |
INSERT INTO t2 VALUES (1,11), (2,22), (3,32), (4,44), (4,44); |
|
2489 |
||
2490 |
SELECT COUNT(*), a, |
|
2491 |
(SELECT m FROM t2 WHERE m = count(*) LIMIT 1) |
|
2492 |
FROM t1 GROUP BY a; |
|
2493 |
||
2494 |
SELECT COUNT(*), a, |
|
2495 |
(SELECT MIN(m) FROM t2 WHERE m = count(*)) |
|
2496 |
FROM t1 GROUP BY a; |
|
2497 |
||
2498 |
SELECT COUNT(*), a |
|
2499 |
FROM t1 GROUP BY a |
|
2500 |
HAVING (SELECT MIN(m) FROM t2 WHERE m = count(*)) > 1; |
|
2501 |
||
2502 |
DROP TABLE t1,t2; |
|
2503 |
||
2504 |
# |
|
2505 |
# Bug #27229: GROUP_CONCAT in subselect with COUNT() as an argument |
|
2506 |
# |
|
2507 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2508 |
CREATE TABLE t1 (a int, b int) ENGINE=MyISAM; |
2509 |
CREATE TABLE t2 (m int, n int) ENGINE=MyISAM; |
|
1
by brian
clean slate |
2510 |
INSERT INTO t1 VALUES (2,2), (2,2), (3,3), (3,3), (3,3), (4,4); |
2511 |
INSERT INTO t2 VALUES (1,11), (2,22), (3,32), (4,44), (4,44); |
|
2512 |
||
2513 |
SELECT COUNT(*) c, a, |
|
2514 |
(SELECT GROUP_CONCAT(COUNT(a)) FROM t2 WHERE m = a) |
|
2515 |
FROM t1 GROUP BY a; |
|
2516 |
||
2517 |
SELECT COUNT(*) c, a, |
|
2518 |
(SELECT GROUP_CONCAT(COUNT(a)+1) FROM t2 WHERE m = a) |
|
2519 |
FROM t1 GROUP BY a; |
|
2520 |
||
2521 |
DROP table t1,t2; |
|
2522 |
||
2523 |
# |
|
2524 |
# Bug#27321: Wrong subquery result in a grouping select |
|
2525 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2526 |
CREATE TABLE t1 (a int, b INT, d INT, c CHAR(10) NOT NULL, PRIMARY KEY (a, b)) ENGINE=MyISAM; |
1
by brian
clean slate |
2527 |
INSERT INTO t1 VALUES (1,1,0,'a'), (1,2,0,'b'), (1,3,0,'c'), (1,4,0,'d'), |
2528 |
(1,5,0,'e'), (2,1,0,'f'), (2,2,0,'g'), (2,3,0,'h'), (3,4,0,'i'), (3,3,0,'j'), |
|
2529 |
(3,2,0,'k'), (3,1,0,'l'), (1,9,0,'m'), (1,0,10,'n'), (2,0,5,'o'), (3,0,7,'p'); |
|
2530 |
||
2531 |
SELECT a, MAX(b), |
|
2532 |
(SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.b=MAX(t1.b + 0)) as test |
|
2533 |
FROM t1 GROUP BY a; |
|
2534 |
SELECT a x, MAX(b), |
|
2535 |
(SELECT t.c FROM t1 AS t WHERE x=t.a AND t.b=MAX(t1.b + 0)) as test |
|
2536 |
FROM t1 GROUP BY a; |
|
2537 |
SELECT a, AVG(b), |
|
2538 |
(SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.b=AVG(t1.b)) AS test |
|
2539 |
FROM t1 WHERE t1.d=0 GROUP BY a; |
|
2540 |
||
2541 |
SELECT tt.a, |
|
2542 |
(SELECT (SELECT c FROM t1 as t WHERE t1.a=t.a AND t.d=MAX(t1.b + tt.a) |
|
2543 |
LIMIT 1) FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1) as test |
|
2544 |
FROM t1 as tt; |
|
2545 |
||
2546 |
SELECT tt.a, |
|
2547 |
(SELECT (SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.d=MAX(t1.b + tt.a) |
|
2548 |
LIMIT 1) |
|
2549 |
FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1) as test |
|
2550 |
FROM t1 as tt GROUP BY tt.a; |
|
2551 |
||
2552 |
SELECT tt.a, MAX( |
|
2553 |
(SELECT (SELECT t.c FROM t1 AS t WHERE t1.a=t.a AND t.d=MAX(t1.b + tt.a) |
|
2554 |
LIMIT 1) |
|
2555 |
FROM t1 WHERE t1.a=tt.a GROUP BY a LIMIT 1)) as test |
|
2556 |
FROM t1 as tt GROUP BY tt.a; |
|
2557 |
||
2558 |
DROP TABLE t1; |
|
2559 |
||
2560 |
# |
|
2561 |
# Bug #27363: nested aggregates in outer, subquery / sum(select |
|
2562 |
# count(outer)) |
|
2563 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2564 |
CREATE TABLE t1 (a INT) ENGINE=MyISAM; INSERT INTO t1 values (1),(1),(1),(1); |
2565 |
CREATE TABLE t2 (x INT) ENGINE=MyISAM; INSERT INTO t1 values (1000),(1001),(1002); |
|
1
by brian
clean slate |
2566 |
|
2567 |
--error ER_INVALID_GROUP_FUNC_USE |
|
2568 |
SELECT SUM( (SELECT COUNT(a) FROM t2) ) FROM t1; |
|
2569 |
--error ER_INVALID_GROUP_FUNC_USE |
|
2570 |
SELECT SUM( (SELECT SUM(COUNT(a)) FROM t2) ) FROM t1; |
|
2571 |
||
2572 |
--error ER_INVALID_GROUP_FUNC_USE |
|
2573 |
SELECT |
|
2574 |
SUM( (SELECT AVG( (SELECT COUNT(*) FROM t1 t HAVING t1.a < 12) ) FROM t2) ) |
|
2575 |
FROM t1; |
|
2576 |
||
2577 |
--error ER_INVALID_GROUP_FUNC_USE |
|
2578 |
SELECT t1.a as XXA, |
|
2579 |
SUM( (SELECT AVG( (SELECT COUNT(*) FROM t1 t HAVING XXA < 12) ) FROM t2) ) |
|
2580 |
FROM t1; |
|
2581 |
||
2582 |
DROP TABLE t1,t2; |
|
2583 |
||
2584 |
# |
|
2585 |
# Bug #27807: Server crash when executing subquery with EXPLAIN |
|
2586 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2587 |
CREATE TABLE t1 (a int, b int, KEY (a)) ENGINE=MyISAM; |
1
by brian
clean slate |
2588 |
INSERT INTO t1 VALUES (1,1),(2,1); |
2589 |
EXPLAIN SELECT 1 FROM t1 WHERE a = (SELECT COUNT(*) FROM t1 GROUP BY b); |
|
2590 |
DROP TABLE t1; |
|
2591 |
||
2592 |
# |
|
2593 |
# Bug #28377: grouping query with a correlated subquery in WHERE condition |
|
2594 |
# |
|
2595 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2596 |
CREATE TABLE t1 (id int NOT NULL, st CHAR(2), INDEX idx(id)) ENGINE=MyISAM; |
1
by brian
clean slate |
2597 |
INSERT INTO t1 VALUES |
2598 |
(3,'FL'), (2,'GA'), (4,'FL'), (1,'GA'), (5,'NY'), (7,'FL'), (6,'NY'); |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2599 |
CREATE TABLE t2 (id int NOT NULL, INDEX idx(id)) ENGINE=MyISAM; |
1
by brian
clean slate |
2600 |
INSERT INTO t2 VALUES (7), (5), (1), (3); |
2601 |
||
2602 |
SELECT id, st FROM t1 |
|
2603 |
WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id); |
|
2604 |
SELECT id, st FROM t1 |
|
2605 |
WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id) |
|
2606 |
GROUP BY id; |
|
2607 |
||
2608 |
SELECT id, st FROM t1 |
|
2609 |
WHERE st IN ('GA','FL') AND NOT EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id); |
|
2610 |
SELECT id, st FROM t1 |
|
2611 |
WHERE st IN ('GA','FL') AND NOT EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id) |
|
2612 |
GROUP BY id; |
|
2613 |
||
2614 |
DROP TABLE t1,t2; |
|
2615 |
||
2616 |
# |
|
2617 |
# Bug #28728: crash with EXPLAIN EXTENDED for a query with a derived table |
|
2618 |
# over a grouping subselect |
|
2619 |
# |
|
2620 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2621 |
CREATE TABLE t1 (a int) ENGINE=MyISAM; |
1
by brian
clean slate |
2622 |
|
2623 |
INSERT INTO t1 VALUES (1), (2); |
|
2624 |
||
2625 |
EXPLAIN EXTENDED |
|
2626 |
SELECT * FROM (SELECT count(*) FROM t1 GROUP BY a) as res; |
|
2627 |
||
2628 |
DROP TABLE t1; |
|
2629 |
||
2630 |
# |
|
2631 |
# Bug #28811: crash for query containing subquery with ORDER BY and LIMIT 1 |
|
2632 |
# |
|
2633 |
||
2634 |
CREATE TABLE t1 ( |
|
2635 |
a varchar(255) default NULL, |
|
2636 |
b timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2637 |
INDEX idx(a,b)) |
2638 |
ENGINE=MyISAM; |
|
2639 |
||
1
by brian
clean slate |
2640 |
CREATE TABLE t2 ( |
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2641 |
a varchar(255) default NULL) |
2642 |
ENGINE=MyISAM; |
|
1
by brian
clean slate |
2643 |
|
2644 |
INSERT INTO t1 VALUES ('abcdefghijk','2007-05-07 06:00:24'); |
|
2645 |
INSERT INTO t1 SELECT * FROM t1; |
|
2646 |
INSERT INTO t1 SELECT * FROM t1; |
|
2647 |
INSERT INTO t1 SELECT * FROM t1; |
|
2648 |
INSERT INTO t1 SELECT * FROM t1; |
|
2649 |
INSERT INTO t1 SELECT * FROM t1; |
|
2650 |
INSERT INTO t1 SELECT * FROM t1; |
|
2651 |
INSERT INTO t1 SELECT * FROM t1; |
|
2652 |
INSERT INTO t1 SELECT * FROM t1; |
|
2653 |
INSERT INTO `t1` VALUES ('asdf','2007-02-08 01:11:26'); |
|
2654 |
INSERT INTO `t2` VALUES ('abcdefghijk'); |
|
2655 |
INSERT INTO `t2` VALUES ('asdf'); |
|
2656 |
||
2657 |
SET session sort_buffer_size=8192; |
|
2658 |
||
2659 |
SELECT (SELECT 1 FROM t1 WHERE t1.a=t2.a ORDER BY t1.b LIMIT 1) AS d1 FROM t2; |
|
2660 |
||
2661 |
DROP TABLE t1,t2; |
|
2662 |
||
2663 |
||
2664 |
# |
|
2665 |
# Bug #27333: subquery grouped for aggregate of outer query / no aggregate |
|
2666 |
# of subquery |
|
2667 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2668 |
CREATE TABLE t1 (a INTEGER, b INTEGER) ENGINE=MyISAM; |
2669 |
CREATE TABLE t2 (x INTEGER) ENGINE=MyISAM; |
|
1
by brian
clean slate |
2670 |
INSERT INTO t1 VALUES (1,11), (2,22), (2,22); |
2671 |
INSERT INTO t2 VALUES (1), (2); |
|
2672 |
||
2673 |
# wasn't failing, but should |
|
2674 |
--error ER_SUBQUERY_NO_1_ROW |
|
2675 |
SELECT a, COUNT(b), (SELECT COUNT(b) FROM t2) FROM t1 GROUP BY a; |
|
2676 |
||
2677 |
# fails as it should |
|
2678 |
--error ER_SUBQUERY_NO_1_ROW |
|
2679 |
SELECT a, COUNT(b), (SELECT COUNT(b)+0 FROM t2) FROM t1 GROUP BY a; |
|
2680 |
||
2681 |
SELECT (SELECT SUM(t1.a)/AVG(t2.x) FROM t2) FROM t1; |
|
2682 |
DROP TABLE t1,t2; |
|
2683 |
||
2684 |
# second test case from 27333 |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2685 |
CREATE TABLE t1 (a INT, b INT) ENGINE=MyISAM; |
1
by brian
clean slate |
2686 |
INSERT INTO t1 VALUES (1, 2), (1,3), (1,4), (2,1), (2,2); |
2687 |
||
2688 |
# returns no rows, when it should |
|
2689 |
SELECT a1.a, COUNT(*) FROM t1 a1 WHERE a1.a = 1 |
|
2690 |
AND EXISTS( SELECT a2.a FROM t1 a2 WHERE a2.a = a1.a) |
|
2691 |
GROUP BY a1.a; |
|
2692 |
DROP TABLE t1; |
|
2693 |
||
2694 |
#test cases from 29297 |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2695 |
CREATE TABLE t1 (a INT) ENGINE=MyISAM; |
2696 |
CREATE TABLE t2 (a INT) ENGINE=MyISAM; |
|
1
by brian
clean slate |
2697 |
INSERT INTO t1 VALUES (1),(2); |
2698 |
INSERT INTO t2 VALUES (1),(2); |
|
2699 |
SELECT (SELECT SUM(t1.a) FROM t2 WHERE a=0) FROM t1; |
|
2700 |
--error ER_SUBQUERY_NO_1_ROW |
|
2701 |
SELECT (SELECT SUM(t1.a) FROM t2 WHERE a!=0) FROM t1; |
|
2702 |
SELECT (SELECT SUM(t1.a) FROM t2 WHERE a=1) FROM t1; |
|
2703 |
DROP TABLE t1,t2; |
|
2704 |
||
2705 |
# |
|
2706 |
# Bug #31884: Assertion + crash in subquery in the SELECT clause. |
|
2707 |
# |
|
2708 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2709 |
CREATE TABLE t1 (a1 INT, a2 INT) ENGINE=MyISAM; |
2710 |
CREATE TABLE t2 (b1 INT, b2 INT) ENGINE=MyISAM; |
|
1
by brian
clean slate |
2711 |
|
2712 |
INSERT INTO t1 VALUES (100, 200); |
|
2713 |
INSERT INTO t1 VALUES (101, 201); |
|
2714 |
INSERT INTO t2 VALUES (101, 201); |
|
2715 |
INSERT INTO t2 VALUES (103, 203); |
|
2716 |
||
2717 |
SELECT ((a1,a2) IN (SELECT * FROM t2 WHERE b2 > 0)) IS NULL FROM t1; |
|
2718 |
DROP TABLE t1, t2; |
|
2719 |
||
2720 |
# |
|
2721 |
# Bug #30788: Inconsistent retrieval of char/varchar |
|
2722 |
# |
|
2723 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2724 |
CREATE TABLE t1 (a CHAR(1), b VARCHAR(10)) ENGINE=MyISAM; |
1
by brian
clean slate |
2725 |
INSERT INTO t1 VALUES ('a', 'aa'); |
2726 |
INSERT INTO t1 VALUES ('a', 'aaa'); |
|
2727 |
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1); |
|
2728 |
CREATE INDEX I1 ON t1 (a); |
|
2729 |
CREATE INDEX I2 ON t1 (b); |
|
2730 |
EXPLAIN SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1); |
|
2731 |
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1); |
|
2732 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2733 |
CREATE TABLE t2 (a VARCHAR(1), b VARCHAR(10)) ENGINE=MyISAM; |
1
by brian
clean slate |
2734 |
INSERT INTO t2 SELECT * FROM t1; |
2735 |
CREATE INDEX I1 ON t2 (a); |
|
2736 |
CREATE INDEX I2 ON t2 (b); |
|
2737 |
EXPLAIN SELECT a,b FROM t2 WHERE b IN (SELECT a FROM t2); |
|
2738 |
SELECT a,b FROM t2 WHERE b IN (SELECT a FROM t2); |
|
2739 |
EXPLAIN |
|
2740 |
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1 WHERE LENGTH(a)<500); |
|
2741 |
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1 WHERE LENGTH(a)<500); |
|
2742 |
||
2743 |
DROP TABLE t1,t2; |
|
2744 |
||
2745 |
# |
|
2746 |
# Bug #32400: Complex SELECT query returns correct result only on some |
|
2747 |
# occasions |
|
2748 |
# |
|
2749 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2750 |
CREATE TABLE t1(a INT, b INT) ENGINE=MyISAM; |
1
by brian
clean slate |
2751 |
INSERT INTO t1 VALUES (1,1), (1,2), (2,3), (2,4); |
2752 |
||
2753 |
--error ER_BAD_FIELD_ERROR |
|
2754 |
EXPLAIN |
|
2755 |
SELECT a AS out_a, MIN(b) FROM t1 |
|
2756 |
WHERE b > (SELECT MIN(b) FROM t1 WHERE a = out_a) |
|
2757 |
GROUP BY a; |
|
2758 |
||
2759 |
--error ER_BAD_FIELD_ERROR |
|
2760 |
SELECT a AS out_a, MIN(b) FROM t1 |
|
2761 |
WHERE b > (SELECT MIN(b) FROM t1 WHERE a = out_a) |
|
2762 |
GROUP BY a; |
|
2763 |
||
2764 |
EXPLAIN |
|
2765 |
SELECT a AS out_a, MIN(b) FROM t1 t1_outer |
|
2766 |
WHERE b > (SELECT MIN(b) FROM t1 WHERE a = t1_outer.a) |
|
2767 |
GROUP BY a; |
|
2768 |
||
2769 |
SELECT a AS out_a, MIN(b) FROM t1 t1_outer |
|
2770 |
WHERE b > (SELECT MIN(b) FROM t1 WHERE a = t1_outer.a) |
|
2771 |
GROUP BY a; |
|
2772 |
||
2773 |
DROP TABLE t1; |
|
2774 |
||
2775 |
||
2776 |
# |
|
2777 |
# Bug #32036: EXISTS within a WHERE clause with a UNION crashes MySQL 5.122 |
|
2778 |
# |
|
2779 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2780 |
CREATE TABLE t1 (a INT) ENGINE=MyISAM; |
2781 |
CREATE TABLE t2 (a INT) ENGINE=MyISAM; |
|
1
by brian
clean slate |
2782 |
|
2783 |
INSERT INTO t1 VALUES (1),(2); |
|
2784 |
INSERT INTO t2 VALUES (1),(2); |
|
2785 |
||
2786 |
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a)); |
|
2787 |
EXPLAIN EXTENDED |
|
2788 |
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a)); |
|
2789 |
||
2790 |
||
2791 |
EXPLAIN EXTENDED |
|
2792 |
SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a) UNION |
|
2793 |
(SELECT 1 FROM t2 WHERE t1.a = t2.a)); |
|
2794 |
||
2795 |
DROP TABLE t1,t2; |
|
2796 |
||
2797 |
# |
|
2798 |
# BUG#33794 "MySQL crashes executing specific query on specific dump" |
|
2799 |
# |
|
2800 |
CREATE TABLE t4 ( |
|
2801 |
f7 varchar(32) collate utf8_bin NOT NULL default '', |
|
2802 |
f10 varchar(32) collate utf8_bin default NULL, |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2803 |
PRIMARY KEY (f7)) |
2804 |
ENGINE=MyISAM; |
|
2805 |
||
1
by brian
clean slate |
2806 |
INSERT INTO t4 VALUES(1,1), (2,null); |
2807 |
||
2808 |
CREATE TABLE t2 ( |
|
2809 |
f4 varchar(32) collate utf8_bin NOT NULL default '', |
|
2810 |
f2 varchar(50) collate utf8_bin default NULL, |
|
2811 |
f3 varchar(10) collate utf8_bin default NULL, |
|
2812 |
PRIMARY KEY (f4), |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2813 |
UNIQUE KEY uk1 (f2)) |
2814 |
ENGINE=MyISAM; |
|
2815 |
||
1
by brian
clean slate |
2816 |
INSERT INTO t2 VALUES(1,1,null), (2,2,null); |
2817 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2818 |
CREATE TABLE t1 ( |
1
by brian
clean slate |
2819 |
f8 varchar(32) collate utf8_bin NOT NULL default '', |
2820 |
f1 varchar(10) collate utf8_bin default NULL, |
|
2821 |
f9 varchar(32) collate utf8_bin default NULL, |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2822 |
PRIMARY KEY (f8)) |
2823 |
ENGINE=MyISAM; |
|
2824 |
||
1
by brian
clean slate |
2825 |
INSERT INTO t1 VALUES (1,'P',1), (2,'P',1), (3,'R',2); |
2826 |
||
2827 |
CREATE TABLE t3 ( |
|
2828 |
f6 varchar(32) collate utf8_bin NOT NULL default '', |
|
2829 |
f5 varchar(50) collate utf8_bin default NULL, |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2830 |
PRIMARY KEY (f6)) |
2831 |
ENGINE=MyISAM; |
|
2832 |
||
1
by brian
clean slate |
2833 |
INSERT INTO t3 VALUES (1,null), (2,null); |
2834 |
||
2835 |
SELECT |
|
2836 |
IF(t1.f1 = 'R', a1.f2, t2.f2) AS a4, |
|
2837 |
IF(t1.f1 = 'R', a1.f3, t2.f3) AS f3, |
|
2838 |
SUM( |
|
2839 |
IF( |
|
2840 |
(SELECT VPC.f2 |
|
2841 |
FROM t2 VPC, t4 a2, t2 a3 |
|
2842 |
WHERE |
|
2843 |
VPC.f4 = a2.f10 AND a3.f2 = a4 |
|
2844 |
LIMIT 1) IS NULL, |
|
2845 |
0, |
|
2846 |
t3.f5 |
|
2847 |
) |
|
2848 |
) AS a6 |
|
2849 |
FROM |
|
2850 |
t2, t3, t1 JOIN t2 a1 ON t1.f9 = a1.f4 |
|
2851 |
GROUP BY a4; |
|
2852 |
||
2853 |
DROP TABLE t1, t2, t3, t4; |
|
2854 |
||
2855 |
--echo End of 5.0 tests. |
|
2856 |
||
2857 |
# |
|
2858 |
# Test [NOT] IN truth table (both as top-level and general predicate). |
|
2859 |
# |
|
2860 |
||
2861 |
create table t_out (subcase char(3), |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
2862 |
a1 char(2), b1 char(2), c1 char(2)) ENGINE=MyISAM; |
2863 |
create table t_in (a2 char(2), b2 char(2), c2 char(2)) ENGINE=MyISAM; |
|
1
by brian
clean slate |
2864 |
|
2865 |
insert into t_out values ('A.1','2a', NULL, '2a'); |
|
2866 |
#------------------------- A.2 - impossible |
|
2867 |
insert into t_out values ('A.3', '2a', NULL, '2a'); |
|
2868 |
insert into t_out values ('A.4', '2a', NULL, 'xx'); |
|
2869 |
insert into t_out values ('B.1', '2a', '2a', '2a'); |
|
2870 |
insert into t_out values ('B.2', '2a', '2a', '2a'); |
|
2871 |
insert into t_out values ('B.3', '3a', 'xx', '3a'); |
|
2872 |
insert into t_out values ('B.4', 'xx', '3a', '3a'); |
|
2873 |
||
2874 |
insert into t_in values ('1a', '1a', '1a'); |
|
2875 |
insert into t_in values ('2a', '2a', '2a'); |
|
2876 |
insert into t_in values (NULL, '2a', '2a'); |
|
2877 |
insert into t_in values ('3a', NULL, '3a'); |
|
2878 |
-- echo |
|
2879 |
-- echo Test general IN semantics (not top-level) |
|
2880 |
-- echo |
|
2881 |
-- echo case A.1 |
|
2882 |
select subcase, |
|
2883 |
(a1, b1, c1) IN (select * from t_in where a2 = 'no_match') pred_in, |
|
2884 |
(a1, b1, c1) NOT IN (select * from t_in where a2 = 'no_match') pred_not_in |
|
2885 |
from t_out where subcase = 'A.1'; |
|
2886 |
||
2887 |
-- echo case A.2 - impossible |
|
2888 |
||
2889 |
-- echo case A.3 |
|
2890 |
select subcase, |
|
2891 |
(a1, b1, c1) IN (select * from t_in) pred_in, |
|
2892 |
(a1, b1, c1) NOT IN (select * from t_in) pred_not_in |
|
2893 |
from t_out where subcase = 'A.3'; |
|
2894 |
||
2895 |
-- echo case A.4 |
|
2896 |
select subcase, |
|
2897 |
(a1, b1, c1) IN (select * from t_in) pred_in, |
|
2898 |
(a1, b1, c1) NOT IN (select * from t_in) pred_not_in |
|
2899 |
from t_out where subcase = 'A.4'; |
|
2900 |
||
2901 |
-- echo case B.1 |
|
2902 |
select subcase, |
|
2903 |
(a1, b1, c1) IN (select * from t_in where a2 = 'no_match') pred_in, |
|
2904 |
(a1, b1, c1) NOT IN (select * from t_in where a2 = 'no_match') pred_not_in |
|
2905 |
from t_out where subcase = 'B.1'; |
|
2906 |
||
2907 |
-- echo case B.2 |
|
2908 |
select subcase, |
|
2909 |
(a1, b1, c1) IN (select * from t_in) pred_in, |
|
2910 |
(a1, b1, c1) NOT IN (select * from t_in) pred_not_in |
|
2911 |
from t_out where subcase = 'B.2'; |
|
2912 |
||
2913 |
-- echo case B.3 |
|
2914 |
select subcase, |
|
2915 |
(a1, b1, c1) IN (select * from t_in) pred_in, |
|
2916 |
(a1, b1, c1) NOT IN (select * from t_in) pred_not_in |
|
2917 |
from t_out where subcase = 'B.3'; |
|
2918 |
||
2919 |
-- echo case B.4 |
|
2920 |
select subcase, |
|
2921 |
(a1, b1, c1) IN (select * from t_in) pred_in, |
|
2922 |
(a1, b1, c1) NOT IN (select * from t_in) pred_not_in |
|
2923 |
from t_out where subcase = 'B.4'; |
|
2924 |
||
2925 |
-- echo |
|
2926 |
-- echo Test IN as top-level predicate, and |
|
2927 |
-- echo as non-top level for cases A.3, B.3 (the only cases with NULL result). |
|
2928 |
-- echo |
|
2929 |
-- echo case A.1 |
|
2930 |
select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out |
|
2931 |
where subcase = 'A.1' and |
|
2932 |
(a1, b1, c1) IN (select * from t_in where a1 = 'no_match'); |
|
2933 |
||
2934 |
select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out |
|
2935 |
where subcase = 'A.1' and |
|
2936 |
(a1, b1, c1) NOT IN (select * from t_in where a1 = 'no_match'); |
|
2937 |
||
2938 |
select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out |
|
2939 |
where subcase = 'A.1' and |
|
2940 |
NOT((a1, b1, c1) IN (select * from t_in where a1 = 'no_match')); |
|
2941 |
||
2942 |
-- echo case A.3 |
|
2943 |
select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out |
|
2944 |
where subcase = 'A.3' and |
|
2945 |
(a1, b1, c1) IN (select * from t_in); |
|
2946 |
||
2947 |
select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out |
|
2948 |
where subcase = 'A.3' and |
|
2949 |
(a1, b1, c1) NOT IN (select * from t_in); |
|
2950 |
||
2951 |
select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out |
|
2952 |
where subcase = 'A.3' and |
|
2953 |
NOT((a1, b1, c1) IN (select * from t_in)); |
|
2954 |
# test non-top level result indirectly |
|
2955 |
select case when count(*) > 0 then 'N' else 'wrong result' end as pred_in from t_out |
|
2956 |
where subcase = 'A.3' and |
|
2957 |
((a1, b1, c1) IN (select * from t_in)) is NULL and |
|
2958 |
((a1, b1, c1) NOT IN (select * from t_in)) is NULL; |
|
2959 |
||
2960 |
-- echo case A.4 |
|
2961 |
select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out |
|
2962 |
where subcase = 'A.4' and |
|
2963 |
(a1, b1, c1) IN (select * from t_in); |
|
2964 |
||
2965 |
select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out |
|
2966 |
where subcase = 'A.4' and |
|
2967 |
(a1, b1, c1) NOT IN (select * from t_in); |
|
2968 |
||
2969 |
select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out |
|
2970 |
where subcase = 'A.4' and |
|
2971 |
NOT((a1, b1, c1) IN (select * from t_in)); |
|
2972 |
||
2973 |
-- echo case B.1 |
|
2974 |
select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out |
|
2975 |
where subcase = 'B.1' and |
|
2976 |
(a1, b1, c1) IN (select * from t_in where a1 = 'no_match'); |
|
2977 |
||
2978 |
select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out |
|
2979 |
where subcase = 'B.1' and |
|
2980 |
(a1, b1, c1) NOT IN (select * from t_in where a1 = 'no_match'); |
|
2981 |
||
2982 |
select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out |
|
2983 |
where subcase = 'B.1' and |
|
2984 |
NOT((a1, b1, c1) IN (select * from t_in where a1 = 'no_match')); |
|
2985 |
||
2986 |
-- echo case B.2 |
|
2987 |
select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out |
|
2988 |
where subcase = 'B.2' and |
|
2989 |
(a1, b1, c1) IN (select * from t_in); |
|
2990 |
||
2991 |
select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out |
|
2992 |
where subcase = 'B.2' and |
|
2993 |
(a1, b1, c1) NOT IN (select * from t_in); |
|
2994 |
||
2995 |
select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out |
|
2996 |
where subcase = 'B.2' and |
|
2997 |
NOT((a1, b1, c1) IN (select * from t_in)); |
|
2998 |
||
2999 |
-- echo case B.3 |
|
3000 |
select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out |
|
3001 |
where subcase = 'B.3' and |
|
3002 |
(a1, b1, c1) IN (select * from t_in); |
|
3003 |
||
3004 |
select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out |
|
3005 |
where subcase = 'B.3' and |
|
3006 |
(a1, b1, c1) NOT IN (select * from t_in); |
|
3007 |
||
3008 |
select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out |
|
3009 |
where subcase = 'B.3' and |
|
3010 |
NOT((a1, b1, c1) IN (select * from t_in)); |
|
3011 |
# test non-top level result indirectly |
|
3012 |
select case when count(*) > 0 then 'N' else 'wrong result' end as pred_in from t_out |
|
3013 |
where subcase = 'B.3' and |
|
3014 |
((a1, b1, c1) IN (select * from t_in)) is NULL and |
|
3015 |
((a1, b1, c1) NOT IN (select * from t_in)) is NULL; |
|
3016 |
||
3017 |
-- echo case B.4 |
|
3018 |
select case when count(*) > 0 then 'T' else 'F' end as pred_in from t_out |
|
3019 |
where subcase = 'B.4' and |
|
3020 |
(a1, b1, c1) IN (select * from t_in); |
|
3021 |
||
3022 |
select case when count(*) > 0 then 'T' else 'F' end as pred_not_in from t_out |
|
3023 |
where subcase = 'B.4' and |
|
3024 |
(a1, b1, c1) NOT IN (select * from t_in); |
|
3025 |
||
3026 |
select case when count(*) > 0 then 'T' else 'F' end as not_pred_in from t_out |
|
3027 |
where subcase = 'B.4' and |
|
3028 |
NOT((a1, b1, c1) IN (select * from t_in)); |
|
3029 |
||
3030 |
drop table t_out; |
|
3031 |
drop table t_in; |
|
3032 |
||
3033 |
||
3034 |
# |
|
3035 |
# Bug#20835 (literal string with =any values) |
|
3036 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
3037 |
CREATE TABLE t1 (s1 char(1)) ENGINE=MyISAM; |
1
by brian
clean slate |
3038 |
INSERT INTO t1 VALUES ('a'); |
779.3.10
by Monty Taylor
Turned on -Wshadow. |
3039 |
SELECT * FROM t1 WHERE 'a' = ANY (SELECT s1 FROM t1); |
1
by brian
clean slate |
3040 |
DROP TABLE t1; |
3041 |
||
3042 |
# |
|
3043 |
# Bug#33204: INTO is allowed in subselect, causing inconsistent results |
|
3044 |
# |
|
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
3045 |
CREATE TABLE t1( a INT ) ENGINE=MyISAM; |
1
by brian
clean slate |
3046 |
INSERT INTO t1 VALUES (1),(2); |
3047 |
||
642.1.58
by Lee
update subselect tests to use MyISAM tables since we have issues with optimizer and explain when using InnoDB |
3048 |
CREATE TABLE t2( a INT, b INT ) ENGINE=MyISAM; |
1
by brian
clean slate |
3049 |
|
3050 |
--error ER_PARSE_ERROR |
|
3051 |
SELECT * |
|
3052 |
FROM (SELECT a INTO @var FROM t1 WHERE a = 2) t1a; |
|
3053 |
--error ER_PARSE_ERROR |
|
3054 |
SELECT * |
|
3055 |
FROM (SELECT a INTO OUTFILE 'file' FROM t1 WHERE a = 2) t1a; |
|
3056 |
--error ER_PARSE_ERROR |
|
3057 |
SELECT * |
|
3058 |
FROM (SELECT a INTO DUMPFILE 'file' FROM t1 WHERE a = 2) t1a; |
|
3059 |
||
3060 |
--error ER_PARSE_ERROR |
|
3061 |
SELECT * FROM ( |
|
3062 |
SELECT 1 a |
|
3063 |
UNION |
|
3064 |
SELECT a INTO @var FROM t1 WHERE a = 2 |
|
3065 |
) t1a; |
|
3066 |
||
3067 |
--error ER_PARSE_ERROR |
|
3068 |
SELECT * FROM ( |
|
3069 |
SELECT 1 a |
|
3070 |
UNION |
|
3071 |
SELECT a INTO OUTFILE 'file' FROM t1 WHERE a = 2 |
|
3072 |
) t1a; |
|
3073 |
||
3074 |
--error ER_PARSE_ERROR |
|
3075 |
SELECT * FROM ( |
|
3076 |
SELECT 1 a |
|
3077 |
UNION |
|
3078 |
SELECT a INTO DUMPFILE 'file' FROM t1 WHERE a = 2 |
|
3079 |
) t1a; |
|
3080 |
||
3081 |
SELECT * FROM (SELECT a FROM t1 WHERE a = 2) t1a; |
|
3082 |
||
3083 |
SELECT * FROM ( |
|
3084 |
SELECT a FROM t1 WHERE a = 2 |
|
3085 |
UNION |
|
3086 |
SELECT a FROM t1 WHERE a = 2 |
|
3087 |
) t1a; |
|
3088 |
||
3089 |
SELECT * FROM ( |
|
3090 |
SELECT 1 a |
|
3091 |
UNION |
|
3092 |
SELECT a FROM t1 WHERE a = 2 |
|
3093 |
UNION |
|
3094 |
SELECT a FROM t1 WHERE a = 2 |
|
3095 |
) t1a; |
|
3096 |
||
3097 |
# This was not allowed previously. Possibly, it should be allowed on the future. |
|
3098 |
# For now, the intent is to keep the fix as non-intrusive as possible. |
|
3099 |
--error ER_PARSE_ERROR |
|
3100 |
SELECT * FROM ((SELECT 1 a) UNION SELECT 1 a); |
|
3101 |
SELECT * FROM (SELECT 1 a UNION (SELECT 1 a)) alias; |
|
3102 |
SELECT * FROM (SELECT 1 UNION SELECT 1) t1a; |
|
3103 |
--error ER_PARSE_ERROR |
|
3104 |
SELECT * FROM ((SELECT 1 a INTO @a)) t1a; |
|
3105 |
--error ER_PARSE_ERROR |
|
3106 |
SELECT * FROM ((SELECT 1 a INTO OUTFILE 'file' )) t1a; |
|
3107 |
--error ER_PARSE_ERROR |
|
3108 |
SELECT * FROM ((SELECT 1 a INTO DUMPFILE 'file' )) t1a; |
|
3109 |
||
3110 |
--error ER_PARSE_ERROR |
|
3111 |
SELECT * FROM (SELECT 1 a UNION (SELECT 1 a INTO @a)) t1a; |
|
3112 |
--error ER_PARSE_ERROR |
|
3113 |
SELECT * FROM (SELECT 1 a UNION (SELECT 1 a INTO DUMPFILE 'file' )) t1a; |
|
3114 |
--error ER_PARSE_ERROR |
|
3115 |
SELECT * FROM (SELECT 1 a UNION (SELECT 1 a INTO OUTFILE 'file' )) t1a; |
|
3116 |
||
3117 |
--error ER_PARSE_ERROR |
|
3118 |
SELECT * FROM (SELECT 1 a UNION ((SELECT 1 a INTO @a))) t1a; |
|
3119 |
--error ER_PARSE_ERROR |
|
3120 |
SELECT * FROM (SELECT 1 a UNION ((SELECT 1 a INTO DUMPFILE 'file' ))) t1a; |
|
3121 |
--error ER_PARSE_ERROR |
|
3122 |
SELECT * FROM (SELECT 1 a UNION ((SELECT 1 a INTO OUTFILE 'file' ))) t1a; |
|
3123 |
||
3124 |
SELECT * FROM (SELECT 1 a ORDER BY a) t1a; |
|
3125 |
SELECT * FROM (SELECT 1 a UNION SELECT 1 a ORDER BY a) t1a; |
|
3126 |
SELECT * FROM (SELECT 1 a UNION SELECT 1 a LIMIT 1) t1a; |
|
3127 |
SELECT * FROM (SELECT 1 a UNION SELECT 1 a ORDER BY a LIMIT 1) t1a; |
|
3128 |
||
3129 |
# Test of rule |
|
3130 |
# table_factor: '(' get_select_lex query_expression_body ')' opt_table_alias |
|
3131 |
# UNION should not be allowed inside the parentheses, nor should |
|
3132 |
# aliases after. |
|
3133 |
# |
|
3134 |
SELECT * FROM t1 JOIN (SELECT 1 UNION SELECT 1) alias ON 1; |
|
3135 |
--error ER_PARSE_ERROR |
|
3136 |
SELECT * FROM t1 JOIN ((SELECT 1 UNION SELECT 1)) ON 1; |
|
3137 |
--error ER_PARSE_ERROR |
|
3138 |
SELECT * FROM t1 JOIN (t1 t1a UNION SELECT 1) ON 1; |
|
3139 |
--error ER_PARSE_ERROR |
|
3140 |
SELECT * FROM t1 JOIN ((t1 t1a UNION SELECT 1)) ON 1; |
|
3141 |
--error ER_PARSE_ERROR |
|
3142 |
SELECT * FROM t1 JOIN (t1 t1a) t1a ON 1; |
|
3143 |
--error ER_PARSE_ERROR |
|
3144 |
SELECT * FROM t1 JOIN ((t1 t1a)) t1a ON 1; |
|
3145 |
||
3146 |
SELECT * FROM t1 JOIN (t1 t1a) ON 1; |
|
3147 |
SELECT * FROM t1 JOIN ((t1 t1a)) ON 1; |
|
3148 |
||
3149 |
SELECT * FROM (t1 t1a); |
|
3150 |
SELECT * FROM ((t1 t1a)); |
|
3151 |
||
3152 |
SELECT * FROM t1 JOIN (SELECT 1 t1a) alias ON 1; |
|
3153 |
SELECT * FROM t1 JOIN ((SELECT 1 t1a)) alias ON 1; |
|
3154 |
||
3155 |
SELECT * FROM t1 JOIN (SELECT 1 a) a ON 1; |
|
3156 |
SELECT * FROM t1 JOIN ((SELECT 1 a)) a ON 1; |
|
3157 |
||
3158 |
# For the join, TABLE_LIST::select_lex == NULL |
|
3159 |
# Check that we handle this. |
|
3160 |
--error ER_PARSE_ERROR |
|
3161 |
SELECT * FROM (t1 JOIN (SELECT 1) t1a1 ON 1) t1a2; |
|
3162 |
||
3163 |
SELECT * FROM t1 WHERE a = ALL ( SELECT 1 ); |
|
3164 |
SELECT * FROM t1 WHERE a = ALL ( SELECT 1 UNION SELECT 1 ); |
|
3165 |
SELECT * FROM t1 WHERE a = ANY ( SELECT 3 UNION SELECT 1 ); |
|
3166 |
||
3167 |
--error ER_PARSE_ERROR |
|
3168 |
SELECT * FROM t1 WHERE a = ANY ( SELECT 1 UNION SELECT 1 INTO @a); |
|
3169 |
--error ER_PARSE_ERROR |
|
3170 |
SELECT * FROM t1 WHERE a = ANY ( SELECT 1 UNION SELECT 1 INTO OUTFILE 'file' ); |
|
3171 |
--error ER_PARSE_ERROR |
|
3172 |
SELECT * FROM t1 WHERE a = ANY ( SELECT 1 UNION SELECT 1 INTO DUMPFILE 'file' ); |
|
3173 |
||
3174 |
SELECT * FROM t1 WHERE a = ( SELECT 1 ); |
|
3175 |
SELECT * FROM t1 WHERE a = ( SELECT 1 UNION SELECT 1 ); |
|
3176 |
--error ER_PARSE_ERROR |
|
3177 |
SELECT * FROM t1 WHERE a = ( SELECT 1 INTO @a); |
|
3178 |
--error ER_PARSE_ERROR |
|
3179 |
SELECT * FROM t1 WHERE a = ( SELECT 1 INTO OUTFILE 'file' ); |
|
3180 |
--error ER_PARSE_ERROR |
|
3181 |
SELECT * FROM t1 WHERE a = ( SELECT 1 INTO DUMPFILE 'file' ); |
|
3182 |
||
3183 |
--error ER_PARSE_ERROR |
|
3184 |
SELECT * FROM t1 WHERE a = ( SELECT 1 UNION SELECT 1 INTO @a); |
|
3185 |
--error ER_PARSE_ERROR |
|
3186 |
SELECT * FROM t1 WHERE a = ( SELECT 1 UNION SELECT 1 INTO OUTFILE 'file' ); |
|
3187 |
--error ER_PARSE_ERROR |
|
3188 |
SELECT * FROM t1 WHERE a = ( SELECT 1 UNION SELECT 1 INTO DUMPFILE 'file' ); |
|
3189 |
||
3190 |
--error ER_PARSE_ERROR |
|
3191 |
SELECT ( SELECT 1 INTO @v ); |
|
3192 |
--error ER_PARSE_ERROR |
|
3193 |
SELECT ( SELECT 1 INTO OUTFILE 'file' ); |
|
3194 |
--error ER_PARSE_ERROR |
|
3195 |
SELECT ( SELECT 1 INTO DUMPFILE 'file' ); |
|
3196 |
||
3197 |
--error ER_PARSE_ERROR |
|
3198 |
SELECT ( SELECT 1 UNION SELECT 1 INTO @v ); |
|
3199 |
--error ER_PARSE_ERROR |
|
3200 |
SELECT ( SELECT 1 UNION SELECT 1 INTO OUTFILE 'file' ); |
|
3201 |
--error ER_PARSE_ERROR |
|
3202 |
SELECT ( SELECT 1 UNION SELECT 1 INTO DUMPFILE 'file' ); |
|
3203 |
||
3204 |
# Make sure context is popped when we leave the nested select |
|
3205 |
SELECT ( SELECT a FROM t1 WHERE a = 1 ), a FROM t1; |
|
3206 |
SELECT ( SELECT a FROM t1 WHERE a = 1 UNION SELECT 1 ), a FROM t1; |
|
3207 |
||
3208 |
# Make sure we have feature F561 (see .yy file) |
|
3209 |
SELECT * FROM t2 WHERE (a, b) IN (SELECT a, b FROM t2); |
|
3210 |
||
3211 |
# Make sure the parser does not allow nested UNIONs anywhere |
|
3212 |
||
3213 |
--error ER_PARSE_ERROR |
|
3214 |
SELECT 1 UNION ( SELECT 1 UNION SELECT 1 ); |
|
3215 |
--error ER_PARSE_ERROR |
|
3216 |
( SELECT 1 UNION SELECT 1 ) UNION SELECT 1; |
|
3217 |
||
3218 |
--error ER_PARSE_ERROR |
|
3219 |
SELECT ( SELECT 1 UNION ( SELECT 1 UNION SELECT 1 ) ); |
|
3220 |
--error ER_PARSE_ERROR |
|
3221 |
SELECT ( ( SELECT 1 UNION SELECT 1 ) UNION SELECT 1; |
|
3222 |
SELECT ( SELECT 1 UNION SELECT 1 UNION SELECT 1 ); |
|
3223 |
SELECT ((SELECT 1 UNION SELECT 1 UNION SELECT 1)); |
|
3224 |
||
3225 |
--error ER_PARSE_ERROR |
|
3226 |
SELECT * FROM ( SELECT 1 UNION ( SELECT 1 UNION SELECT 1 ) ); |
|
3227 |
--error ER_PARSE_ERROR |
|
3228 |
SELECT * FROM ( ( SELECT 1 UNION SELECT 1 ) UNION SELECT 1 ); |
|
3229 |
SELECT * FROM ( SELECT 1 UNION SELECT 1 UNION SELECT 1 ) a; |
|
3230 |
||
3231 |
--error ER_PARSE_ERROR |
|
3232 |
SELECT * FROM t1 WHERE a = ( SELECT 1 UNION ( SELECT 1 UNION SELECT 1 ) ); |
|
3233 |
--error ER_PARSE_ERROR |
|
3234 |
SELECT * FROM t1 WHERE a = ALL ( SELECT 1 UNION ( SELECT 1 UNION SELECT 1 ) ); |
|
3235 |
--error ER_PARSE_ERROR |
|
3236 |
SELECT * FROM t1 WHERE a = ANY ( SELECT 1 UNION ( SELECT 1 UNION SELECT 1 ) ); |
|
3237 |
--error ER_PARSE_ERROR |
|
3238 |
SELECT * FROM t1 WHERE a IN ( SELECT 1 UNION ( SELECT 1 UNION SELECT 1 ) ); |
|
3239 |
||
3240 |
--error ER_PARSE_ERROR |
|
3241 |
SELECT * FROM t1 WHERE a = ( ( SELECT 1 UNION SELECT 1 ) UNION SELECT 1 ); |
|
3242 |
--error ER_PARSE_ERROR |
|
3243 |
SELECT * FROM t1 WHERE a = ALL ( ( SELECT 1 UNION SELECT 1 ) UNION SELECT 1 ); |
|
3244 |
--error ER_PARSE_ERROR |
|
3245 |
SELECT * FROM t1 WHERE a = ANY ( ( SELECT 1 UNION SELECT 1 ) UNION SELECT 1 ); |
|
3246 |
--error ER_PARSE_ERROR |
|
3247 |
SELECT * FROM t1 WHERE a IN ( ( SELECT 1 UNION SELECT 1 ) UNION SELECT 1 ); |
|
3248 |
||
3249 |
SELECT * FROM t1 WHERE a = ( SELECT 1 UNION SELECT 1 UNION SELECT 1 ); |
|
3250 |
SELECT * FROM t1 WHERE a = ALL ( SELECT 1 UNION SELECT 1 UNION SELECT 1 ); |
|
3251 |
SELECT * FROM t1 WHERE a = ANY ( SELECT 1 UNION SELECT 1 UNION SELECT 1 ); |
|
3252 |
SELECT * FROM t1 WHERE a IN ( SELECT 1 UNION SELECT 1 UNION SELECT 1 ); |
|
3253 |
||
3254 |
--error ER_PARSE_ERROR |
|
3255 |
SELECT * FROM t1 WHERE EXISTS ( SELECT 1 UNION SELECT 1 INTO @v ); |
|
3256 |
SELECT EXISTS(SELECT 1+1); |
|
3257 |
--error ER_PARSE_ERROR |
|
3258 |
SELECT EXISTS(SELECT 1+1 INTO @test); |
|
3259 |
--error ER_PARSE_ERROR |
|
3260 |
SELECT * FROM t1 WHERE a IN ( SELECT 1 UNION SELECT 1 INTO @v ); |
|
3261 |
||
3262 |
--error ER_PARSE_ERROR |
|
3263 |
SELECT * FROM t1 WHERE EXISTS ( SELECT 1 INTO @v ); |
|
3264 |
--error ER_PARSE_ERROR |
|
3265 |
SELECT * FROM t1 WHERE a IN ( SELECT 1 INTO @v ); |
|
3266 |
||
3267 |
DROP TABLE t1, t2; |