~drizzle-trunk/drizzle/development

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