~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/union.test

  • Committer: Brian Aker
  • Date: 2009-02-05 10:38:55 UTC
  • Revision ID: brian@tangent.org-20090205103855-wajzccrbu7zbvmh4
Reworked some classes out of session.h
Also updated ignore file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
98
98
CREATE TABLE t1 (
99
99
  `pseudo` char(35) NOT NULL default '',
100
100
  `pseudo1` char(35) NOT NULL default '',
101
 
  `same` int(1) NOT NULL default '1',
 
101
  `same` int NOT NULL default '1',
102
102
  PRIMARY KEY  (`pseudo1`),
103
103
  KEY `pseudo` (`pseudo`)
104
104
) ENGINE=MyISAM;
128
128
#
129
129
 
130
130
CREATE TABLE t1 (
131
 
  cid int(5) NOT NULL default '0',
132
 
  cv varchar(250) NOT NULL default '',
 
131
  cid int NOT NULL default '0',
 
132
  cv varchar(190) NOT NULL default '',
133
133
  PRIMARY KEY  (cid),
134
134
  UNIQUE KEY cv (cv)
135
135
) ;
136
136
INSERT INTO t1 VALUES (8,'dummy');
137
137
CREATE TABLE t2 (
138
 
  cid bigint(20) NOT NULL auto_increment,
 
138
  cid int NOT NULL auto_increment,
139
139
  cap varchar(255) NOT NULL default '',
140
140
  PRIMARY KEY  (cid),
141
141
  KEY cap (cap)
142
142
) ;
143
143
CREATE TABLE t3 (
144
 
  gid bigint(20) NOT NULL auto_increment,
 
144
  gid int NOT NULL auto_increment,
145
145
  gn varchar(255) NOT NULL default '',
146
 
  must int(4) default NULL,
 
146
  must int default NULL,
147
147
  PRIMARY KEY  (gid),
148
148
  KEY gn (gn)
149
149
) ;
150
150
INSERT INTO t3 VALUES (1,'V1',NULL);
151
151
CREATE TABLE t4 (
152
 
  uid bigint(20) NOT NULL default '0',
153
 
  gid bigint(20) default NULL,
154
 
  rid bigint(20) default NULL,
155
 
  cid bigint(20) default NULL,
 
152
  uid bigint NOT NULL default '0',
 
153
  gid bigint default NULL,
 
154
  rid bigint default NULL,
 
155
  cid bigint default NULL,
156
156
  UNIQUE KEY m (uid,gid,rid,cid),
157
157
  KEY uid (uid),
158
158
  KEY rid (rid),
161
161
) ;
162
162
INSERT INTO t4 VALUES (1,1,NULL,NULL);
163
163
CREATE TABLE t5 (
164
 
  rid bigint(20) NOT NULL auto_increment,
 
164
  rid bigint NOT NULL auto_increment,
165
165
  rl varchar(255) NOT NULL default '',
166
166
  PRIMARY KEY  (rid),
167
167
  KEY rl (rl)
168
168
) ;
169
169
CREATE TABLE t6 (
170
 
  uid bigint(20) NOT NULL auto_increment,
171
 
  un varchar(250) NOT NULL default '',
172
 
  uc int(5) NOT NULL default '0',
 
170
  uid bigint NOT NULL auto_increment,
 
171
  un varchar(190) NOT NULL default '',
 
172
  uc int NOT NULL default '0',
173
173
  PRIMARY KEY  (uid),
174
174
  UNIQUE KEY nc (un,uc),
175
175
  KEY un (un)
276
276
#
277
277
# Test for another bug with UNION and LEFT JOIN
278
278
#
279
 
CREATE TABLE t1 (  id int(3) default '0') ENGINE=MyISAM;
 
279
CREATE TABLE t1 (  id int default '0') ENGINE=MyISAM;
280
280
INSERT INTO t1 (id) VALUES("1");
281
 
CREATE TABLE t2 ( id int(3) default '0',  id_master int(5) default '0',  text1 varchar(5) default NULL,  text2 varchar(5) default NULL) ENGINE=MyISAM;
 
281
CREATE TABLE t2 ( id int default '0',  id_master int default '0',  text1 varchar(5) default NULL,  text2 varchar(5) default NULL) ENGINE=MyISAM;
282
282
INSERT INTO t2 (id, id_master, text1, text2) VALUES("1", "1",
283
283
"foo1", "bar1");
284
284
INSERT INTO t2 (id, id_master, text1, text2) VALUES("2", "1",
309
309
drop table t1,t2;
310
310
create table t1 (   id int not null auto_increment, primary key (id)   ,user_name text );
311
311
create table t2 (    id int not null auto_increment, primary key (id)   ,group_name text );
312
 
create table t3 (    id int not null auto_increment, primary key (id)   ,user_id int   ,index user_idx (user_id)   ,foreign key (user_id) references users(id)   ,group_id int   ,index group_idx (group_id)   ,foreign key (group_id) references groups(id) );
 
312
create table t3 (    id int not null auto_increment, primary key (id)   ,user_id int   ,index user_idx (user_id)   ,foreign key (user_id) references t1(id)   ,group_id int   ,index group_idx (group_id)   ,foreign key (group_id) references t2(id) );
313
313
insert into t1 (user_name) values ('Tester');
314
314
insert into t2 (group_name) values ('Group A');
315
315
insert into t2 (group_name) values ('Group B');
316
316
insert into t3 (user_id, group_id) values (1,1);
317
317
select 1 'is_in_group', a.user_name, c.group_name, b.id from t1 a, t3 b, t2 c where a.id = b.user_id and b.group_id = c.id UNION  select 0 'is_in_group', a.user_name, c.group_name, null from t1 a, t2 c;
318
 
drop table t1, t2, t3;
 
318
drop table t3, t1, t2;
319
319
 
320
320
#
321
321
# fix_fields problem
322
322
#
323
 
create table t1 (mat_id MEDIUMINT NOT NULL AUTO_INCREMENT PRIMARY KEY, matintnum CHAR(6) NOT NULL, test MEDIUMINT NULL);
324
 
create table t2 (mat_id MEDIUMINT NOT NULL, pla_id MEDIUMINT NOT NULL);
 
323
create table t1 (mat_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, matintnum CHAR(6) NOT NULL, test INT NULL);
 
324
create table t2 (mat_id INT NOT NULL, pla_id INT NOT NULL);
325
325
insert into t1 values (NULL, 'a', 1), (NULL, 'b', 2), (NULL, 'c', 3), (NULL, 'd', 4), (NULL, 'e', 5), (NULL, 'f', 6), (NULL, 'g', 7), (NULL, 'h', 8), (NULL, 'i', 9);
326
326
insert into t2 values (1, 100), (1, 101), (1, 102), (2, 100), (2, 103), (2, 104), (3, 101), (3, 102), (3, 105);
327
327
SELECT mp.pla_id, MIN(m1.matintnum) AS matintnum FROM t2 mp INNER JOIN t1 m1 ON mp.mat_id=m1.mat_id GROUP BY mp.pla_id union SELECT 0, 0;
343
343
show create table t1;
344
344
drop table t1;
345
345
 
346
 
create table t2 (it1 int, it2 int not null, i int not null, ib bigint, f float, d double, y year, da date, dt datetime, sc char(10), sv varchar(10), b blob, tx text);
347
 
insert into t2 values (NULL, 1, 3, 4, 1.5, 2.5, 1972, '1972-10-22', '1972-10-22 11:50', 'testc', 'testv', 'tetetetetest', 'teeeeeeeeeeeest');
 
346
create table t2 (it1 int, it2 int not null, i int not null, ib int, f float, d double, da date, dt datetime, sc char(10), sv varchar(10), b blob, tx text);
 
347
insert into t2 values (NULL, 1, 3, 4, 1.5, 2.5, '1972-10-22', '1972-10-22 11:50', 'testc', 'testv', 'tetetetetest', 'teeeeeeeeeeeest');
348
348
 
349
349
create table t1 SELECT it2 from t2 UNION select it1 from t2;
350
350
select * from t1;
370
370
select * from t1;
371
371
show create table t1;
372
372
drop table t1;
373
 
create table t1 SELECT f from t2 UNION select y from t2;
374
 
select * from t1;
375
 
show create table t1;
376
 
drop table t1;
377
373
create table t1 SELECT f from t2 UNION select da from t2;
378
374
select * from t1;
379
375
show create table t1;
380
376
drop table t1;
381
 
create table t1 SELECT y from t2 UNION select da from t2;
382
 
select * from t1;
383
 
show create table t1;
384
 
drop table t1;
385
 
create table t1 SELECT y from t2 UNION select dt from t2;
386
 
select * from t1;
387
 
show create table t1;
388
 
drop table t1;
389
377
create table t1 SELECT da from t2 UNION select dt from t2;
390
378
select * from t1;
391
379
show create table t1;
426
414
select * from t1;
427
415
show create table t1;
428
416
drop table t1;
429
 
create table t1 select _latin1"test" union select _latin2"testt" ;
430
 
create table t1 select _latin2"test" union select _latin2"testt" ;
 
417
-- error 1054
 
418
create table t1 select _latin1"test" union select _latin1"testt" ;
 
419
-- error 1054
 
420
create table t1 select _utf8"test" union select _utf8"testt" ;
 
421
create table t1 select "test" union select "testt" ;
431
422
show create table t1;
432
423
drop table t1;
433
424
 
479
469
#
480
470
# Column 'name' cannot be null (error with union and left join) (bug #2508)
481
471
#
482
 
create table t1 (   RID int(11) not null default '0',   IID int(11) not null default '0',    nada varchar(50)  not null,NAME varchar(50) not null,PHONE varchar(50) not null) engine=MyISAM;
 
472
create table t1 (   RID int not null default '0',   IID int not null default '0',    nada varchar(50)  not null,NAME varchar(50) not null,PHONE varchar(50) not null) engine=MyISAM;
483
473
insert into t1 ( RID,IID,nada,NAME,PHONE) values (1, 1, 'main', 'a', '111'), (2, 1, 'main', 'b', '222'), (3, 1, 'main', 'c', '333'), (4, 1, 'main', 'd', '444'), (5, 1, 'main', 'e', '555'), (6, 2, 'main', 'c', '333'), (7, 2, 'main', 'd', '454'), (8, 2, 'main', 'e', '555'), (9, 2, 'main', 'f', '666'), (10, 2, 'main', 'g', '777');
484
474
select A.NAME, A.PHONE, B.NAME, B.PHONE from t1 A left join t1 B on A.NAME = B.NAME and B.IID = 2 where A.IID = 1 and (A.PHONE <> B.PHONE or B.NAME is null) union select A.NAME, A.PHONE, B.NAME, B.PHONE from t1 B left join t1 A on B.NAME = A.NAME and A.IID = 1 where B.IID = 2 and (A.PHONE <> B.PHONE or A.NAME is null);
485
475
drop  table t1;
527
517
#
528
518
# nonexisting column in global ORDER BY
529
519
#
530
 
CREATE TABLE t1 (i int(11) default NULL,c char(1) default NULL,KEY i (i));
531
 
CREATE TABLE t2 (i int(11) default NULL,c char(1) default NULL,KEY i (i));
 
520
CREATE TABLE t1 (i int default NULL,c char(1) default NULL,KEY i (i));
 
521
CREATE TABLE t2 (i int default NULL,c char(1) default NULL,KEY i (i));
532
522
--error 1054
533
523
explain (select * from t1) union (select * from t2) order by not_existing_column;
534
524
drop table t1, t2;
536
526
#
537
527
# length detecting
538
528
#
539
 
CREATE TABLE t1 (uid int(1));
 
529
CREATE TABLE t1 (uid int);
540
530
INSERT INTO t1 SELECT 150;
541
531
SELECT 'a' UNION SELECT uid FROM t1;
542
532
drop table t1;
544
534
#
545
535
# parser stack overflow
546
536
#
547
 
CREATE TABLE t1 ( ID1 int(10) NOT NULL DEFAULT '0' , ID2 datetime NOT NULL DEFAULT '0000-00-00 00:00:00' , DATA1 varchar(10) , DATA2 double(5,4) , DATA3 datetime , PRIMARY KEY (ID1,ID2));
 
537
CREATE TABLE t1 ( ID1 int NOT NULL DEFAULT '0' , ID2 datetime NOT NULL DEFAULT '0000-00-00 00:00:00' , DATA1 varchar(10) , DATA2 double(5,4) , DATA3 datetime , PRIMARY KEY (ID1,ID2));
548
538
 
549
 
CREATE TABLE t2 ( ID int(3) NOT NULL DEFAULT '0' , DATA1 timestamp DEFAULT '0000-00-00 00:00:00' , PRIMARY KEY (ID));
 
539
CREATE TABLE t2 ( ID int NOT NULL DEFAULT '0' , DATA1 timestamp DEFAULT '0000-00-00 00:00:00' , PRIMARY KEY (ID));
550
540
(SELECT * FROM t1 AS PARTITIONED, t2 AS
551
541
PARTITIONED_B WHERE PARTITIONED_B.ID=PARTITIONED.ID1) UNION
552
542
(SELECT * FROM t1 AS PARTITIONED, t2 AS
580
570
create table t2 (a ENUM('aaa', 'bbb') NOT NULL);
581
571
insert into t1 values ('No');
582
572
insert into t2 values ('bbb');
583
 
create table t3 (a SET('Yes', 'No') NOT NULL);
584
 
create table t4 (a SET('aaa', 'bbb') NOT NULL);
 
573
create table t3 (a ENUM('Yes', 'No') NOT NULL);
 
574
create table t4 (a ENUM('aaa', 'bbb') NOT NULL);
585
575
insert into t3 values (1);
 
576
--error 1265
586
577
insert into t4 values (3);
587
578
select "1" as a union select a from t1;
588
579
select a as a from t1 union select "1";
597
588
# Bug #6139 UNION doesn't understand collate in the column of second select
598
589
#
599
590
create table t1 as
600
 
(select _latin1'test') union
601
 
(select _latin1'TEST') union
602
 
(select _latin1'TeST');
603
 
show create table t1;
604
 
select count(*) from t1;
605
 
drop table t1;
606
 
 
607
 
create table t1 as
608
 
(select _latin1'test' collate latin1_bin) union
609
 
(select _latin1'TEST') union
610
 
(select _latin1'TeST');
611
 
show create table t1;
612
 
select count(*) from t1;
613
 
drop table t1;
614
 
 
615
 
create table t1 as
616
 
(select _latin1'test') union
617
 
(select _latin1'TEST' collate latin1_bin) union
618
 
(select _latin1'TeST');
619
 
show create table t1;
620
 
select count(*) from t1;
621
 
drop table t1;
622
 
 
623
 
create table t1 as
624
 
(select _latin1'test') union
625
 
(select _latin1'TEST') union
626
 
(select _latin1'TeST' collate latin1_bin);
627
 
show create table t1;
628
 
select count(*) from t1;
629
 
drop table t1;
630
 
 
631
 
create table t2 (
632
 
a char character set latin1 collate latin1_swedish_ci,
633
 
b char character set latin1 collate latin1_german1_ci);
 
591
(select 'test') union
 
592
(select 'TEST') union
 
593
(select 'TeST');
 
594
show create table t1;
 
595
select count(*) from t1;
 
596
drop table t1;
 
597
 
 
598
create table t1 as
 
599
(select 'test' collate utf8_bin) union
 
600
(select 'TEST') union
 
601
(select 'TeST');
 
602
show create table t1;
 
603
select count(*) from t1;
 
604
drop table t1;
 
605
 
 
606
create table t1 as
 
607
(select 'test') union
 
608
(select 'TEST' collate utf8_bin) union
 
609
(select 'TeST');
 
610
show create table t1;
 
611
select count(*) from t1;
 
612
drop table t1;
 
613
 
 
614
create table t1 as
 
615
(select 'test') union
 
616
(select 'TEST') union
 
617
(select 'TeST' collate utf8_bin);
 
618
show create table t1;
 
619
select count(*) from t1;
 
620
drop table t1;
 
621
 
 
622
# Drizzle doesn't support specifying character set, it is all UTF8
 
623
--error 1064
 
624
create table t2 (
 
625
a char character set utf8 collate utf8_swedish_ci,
 
626
b char character set utf8 collate utf8_spanish_ci);
 
627
 
 
628
create table t2 (
 
629
a char collate utf8_swedish_ci,
 
630
b char collate utf8_spanish_ci);
634
631
--error 1271
635
632
create table t1 as
636
633
(select a from t2) union
637
634
(select b from t2);
 
635
 
 
636
--error 1166
638
637
create table t1 as
639
 
(select a collate latin1_german1_ci from t2) union
 
638
(select a collate utf8_swedish_ci from t2) union
640
639
(select b from t2);
641
 
show create table t1;
642
 
drop table t1;
 
640
#show create table t1;
 
641
#drop table t1;
 
642
 
643
643
create table t1 as
644
644
(select a from t2) union
645
 
(select b collate latin1_german1_ci from t2);
 
645
(select b collate utf8_swedish_ci from t2);
646
646
show create table t1;
647
647
drop table t1;
648
648
create table t1 as
649
649
(select a from t2) union
650
650
(select b from t2) union
651
 
(select 'c' collate latin1_german1_ci from t2);
 
651
(select 'c' collate utf8_spanish_ci from t2);
652
652
show create table t1;
653
653
drop table t1;
654
654
drop table t2;
710
710
#
711
711
# Bug#15949 union + illegal mix of collations (IMPLICIT + COERCIBLE)
712
712
#
713
 
select concat(_latin1'a', _ascii'b' collate ascii_bin);
714
 
create table t1 (foo varchar(100)) collate ascii_bin;
 
713
select concat('a', 'b' collate utf8_bin);
 
714
create table t1 (foo varchar(100)) collate utf8_bin;
715
715
insert into t1 (foo) values ("foo");
 
716
--error 1146
716
717
select foo from t1 union select 'bar' as foo from dual;
 
718
select foo from t1 union select 'bar' as foo;
717
719
drop table t1;
718
720
 
 
721
 
 
722
# Commenting out this test until Bug 308841 is fixed
719
723
#
720
724
# Enum merging test
721
725
#
722
 
CREATE TABLE t1 (
723
 
  a ENUM('�','�','�') character set utf8 not null default '�',
724
 
  b ENUM("one", "two") character set utf8,
725
 
  c ENUM("one", "two")
726
 
);
727
 
show create table t1;
728
 
insert into t1 values ('�', 'one', 'one'), ('�', 'two', 'one'), ('�', NULL, NULL);
729
 
create table t2 select NULL union select a from t1;
730
 
show columns from t2;
731
 
drop table t2;
732
 
create table t2 select a from t1 union select NULL;
733
 
show columns from t2;
734
 
drop table t2;
735
 
create table t2 select a from t1 union select a from t1;
736
 
show columns from t2;
737
 
drop table t2;
738
 
create table t2 select a from t1 union select c from t1;
739
 
drop table t2;
740
 
create table t2 select a from t1 union select b from t1;
741
 
show columns from t2;
742
 
drop table t2, t1;
 
726
#CREATE TABLE t1 (
 
727
#  a ENUM('�','�','�') character set utf8 not null default '�',
 
728
#  b ENUM("one", "two") character set utf8,
 
729
#  c ENUM("one", "two")
 
730
#);
 
731
#show create table t1;
 
732
#insert into t1 values ('�', 'one', 'one'), ('�', 'two', 'one'), ('�', NULL, NULL);
 
733
#create table t2 select NULL union select a from t1;
 
734
#show columns from t2;
 
735
#drop table t2;
 
736
#create table t2 select a from t1 union select NULL;
 
737
#show columns from t2;
 
738
#drop table t2;
 
739
#create table t2 select a from t1 union select a from t1;
 
740
#show columns from t2;
 
741
#drop table t2;
 
742
#create table t2 select a from t1 union select c from t1;
 
743
#drop table t2;
 
744
#create table t2 select a from t1 union select b from t1;
 
745
#show columns from t2;
 
746
#drop table t2, t1;
743
747
 
744
748
745
749
# Bug #14216: UNION + DECIMAL wrong values in result
842
846
#
843
847
# Bug#12185: Data type aggregation may produce wrong result
844
848
#
845
 
create table t1(f1 char(1), f2 char(5), f3 binary(1), f4 binary(5), f5 timestamp, f6 varchar(1) character set utf8 collate utf8_general_ci, f7 text);
 
849
create table t1(f1 char(1), f2 char(5), f3 blob, f4 blob, f5 timestamp, f6 varchar(1) collate utf8_general_ci, f7 text);
846
850
create table t2 as select *, f6 as f8 from t1 union select *, f7 from t1;
847
851
show create table t2;
848
852
drop table t1, t2;
898
902
# Bug #16881: password() and union select
899
903
# (The issue was poor handling of character set aggregation.)
900
904
#
901
 
select _utf8'12' union select _latin1'12345';
 
905
select '12' union select '12345';
902
906
 
903
907
#
904
908
# Bug #26661: UNION with ORDER BY undefined column in FROM list