350
350
CREATE TABLE `t8` (
351
`pseudo` varchar(35) NOT NULL default '',
352
`email` varchar(60) NOT NULL default '',
351
`pseudo` varchar(35) character set latin1 NOT NULL default '',
352
`email` varchar(60) character set latin1 NOT NULL default '',
353
353
PRIMARY KEY (`pseudo`),
354
354
UNIQUE KEY `email` (`email`)
355
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
355
) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
356
356
INSERT INTO t8 (pseudo,email) VALUES ('joce','test');
357
357
INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1');
358
358
INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1');
359
359
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');
360
360
id select_type table type possible_keys key key_len ref rows filtered Extra
361
1 PRIMARY t8 const PRIMARY PRIMARY 142 const 1 100.00 Using index
362
4 SUBQUERY t8 const PRIMARY PRIMARY 142 1 100.00 Using index
363
2 SUBQUERY t8 const PRIMARY PRIMARY 142 const 1 100.00
364
3 SUBQUERY t8 const PRIMARY PRIMARY 142 1 100.00 Using index
361
1 PRIMARY t8 const PRIMARY PRIMARY 37 const 1 100.00 Using index
362
4 SUBQUERY t8 const PRIMARY PRIMARY 37 1 100.00 Using index
363
2 SUBQUERY t8 const PRIMARY PRIMARY 37 const 1 100.00
364
3 SUBQUERY t8 const PRIMARY PRIMARY 37 1 100.00 Using index
366
Note 1003 select 'joce' AS `pseudo`,(select 'test' AS `email` from `test`.`t8` where ('joce' = (select 'joce' AS `pseudo` from `test`.`t8` where ('joce' = 'joce')))) AS `(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))` from `test`.`t8` where ('joce' = (select 'joce' AS `pseudo` from `test`.`t8` where ('joce' = 'joce')))
366
Note 1003 select 'joce' AS "pseudo",(select 'test' AS "email" from "test"."t8" where 1) AS "(SELECT email FROM t8 WHERE pseudo=(SELECT pseudo FROM t8 WHERE pseudo='joce'))" from "test"."t8" where 1
367
367
SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM
368
368
t8 WHERE pseudo='joce');
369
369
ERROR 21000: Operand should contain 1 column(s)
902
902
2 DEPENDENT SUBQUERY t2 ref_or_null a a 5 func 2 100.00 Using index
903
903
2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer
905
Note 1003 select `test`.`t1`.`a` AS `a`,<in_optimizer>(`test`.`t1`.`a`,<exists>(select 1 AS `Not_used` from `test`.`t2` join `test`.`t3` where ((`test`.`t3`.`a` = `test`.`t2`.`a`) and ((<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a`) or isnull(`test`.`t2`.`a`))) having <is_not_null_test>(`test`.`t2`.`a`))) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1`
905
Note 1003 select "test"."t1"."a" AS "a",<in_optimizer>("test"."t1"."a",<exists>(select 1 AS "Not_used" from "test"."t2" join "test"."t3" where (("test"."t3"."a" = "test"."t2"."a") and ((<cache>("test"."t1"."a") = "test"."t2"."a") or isnull("test"."t2"."a"))) having <is_not_null_test>("test"."t2"."a"))) AS "t1.a in (select t2.a from t2,t3 where t3.a=t2.a)" from "test"."t1"
906
906
drop table t1,t2,t3;
907
CREATE TABLE t1 (a int);
907
create table t1 (a float);
908
select 10.5 IN (SELECT * from t1 LIMIT 1);
909
ERROR 42000: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
910
select 10.5 IN (SELECT * from t1 LIMIT 1 UNION SELECT 1.5);
911
ERROR 42000: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
913
create table t1 (a int, b int, c varchar(10));
914
create table t2 (a int);
915
insert into t1 values (1,2,'a'),(2,3,'b'),(3,4,'c');
916
insert into t2 values (1),(2),(NULL);
917
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;
918
a (select a,b,c from t1 where t1.a=t2.a) = ROW(a,2,'a') (select c from t1 where a=t2.a)
922
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;
923
a (select a,b,c from t1 where t1.a=t2.a) = ROW(a,3,'b') (select c from t1 where a=t2.a)
927
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;
928
a (select a,b,c from t1 where t1.a=t2.a) = ROW(a,4,'c') (select c from t1 where a=t2.a)
933
create table t1 (a int, b real, c varchar(10));
934
insert into t1 values (1, 1, 'a'), (2,2,'b'), (NULL, 2, 'b');
935
select ROW(1, 1, 'a') IN (select a,b,c from t1);
936
ROW(1, 1, 'a') IN (select a,b,c from t1)
938
select ROW(1, 2, 'a') IN (select a,b,c from t1);
939
ROW(1, 2, 'a') IN (select a,b,c from t1)
941
select ROW(1, 1, 'a') IN (select b,a,c from t1);
942
ROW(1, 1, 'a') IN (select b,a,c from t1)
944
select ROW(1, 1, 'a') IN (select a,b,c from t1 where a is not null);
945
ROW(1, 1, 'a') IN (select a,b,c from t1 where a is not null)
947
select ROW(1, 2, 'a') IN (select a,b,c from t1 where a is not null);
948
ROW(1, 2, 'a') IN (select a,b,c from t1 where a is not null)
950
select ROW(1, 1, 'a') IN (select b,a,c from t1 where a is not null);
951
ROW(1, 1, 'a') IN (select b,a,c from t1 where a is not null)
953
select ROW(1, 1, 'a') IN (select a,b,c from t1 where c='b' or c='a');
954
ROW(1, 1, 'a') IN (select a,b,c from t1 where c='b' or c='a')
956
select ROW(1, 2, 'a') IN (select a,b,c from t1 where c='b' or c='a');
957
ROW(1, 2, 'a') IN (select a,b,c from t1 where c='b' or c='a')
959
select ROW(1, 1, 'a') IN (select b,a,c from t1 where c='b' or c='a');
960
ROW(1, 1, 'a') IN (select b,a,c from t1 where c='b' or c='a')
962
select ROW(1, 1, 'a') IN (select b,a,c from t1 limit 2);
963
ERROR 42000: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
965
CREATE TABLE t1 (a int(1));
908
966
EXPLAIN EXTENDED SELECT (SELECT RAND() FROM t1) FROM t1;
909
967
id select_type table type possible_keys key key_len ref rows filtered Extra
910
1 PRIMARY t1 ALL NULL NULL NULL NULL 1 100.00
911
2 SUBQUERY t1 ALL NULL NULL NULL NULL 1 100.00
913
Note 1003 select (select rand() AS `RAND()` from `test`.`t1`) AS `(SELECT RAND() FROM t1)` from `test`.`t1`
968
1 PRIMARY t1 system NULL NULL NULL NULL 0 0.00 const row not found
969
2 SUBQUERY t1 system NULL NULL NULL NULL 0 0.00 const row not found
971
Note 1003 select (select rand() AS "RAND()" from "test"."t1") AS "(SELECT RAND() FROM t1)" from "test"."t1"
972
EXPLAIN EXTENDED SELECT (SELECT ENCRYPT('test') FROM t1) FROM t1;
973
id select_type table type possible_keys key key_len ref rows filtered Extra
974
1 PRIMARY t1 system NULL NULL NULL NULL 0 0.00 const row not found
975
2 SUBQUERY t1 system NULL NULL NULL NULL 0 0.00 const row not found
977
Note 1003 select (select encrypt('test') AS "ENCRYPT('test')" from "test"."t1") AS "(SELECT ENCRYPT('test') FROM t1)" from "test"."t1"
914
978
EXPLAIN EXTENDED SELECT (SELECT BENCHMARK(1,1) FROM t1) FROM t1;
915
979
id select_type table type possible_keys key key_len ref rows filtered Extra
916
1 PRIMARY t1 ALL NULL NULL NULL NULL 1 100.00
917
2 SUBQUERY t1 ALL NULL NULL NULL NULL 1 100.00
980
1 PRIMARY t1 system NULL NULL NULL NULL 0 0.00 const row not found
981
2 SUBQUERY t1 system NULL NULL NULL NULL 0 0.00 const row not found
919
Note 1003 select (select benchmark(1,1) AS `BENCHMARK(1,1)` from `test`.`t1`) AS `(SELECT BENCHMARK(1,1) FROM t1)` from `test`.`t1`
983
Note 1003 select (select benchmark(1,1) AS "BENCHMARK(1,1)" from "test"."t1") AS "(SELECT BENCHMARK(1,1) FROM t1)" from "test"."t1"
921
985
CREATE TABLE `t1` (
922
`mot` varchar(30) NOT NULL default '',
923
`topic` bigint NOT NULL default '0',
986
`mot` varchar(30) character set latin1 NOT NULL default '',
987
`topic` mediumint(8) unsigned NOT NULL default '0',
924
988
`date` date NOT NULL default '0000-00-00',
925
`pseudo` varchar(35) NOT NULL default '',
989
`pseudo` varchar(35) character set latin1 NOT NULL default '',
926
990
PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`),
927
991
KEY `pseudo` (`pseudo`,`date`,`topic`),
928
992
KEY `topic` (`topic`)
929
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
993
) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
930
994
CREATE TABLE `t2` (
931
`mot` varchar(30) NOT NULL default '',
932
`topic` bigint NOT NULL default '0',
995
`mot` varchar(30) character set latin1 NOT NULL default '',
996
`topic` mediumint(8) unsigned NOT NULL default '0',
933
997
`date` date NOT NULL default '0000-00-00',
934
`pseudo` varchar(35) NOT NULL default '',
998
`pseudo` varchar(35) character set latin1 NOT NULL default '',
935
999
PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`),
936
1000
KEY `pseudo` (`pseudo`,`date`,`topic`),
937
1001
KEY `topic` (`topic`)
938
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
1002
) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
939
1003
CREATE TABLE `t3` (
940
`numeropost` bigint NOT NULL auto_increment,
941
`maxnumrep` int NOT NULL default '0',
1004
`numeropost` mediumint(8) unsigned NOT NULL auto_increment,
1005
`maxnumrep` int(10) unsigned NOT NULL default '0',
942
1006
PRIMARY KEY (`numeropost`),
943
1007
UNIQUE KEY `maxnumrep` (`maxnumrep`)
1008
) ENGINE=MyISAM CHARSET=latin1;
945
1009
INSERT INTO t1 (mot, topic, pseudo) VALUES ('joce','1','joce'),('test','2','test');
946
1010
INSERT INTO t2 (mot, topic, pseudo) VALUES ('joce','1','joce'),('test','2','test');
947
1011
INSERT INTO t3 VALUES (1,1);
1333
1405
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1;
1334
1406
id select_type table type possible_keys key key_len ref rows filtered Extra
1335
1 PRIMARY t1 index NULL s1 23 NULL 3 100.00 Using index
1336
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 23 func 2 100.00 Using index; Full scan on NULL key
1407
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
1408
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
1338
Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`))))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1`
1410
Note 1003 select "test"."t1"."s1" AS "s1",(not(<in_optimizer>("test"."t1"."s1",<exists>(<index_lookup>(<cache>("test"."t1"."s1") in t2 on s1 checking NULL having trigcond(<is_not_null_test>("test"."t2"."s1"))))))) AS "s1 NOT IN (SELECT s1 FROM t2)" from "test"."t1"
1339
1411
explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1;
1340
1412
id select_type table type possible_keys key key_len ref rows filtered Extra
1341
1 PRIMARY t1 index NULL s1 23 NULL 3 100.00 Using index
1342
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 23 func 2 100.00 Using index; Full scan on NULL key
1413
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
1414
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
1344
Note 1003 select `test`.`t1`.`s1` AS `s1`,<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`))))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1`
1416
Note 1003 select "test"."t1"."s1" AS "s1",<in_optimizer>("test"."t1"."s1",<exists>(<index_lookup>(<cache>("test"."t1"."s1") in t2 on s1 checking NULL having trigcond(<is_not_null_test>("test"."t2"."s1"))))) AS "s1 = ANY (SELECT s1 FROM t2)" from "test"."t1"
1345
1417
explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1;
1346
1418
id select_type table type possible_keys key key_len ref rows filtered Extra
1347
1 PRIMARY t1 index NULL s1 23 NULL 3 100.00 Using index
1348
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 23 func 2 100.00 Using index; Full scan on NULL key
1419
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
1420
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key
1350
Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(<is_not_null_test>(`test`.`t2`.`s1`))))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1`
1422
Note 1003 select "test"."t1"."s1" AS "s1",(not(<in_optimizer>("test"."t1"."s1",<exists>(<index_lookup>(<cache>("test"."t1"."s1") in t2 on s1 checking NULL having trigcond(<is_not_null_test>("test"."t2"."s1"))))))) AS "s1 <> ALL (SELECT s1 FROM t2)" from "test"."t1"
1351
1423
explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1;
1352
1424
id select_type table type possible_keys key key_len ref rows filtered Extra
1353
1 PRIMARY t1 index NULL s1 23 NULL 3 100.00 Using index
1354
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 23 func 2 100.00 Using index; Using where; Full scan on NULL key
1425
1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index
1426
2 DEPENDENT SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Using where; Full scan on NULL key
1356
Note 1003 select `test`.`t1`.`s1` AS `s1`,(not(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL where (`test`.`t2`.`s1` < 'a2') having trigcond(<is_not_null_test>(`test`.`t2`.`s1`))))))) AS `s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2')` from `test`.`t1`
1428
Note 1003 select "test"."t1"."s1" AS "s1",(not(<in_optimizer>("test"."t1"."s1",<exists>(<index_lookup>(<cache>("test"."t1"."s1") in t2 on s1 checking NULL where ("test"."t2"."s1" < 'a2') having trigcond(<is_not_null_test>("test"."t2"."s1"))))))) AS "s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2')" from "test"."t1"
1357
1429
drop table t1,t2;
1358
1430
create table t2 (a int, b int);
1359
1431
create table t3 (a int);
1385
1457
explain extended select * from t3 where a >= all (select b from t2 group by 1);
1386
1458
id select_type table type possible_keys key key_len ref rows filtered Extra
1387
1459
1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 Using where
1388
2 SUBQUERY t2 ALL NULL NULL NULL NULL 1 100.00 Using temporary; Using filesort
1460
2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found
1390
Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <not>((`test`.`t3`.`a` < <max>(select `test`.`t2`.`b` AS `b` from `test`.`t2` group by 1)))
1462
Note 1003 select "test"."t3"."a" AS "a" from "test"."t3" where <not>(("test"."t3"."a" < <max>(select '0' AS "b" from "test"."t2" group by 1)))
1391
1463
select * from t3 where a >= some (select b from t2 group by 1);
1393
1465
explain extended select * from t3 where a >= some (select b from t2 group by 1);
1394
1466
id select_type table type possible_keys key key_len ref rows filtered Extra
1395
1467
1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 Using where
1396
2 SUBQUERY t2 ALL NULL NULL NULL NULL 1 100.00 Using temporary; Using filesort
1468
2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found
1398
Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <nop>((`test`.`t3`.`a` >= <min>(select `test`.`t2`.`b` AS `b` from `test`.`t2` group by 1)))
1470
Note 1003 select "test"."t3"."a" AS "a" from "test"."t3" where <nop>(("test"."t3"."a" >= <min>(select '0' AS "b" from "test"."t2" group by 1)))
1399
1471
select * from t3 where NULL >= any (select b from t2);
1401
1473
explain extended select * from t3 where NULL >= any (select b from t2);
1402
1474
id select_type table type possible_keys key key_len ref rows filtered Extra
1403
1475
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
1404
2 SUBQUERY t2 ALL NULL NULL NULL NULL 1 100.00
1476
2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found
1406
Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
1478
Note 1003 select "test"."t3"."a" AS "a" from "test"."t3" where 0
1407
1479
select * from t3 where NULL >= any (select b from t2 group by 1);
1409
1481
explain extended select * from t3 where NULL >= any (select b from t2 group by 1);
1410
1482
id select_type table type possible_keys key key_len ref rows filtered Extra
1411
1483
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
1412
2 SUBQUERY t2 ALL NULL NULL NULL NULL 1 100.00 Using temporary; Using filesort
1484
2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found
1414
Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
1486
Note 1003 select "test"."t3"."a" AS "a" from "test"."t3" where 0
1415
1487
select * from t3 where NULL >= some (select b from t2);
1417
1489
explain extended select * from t3 where NULL >= some (select b from t2);
1418
1490
id select_type table type possible_keys key key_len ref rows filtered Extra
1419
1491
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
1420
2 SUBQUERY t2 ALL NULL NULL NULL NULL 1 100.00
1492
2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found
1422
Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
1494
Note 1003 select "test"."t3"."a" AS "a" from "test"."t3" where 0
1423
1495
select * from t3 where NULL >= some (select b from t2 group by 1);
1425
1497
explain extended select * from t3 where NULL >= some (select b from t2 group by 1);
1426
1498
id select_type table type possible_keys key key_len ref rows filtered Extra
1427
1499
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
1428
2 SUBQUERY t2 ALL NULL NULL NULL NULL 1 100.00 Using temporary; Using filesort
1500
2 SUBQUERY t2 system NULL NULL NULL NULL 0 0.00 const row not found
1430
Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where 0
1502
Note 1003 select "test"."t3"."a" AS "a" from "test"."t3" where 0
1431
1503
insert into t2 values (2,2), (2,1), (3,3), (3,1);
1432
1504
select * from t3 where a > all (select max(b) from t2 group by a);
1438
1510
1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00 Using where
1439
1511
2 SUBQUERY t2 ALL NULL NULL NULL NULL 4 100.00 Using temporary; Using filesort
1441
Note 1003 select `test`.`t3`.`a` AS `a` from `test`.`t3` where <not>((`test`.`t3`.`a` <= <max>(select max(`test`.`t2`.`b`) AS `max(b)` from `test`.`t2` group by `test`.`t2`.`a`)))
1513
Note 1003 select "test"."t3"."a" AS "a" from "test"."t3" where <not>(("test"."t3"."a" <= <max>(select max("test"."t2"."b") AS "max(b)" from "test"."t2" group by "test"."t2"."a")))
1442
1514
drop table t2, t3;
1443
CREATE TABLE `t1` ( `id` bigint NOT NULL auto_increment, `taskid` bigint NOT NULL default '0', `dbid` int NOT NULL default '0', `create_date` datetime NOT NULL default '0000-00-00 00:00:00', `last_update` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`id`)) ENGINE=MyISAM AUTO_INCREMENT=3 ;
1515
CREATE TABLE `t1` ( `id` mediumint(9) NOT NULL auto_increment, `taskid` bigint(20) NOT NULL default '0', `dbid` int(11) NOT NULL default '0', `create_date` datetime NOT NULL default '0000-00-00 00:00:00', `last_update` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`id`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=3 ;
1444
1516
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());
1445
CREATE TABLE `t2` (`db_id` int NOT NULL auto_increment,`name` varchar(200) NOT NULL default '',`primary_uid` int NOT NULL default '0',`secondary_uid` int NOT NULL default '0',PRIMARY KEY (`db_id`),UNIQUE KEY `name_2` (`name`)) ENGINE=MyISAM AUTO_INCREMENT=2147483647;
1517
CREATE TABLE `t2` (`db_id` int(11) NOT NULL auto_increment,`name` varchar(200) NOT NULL default '',`primary_uid` smallint(6) NOT NULL default '0',`secondary_uid` smallint(6) NOT NULL default '0',PRIMARY KEY (`db_id`),UNIQUE KEY `name_2` (`name`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=2147483647;
1446
1518
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);
1447
CREATE TABLE `t3` (`taskgenid` bigint NOT NULL auto_increment,`dbid` int NOT NULL default '0',`taskid` int NOT NULL default '0',`mon` int NOT NULL default '1',`tues` int NOT NULL default '1',`wed` int NOT NULL default '1',`thur` int NOT NULL default '1',`fri` int NOT NULL default '1',`sat` int NOT NULL default '0',`sun` int NOT NULL default '0',`how_often` int NOT NULL default '1',`userid` int NOT NULL default '0',`active` int NOT NULL default '1',PRIMARY KEY (`taskgenid`)) ENGINE=MyISAM AUTO_INCREMENT=2 ;
1519
CREATE TABLE `t3` (`taskgenid` mediumint(9) NOT NULL auto_increment,`dbid` int(11) NOT NULL default '0',`taskid` int(11) NOT NULL default '0',`mon` tinyint(4) NOT NULL default '1',`tues` tinyint(4) NOT NULL default '1',`wed` tinyint(4) NOT NULL default '1',`thur` tinyint(4) NOT NULL default '1',`fri` tinyint(4) NOT NULL default '1',`sat` tinyint(4) NOT NULL default '0',`sun` tinyint(4) NOT NULL default '0',`how_often` smallint(6) NOT NULL default '1',`userid` smallint(6) NOT NULL default '0',`active` tinyint(4) NOT NULL default '1',PRIMARY KEY (`taskgenid`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=2 ;
1448
1520
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);
1449
CREATE TABLE `t4` (`task_id` int NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM;
1521
CREATE TABLE `t4` (`task_id` smallint(6) NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1;
1450
1522
INSERT INTO `t4` (`task_id`, `description`) VALUES (1, 'Daily Check List'),(2, 'Weekly Status');
1451
1523
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;
1452
1524
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')
1522
1594
CREATE TABLE `t1` (
1523
`id` int NOT NULL auto_increment,
1524
`id_cns` int NOT NULL default '0',
1595
`id` int(11) NOT NULL auto_increment,
1596
`id_cns` tinyint(3) unsigned NOT NULL default '0',
1525
1597
`tipo` enum('','UNO','DUE') NOT NULL default '',
1526
`anno_dep` int NOT NULL default '0',
1527
`particolare` bigint NOT NULL default '0',
1528
`generale` bigint NOT NULL default '0',
1529
`bis` int NOT NULL default '0',
1598
`anno_dep` smallint(4) unsigned zerofill NOT NULL default '0000',
1599
`particolare` mediumint(8) unsigned NOT NULL default '0',
1600
`generale` mediumint(8) unsigned NOT NULL default '0',
1601
`bis` tinyint(3) unsigned NOT NULL default '0',
1530
1602
PRIMARY KEY (`id`),
1531
1603
UNIQUE KEY `idx_cns_gen_anno` (`anno_dep`,`id_cns`,`generale`,`particolare`),
1532
1604
UNIQUE KEY `idx_cns_par_anno` (`id_cns`,`anno_dep`,`tipo`,`particolare`,`bis`)
1534
1606
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);
1535
1607
CREATE TABLE `t2` (
1536
`id` int NOT NULL auto_increment,
1537
`max_anno_dep` int NOT NULL default '0',
1608
`id` tinyint(3) unsigned NOT NULL auto_increment,
1609
`max_anno_dep` smallint(6) unsigned NOT NULL default '0',
1538
1610
PRIMARY KEY (`id`)
1540
1612
INSERT INTO `t2` VALUES (16,1987),(50,1990),(51,1990);
1590
1662
1 PRIMARY t1 ALL NULL NULL NULL NULL 12 100.00 Using where
1591
1663
2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using index; Using where
1593
Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`text` AS `text` from `test`.`t1` where (not(<in_optimizer>(`test`.`t1`.`id`,<exists>(<primary_index_lookup>(<cache>(`test`.`t1`.`id`) in t1 on PRIMARY where ((`test`.`t1`.`id` < 8) and (<cache>(`test`.`t1`.`id`) = `test`.`t1`.`id`)))))))
1665
Note 1003 select "test"."t1"."id" AS "id","test"."t1"."text" AS "text" from "test"."t1" where (not(<in_optimizer>("test"."t1"."id",<exists>(<primary_index_lookup>(<cache>("test"."t1"."id") in t1 on PRIMARY where (("test"."t1"."id" < 8) and (<cache>("test"."t1"."id") = "test"."t1"."id")))))))
1594
1666
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);
1595
1667
id select_type table type possible_keys key key_len ref rows filtered Extra
1596
1668
1 PRIMARY tt ALL NULL NULL NULL NULL 12 100.00 Using where
1597
1669
2 DEPENDENT SUBQUERY t1 eq_ref PRIMARY PRIMARY 4 test.tt.id 1 100.00 Using where; Using index
1599
1671
Note 1276 Field or reference 'test.tt.id' of SELECT #2 was resolved in SELECT #1
1600
Note 1003 select `test`.`tt`.`id` AS `id`,`test`.`tt`.`text` AS `text` from `test`.`t1` `tt` where (not(exists(select `test`.`t1`.`id` AS `id` from `test`.`t1` where ((`test`.`t1`.`id` < 8) and (`test`.`t1`.`id` = `test`.`tt`.`id`)) having (`test`.`t1`.`id` is not null))))
1672
Note 1003 select "test"."tt"."id" AS "id","test"."tt"."text" AS "text" from "test"."t1" "tt" where (not(exists(select "test"."t1"."id" AS "id" from "test"."t1" where (("test"."t1"."id" < 8) and ("test"."t1"."id" = "test"."tt"."id")) having ("test"."t1"."id" is not null))))
1601
1673
insert into t1 (id, text) values (1000, 'text1000'), (1001, 'text1001');
1602
1674
create table t2 (id int not null, text varchar(20) not null default '', primary key (id));
1603
1675
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');
2231
2303
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;
2232
2304
(select b.x from t1 as b where b.x=a.x)
2234
CREATE TABLE `t1` ( `master` int NOT NULL default '0', `map` int NOT NULL default '0', `slave` int NOT NULL default '0', `access` int NOT NULL default '0', UNIQUE KEY `access_u` (`master`,`map`,`slave`));
2306
CREATE TABLE `t1` ( `master` int(10) unsigned NOT NULL default '0', `map` smallint(6) unsigned NOT NULL default '0', `slave` int(10) unsigned NOT NULL default '0', `access` int(10) unsigned NOT NULL default '0', UNIQUE KEY `access_u` (`master`,`map`,`slave`));
2235
2307
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);
2236
CREATE TABLE `t2` ( `id` int NOT NULL default '0', `pid` int NOT NULL default '0', `map` int NOT NULL default '0', `level` int NOT NULL default '0', `title` varchar(255) default NULL, PRIMARY KEY (`id`,`pid`,`map`), KEY `level` (`level`), KEY `id` (`id`,`map`)) ;
2308
CREATE TABLE `t2` ( `id` int(10) unsigned NOT NULL default '0', `pid` int(10) unsigned NOT NULL default '0', `map` smallint(6) unsigned NOT NULL default '0', `level` tinyint(4) unsigned NOT NULL default '0', `title` varchar(255) default NULL, PRIMARY KEY (`id`,`pid`,`map`), KEY `level` (`level`), KEY `id` (`id`,`map`)) ;
2237
2309
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');
2238
2310
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;
2239
2311
ERROR 42S22: Unknown column 'b.sc' in 'field list'
2275
2347
Continent enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL default 'Asia',
2276
2348
Region char(26) NOT NULL default '',
2277
2349
SurfaceArea float(10,2) NOT NULL default '0.00',
2278
IndepYear int default NULL,
2279
Population int NOT NULL default '0',
2350
IndepYear smallint(6) default NULL,
2351
Population int(11) NOT NULL default '0',
2280
2352
LifeExpectancy float(3,1) default NULL,
2281
2353
GNP float(10,2) default NULL,
2282
2354
GNPOld float(10,2) default NULL,
2283
2355
LocalName char(45) NOT NULL default '',
2284
2356
GovernmentForm char(45) NOT NULL default '',
2285
2357
HeadOfState char(60) default NULL,
2286
Capital int default NULL,
2358
Capital int(11) default NULL,
2287
2359
Code2 char(2) NOT NULL default ''
2288
2360
) ENGINE=MyISAM;
2289
2361
INSERT INTO t1 VALUES ('XXX','Xxxxx','Oceania','Xxxxxx',26.00,0,0,0,0,0,'Xxxxx','Xxxxx','Xxxxx',NULL,'XX');
2537
2631
1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00
2538
2632
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where
2540
Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one` AS `one`,`test`.`t2`.`two` AS `two` from `test`.`t2` where ((`test`.`t2`.`flag` = '0') and trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`)))) having (trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`))))) AS `test` from `test`.`t1`
2634
Note 1003 select "test"."t1"."one" AS "one","test"."t1"."two" AS "two",<in_optimizer>(("test"."t1"."one","test"."t1"."two"),<exists>(select "test"."t2"."one" AS "one","test"."t2"."two" AS "two" from "test"."t2" where (("test"."t2"."flag" = '0') and trigcond(((<cache>("test"."t1"."one") = "test"."t2"."one") or isnull("test"."t2"."one"))) and trigcond(((<cache>("test"."t1"."two") = "test"."t2"."two") or isnull("test"."t2"."two")))) having (trigcond(<is_not_null_test>("test"."t2"."one")) and trigcond(<is_not_null_test>("test"."t2"."two"))))) AS "test" from "test"."t1"
2541
2635
explain extended SELECT one,two from t1 where ROW(one,two) IN (SELECT one,two FROM t2 WHERE flag = 'N');
2542
2636
id select_type table type possible_keys key key_len ref rows filtered Extra
2543
2637
1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00 Start temporary
2544
2638
1 PRIMARY t2 ALL NULL NULL NULL NULL 9 100.00 Using where; End temporary; Using join buffer
2546
Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`two` = `test`.`t1`.`two`) and (`test`.`t2`.`one` = `test`.`t1`.`one`) and (`test`.`t2`.`flag` = 'N'))
2640
Note 1003 select "test"."t1"."one" AS "one","test"."t1"."two" AS "two" from "test"."t1" semi join ("test"."t2") where (("test"."t2"."two" = "test"."t1"."two") and ("test"."t2"."one" = "test"."t1"."one") and ("test"."t2"."flag" = 'N'))
2547
2641
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;
2548
2642
id select_type table type possible_keys key key_len ref rows filtered Extra
2549
2643
1 PRIMARY t1 ALL NULL NULL NULL NULL 8 100.00
2550
2644
2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 9 100.00 Using where; Using temporary; Using filesort
2552
Note 1003 select `test`.`t1`.`one` AS `one`,`test`.`t1`.`two` AS `two`,<in_optimizer>((`test`.`t1`.`one`,`test`.`t1`.`two`),<exists>(select `test`.`t2`.`one` AS `one`,`test`.`t2`.`two` AS `two` from `test`.`t2` where (`test`.`t2`.`flag` = '0') group by `test`.`t2`.`one`,`test`.`t2`.`two` having (trigcond(((<cache>(`test`.`t1`.`one`) = `test`.`t2`.`one`) or isnull(`test`.`t2`.`one`))) and trigcond(((<cache>(`test`.`t1`.`two`) = `test`.`t2`.`two`) or isnull(`test`.`t2`.`two`))) and trigcond(<is_not_null_test>(`test`.`t2`.`one`)) and trigcond(<is_not_null_test>(`test`.`t2`.`two`))))) AS `test` from `test`.`t1`
2646
Note 1003 select "test"."t1"."one" AS "one","test"."t1"."two" AS "two",<in_optimizer>(("test"."t1"."one","test"."t1"."two"),<exists>(select "test"."t2"."one" AS "one","test"."t2"."two" AS "two" from "test"."t2" where ("test"."t2"."flag" = '0') group by "test"."t2"."one","test"."t2"."two" having (trigcond(((<cache>("test"."t1"."one") = "test"."t2"."one") or isnull("test"."t2"."one"))) and trigcond(((<cache>("test"."t1"."two") = "test"."t2"."two") or isnull("test"."t2"."two"))) and trigcond(<is_not_null_test>("test"."t2"."one")) and trigcond(<is_not_null_test>("test"."t2"."two"))))) AS "test" from "test"."t1"
2553
2647
DROP TABLE t1,t2;
2554
2648
CREATE TABLE t1 (a char(5), b char(5));
2555
2649
INSERT INTO t1 VALUES (NULL,'aaa'), ('aaa','aaa');
3229
3345
explain select * from t1 where not exists
3230
3346
((select t11.i from t1 t11) union (select t12.i from t1 t12));
3231
3347
id select_type table type possible_keys key key_len ref rows Extra
3232
1 PRIMARY t1 ALL NULL NULL NULL NULL 1
3233
2 SUBQUERY t11 ALL NULL NULL NULL NULL 1
3234
3 UNION t12 ALL NULL NULL NULL NULL 1
3348
1 PRIMARY t1 system NULL NULL NULL NULL 0 const row not found
3349
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table
3350
3 UNION NULL NULL NULL NULL NULL NULL NULL no matching row in const table
3235
3351
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
3353
CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b));
3354
insert into t1 (a) values (FLOOR(rand() * 100));
3355
insert into t1 (a) select FLOOR(rand() * 100) from t1;
3356
insert into t1 (a) select FLOOR(rand() * 100) from t1;
3357
insert into t1 (a) select FLOOR(rand() * 100) from t1;
3358
insert into t1 (a) select FLOOR(rand() * 100) from t1;
3359
insert into t1 (a) select FLOOR(rand() * 100) from t1;
3360
insert into t1 (a) select FLOOR(rand() * 100) from t1;
3361
insert into t1 (a) select FLOOR(rand() * 100) from t1;
3362
insert into t1 (a) select FLOOR(rand() * 100) from t1;
3363
insert into t1 (a) select FLOOR(rand() * 100) from t1;
3364
insert into t1 (a) select FLOOR(rand() * 100) from t1;
3365
insert into t1 (a) select FLOOR(rand() * 100) from t1;
3366
insert into t1 (a) select FLOOR(rand() * 100) from t1;
3367
insert into t1 (a) select FLOOR(rand() * 100) from t1;
3369
(SELECT REPEAT(' ',250) FROM t1 i1
3370
WHERE i1.b=t1.a ORDER BY RAND() LIMIT 1) AS a
3371
FROM t1 ORDER BY a LIMIT 5;
3237
3379
CREATE TABLE t1 (a INT, b INT);
3238
3380
CREATE TABLE t2 (a INT);
3239
3381
INSERT INTO t2 values (1);
3700
3840
DROP TABLE t1, t2;
3841
CREATE TABLE t1 (s1 BINARY(5), s2 VARBINARY(5));
3842
INSERT INTO t1 VALUES (0x41,0x41), (0x42,0x42), (0x43,0x43);
3843
SELECT s1, s2 FROM t1 WHERE s2 IN (SELECT s1 FROM t1);
3845
SELECT s1, s2 FROM t1 WHERE (s2, 10) IN (SELECT s1, 10 FROM t1);
3847
CREATE INDEX I1 ON t1 (s1);
3848
CREATE INDEX I2 ON t1 (s2);
3849
SELECT s1, s2 FROM t1 WHERE s2 IN (SELECT s1 FROM t1);
3851
SELECT s1, s2 FROM t1 WHERE (s2, 10) IN (SELECT s1, 10 FROM t1);
3854
INSERT INTO t1 VALUES (0x41,0x41);
3855
SELECT * FROM t1 WHERE s1 = (SELECT s2 FROM t1);
3858
CREATE TABLE t1 (a1 VARBINARY(2) NOT NULL DEFAULT '0', PRIMARY KEY (a1));
3859
CREATE TABLE t2 (a2 BINARY(2) default '0', INDEX (a2));
3860
CREATE TABLE t3 (a3 BINARY(2) default '0');
3861
INSERT INTO t1 VALUES (1),(2),(3),(4);
3862
INSERT INTO t2 VALUES (1),(2),(3);
3863
INSERT INTO t3 VALUES (1),(2),(3);
3864
SELECT LEFT(t2.a2, 1) FROM t2,t3 WHERE t3.a3=t2.a2;
3869
SELECT t1.a1, t1.a1 in (SELECT t2.a2 FROM t2,t3 WHERE t3.a3=t2.a2) FROM t1;
3870
a1 t1.a1 in (SELECT t2.a2 FROM t2,t3 WHERE t3.a3=t2.a2)
3875
DROP TABLE t1,t2,t3;
3876
CREATE TABLE t1 (a1 BINARY(3) PRIMARY KEY, b1 VARBINARY(3));
3877
CREATE TABLE t2 (a2 VARBINARY(3) PRIMARY KEY);
3878
CREATE TABLE t3 (a3 VARBINARY(3) PRIMARY KEY);
3879
INSERT INTO t1 VALUES (1,10), (2,20), (3,30), (4,40);
3880
INSERT INTO t2 VALUES (2), (3), (4), (5);
3881
INSERT INTO t3 VALUES (10), (20), (30);
3882
SELECT LEFT(t1.a1,1) FROM t1,t3 WHERE t1.b1=t3.a3;
3887
SELECT a2 FROM t2 WHERE t2.a2 IN (SELECT t1.a1 FROM t1,t3 WHERE t1.b1=t3.a3);
3889
DROP TABLE t1, t2, t3;
3701
3890
CREATE TABLE t1 (a CHAR(1), b VARCHAR(10));
3702
3891
INSERT INTO t1 VALUES ('a', 'aa');
3703
3892
INSERT INTO t1 VALUES ('a', 'aaa');