~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysql-test/t/subselect.test

  • Committer: Brian Aker
  • Date: 2008-07-07 16:07:49 UTC
  • mfrom: (80.1.1 food)
  • Revision ID: brian@tangent.org-20080707160749-qj89fnnwufz4xgop
Clean up install, we no longer have system tables.

Show diffs side-by-side

added added

removed removed

Lines of Context:
145
145
SELECT * FROM t3 WHERE b = (SELECT MIN(b) FROM t3);
146
146
 
147
147
CREATE TABLE `t8` (
148
 
  `pseudo` varchar(35) NOT NULL default '',
149
 
  `email` varchar(60) NOT NULL default '',
 
148
  `pseudo` varchar(35) character set latin1 NOT NULL default '',
 
149
  `email` varchar(60) character set latin1 NOT NULL default '',
150
150
  PRIMARY KEY  (`pseudo`),
151
151
  UNIQUE KEY `email` (`email`)
152
 
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
 
152
) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
153
153
 
154
154
INSERT INTO t8 (pseudo,email) VALUES ('joce','test');
155
155
INSERT INTO t8 (pseudo,email) VALUES ('joce1','test1');
169
169
 
170
170
#searchconthardwarefr3 forumconthardwarefr7
171
171
CREATE TABLE `t1` (
172
 
  `topic` bigint NOT NULL default '0',
 
172
  `topic` bigint(8) unsigned NOT NULL default '0',
173
173
  `date` date NOT NULL default '0000-00-00',
174
 
  `pseudo` varchar(35) NOT NULL default '',
 
174
  `pseudo` varchar(35) character set latin1 NOT NULL default '',
175
175
  PRIMARY KEY  (`pseudo`,`date`,`topic`),
176
176
  KEY `topic` (`topic`)
177
177
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
189
189
 
190
190
#forumconthardwarefr7 searchconthardwarefr7
191
191
CREATE TABLE `t1` (
192
 
  `numeropost` bigint NOT NULL auto_increment,
193
 
  `maxnumrep` int NOT NULL default '0',
 
192
  `numeropost` bigint(8) unsigned NOT NULL auto_increment,
 
193
  `maxnumrep` int(10) unsigned NOT NULL default '0',
194
194
  PRIMARY KEY  (`numeropost`),
195
195
  UNIQUE KEY `maxnumrep` (`maxnumrep`)
196
196
) ENGINE=MyISAM ROW_FORMAT=FIXED;
199
199
 
200
200
CREATE TABLE `t2` (
201
201
      `mot` varchar(30) NOT NULL default '',
202
 
      `topic` bigint NOT NULL default '0',
 
202
      `topic` bigint(8) unsigned NOT NULL default '0',
203
203
      `date` date NOT NULL default '0000-00-00',
204
204
      `pseudo` varchar(35) NOT NULL default '',
205
205
       PRIMARY KEY  (`mot`,`pseudo`,`date`,`topic`)
232
232
 
233
233
#forumconthardwarefr7
234
234
CREATE TABLE `t1` (
235
 
  `numeropost` bigint NOT NULL auto_increment,
236
 
  `maxnumrep` int NOT NULL default '0',
 
235
  `numeropost` bigint(8) unsigned NOT NULL auto_increment,
 
236
  `maxnumrep` int(10) unsigned NOT NULL default '0',
237
237
  PRIMARY KEY  (`numeropost`),
238
238
  UNIQUE KEY `maxnumrep` (`maxnumrep`)
239
239
) ENGINE=MyISAM ROW_FORMAT=FIXED;
259
259
 
260
260
# threadhardwarefr7
261
261
CREATE TABLE `t1` (
262
 
  `numeropost` bigint NOT NULL default '0',
263
 
  `numreponse` int NOT NULL auto_increment,
 
262
  `numeropost` bigint(8) unsigned NOT NULL default '0',
 
263
  `numreponse` int(10) unsigned NOT NULL auto_increment,
264
264
  `pseudo` varchar(35) NOT NULL default '',
265
265
  PRIMARY KEY  (`numeropost`,`numreponse`),
266
266
  UNIQUE KEY `numreponse` (`numreponse`),
278
278
EXPLAIN EXTENDED SELECT numreponse FROM t1 WHERE numeropost='1' AND numreponse=(SELECT MAX(numreponse) FROM t1 WHERE numeropost='1');
279
279
drop table t1;
280
280
 
281
 
CREATE TABLE t1 (a int);
 
281
CREATE TABLE t1 (a int(1));
282
282
INSERT INTO t1 VALUES (1);
283
283
SELECT 1 FROM (SELECT a FROM t1) b HAVING (SELECT b.a)=1;
284
284
drop table t1;
391
391
-- error 1096
392
392
SELECT * FROM (SELECT 1) b WHERE 1 IN (SELECT *);
393
393
 
394
 
CREATE TABLE t2 (id int default NULL, KEY id (id)) ENGINE=MyISAM;
 
394
CREATE TABLE t2 (id int(11) default NULL, KEY id (id)) ENGINE=MyISAM CHARSET=latin1;
395
395
INSERT INTO t2 VALUES (1),(2);
396
396
SELECT * FROM t2 WHERE id IN (SELECT 1);
397
397
EXPLAIN EXTENDED SELECT * FROM t2 WHERE id IN (SELECT 1);
406
406
-- error 1093
407
407
INSERT INTO t2 VALUES ((SELECT id FROM t2));
408
408
SELECT * FROM t2;
409
 
CREATE TABLE t1 (id int default NULL, KEY id (id)) ENGINE=MyISAM;
 
409
CREATE TABLE t1 (id int(11) default NULL, KEY id (id)) ENGINE=MyISAM CHARSET=latin1;
410
410
INSERT INTO t1 values (1),(1);
411
411
-- error 1242
412
412
UPDATE t2 SET id=(SELECT * FROM t1);
462
462
# Null with keys
463
463
#
464
464
 
465
 
CREATE TABLE t1 (a int NOT NULL default '0', PRIMARY KEY  (a));
466
 
CREATE TABLE t2 (a int default '0', INDEX (a));
 
465
CREATE TABLE t1 (a int(11) NOT NULL default '0', PRIMARY KEY  (a));
 
466
CREATE TABLE t2 (a int(11) default '0', INDEX (a));
467
467
INSERT INTO t1 VALUES (1),(2),(3),(4);
468
468
INSERT INTO t2 VALUES (1),(2),(3);
469
469
SELECT t1.a, t1.a in (select t2.a from t2) FROM t1;
470
470
explain extended SELECT t1.a, t1.a in (select t2.a from t2) FROM t1;
471
 
CREATE TABLE t3 (a int default '0');
 
471
CREATE TABLE t3 (a int(11) default '0');
472
472
INSERT INTO t3 VALUES (1),(2),(3);
473
473
SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
474
474
explain extended SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1;
475
475
drop table t1,t2,t3;
476
476
 
477
477
#LIMIT is not supported now
478
 
#create table t1 (a float);
479
 
#-- error 1235
480
 
#select 10.5 IN (SELECT * from t1 LIMIT 1);
481
 
#-- error 1235
482
 
#select 10.5 IN (SELECT * from t1 LIMIT 1 UNION SELECT 1.5);
483
 
#drop table t1;
484
 
#
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;
492
 
#drop table t1,t2;
493
 
#
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');
505
 
#-- error 1235
506
 
#select ROW(1, 1, 'a') IN (select b,a,c from t1 limit 2);
507
 
#drop table t1;
 
478
create table t1 (a float);
 
479
-- error 1235
 
480
select 10.5 IN (SELECT * from t1 LIMIT 1);
 
481
-- error 1235
 
482
select 10.5 IN (SELECT * from t1 LIMIT 1 UNION SELECT 1.5);
 
483
drop table t1;
 
484
 
 
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;
 
492
drop table t1,t2;
 
493
 
 
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');
 
505
-- error 1235
 
506
select ROW(1, 1, 'a') IN (select b,a,c from t1 limit 2);
 
507
drop table t1;
508
508
 
509
509
#test of uncacheable subqueries
510
 
CREATE TABLE t1 (a int);
 
510
CREATE TABLE t1 (a int(1));
511
511
EXPLAIN EXTENDED SELECT (SELECT RAND() FROM t1) FROM t1;
 
512
EXPLAIN EXTENDED SELECT (SELECT ENCRYPT('test') FROM t1) FROM t1;
512
513
EXPLAIN EXTENDED SELECT (SELECT BENCHMARK(1,1) FROM t1) FROM t1;
513
514
drop table t1;
514
515
 
515
516
 
516
517
CREATE TABLE `t1` (
517
 
  `mot` varchar(30) NOT NULL default '',
518
 
  `topic` bigint NOT NULL default '0',
 
518
  `mot` varchar(30) character set latin1 NOT NULL default '',
 
519
  `topic` bigint(8) unsigned NOT NULL default '0',
519
520
  `date` date NOT NULL default '0000-00-00',
520
 
  `pseudo` varchar(35) NOT NULL default '',
 
521
  `pseudo` varchar(35) character set latin1 NOT NULL default '',
521
522
  PRIMARY KEY  (`mot`,`pseudo`,`date`,`topic`),
522
523
  KEY `pseudo` (`pseudo`,`date`,`topic`),
523
524
  KEY `topic` (`topic`)
524
 
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
 
525
) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
525
526
 
526
527
CREATE TABLE `t2` (
527
 
  `mot` varchar(30) NOT NULL default '',
528
 
  `topic` bigint NOT NULL default '0',
 
528
  `mot` varchar(30) character set latin1 NOT NULL default '',
 
529
  `topic` bigint(8) unsigned NOT NULL default '0',
529
530
  `date` date NOT NULL default '0000-00-00',
530
 
  `pseudo` varchar(35) NOT NULL default '',
 
531
  `pseudo` varchar(35) character set latin1 NOT NULL default '',
531
532
  PRIMARY KEY  (`mot`,`pseudo`,`date`,`topic`),
532
533
  KEY `pseudo` (`pseudo`,`date`,`topic`),
533
534
  KEY `topic` (`topic`)
534
 
) ENGINE=MyISAM ROW_FORMAT=DYNAMIC;
 
535
) ENGINE=MyISAM CHARSET=latin1 ROW_FORMAT=DYNAMIC;
535
536
 
536
537
CREATE TABLE `t3` (
537
 
  `numeropost` bigint NOT NULL auto_increment,
538
 
  `maxnumrep` int NOT NULL default '0',
 
538
  `numeropost` bigint(8) unsigned NOT NULL auto_increment,
 
539
  `maxnumrep` int(10) unsigned NOT NULL default '0',
539
540
  PRIMARY KEY  (`numeropost`),
540
541
  UNIQUE KEY `maxnumrep` (`maxnumrep`)
541
 
) ENGINE=MyISAM;
 
542
) ENGINE=MyISAM CHARSET=latin1;
542
543
INSERT INTO t1 (mot, topic, pseudo) VALUES ('joce','1','joce'),('test','2','test');
543
544
 
544
545
INSERT INTO t2 (mot, topic, pseudo) VALUES ('joce','1','joce'),('test','2','test');
586
587
#
587
588
 
588
589
CREATE TABLE t1 (
589
 
  ID int NOT NULL auto_increment,
 
590
  ID int(11) NOT NULL auto_increment,
590
591
  name char(35) NOT NULL default '',
591
592
  t2 char(3) NOT NULL default '',
592
593
  District char(20) NOT NULL default '',
593
 
  Population int NOT NULL default '0',
 
594
  Population int(11) NOT NULL default '0',
594
595
  PRIMARY KEY  (ID)
595
596
) ENGINE=MyISAM;
596
597
 
604
605
  Continent enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL default 'Asia',
605
606
  Region char(26) NOT NULL default '',
606
607
  SurfaceArea float(10,2) NOT NULL default '0.00',
607
 
  IndepYear int default NULL,
608
 
  Population int NOT NULL default '0',
 
608
  IndepYear smallint(6) default NULL,
 
609
  Population int(11) NOT NULL default '0',
609
610
  LifeExpectancy float(3,1) default NULL,
610
611
  GNP float(10,2) default NULL,
611
612
  GNPOld float(10,2) default NULL,
612
613
  LocalName char(45) NOT NULL default '',
613
614
  GovernmentForm char(45) NOT NULL default '',
614
615
  HeadOfState char(60) default NULL,
615
 
  Capital int default NULL,
 
616
  Capital int(11) default NULL,
616
617
  Code2 char(2) NOT NULL default '',
617
618
  PRIMARY KEY  (Code)
618
619
) ENGINE=MyISAM;
628
629
# constants in IN
629
630
#
630
631
CREATE TABLE `t1` (
631
 
  `id` bigint NOT NULL auto_increment,
632
 
  `pseudo` varchar(35) NOT NULL default '',
 
632
  `id` bigint(8) unsigned NOT NULL auto_increment,
 
633
  `pseudo` varchar(35) character set latin1 NOT NULL default '',
633
634
  PRIMARY KEY  (`id`),
634
635
  UNIQUE KEY `pseudo` (`pseudo`)
635
636
) ENGINE=MyISAM PACK_KEYS=1 ROW_FORMAT=DYNAMIC;
642
643
drop table t1;
643
644
 
644
645
CREATE TABLE `t1` (
645
 
  `i` int NOT NULL default '0',
 
646
  `i` int(11) NOT NULL default '0',
646
647
  PRIMARY KEY  (`i`)
647
 
) ENGINE=MyISAM;
 
648
) ENGINE=MyISAM CHARSET=latin1;
648
649
 
649
650
INSERT INTO t1 VALUES (1);
650
651
UPDATE t1 SET i=i+(SELECT MAX(i) FROM (SELECT 1) t) WHERE i=(SELECT MAX(i));
658
659
# Multi update test
659
660
#
660
661
CREATE TABLE t1 (
661
 
  id int default NULL
662
 
) ENGINE=MyISAM;
 
662
  id int(11) default NULL
 
663
) ENGINE=MyISAM CHARSET=latin1;
663
664
INSERT INTO t1 VALUES (1),(1),(2),(2),(1),(3);
664
665
CREATE TABLE t2 (
665
 
  id int default NULL,
 
666
  id int(11) default NULL,
666
667
  name varchar(15) default NULL
667
 
) ENGINE=MyISAM;
 
668
) ENGINE=MyISAM CHARSET=latin1;
668
669
 
669
670
INSERT INTO t2 VALUES (4,'vita'), (1,'vita'), (2,'vita'), (1,'vita');
670
671
update t1, t2 set t2.name='lenka' where t2.id in (select id from t1);
688
689
drop table t1;
689
690
 
690
691
CREATE TABLE t1 (
691
 
  ID int NOT NULL auto_increment,
692
 
  SUB_ID int NOT NULL default '0',
693
 
  REF_ID int default NULL,
694
 
  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',
695
696
  PRIMARY KEY (ID,SUB_ID),
696
697
  UNIQUE KEY t1_PK (ID,SUB_ID),
697
698
  KEY t1_FK (REF_ID,REF_SUB),
698
699
  KEY t1_REFID (REF_ID)
699
 
) ENGINE=MyISAM;
 
700
) ENGINE=MyISAM CHARSET=cp1251;
700
701
INSERT INTO t1 VALUES (1,0,NULL,NULL),(2,0,NULL,NULL);
701
702
SELECT DISTINCT REF_ID FROM t1 WHERE ID= (SELECT DISTINCT REF_ID FROM t1 WHERE ID=2);
702
703
DROP TABLE t1;
720
721
#
721
722
 
722
723
CREATE TABLE `t1` (
723
 
  `id` bigint NOT NULL auto_increment,
 
724
  `id` bigint(8) unsigned NOT NULL auto_increment,
724
725
  `pseudo` varchar(35) NOT NULL default '',
725
726
  `email` varchar(60) NOT NULL default '',
726
727
  PRIMARY KEY  (`id`),
727
728
  UNIQUE KEY `email` (`email`),
728
729
  UNIQUE KEY `pseudo` (`pseudo`)
729
 
) ENGINE=MyISAM PACK_KEYS=1 ROW_FORMAT=DYNAMIC;
 
730
) ENGINE=MyISAM CHARSET=latin1 PACK_KEYS=1 ROW_FORMAT=DYNAMIC;
730
731
INSERT INTO t1 (id,pseudo,email) VALUES (1,'test','test'),(2,'test1','test1');
731
732
SELECT pseudo as a, pseudo as b FROM t1 GROUP BY (SELECT a) ORDER BY (SELECT id*1);
732
733
drop table if exists t1;
755
756
insert into t1 values (1,10), (2,20), (3,30), (4,40);
756
757
disable_query_log;
757
758
# making table large enough
758
 
set autocommit=0;
759
 
begin;
760
759
let $1 = 10000;
761
760
while ($1)
762
761
 {
763
762
  eval insert into t1 values (rand()*100000+200,rand()*100000); 
764
763
  dec $1;
765
764
 }
766
 
commit;
767
 
set autocommit=1;
768
765
enable_query_log;
769
766
insert into t2 values (2), (3), (4), (5);
770
767
insert into t3 values (10,3), (20,4), (30,5);
817
814
#
818
815
# collation test
819
816
#
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
 
#-- error 1267
824
 
#select * from t1 where s1 > (select max(s2) from t1);
825
 
#-- error 1267
826
 
#select * from t1 where s1 > any (select max(s2) from t1);
827
 
#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','?');
 
820
-- error 1267
 
821
select * from t1 where s1 > (select max(s2) from t1);
 
822
-- error 1267
 
823
select * from t1 where s1 > any (select max(s2) from t1);
 
824
drop table t1;
828
825
 
829
826
#
830
827
# aggregate functions reinitialization
899
896
# correct used_tables()
900
897
#
901
898
 
902
 
CREATE TABLE `t1` ( `id` bigint NOT NULL auto_increment, `taskid` bigint NOT NULL default '0', `dbid` int NOT NULL default '0', `create_date` datetime NOT NULL default '0000-00-00 00:00:00', `last_update` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY  (`id`)) ENGINE=MyISAM AUTO_INCREMENT=3 ;
 
899
CREATE TABLE `t1` ( `id` bigint(9) NOT NULL auto_increment, `taskid` bigint(20) NOT NULL default '0', `dbid` int(11) NOT NULL default '0', `create_date` datetime NOT NULL default '0000-00-00 00:00:00', `last_update` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY  (`id`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=3 ;
903
900
INSERT INTO `t1` (`id`, `taskid`, `dbid`, `create_date`,`last_update`) VALUES (1, 1, 15, '2003-09-29 10:31:36', '2003-09-29 10:31:36'), (2, 1, 21, now(), now());
904
 
CREATE TABLE `t2` (`db_id` int NOT NULL auto_increment,`name` varchar(200) NOT NULL default '',`primary_uid` int NOT NULL default '0',`secondary_uid` int NOT NULL default '0',PRIMARY KEY  (`db_id`),UNIQUE KEY `name_2` (`name`)) ENGINE=MyISAM AUTO_INCREMENT=2147483647;
 
901
CREATE TABLE `t2` (`db_id` int(11) NOT NULL auto_increment,`name` varchar(200) NOT NULL default '',`primary_uid` smallint(6) NOT NULL default '0',`secondary_uid` smallint(6) NOT NULL default '0',PRIMARY KEY  (`db_id`),UNIQUE KEY `name_2` (`name`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=2147483647;
905
902
INSERT INTO `t2` (`db_id`, `name`, `primary_uid`, `secondary_uid`) VALUES (18, 'Not Set 1', 0, 0),(19, 'Valid', 1, 2),(20, 'Valid 2', 1, 2),(21, 'Should Not Return', 1, 2),(26, 'Not Set 2', 0, 0),(-1, 'ALL DB\'S', 0, 0);
906
 
CREATE TABLE `t3` (`taskgenid` bigint NOT NULL auto_increment,`dbid` int NOT NULL default '0',`taskid` int NOT NULL default '0',`mon` int NOT NULL default '1',`tues` int NOT NULL default '1',`wed` int NOT NULL default '1',`thur` int NOT NULL default '1',`fri` int NOT NULL default '1',`sat` int NOT NULL default '0',`sun` int NOT NULL default '0',`how_often` int NOT NULL default '1',`userid` int NOT NULL default '0',`active` int NOT NULL default '1',PRIMARY KEY  (`taskgenid`)) ENGINE=MyISAM AUTO_INCREMENT=2 ;
 
903
CREATE TABLE `t3` (`taskgenid` bigint(9) NOT NULL auto_increment,`dbid` int(11) NOT NULL default '0',`taskid` int(11) NOT NULL default '0',`mon` tinyint(4) NOT NULL default '1',`tues` tinyint(4) NOT NULL default '1',`wed` tinyint(4) NOT NULL default '1',`thur` tinyint(4) NOT NULL default '1',`fri` tinyint(4) NOT NULL default '1',`sat` tinyint(4) NOT NULL default '0',`sun` tinyint(4) NOT NULL default '0',`how_often` smallint(6) NOT NULL default '1',`userid` smallint(6) NOT NULL default '0',`active` tinyint(4) NOT NULL default '1',PRIMARY KEY  (`taskgenid`)) ENGINE=MyISAM CHARSET=latin1 AUTO_INCREMENT=2 ;
907
904
INSERT INTO `t3` (`taskgenid`, `dbid`, `taskid`, `mon`, `tues`,`wed`, `thur`, `fri`, `sat`, `sun`, `how_often`, `userid`, `active`) VALUES (1,-1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1);
908
 
CREATE TABLE `t4` (`task_id` int NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM;
 
905
CREATE TABLE `t4` (`task_id` smallint(6) NOT NULL default '0',`description` varchar(200) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1;
909
906
INSERT INTO `t4` (`task_id`, `description`) VALUES (1, 'Daily Check List'),(2, 'Weekly Status');
910
907
select  dbid, name, (date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01') from t3 a, t2 b, t4  WHERE dbid = - 1 AND primary_uid = '1' AND t4.task_id = taskid;
911
908
SELECT dbid, name FROM t3 a, t2 b, t4 WHERE dbid = - 1 AND primary_uid = '1' AND ((date_format(now() , '%Y-%m-%d') - INTERVAL how_often DAY) >= ifnull((SELECT date_format(max(create_date),'%Y-%m-%d') FROM t1 WHERE dbid = b.db_id AND taskid = a.taskgenid), '1950-01-01')) AND t4.task_id = taskid;
914
911
#
915
912
# cardinality check
916
913
#
917
 
CREATE TABLE t1 (id int default NULL) ENGINE=MyISAM;
 
914
CREATE TABLE t1 (id int(11) default NULL) ENGINE=MyISAM CHARSET=latin1;
918
915
INSERT INTO t1 VALUES (1),(5);
919
 
CREATE TABLE t2 (id int default NULL) ENGINE=MyISAM;
 
916
CREATE TABLE t2 (id int(11) default NULL) ENGINE=MyISAM CHARSET=latin1;
920
917
INSERT INTO t2 VALUES (2),(6);
921
918
-- error 1241
922
919
select * from t1 where (1,2,6) in (select * from t2);
935
932
#
936
933
# filesort in subquery (restoring join_tab)
937
934
#
938
 
CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM;
 
935
CREATE TABLE t1 (number char(11) NOT NULL default '') ENGINE=MyISAM CHARSET=latin1;
939
936
INSERT INTO t1 VALUES ('69294728265'),('18621828126'),('89356874041'),('95895001874');
940
 
CREATE 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;
941
938
INSERT INTO t2 VALUES ('1'),('1226'),('1245'),('1862'),('18623'),('1874'),('1967'),('6');
942
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;
943
940
drop table t1, t2;
965
962
SELECT DISTINCT COLC FROM t1 WHERE COLA = (SELECT COLA FROM t2 WHERE COLB = 200 AND COLC ='C' LIMIT 1);
966
963
DROP TABLE t1, t2;
967
964
 
968
 
CREATE TABLE t1 (a int);
 
965
CREATE TABLE t1 (a int(1));
969
966
INSERT INTO t1 VALUES (1),(1),(1),(1),(1),(2),(3),(4),(5);
970
967
SELECT DISTINCT (SELECT a) FROM t1 LIMIT 100;
971
968
DROP TABLE t1;
975
972
#
976
973
 
977
974
CREATE TABLE `t1` (
978
 
  `id` int NOT NULL auto_increment,
979
 
  `id_cns` int NOT NULL default '0',
 
975
  `id` int(11) NOT NULL auto_increment,
 
976
  `id_cns` tinyint(3) unsigned NOT NULL default '0',
980
977
  `tipo` enum('','UNO','DUE') NOT NULL default '',
981
 
  `anno_dep` int NOT NULL default '0',
982
 
  `particolare` bigint NOT NULL default '0',
983
 
  `generale` bigint NOT NULL default '0',
984
 
  `bis` int NOT NULL default '0',
 
978
  `anno_dep` smallint(4) unsigned zerofill NOT NULL default '0000',
 
979
  `particolare` bigint(8) unsigned NOT NULL default '0',
 
980
  `generale` bigint(8) unsigned NOT NULL default '0',
 
981
  `bis` tinyint(3) unsigned NOT NULL default '0',
985
982
  PRIMARY KEY  (`id`),
986
983
  UNIQUE KEY `idx_cns_gen_anno` (`anno_dep`,`id_cns`,`generale`,`particolare`),
987
984
  UNIQUE KEY `idx_cns_par_anno` (`id_cns`,`anno_dep`,`tipo`,`particolare`,`bis`)
988
985
);
989
986
INSERT INTO `t1` VALUES (1,16,'UNO',1987,2048,9681,0),(2,50,'UNO',1987,1536,13987,0),(3,16,'UNO',1987,2432,14594,0),(4,16,'UNO',1987,1792,13422,0),(5,16,'UNO',1987,1025,10240,0),(6,16,'UNO',1987,1026,7089,0);
990
987
CREATE TABLE `t2` (
991
 
  `id` int NOT NULL auto_increment,
992
 
  `max_anno_dep` int NOT NULL default '0',
 
988
  `id` tinyint(3) unsigned NOT NULL auto_increment,
 
989
  `max_anno_dep` smallint(6) unsigned NOT NULL default '0',
993
990
  PRIMARY KEY  (`id`)
994
991
);
995
992
INSERT INTO `t2` VALUES (16,1987),(50,1990),(51,1990);
1267
1264
# Test problem with NULL and derived tables (Bug #4097)
1268
1265
#
1269
1266
 
1270
 
CREATE TABLE t1 (id int default NULL,name varchar(10) default NULL);
 
1267
CREATE TABLE t1 (id int(11) default NULL,name varchar(10) default NULL);
1271
1268
INSERT INTO t1 VALUES (1,'Tim'),(2,'Rebecca'),(3,NULL);
1272
 
CREATE TABLE t2 (id int default NULL, pet varchar(10) default NULL);
 
1269
CREATE TABLE t2 (id int(11) default NULL, pet varchar(10) default NULL);
1273
1270
INSERT INTO t2 VALUES (1,'Fido'),(2,'Spot'),(3,'Felix');
1274
1271
SELECT a.*, b.* FROM (SELECT * FROM t1) AS a JOIN t2 as b on a.id=b.id;
1275
1272
drop table t1,t2;
1277
1274
#
1278
1275
# Aggregate function comparation with ALL/ANY/SOME subselect
1279
1276
#
1280
 
CREATE TABLE `t1` ( `a` int default NULL) ENGINE=MyISAM;
 
1277
CREATE TABLE `t1` ( `a` int(11) default NULL) ENGINE=MyISAM DEFAULT CHARSET=latin1;
1281
1278
insert into t1 values (1);
1282
 
CREATE 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;
1283
1280
insert into t2 values (1,2);
1284
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);
1285
1282
drop table t1,t2;
1287
1284
#
1288
1285
# BUG#5003 - like in subselect
1289
1286
#
1290
 
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);
 
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);
1291
1288
CREATE INDEX AK01IZAVORGANG ON t1(izaAnalyseart_id,Kuerzel);
1292
1289
INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000001','601','D0000000001','I0000000001');
1293
1290
INSERT INTO t1(`IZAVORGANG_ID`,`KUERZEL`,`IZAANALYSEART_ID`,`IZAPMKZ_ID`)VALUES('D0000000002','602','D0000000001','I0000000001');
1299
1296
#
1300
1297
# Optimized IN with compound index
1301
1298
#
1302
 
CREATE TABLE `t1` ( `aid` int NOT NULL default '0', `bid` int NOT NULL default '0', PRIMARY KEY  (`aid`,`bid`));
1303
 
CREATE TABLE `t2` ( `aid` int NOT NULL default '0', `bid` int NOT NULL default '0', PRIMARY KEY  (`aid`,`bid`));
 
1299
CREATE TABLE `t1` ( `aid` int(11) NOT NULL default '0', `bid` int(11) NOT NULL default '0', PRIMARY KEY  (`aid`,`bid`));
 
1300
CREATE TABLE `t2` ( `aid` int(11) NOT NULL default '0', `bid` int(11) NOT NULL default '0', PRIMARY KEY  (`aid`,`bid`));
1304
1301
insert into t1 values (1,1),(1,2),(2,1),(2,2);
1305
1302
insert into t2 values (1,2),(2,2);
1306
1303
select * from t1 where t1.aid not in (select aid from t2 where bid=t1.bid);
1333
1330
# Test of correct maybe_null flag returning by subquwery for temporary table
1334
1331
# creation
1335
1332
#
1336
 
CREATE TABLE `t1` ( `master` int NOT NULL default '0', `map` int NOT NULL default '0', `slave` int NOT NULL default '0', `access` int NOT NULL default '0', UNIQUE KEY `access_u` (`master`,`map`,`slave`));
 
1333
CREATE TABLE `t1` ( `master` int(10) unsigned NOT NULL default '0', `map` smallint(6) unsigned NOT NULL default '0', `slave` int(10) unsigned NOT NULL default '0', `access` int(10) unsigned NOT NULL default '0', UNIQUE KEY `access_u` (`master`,`map`,`slave`));
1337
1334
INSERT INTO `t1` VALUES (1,0,0,700),(1,1,1,400),(1,5,5,400),(1,12,12,400),(1,12,32,400),(4,12,32,400);
1338
 
CREATE TABLE `t2` ( `id` int NOT NULL default '0', `pid` int NOT NULL default '0', `map` int NOT NULL default '0', `level` int NOT NULL default '0', `title` varchar(255) default NULL, PRIMARY KEY  (`id`,`pid`,`map`), KEY `level` (`level`), KEY `id` (`id`,`map`)) ;
 
1335
CREATE TABLE `t2` ( `id` int(10) unsigned NOT NULL default '0', `pid` int(10) unsigned NOT NULL default '0', `map` smallint(6) unsigned NOT NULL default '0', `level` tinyint(4) unsigned NOT NULL default '0', `title` varchar(255) default NULL, PRIMARY KEY  (`id`,`pid`,`map`), KEY `level` (`level`), KEY `id` (`id`,`map`)) ;
1339
1336
INSERT INTO `t2` VALUES (6,5,12,7,'a'),(12,0,0,7,'a'),(12,1,0,7,'a'),(12,5,5,7,'a'),(12,5,12,7,'a');
1340
1337
-- error 1054
1341
1338
SELECT b.sc FROM (SELECT (SELECT a.access FROM t1 a WHERE a.map = op.map AND a.slave = op.pid AND a.master = 1) ac FROM t2 op WHERE op.id = 12 AND op.map = 0) b;
1385
1382
  Continent enum('Asia','Europe','North America','Africa','Oceania','Antarctica','South America') NOT NULL default 'Asia',
1386
1383
  Region char(26) NOT NULL default '',
1387
1384
  SurfaceArea float(10,2) NOT NULL default '0.00',
1388
 
  IndepYear int default NULL,
1389
 
  Population int NOT NULL default '0',
 
1385
  IndepYear smallint(6) default NULL,
 
1386
  Population int(11) NOT NULL default '0',
1390
1387
  LifeExpectancy float(3,1) default NULL,
1391
1388
  GNP float(10,2) default NULL,
1392
1389
  GNPOld float(10,2) default NULL,
1393
1390
  LocalName char(45) NOT NULL default '',
1394
1391
  GovernmentForm char(45) NOT NULL default '',
1395
1392
  HeadOfState char(60) default NULL,
1396
 
  Capital int default NULL,
 
1393
  Capital int(11) default NULL,
1397
1394
  Code2 char(2) NOT NULL default ''
1398
1395
) ENGINE=MyISAM;
1399
1396
INSERT INTO t1 VALUES ('XXX','Xxxxx','Oceania','Xxxxxx',26.00,0,0,0,0,0,'Xxxxx','Xxxxx','Xxxxx',NULL,'XX');
1459
1456
# Test for BUG#8218
1460
1457
#
1461
1458
CREATE TABLE t1 (
1462
 
  categoryId int NOT NULL,
1463
 
  courseId int NOT NULL,
 
1459
  categoryId int(11) NOT NULL,
 
1460
  courseId int(11) NOT NULL,
1464
1461
  startDate datetime NOT NULL,
1465
1462
  endDate datetime NOT NULL,
1466
1463
  createDate datetime NOT NULL,
1478
1475
(5,12,'2004-02-18','2010-01-01','2004-02-18','2004-02-18','');
1479
1476
 
1480
1477
CREATE TABLE t2 (
1481
 
  userId int NOT NULL,
1482
 
  courseId int NOT NULL,
 
1478
  userId int(11) NOT NULL,
 
1479
  courseId int(11) NOT NULL,
1483
1480
  date datetime NOT NULL
1484
1481
);
1485
1482
INSERT INTO t2 VALUES (5141,71,'2003-11-18'),
1491
1488
 
1492
1489
 
1493
1490
CREATE TABLE t3 (
1494
 
  groupId int NOT NULL,
1495
 
  parentId int NOT NULL,
 
1491
  groupId int(11) NOT NULL,
 
1492
  parentId int(11) NOT NULL,
1496
1493
  startDate datetime NOT NULL,
1497
1494
  endDate datetime NOT NULL,
1498
1495
  createDate datetime NOT NULL,
1499
1496
  modifyDate timestamp NOT NULL,
1500
 
  ordering int
 
1497
  ordering int(11)
1501
1498
);
1502
1499
INSERT INTO t3 VALUES (12,9,'1000-01-01','3999-12-31','2004-01-29','2004-01-29',NULL);
1503
1500
 
1504
1501
CREATE TABLE t4 (
1505
 
  id int NOT NULL,
1506
 
  groupTypeId int NOT NULL,
 
1502
  id int(11) NOT NULL,
 
1503
  groupTypeId int(11) NOT NULL,
1507
1504
  groupKey varchar(50) NOT NULL,
1508
1505
  name text,
1509
 
  ordering int,
 
1506
  ordering int(11),
1510
1507
  description text,
1511
1508
  createDate datetime NOT NULL,
1512
1509
  modifyDate timestamp NOT NULL
1515
1512
(12,5,'group2','group2',0,'group2','2004-01-29','2004-01-29');
1516
1513
 
1517
1514
CREATE TABLE t5 (
1518
 
  userId int NOT NULL,
1519
 
  groupId int NOT NULL,
 
1515
  userId int(11) NOT NULL,
 
1516
  groupId int(11) NOT NULL,
1520
1517
  createDate datetime NOT NULL,
1521
1518
  modifyDate timestamp NOT NULL
1522
1519
);
1586
1583
#
1587
1584
# Item_int_with_ref check (BUG#10020)
1588
1585
#
1589
 
#CREATE TABLE `t1` (
1590
 
#  `itemid` bigint NOT NULL auto_increment,
1591
 
#  `sessionid` bigint default NULL,
1592
 
#  `time` int NOT NULL default '0',
1593
 
#  `data` text collate latin1_general_ci NOT NULL,
1594
 
#  PRIMARY KEY  (`itemid`)
1595
 
#);
1596
 
#INSERT INTO `t1` VALUES (1, 1, 1, '');
1597
 
#CREATE TABLE `t2` (
1598
 
#  `sessionid` bigint NOT NULL auto_increment,
1599
 
#  `pid` int NOT NULL default '0',
1600
 
#  `date` int NOT NULL default '0',
1601
 
#  `ip` varchar(15) collate latin1_general_ci NOT NULL default '',
1602
 
#  PRIMARY KEY  (`sessionid`)
1603
 
#);
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;
1606
 
#drop tables t1,t2;
 
1586
CREATE TABLE `t1` (
 
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
 
1591
NULL default '',
 
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', '');
 
1596
CREATE TABLE `t2` (
 
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;
 
1605
drop tables t1,t2;
1607
1606
 
1608
1607
# BUG#11821 : Select from subselect using aggregate function on an enum
1609
1608
# segfaults:
1708
1707
#
1709
1708
create table t1 (
1710
1709
  retailerID varchar(8) NOT NULL,
1711
 
  statusID   int NOT NULL,
 
1710
  statusID   int(10) unsigned NOT NULL,
1712
1711
  changed    datetime NOT NULL,
1713
1712
  UNIQUE KEY retailerID (retailerID, statusID, changed)
1714
1713
);
1899
1898
drop table t1;
1900
1899
 
1901
1900
CREATE TABLE t1 (
1902
 
  grp int default NULL,
 
1901
  grp int(11) default NULL,
1903
1902
  a decimal(10,2) default NULL);
1904
1903
 
1905
1904
insert into t1 values (1, 1), (2, 2), (2, 3), (3, 4), (3, 5), (3, 6), (NULL, NULL);
1953
1952
DROP TABLE t1,t2,t3;
1954
1953
 
1955
1954
#
 
1955
# Item_int_with_ref check (BUG#10020)
 
1956
#
 
1957
CREATE TABLE `t1` (
 
1958
  `itemid` bigint(20) unsigned NOT NULL auto_increment,
 
1959
  `sessionid` bigint(20) unsigned default NULL,
 
1960
  `time` int(10) unsigned NOT NULL default '0',
 
1961
  `type` set('A','D','E','F','G','I','L','N','U') collate latin1_general_ci NOT
 
1962
NULL default '',
 
1963
  `data` text collate latin1_general_ci NOT NULL,
 
1964
  PRIMARY KEY  (`itemid`)
 
1965
) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
 
1966
INSERT INTO `t1` VALUES (1, 1, 1, 'D', '');
 
1967
CREATE TABLE `t2` (
 
1968
  `sessionid` bigint(20) unsigned NOT NULL auto_increment,
 
1969
  `pid` int(10) unsigned NOT NULL default '0',
 
1970
  `date` int(10) unsigned NOT NULL default '0',
 
1971
  `ip` varchar(15) collate latin1_general_ci NOT NULL default '',
 
1972
  PRIMARY KEY  (`sessionid`)
 
1973
) DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
 
1974
INSERT INTO `t2` VALUES (1, 1, 1, '10.10.10.1');
 
1975
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;
 
1976
drop tables t1,t2;
 
1977
 
 
1978
#
1956
1979
# Correct building of equal fields list (do not include outer
1957
1980
# fields) (BUG#6384)
1958
1981
#
2132
2155
2133
2156
# Bug#19700: subselect returning BIGINT always returned it as SIGNED
2134
2157
#
2135
 
CREATE TABLE t1 (i BIGINT);
2136
 
INSERT INTO t1 VALUES (10000000000000000); # > MAX SIGNED BIGINT 9323372036854775807
 
2158
CREATE TABLE t1 (i BIGINT UNSIGNED);
 
2159
INSERT INTO t1 VALUES (10000000000000000000); # > MAX SIGNED BIGINT 9323372036854775807
2137
2160
INSERT INTO t1 VALUES (1);
2138
2161
 
2139
 
CREATE TABLE t2 (i BIGINT);
2140
 
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
2141
2164
INSERT INTO t2 VALUES (1);
2142
2165
 
2143
2166
/* simple test */
2147
2170
SELECT t1.i FROM t1 WHERE t1.i = (SELECT MAX(i) FROM t2);
2148
2171
 
2149
2172
/* subquery test with cast*/
2150
 
SELECT t1.i FROM t1 WHERE t1.i = (SELECT MAX(i) FROM t2);
 
2173
SELECT t1.i FROM t1 WHERE t1.i = CAST((SELECT MAX(i) FROM t2) AS UNSIGNED);
2151
2174
 
2152
2175
DROP TABLE t1;
2153
2176
DROP TABLE t2;
2157
2180
#
2158
2181
 
2159
2182
CREATE TABLE t1 (
2160
 
  id bigint NOT NULL auto_increment,
 
2183
  id bigint(20) unsigned NOT NULL auto_increment,
2161
2184
  name varchar(255) NOT NULL,
2162
2185
  PRIMARY KEY  (id)
2163
2186
);
2165
2188
  (1, 'Balazs'), (2, 'Joe'), (3, 'Frank');
2166
2189
 
2167
2190
CREATE TABLE t2 (
2168
 
  id bigint NOT NULL auto_increment,
2169
 
  mid bigint NOT NULL,
 
2191
  id bigint(20) unsigned NOT NULL auto_increment,
 
2192
  mid bigint(20) unsigned NOT NULL,
2170
2193
  date date NOT NULL,
2171
2194
  PRIMARY KEY  (id)
2172
2195
);
2197
2220
#
2198
2221
 
2199
2222
CREATE TABLE t1 (
2200
 
  i1 int NOT NULL default '0',
2201
 
  i2 int NOT NULL default '0',
 
2223
  i1 int(11) NOT NULL default '0',
 
2224
  i2 int(11) NOT NULL default '0',
2202
2225
  t datetime NOT NULL default '0000-00-00 00:00:00',
2203
2226
  PRIMARY KEY  (i1,i2,t)
2204
2227
);
2211
2234
(24,2,'2005-05-27 12:40:06');
2212
2235
 
2213
2236
CREATE TABLE t2 (
2214
 
  i1 int NOT NULL default '0',
2215
 
  i2 int NOT NULL default '0',
 
2237
  i1 int(11) NOT NULL default '0',
 
2238
  i2 int(11) NOT NULL default '0',
2216
2239
  t datetime default NULL,
2217
2240
  PRIMARY KEY  (i1)
2218
2241
);
2259
2282
DROP TABLE t1;
2260
2283
 
2261
2284
#
 
2285
# Bug#21798: memory leak during query execution with subquery in column 
 
2286
#             list using a function
 
2287
#
 
2288
CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b));
 
2289
insert into t1 (a) values (FLOOR(rand() * 100));
 
2290
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
2291
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
2292
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
2293
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
2294
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
2295
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
2296
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
2297
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
2298
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
2299
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
2300
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
2301
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
2302
insert into t1 (a) select FLOOR(rand() * 100) from t1;
 
2303
 
 
2304
SELECT a, 
 
2305
       (SELECT REPEAT(' ',250) FROM t1 i1 
 
2306
        WHERE i1.b=t1.a ORDER BY RAND() LIMIT 1) AS a 
 
2307
FROM t1 ORDER BY a LIMIT 5;
 
2308
DROP TABLE t1;
 
2309
 
 
2310
#
2262
2311
# Bug #21540: Subqueries with no from and aggregate functions return 
2263
2312
#              wrong results
2264
2313
CREATE TABLE t1 (a INT, b INT);
2288
2337
CREATE TABLE t1 (a int, b int auto_increment, PRIMARY KEY (b));
2289
2338
CREATE TABLE t2 (x int auto_increment, y int, z int,
2290
2339
                 PRIMARY KEY (x), FOREIGN KEY (y) REFERENCES t1 (b));
 
2340
 
2291
2341
disable_query_log;
2292
 
set autocommit=0;
2293
 
begin;
2294
2342
let $1=3000;
2295
2343
while ($1)
2296
2344
{
2304
2352
  } 
2305
2353
  dec $1;
2306
2354
}
2307
 
commit;
2308
 
set autocommit=1;
2309
2355
enable_query_log;
2310
2356
 
2311
2357
SET SESSION sort_buffer_size = 32 * 1024;
2318
2364
  FROM (SELECT  a, b, (SELECT x FROM t2 WHERE y=b ORDER BY z DESC LIMIT 1) c
2319
2365
          FROM t1) t;
2320
2366
 
2321
 
DROP TABLE t2,t1;
 
2367
DROP TABLE t1,t2;
2322
2368
 
2323
2369
#
2324
2370
# Bug #25219: EXIST subquery with UNION over a mix of
2365
2411
--enable_warnings
2366
2412
 
2367
2413
CREATE TABLE t1 (
2368
 
  id_1 int NOT NULL,
 
2414
  id_1 int(5) NOT NULL,
2369
2415
  t varchar(4) DEFAULT NULL
2370
2416
);
2371
2417
 
2372
2418
CREATE TABLE t2 (
2373
 
  id_2 int NOT NULL,
 
2419
  id_2 int(5) NOT NULL,
2374
2420
  t varchar(4) DEFAULT NULL
2375
2421
);
2376
2422
 
2377
2423
CREATE TABLE t1xt2 (
2378
 
  id_1 int NOT NULL,
2379
 
  id_2 int NOT NULL
 
2424
  id_1 int(5) NOT NULL,
 
2425
  id_2 int(5) NOT NULL
2380
2426
);
2381
2427
 
2382
2428
INSERT INTO t1 VALUES (1, 'a'), (2, 'b'), (3, 'c'), (4, 'd');
2704
2750
DROP TABLE t1, t2;
2705
2751
 
2706
2752
#
 
2753
# Bug #28076: inconsistent binary/varbinary comparison
 
2754
#
 
2755
 
 
2756
CREATE TABLE t1 (s1 BINARY(5), s2 VARBINARY(5));
 
2757
INSERT INTO t1 VALUES (0x41,0x41), (0x42,0x42), (0x43,0x43);
 
2758
 
 
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);
 
2761
 
 
2762
CREATE INDEX I1 ON t1 (s1);
 
2763
CREATE INDEX I2 ON t1 (s2);
 
2764
 
 
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);
 
2767
 
 
2768
TRUNCATE t1;
 
2769
INSERT INTO t1 VALUES (0x41,0x41);
 
2770
SELECT * FROM t1 WHERE s1 = (SELECT s2 FROM t1);
 
2771
 
 
2772
DROP TABLE t1;
 
2773
 
 
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;
 
2783
 
 
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;
 
2793
 
 
2794
#
2707
2795
# Bug #30788: Inconsistent retrieval of char/varchar
2708
2796
#
2709
2797