~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/r/union.result

Merge of Joe's patch (and I updated the author file to include his name as
well).

Show diffs side-by-side

added added

removed removed

Lines of Context:
505
505
explain (select * from t1 where a=1) union (select * from t1 where b=1);
506
506
id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
507
507
1       PRIMARY t1      const   PRIMARY PRIMARY 4       const   1       
508
 
2       UNION   t1      ref     b       b       5       const   1       Using where; Using index
 
508
2       UNION   t1      ref     b       b       5       const   1       Using index
509
509
NULL    UNION RESULT    <union1,2>      ALL     NULL    NULL    NULL    NULL    NULL    
510
510
drop table t1,t2;
511
511
create table t1 (   id int not null auto_increment, primary key (id)   ,user_name text );
542
542
show create table t1;
543
543
Table   Create Table
544
544
t1      CREATE TABLE `t1` (
545
 
  `a` VARCHAR(1) COLLATE utf8_general_ci NOT NULL DEFAULT ''
546
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
545
  `a` varchar(1) NOT NULL DEFAULT ''
 
546
) ENGINE=DEFAULT
547
547
drop table t1;
548
548
create table t1 SELECT 12 as a UNION select "aa" as a;
549
549
select * from t1;
553
553
show create table t1;
554
554
Table   Create Table
555
555
t1      CREATE TABLE `t1` (
556
 
  `a` VARBINARY(4) NOT NULL DEFAULT ''
557
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
556
  `a` varbinary(4) NOT NULL DEFAULT ''
 
557
) ENGINE=DEFAULT
558
558
drop table t1;
559
559
create table t1 SELECT 12 as a UNION select 12.2 as a;
560
560
select * from t1;
564
564
show create table t1;
565
565
Table   Create Table
566
566
t1      CREATE TABLE `t1` (
567
 
  `a` DECIMAL(3,1) NOT NULL DEFAULT '0.0'
568
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
567
  `a` decimal(3,1) NOT NULL DEFAULT '0.0'
 
568
) ENGINE=DEFAULT
569
569
drop table t1;
570
570
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);
571
571
insert into t2 values (NULL, 1, 3, 4, 1.5, 2.5, '1972-10-22', '1972-10-22 11:50:00', 'testc', 'testv', 'tetetetetest', 'teeeeeeeeeeeest');
577
577
show create table t1;
578
578
Table   Create Table
579
579
t1      CREATE TABLE `t1` (
580
 
  `it2` INT DEFAULT NULL
581
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
580
  `it2` int DEFAULT NULL
 
581
) ENGINE=DEFAULT
582
582
drop table t1;
583
583
create table t1 SELECT it2 from t2 UNION select i from t2;
584
584
select * from t1;
588
588
show create table t1;
589
589
Table   Create Table
590
590
t1      CREATE TABLE `t1` (
591
 
  `it2` INT NOT NULL DEFAULT '0'
592
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
591
  `it2` int NOT NULL DEFAULT '0'
 
592
) ENGINE=DEFAULT
593
593
drop table t1;
594
594
create table t1 SELECT i from t2 UNION select f from t2;
595
595
select * from t1;
599
599
show create table t1;
600
600
Table   Create Table
601
601
t1      CREATE TABLE `t1` (
602
 
  `i` DOUBLE DEFAULT NULL
603
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
602
  `i` double DEFAULT NULL
 
603
) ENGINE=DEFAULT
604
604
drop table t1;
605
605
create table t1 SELECT f from t2 UNION select d from t2;
606
606
select * from t1;
610
610
show create table t1;
611
611
Table   Create Table
612
612
t1      CREATE TABLE `t1` (
613
 
  `f` DOUBLE DEFAULT NULL
614
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
613
  `f` double DEFAULT NULL
 
614
) ENGINE=DEFAULT
615
615
drop table t1;
616
616
create table t1 SELECT ib from t2 UNION select f from t2;
617
617
select * from t1;
621
621
show create table t1;
622
622
Table   Create Table
623
623
t1      CREATE TABLE `t1` (
624
 
  `ib` DOUBLE DEFAULT NULL
625
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
624
  `ib` double DEFAULT NULL
 
625
) ENGINE=DEFAULT
626
626
drop table t1;
627
627
create table t1 SELECT ib from t2 UNION select d from t2;
628
628
select * from t1;
632
632
show create table t1;
633
633
Table   Create Table
634
634
t1      CREATE TABLE `t1` (
635
 
  `ib` DOUBLE DEFAULT NULL
636
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
635
  `ib` double DEFAULT NULL
 
636
) ENGINE=DEFAULT
637
637
drop table t1;
638
638
create table t1 SELECT f from t2 UNION select da from t2;
639
639
select * from t1;
643
643
show create table t1;
644
644
Table   Create Table
645
645
t1      CREATE TABLE `t1` (
646
 
  `f` VARBINARY(22) DEFAULT NULL
647
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
646
  `f` varbinary(22) DEFAULT NULL
 
647
) ENGINE=DEFAULT
648
648
drop table t1;
649
649
create table t1 SELECT da from t2 UNION select dt from t2;
650
650
select * from t1;
654
654
show create table t1;
655
655
Table   Create Table
656
656
t1      CREATE TABLE `t1` (
657
 
  `da` DATETIME DEFAULT NULL
658
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
657
  `da` datetime DEFAULT NULL
 
658
) ENGINE=DEFAULT
659
659
drop table t1;
660
660
create table t1 SELECT dt from t2 UNION select trim(sc) from t2;
661
661
select trim(dt) from t1;
665
665
show create table t1;
666
666
Table   Create Table
667
667
t1      CREATE TABLE `t1` (
668
 
  `dt` VARBINARY(19) DEFAULT NULL
669
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
668
  `dt` varbinary(19) DEFAULT NULL
 
669
) ENGINE=DEFAULT
670
670
drop table t1;
671
671
create table t1 SELECT dt from t2 UNION select sv from t2;
672
672
select * from t1;
676
676
show create table t1;
677
677
Table   Create Table
678
678
t1      CREATE TABLE `t1` (
679
 
  `dt` VARBINARY(40) DEFAULT NULL
680
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
679
  `dt` varbinary(40) DEFAULT NULL
 
680
) ENGINE=DEFAULT
681
681
drop table t1;
682
682
create table t1 SELECT sc from t2 UNION select sv from t2;
683
683
select * from t1;
687
687
show create table t1;
688
688
Table   Create Table
689
689
t1      CREATE TABLE `t1` (
690
 
  `sc` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL
691
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
690
  `sc` varchar(10) DEFAULT NULL
 
691
) ENGINE=DEFAULT
692
692
drop table t1;
693
693
create table t1 SELECT dt from t2 UNION select b from t2;
694
694
select * from t1;
698
698
show create table t1;
699
699
Table   Create Table
700
700
t1      CREATE TABLE `t1` (
701
 
  `dt` BLOB
702
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
701
  `dt` blob
 
702
) ENGINE=DEFAULT
703
703
drop table t1;
704
704
create table t1 SELECT sv from t2 UNION select b from t2;
705
705
select * from t1;
709
709
show create table t1;
710
710
Table   Create Table
711
711
t1      CREATE TABLE `t1` (
712
 
  `sv` BLOB
713
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
712
  `sv` blob
 
713
) ENGINE=DEFAULT
714
714
drop table t1;
715
715
create table t1 SELECT i from t2 UNION select d from t2 UNION select b from t2;
716
716
select * from t1;
721
721
show create table t1;
722
722
Table   Create Table
723
723
t1      CREATE TABLE `t1` (
724
 
  `i` BLOB
725
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
724
  `i` blob
 
725
) ENGINE=DEFAULT
726
726
drop table t1;
727
727
create table t1 SELECT sv from t2 UNION select tx from t2;
728
728
select * from t1;
732
732
show create table t1;
733
733
Table   Create Table
734
734
t1      CREATE TABLE `t1` (
735
 
  `sv` TEXT COLLATE utf8_general_ci
736
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
735
  `sv` text
 
736
) ENGINE=DEFAULT
737
737
drop table t1;
738
738
create table t1 SELECT b from t2 UNION select tx from t2;
739
739
select * from t1;
743
743
show create table t1;
744
744
Table   Create Table
745
745
t1      CREATE TABLE `t1` (
746
 
  `b` BLOB
747
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
746
  `b` blob
 
747
) ENGINE=DEFAULT
748
748
drop table t1,t2;
749
749
create table t1 select 1 union select -1;
750
750
select * from t1;
754
754
show create table t1;
755
755
Table   Create Table
756
756
t1      CREATE TABLE `t1` (
757
 
  `1` BIGINT NOT NULL DEFAULT '0'
758
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
757
  `1` bigint NOT NULL DEFAULT '0'
 
758
) ENGINE=DEFAULT
759
759
drop table t1;
760
760
create table t1 select _latin1"test" union select _latin1"testt" ;
761
761
ERROR 42S22: Unknown column '_latin1' in 'field list'
765
765
show create table t1;
766
766
Table   Create Table
767
767
t1      CREATE TABLE `t1` (
768
 
  `test` VARCHAR(4) COLLATE utf8_general_ci NOT NULL DEFAULT ''
769
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
768
  `test` varchar(4) NOT NULL DEFAULT ''
 
769
) ENGINE=DEFAULT
770
770
drop table t1;
771
771
create table t1 (s char(200));
772
772
insert into t1 values (repeat("1",200));
1008
1008
show create table t1;
1009
1009
Table   Create Table
1010
1010
t1      CREATE TABLE `t1` (
1011
 
  `test` VARCHAR(4) COLLATE utf8_general_ci NOT NULL DEFAULT ''
1012
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1011
  `test` varchar(4) NOT NULL DEFAULT ''
 
1012
) ENGINE=DEFAULT
1013
1013
select count(*) from t1;
1014
1014
count(*)
1015
1015
1
1021
1021
show create table t1;
1022
1022
Table   Create Table
1023
1023
t1      CREATE TABLE `t1` (
1024
 
  `'test' collate utf8_bin` VARCHAR(4) COLLATE utf8_bin DEFAULT NULL
1025
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1024
  `'test' collate utf8_bin` varchar(4) COLLATE utf8_bin DEFAULT NULL
 
1025
) ENGINE=DEFAULT
1026
1026
select count(*) from t1;
1027
1027
count(*)
1028
1028
3
1034
1034
show create table t1;
1035
1035
Table   Create Table
1036
1036
t1      CREATE TABLE `t1` (
1037
 
  `test` VARCHAR(4) COLLATE utf8_bin DEFAULT NULL
1038
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1037
  `test` varchar(4) COLLATE utf8_bin DEFAULT NULL
 
1038
) ENGINE=DEFAULT
1039
1039
select count(*) from t1;
1040
1040
count(*)
1041
1041
3
1047
1047
show create table t1;
1048
1048
Table   Create Table
1049
1049
t1      CREATE TABLE `t1` (
1050
 
  `test` VARCHAR(4) COLLATE utf8_bin DEFAULT NULL
1051
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1050
  `test` varchar(4) COLLATE utf8_bin DEFAULT NULL
 
1051
) ENGINE=DEFAULT
1052
1052
select count(*) from t1;
1053
1053
count(*)
1054
1054
3
1075
1075
show create table t1;
1076
1076
Table   Create Table
1077
1077
t1      CREATE TABLE `t1` (
1078
 
  `a` VARCHAR(1) COLLATE utf8_swedish_ci DEFAULT NULL
1079
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1078
  `a` varchar(1) COLLATE utf8_swedish_ci DEFAULT NULL
 
1079
) ENGINE=DEFAULT
1080
1080
drop table t1;
1081
1081
create table t1 as
1082
1082
(select a from t2) union
1085
1085
show create table t1;
1086
1086
Table   Create Table
1087
1087
t1      CREATE TABLE `t1` (
1088
 
  `a` VARCHAR(1) COLLATE utf8_spanish_ci DEFAULT NULL
1089
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1088
  `a` varchar(1) COLLATE utf8_spanish_ci DEFAULT NULL
 
1089
) ENGINE=DEFAULT
1090
1090
drop table t1;
1091
1091
drop table t2;
1092
1092
create table t1(a1 int, f1 char(10));
1097
1097
order by f2, a1;
1098
1098
show columns from t2;
1099
1099
Field   Type    Null    Default Default_is_NULL On_Update
1100
 
f2      DATE    YES             YES     
1101
 
a1      INTEGER YES             YES     
 
1100
f2      DATE    TRUE            TRUE    
 
1101
a1      INTEGER TRUE            TRUE    
1102
1102
drop table t1, t2;
1103
1103
create table t1 (f1 int);
1104
1104
create table t2 (f1 int, f2 int ,f3 date);
1123
1123
order by sdate;
1124
1124
show columns from t4;
1125
1125
Field   Type    Null    Default Default_is_NULL On_Update
1126
 
sdate   DATE    YES             YES     
 
1126
sdate   DATE    TRUE            TRUE    
1127
1127
drop table t1, t2, t3, t4;
1128
1128
create table t1 (a int not null, b char (10) not null);
1129
1129
insert into t1 values(1,'a'),(2,'b'),(3,'c'),(3,'c');
1195
1195
show create table t2;
1196
1196
Table   Create Table
1197
1197
t2      CREATE TABLE `t2` (
1198
 
  `a` VARCHAR(5) COLLATE utf8_general_ci DEFAULT NULL
1199
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1198
  `a` varchar(5) DEFAULT NULL
 
1199
) ENGINE=DEFAULT
1200
1200
select row_format from data_dictionary.TABLES where table_schema="test" and table_name="t2";
1201
1201
row_format
1202
1202
DEFAULT
1203
1203
show create table t2;
1204
1204
Table   Create Table
1205
1205
t2      CREATE TABLE `t2` (
1206
 
  `a` VARCHAR(5) COLLATE utf8_general_ci DEFAULT NULL
1207
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1206
  `a` varchar(5) DEFAULT NULL
 
1207
) ENGINE=DEFAULT
1208
1208
drop table t1,t2;
1209
1209
CREATE TABLE t1 (a mediumtext);
1210
1210
CREATE TABLE t2 (b varchar(20));
1217
1217
show create table t3;
1218
1218
Table   Create Table
1219
1219
t3      CREATE TABLE `t3` (
1220
 
  `left(a,100000000)` TEXT COLLATE utf8_general_ci
1221
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1220
  `left(a,100000000)` text
 
1221
) ENGINE=DEFAULT
1222
1222
drop tables t1,t2,t3;
1223
1223
CREATE TABLE t1 (a longtext);
1224
1224
CREATE TABLE t2 (b varchar(20));
1231
1231
show create table t3;
1232
1232
Table   Create Table
1233
1233
t3      CREATE TABLE `t3` (
1234
 
  `left(a,100000000)` TEXT COLLATE utf8_general_ci
1235
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1234
  `left(a,100000000)` text
 
1235
) ENGINE=DEFAULT
1236
1236
drop tables t1,t2,t3;
1237
1237
SELECT @tmp_max:= @@max_allowed_packet;
1238
1238
@tmp_max:= @@max_allowed_packet
1239
 
67108864
 
1239
1048576
1240
1240
SET max_allowed_packet=25000000;
1241
1241
CREATE TABLE t1 (a mediumtext);
1242
1242
CREATE TABLE t2 (b varchar(20));
1245
1245
SHOW CREATE TABLE t3;
1246
1246
Table   Create Table
1247
1247
t3      CREATE TABLE `t3` (
1248
 
  `a` TEXT COLLATE utf8_general_ci
1249
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1248
  `a` text
 
1249
) ENGINE=DEFAULT
1250
1250
DROP TABLES t1,t3;
1251
1251
CREATE TABLE t1 (a tinytext);
1252
1252
INSERT INTO t1 VALUES ('a');
1254
1254
SHOW CREATE TABLE t3;
1255
1255
Table   Create Table
1256
1256
t3      CREATE TABLE `t3` (
1257
 
  `a` TEXT COLLATE utf8_general_ci
1258
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1257
  `a` text
 
1258
) ENGINE=DEFAULT
1259
1259
DROP TABLES t1,t3;
1260
1260
CREATE TABLE t1 (a mediumtext);
1261
1261
INSERT INTO t1 VALUES ('a');
1263
1263
SHOW CREATE TABLE t3;
1264
1264
Table   Create Table
1265
1265
t3      CREATE TABLE `t3` (
1266
 
  `a` TEXT COLLATE utf8_general_ci
1267
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1266
  `a` text
 
1267
) ENGINE=DEFAULT
1268
1268
DROP TABLES t1,t3;
1269
1269
CREATE TABLE t1 (a tinyblob);
1270
1270
INSERT INTO t1 VALUES ('a');
1272
1272
SHOW CREATE TABLE t3;
1273
1273
Table   Create Table
1274
1274
t3      CREATE TABLE `t3` (
1275
 
  `a` BLOB
1276
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1275
  `a` blob
 
1276
) ENGINE=DEFAULT
1277
1277
DROP TABLES t1,t2,t3;
1278
1278
SET max_allowed_packet:= @tmp_max;
1279
1279
create table t1 ( id int not null auto_increment, primary key (id), col1 int);
1300
1300
show create table t2;
1301
1301
Table   Create Table
1302
1302
t2      CREATE TABLE `t2` (
1303
 
  `f1` VARCHAR(1) COLLATE utf8_general_ci DEFAULT NULL,
1304
 
  `f2` VARCHAR(5) COLLATE utf8_general_ci DEFAULT NULL,
1305
 
  `f3` BLOB,
1306
 
  `f4` BLOB,
1307
 
  `f5` TIMESTAMP NULL DEFAULT NULL,
1308
 
  `f6` VARCHAR(1) COLLATE utf8_general_ci DEFAULT NULL,
1309
 
  `f7` TEXT COLLATE utf8_general_ci,
1310
 
  `f8` TEXT COLLATE utf8_general_ci
1311
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1303
  `f1` varchar(1) DEFAULT NULL,
 
1304
  `f2` varchar(5) DEFAULT NULL,
 
1305
  `f3` blob,
 
1306
  `f4` blob,
 
1307
  `f5` timestamp NULL DEFAULT NULL,
 
1308
  `f6` varchar(1) DEFAULT NULL,
 
1309
  `f7` text,
 
1310
  `f8` text
 
1311
) ENGINE=DEFAULT
1312
1312
drop table t1, t2;
1313
1313
(select avg(1)) union (select avg(1)) union (select avg(1)) union
1314
1314
(select avg(1)) union (select avg(1)) union (select avg(1)) union
1433
1433
CREATE TABLE t2 SELECT * FROM (SELECT NULL) a UNION SELECT a FROM t1;
1434
1434
DESC t2;
1435
1435
Field   Type    Null    Default Default_is_NULL On_Update
1436
 
NULL    INTEGER YES             YES     
 
1436
NULL    INTEGER TRUE            TRUE    
1437
1437
CREATE TABLE t3 SELECT a FROM t1 UNION SELECT * FROM (SELECT NULL) a;
1438
1438
DESC t3;
1439
1439
Field   Type    Null    Default Default_is_NULL On_Update
1440
 
a       INTEGER YES             YES     
 
1440
a       INTEGER TRUE            TRUE    
1441
1441
CREATE TABLE t4 SELECT NULL;
1442
1442
DESC t4;
1443
1443
Field   Type    Null    Default Default_is_NULL On_Update
1444
 
NULL    VARBINARY       YES             YES     
 
1444
NULL    VARCHAR TRUE            TRUE    
1445
1445
CREATE TABLE t5 SELECT NULL UNION SELECT NULL;
1446
1446
DESC t5;
1447
1447
Field   Type    Null    Default Default_is_NULL On_Update
1448
 
NULL    VARBINARY       YES             YES     
 
1448
NULL    VARCHAR TRUE            TRUE    
1449
1449
CREATE TABLE t6 
1450
1450
SELECT * FROM (SELECT * FROM (SELECT NULL)a) b UNION SELECT a FROM t1;
1451
1451
DESC t6;
1452
1452
Field   Type    Null    Default Default_is_NULL On_Update
1453
 
NULL    INTEGER YES             YES     
 
1453
NULL    INTEGER TRUE            TRUE    
1454
1454
DROP TABLE t1, t2, t3, t4, t5, t6;
1455
1455
End of 5.0 tests