465
CREATE TABLE t1 (a int NOT NULL default '0', PRIMARY KEY (a));
466
CREATE TABLE t2 (a int default '0', INDEX (a));
465
CREATE TABLE t1 (a int(11) NOT NULL default '0', PRIMARY KEY (a));
466
CREATE TABLE t2 (a int(11) default '0', INDEX (a));
467
467
INSERT INTO t1 VALUES (1),(2),(3),(4);
468
468
INSERT INTO t2 VALUES (1),(2),(3);
469
469
SELECT t1.a, t1.a in (select t2.a from t2) FROM t1;
470
470
explain extended SELECT t1.a, t1.a in (select t2.a from t2) FROM t1;
471
CREATE TABLE t3 (a int default '0');
471
CREATE TABLE t3 (a int(11) default '0');
472
472
INSERT INTO t3 VALUES (1),(2),(3);
473
473
SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
474
474
explain extended SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
475
475
drop table t1,t2,t3;
477
477
#LIMIT is not supported now
478
#create table t1 (a float);
480
#select 10.5 IN (SELECT * from t1 LIMIT 1);
482
#select 10.5 IN (SELECT * from t1 LIMIT 1 UNION SELECT 1.5);
485
#create table t1 (a int, b int, c varchar(10));
486
#create table t2 (a int);
487
#insert into t1 values (1,2,'a'),(2,3,'b'),(3,4,'c');
488
#insert into t2 values (1),(2),(NULL);
489
#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;
490
#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;
491
#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;
494
#create table t1 (a int, b real, c varchar(10));
495
#insert into t1 values (1, 1, 'a'), (2,2,'b'), (NULL, 2, 'b');
496
#select ROW(1, 1, 'a') IN (select a,b,c from t1);
497
#select ROW(1, 2, 'a') IN (select a,b,c from t1);
498
#select ROW(1, 1, 'a') IN (select b,a,c from t1);
499
#select ROW(1, 1, 'a') IN (select a,b,c from t1 where a is not null);
500
#select ROW(1, 2, 'a') IN (select a,b,c from t1 where a is not null);
501
#select ROW(1, 1, 'a') IN (select b,a,c from t1 where a is not null);
502
#select ROW(1, 1, 'a') IN (select a,b,c from t1 where c='b' or c='a');
503
#select ROW(1, 2, 'a') IN (select a,b,c from t1 where c='b' or c='a');
504
#select ROW(1, 1, 'a') IN (select b,a,c from t1 where c='b' or c='a');
506
#select ROW(1, 1, 'a') IN (select b,a,c from t1 limit 2);
478
create table t1 (a float);
480
select 10.5 IN (SELECT * from t1 LIMIT 1);
482
select 10.5 IN (SELECT * from t1 LIMIT 1 UNION SELECT 1.5);
485
create table t1 (a int, b int, c varchar(10));
486
create table t2 (a int);
487
insert into t1 values (1,2,'a'),(2,3,'b'),(3,4,'c');
488
insert into t2 values (1),(2),(NULL);
489
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;
490
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;
491
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;
494
create table t1 (a int, b real, c varchar(10));
495
insert into t1 values (1, 1, 'a'), (2,2,'b'), (NULL, 2, 'b');
496
select ROW(1, 1, 'a') IN (select a,b,c from t1);
497
select ROW(1, 2, 'a') IN (select a,b,c from t1);
498
select ROW(1, 1, 'a') IN (select b,a,c from t1);
499
select ROW(1, 1, 'a') IN (select a,b,c from t1 where a is not null);
500
select ROW(1, 2, 'a') IN (select a,b,c from t1 where a is not null);
501
select ROW(1, 1, 'a') IN (select b,a,c from t1 where a is not null);
502
select ROW(1, 1, 'a') IN (select a,b,c from t1 where c='b' or c='a');
503
select ROW(1, 2, 'a') IN (select a,b,c from t1 where c='b' or c='a');
504
select ROW(1, 1, 'a') IN (select b,a,c from t1 where c='b' or c='a');
506
select ROW(1, 1, 'a') IN (select b,a,c from t1 limit 2);
509
509
#test of uncacheable subqueries
510
CREATE TABLE t1 (a int);
510
CREATE TABLE t1 (a int(1));
511
511
EXPLAIN EXTENDED SELECT (SELECT RAND() FROM t1) FROM t1;
512
EXPLAIN EXTENDED SELECT (SELECT ENCRYPT('test') FROM t1) FROM t1;
512
513
EXPLAIN EXTENDED SELECT (SELECT BENCHMARK(1,1) FROM t1) FROM t1;
516
517
CREATE TABLE `t1` (
517
`mot` varchar(30) NOT NULL default '',
518
`topic` bigint NOT NULL default '0',
518
`mot` varchar(30) character set latin1 NOT NULL default '',
519
`topic` bigint(8) unsigned NOT NULL default '0',
519
520
`date` date NOT NULL default '0000-00-00',
520
`pseudo` varchar(35) NOT NULL default '',
521
`pseudo` varchar(35) character set latin1 NOT NULL default '',
521
522
PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`),
522
523
KEY `pseudo` (`pseudo`,`date`,`topic`),
523
524
KEY `topic` (`topic`)
524
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
525
) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
526
527
CREATE TABLE `t2` (
527
`mot` varchar(30) NOT NULL default '',
528
`topic` bigint NOT NULL default '0',
528
`mot` varchar(30) character set latin1 NOT NULL default '',
529
`topic` bigint(8) unsigned NOT NULL default '0',
529
530
`date` date NOT NULL default '0000-00-00',
530
`pseudo` varchar(35) NOT NULL default '',
531
`pseudo` varchar(35) character set latin1 NOT NULL default '',
531
532
PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`),
532
533
KEY `pseudo` (`pseudo`,`date`,`topic`),
533
534
KEY `topic` (`topic`)
534
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
535
) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
536
537
CREATE TABLE `t3` (
537
`numeropost` bigint NOT NULL auto_increment,
538
`maxnumrep` int NOT NULL default '0',
538
`numeropost` bigint(8) unsigned NOT NULL auto_increment,
539
`maxnumrep` int(10) unsigned NOT NULL default '0',
539
540
PRIMARY KEY (`numeropost`),
540
541
UNIQUE KEY `maxnumrep` (`maxnumrep`)
542
) ENGINE=MyISAM CHARSET=latin1;
542
543
INSERT INTO t1 (mot, topic, pseudo) VALUES ('joce','1','joce'),('test','2','test');
544
545
INSERT INTO t2 (mot, topic, pseudo) VALUES ('joce','1','joce'),('test','2','test');
899
896
# correct used_tables()
902
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 ;
899
CREATE TABLE `t1` ( `id` bigint(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 ;
903
900
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());
904
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;
901
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;
905
902
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);
906
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 ;
903
CREATE TABLE `t3` (`taskgenid` bigint(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 ;
907
904
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);
908
CREATE TABLE `t4` (`task_id` int NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM;
905
CREATE TABLE `t4` (`task_id` smallint(6) NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1;
909
906
INSERT INTO `t4` (`task_id`, `description`) VALUES (1, 'Daily Check List'),(2, 'Weekly Status');
910
907
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;
911
908
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;
977
974
CREATE TABLE `t1` (
978
`id` int NOT NULL auto_increment,
979
`id_cns` int NOT NULL default '0',
975
`id` int(11) NOT NULL auto_increment,
976
`id_cns` tinyint(3) unsigned NOT NULL default '0',
980
977
`tipo` enum('','UNO','DUE') NOT NULL default '',
981
`anno_dep` int NOT NULL default '0',
982
`particolare` bigint NOT NULL default '0',
983
`generale` bigint NOT NULL default '0',
984
`bis` int NOT NULL default '0',
978
`anno_dep` smallint(4) unsigned zerofill NOT NULL default '0000',
979
`particolare` bigint(8) unsigned NOT NULL default '0',
980
`generale` bigint(8) unsigned NOT NULL default '0',
981
`bis` tinyint(3) unsigned NOT NULL default '0',
985
982
PRIMARY KEY (`id`),
986
983
UNIQUE KEY `idx_cns_gen_anno` (`anno_dep`,`id_cns`,`generale`,`particolare`),
987
984
UNIQUE KEY `idx_cns_par_anno` (`id_cns`,`anno_dep`,`tipo`,`particolare`,`bis`)
989
986
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);
990
987
CREATE TABLE `t2` (
991
`id` int NOT NULL auto_increment,
992
`max_anno_dep` int NOT NULL default '0',
988
`id` tinyint(3) unsigned NOT NULL auto_increment,
989
`max_anno_dep` smallint(6) unsigned NOT NULL default '0',
993
990
PRIMARY KEY (`id`)
995
992
INSERT INTO `t2` VALUES (16,1987),(50,1990),(51,1990);
1333
1330
# Test of correct maybe_null flag returning by subquwery for temporary table
1336
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`));
1333
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`));
1337
1334
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);
1338
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`)) ;
1335
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`)) ;
1339
1336
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');
1341
1338
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;
1587
1584
# Item_int_with_ref check (BUG#10020)
1589
#CREATE TABLE `t1` (
1590
# `itemid` bigint NOT NULL auto_increment,
1591
# `sessionid` bigint default NULL,
1592
# `time` int NOT NULL default '0',
1593
# `data` text collate latin1_general_ci NOT NULL,
1594
# PRIMARY KEY (`itemid`)
1596
#INSERT INTO `t1` VALUES (1, 1, 1, '');
1597
#CREATE TABLE `t2` (
1598
# `sessionid` bigint NOT NULL auto_increment,
1599
# `pid` int NOT NULL default '0',
1600
# `date` int NOT NULL default '0',
1601
# `ip` varchar(15) collate latin1_general_ci NOT NULL default '',
1602
# PRIMARY KEY (`sessionid`)
1604
#INSERT INTO `t2` VALUES (1, 1, 1, '10.10.10.1');
1605
#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;
1587
`itemid` bigint(20) unsigned NOT NULL auto_increment,
1588
`sessionid` bigint(20) unsigned default NULL,
1589
`time` int(10) unsigned NOT NULL default '0',
1590
`type` set('A','D','E','F','G','I','L','N','U') collate latin1_general_ci NOT
1592
`data` text collate latin1_general_ci NOT NULL,
1593
PRIMARY KEY (`itemid`)
1594
) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
1595
INSERT INTO `t1` VALUES (1, 1, 1, 'D', '');
1597
`sessionid` bigint(20) unsigned NOT NULL auto_increment,
1598
`pid` int(10) unsigned NOT NULL default '0',
1599
`date` int(10) unsigned NOT NULL default '0',
1600
`ip` varchar(15) collate latin1_general_ci NOT NULL default '',
1601
PRIMARY KEY (`sessionid`)
1602
) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
1603
INSERT INTO `t2` VALUES (1, 1, 1, '10.10.10.1');
1604
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;
1608
1607
# BUG#11821 : Select from subselect using aggregate function on an enum
2704
2750
DROP TABLE t1, t2;
2753
# Bug #28076: inconsistent binary/varbinary comparison
2756
CREATE TABLE t1 (s1 BINARY(5), s2 VARBINARY(5));
2757
INSERT INTO t1 VALUES (0x41,0x41), (0x42,0x42), (0x43,0x43);
2759
SELECT s1, s2 FROM t1 WHERE s2 IN (SELECT s1 FROM t1);
2760
SELECT s1, s2 FROM t1 WHERE (s2, 10) IN (SELECT s1, 10 FROM t1);
2762
CREATE INDEX I1 ON t1 (s1);
2763
CREATE INDEX I2 ON t1 (s2);
2765
SELECT s1, s2 FROM t1 WHERE s2 IN (SELECT s1 FROM t1);
2766
SELECT s1, s2 FROM t1 WHERE (s2, 10) IN (SELECT s1, 10 FROM t1);
2769
INSERT INTO t1 VALUES (0x41,0x41);
2770
SELECT * FROM t1 WHERE s1 = (SELECT s2 FROM t1);
2774
CREATE TABLE t1 (a1 VARBINARY(2) NOT NULL DEFAULT '0', PRIMARY KEY (a1));
2775
CREATE TABLE t2 (a2 BINARY(2) default '0', INDEX (a2));
2776
CREATE TABLE t3 (a3 BINARY(2) default '0');
2777
INSERT INTO t1 VALUES (1),(2),(3),(4);
2778
INSERT INTO t2 VALUES (1),(2),(3);
2779
INSERT INTO t3 VALUES (1),(2),(3);
2780
SELECT LEFT(t2.a2, 1) FROM t2,t3 WHERE t3.a3=t2.a2;
2781
SELECT t1.a1, t1.a1 in (SELECT t2.a2 FROM t2,t3 WHERE t3.a3=t2.a2) FROM t1;
2782
DROP TABLE t1,t2,t3;
2784
CREATE TABLE t1 (a1 BINARY(3) PRIMARY KEY, b1 VARBINARY(3));
2785
CREATE TABLE t2 (a2 VARBINARY(3) PRIMARY KEY);
2786
CREATE TABLE t3 (a3 VARBINARY(3) PRIMARY KEY);
2787
INSERT INTO t1 VALUES (1,10), (2,20), (3,30), (4,40);
2788
INSERT INTO t2 VALUES (2), (3), (4), (5);
2789
INSERT INTO t3 VALUES (10), (20), (30);
2790
SELECT LEFT(t1.a1,1) FROM t1,t3 WHERE t1.b1=t3.a3;
2791
SELECT a2 FROM t2 WHERE t2.a2 IN (SELECT t1.a1 FROM t1,t3 WHERE t1.b1=t3.a3);
2792
DROP TABLE t1, t2, t3;
2707
2795
# Bug #30788: Inconsistent retrieval of char/varchar