134
134
# different tipes & group functions
135
135
drop table t1,t2,t3;
137
CREATE TABLE t3 (a varchar(20),b char(1) NOT NULL default '0') ENGINE=MyISAM;
137
CREATE TABLE t3 (a varchar(20),b char(1) NOT NULL default '0');
138
138
INSERT INTO t3 VALUES ('W','a'),('A','c'),('J','b');
139
CREATE TABLE t2 (a varchar(20),b int NOT NULL default '0') ENGINE=MyISAM;
139
CREATE TABLE t2 (a varchar(20),b int NOT NULL default '0');
140
140
INSERT INTO t2 VALUES ('W','1'),('A','3'),('J','2');
141
CREATE TABLE t1 (a varchar(20),b date NOT NULL default '0000-00-00') ENGINE=MyISAM;
141
CREATE TABLE t1 (a varchar(20),b date NOT NULL default '0000-00-00');
142
142
INSERT INTO t1 VALUES ('W','1732-02-22'),('A','1735-10-30'),('J','1743-04-13');
143
143
SELECT * FROM t1 WHERE b = (SELECT MIN(b) FROM t1);
144
144
SELECT * FROM t2 WHERE b = (SELECT MIN(b) FROM t2);
145
145
SELECT * FROM t3 WHERE b = (SELECT MIN(b) FROM t3);
147
147
CREATE TABLE `t8` (
148
`pseudo` varchar(35) NOT NULL default '',
149
`email` varchar(60) NOT NULL default '',
148
`pseudo` varchar(35) character set latin1 NOT NULL default '',
149
`email` varchar(60) character set latin1 NOT NULL default '',
150
150
PRIMARY KEY (`pseudo`),
151
151
UNIQUE KEY `email` (`email`)
152
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
152
) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
154
154
INSERT INTO t8 (pseudo,email) VALUES ('joce','test');
155
155
INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1');
470
CREATE TABLE t1 (a int NOT NULL default '0', PRIMARY KEY (a)) ENGINE=MyISAM;
471
CREATE TABLE t2 (a int default '0', INDEX (a)) ENGINE=MyISAM;
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));
472
467
INSERT INTO t1 VALUES (1),(2),(3),(4);
473
468
INSERT INTO t2 VALUES (1),(2),(3);
474
469
SELECT t1.a, t1.a in (select t2.a from t2) FROM t1;
475
470
explain extended SELECT t1.a, t1.a in (select t2.a from t2) FROM t1;
476
CREATE TABLE t3 (a int default '0') ENGINE=MyISAM;
471
CREATE TABLE t3 (a int(11) default '0');
477
472
INSERT INTO t3 VALUES (1),(2),(3);
478
473
SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
479
474
explain extended SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
480
475
drop table t1,t2,t3;
482
477
#LIMIT is not supported now
483
#create table t1 (a float) ENGINE=MyISAM;
485
#select 10.5 IN (SELECT * from t1 LIMIT 1);
487
#select 10.5 IN (SELECT * from t1 LIMIT 1 UNION SELECT 1.5);
490
#create table t1 (a int, b int, c varchar(10)) ENGINE=MyISAM;
491
#create table t2 (a int) ENGINE=MyISAM;
492
#insert into t1 values (1,2,'a'),(2,3,'b'),(3,4,'c');
493
#insert into t2 values (1),(2),(NULL);
494
#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;
495
#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;
496
#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;
499
#create table t1 (a int, b real, c varchar(10)) ENGINE=MyISAM;
500
#insert into t1 values (1, 1, 'a'), (2,2,'b'), (NULL, 2, 'b');
501
#select ROW(1, 1, 'a') IN (select a,b,c from t1);
502
#select ROW(1, 2, 'a') IN (select a,b,c from t1);
503
#select ROW(1, 1, 'a') IN (select b,a,c from t1);
504
#select ROW(1, 1, 'a') IN (select a,b,c from t1 where a is not null);
505
#select ROW(1, 2, 'a') IN (select a,b,c from t1 where a is not null);
506
#select ROW(1, 1, 'a') IN (select b,a,c from t1 where a is not null);
507
#select ROW(1, 1, 'a') IN (select a,b,c from t1 where c='b' or c='a');
508
#select ROW(1, 2, 'a') IN (select a,b,c from t1 where c='b' or c='a');
509
#select ROW(1, 1, 'a') IN (select b,a,c from t1 where c='b' or c='a');
511
#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);
514
509
#test of uncacheable subqueries
515
CREATE TABLE t1 (a int) ENGINE=MyISAM;
510
CREATE TABLE t1 (a int(1));
516
511
EXPLAIN EXTENDED SELECT (SELECT RAND() FROM t1) FROM t1;
512
EXPLAIN EXTENDED SELECT (SELECT ENCRYPT('test') FROM t1) FROM t1;
517
513
EXPLAIN EXTENDED SELECT (SELECT BENCHMARK(1,1) FROM t1) FROM t1;
521
517
CREATE TABLE `t1` (
522
`mot` varchar(30) NOT NULL default '',
523
`topic` bigint NOT NULL default '0',
518
`mot` varchar(30) character set latin1 NOT NULL default '',
519
`topic` mediumint(8) unsigned NOT NULL default '0',
524
520
`date` date NOT NULL default '0000-00-00',
525
`pseudo` varchar(35) NOT NULL default '',
521
`pseudo` varchar(35) character set latin1 NOT NULL default '',
526
522
PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`),
527
523
KEY `pseudo` (`pseudo`,`date`,`topic`),
528
524
KEY `topic` (`topic`)
529
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
525
) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
531
527
CREATE TABLE `t2` (
532
`mot` varchar(30) NOT NULL default '',
533
`topic` bigint NOT NULL default '0',
528
`mot` varchar(30) character set latin1 NOT NULL default '',
529
`topic` mediumint(8) unsigned NOT NULL default '0',
534
530
`date` date NOT NULL default '0000-00-00',
535
`pseudo` varchar(35) NOT NULL default '',
531
`pseudo` varchar(35) character set latin1 NOT NULL default '',
536
532
PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`),
537
533
KEY `pseudo` (`pseudo`,`date`,`topic`),
538
534
KEY `topic` (`topic`)
539
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
535
) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
541
537
CREATE TABLE `t3` (
542
`numeropost` bigint NOT NULL auto_increment,
543
`maxnumrep` int NOT NULL default '0',
538
`numeropost` mediumint(8) unsigned NOT NULL auto_increment,
539
`maxnumrep` int(10) unsigned NOT NULL default '0',
544
540
PRIMARY KEY (`numeropost`),
545
541
UNIQUE KEY `maxnumrep` (`maxnumrep`)
542
) ENGINE=MyISAM CHARSET=latin1;
547
543
INSERT INTO t1 (mot, topic, pseudo) VALUES ('joce','1','joce'),('test','2','test');
549
545
INSERT INTO t2 (mot, topic, pseudo) VALUES ('joce','1','joce'),('test','2','test');
825
#CREATE TABLE t1 (s1 CHAR(5) COLLATE latin1_german1_ci,
826
# s2 CHAR(5) COLLATE latin1_swedish_ci) ENGINE=MyISAM;
827
#INSERT INTO t1 VALUES ('z','?');
829
#select * from t1 where s1 > (select max(s2) from t1);
831
#select * from t1 where s1 > any (select max(s2) from t1);
817
CREATE TABLE t1 (s1 CHAR(5) COLLATE latin1_german1_ci,
818
s2 CHAR(5) COLLATE latin1_swedish_ci);
819
INSERT INTO t1 VALUES ('z','?');
821
select * from t1 where s1 > (select max(s2) from t1);
823
select * from t1 where s1 > any (select max(s2) from t1);
835
827
# aggregate functions reinitialization
837
create table t1(toid int,rd int) ENGINE=MyISAM;
838
create table t2(userid int,pmnew int,pmtotal int) ENGINE=MyISAM;
829
create table t1(toid int,rd int);
830
create table t2(userid int,pmnew int,pmtotal int);
839
831
insert into t2 values(1,0,0),(2,0,0);
840
832
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);
841
833
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);
904
896
# correct used_tables()
907
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` 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 ;
908
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());
909
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;
910
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);
911
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` 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 ;
912
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);
913
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;
914
906
INSERT INTO `t4` (`task_id`, `description`) VALUES (1, 'Daily Check List'),(2, 'Weekly Status');
915
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;
916
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;
982
974
CREATE TABLE `t1` (
983
`id` int NOT NULL auto_increment,
984
`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',
985
977
`tipo` enum('','UNO','DUE') NOT NULL default '',
986
`anno_dep` int NOT NULL default '0',
987
`particolare` bigint NOT NULL default '0',
988
`generale` bigint NOT NULL default '0',
989
`bis` int NOT NULL default '0',
978
`anno_dep` smallint(4) unsigned zerofill NOT NULL default '0000',
979
`particolare` mediumint(8) unsigned NOT NULL default '0',
980
`generale` mediumint(8) unsigned NOT NULL default '0',
981
`bis` tinyint(3) unsigned NOT NULL default '0',
990
982
PRIMARY KEY (`id`),
991
983
UNIQUE KEY `idx_cns_gen_anno` (`anno_dep`,`id_cns`,`generale`,`particolare`),
992
UNIQUE KEY `idx_cns_par_anno` (`id_cns`,`anno_dep`,`tipo`,`particolare`,`bis`))
984
UNIQUE KEY `idx_cns_par_anno` (`id_cns`,`anno_dep`,`tipo`,`particolare`,`bis`)
994
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);
995
987
CREATE TABLE `t2` (
996
`id` int NOT NULL auto_increment,
997
`max_anno_dep` int NOT NULL default '0',
998
PRIMARY KEY (`id`)) ENGINE=MyISAM;
988
`id` tinyint(3) unsigned NOT NULL auto_increment,
989
`max_anno_dep` smallint(6) unsigned NOT NULL default '0',
999
992
INSERT INTO `t2` VALUES (16,1987),(50,1990),(51,1990);
1001
994
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;
1033
1026
# ref_or_null replacing with ref
1035
create table t1 (id int not null, text varchar(20) not null default '', primary key (id)) ENGINE=MyISAM;
1028
create table t1 (id int not null, text varchar(20) not null default '', primary key (id));
1036
1029
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');
1037
1030
select * from t1 where id not in (select id from t1 where id < 8);
1038
1031
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);
1039
1032
explain extended select * from t1 where id not in (select id from t1 where id < 8);
1040
1033
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);
1041
1034
insert into t1 (id, text) values (1000, 'text1000'), (1001, 'text1001');
1042
create table t2 (id int not null, text varchar(20) not null default '', primary key (id)) ENGINE=MyISAM;
1035
create table t2 (id int not null, text varchar(20) not null default '', primary key (id));
1043
1036
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');
1044
1037
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);
1045
1038
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);
1337
1330
# Test of correct maybe_null flag returning by subquwery for temporary table
1340
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`)) ENGINE=MyISAM;
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`));
1341
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);
1342
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`)) ENGINE=MyISAM ;
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`)) ;
1343
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');
1345
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;
1595
1584
# Item_int_with_ref check (BUG#10020)
1597
#CREATE TABLE `t1` (
1598
# `itemid` bigint NOT NULL auto_increment,
1599
# `sessionid` bigint default NULL,
1600
# `time` int NOT NULL default '0',
1601
# `data` text collate latin1_general_ci NOT NULL,
1602
# PRIMARY KEY (`itemid`)
1604
#INSERT INTO `t1` VALUES (1, 1, 1, '');
1605
#CREATE TABLE `t2` (
1606
# `sessionid` bigint NOT NULL auto_increment,
1607
# `pid` int NOT NULL default '0',
1608
# `date` int NOT NULL default '0',
1609
# `ip` varchar(15) collate latin1_general_ci NOT NULL default '',
1610
# PRIMARY KEY (`sessionid`)
1612
#INSERT INTO `t2` VALUES (1, 1, 1, '10.10.10.1');
1613
#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;
1616
1607
# BUG#11821 : Select from subselect using aggregate function on an enum
1618
create table t1 (fld enum('0','1')) ENGINE=MyISAM;
1609
create table t1 (fld enum('0','1'));
1619
1610
insert into t1 values ('1');
1620
1611
select * from (select max(fld) from t1) as foo;
2524
2557
# Bug#27321: Wrong subquery result in a grouping select
2526
CREATE TABLE t1 (a int, b INT, d INT, c CHAR(10) NOT NULL, PRIMARY KEY (a, b)) ENGINE=MyISAM;
2559
CREATE TABLE t1 (a int, b INT, d INT, c CHAR(10) NOT NULL, PRIMARY KEY (a, b));
2527
2560
INSERT INTO t1 VALUES (1,1,0,'a'), (1,2,0,'b'), (1,3,0,'c'), (1,4,0,'d'),
2528
2561
(1,5,0,'e'), (2,1,0,'f'), (2,2,0,'g'), (2,3,0,'h'), (3,4,0,'i'), (3,3,0,'j'),
2529
2562
(3,2,0,'k'), (3,1,0,'l'), (1,9,0,'m'), (1,0,10,'n'), (2,0,5,'o'), (3,0,7,'p');
2718
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;
2721
2795
# Bug #30788: Inconsistent retrieval of char/varchar
2724
CREATE TABLE t1 (a CHAR(1), b VARCHAR(10)) ENGINE=MyISAM;
2798
CREATE TABLE t1 (a CHAR(1), b VARCHAR(10));
2725
2799
INSERT INTO t1 VALUES ('a', 'aa');
2726
2800
INSERT INTO t1 VALUES ('a', 'aaa');
2727
2801
SELECT a,b FROM t1 WHERE b IN (SELECT a FROM t1);