mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / mysql-test / r / subselect_innodb.result
blob4069958267af38433aecf4573dfe65f184ee39f9
1 drop table if exists t1,t2,t3;
2 CREATE TABLE t1
4 FOLDERID VARCHAR(32)BINARY NOT NULL
5 , FOLDERNAME VARCHAR(255)BINARY NOT NULL
6 , CREATOR VARCHAR(255)BINARY
7 , CREATED TIMESTAMP NOT NULL
8 , DESCRIPTION VARCHAR(255)BINARY
9 , FOLDERTYPE INTEGER NOT NULL
10 , MODIFIED TIMESTAMP
11 , MODIFIER VARCHAR(255)BINARY
12 , FOLDERSIZE INTEGER NOT NULL
13 , PARENTID VARCHAR(32)BINARY
14 , REPID VARCHAR(32)BINARY
15 , ORIGINATOR INTEGER
16 , PRIMARY KEY ( FOLDERID )
17 ) ENGINE=InnoDB;
18 CREATE INDEX FFOLDERID_IDX ON t1 (FOLDERID);
19 CREATE INDEX CMFLDRPARNT_IDX ON t1 (PARENTID);
20 INSERT INTO t1 VALUES("0c9aab05b15048c59bc35c8461507deb", "System", "System", "2003-06-05 16:30:00", "The system content repository folder.", "3", "2003-06-05 16:30:00", "System", "0", NULL, "9c9aab05b15048c59bc35c8461507deb", "1");
21 INSERT INTO t1 VALUES("2f6161e879db43c1a5b82c21ddc49089", "Default", "System", "2003-06-09 10:52:02", "The default content repository folder.", "3", "2003-06-05 16:30:00", "System", "0", NULL, "03eea05112b845949f3fd03278b5fe43", "1");
22 INSERT INTO t1 VALUES("c373e9f5ad0791724315444553544200", "AddDocumentTest", "admin", "2003-06-09 10:51:25", "Movie Reviews", "0", "2003-06-09 10:51:25", "admin", "0", "2f6161e879db43c1a5b82c21ddc49089", "03eea05112b845949f3fd03278b5fe43", NULL);
23 SELECT 'c373e9f5ad0791a0dab5444553544200' IN(SELECT t1.FOLDERID FROM t1 WHERE t1.PARENTID='2f6161e879db43c1a5b82c21ddc49089' AND t1.FOLDERNAME = 'Level1');
24 'c373e9f5ad0791a0dab5444553544200' IN(SELECT t1.FOLDERID FROM t1 WHERE t1.PARENTID='2f6161e879db43c1a5b82c21ddc49089' AND t1.FOLDERNAME = 'Level1')
26 drop table t1;
27 create table t1 (a int) engine=innodb;
28 create table t2 (a int) engine=innodb;
29 create table t3 (a int) engine=innodb;
30 insert into t1 values (1),(2),(3),(4);
31 insert into t2 values (10),(20),(30),(40);
32 insert into t3 values (1),(2),(10),(50);
33 select a from t3 where t3.a in (select a from t1 where a <= 3 union select * from t2 where a <= 30);
38 drop table t1,t2,t3;
39 CREATE TABLE t1 (
40 processor_id INTEGER NOT NULL,
41 PRIMARY KEY (processor_id)
42 ) ENGINE=InnoDB;
43 CREATE TABLE t3 (
44 yod_id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL,
45 login_processor INTEGER UNSIGNED ,
46 PRIMARY KEY (yod_id)
47 ) ENGINE=InnoDB;
48 CREATE TABLE t2 (
49 processor_id INTEGER NOT NULL,
50 yod_id BIGINT UNSIGNED NOT NULL,
51 PRIMARY KEY (processor_id, yod_id),
52 INDEX (processor_id),
53 INDEX (yod_id),
54 FOREIGN KEY (processor_id) REFERENCES t1(processor_id),
55 FOREIGN KEY (yod_id) REFERENCES t3(yod_id) 
56 ) ENGINE=InnoDB;
57 INSERT INTO t1 VALUES (1),(2),(3);
58 INSERT INTO t3 VALUES (1,1),(2,2),(3,3);
59 INSERT INTO t2 VALUES (1,1),(2,2),(3,3);
60 SELECT distinct p1.processor_id, (SELECT y.yod_id FROM t1 p2, t2 y WHERE p2.processor_id = p1.processor_id and p2.processor_id = y.processor_id) FROM t1 p1;
61 processor_id    (SELECT y.yod_id FROM t1 p2, t2 y WHERE p2.processor_id = p1.processor_id and p2.processor_id = y.processor_id)
62 1       1
63 2       2
64 3       3
65 drop table t2,t1,t3;
66 CREATE TABLE t1 (
67 id int(11) NOT NULL default '0',
68 b int(11) default NULL,
69 c char(3) default NULL,
70 PRIMARY KEY  (id),
71 KEY t2i1 (b)
72 ) ENGINE=innodb DEFAULT CHARSET=latin1;
73 INSERT INTO t1 VALUES (0,0,'GPL'),(1,0,'GPL'),(2,1,'GPL'),(3,2,'GPL');
74 CREATE TABLE t2 (
75 id int(11) NOT NULL default '0',
76 b int(11) default NULL,
77 c char(3) default NULL,
78 PRIMARY KEY  (id),
79 KEY t2i (b)
80 ) ENGINE=innodb DEFAULT CHARSET=latin1;
81 INSERT INTO t2 VALUES (0,0,'GPL'),(1,0,'GPL'),(2,1,'GPL'),(3,2,'GPL');
82 select (select max(id) from t2 where b=1 group by b) as x,b from t1 where b=1;
83 x       b
84 2       1
85 drop table t1,t2;
86 create table t1 (id int not null, value char(255), primary key(id)) engine=innodb;
87 create table t2 (id int not null, value char(255)) engine=innodb;
88 insert into t1 values (1,'a'),(2,'b');
89 insert into t2 values (1,'z'),(2,'x');
90 select t2.id,t2.value,(select t1.value from t1 where t1.id=t2.id) from t2;
91 id      value   (select t1.value from t1 where t1.id=t2.id)
92 1       z       a
93 2       x       b
94 select t2.id,t2.value,(select t1.value from t1 where t1.id=t2.id) from t2;
95 id      value   (select t1.value from t1 where t1.id=t2.id)
96 1       z       a
97 2       x       b
98 drop table t1,t2;
99 create table t1 (a int, b int) engine=innodb;
100 insert into t1 values (1,2), (1,3), (2,3), (2,4), (2,5), (3,4), (4,5), (4,100);
101 create table t2 (a int) engine=innodb;
102 insert into t2 values (1),(2),(3),(4);
103 select a, sum(b) as b from t1 group by a having b > (select max(a) from t2);
104 a       b
105 1       5
106 2       12
107 4       105
108 drop table t1, t2;
109 CREATE TABLE `t1` ( `unit` varchar(50) NOT NULL default '', `ingredient` varchar(50) NOT NULL default '') ENGINE=InnoDB DEFAULT CHARSET=latin1;
110 CREATE TABLE `t2` ( `ingredient` varchar(50) NOT NULL default '', `unit` varchar(50) NOT NULL default '', PRIMARY KEY (ingredient, unit)) ENGINE=InnoDB DEFAULT CHARSET=latin1;
111 INSERT INTO `t1` VALUES ('xx','yy');
112 INSERT INTO `t2` VALUES ('yy','xx');
113 SELECT R.unit, R.ingredient FROM t1 R WHERE R.ingredient IN (SELECT N.ingredient FROM t2 N WHERE N.unit = R.unit);
114 unit    ingredient
115 xx      yy
116 drop table t1, t2;
117 CREATE TABLE t1 (
118 id INT NOT NULL auto_increment,
119 date1 DATE, coworkerid INT,
120 description VARCHAR(255),
121 sum_used DOUBLE,
122 sum_remaining DOUBLE,
123 comments VARCHAR(255),
124 PRIMARY KEY(id)
125 ) engine=innodb;
126 insert into t1 values (NULL, '1999-01-01', 1,'test', 22, 33, 'comment'), (NULL, '1999-01-01', 1,'test', 22, 33, 'comment'), (NULL, '1999-01-01', 1,'test', 22, 33, 'comment'), (NULL, '1998-01-01', 1,'test', 22, 33, 'comment'), (NULL, '1998-01-01', 1,'test', 22, 33, 'comment'), (NULL, '2004-01-01', 1,'test', 22, 33, 'comment'), (NULL, '2004-01-01', 1,'test', 22, 33, 'comment');
127 SELECT DISTINCT
128 (SELECT sum(sum_used) FROM t1 WHERE sum_used > 0 AND year(date1) <= '2004') as somallontvangsten,
129 (SELECT sum(sum_used) FROM t1 WHERE sum_used < 0 AND year(date1) <= '2004') as somalluitgaven
130 FROM t1;
131 somallontvangsten       somalluitgaven
132 154     NULL
133 select * from t1;
134 id      date1   coworkerid      description     sum_used        sum_remaining   comments
135 1       1999-01-01      1       test    22      33      comment
136 2       1999-01-01      1       test    22      33      comment
137 3       1999-01-01      1       test    22      33      comment
138 4       1998-01-01      1       test    22      33      comment
139 5       1998-01-01      1       test    22      33      comment
140 6       2004-01-01      1       test    22      33      comment
141 7       2004-01-01      1       test    22      33      comment
142 drop table t1;
143 CREATE TABLE `t1` ( `a` char(3) NOT NULL default '', `b` char(3) NOT NULL default '', `c` char(3) NOT NULL default '', PRIMARY KEY  (`a`,`b`,`c`)) ENGINE=InnoDB;
144 CREATE TABLE t2 LIKE t1;
145 INSERT INTO t1 VALUES (1,1,1);
146 INSERT INTO t2 VALUES (1,1,1);
147 PREPARE my_stmt FROM "SELECT t1.b, count(*) FROM t1 group by t1.b having
148 count(*) > ALL (SELECT COUNT(*) FROM t2 WHERE t2.a=1 GROUP By t2.b)";
149 EXECUTE my_stmt;
150 b       count(*)
151 EXECUTE my_stmt;
152 b       count(*)
153 deallocate prepare my_stmt;
154 drop table t1,t2;
155 CREATE TABLE t1 (
156 school_name varchar(45) NOT NULL,
157 country varchar(45) NOT NULL,    
158 funds_requested float NOT NULL,
159 schooltype varchar(45) NOT NULL
160 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
161 insert into t1 values ("the school", "USA", 1200, "Human");
162 select count(country) as countrycount, sum(funds_requested) as smcnt,
163 country, (select sum(funds_requested) from t1) as total_funds
164 from t1
165 group by country;
166 countrycount    smcnt   country total_funds
167 1       1200    USA     1200
168 select count(country) as countrycount, sum(funds_requested) as smcnt,
169 country, (select sum(funds_requested) from t1) as total_funds
170 from t1
171 group by country;
172 countrycount    smcnt   country total_funds
173 1       1200    USA     1200
174 drop table t1;
175 CREATE TABLE `t1` (
176 `t3_id` int NOT NULL,
177 `t1_id` int NOT NULL,
178 PRIMARY KEY  (`t1_id`)
180 CREATE TABLE `t2` (
181 `t2_id` int NOT NULL,
182 `t1_id` int NOT NULL,
183 `b` int NOT NULL,
184 PRIMARY KEY  (`t2_id`),
185 UNIQUE KEY `idx_t2_t1_b` (`t1_id`,`b`)
186 ) ENGINE=InnoDB;
187 CREATE TABLE `t3` (
188 `t3_id` int NOT NULL
190 INSERT INTO `t3` VALUES (3);
191 select
192 (SELECT rs.t2_id
193 FROM t2 rs
194 WHERE rs.t1_id=
195 (SELECT lt.t1_id
196 FROM t1 lt
197 WHERE lt.t3_id=a.t3_id)
198 ORDER BY b DESC LIMIT 1)
199 from t3 AS a;
200 (SELECT rs.t2_id
201 FROM t2 rs
202 WHERE rs.t1_id=
203 (SELECT lt.t1_id
204 FROM t1 lt
205 WHERE lt.t3_id=a.t3_id)
206 ORDER BY b DESC LIMIT 1)
207 NULL
208 DROP PROCEDURE IF EXISTS p1;
209 create procedure p1()
210 begin
211 declare done int default 3;
212 repeat
213 select
214 (SELECT rs.t2_id
215 FROM t2 rs
216 WHERE rs.t1_id=
217 (SELECT lt.t1_id
218 FROM t1 lt
219 WHERE lt.t3_id=a.t3_id)
220 ORDER BY b DESC LIMIT 1) as x
221 from t3 AS a;
222 set done= done-1;
223 until done <= 0 end repeat;
224 end//
225 call p1();
227 NULL
229 NULL
231 NULL
232 call p1();
234 NULL
236 NULL
238 NULL
239 call p1();
241 NULL
243 NULL
245 NULL
246 drop procedure p1;
247 drop tables t1,t2,t3;
249 # Bug #11766300  59387: FAILING ASSERTION: CURSOR->POS_STATE == 1997660512 (BTR_PCUR_IS_POSITIONE
251 CREATE TABLE t1 (a INT) ENGINE=INNODB;
252 INSERT INTO t1 VALUES (0);
253 CREATE TABLE t2 (d BINARY(2), PRIMARY KEY (d(1)), UNIQUE KEY (d)) ENGINE=INNODB;
254 SELECT 1 FROM t1 WHERE NOT EXISTS
255 (SELECT 1 FROM t2 WHERE d = (SELECT d FROM t2 WHERE a >= 1) ORDER BY d);
258 EXPLAIN SELECT 1 FROM t1 WHERE NOT EXISTS
259 (SELECT 1 FROM t2 WHERE d = (SELECT d FROM t2 WHERE a >= 1) ORDER BY d);
260 id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
261 1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    1       Using where
262 2       DEPENDENT SUBQUERY      t2      eq_ref  PRIMARY,d       d       2       func    1       Using where
263 3       DEPENDENT SUBQUERY      t2      index   NULL    d       2       NULL    1       Using where; Using index
264 DROP TABLE t2;
265 CREATE TABLE t2 (b INT, c INT, UNIQUE KEY (b), UNIQUE KEY (b, c )) ENGINE=INNODB;
266 INSERT INTO t2 VALUES (1, 1);
267 SELECT 1 FROM t1
268 WHERE a != (SELECT 1 FROM t2 WHERE a <=> b OR a > '' AND 6 = 7 ORDER BY b, c);
270 DROP TABLE t1, t2;
272 # Bug #13639204 64111: CRASH ON SELECT SUBQUERY WITH NON UNIQUE
273 # INDEX
275 CREATE TABLE t1 (
276 id int
277 ) ENGINE=InnoDB;
278 INSERT INTO t1 (id) VALUES (11);
279 CREATE TABLE t2 (
280 t1_id int,
281 position int,
282 KEY t1_id (t1_id),
283 KEY t1_id_position (t1_id,position)
284 ) ENGINE=InnoDB;
285 EXPLAIN SELECT
286 (SELECT position FROM t2
287 WHERE t2.t1_id = t1.id
288 ORDER BY t2.t1_id , t2.position
289 LIMIT 10,1
290 ) AS maxkey
291 FROM t1
292 LIMIT 1;
293 id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
294 1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    1       
295 2       DEPENDENT SUBQUERY      t2      ref     t1_id,t1_id_position    t1_id_position  5       test.t1.id      1       Using where
296 SELECT
297 (SELECT position FROM t2
298 WHERE t2.t1_id = t1.id
299 ORDER BY t2.t1_id , t2.position
300 LIMIT 10,1
301 ) AS maxkey
302 FROM t1
303 LIMIT 1;
304 maxkey
305 NULL
306 DROP TABLE t1,t2;
307 End of 5.1 tests