~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/union.test

  • Committer: Brian Aker
  • Date: 2009-05-23 17:13:03 UTC
  • mfrom: (1034.1.8 merge)
  • Revision ID: brian@gaz-20090523171303-d28xhutqic0xe2b4
Merge Brian

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
(select a,b from t1 limit 2)  union all (select a,b from t2 order by a) limit 4;
24
24
(select a,b from t1 limit 2)  union all (select a,b from t2 order by a limit 1);
25
25
(select a,b from t1 limit 2)  union all (select a,b from t2 order by a limit 1) order by b desc;
26
 
--error ER_TABLENAME_NOT_ALLOWED_HERE
 
26
--error 1250
27
27
(select a,b from t1 limit 2)  union all (select a,b from t2 order by a limit 1) order by t1.b;
28
 
--replace_column 9 #
29
28
explain extended (select a,b from t1 limit 2)  union all (select a,b from t2 order by a limit 1) order by b desc;
30
29
(select sql_calc_found_rows  a,b from t1 limit 2)  union all (select a,b from t2 order by a) limit 2;
31
30
select found_rows();
36
35
# Test some error conditions with UNION
37
36
#
38
37
 
39
 
--replace_column 9 #
40
38
explain select a,b from t1 union all select a,b from t2;
41
39
 
42
40
--error  1054
43
41
explain select xx from t1 union select 1;
44
 
--error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
 
42
--error 1222
45
43
explain select a,b from t1 union select 1;
46
 
--error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
 
44
--error 1222
47
45
explain select 1 union select a,b from t1 union select 1;
48
 
--error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
 
46
--error 1222
49
47
explain select a,b from t1 union select 1 limit 0;
50
48
 
51
 
--error ER_WRONG_USAGE
 
49
--error 1221
52
50
select a,b from t1 into outfile 'skr' union select a,b from t2;
53
51
 
54
 
--error ER_WRONG_USAGE
 
52
--error 1221
55
53
select a,b from t1 order by a union select a,b from t2;
56
54
 
57
 
--error ER_WRONG_USAGE
 
55
--error 1221
58
56
insert into t3 select a from t1 order by a union select a from t2;
59
57
 
60
 
--error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
 
58
--error 1222
61
59
create table t3 select a,b from t1 union select a from t2;
62
60
 
63
 
--error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
 
61
--error 1222
64
62
select a,b from t1 union select a from t2;
65
63
 
66
 
--error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
 
64
--error 1222
67
65
select * from t1 union select a from t2;
68
66
 
69
 
--error ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
 
67
--error 1222
70
68
select a from t1 union select * from t2;
71
69
 
72
 
--error ER_CANT_USE_OPTION_HERE
 
70
--error 1234
73
71
select * from t1 union select SQL_BUFFER_RESULT * from t2;
74
72
 
75
73
# Test CREATE, INSERT and REPLACE
83
81
#
84
82
# Test some unions without tables
85
83
#
86
 
--error ER_NO_TABLES_USED
 
84
--error 1096
87
85
select * union select 1;
88
86
select 1 as a,(select a union select a);
89
 
--error ER_BAD_FIELD_ERROR
 
87
--error 1054
90
88
(select 1) union (select 2) order by 0;
91
89
SELECT @a:=1 UNION SELECT @a:=@a+1;
92
 
--error ER_BAD_FIELD_ERROR
 
90
--error 1054
93
91
(SELECT 1) UNION (SELECT 2) ORDER BY (SELECT a);
94
92
(SELECT 1,3) UNION (SELECT 2,1) ORDER BY (SELECT 2);
95
93
 
103
101
  `same` int NOT NULL default '1',
104
102
  PRIMARY KEY  (`pseudo1`),
105
103
  KEY `pseudo` (`pseudo`)
106
 
);
 
104
) ENGINE=MyISAM;
107
105
INSERT INTO t1 (pseudo,pseudo1,same) VALUES ('joce', 'testtt', 1),('joce', 'tsestset', 1),('dekad', 'joce', 1);
108
106
SELECT pseudo FROM t1 WHERE pseudo1='joce' UNION SELECT pseudo FROM t1 WHERE pseudo='joce';
109
107
SELECT pseudo1 FROM t1 WHERE pseudo1='joce' UNION SELECT pseudo1 FROM t1 WHERE pseudo='joce';
219
217
(SELECT SQL_CALC_FOUND_ROWS * FROM t1) UNION all (SELECT * FROM t2 LIMIT 1);
220
218
select found_rows();
221
219
# This used to work in 4.0 but not anymore in 4.1
222
 
--error ER_PARSE_ERROR
 
220
--error 1064
223
221
(SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1) UNION SELECT * FROM t2 LIMIT 1;
224
222
#select found_rows();
225
223
 
250
248
(SELECT * FROM t1 ORDER by a) UNION ALL (SELECT * FROM t2 ORDER BY a) ORDER BY A desc LIMIT 4;
251
249
 
252
250
# Wrong usage
253
 
--error ER_CANT_USE_OPTION_HERE
 
251
--error 1234
254
252
(SELECT * FROM t1) UNION all (SELECT SQL_CALC_FOUND_ROWS * FROM t2) LIMIT 1;
255
253
 
256
254
create temporary table t1 select a from t1 union select a from t2;
257
255
drop temporary table t1;
258
 
--error ER_UPDATE_TABLE_USED
 
256
--error 1093
259
257
create table t1 select a from t1 union select a from t2;
260
 
--error ER_BAD_FIELD_ERROR
 
258
--error 1054
261
259
select a from t1 union select a from t2 order by t2.a;
262
260
drop table t1,t2;
263
261
 
278
276
#
279
277
# Test for another bug with UNION and LEFT JOIN
280
278
#
281
 
CREATE TEMPORARY TABLE t1 (  id int default '0') ENGINE=MyISAM;
 
279
CREATE TABLE t1 (  id int default '0') ENGINE=MyISAM;
282
280
INSERT INTO t1 (id) VALUES("1");
283
 
CREATE TEMPORARY TABLE t2 ( id int default '0',  id_master int 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;
284
282
INSERT INTO t2 (id, id_master, text1, text2) VALUES("1", "1",
285
283
"foo1", "bar1");
286
284
INSERT INTO t2 (id, id_master, text1, text2) VALUES("2", "1",
457
455
insert into t1 select * from t2;
458
456
insert into t2 select * from t1;
459
457
set local tmp_table_size=1024;
460
 
select SQL_BIG_RESULT count(*) from (select SQL_BIG_RESULT * from t1 union all select * from t2 order by 1) b;
 
458
select count(*) from (select * from t1 union all select * from t2 order by 1) b;
461
459
select count(*) from t1;
462
460
select count(*) from t2;
463
461
drop table t1,t2;
474
472
insert t1 select a+1, a+b from t1;
475
473
insert t1 select a+1, a+b from t1;
476
474
FLUSH STATUS;
477
 
--replace_column 2 #
478
475
show status like 'Slow_queries';
479
476
select count(*) from t1 where a=7;
480
 
--replace_column 2 #
481
477
show status like 'Slow_queries';
482
478
select count(*) from t1 where b=13;
483
 
--replace_column 2 #
484
479
show status like 'Slow_queries';
485
480
select count(*) from t1 where b=13 union select count(*) from t1 where a=7;
486
 
--replace_column 2 #
487
481
show status like 'Slow_queries';
488
482
select count(*) from t1 where a=7 union select count(*) from t1 where b=13;
489
 
--replace_column 2 #
490
483
show status like 'Slow_queries';
491
484
# additional test for examined rows
492
485
flush status;
493
486
select a from t1 where b not in (1,2,3) union select a from t1 where b not in (4,5,6); 
494
 
--replace_column 2 #
495
487
show status like 'Slow_queries';
496
488
drop table t1;
497
489
 
498
490
#
499
491
# Column 'name' cannot be null (error with union and left join) (bug #2508)
500
492
#
501
 
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);
 
493
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;
502
494
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');
503
495
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);
504
496
drop  table t1;
548
540
#
549
541
CREATE TABLE t1 (i int default NULL,c char(1) default NULL,KEY i (i));
550
542
CREATE TABLE t2 (i int default NULL,c char(1) default NULL,KEY i (i));
551
 
--error ER_BAD_FIELD_ERROR
 
543
--error 1054
552
544
explain (select * from t1) union (select * from t2) order by not_existing_column;
553
545
drop table t1, t2;
554
546
 
602
594
create table t3 (a ENUM('Yes', 'No') NOT NULL);
603
595
create table t4 (a ENUM('aaa', 'bbb') NOT NULL);
604
596
insert into t3 values (1);
605
 
--error ER_INVALID_ENUM_VALUE # Bad enum
 
597
--error 1691 # Bad enum
606
598
insert into t4 values (3);
607
599
select "1" as a union select a from t1;
608
600
select a as a from t1 union select "1";
653
645
drop table t1;
654
646
 
655
647
# Drizzle doesn't support specifying character set, it is all UTF8
656
 
--error ER_PARSE_ERROR
 
648
--error 1064
657
649
create table t2 (
658
650
a char character set utf8 collate utf8_swedish_ci,
659
651
b char character set utf8 collate utf8_spanish_ci);
661
653
create table t2 (
662
654
a char collate utf8_swedish_ci,
663
655
b char collate utf8_spanish_ci);
664
 
--error ER_CANT_AGGREGATE_NCOLLATIONS
 
656
--error 1271
665
657
create table t1 as
666
658
(select a from t2) union
667
659
(select b from t2);
668
660
 
669
 
--error ER_WRONG_COLUMN_NAME
 
661
--error 1166
670
662
create table t1 as
671
663
(select a collate utf8_swedish_ci from t2) union
672
664
(select b from t2);
746
738
# Bug#15949 union + illegal mix of collations (IMPLICIT + COERCIBLE)
747
739
#
748
740
select concat('a', 'b' collate utf8_bin);
749
 
create table t1 (foo varchar(100)) collate=utf8_bin;
 
741
create table t1 (foo varchar(100)) collate utf8_bin;
750
742
insert into t1 (foo) values ("foo");
751
 
--error ER_NO_SUCH_TABLE
 
743
--error 1146
752
744
select foo from t1 union select 'bar' as foo from dual;
753
745
select foo from t1 union select 'bar' as foo;
754
746
drop table t1;
807
799
create table t2 select * from t1 union select 'abcdefghijkl';
808
800
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
809
801
show create table t2;
810
 
select row_format from data_dictionary.TABLES where table_schema="test" and table_name="t2";
 
802
select row_format from information_schema.TABLES where table_schema="test" and table_name="t2";
 
803
alter table t2 ROW_FORMAT=fixed;
811
804
--replace_regex /ENGINE=[a-zA-Z]+/ENGINE=DEFAULT/
812
805
show create table t2;
813
806
drop table t1,t2;
956
949
INSERT INTO t1 VALUES (3),(1),(2),(4),(1);
957
950
 
958
951
SELECT a FROM (SELECT a FROM t1 UNION SELECT a FROM t1 ORDER BY a) AS test;
959
 
--error ER_BAD_FIELD_ERROR 
 
952
--error 1054 
960
953
SELECT a FROM (SELECT a FROM t1 UNION SELECT a FROM t1 ORDER BY c) AS test;
961
954
 
962
955
DROP TABLE t1;
964
957
#
965
958
# Bug#23345: Wrongly allowed INTO in a non-last select of a UNION.
966
959
#
967
 
--error ER_WRONG_USAGE
 
960
--error 1221
968
961
(select 1 into @var) union (select 1);
969
962
(select 1) union (select 1 into @var);
970
963
select @var;
971
 
--error ER_TOO_MANY_ROWS
 
964
--error 1172
972
965
(select 2) union (select 1 into @var);
973
966
 
974
967
#