110
106
select * from t3 where a in (select * from t2);
111
107
insert into t4 values (12,7),(1,7),(10,9),(9,6),(7,6),(3,9),(1,10);
113
109
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
110
insert into t2 values (2,10);
115
111
select b,max(a) as ma from t4 group by b having ma < (select max(t2.a) from t2 where t2.b=t4.b);
116
112
delete from t2 where a=2 and b=10;
117
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);
118
create temporary table t5 (a int) ENGINE=MyISAM;
114
create table t5 (a int);
119
115
select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2;
120
116
insert into t5 values (5);
121
117
select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2;
122
118
insert into t5 values (2);
123
119
select (select a from t1 where t1.a=t2.a union select a from t5 where t5.a=t2.a), a from t2;
125
120
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;
127
122
select (select a from t1 where t1.a=t2.a union all select a from t5 where t5.a=t2.a), a from t2;
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;
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));
130
125
insert into t7 values(1,"Oblastnaia bolnitsa"),(2,"Bolnitsa Krasnogo Kresta");
131
126
insert into t6 values (1,1),(1,2),(2,2),(1,3);
132
127
select * from t6 where exists (select * from t7 where uq = clinic_uq);
133
128
explain extended select * from t6 where exists (select * from t7 where uq = clinic_uq);
135
--echo # not unique fields
137
132
select * from t1 where a= (select a from t2,t4 where t2.b=t4.b);
139
--echo # different tipes & group functions
134
# different tipes & group functions
140
135
drop table t1,t2,t3;
142
137
CREATE TABLE t3 (a varchar(20),b char(1) NOT NULL default '0');
143
138
INSERT INTO t3 VALUES ('W','a'),('A','c'),('J','b');
144
139
CREATE TABLE t2 (a varchar(20),b int NOT NULL default '0');
145
140
INSERT INTO t2 VALUES ('W','1'),('A','3'),('J','2');
146
CREATE TABLE t1 (a varchar(20),b date NULL);
141
CREATE TABLE t1 (a varchar(20),b date NOT NULL default '0000-00-00');
147
142
INSERT INTO t1 VALUES ('W','1732-02-22'),('A','1735-10-30'),('J','1743-04-13');
148
143
SELECT * FROM t1 WHERE b = (SELECT MIN(b) FROM t1);
149
144
SELECT * FROM t2 WHERE b = (SELECT MIN(b) FROM t2);
150
145
SELECT * FROM t3 WHERE b = (SELECT MIN(b) FROM t3);
152
147
CREATE TABLE `t8` (
153
`pseudo` varchar(35) NOT NULL default '',
154
`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 '',
155
150
PRIMARY KEY (`pseudo`),
156
151
UNIQUE KEY `email` (`email`)
152
) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
159
154
INSERT INTO t8 (pseudo,email) VALUES ('joce','test');
160
155
INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1');
161
156
INSERT INTO t8 (pseudo,email) VALUES ('2joce1','2test1');
163
157
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');
165
159
SELECT pseudo FROM t8 WHERE pseudo=(SELECT pseudo,email FROM
442
455
select 1.5 > ANY (SELECT * from t1);
443
456
select 10.5 > ANY (SELECT * from t1);
444
457
explain extended select (select a+1) from t1;
446
458
select (select a+1) from t1;
450
--echo # Null with keys
453
CREATE TEMPORARY TABLE t1 (a int NOT NULL default '0', PRIMARY KEY (a)) ENGINE=MyISAM;
454
CREATE TEMPORARY 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));
455
467
INSERT INTO t1 VALUES (1),(2),(3),(4);
456
468
INSERT INTO t2 VALUES (1),(2),(3);
457
469
SELECT t1.a, t1.a in (select t2.a from t2) FROM t1;
458
470
explain extended SELECT t1.a, t1.a in (select t2.a from t2) FROM t1;
459
CREATE TEMPORARY TABLE t3 (a int default '0') ENGINE=MyISAM;
471
CREATE TABLE t3 (a int(11) default '0');
460
472
INSERT INTO t3 VALUES (1),(2),(3);
461
473
SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
462
474
explain extended SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
463
475
drop table t1,t2,t3;
465
--echo #LIMIT is not supported now
466
--echo #create table t1 (a float) ENGINE=MyISAM;
467
--echo #-- error 1235
468
--echo #select 10.5 IN (SELECT * from t1 LIMIT 1);
469
--echo #-- error 1235
470
--echo #select 10.5 IN (SELECT * from t1 LIMIT 1 UNION SELECT 1.5);
471
--echo #drop table t1;
473
--echo #create table t1 (a int, b int, c varchar(10)) ENGINE=MyISAM;
474
--echo #create table t2 (a int) ENGINE=MyISAM;
475
--echo #insert into t1 values (1,2,'a'),(2,3,'b'),(3,4,'c');
476
--echo #insert into t2 values (1),(2),(NULL);
477
--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;
478
--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;
479
--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;
480
--echo #drop table t1,t2;
482
--echo #create table t1 (a int, b real, c varchar(10)) ENGINE=MyISAM;
483
--echo #insert into t1 values (1, 1, 'a'), (2,2,'b'), (NULL, 2, 'b');
484
--echo #select ROW(1, 1, 'a') IN (select a,b,c from t1);
485
--echo #select ROW(1, 2, 'a') IN (select a,b,c from t1);
486
--echo #select ROW(1, 1, 'a') IN (select b,a,c from t1);
487
--echo #select ROW(1, 1, 'a') IN (select a,b,c from t1 where a is not null);
488
--echo #select ROW(1, 2, 'a') IN (select a,b,c from t1 where a is not null);
489
--echo #select ROW(1, 1, 'a') IN (select b,a,c from t1 where a is not null);
490
--echo #select ROW(1, 1, 'a') IN (select a,b,c from t1 where c='b' or c='a');
491
--echo #select ROW(1, 2, 'a') IN (select a,b,c from t1 where c='b' or c='a');
492
--echo #select ROW(1, 1, 'a') IN (select b,a,c from t1 where c='b' or c='a');
493
--echo #-- error 1235
494
--echo #select ROW(1, 1, 'a') IN (select b,a,c from t1 limit 2);
495
--echo #drop table t1;
497
--echo #test of uncacheable subqueries
498
CREATE TABLE t1 (a int);
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);
509
#test of uncacheable subqueries
510
CREATE TABLE t1 (a int(1));
499
511
EXPLAIN EXTENDED SELECT (SELECT RAND() FROM t1) FROM t1;
512
EXPLAIN EXTENDED SELECT (SELECT ENCRYPT('test') FROM t1) FROM t1;
500
513
EXPLAIN EXTENDED SELECT (SELECT BENCHMARK(1,1) FROM t1) FROM t1;
504
CREATE TEMPORARY TABLE `t1` (
505
`mot` varchar(30) NOT NULL default '',
506
`topic` bigint NOT NULL default '0',
507
`date` date NULL DEFAULT '2009-01-20',
508
`pseudo` varchar(35) NOT NULL default '',
509
PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`),
510
KEY `pseudo` (`pseudo`,`date`,`topic`),
511
KEY `topic` (`topic`)
512
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
514
CREATE TEMPORARY TABLE `t2` (
515
`mot` varchar(30) NOT NULL default '',
516
`topic` bigint NOT NULL default '0',
517
`date` date NULL default '1997-08-29',
518
`pseudo` varchar(35) NOT NULL default '',
519
PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`),
520
KEY `pseudo` (`pseudo`,`date`,`topic`),
521
KEY `topic` (`topic`)
522
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
524
CREATE TEMPORARY TABLE `t3` (
525
`numeropost` bigint NOT NULL auto_increment,
526
`maxnumrep` int NOT NULL default '0',
518
`mot` varchar(30) character set latin1 NOT NULL default '',
519
`topic` mediumint(8) unsigned NOT NULL default '0',
520
`date` date NOT NULL default '0000-00-00',
521
`pseudo` varchar(35) character set latin1 NOT NULL default '',
522
PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`),
523
KEY `pseudo` (`pseudo`,`date`,`topic`),
524
KEY `topic` (`topic`)
525
) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
528
`mot` varchar(30) character set latin1 NOT NULL default '',
529
`topic` mediumint(8) unsigned NOT NULL default '0',
530
`date` date NOT NULL default '0000-00-00',
531
`pseudo` varchar(35) character set latin1 NOT NULL default '',
532
PRIMARY KEY (`mot`,`pseudo`,`date`,`topic`),
533
KEY `pseudo` (`pseudo`,`date`,`topic`),
534
KEY `topic` (`topic`)
535
) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
538
`numeropost` mediumint(8) unsigned NOT NULL auto_increment,
539
`maxnumrep` int(10) unsigned NOT NULL default '0',
527
540
PRIMARY KEY (`numeropost`),
528
541
UNIQUE KEY `maxnumrep` (`maxnumrep`)
542
) ENGINE=MyISAM CHARSET=latin1;
530
543
INSERT INTO t1 (mot, topic, pseudo) VALUES ('joce','1','joce'),('test','2','test');
532
545
INSERT INTO t2 (mot, topic, pseudo) VALUES ('joce','1','joce'),('test','2','test');
593
605
Continent enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL default 'Asia',
594
606
Region char(26) NOT NULL default '',
595
607
SurfaceArea float(10,2) NOT NULL default '0.00',
596
IndepYear int default NULL,
597
Population int NOT NULL default '0',
608
IndepYear smallint(6) default NULL,
609
Population int(11) NOT NULL default '0',
598
610
LifeExpectancy float(3,1) default NULL,
599
611
GNP float(10,2) default NULL,
600
612
GNPOld float(10,2) default NULL,
601
613
LocalName char(45) NOT NULL default '',
602
614
GovernmentForm char(45) NOT NULL default '',
603
615
HeadOfState char(60) default NULL,
604
Capital int default NULL,
616
Capital int(11) default NULL,
605
617
Code2 char(2) NOT NULL default '',
606
618
PRIMARY KEY (Code)
609
621
INSERT INTO t2 VALUES ('AUS','Australia','Oceania','Australia and New Zealand',7741220.00,1901,18886000,79.8,351182.00,392911.00,'Australia','Constitutional Monarchy, Federation','Elisabeth II',135,'AU');
610
622
INSERT INTO t2 VALUES ('AZE','Azerbaijan','Asia','Middle East',86600.00,1991,7734000,62.9,4127.00,4100.00,'Azärbaycan','Federal Republic','Heydär Äliyev',144,'AZ');
643
655
select * from t1;
647
--echo # correct NULL in <CONSTANT> IN (SELECT ...)
649
create temporary table t1 (a int, unique index indexa (a)) ENGINE=MyISAM;
662
id int(11) default NULL
663
) ENGINE=MyISAM CHARSET=latin1;
664
INSERT INTO t1 VALUES (1),(1),(2),(2),(1),(3);
666
id int(11) default NULL,
667
name varchar(15) default NULL
668
) ENGINE=MyISAM CHARSET=latin1;
670
INSERT INTO t2 VALUES (4,'vita'), (1,'vita'), (2,'vita'), (1,'vita');
671
update t1, t2 set t2.name='lenka' where t2.id in (select id from t1);
676
# correct NULL in <CONSTANT> IN (SELECT ...)
678
create table t1 (a int, unique index indexa (a));
650
679
insert into t1 values (-1), (-4), (-2), (NULL);
651
680
select -10 IN (select a from t1 FORCE INDEX (indexa));
655
--echo # Test optimization for sub selects
684
# Test optimization for sub selects
657
686
create table t1 (id int not null auto_increment primary key, salary int, key(salary));
658
687
insert into t1 (salary) values (100),(1000),(10000),(10),(500),(5000),(50000);
660
688
explain extended SELECT id FROM t1 where salary = (SELECT MAX(salary) FROM t1);
663
691
CREATE TABLE t1 (
664
ID int NOT NULL auto_increment,
665
SUB_ID int NOT NULL default '0',
666
REF_ID int default NULL,
667
REF_SUB int default '0',
692
ID int(10) unsigned NOT NULL auto_increment,
693
SUB_ID int(3) unsigned NOT NULL default '0',
694
REF_ID int(10) unsigned default NULL,
695
REF_SUB int(3) unsigned default '0',
668
696
PRIMARY KEY (ID,SUB_ID),
669
697
UNIQUE KEY t1_PK (ID,SUB_ID),
670
698
KEY t1_FK (REF_ID,REF_SUB),
671
699
KEY t1_REFID (REF_ID)
700
) ENGINE=MyISAM CHARSET=cp1251;
673
701
INSERT INTO t1 VALUES (1,0,NULL,NULL),(2,0,NULL,NULL);
674
702
SELECT DISTINCT REF_ID FROM t1 WHERE ID= (SELECT DISTINCT REF_ID FROM t1 WHERE ID=2);
678
--echo # uninterruptable update
680
create temporary table t1 (a int, b int) ENGINE=MyISAM;
681
create temporary table t2 (a int, b int) ENGINE=MyISAM;
706
# uninterruptable update
708
create table t1 (a int, b int);
709
create table t2 (a int, b int);
683
711
insert into t1 values (1,0), (2,0), (3,0);
684
712
insert into t2 values (1,1), (2,1), (3,1), (2,2);
689
717
drop table t1, t2;
692
--echo # reduced subselect in ORDER BY & GROUP BY clauses
720
# reduced subselect in ORDER BY & GROUP BY clauses
695
CREATE TEMPORARY TABLE `t1` (
696
`id` bigint NOT NULL auto_increment,
724
`id` mediumint(8) unsigned NOT NULL auto_increment,
697
725
`pseudo` varchar(35) NOT NULL default '',
698
726
`email` varchar(60) NOT NULL default '',
699
727
PRIMARY KEY (`id`),
700
728
UNIQUE KEY `email` (`email`),
701
729
UNIQUE KEY `pseudo` (`pseudo`)
702
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
730
) ENGINE=MyISAM CHARSET=latin1 PACK_KEYS=1 ROW_FORMAT=DYNAMIC;
703
731
INSERT INTO t1 (id,pseudo,email) VALUES (1,'test','test'),(2,'test1','test1');
704
732
SELECT pseudo as a, pseudo as b FROM t1 GROUP BY (SELECT a) ORDER BY (SELECT id*1);
705
733
drop table if exists t1;
707
735
(SELECT 1 as a) UNION (SELECT 1) ORDER BY (SELECT a+0);
710
--echo # IN subselect optimization test
712
create temporary table t1 (a int not null, b int, primary key (a)) ENGINE=MyISAM;
713
create temporary table t2 (a int not null, primary key (a)) ENGINE=MyISAM;
714
create temporary table t3 (a int not null, b int, primary key (a)) ENGINE=MyISAM;
738
# IN subselect optimization test
740
create table t1 (a int not null, b int, primary key (a));
741
create table t2 (a int not null, primary key (a));
742
create table t3 (a int not null, b int, primary key (a));
715
743
insert into t1 values (1,10), (2,20), (3,30), (4,40);
716
744
insert into t2 values (2), (3), (4), (5);
717
745
insert into t3 values (10,3), (20,4), (30,5);
753
777
explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30);
754
778
drop table t1, t2, t3;
757
--echo # alloc_group_fields() working
759
create temporary table t1 (a int, b int) ENGINE=MyISAM;
760
create temporary table t2 (a int, b int) ENGINE=MyISAM;
761
create temporary table t3 (a int, b int) ENGINE=MyISAM;
781
# alloc_group_fields() working
783
create table t1 (a int, b int);
784
create table t2 (a int, b int);
785
create table t3 (a int, b int);
762
786
insert into t1 values (0,100),(1,2), (1,3), (2,2), (2,7), (2,-1), (3,10);
763
787
insert into t2 values (0,0), (1,1), (2,1), (3,1), (4,1);
764
788
insert into t3 values (3,3), (2,2), (1,1);
765
789
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;
766
790
drop table t1,t2,t3;
769
--echo # aggregate functions in HAVING test
771
create temporary table t1 (s1 int) ENGINE=MyISAM;
772
create temporary table t2 (s1 int) ENGINE=MyISAM;
793
# aggregate functions in HAVING test
795
create table t1 (s1 int);
796
create table t2 (s1 int);
773
797
insert into t1 values (1);
774
798
insert into t2 values (1);
775
799
select * from t1 where exists (select s1 from t2 having max(t2.s1)=t1.s1);
776
800
drop table t1,t2;
779
--echo # update subquery with wrong field (to force name resolving
780
--echo # in UPDATE name space)
782
create temporary table t1 (s1 int) ENGINE=MyISAM;
783
create temporary table t2 (s1 int) ENGINE=MyISAM;
803
# update subquery with wrong field (to force name resolving
804
# in UPDATE name space)
806
create table t1 (s1 int);
807
create table t2 (s1 int);
784
808
insert into t1 values (1);
785
809
insert into t2 values (1);
787
811
update t1 set s1 = s1 + 1 where 1 = (select x.s1 as A from t2 WHERE t2.s1 > t1.s1 order by A);
788
812
DROP TABLE t1, t2;
791
--echo # collation test
793
--echo #CREATE TABLE t1 (s1 CHAR(5) COLLATE latin1_german1_ci,
794
--echo # s2 CHAR(5) COLLATE latin1_swedish_ci) ENGINE=MyISAM;
795
--echo #INSERT INTO t1 VALUES ('z','?');
796
--echo #-- error 1267
797
--echo #select * from t1 where s1 > (select max(s2) from t1);
798
--echo #-- error 1267
799
--echo #select * from t1 where s1 > any (select max(s2) from t1);
800
--echo #drop table 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);
803
--echo # aggregate functions reinitialization
827
# aggregate functions reinitialization
805
829
create table t1(toid int,rd int);
806
830
create table t2(userid int,pmnew int,pmtotal int);
807
831
insert into t2 values(1,0,0),(2,0,0);
861
884
explain extended select * from t3 where NULL >= some (select b from t2);
862
885
select * from t3 where NULL >= some (select b from t2 group by 1);
863
886
explain extended select * from t3 where NULL >= some (select b from t2 group by 1);
865
--echo # optimized static ALL/ANY with grouping
888
# optimized static ALL/ANY with grouping
867
890
insert into t2 values (2,2), (2,1), (3,3), (3,1);
868
891
select * from t3 where a > all (select max(b) from t2 group by a);
869
892
explain extended select * from t3 where a > all (select max(b) from t2 group by a);
870
893
drop table t2, t3;
873
--echo # correct used_tables()
896
# correct used_tables()
876
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 ;
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 ;
877
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());
878
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;
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;
879
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);
880
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 ;
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 ;
881
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);
882
CREATE TEMPORARY 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;
883
906
INSERT INTO `t4` (`task_id`, `description`) VALUES (1, 'Daily Check List'),(2, 'Weekly Status');
884
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;
885
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;
886
909
drop table t1,t2,t3,t4;
889
--echo # cardinality check
891
CREATE TEMPORARY TABLE t1 (id int default NULL) ENGINE=MyISAM;
914
CREATE TABLE t1 (id int(11) default NULL) ENGINE=MyISAM CHARSET=latin1;
892
915
INSERT INTO t1 VALUES (1),(5);
893
CREATE TEMPORARY TABLE t2 (id int default NULL) ENGINE=MyISAM;
916
CREATE TABLE t2 (id int(11) default NULL) ENGINE=MyISAM CHARSET=latin1;
894
917
INSERT INTO t2 VALUES (2),(6);
896
919
select * from t1 where (1,2,6) in (select * from t2);
897
920
DROP TABLE t1,t2;
900
--echo # optimized ALL/ANY with union
923
# optimized ALL/ANY with union
902
925
create table t1 (s1 char);
903
926
insert into t1 values ('e');
904
927
select * from t1 where 'f' > any (select s1 from t1);
905
928
select * from t1 where 'f' > any (select s1 from t1 union select s1 from t1);
907
929
explain extended select * from t1 where 'f' > any (select s1 from t1 union select s1 from t1);
911
--echo # filesort in subquery (restoring join_tab)
913
CREATE TEMPORARY TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM;
933
# filesort in subquery (restoring join_tab)
935
CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1;
914
936
INSERT INTO t1 VALUES ('69294728265'),('18621828126'),('89356874041'),('95895001874');
915
CREATE TEMPORARY TABLE t2 (code char(5) NOT NULL default '',UNIQUE KEY code (code)) ENGINE=MyISAM;
937
CREATE TABLE t2 (code char(5) NOT NULL default '',UNIQUE KEY code (code)) ENGINE=MyISAM CHARSET=latin1;
916
938
INSERT INTO t2 VALUES ('1'),('1226'),('1245'),('1862'),('18623'),('1874'),('1967'),('6');
917
939
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;
918
940
drop table t1, t2;
921
--echo # unresolved field error
923
create temporary table t1 (s1 int) ENGINE=MyISAM;
924
create temporary table t2 (s1 int) ENGINE=MyISAM;
943
# unresolved field error
945
create table t1 (s1 int);
946
create table t2 (s1 int);
926
948
select * from t1 where (select count(*) from t2 where t1.s2) = 1;
930
952
select count(*) from t2 group by t1.s2;
931
953
drop table t1, t2;
934
--echo # fix_fields() in add_ref_to_table_cond()
936
CREATE TEMPORARY TABLE t1(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC VARCHAR(20) DEFAULT NULL,PRIMARY KEY (COLA, COLB)) ENGINE=MyISAM;
937
CREATE TEMPORARY TABLE t2(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC CHAR(1) NOT NULL,PRIMARY KEY (COLA)) ENGINE=MyISAM;
956
# fix_fields() in add_ref_to_table_cond()
958
CREATE TABLE t1(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC VARCHAR(20) DEFAULT NULL,PRIMARY KEY (COLA, COLB));
959
CREATE TABLE t2(COLA FLOAT NOT NULL,COLB FLOAT NOT NULL,COLC CHAR(1) NOT NULL,PRIMARY KEY (COLA));
938
960
INSERT INTO t1 VALUES (1,1,'1A3240'), (1,2,'4W2365');
939
961
INSERT INTO t2 VALUES (100, 200, 'C');
940
962
SELECT DISTINCT COLC FROM t1 WHERE COLA = (SELECT COLA FROM t2 WHERE COLB = 200 AND COLC ='C' LIMIT 1);
941
963
DROP TABLE t1, t2;
943
CREATE TEMPORARY TABLE t1 (a int) ENGINE=MyISAM;
965
CREATE TABLE t1 (a int(1));
944
966
INSERT INTO t1 VALUES (1),(1),(1),(1),(1),(2),(3),(4),(5);
945
967
SELECT DISTINCT (SELECT a) FROM t1 LIMIT 100;
952
CREATE TEMPORARY TABLE `t1` (
953
`id` int NOT NULL auto_increment,
954
`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',
955
977
`tipo` enum('','UNO','DUE') NOT NULL default '',
956
`anno_dep` int NOT NULL default '0',
957
`particolare` bigint NOT NULL default '0',
958
`generale` bigint NOT NULL default '0',
959
`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',
960
982
PRIMARY KEY (`id`),
961
983
UNIQUE KEY `idx_cns_gen_anno` (`anno_dep`,`id_cns`,`generale`,`particolare`),
962
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`)
964
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);
965
CREATE TEMPORARY TABLE `t2` (
966
`id` int NOT NULL auto_increment,
967
`max_anno_dep` int NOT NULL default '0',
968
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',
969
992
INSERT INTO `t2` VALUES (16,1987),(50,1990),(51,1990);
971
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;
973
996
DROP TABLE t1, t2;
976
--echo # GLOBAL LIMIT
978
create temporary table t1 (a int) ENGINE=MyISAM;
1001
create table t1 (a int);
979
1002
insert into t1 values (1), (2), (3);
980
1003
SET SQL_SELECT_LIMIT=1;
981
1004
select sum(a) from (select * from t1) as a;
983
1006
SET SQL_SELECT_LIMIT=default;
987
--echo # Bug #3118: subselect + order by
1010
# Bug #3118: subselect + order by
990
1013
CREATE TABLE t1 (a int, b int, INDEX (a));
991
1014
INSERT INTO t1 VALUES (1, 1), (1, 2), (1, 3);
992
1015
SELECT * FROM t1 WHERE a = (SELECT MAX(a) FROM t1 WHERE a = 1) ORDER BY b;
995
--echo # Item_cond fix field
1018
# Item_cond fix field
997
1020
create table t1(val varchar(10));
998
1021
insert into t1 values ('aaa'), ('bbb'),('eee'),('mmm'),('ppp');
999
1022
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%');
1003
--echo # ref_or_null replacing with ref
1026
# ref_or_null replacing with ref
1005
1028
create table t1 (id int not null, text varchar(20) not null default '', primary key (id));
1006
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');
1007
1030
select * from t1 where id not in (select id from t1 where id < 8);
1008
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);
1009
--replace_column 9 #
1010
1032
explain extended select * from t1 where id not in (select id from t1 where id < 8);
1011
--replace_column 9 #
1012
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);
1013
1034
insert into t1 (id, text) values (1000, 'text1000'), (1001, 'text1001');
1014
create temporary 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));
1015
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');
1016
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);
1017
--replace_column 9 #
1018
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);
1019
1039
drop table t1,t2;
1022
--echo # Static tables & rund() in subqueries
1024
create temporary table t1 (a int) ENGINE=MyISAM;
1042
# Static tables & rund() in subqueries
1044
create table t1 (a int);
1025
1045
insert into t1 values (1);
1026
1046
explain select benchmark(1000, (select a from t1 where a=rand()));
1032
create temporary table t1(id int) ENGINE=MyISAM;
1033
create temporary table t2(id int) ENGINE=MyISAM;
1034
create temporary table t3(flag int) ENGINE=MyISAM;
1052
create table t1(id int);
1053
create table t2(id int);
1054
create table t3(flag int);
1036
1056
select (select * from t3 where id not null) from t1, t2;
1037
1057
drop table t1,t2,t3;
1040
--echo # aggregate functions (Bug #3505)
1060
# aggregate functions (Bug #3505)
1042
1062
CREATE TABLE t1 (id INT);
1043
1063
CREATE TABLE t2 (id INT);
1044
1064
INSERT INTO t1 VALUES (1), (2);
1241
1260
HAVING table2.t2_b = (SELECT MAX(t2_b) FROM t2 WHERE t2_a = table2.t2_a);
1242
1261
DROP TABLE t1, t2;
1245
--echo # Test problem with NULL and derived tables (Bug #4097)
1264
# Test problem with NULL and derived tables (Bug #4097)
1248
CREATE TEMPORARY TABLE t1 (id int default NULL,name varchar(10) default NULL) ENGINE=MyISAM;
1267
CREATE TABLE t1 (id int(11) default NULL,name varchar(10) default NULL);
1249
1268
INSERT INTO t1 VALUES (1,'Tim'),(2,'Rebecca'),(3,NULL);
1250
CREATE TEMPORARY TABLE t2 (id int default NULL, pet varchar(10) default NULL) ENGINE=MyISAM;
1269
CREATE TABLE t2 (id int(11) default NULL, pet varchar(10) default NULL);
1251
1270
INSERT INTO t2 VALUES (1,'Fido'),(2,'Spot'),(3,'Felix');
1252
1271
SELECT a.*, b.* FROM (SELECT * FROM t1) AS a JOIN t2 as b on a.id=b.id;
1253
1272
drop table t1,t2;
1256
--echo # Aggregate function comparation with ALL/ANY/SOME subselect
1258
CREATE TEMPORARY TABLE `t1` ( `a` int default NULL) ENGINE=MyISAM;
1275
# Aggregate function comparation with ALL/ANY/SOME subselect
1277
CREATE TABLE `t1` ( `a` int(11) default NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1;
1259
1278
insert into t1 values (1);
1260
CREATE TEMPORARY TABLE `t2` ( `b` int default NULL, `a` int default NULL) ENGINE=MyISAM;
1279
CREATE TABLE `t2` ( `b` int(11) default NULL, `a` int(11) default NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1;
1261
1280
insert into t2 values (1,2);
1262
1281
select t000.a, count(*) `C` FROM t1 t000 GROUP BY t000.a HAVING count(*) > ALL (SELECT count(*) FROM t2 t001 WHERE t001.a=1);
1263
1282
drop table t1,t2;
1266
--echo # BUG#5003 - like in subselect
1268
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);
1285
# BUG#5003 - like in subselect
1287
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);
1269
1288
CREATE INDEX AK01IZAVORGANG ON t1(izaAnalyseart_id,Kuerzel);
1270
1289
INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000001','601','D0000000001','I0000000001');
1271
1290
INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000002','602','D0000000001','I0000000001');
1307
1326
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;
1311
--echo # Test of correct maybe_null flag returning by subquwery for temporary table
1314
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;
1330
# Test of correct maybe_null flag returning by subquwery for temporary table
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`));
1315
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);
1316
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 ;
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`)) ;
1317
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');
1319
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;
1320
1339
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;
1321
1340
drop tables t1,t2;
1324
--echo # Subselect in non-select command just after connection
1343
# Subselect in non-select command just after connection
1326
1345
connect (root,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
1327
1346
connection root;
1328
1347
set @got_val= (SELECT 1 FROM (SELECT 'A' as my_col) as T1 ) ;
1331
--echo # primary query with temporary table and subquery with groupping
1333
create temporary table t1 (a int, b int) ENGINE=MyISAM;
1334
create temporary table t2 (a int, b int) ENGINE=MyISAM;
1350
# primary query with temporary table and subquery with groupping
1352
create table t1 (a int, b int);
1353
create table t2 (a int, b int);
1335
1354
insert into t1 values (1,1),(1,2),(1,3),(2,4),(2,5);
1336
1355
insert into t2 values (1,3),(2,1);
1337
1356
select distinct a,b, (select max(b) from t2 where t1.b=t2.a) from t1 order by t1.b;
1338
1357
drop table t1, t2;
1341
--echo # Equal operation under row and empty subquery
1360
# Equal operation under row and empty subquery
1343
1362
create table t1 (s1 int,s2 int);
1344
1363
insert into t1 values (20,15);
1345
1364
select * from t1 where (('a',null) <=> (select 'a',s2 from t1 where s1 = 0));
1349
--echo # ALL/ANY with NULL
1351
1370
create table t1 (s1 int);
1352
1371
insert into t1 values (1),(null);
1353
1372
select * from t1 where s1 < all (select s1 from t1);
1354
1373
select s1, s1 < all (select s1 from t1) from t1;
1358
--echo # reference on changable fields from subquery
1377
# reference on changable fields from subquery
1360
1379
CREATE TABLE t1 (
1361
1380
Code char(3) NOT NULL default '',
1362
1381
Name char(52) NOT NULL default '',
1363
1382
Continent enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL default 'Asia',
1364
1383
Region char(26) NOT NULL default '',
1365
1384
SurfaceArea float(10,2) NOT NULL default '0.00',
1366
IndepYear int default NULL,
1367
Population int NOT NULL default '0',
1385
IndepYear smallint(6) default NULL,
1386
Population int(11) NOT NULL default '0',
1368
1387
LifeExpectancy float(3,1) default NULL,
1369
1388
GNP float(10,2) default NULL,
1370
1389
GNPOld float(10,2) default NULL,
1371
1390
LocalName char(45) NOT NULL default '',
1372
1391
GovernmentForm char(45) NOT NULL default '',
1373
1392
HeadOfState char(60) default NULL,
1374
Capital int default NULL,
1393
Capital int(11) default NULL,
1375
1394
Code2 char(2) NOT NULL default ''
1377
1396
INSERT INTO t1 VALUES ('XXX','Xxxxx','Oceania','Xxxxxx',26.00,0,0,0,0,0,'Xxxxx','Xxxxx','Xxxxx',NULL,'XX');
1378
1397
INSERT INTO t1 VALUES ('ASM','American Samoa','Oceania','Polynesia',199.00,0,68000,75.1,334.00,NULL,'Amerika Samoa','US Territory','George W. Bush',54,'AS');
1379
1398
INSERT INTO t1 VALUES ('ATF','French Southern territories','Antarctica','Antarctica',7780.00,0,0,NULL,0.00,NULL,'Terres australes françaises','Nonmetropolitan Territory of France','Jacques Chirac',NULL,'TF');
1470
1487
(5141,89,'2004-10-22'),(5141,51,'2004-10-26');
1473
CREATE TEMPORARY TABLE t3 (
1474
groupId int NOT NULL,
1475
parentId int NOT NULL,
1491
groupId int(11) NOT NULL,
1492
parentId int(11) NOT NULL,
1476
1493
startDate datetime NOT NULL,
1477
1494
endDate datetime NOT NULL,
1478
1495
createDate datetime NOT NULL,
1479
1496
modifyDate timestamp NOT NULL,
1483
1499
INSERT INTO t3 VALUES (12,9,'1000-01-01','3999-12-31','2004-01-29','2004-01-29',NULL);
1485
CREATE TEMPORARY TABLE t4 (
1487
groupTypeId int NOT NULL,
1502
id int(11) NOT NULL,
1503
groupTypeId int(11) NOT NULL,
1488
1504
groupKey varchar(50) NOT NULL,
1491
1507
description text,
1492
1508
createDate datetime NOT NULL,
1493
modifyDate timestamp NOT NULL)
1509
modifyDate timestamp NOT NULL
1496
1511
INSERT INTO t4 VALUES (9,5,'stationer','stationer',0,'Stationer','2004-01-29','2004-01-29'),
1497
1512
(12,5,'group2','group2',0,'group2','2004-01-29','2004-01-29');
1499
CREATE TEMPORARY TABLE t5 (
1500
userId int NOT NULL,
1501
groupId int NOT NULL,
1515
userId int(11) NOT NULL,
1516
groupId int(11) NOT NULL,
1502
1517
createDate datetime NOT NULL,
1503
modifyDate timestamp NOT NULL) ENGINE=MyISAM;
1518
modifyDate timestamp NOT NULL
1505
1520
INSERT INTO t5 VALUES (5141,12,'2004-08-06','2004-08-06');
1565
1580
select (select * from t1) = (1,2,3);
1569
--echo # Item_int_with_ref check (BUG#10020)
1571
--echo #CREATE TABLE `t1` (
1572
--echo # `itemid` bigint NOT NULL auto_increment,
1573
--echo # `sessionid` bigint default NULL,
1574
--echo # `time` int NOT NULL default '0',
1575
--echo # `data` text collate latin1_general_ci NOT NULL,
1576
--echo # PRIMARY KEY (`itemid`)
1578
--echo #INSERT INTO `t1` VALUES (1, 1, 1, '');
1579
--echo #CREATE TABLE `t2` (
1580
--echo # `sessionid` bigint NOT NULL auto_increment,
1581
--echo # `pid` int NOT NULL default '0',
1582
--echo # `date` int NOT NULL default '0',
1583
--echo # `ip` varchar(15) collate latin1_general_ci NOT NULL default '',
1584
--echo # PRIMARY KEY (`sessionid`)
1586
--echo #INSERT INTO `t2` VALUES (1, 1, 1, '10.10.10.1');
1587
--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;
1588
--echo #drop tables t1,t2;
1584
# Item_int_with_ref check (BUG#10020)
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;
1590
--echo # BUG#11821 : Select from subselect using aggregate function on an enum
1592
create temporary table t1 (fld enum('0','1')) ENGINE=MyISAM;
1607
# BUG#11821 : Select from subselect using aggregate function on an enum
1609
create table t1 (fld enum('0','1'));
1593
1610
insert into t1 values ('1');
1594
1611
select * from (select max(fld) from t1) as foo;
1598
--echo # Bug #11867: queries with ROW(,elems>) IN (SELECT DISTINCT <cols> FROM ...)
1615
# Bug #11867: queries with ROW(,elems>) IN (SELECT DISTINCT <cols> FROM ...)
1601
1618
CREATE TABLE t1 (one int, two int, flag char(1));
1602
1619
CREATE TABLE t2 (one int, two int, flag char(1));
2074
2114
('CCC', 7), ('AAA', 2), ('AAA', 4), ('BBB', 3), ('AAA', 8);
2076
2116
SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
2077
--replace_column 9 #
2079
2118
SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
2081
2120
ALTER TABLE t1 ADD INDEX(a);
2083
2122
SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
2084
--replace_column 9 #
2086
2124
SELECT * FROM t1 WHERE (a,b) = ANY (SELECT a, max(b) FROM t1 GROUP BY a);
2091
--echo # Bug#17366: Unchecked Item_int results in server crash
2129
# Bug#17366: Unchecked Item_int results in server crash
2093
2131
create table t1( f1 int,f2 int);
2094
2132
insert into t1 values (1,1),(2,2);
2095
2133
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';
2099
--echo # Bug #18306: server crash on delete using subquery.
2137
# Bug #18306: server crash on delete using subquery.
2102
create temporary table t1 (c int, key(c)) ENGINE=MyISAM;
2140
create table t1 (c int, key(c));
2103
2141
insert into t1 values (1142477582), (1142455969);
2104
create temporary table t2 (a int, b int) ENGINE=MyISAM;
2142
create table t2 (a int, b int);
2105
2143
insert into t2 values (2, 1), (1, 0);
2106
2144
delete from t1 where c <= 1140006215 and (select b from t2 where a = 2) = 1;
2107
2145
drop table t1, t2;
2110
--echo # Bug#19077: A nested materialized derived table is used before being populated.
2148
# Bug#19077: A nested materialized derived table is used before being populated.
2112
2150
create table t1 (i int, j bigint);
2113
2151
insert into t1 values (1, 2), (2, 2), (3, 2);
2114
2152
select * from (select min(i) from t1 where j=(select * from (select min(j) from t1) t2)) t3;
2118
--echo # Bug#19700: subselect returning BIGINT always returned it as SIGNED
2120
CREATE TEMPORARY TABLE t1 (i BIGINT) ENGINE=MyISAM;
2121
INSERT INTO t1 VALUES (10000000000000000); # > MAX SIGNED BIGINT 9323372036854775807
2156
# Bug#19700: subselect returning BIGINT always returned it as SIGNED
2158
CREATE TABLE t1 (i BIGINT UNSIGNED);
2159
INSERT INTO t1 VALUES (10000000000000000000); # > MAX SIGNED BIGINT 9323372036854775807
2122
2160
INSERT INTO t1 VALUES (1);
2124
CREATE TEMPORARY TABLE t2 (i BIGINT) ENGINE=MyISAM;
2125
INSERT INTO t2 VALUES (10000000000000000); # same as first table
2162
CREATE TABLE t2 (i BIGINT UNSIGNED);
2163
INSERT INTO t2 VALUES (10000000000000000000); # same as first table
2126
2164
INSERT INTO t2 VALUES (1);
2128
2166
/* simple test */
2633
2693
DROP TABLE t1,t2;
2637
--echo # Bug #27333: subquery grouped for aggregate of outer query / no aggregate
2638
--echo # of subquery
2640
CREATE TEMPORARY TABLE t1 (a INTEGER, b INTEGER) ENGINE=MyISAM;
2641
CREATE TEMPORARY TABLE t2 (x INTEGER) ENGINE=MyISAM;
2697
# Bug #27333: subquery grouped for aggregate of outer query / no aggregate
2700
CREATE TABLE t1 (a INTEGER, b INTEGER);
2701
CREATE TABLE t2 (x INTEGER);
2642
2702
INSERT INTO t1 VALUES (1,11), (2,22), (2,22);
2643
2703
INSERT INTO t2 VALUES (1), (2);
2645
--echo # wasn't failing, but should
2705
# wasn't failing, but should
2646
2706
--error ER_SUBQUERY_NO_1_ROW
2647
2707
SELECT a, COUNT(b), (SELECT COUNT(b) FROM t2) FROM t1 GROUP BY a;
2649
--echo # fails as it should
2709
# fails as it should
2650
2710
--error ER_SUBQUERY_NO_1_ROW
2651
2711
SELECT a, COUNT(b), (SELECT COUNT(b)+0 FROM t2) FROM t1 GROUP BY a;
2653
2713
SELECT (SELECT SUM(t1.a)/AVG(t2.x) FROM t2) FROM t1;
2654
2714
DROP TABLE t1,t2;
2656
--echo # second test case from 27333
2716
# second test case from 27333
2657
2717
CREATE TABLE t1 (a INT, b INT);
2658
2718
INSERT INTO t1 VALUES (1, 2), (1,3), (1,4), (2,1), (2,2);
2660
--echo # returns no rows, when it should
2720
# returns no rows, when it should
2661
2721
SELECT a1.a, COUNT(*) FROM t1 a1 WHERE a1.a = 1
2662
2722
AND EXISTS( SELECT a2.a FROM t1 a2 WHERE a2.a = a1.a)
2666
--echo #test cases from 29297
2667
CREATE TEMPORARY TABLE t1 (a INT) ENGINE=MyISAM;
2668
CREATE TEMPORARY TABLE t2 (a INT) ENGINE=MyISAM;
2726
#test cases from 29297
2727
CREATE TABLE t1 (a INT);
2728
CREATE TABLE t2 (a INT);
2669
2729
INSERT INTO t1 VALUES (1),(2);
2670
2730
INSERT INTO t2 VALUES (1),(2);
2671
2731
SELECT (SELECT SUM(t1.a) FROM t2 WHERE a=0) FROM t1;
2689
2749
SELECT ((a1,a2) IN (SELECT * FROM t2 WHERE b2 > 0)) IS NULL FROM t1;
2690
2750
DROP TABLE t1, t2;
2693
--echo # Bug #30788: Inconsistent retrieval of char/varchar
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;
2795
# Bug #30788: Inconsistent retrieval of char/varchar
2696
2798
CREATE TABLE t1 (a CHAR(1), b VARCHAR(10));
2697
2799
INSERT INTO t1 VALUES ('a', 'aa');