106
110
select * from t3 where a in (select * from t2);
107
111
insert into t4 values (12,7),(1,7),(10,9),(9,6),(7,6),(3,9),(1,10);
109
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);
110
114
insert into t2 values (2,10);
111
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);
112
116
delete from t2 where a=2 and b=10;
113
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);
114
create table t5 (a int);
118
create temporary table t5 (a int) ENGINE=MyISAM;
115
119
select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2;
116
120
insert into t5 values (5);
117
121
select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2;
118
122
insert into t5 values (2);
119
123
select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2;
120
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;
122
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;
123
create table t6 (patient_uq int, clinic_uq int, index i1 (clinic_uq));
124
create table t7( uq int primary key, name char(25));
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;
125
130
insert into t7 values(1,"Oblastnaia bolnitsa"),(2,"Bolnitsa Krasnogo Kresta");
126
131
insert into t6 values (1,1),(1,2),(2,2),(1,3);
127
132
select * from t6 where exists (select * from t7 where uq = clinic_uq);
128
133
explain extended select * from t6 where exists (select * from t7 where uq = clinic_uq);
135
--echo # not unique fields
132
137
select * from t1 where a= (select a from t2,t4 where t2.b=t4.b);
134
# different tipes & group functions
139
--echo # different tipes & group functions
135
140
drop table t1,t2,t3;
137
142
CREATE TABLE t3 (a varchar(20),b char(1) NOT NULL default '0');
138
143
INSERT INTO t3 VALUES ('W','a'),('A','c'),('J','b');
139
144
CREATE TABLE t2 (a varchar(20),b int NOT NULL default '0');
140
145
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');
146
CREATE TABLE t1 (a varchar(20),b date NULL);
142
147
INSERT INTO t1 VALUES ('W','1732-02-22'),('A','1735-10-30'),('J','1743-04-13');
143
148
SELECT * FROM t1 WHERE b = (SELECT MIN(b) FROM t1);
144
149
SELECT * FROM t2 WHERE b = (SELECT MIN(b) FROM t2);
145
150
SELECT * FROM t3 WHERE b = (SELECT MIN(b) FROM t3);
147
152
CREATE TABLE `t8` (
148
`pseudo` varchar(35) character set latin1 NOT NULL default '',
149
`email` varchar(60) character set latin1 NOT NULL default '',
153
`pseudo` varchar(35) NOT NULL default '',
154
`email` varchar(60) NOT NULL default '',
150
155
PRIMARY KEY (`pseudo`),
151
156
UNIQUE KEY `email` (`email`)
152
) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
154
159
INSERT INTO t8 (pseudo,email) VALUES ('joce','test');
155
160
INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1');
156
161
INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1');
157
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');
159
165
SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM
455
446
select 1.5 > ANY (SELECT * from t1);
456
447
select 10.5 > ANY (SELECT * from t1);
457
448
explain extended select (select a+1) from t1;
458
450
select (select a+1) from t1;
454
--echo # Null with keys
465
CREATE TABLE t1 (a int NOT NULL default '0', PRIMARY KEY (a));
466
CREATE TABLE t2 (a int default '0', INDEX (a));
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;
467
459
INSERT INTO t1 VALUES (1),(2),(3),(4);
468
460
INSERT INTO t2 VALUES (1),(2),(3);
469
461
SELECT t1.a, t1.a in (select t2.a from t2) FROM t1;
470
462
explain extended SELECT t1.a, t1.a in (select t2.a from t2) FROM t1;
471
CREATE TABLE t3 (a int default '0');
463
CREATE TEMPORARY TABLE t3 (a int default '0') ENGINE=MyISAM;
472
464
INSERT INTO t3 VALUES (1),(2),(3);
473
465
SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
474
466
explain extended SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
475
467
drop table t1,t2,t3;
477
#LIMIT is not supported now
478
create table t1 (a float);
479
select 10.5 IN (SELECT * from t1 LIMIT 1);
480
select 10.5 IN (SELECT * from t1 LIMIT 1 UNION SELECT 1.5);
483
create table t1 (a int, b int, c varchar(10));
484
create table t2 (a int);
485
insert into t1 values (1,2,'a'),(2,3,'b'),(3,4,'c');
486
insert into t2 values (1),(2),(NULL);
487
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;
488
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;
489
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;
492
create table t1 (a int, b real, c varchar(10));
493
insert into t1 values (1, 1, 'a'), (2,2,'b'), (NULL, 2, 'b');
494
select ROW(1, 1, 'a') IN (select a,b,c from t1);
495
select ROW(1, 2, 'a') IN (select a,b,c from t1);
496
select ROW(1, 1, 'a') IN (select b,a,c from t1);
497
select ROW(1, 1, 'a') IN (select a,b,c from t1 where a is not null);
498
select ROW(1, 2, 'a') IN (select a,b,c from t1 where a is not null);
499
select ROW(1, 1, 'a') IN (select b,a,c from t1 where a is not null);
500
select ROW(1, 1, 'a') IN (select a,b,c from t1 where c='b' or c='a');
501
select ROW(1, 2, 'a') IN (select a,b,c from t1 where c='b' or c='a');
502
select ROW(1, 1, 'a') IN (select b,a,c from t1 where c='b' or c='a');
503
select ROW(1, 1, 'a') IN (select b,a,c from t1 limit 2);
506
#test of uncacheable subqueries
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;
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;
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;
501
--echo #test of uncacheable subqueries
507
502
CREATE TABLE t1 (a int);
508
503
EXPLAIN EXTENDED SELECT (SELECT RAND() FROM t1) FROM t1;
509
504
EXPLAIN EXTENDED SELECT (SELECT BENCHMARK(1,1) FROM t1) FROM t1;
514
`mot` varchar(30) character set latin1 NOT NULL default '',
515
`topic` bigint unsigned NOT NULL default '0',
516
`date` date NOT NULL default '0000-00-00',
517
`pseudo` varchar(35) character set latin1 NOT NULL default '',
518
PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`),
519
KEY `pseudo` (`pseudo`,`date`,`topic`),
520
KEY `topic` (`topic`)
521
) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
524
`mot` varchar(30) character set latin1 NOT NULL default '',
525
`topic` bigint unsigned NOT NULL default '0',
526
`date` date NOT NULL default '0000-00-00',
527
`pseudo` varchar(35) character set latin1 NOT NULL default '',
528
PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`),
529
KEY `pseudo` (`pseudo`,`date`,`topic`),
530
KEY `topic` (`topic`)
531
) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
534
`numeropost` bigint unsigned NOT NULL auto_increment,
535
`maxnumrep` int unsigned NOT NULL default '0',
508
CREATE TEMPORARY TABLE `t1` (
509
`mot` varchar(30) NOT NULL default '',
510
`topic` bigint NOT NULL default '0',
511
`date` date NULL DEFAULT '2009-01-20',
512
`pseudo` varchar(35) NOT NULL default '',
513
PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`),
514
KEY `pseudo` (`pseudo`,`date`,`topic`),
515
KEY `topic` (`topic`)
516
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
518
CREATE TEMPORARY TABLE `t2` (
519
`mot` varchar(30) NOT NULL default '',
520
`topic` bigint NOT NULL default '0',
521
`date` date NULL default '1997-08-29',
522
`pseudo` varchar(35) NOT NULL default '',
523
PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`),
524
KEY `pseudo` (`pseudo`,`date`,`topic`),
525
KEY `topic` (`topic`)
526
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
528
CREATE TEMPORARY TABLE `t3` (
529
`numeropost` bigint NOT NULL auto_increment,
530
`maxnumrep` int NOT NULL default '0',
536
531
PRIMARY KEY (`numeropost`),
537
532
UNIQUE KEY `maxnumrep` (`maxnumrep`)
538
) ENGINE=MyISAM CHARSET=latin1;
539
534
INSERT INTO t1 (mot, topic, pseudo) VALUES ('joce','1','joce'),('test','2','test');
541
536
INSERT INTO t2 (mot, topic, pseudo) VALUES ('joce','1','joce'),('test','2','test');
654
647
select * from t1;
662
) ENGINE=MyISAM CHARSET=latin1;
663
INSERT INTO t1 VALUES (1),(1),(2),(2),(1),(3);
666
name varchar(15) default NULL
667
) ENGINE=MyISAM CHARSET=latin1;
669
INSERT INTO t2 VALUES (4,'vita'), (1,'vita'), (2,'vita'), (1,'vita');
670
update t1, t2 set t2.name='lenka' where t2.id in (select id from t1);
675
# correct NULL in <CONSTANT> IN (SELECT ...)
677
create table t1 (a int, unique index indexa (a));
651
--echo # correct NULL in <CONSTANT> IN (SELECT ...)
653
create temporary table t1 (a int, unique index indexa (a)) ENGINE=MyISAM;
678
654
insert into t1 values (-1), (-4), (-2), (NULL);
679
655
select -10 IN (select a from t1 FORCE INDEX (indexa));
683
# Test optimization for sub selects
659
--echo # Test optimization for sub selects
685
661
create table t1 (id int not null auto_increment primary key, salary int, key(salary));
686
662
insert into t1 (salary) values (100),(1000),(10000),(10),(500),(5000),(50000);
687
664
explain extended SELECT id FROM t1 where salary = (SELECT MAX(salary) FROM t1);
690
667
CREATE TABLE t1 (
691
ID int unsigned NOT NULL auto_increment,
692
SUB_ID int unsigned NOT NULL default '0',
693
REF_ID int unsigned default NULL,
694
REF_SUB int unsigned default '0',
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',
695
672
PRIMARY KEY (ID,SUB_ID),
696
673
UNIQUE KEY t1_PK (ID,SUB_ID),
697
674
KEY t1_FK (REF_ID,REF_SUB),
698
675
KEY t1_REFID (REF_ID)
699
) ENGINE=MyISAM CHARSET=cp1251;
700
677
INSERT INTO t1 VALUES (1,0,NULL,NULL),(2,0,NULL,NULL);
701
678
SELECT DISTINCT REF_ID FROM t1 WHERE ID= (SELECT DISTINCT REF_ID FROM t1 WHERE ID=2);
705
# uninterruptable update
707
create table t1 (a int, b int);
708
create table t2 (a int, b int);
682
--echo # uninterruptable update
684
create temporary table t1 (a int, b int) ENGINE=MyISAM;
685
create temporary table t2 (a int, b int) ENGINE=MyISAM;
710
687
insert into t1 values (1,0), (2,0), (3,0);
711
688
insert into t2 values (1,1), (2,1), (3,1), (2,2);
716
693
drop table t1, t2;
719
# reduced subselect in ORDER BY & GROUP BY clauses
696
--echo # reduced subselect in ORDER BY & GROUP BY clauses
723
`id` bigint unsigned NOT NULL auto_increment,
699
CREATE TEMPORARY TABLE `t1` (
700
`id` bigint NOT NULL auto_increment,
724
701
`pseudo` varchar(35) NOT NULL default '',
725
702
`email` varchar(60) NOT NULL default '',
726
703
PRIMARY KEY (`id`),
727
704
UNIQUE KEY `email` (`email`),
728
705
UNIQUE KEY `pseudo` (`pseudo`)
729
) ENGINE=MyISAM CHARSET=latin1 PACK_KEYS=1 ROW_FORMAT=DYNAMIC;
706
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
730
707
INSERT INTO t1 (id,pseudo,email) VALUES (1,'test','test'),(2,'test1','test1');
731
708
SELECT pseudo as a, pseudo as b FROM t1 GROUP BY (SELECT a) ORDER BY (SELECT id*1);
732
709
drop table if exists t1;
734
711
(SELECT 1 as a) UNION (SELECT 1) ORDER BY (SELECT a+0);
737
# IN subselect optimization test
739
create table t1 (a int not null, b int, primary key (a));
740
create table t2 (a int not null, primary key (a));
741
create table t3 (a int not null, b int, primary key (a));
714
--echo # IN subselect optimization test
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;
742
719
insert into t1 values (1,10), (2,20), (3,30), (4,40);
743
720
insert into t2 values (2), (3), (4), (5);
744
721
insert into t3 values (10,3), (20,4), (30,5);
780
757
explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
781
758
drop table t1, t2, t3;
784
# alloc_group_fields() working
786
create table t1 (a int, b int);
787
create table t2 (a int, b int);
788
create table t3 (a int, b int);
761
--echo # alloc_group_fields() working
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;
789
766
insert into t1 values (0,100),(1,2), (1,3), (2,2), (2,7), (2,-1), (3,10);
790
767
insert into t2 values (0,0), (1,1), (2,1), (3,1), (4,1);
791
768
insert into t3 values (3,3), (2,2), (1,1);
792
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;
793
770
drop table t1,t2,t3;
796
# aggregate functions in HAVING test
798
create table t1 (s1 int);
799
create table t2 (s1 int);
773
--echo # aggregate functions in HAVING test
775
create temporary table t1 (s1 int) ENGINE=MyISAM;
776
create temporary table t2 (s1 int) ENGINE=MyISAM;
800
777
insert into t1 values (1);
801
778
insert into t2 values (1);
802
779
select * from t1 where exists (select s1 from t2 having max(t2.s1)=t1.s1);
803
780
drop table t1,t2;
806
# update subquery with wrong field (to force name resolving
807
# in UPDATE name space)
809
create table t1 (s1 int);
810
create table t2 (s1 int);
783
--echo # update subquery with wrong field (to force name resolving
784
--echo # in UPDATE name space)
786
create temporary table t1 (s1 int) ENGINE=MyISAM;
787
create temporary table t2 (s1 int) ENGINE=MyISAM;
811
788
insert into t1 values (1);
812
789
insert into t2 values (1);
814
791
update t1 set s1 = s1 + 1 where 1 = (select x.s1 as A from t2 WHERE t2.s1 > t1.s1 order by A);
815
792
DROP TABLE t1, t2;
820
CREATE TABLE t1 (s1 CHAR(5) COLLATE latin1_german1_ci,
821
s2 CHAR(5) COLLATE latin1_swedish_ci);
822
INSERT INTO t1 VALUES ('z','?');
823
select * from t1 where s1 > (select max(s2) from t1);
824
select * from t1 where s1 > any (select max(s2) from t1);
795
--echo # collation test
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;
828
# aggregate functions reinitialization
807
--echo # aggregate functions reinitialization
830
809
create table t1(toid int,rd int);
831
810
create table t2(userid int,pmnew int,pmtotal int);
832
811
insert into t2 values(1,0,0),(2,0,0);
887
865
explain extended select * from t3 where NULL >= some (select b from t2);
888
866
select * from t3 where NULL >= some (select b from t2 group by 1);
889
867
explain extended select * from t3 where NULL >= some (select b from t2 group by 1);
891
# optimized static ALL/ANY with grouping
869
--echo # optimized static ALL/ANY with grouping
893
871
insert into t2 values (2,2), (2,1), (3,3), (3,1);
894
872
select * from t3 where a > all (select max(b) from t2 group by a);
895
873
explain extended select * from t3 where a > all (select max(b) from t2 group by a);
896
874
drop table t2, t3;
899
# correct used_tables()
877
--echo # 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 CHARSET=latin1 AUTO_INCREMENT=3 ;
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 ;
903
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());
904
CREATE TABLE `t2` (`db_id` int NOT NULL auto_increment,`name` varchar(200) NOT NULL default '',`primary_uid` smallint NOT NULL default '0',`secondary_uid` smallint NOT NULL default '0',PRIMARY KEY (`db_id`),UNIQUE KEY `name_2` (`name`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=2147483647;
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;
905
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);
906
CREATE TABLE `t3` (`taskgenid` bigint NOT NULL auto_increment,`dbid` int NOT NULL default '0',`taskid` int NOT NULL default '0',`mon` tinyint NOT NULL default '1',`tues` tinyint NOT NULL default '1',`wed` tinyint NOT NULL default '1',`thur` tinyint NOT NULL default '1',`fri` tinyint NOT NULL default '1',`sat` tinyint NOT NULL default '0',`sun` tinyint NOT NULL default '0',`how_often` smallint NOT NULL default '1',`userid` smallint NOT NULL default '0',`active` tinyint NOT NULL default '1',PRIMARY KEY (`taskgenid`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=2 ;
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 ;
907
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);
908
CREATE TABLE `t4` (`task_id` smallint NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1;
886
CREATE TEMPORARY TABLE `t4` (`task_id` int NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM;
909
887
INSERT INTO `t4` (`task_id`, `description`) VALUES (1, 'Daily Check List'),(2, 'Weekly Status');
910
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;
911
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;
912
890
drop table t1,t2,t3,t4;
917
CREATE TABLE t1 (id int default NULL) ENGINE=MyISAM CHARSET=latin1;
893
--echo # cardinality check
895
CREATE TEMPORARY TABLE t1 (id int default NULL) ENGINE=MyISAM;
918
896
INSERT INTO t1 VALUES (1),(5);
919
CREATE TABLE t2 (id int default NULL) ENGINE=MyISAM CHARSET=latin1;
897
CREATE TEMPORARY TABLE t2 (id int default NULL) ENGINE=MyISAM;
920
898
INSERT INTO t2 VALUES (2),(6);
922
900
select * from t1 where (1,2,6) in (select * from t2);
923
901
DROP TABLE t1,t2;
926
# optimized ALL/ANY with union
904
--echo # optimized ALL/ANY with union
928
906
create table t1 (s1 char);
929
907
insert into t1 values ('e');
930
908
select * from t1 where 'f' > any (select s1 from t1);
931
909
select * from t1 where 'f' > any (select s1 from t1 union select s1 from t1);
932
911
explain extended select * from t1 where 'f' > any (select s1 from t1 union select s1 from t1);
936
# filesort in subquery (restoring join_tab)
938
CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1;
915
--echo # filesort in subquery (restoring join_tab)
917
CREATE TEMPORARY TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM;
939
918
INSERT INTO t1 VALUES ('69294728265'),('18621828126'),('89356874041'),('95895001874');
940
CREATE TABLE t2 (code char(5) NOT NULL default '',UNIQUE KEY code (code)) ENGINE=MyISAM CHARSET=latin1;
919
CREATE TEMPORARY TABLE t2 (code char(5) NOT NULL default '',UNIQUE KEY code (code)) ENGINE=MyISAM;
941
920
INSERT INTO t2 VALUES ('1'),('1226'),('1245'),('1862'),('18623'),('1874'),('1967'),('6');
942
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;
943
922
drop table t1, t2;
946
# unresolved field error
948
create table t1 (s1 int);
949
create table t2 (s1 int);
925
--echo # unresolved field error
927
create temporary table t1 (s1 int) ENGINE=MyISAM;
928
create temporary table t2 (s1 int) ENGINE=MyISAM;
951
930
select * from t1 where (select count(*) from t2 where t1.s2) = 1;
955
934
select count(*) from t2 group by t1.s2;
956
935
drop table t1, t2;
959
# fix_fields() in add_ref_to_table_cond()
961
CREATE TABLE t1(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC VARCHAR(20) DEFAULT NULL,PRIMARY KEY (COLA, COLB));
962
CREATE TABLE t2(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC CHAR(1) NOT NULL,PRIMARY KEY (COLA));
938
--echo # fix_fields() in add_ref_to_table_cond()
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;
963
942
INSERT INTO t1 VALUES (1,1,'1A3240'), (1,2,'4W2365');
964
943
INSERT INTO t2 VALUES (100, 200, 'C');
965
944
SELECT DISTINCT COLC FROM t1 WHERE COLA = (SELECT COLA FROM t2 WHERE COLB = 200 AND COLC ='C' LIMIT 1);
966
945
DROP TABLE t1, t2;
968
CREATE TABLE t1 (a int);
947
CREATE TEMPORARY TABLE t1 (a int) ENGINE=MyISAM;
969
948
INSERT INTO t1 VALUES (1),(1),(1),(1),(1),(2),(3),(4),(5);
970
949
SELECT DISTINCT (SELECT a) FROM t1 LIMIT 100;
956
CREATE TEMPORARY TABLE `t1` (
978
957
`id` int NOT NULL auto_increment,
979
`id_cns` tinyint unsigned NOT NULL default '0',
958
`id_cns` int NOT NULL default '0',
980
959
`tipo` enum('','UNO','DUE') NOT NULL default '',
981
`anno_dep` smallint unsigned NOT NULL default '0',
982
`particolare` bigint unsigned NOT NULL default '0',
983
`generale` bigint unsigned NOT NULL default '0',
984
`bis` tinyint unsigned NOT NULL default '0',
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',
985
964
PRIMARY KEY (`id`),
986
965
UNIQUE KEY `idx_cns_gen_anno` (`anno_dep`,`id_cns`,`generale`,`particolare`),
987
UNIQUE KEY `idx_cns_par_anno` (`id_cns`,`anno_dep`,`tipo`,`particolare`,`bis`)
966
UNIQUE KEY `idx_cns_par_anno` (`id_cns`,`anno_dep`,`tipo`,`particolare`,`bis`))
989
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);
991
`id` tinyint unsigned NOT NULL auto_increment,
992
`max_anno_dep` smallint unsigned NOT NULL default '0',
969
CREATE TEMPORARY TABLE `t2` (
970
`id` int NOT NULL auto_increment,
971
`max_anno_dep` int NOT NULL default '0',
972
PRIMARY KEY (`id`)) ENGINE=MyISAM;
995
973
INSERT INTO `t2` VALUES (16,1987),(50,1990),(51,1990);
997
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;
999
977
DROP TABLE t1, t2;
1004
create table t1 (a int);
980
--echo # GLOBAL LIMIT
982
create temporary table t1 (a int) ENGINE=MyISAM;
1005
983
insert into t1 values (1), (2), (3);
1006
984
SET SQL_SELECT_LIMIT=1;
1007
985
select sum(a) from (select * from t1) as a;
1009
987
SET SQL_SELECT_LIMIT=default;
1013
# Bug #3118: subselect + order by
991
--echo # Bug #3118: subselect + order by
1016
994
CREATE TABLE t1 (a int, b int, INDEX (a));
1017
995
INSERT INTO t1 VALUES (1, 1), (1, 2), (1, 3);
1018
996
SELECT * FROM t1 WHERE a = (SELECT MAX(a) FROM t1 WHERE a = 1) ORDER BY b;
1021
# Item_cond fix field
999
--echo # Item_cond fix field
1023
1001
create table t1(val varchar(10));
1024
1002
insert into t1 values ('aaa'), ('bbb'),('eee'),('mmm'),('ppp');
1025
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%');
1029
# ref_or_null replacing with ref
1007
--echo # ref_or_null replacing with ref
1031
1009
create table t1 (id int not null, text varchar(20) not null default '', primary key (id));
1032
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');
1033
1011
select * from t1 where id not in (select id from t1 where id < 8);
1034
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);
1013
--replace_column 9 #
1035
1014
explain extended select * from t1 where id not in (select id from t1 where id < 8);
1015
--replace_column 9 #
1036
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);
1037
1017
insert into t1 (id, text) values (1000, 'text1000'), (1001, 'text1001');
1038
create table t2 (id int not null, text varchar(20) not null default '', primary key (id));
1018
create temporary table t2 (id int not null, text varchar(20) not null default '', primary key (id)) ENGINE=MyISAM;
1039
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');
1040
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);
1021
--replace_column 9 #
1041
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);
1042
1023
drop table t1,t2;
1045
# Static tables & rund() in subqueries
1047
create table t1 (a int);
1026
--echo # Static tables & rund() in subqueries
1028
create temporary table t1 (a int) ENGINE=MyISAM;
1048
1029
insert into t1 values (1);
1049
1030
explain select benchmark(1000, (select a from t1 where a=rand()));
1055
create table t1(id int);
1056
create table t2(id int);
1057
create table t3(flag int);
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;
1059
1040
select (select * from t3 where id not null) from t1, t2;
1060
1041
drop table t1,t2,t3;
1063
# aggregate functions (Bug #3505)
1044
--echo # aggregate functions (Bug #3505)
1065
1046
CREATE TABLE t1 (id INT);
1066
1047
CREATE TABLE t2 (id INT);
1067
1048
INSERT INTO t1 VALUES (1), (2);
1263
1245
HAVING table2.t2_b = (SELECT MAX(t2_b) FROM t2 WHERE t2_a = table2.t2_a);
1264
1246
DROP TABLE t1, t2;
1267
# Test problem with NULL and derived tables (Bug #4097)
1249
--echo # Test problem with NULL and derived tables (Bug #4097)
1270
CREATE TABLE t1 (id int default NULL,name varchar(10) default NULL);
1252
CREATE TEMPORARY TABLE t1 (id int default NULL,name varchar(10) default NULL) ENGINE=MyISAM;
1271
1253
INSERT INTO t1 VALUES (1,'Tim'),(2,'Rebecca'),(3,NULL);
1272
CREATE TABLE t2 (id int default NULL, pet varchar(10) default NULL);
1254
CREATE TEMPORARY TABLE t2 (id int default NULL, pet varchar(10) default NULL) ENGINE=MyISAM;
1273
1255
INSERT INTO t2 VALUES (1,'Fido'),(2,'Spot'),(3,'Felix');
1274
1256
SELECT a.*, b.* FROM (SELECT * FROM t1) AS a JOIN t2 as b on a.id=b.id;
1275
1257
drop table t1,t2;
1278
# Aggregate function comparation with ALL/ANY/SOME subselect
1280
CREATE TABLE `t1` ( `a` int default NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1;
1260
--echo # Aggregate function comparation with ALL/ANY/SOME subselect
1262
CREATE TEMPORARY TABLE `t1` ( `a` int default NULL) ENGINE=MyISAM;
1281
1263
insert into t1 values (1);
1282
CREATE TABLE `t2` ( `b` int default NULL, `a` int default NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1;
1264
CREATE TEMPORARY TABLE `t2` ( `b` int default NULL, `a` int default NULL) ENGINE=MyISAM;
1283
1265
insert into t2 values (1,2);
1284
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);
1285
1267
drop table t1,t2;
1288
# BUG#5003 - like in subselect
1290
CREATE TABLE t1(`IZAVORGANG_ID` VARCHAR(11) CHARACTER SET latin1 COLLATE latin1_bin,`KUERZEL` VARCHAR(10) CHARACTER SET latin1 COLLATE latin1_bin,`IZAANALYSEART_ID` VARCHAR(11) CHARACTER SET latin1 COLLATE latin1_bin,`IZAPMKZ_ID` VARCHAR(11) CHARACTER SET latin1 COLLATE latin1_bin);
1270
--echo # BUG#5003 - like in subselect
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);
1291
1273
CREATE INDEX AK01IZAVORGANG ON t1(izaAnalyseart_id,Kuerzel);
1292
1274
INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000001','601','D0000000001','I0000000001');
1293
1275
INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000002','602','D0000000001','I0000000001');
1329
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;
1333
# Test of correct maybe_null flag returning by subquwery for temporary table
1336
CREATE TABLE `t1` ( `master` int unsigned NOT NULL default '0', `map` smallint unsigned NOT NULL default '0', `slave` int unsigned NOT NULL default '0', `access` int unsigned NOT NULL default '0', UNIQUE KEY `access_u` (`master`,`map`,`slave`));
1315
--echo # Test of correct maybe_null flag returning by subquwery for temporary table
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;
1337
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);
1338
CREATE TABLE `t2` ( `id` int unsigned NOT NULL default '0', `pid` int unsigned NOT NULL default '0', `map` smallint unsigned NOT NULL default '0', `level` tinyint unsigned NOT NULL default '0', `title` varchar(255) default NULL, PRIMARY KEY (`id`,`pid`,`map`), KEY `level` (`level`), KEY `id` (`id`,`map`)) ;
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 ;
1339
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');
1341
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;
1342
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;
1343
1325
drop tables t1,t2;
1346
# Subselect in non-select command just after connection
1328
--echo # Subselect in non-select command just after connection
1348
1330
connect (root,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
1349
1331
connection root;
1350
1332
set @got_val= (SELECT 1 FROM (SELECT 'A' as my_col) as T1 ) ;
1353
# primary query with temporary table and subquery with groupping
1355
create table t1 (a int, b int);
1356
create table t2 (a int, b int);
1335
--echo # primary query with temporary table and subquery with groupping
1337
create temporary table t1 (a int, b int) ENGINE=MyISAM;
1338
create temporary table t2 (a int, b int) ENGINE=MyISAM;
1357
1339
insert into t1 values (1,1),(1,2),(1,3),(2,4),(2,5);
1358
1340
insert into t2 values (1,3),(2,1);
1359
1341
select distinct a,b, (select max(b) from t2 where t1.b=t2.a) from t1 order by t1.b;
1360
1342
drop table t1, t2;
1363
# Equal operation under row and empty subquery
1345
--echo # Equal operation under row and empty subquery
1365
1347
create table t1 (s1 int,s2 int);
1366
1348
insert into t1 values (20,15);
1367
1349
select * from t1 where (('a',null) <=> (select 'a',s2 from t1 where s1 = 0));
1353
--echo # ALL/ANY with NULL
1373
1355
create table t1 (s1 int);
1374
1356
insert into t1 values (1),(null);
1375
1357
select * from t1 where s1 < all (select s1 from t1);
1376
1358
select s1, s1 < all (select s1 from t1) from t1;
1380
# reference on changable fields from subquery
1362
--echo # reference on changable fields from subquery
1382
1364
CREATE TABLE t1 (
1383
1365
Code char(3) NOT NULL default '',
1384
1366
Name char(52) NOT NULL default '',
1385
1367
Continent enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL default 'Asia',
1386
1368
Region char(26) NOT NULL default '',
1387
1369
SurfaceArea float(10,2) NOT NULL default '0.00',
1388
IndepYear smallint default NULL,
1370
IndepYear int default NULL,
1389
1371
Population int NOT NULL default '0',
1390
1372
LifeExpectancy float(3,1) default NULL,
1391
1373
GNP float(10,2) default NULL,
1583
1569
select (select * from t1) = (1,2,3);
1587
# Item_int_with_ref check (BUG#10020)
1590
`itemid` bigint unsigned NOT NULL auto_increment,
1591
`sessionid` bigint unsigned default NULL,
1592
`time` int unsigned NOT NULL default '0',
1593
`data` text collate latin1_general_ci NOT NULL,
1594
PRIMARY KEY (`itemid`)
1595
) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
1596
INSERT INTO `t1` VALUES (1, 1, 1, '');
1598
`sessionid` bigint unsigned NOT NULL auto_increment,
1599
`pid` int unsigned NOT NULL default '0',
1600
`date` int unsigned NOT NULL default '0',
1601
`ip` varchar(15) collate latin1_general_ci NOT NULL default '',
1602
PRIMARY KEY (`sessionid`)
1603
) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
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;
1573
--echo # Item_int_with_ref check (BUG#10020)
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`)
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`)
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;
1608
# BUG#11821 : Select from subselect using aggregate function on an enum
1610
create table t1 (fld enum('0','1'));
1594
--echo # BUG#11821 : Select from subselect using aggregate function on an enum
1596
create temporary table t1 (fld enum('0','1')) ENGINE=MyISAM;
1611
1597
insert into t1 values ('1');
1612
1598
select * from (select max(fld) from t1) as foo;
1616
# Bug #11867: queries with ROW(,elems>) IN (SELECT DISTINCT <cols> FROM ...)
1602
--echo # Bug #11867: queries with ROW(,elems>) IN (SELECT DISTINCT <cols> FROM ...)
1619
1605
CREATE TABLE t1 (one int, two int, flag char(1));
1620
1606
CREATE TABLE t2 (one int, two int, flag char(1));
2091
2078
('CCC', 7), ('AAA', 2), ('AAA', 4), ('BBB', 3), ('AAA', 8);
2093
2080
SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
2081
--replace_column 9 #
2095
2083
SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
2097
2085
ALTER TABLE t1 ADD INDEX(a);
2099
2087
SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
2088
--replace_column 9 #
2101
2090
SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
2106
# Bug#17366: Unchecked Item_int results in server crash
2095
--echo # Bug#17366: Unchecked Item_int results in server crash
2108
2097
create table t1( f1 int,f2 int);
2109
2098
insert into t1 values (1,1),(2,2);
2110
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';
2114
# Bug #18306: server crash on delete using subquery.
2103
--echo # Bug #18306: server crash on delete using subquery.
2117
create table t1 (c int, key(c));
2106
create temporary table t1 (c int, key(c)) ENGINE=MyISAM;
2118
2107
insert into t1 values (1142477582), (1142455969);
2119
create table t2 (a int, b int);
2108
create temporary table t2 (a int, b int) ENGINE=MyISAM;
2120
2109
insert into t2 values (2, 1), (1, 0);
2121
2110
delete from t1 where c <= 1140006215 and (select b from t2 where a = 2) = 1;
2122
2111
drop table t1, t2;
2125
# Bug#19077: A nested materialized derived table is used before being populated.
2114
--echo # Bug#19077: A nested materialized derived table is used before being populated.
2127
2116
create table t1 (i int, j bigint);
2128
2117
insert into t1 values (1, 2), (2, 2), (3, 2);
2129
2118
select * from (select min(i) from t1 where j=(select * from (select min(j) from t1) t2)) t3;
2133
# Bug#19700: subselect returning BIGINT always returned it as SIGNED
2135
CREATE TABLE t1 (i BIGINT UNSIGNED);
2136
INSERT INTO t1 VALUES (10000000000000000000); # > MAX SIGNED BIGINT 9323372036854775807
2122
--echo # Bug#19700: subselect returning BIGINT always returned it as SIGNED
2124
CREATE TEMPORARY TABLE t1 (i BIGINT) ENGINE=MyISAM;
2125
INSERT INTO t1 VALUES (10000000000000000); # > MAX SIGNED BIGINT 9323372036854775807
2137
2126
INSERT INTO t1 VALUES (1);
2139
CREATE TABLE t2 (i BIGINT UNSIGNED);
2140
INSERT INTO t2 VALUES (10000000000000000000); # same as first table
2128
CREATE TEMPORARY TABLE t2 (i BIGINT) ENGINE=MyISAM;
2129
INSERT INTO t2 VALUES (10000000000000000); # same as first table
2141
2130
INSERT INTO t2 VALUES (1);
2143
2132
/* simple test */
2647
2637
DROP TABLE t1,t2;
2651
# Bug #27333: subquery grouped for aggregate of outer query / no aggregate
2654
CREATE TABLE t1 (a INTEGER, b INTEGER);
2655
CREATE TABLE t2 (x INTEGER);
2641
--echo # Bug #27333: subquery grouped for aggregate of outer query / no aggregate
2642
--echo # of subquery
2644
CREATE TEMPORARY TABLE t1 (a INTEGER, b INTEGER) ENGINE=MyISAM;
2645
CREATE TEMPORARY TABLE t2 (x INTEGER) ENGINE=MyISAM;
2656
2646
INSERT INTO t1 VALUES (1,11), (2,22), (2,22);
2657
2647
INSERT INTO t2 VALUES (1), (2);
2659
# wasn't failing, but should
2649
--echo # wasn't failing, but should
2660
2650
--error ER_SUBQUERY_NO_1_ROW
2661
2651
SELECT a, COUNT(b), (SELECT COUNT(b) FROM t2) FROM t1 GROUP BY a;
2663
# fails as it should
2653
--echo # fails as it should
2664
2654
--error ER_SUBQUERY_NO_1_ROW
2665
2655
SELECT a, COUNT(b), (SELECT COUNT(b)+0 FROM t2) FROM t1 GROUP BY a;
2667
2657
SELECT (SELECT SUM(t1.a)/AVG(t2.x) FROM t2) FROM t1;
2668
2658
DROP TABLE t1,t2;
2670
# second test case from 27333
2660
--echo # second test case from 27333
2671
2661
CREATE TABLE t1 (a INT, b INT);
2672
2662
INSERT INTO t1 VALUES (1, 2), (1,3), (1,4), (2,1), (2,2);
2674
# returns no rows, when it should
2664
--echo # returns no rows, when it should
2675
2665
SELECT a1.a, COUNT(*) FROM t1 a1 WHERE a1.a = 1
2676
2666
AND EXISTS( SELECT a2.a FROM t1 a2 WHERE a2.a = a1.a)
2680
#test cases from 29297
2681
CREATE TABLE t1 (a INT);
2682
CREATE TABLE t2 (a INT);
2670
--echo #test cases from 29297
2671
CREATE TEMPORARY TABLE t1 (a INT) ENGINE=MyISAM;
2672
CREATE TEMPORARY TABLE t2 (a INT) ENGINE=MyISAM;
2683
2673
INSERT INTO t1 VALUES (1),(2);
2684
2674
INSERT INTO t2 VALUES (1),(2);
2685
2675
SELECT (SELECT SUM(t1.a) FROM t2 WHERE a=0) FROM t1;