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