~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/r/union.result

  • Committer: Brian Aker
  • Date: 2010-07-30 20:31:19 UTC
  • mto: This revision was merged to the branch mainline in revision 1679.
  • Revision ID: brian@gaz-20100730203119-89g2ye4zwnvcacxg
First pass in encapsulating row

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 );
515
515
insert into t2 (group_name) values ('Group A');
516
516
insert into t2 (group_name) values ('Group B');
517
517
insert into t3 (user_id, group_id) values (1,1);
518
 
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 CROSS JOIN t2 c;
 
518
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;
519
519
is_in_group     user_name       group_name      id
520
520
1       Tester  Group A 1
521
521
0       Tester  Group A NULL
539
539
select * from t1;
540
540
a
541
541
a
542
 
aa
543
542
show create table t1;
544
543
Table   Create Table
545
544
t1      CREATE TABLE `t1` (
546
 
  `a` VARCHAR(2) COLLATE utf8_general_ci NOT NULL DEFAULT ''
547
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
545
  `a` varchar(1) NOT NULL DEFAULT ''
 
546
) ENGINE=DEFAULT
548
547
drop table t1;
549
548
create table t1 SELECT 12 as a UNION select "aa" as a;
550
549
select * from t1;
554
553
show create table t1;
555
554
Table   Create Table
556
555
t1      CREATE TABLE `t1` (
557
 
  `a` VARBINARY(8) NOT NULL DEFAULT ''
558
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
556
  `a` varbinary(4) NOT NULL DEFAULT ''
 
557
) ENGINE=DEFAULT
559
558
drop table t1;
560
559
create table t1 SELECT 12 as a UNION select 12.2 as a;
561
560
select * from t1;
565
564
show create table t1;
566
565
Table   Create Table
567
566
t1      CREATE TABLE `t1` (
568
 
  `a` DECIMAL(3,1) NOT NULL DEFAULT '0.0'
569
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
567
  `a` decimal(3,1) NOT NULL DEFAULT '0.0'
 
568
) ENGINE=DEFAULT
570
569
drop table t1;
571
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);
572
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');
578
577
show create table t1;
579
578
Table   Create Table
580
579
t1      CREATE TABLE `t1` (
581
 
  `it2` INT DEFAULT NULL
582
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
580
  `it2` int DEFAULT NULL
 
581
) ENGINE=DEFAULT
583
582
drop table t1;
584
583
create table t1 SELECT it2 from t2 UNION select i from t2;
585
584
select * from t1;
589
588
show create table t1;
590
589
Table   Create Table
591
590
t1      CREATE TABLE `t1` (
592
 
  `it2` INT NOT NULL DEFAULT '0'
593
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
591
  `it2` int NOT NULL DEFAULT '0'
 
592
) ENGINE=DEFAULT
594
593
drop table t1;
595
594
create table t1 SELECT i from t2 UNION select f from t2;
596
595
select * from t1;
600
599
show create table t1;
601
600
Table   Create Table
602
601
t1      CREATE TABLE `t1` (
603
 
  `i` DOUBLE DEFAULT NULL
604
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
602
  `i` double DEFAULT NULL
 
603
) ENGINE=DEFAULT
605
604
drop table t1;
606
605
create table t1 SELECT f from t2 UNION select d from t2;
607
606
select * from t1;
611
610
show create table t1;
612
611
Table   Create Table
613
612
t1      CREATE TABLE `t1` (
614
 
  `f` DOUBLE DEFAULT NULL
615
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
613
  `f` double DEFAULT NULL
 
614
) ENGINE=DEFAULT
616
615
drop table t1;
617
616
create table t1 SELECT ib from t2 UNION select f from t2;
618
617
select * from t1;
622
621
show create table t1;
623
622
Table   Create Table
624
623
t1      CREATE TABLE `t1` (
625
 
  `ib` DOUBLE DEFAULT NULL
626
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
624
  `ib` double DEFAULT NULL
 
625
) ENGINE=DEFAULT
627
626
drop table t1;
628
627
create table t1 SELECT ib from t2 UNION select d from t2;
629
628
select * from t1;
633
632
show create table t1;
634
633
Table   Create Table
635
634
t1      CREATE TABLE `t1` (
636
 
  `ib` DOUBLE DEFAULT NULL
637
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
635
  `ib` double DEFAULT NULL
 
636
) ENGINE=DEFAULT
638
637
drop table t1;
639
638
create table t1 SELECT f from t2 UNION select da from t2;
640
639
select * from t1;
644
643
show create table t1;
645
644
Table   Create Table
646
645
t1      CREATE TABLE `t1` (
647
 
  `f` VARBINARY(22) DEFAULT NULL
648
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
646
  `f` varbinary(22) DEFAULT NULL
 
647
) ENGINE=DEFAULT
649
648
drop table t1;
650
649
create table t1 SELECT da from t2 UNION select dt from t2;
651
650
select * from t1;
655
654
show create table t1;
656
655
Table   Create Table
657
656
t1      CREATE TABLE `t1` (
658
 
  `da` DATETIME DEFAULT NULL
659
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
657
  `da` datetime DEFAULT NULL
 
658
) ENGINE=DEFAULT
660
659
drop table t1;
661
660
create table t1 SELECT dt from t2 UNION select trim(sc) from t2;
662
661
select trim(dt) from t1;
666
665
show create table t1;
667
666
Table   Create Table
668
667
t1      CREATE TABLE `t1` (
669
 
  `dt` VARBINARY(40) DEFAULT NULL
670
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
668
  `dt` varbinary(19) DEFAULT NULL
 
669
) ENGINE=DEFAULT
671
670
drop table t1;
672
671
create table t1 SELECT dt from t2 UNION select sv from t2;
673
672
select * from t1;
677
676
show create table t1;
678
677
Table   Create Table
679
678
t1      CREATE TABLE `t1` (
680
 
  `dt` VARBINARY(40) DEFAULT NULL
681
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
679
  `dt` varbinary(40) DEFAULT NULL
 
680
) ENGINE=DEFAULT
682
681
drop table t1;
683
682
create table t1 SELECT sc from t2 UNION select sv from t2;
684
683
select * from t1;
688
687
show create table t1;
689
688
Table   Create Table
690
689
t1      CREATE TABLE `t1` (
691
 
  `sc` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL
692
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
690
  `sc` varchar(10) DEFAULT NULL
 
691
) ENGINE=DEFAULT
693
692
drop table t1;
694
693
create table t1 SELECT dt from t2 UNION select b from t2;
695
694
select * from t1;
699
698
show create table t1;
700
699
Table   Create Table
701
700
t1      CREATE TABLE `t1` (
702
 
  `dt` BLOB
703
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
701
  `dt` blob
 
702
) ENGINE=DEFAULT
704
703
drop table t1;
705
704
create table t1 SELECT sv from t2 UNION select b from t2;
706
705
select * from t1;
710
709
show create table t1;
711
710
Table   Create Table
712
711
t1      CREATE TABLE `t1` (
713
 
  `sv` BLOB
714
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
712
  `sv` blob
 
713
) ENGINE=DEFAULT
715
714
drop table t1;
716
715
create table t1 SELECT i from t2 UNION select d from t2 UNION select b from t2;
717
716
select * from t1;
722
721
show create table t1;
723
722
Table   Create Table
724
723
t1      CREATE TABLE `t1` (
725
 
  `i` BLOB
726
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
724
  `i` blob
 
725
) ENGINE=DEFAULT
727
726
drop table t1;
728
727
create table t1 SELECT sv from t2 UNION select tx from t2;
729
728
select * from t1;
733
732
show create table t1;
734
733
Table   Create Table
735
734
t1      CREATE TABLE `t1` (
736
 
  `sv` TEXT COLLATE utf8_general_ci
737
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
735
  `sv` text
 
736
) ENGINE=DEFAULT
738
737
drop table t1;
739
738
create table t1 SELECT b from t2 UNION select tx from t2;
740
739
select * from t1;
744
743
show create table t1;
745
744
Table   Create Table
746
745
t1      CREATE TABLE `t1` (
747
 
  `b` BLOB
748
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
746
  `b` blob
 
747
) ENGINE=DEFAULT
749
748
drop table t1,t2;
750
749
create table t1 select 1 union select -1;
751
750
select * from t1;
755
754
show create table t1;
756
755
Table   Create Table
757
756
t1      CREATE TABLE `t1` (
758
 
  `1` BIGINT NOT NULL DEFAULT '0'
759
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
757
  `1` bigint NOT NULL DEFAULT '0'
 
758
) ENGINE=DEFAULT
760
759
drop table t1;
761
760
create table t1 select _latin1"test" union select _latin1"testt" ;
762
761
ERROR 42S22: Unknown column '_latin1' in 'field list'
766
765
show create table t1;
767
766
Table   Create Table
768
767
t1      CREATE TABLE `t1` (
769
 
  `test` VARCHAR(5) COLLATE utf8_general_ci NOT NULL DEFAULT ''
770
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
768
  `test` varchar(4) NOT NULL DEFAULT ''
 
769
) ENGINE=DEFAULT
771
770
drop table t1;
772
771
create table t1 (s char(200));
773
772
insert into t1 values (repeat("1",200));
1009
1008
show create table t1;
1010
1009
Table   Create Table
1011
1010
t1      CREATE TABLE `t1` (
1012
 
  `test` VARCHAR(4) COLLATE utf8_general_ci NOT NULL DEFAULT ''
1013
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1011
  `test` varchar(4) NOT NULL DEFAULT ''
 
1012
) ENGINE=DEFAULT
1014
1013
select count(*) from t1;
1015
1014
count(*)
1016
1015
1
1022
1021
show create table t1;
1023
1022
Table   Create Table
1024
1023
t1      CREATE TABLE `t1` (
1025
 
  `'test' collate utf8_bin` VARCHAR(4) COLLATE utf8_bin DEFAULT NULL
1026
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1024
  `'test' collate utf8_bin` varchar(4) COLLATE utf8_bin DEFAULT NULL
 
1025
) ENGINE=DEFAULT
1027
1026
select count(*) from t1;
1028
1027
count(*)
1029
1028
3
1035
1034
show create table t1;
1036
1035
Table   Create Table
1037
1036
t1      CREATE TABLE `t1` (
1038
 
  `test` VARCHAR(4) COLLATE utf8_bin DEFAULT NULL
1039
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1037
  `test` varchar(4) COLLATE utf8_bin DEFAULT NULL
 
1038
) ENGINE=DEFAULT
1040
1039
select count(*) from t1;
1041
1040
count(*)
1042
1041
3
1048
1047
show create table t1;
1049
1048
Table   Create Table
1050
1049
t1      CREATE TABLE `t1` (
1051
 
  `test` VARCHAR(4) COLLATE utf8_bin DEFAULT NULL
1052
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1050
  `test` varchar(4) COLLATE utf8_bin DEFAULT NULL
 
1051
) ENGINE=DEFAULT
1053
1052
select count(*) from t1;
1054
1053
count(*)
1055
1054
3
1076
1075
show create table t1;
1077
1076
Table   Create Table
1078
1077
t1      CREATE TABLE `t1` (
1079
 
  `a` VARCHAR(1) COLLATE utf8_swedish_ci DEFAULT NULL
1080
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1078
  `a` varchar(1) COLLATE utf8_swedish_ci DEFAULT NULL
 
1079
) ENGINE=DEFAULT
1081
1080
drop table t1;
1082
1081
create table t1 as
1083
1082
(select a from t2) union
1086
1085
show create table t1;
1087
1086
Table   Create Table
1088
1087
t1      CREATE TABLE `t1` (
1089
 
  `a` VARCHAR(1) COLLATE utf8_spanish_ci DEFAULT NULL
1090
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1088
  `a` varchar(1) COLLATE utf8_spanish_ci DEFAULT NULL
 
1089
) ENGINE=DEFAULT
1091
1090
drop table t1;
1092
1091
drop table t2;
1093
1092
create table t1(a1 int, f1 char(10));
1159
1158
create table t1 (foo varchar(100)) collate=utf8_bin;
1160
1159
insert into t1 (foo) values ("foo");
1161
1160
select foo from t1 union select 'bar' as foo from dual;
1162
 
ERROR 42S02: Unknown table 'test.dual'
 
1161
ERROR 42S02: Table 'test.dual' doesn't exist
1163
1162
select foo from t1 union select 'bar' as foo;
1164
1163
foo
1165
1164
foo
1196
1195
show create table t2;
1197
1196
Table   Create Table
1198
1197
t2      CREATE TABLE `t2` (
1199
 
  `a` VARCHAR(12) COLLATE utf8_general_ci DEFAULT NULL
1200
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1198
  `a` varchar(5) DEFAULT NULL
 
1199
) ENGINE=DEFAULT
1201
1200
select row_format from data_dictionary.TABLES where table_schema="test" and table_name="t2";
1202
1201
row_format
1203
1202
DEFAULT
1204
1203
show create table t2;
1205
1204
Table   Create Table
1206
1205
t2      CREATE TABLE `t2` (
1207
 
  `a` VARCHAR(12) COLLATE utf8_general_ci DEFAULT NULL
1208
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1206
  `a` varchar(5) DEFAULT NULL
 
1207
) ENGINE=DEFAULT
1209
1208
drop table t1,t2;
1210
1209
CREATE TABLE t1 (a mediumtext);
1211
1210
CREATE TABLE t2 (b varchar(20));
1218
1217
show create table t3;
1219
1218
Table   Create Table
1220
1219
t3      CREATE TABLE `t3` (
1221
 
  `left(a,100000000)` TEXT COLLATE utf8_general_ci
1222
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1220
  `left(a,100000000)` text
 
1221
) ENGINE=DEFAULT
1223
1222
drop tables t1,t2,t3;
1224
1223
CREATE TABLE t1 (a longtext);
1225
1224
CREATE TABLE t2 (b varchar(20));
1232
1231
show create table t3;
1233
1232
Table   Create Table
1234
1233
t3      CREATE TABLE `t3` (
1235
 
  `left(a,100000000)` TEXT COLLATE utf8_general_ci
1236
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1234
  `left(a,100000000)` text
 
1235
) ENGINE=DEFAULT
1237
1236
drop tables t1,t2,t3;
1238
1237
SELECT @tmp_max:= @@max_allowed_packet;
1239
1238
@tmp_max:= @@max_allowed_packet
1240
 
67108864
 
1239
1048576
1241
1240
SET max_allowed_packet=25000000;
1242
1241
CREATE TABLE t1 (a mediumtext);
1243
1242
CREATE TABLE t2 (b varchar(20));
1246
1245
SHOW CREATE TABLE t3;
1247
1246
Table   Create Table
1248
1247
t3      CREATE TABLE `t3` (
1249
 
  `a` TEXT COLLATE utf8_general_ci
1250
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1248
  `a` text
 
1249
) ENGINE=DEFAULT
1251
1250
DROP TABLES t1,t3;
1252
1251
CREATE TABLE t1 (a tinytext);
1253
1252
INSERT INTO t1 VALUES ('a');
1255
1254
SHOW CREATE TABLE t3;
1256
1255
Table   Create Table
1257
1256
t3      CREATE TABLE `t3` (
1258
 
  `a` TEXT COLLATE utf8_general_ci
1259
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1257
  `a` text
 
1258
) ENGINE=DEFAULT
1260
1259
DROP TABLES t1,t3;
1261
1260
CREATE TABLE t1 (a mediumtext);
1262
1261
INSERT INTO t1 VALUES ('a');
1264
1263
SHOW CREATE TABLE t3;
1265
1264
Table   Create Table
1266
1265
t3      CREATE TABLE `t3` (
1267
 
  `a` TEXT COLLATE utf8_general_ci
1268
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1266
  `a` text
 
1267
) ENGINE=DEFAULT
1269
1268
DROP TABLES t1,t3;
1270
1269
CREATE TABLE t1 (a tinyblob);
1271
1270
INSERT INTO t1 VALUES ('a');
1273
1272
SHOW CREATE TABLE t3;
1274
1273
Table   Create Table
1275
1274
t3      CREATE TABLE `t3` (
1276
 
  `a` BLOB
1277
 
) ENGINE=DEFAULT COLLATE = utf8_general_ci
 
1275
  `a` blob
 
1276
) ENGINE=DEFAULT
1278
1277
DROP TABLES t1,t2,t3;
1279
1278
SET max_allowed_packet:= @tmp_max;
1280
1279
create table t1 ( id int not null auto_increment, primary key (id), col1 int);
1301
1300
show create table t2;
1302
1301
Table   Create Table
1303
1302
t2      CREATE TABLE `t2` (
1304
 
  `f1` VARCHAR(1) COLLATE utf8_general_ci DEFAULT NULL,
1305
 
  `f2` VARCHAR(5) COLLATE utf8_general_ci DEFAULT NULL,
1306
 
  `f3` BLOB,
1307
 
  `f4` BLOB,
1308
 
  `f5` TIMESTAMP NULL DEFAULT NULL,
1309
 
  `f6` VARCHAR(1) COLLATE utf8_general_ci DEFAULT NULL,
1310
 
  `f7` TEXT COLLATE utf8_general_ci,
1311
 
  `f8` TEXT COLLATE utf8_general_ci
1312
 
) 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
1313
1312
drop table t1, t2;
1314
1313
(select avg(1)) union (select avg(1)) union (select avg(1)) union
1315
1314
(select avg(1)) union (select avg(1)) union (select avg(1)) union
1359
1358
select '12' union select '12345';
1360
1359
12
1361
1360
12
1362
 
12345
1363
1361
CREATE TABLE t1 (a int);
1364
1362
INSERT INTO t1 VALUES (3),(1),(2),(4),(1);
1365
1363
SELECT a FROM (SELECT a FROM t1 UNION SELECT a FROM t1 ORDER BY a) AS test;
1443
1441
CREATE TABLE t4 SELECT NULL;
1444
1442
DESC t4;
1445
1443
Field   Type    Null    Default Default_is_NULL On_Update
1446
 
NULL    VARBINARY       YES             YES     
 
1444
NULL    VARCHAR YES             YES     
1447
1445
CREATE TABLE t5 SELECT NULL UNION SELECT NULL;
1448
1446
DESC t5;
1449
1447
Field   Type    Null    Default Default_is_NULL On_Update
1450
 
NULL    VARBINARY       YES             YES     
 
1448
NULL    VARCHAR YES             YES     
1451
1449
CREATE TABLE t6 
1452
1450
SELECT * FROM (SELECT * FROM (SELECT NULL)a) b UNION SELECT a FROM t1;
1453
1451
DESC t6;