MDEV-18844 Implement EXCEPT ALL and INTERSECT ALL operations
This commit is contained in:
parent
afe969ba05
commit
a896bebfa6
@ -54,7 +54,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
3 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
||||
NULL UNION RESULT <union1,4> ALL NULL NULL NULL NULL NULL NULL
|
||||
Warnings:
|
||||
Note 1003 /* select#1 */ select 1 AS `1` union /* select#4 */ select `__4`.`1` AS `1` from (/* select#2 */ select 1 AS `1` union all /* select#3 */ select 1 AS `1`) `__4`
|
||||
Note 1003 /* select#1 */ select 1 AS `1` union /* select#4 */ select `__4`.`1` AS `1` from (/* select#2 */ select 1 AS `1` union /* select#3 */ select 1 AS `1`) `__4`
|
||||
select 1 union select 1 union all select 1;
|
||||
1
|
||||
1
|
||||
|
@ -507,8 +507,6 @@ select 1 as a from dual union all select 1 from dual;
|
||||
a
|
||||
1
|
||||
1
|
||||
select 1 from dual except all select 1 from dual;
|
||||
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'all select 1 from dual' at line 1
|
||||
create table t1 (a int, b blob, a1 int, b1 blob) engine=MyISAM;
|
||||
create table t2 (c int, d blob, c1 int, d1 blob) engine=MyISAM;
|
||||
insert into t1 values (1,"ddd", 1, "sdfrrwwww"),(2, "fgh", 2, "dffggtt");
|
||||
|
@ -67,7 +67,6 @@ select 1 from dual ORDER BY 1 except select 1 from dual;
|
||||
|
||||
select 1 as a from dual union all select 1 from dual;
|
||||
--error ER_PARSE_ERROR
|
||||
select 1 from dual except all select 1 from dual;
|
||||
|
||||
|
||||
create table t1 (a int, b blob, a1 int, b1 blob) engine=MyISAM;
|
||||
|
660
mysql-test/main/except_all.result
Normal file
660
mysql-test/main/except_all.result
Normal file
@ -0,0 +1,660 @@
|
||||
create table t1 (a int, b int) engine=MyISAM;
|
||||
create table t2 (c int, d int) engine=MyISAM;
|
||||
insert into t1 values (1,1),(2,2),(3,3),(2,2),(4,4),(4,4),(4,4);
|
||||
insert into t2 values (1,1),(1,1),(1,1),(2,2),(3,3),(3,3),(5,5);
|
||||
select * from t1 except select * from t2;
|
||||
a b
|
||||
4 4
|
||||
select * from t1 except all select * from t2;
|
||||
a b
|
||||
4 4
|
||||
2 2
|
||||
4 4
|
||||
4 4
|
||||
select * from t1 except all select c+1,d+1 from t2;
|
||||
a b
|
||||
1 1
|
||||
4 4
|
||||
(select * from t1) except all (select * from t2);
|
||||
a b
|
||||
4 4
|
||||
2 2
|
||||
4 4
|
||||
4 4
|
||||
select * from ((select * from t1) except all (select * from t2)) a;
|
||||
a b
|
||||
4 4
|
||||
2 2
|
||||
4 4
|
||||
4 4
|
||||
select * from ((select a from t1) except all (select c from t2)) a;
|
||||
a
|
||||
4
|
||||
2
|
||||
4
|
||||
4
|
||||
select * from t1 except all select * from t1 union all select * from t1 union all select * from t1 except select * from t2;
|
||||
a b
|
||||
4 4
|
||||
select * from t1 except all select * from t1 union all select * from t1 union all select * from t1 except all select * from t2;
|
||||
a b
|
||||
4 4
|
||||
2 2
|
||||
4 4
|
||||
4 4
|
||||
4 4
|
||||
4 4
|
||||
4 4
|
||||
2 2
|
||||
2 2
|
||||
select * from (select * from t1 except all select * from t2) q1 except all select * from (select * from t1 except all select * from t2) q2;
|
||||
a b
|
||||
EXPLAIN select * from t1 except all select * from t2;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 PRIMARY t1 ALL NULL NULL NULL NULL 7
|
||||
2 EXCEPT t2 ALL NULL NULL NULL NULL 7
|
||||
NULL EXCEPT RESULT <except1,2> ALL NULL NULL NULL NULL NULL
|
||||
EXPLAIN format=json select * from t1 except all select * from t2;
|
||||
EXPLAIN
|
||||
{
|
||||
"query_block": {
|
||||
"union_result": {
|
||||
"table_name": "<except1,2>",
|
||||
"access_type": "ALL",
|
||||
"query_specifications": [
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 1,
|
||||
"table": {
|
||||
"table_name": "t1",
|
||||
"access_type": "ALL",
|
||||
"rows": 7,
|
||||
"filtered": 100
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 2,
|
||||
"operation": "EXCEPT",
|
||||
"table": {
|
||||
"table_name": "t2",
|
||||
"access_type": "ALL",
|
||||
"rows": 7,
|
||||
"filtered": 100
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
EXPLAIN extended (select * from t1) except all (select * from t2);
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t1 ALL NULL NULL NULL NULL 7 100.00
|
||||
2 EXCEPT t2 ALL NULL NULL NULL NULL 7 100.00
|
||||
NULL EXCEPT RESULT <except1,2> ALL NULL NULL NULL NULL NULL NULL
|
||||
Warnings:
|
||||
Note 1003 (/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1`) except all (/* select#2 */ select `test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2`)
|
||||
EXPLAIN extended select * from ((select * from t1) except all (select * from t2)) a;
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 7 100.00
|
||||
2 DERIVED t1 ALL NULL NULL NULL NULL 7 100.00
|
||||
3 EXCEPT t2 ALL NULL NULL NULL NULL 7 100.00
|
||||
NULL EXCEPT RESULT <except2,3> ALL NULL NULL NULL NULL NULL NULL
|
||||
Warnings:
|
||||
Note 1003 /* select#1 */ select `a`.`a` AS `a`,`a`.`b` AS `b` from (/* select#2 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` except all (/* select#3 */ select `test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2`)) `a`
|
||||
ANALYZE format=json select * from ((select a,b from t1) except all (select c,d from t2)) a;
|
||||
ANALYZE
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 1,
|
||||
"r_loops": 1,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"table": {
|
||||
"table_name": "<derived2>",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 7,
|
||||
"r_rows": 4,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100,
|
||||
"materialized": {
|
||||
"query_block": {
|
||||
"union_result": {
|
||||
"table_name": "<except2,3>",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"r_rows": 4,
|
||||
"query_specifications": [
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 2,
|
||||
"r_loops": 1,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"table": {
|
||||
"table_name": "t1",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 7,
|
||||
"r_rows": 7,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 3,
|
||||
"operation": "EXCEPT",
|
||||
"r_loops": 1,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"table": {
|
||||
"table_name": "t2",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 7,
|
||||
"r_rows": 7,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ANALYZE format=json select * from ((select a from t1) except all (select c from t2)) a;
|
||||
ANALYZE
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 1,
|
||||
"r_loops": 1,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"table": {
|
||||
"table_name": "<derived2>",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 7,
|
||||
"r_rows": 4,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100,
|
||||
"materialized": {
|
||||
"query_block": {
|
||||
"union_result": {
|
||||
"table_name": "<except2,3>",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"r_rows": 4,
|
||||
"query_specifications": [
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 2,
|
||||
"r_loops": 1,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"table": {
|
||||
"table_name": "t1",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 7,
|
||||
"r_rows": 7,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 3,
|
||||
"operation": "EXCEPT",
|
||||
"r_loops": 1,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"table": {
|
||||
"table_name": "t2",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 7,
|
||||
"r_rows": 7,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
select * from ((select a from t1) except all (select c from t2)) a;
|
||||
a
|
||||
4
|
||||
2
|
||||
4
|
||||
4
|
||||
prepare stmt from "(select a,b from t1) except all (select c,d from t2)";
|
||||
execute stmt;
|
||||
a b
|
||||
4 4
|
||||
2 2
|
||||
4 4
|
||||
4 4
|
||||
execute stmt;
|
||||
a b
|
||||
4 4
|
||||
2 2
|
||||
4 4
|
||||
4 4
|
||||
prepare stmt from "select * from ((select a,b from t1) except all (select c,d from t2)) a";
|
||||
execute stmt;
|
||||
a b
|
||||
4 4
|
||||
2 2
|
||||
4 4
|
||||
4 4
|
||||
execute stmt;
|
||||
a b
|
||||
4 4
|
||||
2 2
|
||||
4 4
|
||||
4 4
|
||||
drop tables t1,t2;
|
||||
create table t1 (a int, b int) engine=MyISAM;
|
||||
create table t2 (c int, d int) engine=MyISAM;
|
||||
create table t3 (e int, f int) engine=MyISAM;
|
||||
create table t4 (g int, h int) engine=MyISAM;
|
||||
insert into t1 values (1,1),(2,2),(2,2);
|
||||
insert into t2 values (2,2),(3,3);
|
||||
insert into t3 values (4,4),(5,5),(4,4);
|
||||
insert into t4 values (4,4),(7,7),(4,4);
|
||||
(select a,b,e,f from t1,t3) except all (select c,d,g,h from t2,t4);
|
||||
a b e f
|
||||
1 1 4 4
|
||||
2 2 4 4
|
||||
1 1 5 5
|
||||
2 2 5 5
|
||||
1 1 4 4
|
||||
2 2 4 4
|
||||
2 2 5 5
|
||||
select * from ((select a,b,e,f from t1,t3) except all (select c,d,g,h from t2,t4)) t;
|
||||
a b e f
|
||||
1 1 4 4
|
||||
2 2 4 4
|
||||
1 1 5 5
|
||||
2 2 5 5
|
||||
1 1 4 4
|
||||
2 2 4 4
|
||||
2 2 5 5
|
||||
(select * from t1,t3) except all (select * from t2,t4);
|
||||
a b e f
|
||||
1 1 4 4
|
||||
2 2 4 4
|
||||
1 1 5 5
|
||||
2 2 5 5
|
||||
1 1 4 4
|
||||
2 2 4 4
|
||||
2 2 5 5
|
||||
(select a,b,e from t1,t3) except all (select c,d,g from t2,t4);
|
||||
a b e
|
||||
1 1 4
|
||||
2 2 4
|
||||
1 1 5
|
||||
2 2 5
|
||||
1 1 4
|
||||
2 2 4
|
||||
2 2 5
|
||||
EXPLAIN (select a,b,e,f from t1,t3) except all (select c,d,g,h from t2,t4);
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 PRIMARY t1 ALL NULL NULL NULL NULL 3
|
||||
1 PRIMARY t3 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join)
|
||||
2 EXCEPT t2 ALL NULL NULL NULL NULL 2
|
||||
2 EXCEPT t4 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join)
|
||||
NULL EXCEPT RESULT <except1,2> ALL NULL NULL NULL NULL NULL
|
||||
EXPLAIN select * from ((select a,b,e,f from t1,t3) except all (select c,d,g,h from t2,t4)) t;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 9
|
||||
2 DERIVED t1 ALL NULL NULL NULL NULL 3
|
||||
2 DERIVED t3 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join)
|
||||
3 EXCEPT t2 ALL NULL NULL NULL NULL 2
|
||||
3 EXCEPT t4 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join)
|
||||
NULL EXCEPT RESULT <except2,3> ALL NULL NULL NULL NULL NULL
|
||||
EXPLAIN extended select * from ((select a,b,e,f from t1,t3) except all (select c,d,g,h from t2,t4)) t;
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 9 100.00
|
||||
2 DERIVED t1 ALL NULL NULL NULL NULL 3 100.00
|
||||
2 DERIVED t3 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
|
||||
3 EXCEPT t2 ALL NULL NULL NULL NULL 2 100.00
|
||||
3 EXCEPT t4 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join)
|
||||
NULL EXCEPT RESULT <except2,3> ALL NULL NULL NULL NULL NULL NULL
|
||||
Warnings:
|
||||
Note 1003 /* select#1 */ select `t`.`a` AS `a`,`t`.`b` AS `b`,`t`.`e` AS `e`,`t`.`f` AS `f` from (/* select#2 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t1` join `test`.`t3` except all (/* select#3 */ select `test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d`,`test`.`t4`.`g` AS `g`,`test`.`t4`.`h` AS `h` from `test`.`t2` join `test`.`t4`)) `t`
|
||||
EXPLAIN format=json select * from ((select a,b,e,f from t1,t3) except all (select c,d,g,h from t2,t4)) t;
|
||||
EXPLAIN
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 1,
|
||||
"table": {
|
||||
"table_name": "<derived2>",
|
||||
"access_type": "ALL",
|
||||
"rows": 9,
|
||||
"filtered": 100,
|
||||
"materialized": {
|
||||
"query_block": {
|
||||
"union_result": {
|
||||
"table_name": "<except2,3>",
|
||||
"access_type": "ALL",
|
||||
"query_specifications": [
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 2,
|
||||
"table": {
|
||||
"table_name": "t1",
|
||||
"access_type": "ALL",
|
||||
"rows": 3,
|
||||
"filtered": 100
|
||||
},
|
||||
"block-nl-join": {
|
||||
"table": {
|
||||
"table_name": "t3",
|
||||
"access_type": "ALL",
|
||||
"rows": 3,
|
||||
"filtered": 100
|
||||
},
|
||||
"buffer_type": "flat",
|
||||
"buffer_size": "119",
|
||||
"join_type": "BNL"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 3,
|
||||
"operation": "EXCEPT",
|
||||
"table": {
|
||||
"table_name": "t2",
|
||||
"access_type": "ALL",
|
||||
"rows": 2,
|
||||
"filtered": 100
|
||||
},
|
||||
"block-nl-join": {
|
||||
"table": {
|
||||
"table_name": "t4",
|
||||
"access_type": "ALL",
|
||||
"rows": 3,
|
||||
"filtered": 100
|
||||
},
|
||||
"buffer_type": "flat",
|
||||
"buffer_size": "119",
|
||||
"join_type": "BNL"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ANALYZE format=json (select a,b,e,f from t1,t3) except all (select c,d,g,h from t2,t4);
|
||||
ANALYZE
|
||||
{
|
||||
"query_block": {
|
||||
"union_result": {
|
||||
"table_name": "<except1,2>",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"r_rows": 7,
|
||||
"query_specifications": [
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 1,
|
||||
"r_loops": 1,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"table": {
|
||||
"table_name": "t1",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 3,
|
||||
"r_rows": 3,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100
|
||||
},
|
||||
"block-nl-join": {
|
||||
"table": {
|
||||
"table_name": "t3",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 3,
|
||||
"r_rows": 3,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100
|
||||
},
|
||||
"buffer_type": "flat",
|
||||
"buffer_size": "119",
|
||||
"join_type": "BNL",
|
||||
"r_filtered": 100
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 2,
|
||||
"operation": "EXCEPT",
|
||||
"r_loops": 1,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"table": {
|
||||
"table_name": "t2",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 2,
|
||||
"r_rows": 2,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100
|
||||
},
|
||||
"block-nl-join": {
|
||||
"table": {
|
||||
"table_name": "t4",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 3,
|
||||
"r_rows": 3,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100
|
||||
},
|
||||
"buffer_type": "flat",
|
||||
"buffer_size": "119",
|
||||
"join_type": "BNL",
|
||||
"r_filtered": 100
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
ANALYZE format=json select * from ((select a,b,e,f from t1,t3) except all (select c,d,g,h from t2,t4)) t;
|
||||
ANALYZE
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 1,
|
||||
"r_loops": 1,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"table": {
|
||||
"table_name": "<derived2>",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 9,
|
||||
"r_rows": 7,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100,
|
||||
"materialized": {
|
||||
"query_block": {
|
||||
"union_result": {
|
||||
"table_name": "<except2,3>",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"r_rows": 7,
|
||||
"query_specifications": [
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 2,
|
||||
"r_loops": 1,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"table": {
|
||||
"table_name": "t1",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 3,
|
||||
"r_rows": 3,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100
|
||||
},
|
||||
"block-nl-join": {
|
||||
"table": {
|
||||
"table_name": "t3",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 3,
|
||||
"r_rows": 3,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100
|
||||
},
|
||||
"buffer_type": "flat",
|
||||
"buffer_size": "119",
|
||||
"join_type": "BNL",
|
||||
"r_filtered": 100
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 3,
|
||||
"operation": "EXCEPT",
|
||||
"r_loops": 1,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"table": {
|
||||
"table_name": "t2",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 2,
|
||||
"r_rows": 2,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100
|
||||
},
|
||||
"block-nl-join": {
|
||||
"table": {
|
||||
"table_name": "t4",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 3,
|
||||
"r_rows": 3,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100
|
||||
},
|
||||
"buffer_type": "flat",
|
||||
"buffer_size": "119",
|
||||
"join_type": "BNL",
|
||||
"r_filtered": 100
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
prepare stmt from "(select a,b,e,f from t1,t3) except all (select c,d,g,h from t2,t4)";
|
||||
execute stmt;
|
||||
a b e f
|
||||
1 1 4 4
|
||||
2 2 4 4
|
||||
1 1 5 5
|
||||
2 2 5 5
|
||||
1 1 4 4
|
||||
2 2 4 4
|
||||
2 2 5 5
|
||||
execute stmt;
|
||||
a b e f
|
||||
1 1 4 4
|
||||
2 2 4 4
|
||||
1 1 5 5
|
||||
2 2 5 5
|
||||
1 1 4 4
|
||||
2 2 4 4
|
||||
2 2 5 5
|
||||
prepare stmt from "select * from ((select a,b,e,f from t1,t3) except all (select c,d,g,h from t2,t4)) a";
|
||||
execute stmt;
|
||||
a b e f
|
||||
1 1 4 4
|
||||
2 2 4 4
|
||||
1 1 5 5
|
||||
2 2 5 5
|
||||
1 1 4 4
|
||||
2 2 4 4
|
||||
2 2 5 5
|
||||
execute stmt;
|
||||
a b e f
|
||||
1 1 4 4
|
||||
2 2 4 4
|
||||
1 1 5 5
|
||||
2 2 5 5
|
||||
1 1 4 4
|
||||
2 2 4 4
|
||||
2 2 5 5
|
||||
drop tables t1,t2,t3,t4;
|
||||
select 1 as a from dual except all select 1 from dual;
|
||||
a
|
||||
(select 1 from dual) except all (select 1 from dual);
|
||||
1
|
||||
(select 1 from dual into @v) except all (select 1 from dual);
|
||||
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'into @v) except all (select 1 from dual)' at line 1
|
||||
select 1 from dual ORDER BY 1 except all select 1 from dual;
|
||||
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'except all select 1 from dual' at line 1
|
||||
select 1 as a from dual union all select 1 from dual;
|
||||
a
|
||||
1
|
||||
1
|
||||
create table t1 (a int, b blob, a1 int, b1 blob) engine=MyISAM;
|
||||
create table t2 (c int, d blob, c1 int, d1 blob) engine=MyISAM;
|
||||
insert into t1 values (1,"ddd", 1, "sdfrrwwww"),(2, "fgh", 2, "dffggtt"),(2, "fgh", 2, "dffggtt");
|
||||
insert into t2 values (2, "fgh", 2, "dffggtt"),(3, "ffggddd", 3, "dfgg");
|
||||
(select a,b,b1 from t1) except all (select c,d,d1 from t2);
|
||||
a b b1
|
||||
1 ddd sdfrrwwww
|
||||
2 fgh dffggtt
|
||||
create table t3 (select a,b,b1 from t1) except all (select c,d,d1 from t2);
|
||||
show create table t3;
|
||||
Table Create Table
|
||||
t3 CREATE TABLE `t3` (
|
||||
`a` int(11) DEFAULT NULL,
|
||||
`b` blob DEFAULT NULL,
|
||||
`b1` blob DEFAULT NULL
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1
|
||||
drop tables t1,t2,t3;
|
||||
CREATE TABLE t (i INT);
|
||||
INSERT INTO t VALUES (1),(2);
|
||||
SELECT * FROM t WHERE i != ANY ( SELECT 3 EXCEPT ALL SELECT 3 );
|
||||
i
|
||||
drop table t;
|
99
mysql-test/main/except_all.test
Normal file
99
mysql-test/main/except_all.test
Normal file
@ -0,0 +1,99 @@
|
||||
create table t1 (a int, b int) engine=MyISAM;
|
||||
create table t2 (c int, d int) engine=MyISAM;
|
||||
insert into t1 values (1,1),(2,2),(3,3),(2,2),(4,4),(4,4),(4,4);
|
||||
insert into t2 values (1,1),(1,1),(1,1),(2,2),(3,3),(3,3),(5,5);
|
||||
|
||||
select * from t1 except select * from t2;
|
||||
select * from t1 except all select * from t2;
|
||||
select * from t1 except all select c+1,d+1 from t2;
|
||||
(select * from t1) except all (select * from t2);
|
||||
select * from ((select * from t1) except all (select * from t2)) a;
|
||||
select * from ((select a from t1) except all (select c from t2)) a;
|
||||
select * from t1 except all select * from t1 union all select * from t1 union all select * from t1 except select * from t2;
|
||||
|
||||
select * from t1 except all select * from t1 union all select * from t1 union all select * from t1 except all select * from t2;
|
||||
|
||||
select * from (select * from t1 except all select * from t2) q1 except all select * from (select * from t1 except all select * from t2) q2;
|
||||
|
||||
EXPLAIN select * from t1 except all select * from t2;
|
||||
EXPLAIN format=json select * from t1 except all select * from t2;
|
||||
EXPLAIN extended (select * from t1) except all (select * from t2);
|
||||
EXPLAIN extended select * from ((select * from t1) except all (select * from t2)) a;
|
||||
|
||||
--source include/analyze-format.inc
|
||||
ANALYZE format=json select * from ((select a,b from t1) except all (select c,d from t2)) a;
|
||||
--source include/analyze-format.inc
|
||||
ANALYZE format=json select * from ((select a from t1) except all (select c from t2)) a;
|
||||
select * from ((select a from t1) except all (select c from t2)) a;
|
||||
|
||||
prepare stmt from "(select a,b from t1) except all (select c,d from t2)";
|
||||
execute stmt;
|
||||
execute stmt;
|
||||
|
||||
prepare stmt from "select * from ((select a,b from t1) except all (select c,d from t2)) a";
|
||||
execute stmt;
|
||||
execute stmt;
|
||||
|
||||
drop tables t1,t2;
|
||||
|
||||
create table t1 (a int, b int) engine=MyISAM;
|
||||
create table t2 (c int, d int) engine=MyISAM;
|
||||
create table t3 (e int, f int) engine=MyISAM;
|
||||
create table t4 (g int, h int) engine=MyISAM;
|
||||
insert into t1 values (1,1),(2,2),(2,2);
|
||||
insert into t2 values (2,2),(3,3);
|
||||
insert into t3 values (4,4),(5,5),(4,4);
|
||||
insert into t4 values (4,4),(7,7),(4,4);
|
||||
|
||||
(select a,b,e,f from t1,t3) except all (select c,d,g,h from t2,t4);
|
||||
select * from ((select a,b,e,f from t1,t3) except all (select c,d,g,h from t2,t4)) t;
|
||||
(select * from t1,t3) except all (select * from t2,t4);
|
||||
(select a,b,e from t1,t3) except all (select c,d,g from t2,t4);
|
||||
|
||||
EXPLAIN (select a,b,e,f from t1,t3) except all (select c,d,g,h from t2,t4);
|
||||
EXPLAIN select * from ((select a,b,e,f from t1,t3) except all (select c,d,g,h from t2,t4)) t;
|
||||
EXPLAIN extended select * from ((select a,b,e,f from t1,t3) except all (select c,d,g,h from t2,t4)) t;
|
||||
EXPLAIN format=json select * from ((select a,b,e,f from t1,t3) except all (select c,d,g,h from t2,t4)) t;
|
||||
|
||||
--source include/analyze-format.inc
|
||||
ANALYZE format=json (select a,b,e,f from t1,t3) except all (select c,d,g,h from t2,t4);
|
||||
--source include/analyze-format.inc
|
||||
ANALYZE format=json select * from ((select a,b,e,f from t1,t3) except all (select c,d,g,h from t2,t4)) t;
|
||||
|
||||
prepare stmt from "(select a,b,e,f from t1,t3) except all (select c,d,g,h from t2,t4)";
|
||||
execute stmt;
|
||||
execute stmt;
|
||||
|
||||
prepare stmt from "select * from ((select a,b,e,f from t1,t3) except all (select c,d,g,h from t2,t4)) a";
|
||||
execute stmt;
|
||||
execute stmt;
|
||||
|
||||
drop tables t1,t2,t3,t4;
|
||||
|
||||
select 1 as a from dual except all select 1 from dual;
|
||||
(select 1 from dual) except all (select 1 from dual);
|
||||
--error ER_PARSE_ERROR
|
||||
(select 1 from dual into @v) except all (select 1 from dual);
|
||||
--error ER_PARSE_ERROR
|
||||
select 1 from dual ORDER BY 1 except all select 1 from dual;
|
||||
select 1 as a from dual union all select 1 from dual;
|
||||
|
||||
create table t1 (a int, b blob, a1 int, b1 blob) engine=MyISAM;
|
||||
create table t2 (c int, d blob, c1 int, d1 blob) engine=MyISAM;
|
||||
insert into t1 values (1,"ddd", 1, "sdfrrwwww"),(2, "fgh", 2, "dffggtt"),(2, "fgh", 2, "dffggtt");
|
||||
insert into t2 values (2, "fgh", 2, "dffggtt"),(3, "ffggddd", 3, "dfgg");
|
||||
|
||||
|
||||
(select a,b,b1 from t1) except all (select c,d,d1 from t2);
|
||||
# make sure that blob is used
|
||||
create table t3 (select a,b,b1 from t1) except all (select c,d,d1 from t2);
|
||||
show create table t3;
|
||||
|
||||
drop tables t1,t2,t3;
|
||||
|
||||
CREATE TABLE t (i INT);
|
||||
INSERT INTO t VALUES (1),(2);
|
||||
|
||||
SELECT * FROM t WHERE i != ANY ( SELECT 3 EXCEPT ALL SELECT 3 );
|
||||
|
||||
drop table t;
|
@ -504,8 +504,6 @@ select 1 as a from dual union all select 1 from dual;
|
||||
a
|
||||
1
|
||||
1
|
||||
select 1 from dual intersect all select 1 from dual;
|
||||
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'all select 1 from dual' at line 1
|
||||
create table t1 (a int, b blob, a1 int, b1 blob);
|
||||
create table t2 (c int, d blob, c1 int, d1 blob);
|
||||
insert into t1 values (1,"ddd", 1, "sdfrrwwww"),(2, "fgh", 2, "dffggtt");
|
||||
@ -607,22 +605,6 @@ NULL INTERSECT RESULT <intersect2,3> ALL NULL NULL NULL NULL NULL NULL
|
||||
NULL UNION RESULT <union1,5,4> ALL NULL NULL NULL NULL NULL NULL
|
||||
Warnings:
|
||||
Note 1003 (/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1`) union /* select#5 */ select `__5`.`c` AS `c`,`__5`.`d` AS `d` from ((/* select#2 */ select `test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2`) intersect (/* select#3 */ select `test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t3`)) `__5` union (/* select#4 */ select 4 AS `4`,4 AS `4`)
|
||||
set SQL_MODE=ORACLE;
|
||||
(select a,b from t1) union (select c,d from t2) intersect (select e,f from t3) union (select 4,4);
|
||||
a b
|
||||
3 3
|
||||
4 4
|
||||
explain extended
|
||||
(select a,b from t1) union (select c,d from t2) intersect (select e,f from t3) union (select 4,4);
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
|
||||
2 UNION t2 ALL NULL NULL NULL NULL 2 100.00
|
||||
3 INTERSECT t3 ALL NULL NULL NULL NULL 2 100.00
|
||||
4 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
||||
NULL UNIT RESULT <unit1,2,3,4> ALL NULL NULL NULL NULL NULL NULL
|
||||
Warnings:
|
||||
Note 1003 (/* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1") union (/* select#2 */ select "test"."t2"."c" AS "c","test"."t2"."d" AS "d" from "test"."t2") intersect (/* select#3 */ select "test"."t3"."e" AS "e","test"."t3"."f" AS "f" from "test"."t3") union (/* select#4 */ select 4 AS "4",4 AS "4")
|
||||
set SQL_MODE=default;
|
||||
(select e,f from t3) intersect (select c,d from t2) union (select a,b from t1) union (select 4,4);
|
||||
e f
|
||||
3 3
|
||||
@ -639,24 +621,6 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
NULL UNIT RESULT <unit1,2,3,4> ALL NULL NULL NULL NULL NULL NULL
|
||||
Warnings:
|
||||
Note 1003 (/* select#1 */ select `test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t3`) intersect (/* select#2 */ select `test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2`) union (/* select#3 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1`) union (/* select#4 */ select 4 AS `4`,4 AS `4`)
|
||||
set SQL_MODE=ORACLE;
|
||||
(select e,f from t3) intersect (select c,d from t2) union (select a,b from t1) union (select 4,4);
|
||||
e f
|
||||
3 3
|
||||
4 4
|
||||
5 5
|
||||
6 6
|
||||
explain extended
|
||||
(select e,f from t3) intersect (select c,d from t2) union (select a,b from t1) union (select 4,4);
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t3 ALL NULL NULL NULL NULL 2 100.00
|
||||
2 INTERSECT t2 ALL NULL NULL NULL NULL 2 100.00
|
||||
3 UNION t1 ALL NULL NULL NULL NULL 2 100.00
|
||||
4 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
||||
NULL UNIT RESULT <unit1,2,3,4> ALL NULL NULL NULL NULL NULL NULL
|
||||
Warnings:
|
||||
Note 1003 (/* select#1 */ select "test"."t3"."e" AS "e","test"."t3"."f" AS "f" from "test"."t3") intersect (/* select#2 */ select "test"."t2"."c" AS "c","test"."t2"."d" AS "d" from "test"."t2") union (/* select#3 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1") union (/* select#4 */ select 4 AS "4",4 AS "4")
|
||||
set SQL_MODE=default;
|
||||
(/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1`) union /* select#3 */ select `__3`.`c` AS `c`,`__3`.`d` AS `d` from ((/* select#2 */ select `test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2`) intersect (/* select#4 */ select `test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t3`)) `__3` union (/* select#5 */ select 4 AS `4`,4 AS `4`);
|
||||
a b
|
||||
3 3
|
||||
@ -820,12 +784,6 @@ create table t234(c1 int);
|
||||
insert into t234 values(2);
|
||||
insert into t234 values(3);
|
||||
insert into t234 values(4);
|
||||
set SQL_MODE=oracle;
|
||||
select * from t13 union select * from t234 intersect select * from t12;
|
||||
c1
|
||||
1
|
||||
2
|
||||
set SQL_MODE=default;
|
||||
select * from t13 union select * from t234 intersect select * from t12;
|
||||
c1
|
||||
1
|
||||
@ -848,9 +806,9 @@ select * from t2 where a < 5
|
||||
intersect
|
||||
select * from t3 where a < 5;
|
||||
a
|
||||
7
|
||||
7
|
||||
1
|
||||
7
|
||||
7
|
||||
explain extended
|
||||
select * from t1 where a > 4
|
||||
union all
|
||||
|
@ -66,7 +66,6 @@ select 1 from dual ORDER BY 1 intersect select 1 from dual;
|
||||
|
||||
select 1 as a from dual union all select 1 from dual;
|
||||
--error ER_PARSE_ERROR
|
||||
select 1 from dual intersect all select 1 from dual;
|
||||
|
||||
|
||||
|
||||
@ -147,12 +146,6 @@ insert into t3 values (1,1),(3,3);
|
||||
(select a,b from t1) union (select c,d from t2) intersect (select e,f from t3) union (select 4,4);
|
||||
explain extended
|
||||
(select a,b from t1) union (select c,d from t2) intersect (select e,f from t3) union (select 4,4);
|
||||
set SQL_MODE=ORACLE;
|
||||
--sorted_result
|
||||
(select a,b from t1) union (select c,d from t2) intersect (select e,f from t3) union (select 4,4);
|
||||
explain extended
|
||||
(select a,b from t1) union (select c,d from t2) intersect (select e,f from t3) union (select 4,4);
|
||||
set SQL_MODE=default;
|
||||
|
||||
|
||||
# test result of linear mix operation
|
||||
@ -160,12 +153,6 @@ set SQL_MODE=default;
|
||||
(select e,f from t3) intersect (select c,d from t2) union (select a,b from t1) union (select 4,4);
|
||||
explain extended
|
||||
(select e,f from t3) intersect (select c,d from t2) union (select a,b from t1) union (select 4,4);
|
||||
set SQL_MODE=ORACLE;
|
||||
--sorted_result
|
||||
(select e,f from t3) intersect (select c,d from t2) union (select a,b from t1) union (select 4,4);
|
||||
explain extended
|
||||
(select e,f from t3) intersect (select c,d from t2) union (select a,b from t1) union (select 4,4);
|
||||
set SQL_MODE=default;
|
||||
|
||||
--sorted_result
|
||||
(/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1`) union /* select#3 */ select `__3`.`c` AS `c`,`__3`.`d` AS `d` from ((/* select#2 */ select `test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2`) intersect (/* select#4 */ select `test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t3`)) `__3` union (/* select#5 */ select 4 AS `4`,4 AS `4`);
|
||||
@ -310,11 +297,7 @@ create table t234(c1 int);
|
||||
insert into t234 values(2);
|
||||
insert into t234 values(3);
|
||||
insert into t234 values(4);
|
||||
|
||||
set SQL_MODE=oracle;
|
||||
--sorted_result
|
||||
select * from t13 union select * from t234 intersect select * from t12;
|
||||
set SQL_MODE=default;
|
||||
|
||||
--sorted_result
|
||||
select * from t13 union select * from t234 intersect select * from t12;
|
||||
|
||||
@ -333,7 +316,7 @@ insert into t2 values (4), (5), (9), (1), (8), (9);
|
||||
create table t3 (a int);
|
||||
insert into t3 values (8), (1), (8), (2), (3), (7), (2);
|
||||
|
||||
|
||||
--sorted_result
|
||||
select * from t1 where a > 4
|
||||
union all
|
||||
select * from t2 where a < 5
|
||||
|
888
mysql-test/main/intersect_all.result
Normal file
888
mysql-test/main/intersect_all.result
Normal file
@ -0,0 +1,888 @@
|
||||
create table t1 (a int, b int) engine=MyISAM;
|
||||
create table t2 (c int, d int) engine=MyISAM;
|
||||
insert into t1 values (1,1),(2,2),(3,3),(2,2);
|
||||
insert into t2 values (2,2),(2,2),(5,5);
|
||||
select * from t1 intersect all select * from t2;
|
||||
a b
|
||||
2 2
|
||||
2 2
|
||||
(select a,b from t1) intersect all (select c,d from t2);
|
||||
a b
|
||||
2 2
|
||||
2 2
|
||||
select * from ((select a,b from t1) intersect all (select c,d from t2)) t;
|
||||
a b
|
||||
2 2
|
||||
2 2
|
||||
select * from ((select a from t1) intersect all (select c from t2)) t;
|
||||
a
|
||||
2
|
||||
2
|
||||
drop tables t1,t2;
|
||||
create table t1 (a int, b int) engine=MyISAM;
|
||||
create table t2 (c int, d int) engine=MyISAM;
|
||||
create table t3 (e int, f int) engine=MyISAM;
|
||||
insert into t1 values (1,1),(2,2),(3,3),(2,2);
|
||||
insert into t2 values (2,2),(3,3),(4,4),(2,2);
|
||||
insert into t3 values (1,1),(2,2),(5,5),(2,2);
|
||||
(select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3);
|
||||
a b
|
||||
2 2
|
||||
2 2
|
||||
EXPLAIN (select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3);
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 PRIMARY t1 ALL NULL NULL NULL NULL 4
|
||||
2 INTERSECT t2 ALL NULL NULL NULL NULL 4
|
||||
3 INTERSECT t3 ALL NULL NULL NULL NULL 4
|
||||
NULL INTERSECT RESULT <intersect1,2,3> ALL NULL NULL NULL NULL NULL
|
||||
EXPLAIN extended (select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3);
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00
|
||||
2 INTERSECT t2 ALL NULL NULL NULL NULL 4 100.00
|
||||
3 INTERSECT t3 ALL NULL NULL NULL NULL 4 100.00
|
||||
NULL INTERSECT RESULT <intersect1,2,3> ALL NULL NULL NULL NULL NULL NULL
|
||||
Warnings:
|
||||
Note 1003 (/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1`) intersect all (/* select#2 */ select `test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2`) intersect all (/* select#3 */ select `test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t3`)
|
||||
EXPLAIN extended select * from ((select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3)) a;
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 4 100.00
|
||||
2 DERIVED t1 ALL NULL NULL NULL NULL 4 100.00
|
||||
3 INTERSECT t2 ALL NULL NULL NULL NULL 4 100.00
|
||||
4 INTERSECT t3 ALL NULL NULL NULL NULL 4 100.00
|
||||
NULL INTERSECT RESULT <intersect2,3,4> ALL NULL NULL NULL NULL NULL NULL
|
||||
Warnings:
|
||||
Note 1003 /* select#1 */ select `a`.`a` AS `a`,`a`.`b` AS `b` from (/* select#2 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` intersect all (/* select#3 */ select `test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2`) intersect all (/* select#4 */ select `test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t3`)) `a`
|
||||
EXPLAIN format=json (select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3);
|
||||
EXPLAIN
|
||||
{
|
||||
"query_block": {
|
||||
"union_result": {
|
||||
"table_name": "<intersect1,2,3>",
|
||||
"access_type": "ALL",
|
||||
"query_specifications": [
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 1,
|
||||
"table": {
|
||||
"table_name": "t1",
|
||||
"access_type": "ALL",
|
||||
"rows": 4,
|
||||
"filtered": 100
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 2,
|
||||
"operation": "INTERSECT",
|
||||
"table": {
|
||||
"table_name": "t2",
|
||||
"access_type": "ALL",
|
||||
"rows": 4,
|
||||
"filtered": 100
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 3,
|
||||
"operation": "INTERSECT",
|
||||
"table": {
|
||||
"table_name": "t3",
|
||||
"access_type": "ALL",
|
||||
"rows": 4,
|
||||
"filtered": 100
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
ANALYZE format=json (select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3);
|
||||
ANALYZE
|
||||
{
|
||||
"query_block": {
|
||||
"union_result": {
|
||||
"table_name": "<intersect1,2,3>",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"r_rows": 2,
|
||||
"query_specifications": [
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 1,
|
||||
"r_loops": 1,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"table": {
|
||||
"table_name": "t1",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 4,
|
||||
"r_rows": 4,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 2,
|
||||
"operation": "INTERSECT",
|
||||
"r_loops": 1,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"table": {
|
||||
"table_name": "t2",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 4,
|
||||
"r_rows": 4,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 3,
|
||||
"operation": "INTERSECT",
|
||||
"r_loops": 1,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"table": {
|
||||
"table_name": "t3",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 4,
|
||||
"r_rows": 4,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
ANALYZE format=json select * from ((select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3)) a;
|
||||
ANALYZE
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 1,
|
||||
"r_loops": 1,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"table": {
|
||||
"table_name": "<derived2>",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 4,
|
||||
"r_rows": 2,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100,
|
||||
"materialized": {
|
||||
"query_block": {
|
||||
"union_result": {
|
||||
"table_name": "<intersect2,3,4>",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"r_rows": 2,
|
||||
"query_specifications": [
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 2,
|
||||
"r_loops": 1,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"table": {
|
||||
"table_name": "t1",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 4,
|
||||
"r_rows": 4,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 3,
|
||||
"operation": "INTERSECT",
|
||||
"r_loops": 1,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"table": {
|
||||
"table_name": "t2",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 4,
|
||||
"r_rows": 4,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 4,
|
||||
"operation": "INTERSECT",
|
||||
"r_loops": 1,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"table": {
|
||||
"table_name": "t3",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 4,
|
||||
"r_rows": 4,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
select * from ((select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3)) a;
|
||||
a b
|
||||
2 2
|
||||
2 2
|
||||
prepare stmt from "(select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3);";
|
||||
execute stmt;
|
||||
a b
|
||||
2 2
|
||||
2 2
|
||||
execute stmt;
|
||||
a b
|
||||
2 2
|
||||
2 2
|
||||
prepare stmt from "select * from ((select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3)) a";
|
||||
execute stmt;
|
||||
a b
|
||||
2 2
|
||||
2 2
|
||||
execute stmt;
|
||||
a b
|
||||
2 2
|
||||
2 2
|
||||
insert into t1 values (2,2),(3,3);
|
||||
insert into t2 values (2,2),(2,2),(2,2);
|
||||
(select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3);
|
||||
a b
|
||||
2 2
|
||||
2 2
|
||||
(select a,b from t1) intersect (select c,d from t2) intersect all (select e,f from t3);
|
||||
a b
|
||||
2 2
|
||||
insert into t3 values (2,2);
|
||||
(select a,b from t1) intersect all (select c,d from t2) intersect (select e,f from t3);
|
||||
a b
|
||||
2 2
|
||||
(select a,b from t1) intersect all (select c,e from t2,t3);
|
||||
a b
|
||||
2 2
|
||||
2 2
|
||||
2 2
|
||||
EXPLAIN (select a,b from t1) intersect all (select c,e from t2,t3);
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 PRIMARY t1 ALL NULL NULL NULL NULL 6
|
||||
2 INTERSECT t3 ALL NULL NULL NULL NULL 5
|
||||
2 INTERSECT t2 ALL NULL NULL NULL NULL 7 Using join buffer (flat, BNL join)
|
||||
NULL INTERSECT RESULT <intersect1,2> ALL NULL NULL NULL NULL NULL
|
||||
EXPLAIN extended (select a,b from t1) intersect all (select c,e from t2,t3);
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00
|
||||
2 INTERSECT t3 ALL NULL NULL NULL NULL 5 100.00
|
||||
2 INTERSECT t2 ALL NULL NULL NULL NULL 7 100.00 Using join buffer (flat, BNL join)
|
||||
NULL INTERSECT RESULT <intersect1,2> ALL NULL NULL NULL NULL NULL NULL
|
||||
Warnings:
|
||||
Note 1003 (/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1`) intersect all (/* select#2 */ select `test`.`t2`.`c` AS `c`,`test`.`t3`.`e` AS `e` from `test`.`t2` join `test`.`t3`)
|
||||
EXPLAIN extended select * from ((select a,b from t1) intersect all (select c,e from t2,t3)) a;
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 6 100.00
|
||||
2 DERIVED t1 ALL NULL NULL NULL NULL 6 100.00
|
||||
3 INTERSECT t3 ALL NULL NULL NULL NULL 5 100.00
|
||||
3 INTERSECT t2 ALL NULL NULL NULL NULL 7 100.00 Using join buffer (flat, BNL join)
|
||||
NULL INTERSECT RESULT <intersect2,3> ALL NULL NULL NULL NULL NULL NULL
|
||||
Warnings:
|
||||
Note 1003 /* select#1 */ select `a`.`a` AS `a`,`a`.`b` AS `b` from (/* select#2 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` intersect all (/* select#3 */ select `test`.`t2`.`c` AS `c`,`test`.`t3`.`e` AS `e` from `test`.`t2` join `test`.`t3`)) `a`
|
||||
EXPLAIN format=json (select a,b from t1) intersect all (select c,e from t2,t3);
|
||||
EXPLAIN
|
||||
{
|
||||
"query_block": {
|
||||
"union_result": {
|
||||
"table_name": "<intersect1,2>",
|
||||
"access_type": "ALL",
|
||||
"query_specifications": [
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 1,
|
||||
"table": {
|
||||
"table_name": "t1",
|
||||
"access_type": "ALL",
|
||||
"rows": 6,
|
||||
"filtered": 100
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 2,
|
||||
"operation": "INTERSECT",
|
||||
"table": {
|
||||
"table_name": "t3",
|
||||
"access_type": "ALL",
|
||||
"rows": 5,
|
||||
"filtered": 100
|
||||
},
|
||||
"block-nl-join": {
|
||||
"table": {
|
||||
"table_name": "t2",
|
||||
"access_type": "ALL",
|
||||
"rows": 7,
|
||||
"filtered": 100
|
||||
},
|
||||
"buffer_type": "flat",
|
||||
"buffer_size": "65",
|
||||
"join_type": "BNL"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
ANALYZE format=json (select a,b from t1) intersect all (select c,e from t2,t3);
|
||||
ANALYZE
|
||||
{
|
||||
"query_block": {
|
||||
"union_result": {
|
||||
"table_name": "<intersect1,2>",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"r_rows": 3,
|
||||
"query_specifications": [
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 1,
|
||||
"r_loops": 1,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"table": {
|
||||
"table_name": "t1",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 6,
|
||||
"r_rows": 6,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 2,
|
||||
"operation": "INTERSECT",
|
||||
"r_loops": 1,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"table": {
|
||||
"table_name": "t3",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 5,
|
||||
"r_rows": 5,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100
|
||||
},
|
||||
"block-nl-join": {
|
||||
"table": {
|
||||
"table_name": "t2",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 7,
|
||||
"r_rows": 7,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100
|
||||
},
|
||||
"buffer_type": "flat",
|
||||
"buffer_size": "65",
|
||||
"join_type": "BNL",
|
||||
"r_filtered": 100
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
ANALYZE format=json select * from ((select a,b from t1) intersect all (select c,e from t2,t3)) a;
|
||||
ANALYZE
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 1,
|
||||
"r_loops": 1,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"table": {
|
||||
"table_name": "<derived2>",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 6,
|
||||
"r_rows": 3,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100,
|
||||
"materialized": {
|
||||
"query_block": {
|
||||
"union_result": {
|
||||
"table_name": "<intersect2,3>",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"r_rows": 3,
|
||||
"query_specifications": [
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 2,
|
||||
"r_loops": 1,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"table": {
|
||||
"table_name": "t1",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 6,
|
||||
"r_rows": 6,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"query_block": {
|
||||
"select_id": 3,
|
||||
"operation": "INTERSECT",
|
||||
"r_loops": 1,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"table": {
|
||||
"table_name": "t3",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 5,
|
||||
"r_rows": 5,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100
|
||||
},
|
||||
"block-nl-join": {
|
||||
"table": {
|
||||
"table_name": "t2",
|
||||
"access_type": "ALL",
|
||||
"r_loops": 1,
|
||||
"rows": 7,
|
||||
"r_rows": 7,
|
||||
"r_total_time_ms": "REPLACED",
|
||||
"filtered": 100,
|
||||
"r_filtered": 100
|
||||
},
|
||||
"buffer_type": "flat",
|
||||
"buffer_size": "65",
|
||||
"join_type": "BNL",
|
||||
"r_filtered": 100
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
select * from ((select a,b from t1) intersect all (select c,e from t2,t3)) a;
|
||||
a b
|
||||
2 2
|
||||
2 2
|
||||
2 2
|
||||
prepare stmt from "(select a,b from t1) intersect all (select c,e from t2,t3);";
|
||||
execute stmt;
|
||||
a b
|
||||
2 2
|
||||
2 2
|
||||
2 2
|
||||
execute stmt;
|
||||
a b
|
||||
2 2
|
||||
2 2
|
||||
2 2
|
||||
prepare stmt from "select * from ((select a,b from t1) intersect all (select c,e from t2,t3)) a";
|
||||
execute stmt;
|
||||
a b
|
||||
2 2
|
||||
2 2
|
||||
2 2
|
||||
execute stmt;
|
||||
a b
|
||||
2 2
|
||||
2 2
|
||||
2 2
|
||||
drop tables t1,t2,t3;
|
||||
select 1 as a from dual intersect all select 1 from dual;
|
||||
a
|
||||
1
|
||||
(select 1 from dual) intersect all (select 1 from dual);
|
||||
1
|
||||
1
|
||||
(select 1 from dual into @v) intersect all (select 1 from dual);
|
||||
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'into @v) intersect all (select 1 from dual)' at line 1
|
||||
select 1 from dual ORDER BY 1 intersect all select 1 from dual;
|
||||
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'intersect all select 1 from dual' at line 1
|
||||
select 1 as a from dual union all select 1 from dual;
|
||||
a
|
||||
1
|
||||
1
|
||||
create table t1 (a int, b blob, a1 int, b1 blob);
|
||||
create table t2 (c int, d blob, c1 int, d1 blob);
|
||||
insert into t1 values (1,"ddd", 1, "sdfrrwwww"),(2, "fgh", 2, "dffggtt"),(2, "fgh", 2, "dffggtt");
|
||||
insert into t2 values (2, "fgh", 2, "dffggtt"),(3, "ffggddd", 3, "dfgg"),(2, "fgh", 2, "dffggtt");
|
||||
(select a,b,b1 from t1) intersect all (select c,d,d1 from t2);
|
||||
a b b1
|
||||
2 fgh dffggtt
|
||||
2 fgh dffggtt
|
||||
drop tables t1,t2;
|
||||
create table t1 (a int, b blob) engine=MyISAM;
|
||||
create table t2 (c int, d blob) engine=MyISAM;
|
||||
create table t3 (e int, f blob) engine=MyISAM;
|
||||
insert into t1 values (1,1),(2,2),(3,3),(2,2),(3,3);
|
||||
insert into t2 values (2,2),(3,3),(4,4),(2,2),(2,2),(2,2);
|
||||
insert into t3 values (1,1),(2,2),(5,5),(2,2),(5,5);
|
||||
(select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3);
|
||||
a b
|
||||
2 2
|
||||
2 2
|
||||
select * from ((select a,b from t1) intersect all (select c,d from t2) intersect (select e,f from t3)) a;
|
||||
a b
|
||||
2 2
|
||||
prepare stmt from "(select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3);";
|
||||
execute stmt;
|
||||
a b
|
||||
2 2
|
||||
2 2
|
||||
execute stmt;
|
||||
a b
|
||||
2 2
|
||||
2 2
|
||||
prepare stmt from "select * from ((select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3)) a";
|
||||
execute stmt;
|
||||
a b
|
||||
2 2
|
||||
2 2
|
||||
execute stmt;
|
||||
a b
|
||||
2 2
|
||||
2 2
|
||||
create table t4 (select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3);
|
||||
show create table t4;
|
||||
Table Create Table
|
||||
t4 CREATE TABLE `t4` (
|
||||
`a` int(11) DEFAULT NULL,
|
||||
`b` blob DEFAULT NULL
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1
|
||||
drop tables t4;
|
||||
(select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3) union all (select 4,4);
|
||||
a b
|
||||
4 4
|
||||
2 2
|
||||
2 2
|
||||
(select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3) union all (select 4,4) except all (select 2,2);
|
||||
a b
|
||||
4 4
|
||||
2 2
|
||||
drop tables t1,t2,t3;
|
||||
create table t1 (a int, b int);
|
||||
create table t2 (c int, d int);
|
||||
create table t3 (e int, f int);
|
||||
insert into t1 values (1,1),(2,2),(3,3),(2,2),(3,3);
|
||||
insert into t2 values (2,2),(3,3),(4,4),(2,2),(2,2),(2,2);
|
||||
insert into t3 values (1,1),(2,2),(5,5),(2,2),(5,5);
|
||||
(select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3) union all (select 4,4);
|
||||
a b
|
||||
4 4
|
||||
2 2
|
||||
2 2
|
||||
(select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3) union all (select 4,4) except all (select 2,2);
|
||||
a b
|
||||
4 4
|
||||
2 2
|
||||
drop tables t1,t2,t3;
|
||||
#
|
||||
# INTERSECT precedence
|
||||
#
|
||||
create table t1 (a int, b blob) engine=MyISAM;
|
||||
create table t2 (c int, d blob) engine=MyISAM;
|
||||
create table t3 (e int, f blob) engine=MyISAM;
|
||||
insert into t1 values (5,5),(6,6);
|
||||
insert into t2 values (2,2),(3,3);
|
||||
insert into t3 values (1,1),(3,3);
|
||||
(select a,b from t1) union all (select c,d from t2) intersect (select e,f from t3) union all (select 4,4);
|
||||
a b
|
||||
5 5
|
||||
6 6
|
||||
3 3
|
||||
4 4
|
||||
(select a,b from t1) union all (select c,d from t2) intersect all (select e,f from t3) union all (select 4,4);
|
||||
a b
|
||||
5 5
|
||||
6 6
|
||||
3 3
|
||||
4 4
|
||||
explain extended (select a,b from t1) union all (select c,d from t2) intersect all (select e,f from t3) union all (select 4,4);
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
|
||||
5 UNION <derived2> ALL NULL NULL NULL NULL 2 100.00
|
||||
2 DERIVED t2 ALL NULL NULL NULL NULL 2 100.00
|
||||
3 INTERSECT t3 ALL NULL NULL NULL NULL 2 100.00
|
||||
NULL INTERSECT RESULT <intersect2,3> ALL NULL NULL NULL NULL NULL NULL
|
||||
4 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
||||
Warnings:
|
||||
Note 1003 (/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1`) union all /* select#5 */ select `__5`.`c` AS `c`,`__5`.`d` AS `d` from ((/* select#2 */ select `test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2`) intersect all (/* select#3 */ select `test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t3`)) `__5` union all (/* select#4 */ select 4 AS `4`,4 AS `4`)
|
||||
insert into t2 values (3,3);
|
||||
insert into t3 values (3,3);
|
||||
(select e,f from t3) intersect all (select c,d from t2) union all (select a,b from t1) union all (select 4,4);
|
||||
e f
|
||||
3 3
|
||||
3 3
|
||||
5 5
|
||||
6 6
|
||||
4 4
|
||||
explain extended (select e,f from t3) intersect all (select c,d from t2) union all (select a,b from t1) union all (select 4,4);
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t3 ALL NULL NULL NULL NULL 3 100.00
|
||||
2 INTERSECT t2 ALL NULL NULL NULL NULL 3 100.00
|
||||
3 UNION t1 ALL NULL NULL NULL NULL 2 100.00
|
||||
4 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
||||
NULL UNIT RESULT <unit1,2,3,4> ALL NULL NULL NULL NULL NULL NULL
|
||||
Warnings:
|
||||
Note 1003 (/* select#1 */ select `test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t3`) intersect all (/* select#2 */ select `test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2`) union all (/* select#3 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1`) union all (/* select#4 */ select 4 AS `4`,4 AS `4`)
|
||||
(/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1`) union /* select#3 */ select `__3`.`c` AS `c`,`__3`.`d` AS `d` from ((/* select#2 */ select `test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2`) intersect all (/* select#4 */ select `test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t3`)) `__3` union (/* select#5 */ select 4 AS `4`,4 AS `4`);
|
||||
a b
|
||||
5 5
|
||||
6 6
|
||||
3 3
|
||||
4 4
|
||||
prepare stmt from "(select a,b from t1) union all (select c,d from t2) intersect all (select e,f from t3) union all (select 4,4)";
|
||||
execute stmt;
|
||||
a b
|
||||
5 5
|
||||
6 6
|
||||
3 3
|
||||
3 3
|
||||
4 4
|
||||
execute stmt;
|
||||
a b
|
||||
5 5
|
||||
6 6
|
||||
3 3
|
||||
3 3
|
||||
4 4
|
||||
create view v1 as (select a,b from t1) union all (select c,d from t2) intersect all (select e,f from t3) union all (select 4,4);
|
||||
select b,a,b+1 from v1;
|
||||
b a b+1
|
||||
5 5 6
|
||||
6 6 7
|
||||
3 3 4
|
||||
3 3 4
|
||||
4 4 5
|
||||
select b,a,b+1 from v1 where a > 3;
|
||||
b a b+1
|
||||
5 5 6
|
||||
6 6 7
|
||||
4 4 5
|
||||
create procedure p1()
|
||||
select * from v1;
|
||||
call p1();
|
||||
a b
|
||||
5 5
|
||||
6 6
|
||||
3 3
|
||||
3 3
|
||||
4 4
|
||||
call p1();
|
||||
a b
|
||||
5 5
|
||||
6 6
|
||||
3 3
|
||||
3 3
|
||||
4 4
|
||||
drop procedure p1;
|
||||
create procedure p1()
|
||||
(select a,b from t1) union all (select c,d from t2) intersect all (select e,f from t3) union all (select 4,4);
|
||||
call p1();
|
||||
a b
|
||||
5 5
|
||||
6 6
|
||||
3 3
|
||||
3 3
|
||||
4 4
|
||||
call p1();
|
||||
a b
|
||||
5 5
|
||||
6 6
|
||||
3 3
|
||||
3 3
|
||||
4 4
|
||||
drop procedure p1;
|
||||
show create view v1;
|
||||
View Create View character_set_client collation_connection
|
||||
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS (select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1`) union all select `__6`.`c` AS `c`,`__6`.`d` AS `d` from (select `test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2` intersect all (select `test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t3`)) `__6` union all (select 4 AS `4`,4 AS `4`) latin1 latin1_swedish_ci
|
||||
drop view v1;
|
||||
drop tables t1,t2,t3;
|
||||
CREATE TABLE t (i INT);
|
||||
INSERT INTO t VALUES (1),(2);
|
||||
SELECT * FROM t WHERE i != ANY ( SELECT 6 INTERSECT ALL SELECT 3 );
|
||||
i
|
||||
select i from t where
|
||||
exists ((select 6 as r from dual having t.i <> 6)
|
||||
intersect all
|
||||
(select 3 from dual having t.i <> 3));
|
||||
i
|
||||
drop table t;
|
||||
CREATE TABLE t1 (a varchar(32)) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES
|
||||
('Jakarta'),('Lisbon'),('Honolulu'),('Lusaka'),('Barcelona'),('Taipei'),
|
||||
('Brussels'),('Orlando'),('Osaka'),('Quito'),('Lima'),('Tunis'),
|
||||
('Unalaska'),('Rotterdam'),('Zagreb'),('Ufa'),('Ryazan'),('Xiamen'),
|
||||
('London'),('Izmir'),('Samara'),('Bern'),('Zhengzhou'),('Vladivostok'),
|
||||
('Yangon'),('Victoria'),('Warsaw'),('Luanda'),('Leon'),('Bangkok'),
|
||||
('Wellington'),('Zibo'),('Qiqihar'),('Delhi'),('Hamburg'),('Ottawa'),
|
||||
('Vaduz');
|
||||
CREATE TABLE t2 (b varchar(32)) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES
|
||||
('Gaza'),('Jeddah'),('Beirut'),('Incheon'),('Tbilisi'),('Izmir'),
|
||||
('Quito'),('Riga'),('Freetown'),('Zagreb'),('Caracas'),('Orlando'),
|
||||
('Kingston'),('Turin'),('Xinyang'),('Osaka'),('Albany'),('Geneva'),
|
||||
('Omsk'),('Kazan'),('Quezon'),('Indore'),('Odessa'),('Xiamen'),
|
||||
('Winnipeg'),('Yakutsk'),('Nairobi'),('Ufa'),('Helsinki'),('Vilnius'),
|
||||
('Aden'),('Liverpool'),('Honolulu'),('Frankfurt'),('Glasgow'),
|
||||
('Vienna'),('Jackson'),('Jakarta'),('Sydney'),('Oslo'),('Novgorod'),
|
||||
('Norilsk'),('Izhevsk'),('Istanbul'),('Nice');
|
||||
CREATE TABLE t3 (c varchar(32)) ENGINE=MyISAM;
|
||||
INSERT INTO t3 VALUES
|
||||
('Nicosia'),('Istanbul'),('Richmond'),('Stockholm'),('Dublin'),
|
||||
('Wichita'),('Warsaw'),('Glasgow'),('Winnipeg'),('Irkutsk'),('Quito'),
|
||||
('Xiamen'),('Berlin'),('Rome'),('Denver'),('Dallas'),('Kabul'),
|
||||
('Prague'),('Izhevsk'),('Tirana'),('Sofia'),('Detroit'),('Sorbonne');
|
||||
select count(*) from (
|
||||
SELECT * FROM t1 LEFT OUTER JOIN t2 LEFT OUTER JOIN t3 ON b < c ON a > b
|
||||
INTERSECT
|
||||
SELECT * FROM t1 LEFT OUTER JOIN t2 LEFT OUTER JOIN t3 ON b < c ON a > b
|
||||
) a;
|
||||
count(*)
|
||||
14848
|
||||
select count(*) from (
|
||||
SELECT * FROM t1 LEFT OUTER JOIN t2 LEFT OUTER JOIN t3 ON b < c ON a > b
|
||||
INTERSECT ALL
|
||||
SELECT * FROM t1 LEFT OUTER JOIN t2 LEFT OUTER JOIN t3 ON b < c ON a > b
|
||||
) a;
|
||||
count(*)
|
||||
14848
|
||||
insert into t1 values ('Xiamen');
|
||||
insert into t2 values ('Xiamen'),('Xiamen');
|
||||
insert into t3 values ('Xiamen');
|
||||
select count(*) from (
|
||||
SELECT * FROM t1 LEFT OUTER JOIN t2 LEFT OUTER JOIN t3 ON b < c ON a > b
|
||||
INTERSECT ALL
|
||||
SELECT * FROM t1 LEFT OUTER JOIN t2 LEFT OUTER JOIN t3 ON b < c ON a > b
|
||||
) a;
|
||||
count(*)
|
||||
16430
|
||||
drop table t1,t2,t3;
|
||||
CREATE TABLE t1 (a varchar(32) not null) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES
|
||||
('Jakarta'),('Lisbon'),('Honolulu'),('Lusaka'),('Barcelona'),('Taipei'),
|
||||
('Brussels'),('Orlando'),('Osaka'),('Quito'),('Lima'),('Tunis'),
|
||||
('Unalaska'),('Rotterdam'),('Zagreb'),('Ufa'),('Ryazan'),('Xiamen'),
|
||||
('London'),('Izmir'),('Samara'),('Bern'),('Zhengzhou'),('Vladivostok'),
|
||||
('Yangon'),('Victoria'),('Warsaw'),('Luanda'),('Leon'),('Bangkok'),
|
||||
('Wellington'),('Zibo'),('Qiqihar'),('Delhi'),('Hamburg'),('Ottawa'),
|
||||
('Vaduz'),('Detroit'),('Detroit');
|
||||
CREATE TABLE t2 (b varchar(32) not null) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES
|
||||
('Gaza'),('Jeddah'),('Beirut'),('Incheon'),('Tbilisi'),('Izmir'),
|
||||
('Quito'),('Riga'),('Freetown'),('Zagreb'),('Caracas'),('Orlando'),
|
||||
('Kingston'),('Turin'),('Xinyang'),('Osaka'),('Albany'),('Geneva'),
|
||||
('Omsk'),('Kazan'),('Quezon'),('Indore'),('Odessa'),('Xiamen'),
|
||||
('Winnipeg'),('Yakutsk'),('Nairobi'),('Ufa'),('Helsinki'),('Vilnius'),
|
||||
('Aden'),('Liverpool'),('Honolulu'),('Frankfurt'),('Glasgow'),
|
||||
('Vienna'),('Jackson'),('Jakarta'),('Sydney'),('Oslo'),('Novgorod'),
|
||||
('Norilsk'),('Izhevsk'),('Istanbul'),('Nice'),('Detroit'),('Detroit');
|
||||
CREATE TABLE t3 (c varchar(32) not null) ENGINE=MyISAM;
|
||||
INSERT INTO t3 VALUES
|
||||
('Nicosia'),('Istanbul'),('Richmond'),('Stockholm'),('Dublin'),
|
||||
('Wichita'),('Warsaw'),('Glasgow'),('Winnipeg'),('Irkutsk'),('Quito'),
|
||||
('Xiamen'),('Berlin'),('Rome'),('Denver'),('Dallas'),('Kabul'),
|
||||
('Prague'),('Izhevsk'),('Tirana'),('Sofia'),('Detroit'),('Sorbonne'),
|
||||
('Detroit');
|
||||
select count(*) from (
|
||||
SELECT * FROM t1 LEFT OUTER JOIN t2 LEFT OUTER JOIN t3 ON b < c ON a > b
|
||||
INTERSECT
|
||||
SELECT * FROM t1 LEFT OUTER JOIN t2 LEFT OUTER JOIN t3 ON b < c ON a > b
|
||||
) a;
|
||||
count(*)
|
||||
15547
|
||||
drop table t1,t2,t3;
|
||||
create table t12(c1 int);
|
||||
insert into t12 values(1);
|
||||
insert into t12 values(2);
|
||||
create table t13(c1 int);
|
||||
insert into t13 values(1);
|
||||
insert into t13 values(3);
|
||||
create table t234(c1 int);
|
||||
insert into t234 values(2);
|
||||
insert into t234 values(3);
|
||||
insert into t234 values(4);
|
||||
select * from t13 union select * from t234 intersect all select * from t12;
|
||||
c1
|
||||
1
|
||||
3
|
||||
2
|
||||
drop table t12,t13,t234;
|
||||
create table t1 (a int);
|
||||
insert into t1 values (3), (1), (7), (3), (2), (7), (4);
|
||||
create table t2 (a int);
|
||||
insert into t2 values (4), (5), (9), (1), (8), (9), (2), (2);
|
||||
create table t3 (a int);
|
||||
insert into t3 values (8), (1), (8), (2), (3), (7), (2);
|
||||
select * from t1 where a > 4
|
||||
union all
|
||||
select * from t2 where a < 5
|
||||
intersect all
|
||||
select * from t3 where a < 5;
|
||||
a
|
||||
7
|
||||
7
|
||||
2
|
||||
1
|
||||
2
|
||||
explain extended
|
||||
select * from t1 where a > 4
|
||||
union all
|
||||
select * from t2 where a < 5
|
||||
intersect all
|
||||
select * from t3 where a < 5;
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t1 ALL NULL NULL NULL NULL 7 100.00 Using where
|
||||
4 UNION <derived2> ALL NULL NULL NULL NULL 7 100.00
|
||||
2 DERIVED t2 ALL NULL NULL NULL NULL 8 100.00 Using where
|
||||
3 INTERSECT t3 ALL NULL NULL NULL NULL 7 100.00 Using where
|
||||
NULL INTERSECT RESULT <intersect2,3> ALL NULL NULL NULL NULL NULL NULL
|
||||
Warnings:
|
||||
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` > 4 union all /* select#4 */ select `__4`.`a` AS `a` from (/* select#2 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where `test`.`t2`.`a` < 5 intersect all /* select#3 */ select `test`.`t3`.`a` AS `a` from `test`.`t3` where `test`.`t3`.`a` < 5) `__4`
|
||||
drop table t1,t2,t3;
|
328
mysql-test/main/intersect_all.test
Normal file
328
mysql-test/main/intersect_all.test
Normal file
@ -0,0 +1,328 @@
|
||||
create table t1 (a int, b int) engine=MyISAM;
|
||||
create table t2 (c int, d int) engine=MyISAM;
|
||||
insert into t1 values (1,1),(2,2),(3,3),(2,2);
|
||||
insert into t2 values (2,2),(2,2),(5,5);
|
||||
|
||||
select * from t1 intersect all select * from t2;
|
||||
(select a,b from t1) intersect all (select c,d from t2);
|
||||
select * from ((select a,b from t1) intersect all (select c,d from t2)) t;
|
||||
select * from ((select a from t1) intersect all (select c from t2)) t;
|
||||
|
||||
drop tables t1,t2;
|
||||
|
||||
create table t1 (a int, b int) engine=MyISAM;
|
||||
create table t2 (c int, d int) engine=MyISAM;
|
||||
create table t3 (e int, f int) engine=MyISAM;
|
||||
insert into t1 values (1,1),(2,2),(3,3),(2,2);
|
||||
insert into t2 values (2,2),(3,3),(4,4),(2,2);
|
||||
insert into t3 values (1,1),(2,2),(5,5),(2,2);
|
||||
|
||||
(select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3);
|
||||
|
||||
EXPLAIN (select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3);
|
||||
EXPLAIN extended (select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3);
|
||||
EXPLAIN extended select * from ((select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3)) a;
|
||||
EXPLAIN format=json (select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3);
|
||||
--source include/analyze-format.inc
|
||||
ANALYZE format=json (select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3);
|
||||
--source include/analyze-format.inc
|
||||
ANALYZE format=json select * from ((select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3)) a;
|
||||
select * from ((select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3)) a;
|
||||
|
||||
prepare stmt from "(select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3);";
|
||||
execute stmt;
|
||||
execute stmt;
|
||||
|
||||
prepare stmt from "select * from ((select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3)) a";
|
||||
execute stmt;
|
||||
execute stmt;
|
||||
|
||||
insert into t1 values (2,2),(3,3);
|
||||
insert into t2 values (2,2),(2,2),(2,2);
|
||||
(select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3);
|
||||
(select a,b from t1) intersect (select c,d from t2) intersect all (select e,f from t3);
|
||||
|
||||
insert into t3 values (2,2);
|
||||
(select a,b from t1) intersect all (select c,d from t2) intersect (select e,f from t3);
|
||||
|
||||
(select a,b from t1) intersect all (select c,e from t2,t3);
|
||||
|
||||
EXPLAIN (select a,b from t1) intersect all (select c,e from t2,t3);
|
||||
EXPLAIN extended (select a,b from t1) intersect all (select c,e from t2,t3);
|
||||
EXPLAIN extended select * from ((select a,b from t1) intersect all (select c,e from t2,t3)) a;
|
||||
EXPLAIN format=json (select a,b from t1) intersect all (select c,e from t2,t3);
|
||||
--source include/analyze-format.inc
|
||||
ANALYZE format=json (select a,b from t1) intersect all (select c,e from t2,t3);
|
||||
--source include/analyze-format.inc
|
||||
ANALYZE format=json select * from ((select a,b from t1) intersect all (select c,e from t2,t3)) a;
|
||||
select * from ((select a,b from t1) intersect all (select c,e from t2,t3)) a;
|
||||
|
||||
prepare stmt from "(select a,b from t1) intersect all (select c,e from t2,t3);";
|
||||
execute stmt;
|
||||
execute stmt;
|
||||
|
||||
prepare stmt from "select * from ((select a,b from t1) intersect all (select c,e from t2,t3)) a";
|
||||
execute stmt;
|
||||
execute stmt;
|
||||
|
||||
drop tables t1,t2,t3;
|
||||
|
||||
select 1 as a from dual intersect all select 1 from dual;
|
||||
(select 1 from dual) intersect all (select 1 from dual);
|
||||
--error ER_PARSE_ERROR
|
||||
(select 1 from dual into @v) intersect all (select 1 from dual);
|
||||
--error ER_PARSE_ERROR
|
||||
select 1 from dual ORDER BY 1 intersect all select 1 from dual;
|
||||
select 1 as a from dual union all select 1 from dual;
|
||||
|
||||
create table t1 (a int, b blob, a1 int, b1 blob);
|
||||
create table t2 (c int, d blob, c1 int, d1 blob);
|
||||
insert into t1 values (1,"ddd", 1, "sdfrrwwww"),(2, "fgh", 2, "dffggtt"),(2, "fgh", 2, "dffggtt");
|
||||
insert into t2 values (2, "fgh", 2, "dffggtt"),(3, "ffggddd", 3, "dfgg"),(2, "fgh", 2, "dffggtt");
|
||||
|
||||
(select a,b,b1 from t1) intersect all (select c,d,d1 from t2);
|
||||
|
||||
drop tables t1,t2;
|
||||
|
||||
create table t1 (a int, b blob) engine=MyISAM;
|
||||
create table t2 (c int, d blob) engine=MyISAM;
|
||||
create table t3 (e int, f blob) engine=MyISAM;
|
||||
insert into t1 values (1,1),(2,2),(3,3),(2,2),(3,3);
|
||||
insert into t2 values (2,2),(3,3),(4,4),(2,2),(2,2),(2,2);
|
||||
insert into t3 values (1,1),(2,2),(5,5),(2,2),(5,5);
|
||||
|
||||
(select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3);
|
||||
select * from ((select a,b from t1) intersect all (select c,d from t2) intersect (select e,f from t3)) a;
|
||||
|
||||
prepare stmt from "(select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3);";
|
||||
execute stmt;
|
||||
execute stmt;
|
||||
|
||||
prepare stmt from "select * from ((select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3)) a";
|
||||
execute stmt;
|
||||
execute stmt;
|
||||
|
||||
# make sure that blob is used
|
||||
create table t4 (select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3);
|
||||
show create table t4;
|
||||
drop tables t4;
|
||||
|
||||
|
||||
(select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3) union all (select 4,4);
|
||||
|
||||
(select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3) union all (select 4,4) except all (select 2,2);
|
||||
|
||||
drop tables t1,t2,t3;
|
||||
|
||||
create table t1 (a int, b int);
|
||||
create table t2 (c int, d int);
|
||||
create table t3 (e int, f int);
|
||||
insert into t1 values (1,1),(2,2),(3,3),(2,2),(3,3);
|
||||
insert into t2 values (2,2),(3,3),(4,4),(2,2),(2,2),(2,2);
|
||||
insert into t3 values (1,1),(2,2),(5,5),(2,2),(5,5);
|
||||
|
||||
|
||||
(select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3) union all (select 4,4);
|
||||
|
||||
(select a,b from t1) intersect all (select c,d from t2) intersect all (select e,f from t3) union all (select 4,4) except all (select 2,2);
|
||||
|
||||
drop tables t1,t2,t3;
|
||||
|
||||
--echo #
|
||||
--echo # INTERSECT precedence
|
||||
--echo #
|
||||
create table t1 (a int, b blob) engine=MyISAM;
|
||||
create table t2 (c int, d blob) engine=MyISAM;
|
||||
create table t3 (e int, f blob) engine=MyISAM;
|
||||
insert into t1 values (5,5),(6,6);
|
||||
insert into t2 values (2,2),(3,3);
|
||||
insert into t3 values (1,1),(3,3);
|
||||
|
||||
|
||||
|
||||
(select a,b from t1) union all (select c,d from t2) intersect (select e,f from t3) union all (select 4,4);
|
||||
|
||||
(select a,b from t1) union all (select c,d from t2) intersect all (select e,f from t3) union all (select 4,4);
|
||||
explain extended (select a,b from t1) union all (select c,d from t2) intersect all (select e,f from t3) union all (select 4,4);
|
||||
|
||||
# test result of linear mix operation
|
||||
insert into t2 values (3,3);
|
||||
insert into t3 values (3,3);
|
||||
|
||||
(select e,f from t3) intersect all (select c,d from t2) union all (select a,b from t1) union all (select 4,4);
|
||||
explain extended (select e,f from t3) intersect all (select c,d from t2) union all (select a,b from t1) union all (select 4,4);
|
||||
|
||||
|
||||
(/* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1`) union /* select#3 */ select `__3`.`c` AS `c`,`__3`.`d` AS `d` from ((/* select#2 */ select `test`.`t2`.`c` AS `c`,`test`.`t2`.`d` AS `d` from `test`.`t2`) intersect all (/* select#4 */ select `test`.`t3`.`e` AS `e`,`test`.`t3`.`f` AS `f` from `test`.`t3`)) `__3` union (/* select#5 */ select 4 AS `4`,4 AS `4`);
|
||||
|
||||
prepare stmt from "(select a,b from t1) union all (select c,d from t2) intersect all (select e,f from t3) union all (select 4,4)";
|
||||
|
||||
execute stmt;
|
||||
|
||||
execute stmt;
|
||||
|
||||
create view v1 as (select a,b from t1) union all (select c,d from t2) intersect all (select e,f from t3) union all (select 4,4);
|
||||
|
||||
|
||||
select b,a,b+1 from v1;
|
||||
|
||||
select b,a,b+1 from v1 where a > 3;
|
||||
|
||||
create procedure p1()
|
||||
select * from v1;
|
||||
|
||||
call p1();
|
||||
|
||||
call p1();
|
||||
drop procedure p1;
|
||||
|
||||
create procedure p1()
|
||||
(select a,b from t1) union all (select c,d from t2) intersect all (select e,f from t3) union all (select 4,4);
|
||||
|
||||
call p1();
|
||||
|
||||
call p1();
|
||||
drop procedure p1;
|
||||
|
||||
show create view v1;
|
||||
|
||||
drop view v1;
|
||||
drop tables t1,t2,t3;
|
||||
|
||||
CREATE TABLE t (i INT);
|
||||
INSERT INTO t VALUES (1),(2);
|
||||
SELECT * FROM t WHERE i != ANY ( SELECT 6 INTERSECT ALL SELECT 3 );
|
||||
|
||||
select i from t where
|
||||
exists ((select 6 as r from dual having t.i <> 6)
|
||||
intersect all
|
||||
(select 3 from dual having t.i <> 3));
|
||||
|
||||
drop table t;
|
||||
|
||||
CREATE TABLE t1 (a varchar(32)) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES
|
||||
('Jakarta'),('Lisbon'),('Honolulu'),('Lusaka'),('Barcelona'),('Taipei'),
|
||||
('Brussels'),('Orlando'),('Osaka'),('Quito'),('Lima'),('Tunis'),
|
||||
('Unalaska'),('Rotterdam'),('Zagreb'),('Ufa'),('Ryazan'),('Xiamen'),
|
||||
('London'),('Izmir'),('Samara'),('Bern'),('Zhengzhou'),('Vladivostok'),
|
||||
('Yangon'),('Victoria'),('Warsaw'),('Luanda'),('Leon'),('Bangkok'),
|
||||
('Wellington'),('Zibo'),('Qiqihar'),('Delhi'),('Hamburg'),('Ottawa'),
|
||||
('Vaduz');
|
||||
|
||||
CREATE TABLE t2 (b varchar(32)) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES
|
||||
('Gaza'),('Jeddah'),('Beirut'),('Incheon'),('Tbilisi'),('Izmir'),
|
||||
('Quito'),('Riga'),('Freetown'),('Zagreb'),('Caracas'),('Orlando'),
|
||||
('Kingston'),('Turin'),('Xinyang'),('Osaka'),('Albany'),('Geneva'),
|
||||
('Omsk'),('Kazan'),('Quezon'),('Indore'),('Odessa'),('Xiamen'),
|
||||
('Winnipeg'),('Yakutsk'),('Nairobi'),('Ufa'),('Helsinki'),('Vilnius'),
|
||||
('Aden'),('Liverpool'),('Honolulu'),('Frankfurt'),('Glasgow'),
|
||||
('Vienna'),('Jackson'),('Jakarta'),('Sydney'),('Oslo'),('Novgorod'),
|
||||
('Norilsk'),('Izhevsk'),('Istanbul'),('Nice');
|
||||
|
||||
CREATE TABLE t3 (c varchar(32)) ENGINE=MyISAM;
|
||||
INSERT INTO t3 VALUES
|
||||
('Nicosia'),('Istanbul'),('Richmond'),('Stockholm'),('Dublin'),
|
||||
('Wichita'),('Warsaw'),('Glasgow'),('Winnipeg'),('Irkutsk'),('Quito'),
|
||||
('Xiamen'),('Berlin'),('Rome'),('Denver'),('Dallas'),('Kabul'),
|
||||
('Prague'),('Izhevsk'),('Tirana'),('Sofia'),('Detroit'),('Sorbonne');
|
||||
|
||||
select count(*) from (
|
||||
SELECT * FROM t1 LEFT OUTER JOIN t2 LEFT OUTER JOIN t3 ON b < c ON a > b
|
||||
INTERSECT
|
||||
SELECT * FROM t1 LEFT OUTER JOIN t2 LEFT OUTER JOIN t3 ON b < c ON a > b
|
||||
) a;
|
||||
|
||||
select count(*) from (
|
||||
SELECT * FROM t1 LEFT OUTER JOIN t2 LEFT OUTER JOIN t3 ON b < c ON a > b
|
||||
INTERSECT ALL
|
||||
SELECT * FROM t1 LEFT OUTER JOIN t2 LEFT OUTER JOIN t3 ON b < c ON a > b
|
||||
) a;
|
||||
|
||||
insert into t1 values ('Xiamen');
|
||||
insert into t2 values ('Xiamen'),('Xiamen');
|
||||
insert into t3 values ('Xiamen');
|
||||
select count(*) from (
|
||||
SELECT * FROM t1 LEFT OUTER JOIN t2 LEFT OUTER JOIN t3 ON b < c ON a > b
|
||||
INTERSECT ALL
|
||||
SELECT * FROM t1 LEFT OUTER JOIN t2 LEFT OUTER JOIN t3 ON b < c ON a > b
|
||||
) a;
|
||||
|
||||
drop table t1,t2,t3;
|
||||
|
||||
CREATE TABLE t1 (a varchar(32) not null) ENGINE=MyISAM;
|
||||
INSERT INTO t1 VALUES
|
||||
('Jakarta'),('Lisbon'),('Honolulu'),('Lusaka'),('Barcelona'),('Taipei'),
|
||||
('Brussels'),('Orlando'),('Osaka'),('Quito'),('Lima'),('Tunis'),
|
||||
('Unalaska'),('Rotterdam'),('Zagreb'),('Ufa'),('Ryazan'),('Xiamen'),
|
||||
('London'),('Izmir'),('Samara'),('Bern'),('Zhengzhou'),('Vladivostok'),
|
||||
('Yangon'),('Victoria'),('Warsaw'),('Luanda'),('Leon'),('Bangkok'),
|
||||
('Wellington'),('Zibo'),('Qiqihar'),('Delhi'),('Hamburg'),('Ottawa'),
|
||||
('Vaduz'),('Detroit'),('Detroit');
|
||||
|
||||
CREATE TABLE t2 (b varchar(32) not null) ENGINE=MyISAM;
|
||||
INSERT INTO t2 VALUES
|
||||
('Gaza'),('Jeddah'),('Beirut'),('Incheon'),('Tbilisi'),('Izmir'),
|
||||
('Quito'),('Riga'),('Freetown'),('Zagreb'),('Caracas'),('Orlando'),
|
||||
('Kingston'),('Turin'),('Xinyang'),('Osaka'),('Albany'),('Geneva'),
|
||||
('Omsk'),('Kazan'),('Quezon'),('Indore'),('Odessa'),('Xiamen'),
|
||||
('Winnipeg'),('Yakutsk'),('Nairobi'),('Ufa'),('Helsinki'),('Vilnius'),
|
||||
('Aden'),('Liverpool'),('Honolulu'),('Frankfurt'),('Glasgow'),
|
||||
('Vienna'),('Jackson'),('Jakarta'),('Sydney'),('Oslo'),('Novgorod'),
|
||||
('Norilsk'),('Izhevsk'),('Istanbul'),('Nice'),('Detroit'),('Detroit');
|
||||
|
||||
CREATE TABLE t3 (c varchar(32) not null) ENGINE=MyISAM;
|
||||
INSERT INTO t3 VALUES
|
||||
('Nicosia'),('Istanbul'),('Richmond'),('Stockholm'),('Dublin'),
|
||||
('Wichita'),('Warsaw'),('Glasgow'),('Winnipeg'),('Irkutsk'),('Quito'),
|
||||
('Xiamen'),('Berlin'),('Rome'),('Denver'),('Dallas'),('Kabul'),
|
||||
('Prague'),('Izhevsk'),('Tirana'),('Sofia'),('Detroit'),('Sorbonne'),
|
||||
('Detroit');
|
||||
|
||||
select count(*) from (
|
||||
SELECT * FROM t1 LEFT OUTER JOIN t2 LEFT OUTER JOIN t3 ON b < c ON a > b
|
||||
INTERSECT
|
||||
SELECT * FROM t1 LEFT OUTER JOIN t2 LEFT OUTER JOIN t3 ON b < c ON a > b
|
||||
) a;
|
||||
|
||||
drop table t1,t2,t3;
|
||||
|
||||
create table t12(c1 int);
|
||||
insert into t12 values(1);
|
||||
insert into t12 values(2);
|
||||
create table t13(c1 int);
|
||||
insert into t13 values(1);
|
||||
insert into t13 values(3);
|
||||
create table t234(c1 int);
|
||||
insert into t234 values(2);
|
||||
insert into t234 values(3);
|
||||
insert into t234 values(4);
|
||||
|
||||
|
||||
select * from t13 union select * from t234 intersect all select * from t12;
|
||||
|
||||
drop table t12,t13,t234;
|
||||
|
||||
create table t1 (a int);
|
||||
insert into t1 values (3), (1), (7), (3), (2), (7), (4);
|
||||
create table t2 (a int);
|
||||
insert into t2 values (4), (5), (9), (1), (8), (9), (2), (2);
|
||||
create table t3 (a int);
|
||||
insert into t3 values (8), (1), (8), (2), (3), (7), (2);
|
||||
|
||||
|
||||
select * from t1 where a > 4
|
||||
union all
|
||||
select * from t2 where a < 5
|
||||
intersect all
|
||||
select * from t3 where a < 5;
|
||||
|
||||
explain extended
|
||||
select * from t1 where a > 4
|
||||
union all
|
||||
select * from t2 where a < 5
|
||||
intersect all
|
||||
select * from t3 where a < 5;
|
||||
|
||||
drop table t1,t2,t3;
|
1157
mysql-test/main/set_operation.result
Normal file
1157
mysql-test/main/set_operation.result
Normal file
File diff suppressed because it is too large
Load Diff
526
mysql-test/main/set_operation.test
Normal file
526
mysql-test/main/set_operation.test
Normal file
@ -0,0 +1,526 @@
|
||||
create table t1 (a int, b int) engine=MyISAM;
|
||||
create table t2 (c int, d int) engine=MyISAM;
|
||||
create table t3 (e int, f int) engine=MyISAM;
|
||||
create table t4 (g int, h int) engine=MyISAM;
|
||||
insert into t1 values (1,1),(2,2),(3,3),(2,2),(3,3);
|
||||
insert into t2 values (2,2),(3,3),(5,5),(2,2),(2,2),(3,3);
|
||||
insert into t3 values (4,4),(2,2),(2,2),(1,1),(3,3);
|
||||
insert into t4 values (2,2),(4,4),(1,1);
|
||||
create view v0(g, h) as select a,c from t1,t2;
|
||||
|
||||
--echo # test optimization
|
||||
|
||||
let $q=
|
||||
select * from t1
|
||||
INTERSECT ALL
|
||||
select * from t2
|
||||
INTERSECT ALL
|
||||
select * from t3;
|
||||
eval $q;
|
||||
eval EXPLAIN EXTENDED $q;
|
||||
|
||||
let $q=
|
||||
select * from t1
|
||||
INTERSECT ALL
|
||||
select * from t2
|
||||
INTERSECT ALL
|
||||
select * from t3
|
||||
INTERSECT
|
||||
select * from t1;
|
||||
eval $q;
|
||||
eval EXPLAIN EXTENDED $q;
|
||||
|
||||
let $q=
|
||||
select * from t1
|
||||
INTERSECT ALL
|
||||
select * from t2
|
||||
INTERSECT ALL
|
||||
select * from t3
|
||||
EXCEPT ALL
|
||||
select * from t4;
|
||||
eval $q;
|
||||
eval EXPLAIN EXTENDED $q;
|
||||
|
||||
let $q=
|
||||
select * from t1
|
||||
INTERSECT
|
||||
select * from t2
|
||||
EXCEPT ALL
|
||||
select * from t4;
|
||||
eval $q;
|
||||
eval EXPLAIN EXTENDED $q;
|
||||
|
||||
insert into t4 values (1,1),(9,9);
|
||||
let $q=
|
||||
select * from t1
|
||||
UNION ALL
|
||||
select * from t2
|
||||
UNION ALL
|
||||
select * from t3
|
||||
EXCEPT
|
||||
select * from t4;
|
||||
eval $q;
|
||||
eval EXPLAIN EXTENDED $q;
|
||||
|
||||
delete from t4;
|
||||
insert into t4 values (3,3),(3,3);
|
||||
let $q=
|
||||
select * from t1
|
||||
INTERSECT ALL
|
||||
select * from t2
|
||||
UNION ALL
|
||||
select * from t3
|
||||
EXCEPT ALL
|
||||
select * from t1
|
||||
UNION
|
||||
select * from t4
|
||||
EXCEPT
|
||||
select * from t3
|
||||
UNION ALL
|
||||
select * from t1;
|
||||
|
||||
eval $q;
|
||||
eval EXPLAIN EXTENDED $q;
|
||||
drop table t4;
|
||||
|
||||
--echo # test optimization with brackets
|
||||
|
||||
let $q=
|
||||
(
|
||||
(select 1 except select 5 union all select 6)
|
||||
union
|
||||
(select 2 intersect all select 3 intersect all select 4)
|
||||
except
|
||||
(select 7 intersect all select 8)
|
||||
)
|
||||
union all
|
||||
(select 9 union all select 10)
|
||||
except all
|
||||
select 11;
|
||||
eval $q;
|
||||
eval EXPLAIN EXTENDED $q;
|
||||
|
||||
let $q=
|
||||
(select 1 union all select 2)
|
||||
union
|
||||
(select 3 union all select 4);
|
||||
eval $q;
|
||||
eval EXPLAIN EXTENDED $q;
|
||||
|
||||
let $q=
|
||||
(select 1 intersect all select 2)
|
||||
except
|
||||
select 3;
|
||||
eval $q;
|
||||
eval EXPLAIN EXTENDED $q;
|
||||
|
||||
let $q=
|
||||
(select 1 intersect all select 2 intersect all select 3)
|
||||
intersect
|
||||
(select 4 intersect all select 5);
|
||||
eval $q;
|
||||
eval EXPLAIN EXTENDED $q;
|
||||
|
||||
|
||||
--echo # test set operations with table value constructor
|
||||
|
||||
(values (1,1),(1,1),(1,1),(2,2),(2,2),(3,3),(9,9))
|
||||
INTERSECT ALL
|
||||
(values (1,1),(2,2),(2,2),(3,3),(3,3),(3,3),(8,8))
|
||||
EXCEPT ALL
|
||||
(values (7,7),(1,1));
|
||||
|
||||
delete from t1;
|
||||
insert into t1 values(1,1),(1,1),(2,2),(4,4),(9,9);
|
||||
|
||||
select * from t1
|
||||
UNION ALL
|
||||
(values (11,12),(3,3),(2,2),(3,3),(4,4),(8,8))
|
||||
INTERSECT
|
||||
(values (13,14),(7,7),(2,2),(3,3),(1,1))
|
||||
INTERSECT ALL
|
||||
(values (15,16),(2,2),(1,1))
|
||||
EXCEPT
|
||||
(values (17,18),(1,1));
|
||||
|
||||
--echo # test set operations with derived table
|
||||
|
||||
select * from (
|
||||
select * from t1
|
||||
UNION ALL
|
||||
select * from t2
|
||||
)dt1
|
||||
INTERSECT ALL
|
||||
select * from (
|
||||
select * from t2
|
||||
EXCEPT ALL
|
||||
select * from t3
|
||||
)dt2;
|
||||
|
||||
select * from (
|
||||
select * from t1
|
||||
UNION ALL
|
||||
select * from t3
|
||||
)dt1
|
||||
EXCEPT ALL
|
||||
select * from (
|
||||
select * from t2
|
||||
INTERSECT ALL
|
||||
select * from t2
|
||||
)dt2;
|
||||
|
||||
SELECT * from(
|
||||
select * from (
|
||||
select * from t1
|
||||
UNION ALL
|
||||
select * from t2
|
||||
)dt1
|
||||
INTERSECT ALL
|
||||
select * from (
|
||||
select * from t2
|
||||
EXCEPT ALL
|
||||
select * from t3
|
||||
)dt2
|
||||
)dt3;
|
||||
|
||||
--echo # integration test
|
||||
|
||||
|
||||
select * from t1
|
||||
UNION ALL
|
||||
select * from t2
|
||||
INTERSECT ALL
|
||||
(values (1,1), (2,2), (2,2), (5,5), (2,2))
|
||||
INTERSECT ALL
|
||||
select * from (select * from t1 union all select * from t1) sq
|
||||
EXCEPT ALL
|
||||
select * from t3
|
||||
UNION ALL
|
||||
select * from t2
|
||||
UNION
|
||||
select * from t3
|
||||
EXCEPT
|
||||
select a,c from t1,t2
|
||||
UNION ALL
|
||||
select * from v0 where g < 4
|
||||
UNION ALL
|
||||
select * from t3;
|
||||
|
||||
--sorted_result
|
||||
select * from t1
|
||||
UNION ALL
|
||||
select * from t2
|
||||
INTERSECT ALL
|
||||
(values (1,1), (2,2), (2,2), (5,5), (2,2))
|
||||
INTERSECT ALL
|
||||
select * from (select * from t1 union all select * from t1) sq
|
||||
EXCEPT ALL
|
||||
select * from t3
|
||||
UNION ALL
|
||||
select * from t2
|
||||
UNION
|
||||
select * from t3
|
||||
EXCEPT
|
||||
select a,c from t1,t2
|
||||
UNION ALL
|
||||
select * from v0 where g < 4
|
||||
UNION ALL
|
||||
select * from t3
|
||||
ORDER BY a;
|
||||
|
||||
|
||||
select * from (
|
||||
select * from t1
|
||||
UNION ALL
|
||||
select * from t2
|
||||
INTERSECT ALL
|
||||
(values (1,1), (2,2), (2,2), (5,5), (2,2) )
|
||||
INTERSECT ALL
|
||||
select * from (select * from t1 union all select * from t1) sq
|
||||
EXCEPT ALL
|
||||
select * from t3
|
||||
UNION ALL
|
||||
select * from t2
|
||||
UNION
|
||||
select * from t3
|
||||
EXCEPT
|
||||
select a,c from t1,t2
|
||||
UNION ALL
|
||||
select * from v0 where g < 4
|
||||
UNION ALL
|
||||
select * from t3
|
||||
) dt;
|
||||
|
||||
EXPLAIN
|
||||
select * from t1
|
||||
UNION ALL
|
||||
select * from t2
|
||||
INTERSECT ALL
|
||||
(values (1,1), (2,2), (2,2), (5,5), (2,2) )
|
||||
INTERSECT ALL
|
||||
select * from (select * from t1 union all select * from t1) sq
|
||||
EXCEPT ALL
|
||||
select * from t3
|
||||
UNION ALL
|
||||
select * from t2
|
||||
UNION
|
||||
select * from t3
|
||||
EXCEPT
|
||||
select a,c from t1,t2
|
||||
UNION ALL
|
||||
select * from v0 where g < 4
|
||||
UNION ALL
|
||||
select * from t3;
|
||||
|
||||
EXPLAIN format=json
|
||||
select * from t1
|
||||
UNION ALL
|
||||
select * from t2
|
||||
INTERSECT ALL
|
||||
(values (1,1), (2,2), (2,2), (5,5), (2,2) )
|
||||
INTERSECT ALL
|
||||
select * from (select * from t1 union all select * from t1) sq
|
||||
EXCEPT ALL
|
||||
select * from t3
|
||||
UNION ALL
|
||||
select * from t2
|
||||
UNION
|
||||
select * from t3
|
||||
EXCEPT
|
||||
select a,c from t1,t2
|
||||
UNION ALL
|
||||
select * from v0 where g < 4
|
||||
UNION ALL
|
||||
select * from t3;
|
||||
|
||||
EXPLAIN EXTENDED
|
||||
select * from t1
|
||||
UNION ALL
|
||||
select * from t2
|
||||
INTERSECT ALL
|
||||
(values (1,1), (2,2), (2,2), (5,5), (2,2) )
|
||||
INTERSECT ALL
|
||||
select * from (select * from t1 union all select * from t1) sq
|
||||
EXCEPT ALL
|
||||
select * from t3
|
||||
UNION ALL
|
||||
select * from t2
|
||||
UNION
|
||||
select * from t3
|
||||
EXCEPT
|
||||
select a,c from t1,t2
|
||||
UNION ALL
|
||||
select * from v0 where g < 4
|
||||
UNION ALL
|
||||
select * from t3;
|
||||
|
||||
PREPARE stmt from"
|
||||
select * from t1
|
||||
UNION ALL
|
||||
select * from t2
|
||||
INTERSECT ALL
|
||||
(values (1,1), (2,2), (2,2), (5,5), (2,2) )
|
||||
INTERSECT ALL
|
||||
select * from (select * from t1 union all select * from t1) sq
|
||||
EXCEPT ALL
|
||||
select * from t3
|
||||
UNION ALL
|
||||
select * from t2
|
||||
UNION
|
||||
select * from t3
|
||||
EXCEPT
|
||||
select a,c from t1,t2
|
||||
UNION ALL
|
||||
select * from v0 where g < 4
|
||||
UNION ALL
|
||||
select * from t3
|
||||
";
|
||||
|
||||
|
||||
EXECUTE stmt;
|
||||
|
||||
EXECUTE stmt;
|
||||
deallocate prepare stmt;
|
||||
|
||||
create view v1(i1, i2) as
|
||||
select * from t1
|
||||
UNION ALL
|
||||
select * from t2
|
||||
INTERSECT ALL
|
||||
(values (1,1), (2,2), (2,2), (5,5), (2,2) )
|
||||
INTERSECT ALL
|
||||
select * from (select * from t1 union all select * from t1) sq
|
||||
EXCEPT ALL
|
||||
select * from t3
|
||||
UNION ALL
|
||||
select * from t2
|
||||
UNION
|
||||
select * from t3
|
||||
EXCEPT
|
||||
select a,c from t1,t2
|
||||
UNION ALL
|
||||
select * from v0 where g < 4
|
||||
UNION ALL
|
||||
select * from t3;
|
||||
|
||||
show create view v1;
|
||||
|
||||
select * from v1 limit 14;
|
||||
--sorted_result
|
||||
select * from v1 order by i1 limit 14;
|
||||
|
||||
drop table t1,t2,t3;
|
||||
drop view v0,v1;
|
||||
|
||||
--echo # compare result
|
||||
|
||||
create table t1 (a int, b int);
|
||||
create table t2 (c int, d int);
|
||||
create table t3 (e int, f int);
|
||||
create table t4 (g int, h int);
|
||||
|
||||
|
||||
insert into t1 values (1,1),(1,1),(2,2);
|
||||
insert into t2 values (1,1),(1,1),(2,2),(3,3);
|
||||
insert into t3 values (1,1);
|
||||
insert into t4 values (4,4);
|
||||
|
||||
select * from t1 intersect all select * from t2 except select * from t3 union select * from t4;
|
||||
select * from t1 intersect all select * from t2 except ALL select * from t3 union select * from t4;
|
||||
|
||||
select * from t1 intersect DISTINCT select * from t2 except select * from t3 union select * from t4;
|
||||
select * from t1 intersect DISTINCT select * from t2 except ALL select * from t3 union select * from t4;
|
||||
|
||||
delete from t1;
|
||||
delete from t2;
|
||||
delete from t3;
|
||||
delete from t4;
|
||||
|
||||
|
||||
insert into t1 values (1,1),(1,1),(1,1),(2,2),(2,2),(4,4),(5,5);
|
||||
insert into t2 values (1,1),(1,1),(1,1),(2,2),(2,2),(3,3);
|
||||
insert into t3 values (1,1),(2,2),(2,2);
|
||||
|
||||
select * from t1 intersect all select * from t2 intersect all select * from t3;
|
||||
select * from t1 intersect all select * from t2 intersect select * from t3;
|
||||
select * from t1 intersect all select * from t1 intersect all select * from t2 intersect select * from t3;
|
||||
|
||||
delete from t1;
|
||||
delete from t2;
|
||||
delete from t3;
|
||||
|
||||
|
||||
insert into t1 values (1,1),(1,1),(2,2);
|
||||
insert into t2 values (1,1),(1,1),(2,2),(3,3);
|
||||
insert into t3 values (1,1),(5,5);
|
||||
insert into t4 values (4,4),(4,4),(4,4);
|
||||
|
||||
select * from t1 intersect all select * from t2 union all select * from t3 union select * from t4;
|
||||
select * from t1 intersect DISTINCT select * from t2 union DISTINCT select * from t3 union select * from t4;
|
||||
|
||||
select * from t1 intersect all select * from t2 intersect all select * from t3 union select * from t4;
|
||||
select * from t1 intersect all select * from t2 intersect DISTINCT select * from t3 union select * from t4;
|
||||
select * from t1 intersect DISTINCT select * from t2 intersect DISTINCT select * from t3 union select * from t4;
|
||||
|
||||
select * from t1 intersect all select * from t2 EXCEPT select * from t3 union select * from t4;
|
||||
select * from t1 intersect DISTINCT select * from t2 EXCEPT select * from t3 union select * from t4;
|
||||
select * from t1 intersect all select * from t2 EXCEPT ALL select * from t3 union select * from t4;
|
||||
|
||||
select * from t1 EXCEPT select * from t2 union all select * from t3 union select * from t4;
|
||||
select * from t1 EXCEPT select * from t2 union DISTINCT select * from t3 union select * from t4;
|
||||
|
||||
delete from t1;
|
||||
delete from t2;
|
||||
delete from t3;
|
||||
delete from t4;
|
||||
|
||||
|
||||
insert into t1 values (1,1),(2,2);
|
||||
insert into t2 values (1,1),(2,2);
|
||||
insert into t3 values (1,1),(3,3);
|
||||
|
||||
select * from t1 union all select * from t2 except all select * from t3;
|
||||
select * from t1 union all select * from t2 except DISTINCT select * from t3;
|
||||
select * from t1 union DISTINCT select * from t2 except all select * from t3;
|
||||
select * from t1 union DISTINCT select * from t2 except DISTINCT select * from t3;
|
||||
|
||||
drop table t1;
|
||||
drop table t2;
|
||||
drop table t3;
|
||||
drop table t4;
|
||||
|
||||
|
||||
select 1 intersect all select 2 intersect all select 3 intersect select 4 union select 5;
|
||||
select 1 intersect all select 2 intersect all select 3 union select 4 except select 5;
|
||||
select 1 union select 2 except all select 3 union select 4;
|
||||
select 1 union all select 2 union all select 3 union select 4;
|
||||
|
||||
--echo # test with limited resource
|
||||
|
||||
set @@max_heap_table_size= 1024;
|
||||
set @@tmp_table_size= 1024;
|
||||
|
||||
create table t1 (a int, b int);
|
||||
insert into t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(0,0);
|
||||
insert into t1 select * from t1;
|
||||
insert into t1 select * from t1;
|
||||
insert into t1 select * from t1;
|
||||
insert into t1 select a+100, b+100 from t1;
|
||||
create table t2 (a int, b int);
|
||||
insert into t2 values (10,10),(11,11),(12,12),(13,13),(14,14),(5,5),(6,6),(7,7),(8,8),(9,9);
|
||||
insert into t2 select * from t2;
|
||||
insert into t2 select * from t2;
|
||||
insert into t2 select * from t2;
|
||||
insert into t2 select a+100, b+100 from t2;
|
||||
|
||||
|
||||
select count(*) from
|
||||
(
|
||||
select * from t1
|
||||
INTERSECT ALL
|
||||
select * from t2
|
||||
) c;
|
||||
|
||||
select count(*) from
|
||||
(
|
||||
select * from t1
|
||||
EXCEPT ALL
|
||||
select * from t2
|
||||
) c;
|
||||
|
||||
select count(*) from
|
||||
(
|
||||
select * from t1
|
||||
INTERSECT ALL
|
||||
select * from t2
|
||||
UNION ALL
|
||||
select * from t1
|
||||
EXCEPT ALL
|
||||
select * from t2
|
||||
) c;
|
||||
|
||||
delete from t1;
|
||||
delete from t2;
|
||||
|
||||
insert into t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(0,0);
|
||||
insert into t1 select a+10, b+10 from t1;
|
||||
insert into t1 select a+20, b+20 from t1;
|
||||
insert into t1 select a+40, b+40 from t1;
|
||||
insert into t1 select a+80, b+80 from t1;
|
||||
insert into t2 values (1110,1110),(1111,1111),(1112,1112),(1113,1113),(1114,1114),(1105,1105),(1106,1106),(1107,1107),(1108,1108),(1109,1109);
|
||||
insert into t2 select a+10, b+10 from t2;
|
||||
insert into t2 select a+20, b+20 from t2;
|
||||
insert into t2 select a+40, b+40 from t2;
|
||||
insert into t2 select a+80, b+80 from t2;
|
||||
|
||||
select count(*) from
|
||||
(
|
||||
select * from t1
|
||||
UNION ALL
|
||||
select * from t2
|
||||
EXCEPT ALL
|
||||
values (1,1)
|
||||
) c;
|
||||
|
||||
drop table t1;
|
||||
drop table t2;
|
75
mysql-test/main/set_operation_oracle.result
Normal file
75
mysql-test/main/set_operation_oracle.result
Normal file
@ -0,0 +1,75 @@
|
||||
create table t1 (a int, b blob) engine=MyISAM;
|
||||
create table t2 (c int, d blob) engine=MyISAM;
|
||||
create table t3 (e int, f blob) engine=MyISAM;
|
||||
insert into t1 values (5,5),(6,6);
|
||||
insert into t2 values (2,2),(3,3);
|
||||
insert into t3 values (1,1),(3,3);
|
||||
set SQL_MODE=ORACLE;
|
||||
(select a,b from t1) union (select c,d from t2) intersect (select e,f from t3) union (select 4,4);
|
||||
a b
|
||||
4 4
|
||||
3 3
|
||||
explain extended
|
||||
(select a,b from t1) union (select c,d from t2) intersect (select e,f from t3) union (select 4,4);
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
|
||||
2 UNION t2 ALL NULL NULL NULL NULL 2 100.00
|
||||
3 INTERSECT t3 ALL NULL NULL NULL NULL 2 100.00
|
||||
4 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
||||
NULL UNIT RESULT <unit1,2,3,4> ALL NULL NULL NULL NULL NULL NULL
|
||||
Warnings:
|
||||
Note 1003 (/* select#1 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1") union (/* select#2 */ select "test"."t2"."c" AS "c","test"."t2"."d" AS "d" from "test"."t2") intersect (/* select#3 */ select "test"."t3"."e" AS "e","test"."t3"."f" AS "f" from "test"."t3") union (/* select#4 */ select 4 AS "4",4 AS "4")
|
||||
(select e,f from t3) intersect (select c,d from t2) union (select a,b from t1) union (select 4,4);
|
||||
e f
|
||||
5 5
|
||||
3 3
|
||||
6 6
|
||||
4 4
|
||||
explain extended
|
||||
(select e,f from t3) intersect (select c,d from t2) union (select a,b from t1) union (select 4,4);
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 PRIMARY t3 ALL NULL NULL NULL NULL 2 100.00
|
||||
2 INTERSECT t2 ALL NULL NULL NULL NULL 2 100.00
|
||||
3 UNION t1 ALL NULL NULL NULL NULL 2 100.00
|
||||
4 UNION NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
||||
NULL UNIT RESULT <unit1,2,3,4> ALL NULL NULL NULL NULL NULL NULL
|
||||
Warnings:
|
||||
Note 1003 (/* select#1 */ select "test"."t3"."e" AS "e","test"."t3"."f" AS "f" from "test"."t3") intersect (/* select#2 */ select "test"."t2"."c" AS "c","test"."t2"."d" AS "d" from "test"."t2") union (/* select#3 */ select "test"."t1"."a" AS "a","test"."t1"."b" AS "b" from "test"."t1") union (/* select#4 */ select 4 AS "4",4 AS "4")
|
||||
create table t12(c1 int);
|
||||
insert into t12 values(1);
|
||||
insert into t12 values(2);
|
||||
create table t13(c1 int);
|
||||
insert into t13 values(1);
|
||||
insert into t13 values(3);
|
||||
create table t234(c1 int);
|
||||
insert into t234 values(2);
|
||||
insert into t234 values(3);
|
||||
insert into t234 values(4);
|
||||
select * from t13 union select * from t234 intersect select * from t12;
|
||||
c1
|
||||
1
|
||||
2
|
||||
set SQL_MODE=default;
|
||||
drop table t1,t2,t3;
|
||||
drop table t12,t13, t234;
|
||||
create table t1 (a int, b blob) engine=MyISAM;
|
||||
create table t2 (c int, d blob) engine=MyISAM;
|
||||
create table t3 (e int, f blob) engine=MyISAM;
|
||||
insert into t1 values (5,5),(6,6);
|
||||
insert into t2 values (2,2),(3,3);
|
||||
insert into t3 values (1,1),(3,3);
|
||||
set SQL_MODE=ORACLE;
|
||||
(select a,b from t1) union all (select c,d from t2) intersect all (select e,f from t3) union all (select 4,4);
|
||||
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'all (select e,f from t3) union all (select 4,4)' at line 1
|
||||
explain extended (select a,b from t1) union all (select c,d from t2) intersect all (select e,f from t3) union all (select 4,4);
|
||||
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'all (select e,f from t3) union all (select 4,4)' at line 1
|
||||
(select e,f from t3) intersect all (select c,d from t2) union all (select a,b from t1) union all (select 4,4);
|
||||
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'all (select c,d from t2) union all (select a,b from t1) union all (select 4,4)' at line 1
|
||||
explain extended (select e,f from t3) intersect all (select c,d from t2) union all (select a,b from t1) union all (select 4,4);
|
||||
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'all (select c,d from t2) union all (select a,b from t1) union all (select 4,4)' at line 1
|
||||
set SQL_MODE=default;
|
||||
drop table t1,t2,t3;
|
||||
set SQL_MODE=oracle;
|
||||
select * from t13 union select * from t234 intersect all select * from t12;
|
||||
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'all select * from t12' at line 1
|
||||
set SQL_MODE=default;
|
65
mysql-test/main/set_operation_oracle.test
Normal file
65
mysql-test/main/set_operation_oracle.test
Normal file
@ -0,0 +1,65 @@
|
||||
# from intersect.test
|
||||
create table t1 (a int, b blob) engine=MyISAM;
|
||||
create table t2 (c int, d blob) engine=MyISAM;
|
||||
create table t3 (e int, f blob) engine=MyISAM;
|
||||
insert into t1 values (5,5),(6,6);
|
||||
insert into t2 values (2,2),(3,3);
|
||||
insert into t3 values (1,1),(3,3);
|
||||
|
||||
set SQL_MODE=ORACLE;
|
||||
|
||||
(select a,b from t1) union (select c,d from t2) intersect (select e,f from t3) union (select 4,4);
|
||||
explain extended
|
||||
(select a,b from t1) union (select c,d from t2) intersect (select e,f from t3) union (select 4,4);
|
||||
|
||||
|
||||
(select e,f from t3) intersect (select c,d from t2) union (select a,b from t1) union (select 4,4);
|
||||
explain extended
|
||||
(select e,f from t3) intersect (select c,d from t2) union (select a,b from t1) union (select 4,4);
|
||||
|
||||
create table t12(c1 int);
|
||||
insert into t12 values(1);
|
||||
insert into t12 values(2);
|
||||
create table t13(c1 int);
|
||||
insert into t13 values(1);
|
||||
insert into t13 values(3);
|
||||
create table t234(c1 int);
|
||||
insert into t234 values(2);
|
||||
insert into t234 values(3);
|
||||
insert into t234 values(4);
|
||||
|
||||
|
||||
select * from t13 union select * from t234 intersect select * from t12;
|
||||
set SQL_MODE=default;
|
||||
|
||||
drop table t1,t2,t3;
|
||||
drop table t12,t13, t234;
|
||||
|
||||
#from intersect_all.test
|
||||
create table t1 (a int, b blob) engine=MyISAM;
|
||||
create table t2 (c int, d blob) engine=MyISAM;
|
||||
create table t3 (e int, f blob) engine=MyISAM;
|
||||
insert into t1 values (5,5),(6,6);
|
||||
insert into t2 values (2,2),(3,3);
|
||||
insert into t3 values (1,1),(3,3);
|
||||
|
||||
set SQL_MODE=ORACLE;
|
||||
|
||||
#(select a,b from t1) union all (select c,d from t2) intersect (select e,f from t3) union all (select 4,4);
|
||||
--error ER_PARSE_ERROR
|
||||
(select a,b from t1) union all (select c,d from t2) intersect all (select e,f from t3) union all (select 4,4);
|
||||
--error ER_PARSE_ERROR
|
||||
explain extended (select a,b from t1) union all (select c,d from t2) intersect all (select e,f from t3) union all (select 4,4);
|
||||
|
||||
--error ER_PARSE_ERROR
|
||||
(select e,f from t3) intersect all (select c,d from t2) union all (select a,b from t1) union all (select 4,4);
|
||||
--error ER_PARSE_ERROR
|
||||
explain extended (select e,f from t3) intersect all (select c,d from t2) union all (select a,b from t1) union all (select 4,4);
|
||||
set SQL_MODE=default;
|
||||
|
||||
drop table t1,t2,t3;
|
||||
|
||||
set SQL_MODE=oracle;
|
||||
--error ER_PARSE_ERROR
|
||||
select * from t13 union select * from t234 intersect all select * from t12;
|
||||
set SQL_MODE=default;
|
151
sql/sql_class.h
151
sql/sql_class.h
@ -5708,17 +5708,18 @@ public:
|
||||
|
||||
class select_unit :public select_result_interceptor
|
||||
{
|
||||
public:
|
||||
uint curr_step, prev_step, curr_sel;
|
||||
enum sub_select_type step;
|
||||
public:
|
||||
Item_int *intersect_mark;
|
||||
TMP_TABLE_PARAM tmp_table_param;
|
||||
/* Number of additional (hidden) field of the used temporary table */
|
||||
int addon_cnt;
|
||||
int write_err; /* Error code from the last send_data->ha_write_row call. */
|
||||
TABLE *table;
|
||||
|
||||
select_unit(THD *thd_arg):
|
||||
select_result_interceptor(thd_arg),
|
||||
intersect_mark(0), table(0)
|
||||
select_result_interceptor(thd_arg), addon_cnt(0), table(0)
|
||||
{
|
||||
init();
|
||||
tmp_table_param.init();
|
||||
@ -5735,6 +5736,9 @@ public:
|
||||
virtual bool postponed_prepare(List<Item> &types)
|
||||
{ return false; }
|
||||
int send_data(List<Item> &items);
|
||||
int write_record();
|
||||
int update_counter(Field *counter, longlong value);
|
||||
int delete_record();
|
||||
bool send_eof();
|
||||
virtual bool flush();
|
||||
void cleanup();
|
||||
@ -5753,7 +5757,148 @@ public:
|
||||
step= UNION_TYPE;
|
||||
write_err= 0;
|
||||
}
|
||||
virtual void change_select();
|
||||
virtual bool force_enable_index_if_needed() { return false; }
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
@class select_unit_ext
|
||||
|
||||
The class used when processing rows produced by operands of query expressions
|
||||
containing INTERSECT ALL and/or EXCEPT all operations. One or two extra fields
|
||||
of the temporary to store the rows of the partial and final result can be employed.
|
||||
Both of them contain counters. The second additional field is used only when
|
||||
the processed query expression contains INTERSECT ALL.
|
||||
|
||||
Consider how these extra fields are used.
|
||||
|
||||
Let
|
||||
table t1 (f char(8))
|
||||
table t2 (f char(8))
|
||||
table t3 (f char(8))
|
||||
contain the following sets:
|
||||
("b"),("a"),("d"),("c"),("b"),("a"),("c"),("a")
|
||||
("c"),("b"),("c"),("c"),("a"),("b"),("g")
|
||||
("c"),("a"),("b"),("d"),("b"),("e")
|
||||
|
||||
- Let's demonstrate how the the set operation INTERSECT ALL is proceesed
|
||||
for the query
|
||||
SELECT f FROM t1 INTERSECT ALL SELECT f FROM t2
|
||||
|
||||
When send_data() is called for the rows of the first operand we put
|
||||
the processed record into the temporary table if there was no such record
|
||||
setting dup_cnt field to 1 and add_cnt field to 0 and increment the
|
||||
counter in the dup_cnt field by one otherwise. We get
|
||||
|
||||
|add_cnt|dup_cnt| f |
|
||||
|0 |2 |b |
|
||||
|0 |3 |a |
|
||||
|0 |1 |d |
|
||||
|0 |2 |c |
|
||||
|
||||
The call of send_eof() for the first operand swaps the values stored in
|
||||
dup_cnt and add_cnt. After this, we'll see the following rows in the
|
||||
temporary table
|
||||
|
||||
|add_cnt|dup_cnt| f |
|
||||
|2 |0 |b |
|
||||
|3 |0 |a |
|
||||
|1 |0 |d |
|
||||
|2 |0 |c |
|
||||
|
||||
When send_data() is called for the rows of the second operand we increment
|
||||
the counter in dup_cnt if the processed row is found in the table and do
|
||||
nothing otherwise. As a result we get
|
||||
|
||||
|add_cnt|dup_cnt| f |
|
||||
|2 |2 |b |
|
||||
|3 |1 |a |
|
||||
|1 |0 |d |
|
||||
|2 |3 |c |
|
||||
|
||||
At the call of send_eof() for the second operand first we disable index.
|
||||
Then for each record, the minimum of counters from dup_cnt and add_cnt m is
|
||||
taken. If m == 0 then the record is deleted. Otherwise record is replaced
|
||||
with m copies of it. Yet the counter in this copies are set to 1 for
|
||||
dup_cnt and to 0 for add_cnt
|
||||
|
||||
|add_cnt|dup_cnt| f |
|
||||
|0 |1 |b |
|
||||
|0 |1 |b |
|
||||
|0 |1 |a |
|
||||
|0 |1 |c |
|
||||
|0 |1 |c |
|
||||
|
||||
- Let's demonstrate how the the set operation EXCEPT ALL is proceesed
|
||||
for the query
|
||||
SELECT f FROM t1 EXCEPT ALL SELECT f FROM t3
|
||||
|
||||
Only one additional counter field dup_cnt is used for EXCEPT ALL.
|
||||
After the first operand has been processed we have in the temporary table
|
||||
|
||||
|dup_cnt| f |
|
||||
|2 |b |
|
||||
|3 |a |
|
||||
|1 |d |
|
||||
|2 |c |
|
||||
|
||||
When send_data() is called for the rows of the second operand we decrement
|
||||
the counter in dup_cnt if the processed row is found in the table and do
|
||||
nothing otherwise. If the counter becomes 0 we delete the record
|
||||
|
||||
|dup_cnt| f |
|
||||
|2 |a |
|
||||
|1 |c |
|
||||
|
||||
Finally at the call of send_eof() for the second operand we disable index
|
||||
unfold rows adding duplicates
|
||||
|
||||
|dup_cnt| f |
|
||||
|1 |a |
|
||||
|1 |a |
|
||||
|1 |c |
|
||||
*/
|
||||
|
||||
class select_unit_ext :public select_unit
|
||||
{
|
||||
public:
|
||||
select_unit_ext(THD *thd_arg):
|
||||
select_unit(thd_arg), increment(0), is_index_enabled(TRUE),
|
||||
curr_op_type(UNSPECIFIED)
|
||||
{
|
||||
};
|
||||
int send_data(List<Item> &items);
|
||||
void change_select();
|
||||
int unfold_record(int cnt);
|
||||
bool send_eof();
|
||||
bool force_enable_index_if_needed()
|
||||
{
|
||||
is_index_enabled= true;
|
||||
return true;
|
||||
}
|
||||
bool disable_index_if_needed(SELECT_LEX *curr_sl);
|
||||
|
||||
/*
|
||||
How to change increment/decrement the counter in duplicate_cnt field
|
||||
when processing a record produced by the current operand in send_data().
|
||||
The value can be 1 or -1
|
||||
*/
|
||||
int increment;
|
||||
/* TRUE <=> the index of the result temporary table is enabled */
|
||||
bool is_index_enabled;
|
||||
/* The type of the set operation currently executed */
|
||||
enum set_op_type curr_op_type;
|
||||
/*
|
||||
Points to the extra field of the temporary table where
|
||||
duplicate counters are stored
|
||||
*/
|
||||
Field *duplicate_cnt;
|
||||
/*
|
||||
Points to the extra field of the temporary table where additional
|
||||
counters used only for INTERSECT ALL operations are stored
|
||||
*/
|
||||
Field *additional_cnt;
|
||||
};
|
||||
|
||||
class select_union_recursive :public select_unit
|
||||
|
@ -2354,6 +2354,7 @@ void st_select_lex_unit::init_query()
|
||||
offset_limit_cnt= 0;
|
||||
union_distinct= 0;
|
||||
prepared= optimized= optimized_2= executed= 0;
|
||||
bag_set_op_optimized= 0;
|
||||
optimize_started= 0;
|
||||
item= 0;
|
||||
union_result= 0;
|
||||
@ -2369,8 +2370,8 @@ void st_select_lex_unit::init_query()
|
||||
with_clause= 0;
|
||||
with_element= 0;
|
||||
columns_are_renamed= false;
|
||||
intersect_mark= NULL;
|
||||
with_wrapped_tvc= false;
|
||||
have_except_all_or_intersect_all= false;
|
||||
}
|
||||
|
||||
void st_select_lex::init_query()
|
||||
@ -2468,6 +2469,7 @@ void st_select_lex::init_select()
|
||||
curr_tvc_name= 0;
|
||||
in_tvc= false;
|
||||
versioned_tables= 0;
|
||||
nest_flags= 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -2986,7 +2988,6 @@ bool st_select_lex::setup_ref_array(THD *thd, uint order_group_num)
|
||||
|
||||
void st_select_lex_unit::print(String *str, enum_query_type query_type)
|
||||
{
|
||||
bool union_all= !union_distinct;
|
||||
if (with_clause)
|
||||
with_clause->print(str, query_type);
|
||||
for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select())
|
||||
@ -2999,8 +3000,6 @@ void st_select_lex_unit::print(String *str, enum_query_type query_type)
|
||||
DBUG_ASSERT(0);
|
||||
case UNION_TYPE:
|
||||
str->append(STRING_WITH_LEN(" union "));
|
||||
if (union_all)
|
||||
str->append(STRING_WITH_LEN("all "));
|
||||
break;
|
||||
case INTERSECT_TYPE:
|
||||
str->append(STRING_WITH_LEN(" intersect "));
|
||||
@ -3009,8 +3008,8 @@ void st_select_lex_unit::print(String *str, enum_query_type query_type)
|
||||
str->append(STRING_WITH_LEN(" except "));
|
||||
break;
|
||||
}
|
||||
if (sl == union_distinct)
|
||||
union_all= TRUE;
|
||||
if (!sl->distinct)
|
||||
str->append(STRING_WITH_LEN("all "));
|
||||
}
|
||||
if (sl->braces)
|
||||
str->append('(');
|
||||
@ -3523,6 +3522,8 @@ bool st_select_lex_unit::union_needs_tmp_table()
|
||||
with_wrapped_tvc= true;
|
||||
break;
|
||||
}
|
||||
if (sl != first_select() && sl->linkage != UNION_TYPE)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (with_wrapped_tvc)
|
||||
@ -5394,7 +5395,7 @@ LEX::wrap_unit_into_derived(SELECT_LEX_UNIT *unit)
|
||||
Name_resolution_context *context= &wrapping_sel->context;
|
||||
context->init();
|
||||
wrapping_sel->automatic_brackets= FALSE;
|
||||
|
||||
wrapping_sel->mark_as_unit_nest();
|
||||
wrapping_sel->register_unit(unit, context);
|
||||
|
||||
/* stuff dummy SELECT * FROM (...) */
|
||||
|
@ -207,6 +207,14 @@ enum sub_select_type
|
||||
GLOBAL_OPTIONS_TYPE, DERIVED_TABLE_TYPE, OLAP_TYPE
|
||||
};
|
||||
|
||||
enum set_op_type
|
||||
{
|
||||
UNSPECIFIED,
|
||||
UNION_DISTINCT, UNION_ALL,
|
||||
EXCEPT_DISTINCT, EXCEPT_ALL,
|
||||
INTERSECT_DISTINCT, INTERSECT_ALL
|
||||
};
|
||||
|
||||
inline int cmp_unit_op(enum sub_select_type op1, enum sub_select_type op2)
|
||||
{
|
||||
DBUG_ASSERT(op1 >= UNION_TYPE && op1 <= EXCEPT_TYPE);
|
||||
@ -841,8 +849,8 @@ public:
|
||||
// Ensures that at least all members used during cleanup() are initialized.
|
||||
st_select_lex_unit()
|
||||
: union_result(NULL), table(NULL), result(NULL),
|
||||
cleaned(false),
|
||||
fake_select_lex(NULL)
|
||||
cleaned(false), bag_set_op_optimized(false),
|
||||
have_except_all_or_intersect_all(false), fake_select_lex(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
@ -853,9 +861,11 @@ public:
|
||||
optimized, // optimize phase already performed for UNION (unit)
|
||||
optimized_2,
|
||||
executed, // already executed
|
||||
cleaned;
|
||||
cleaned,
|
||||
bag_set_op_optimized;
|
||||
|
||||
bool optimize_started;
|
||||
bool have_except_all_or_intersect_all;
|
||||
|
||||
// list of fields which points to temporary table for union
|
||||
List<Item> item_list;
|
||||
@ -867,11 +877,6 @@ public:
|
||||
any SELECT of this unit execution
|
||||
*/
|
||||
List<Item> types;
|
||||
/**
|
||||
There is INTERSECT and it is item used in creating temporary
|
||||
table for it
|
||||
*/
|
||||
Item_int *intersect_mark;
|
||||
/**
|
||||
TRUE if the unit contained TVC at the top level that has been wrapped
|
||||
into SELECT:
|
||||
@ -928,8 +933,9 @@ public:
|
||||
fake_select_lex is used.
|
||||
*/
|
||||
st_select_lex *saved_fake_select_lex;
|
||||
|
||||
st_select_lex *union_distinct; /* pointer to the last UNION DISTINCT */
|
||||
|
||||
/* pointer to the last node before last subsequence of UNION ALL */
|
||||
st_select_lex *union_distinct;
|
||||
bool describe; /* union exec() called for EXPLAIN */
|
||||
Procedure *last_procedure; /* Pointer to procedure, if such exists */
|
||||
|
||||
@ -955,6 +961,7 @@ public:
|
||||
bool prepare(TABLE_LIST *derived_arg, select_result *sel_result,
|
||||
ulong additional_options);
|
||||
bool optimize();
|
||||
void optimize_bag_operation(bool is_outer_distinct);
|
||||
bool exec();
|
||||
bool exec_recursive();
|
||||
bool cleanup();
|
||||
@ -1025,7 +1032,7 @@ Field_pair *find_matching_field_pair(Item *item, List<Field_pair> pair_list);
|
||||
#define TOUCHED_SEL_COND 1/* WHERE/HAVING/ON should be reinited before use */
|
||||
#define TOUCHED_SEL_DERIVED (1<<1)/* derived should be reinited before use */
|
||||
|
||||
|
||||
#define UNIT_NEST_FL 1
|
||||
/*
|
||||
SELECT_LEX - store information of parsed SELECT statment
|
||||
*/
|
||||
@ -1048,7 +1055,7 @@ public:
|
||||
select1->first_nested points to select1.
|
||||
*/
|
||||
st_select_lex *first_nested;
|
||||
|
||||
uint8 nest_flags;
|
||||
Name_resolution_context context;
|
||||
LEX_CSTRING db;
|
||||
Item *where, *having; /* WHERE & HAVING clauses */
|
||||
@ -1524,6 +1531,13 @@ public:
|
||||
|
||||
select_handler *find_select_handler(THD *thd);
|
||||
|
||||
bool is_set_op()
|
||||
{
|
||||
return linkage == UNION_TYPE ||
|
||||
linkage == EXCEPT_TYPE ||
|
||||
linkage == INTERSECT_TYPE;
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_non_agg_field_used;
|
||||
bool m_agg_func_used;
|
||||
@ -1570,6 +1584,8 @@ public:
|
||||
void add_statistics(SELECT_LEX_UNIT *unit);
|
||||
bool make_unique_derived_name(THD *thd, LEX_CSTRING *alias);
|
||||
void lex_start(LEX *plex);
|
||||
bool is_unit_nest() { return (nest_flags & UNIT_NEST_FL); }
|
||||
void mark_as_unit_nest() { nest_flags= UNIT_NEST_FL; }
|
||||
};
|
||||
typedef class st_select_lex SELECT_LEX;
|
||||
|
||||
|
@ -751,6 +751,7 @@ st_select_lex *wrap_tvc_with_tail(THD *thd, st_select_lex *tvc_sl)
|
||||
{
|
||||
wrapper_sl->master_unit()->union_distinct= wrapper_sl;
|
||||
}
|
||||
wrapper_sl->distinct= tvc_sl->distinct;
|
||||
thd->lex->current_select= wrapper_sl;
|
||||
return wrapper_sl;
|
||||
}
|
||||
|
952
sql/sql_union.cc
952
sql/sql_union.cc
File diff suppressed because it is too large
Load Diff
@ -17577,10 +17577,10 @@ release:
|
||||
unit_type_decl:
|
||||
UNION_SYM union_option
|
||||
{ $$.unit_type= UNION_TYPE; $$.distinct= $2; }
|
||||
| INTERSECT_SYM
|
||||
{ $$.unit_type= INTERSECT_TYPE; $$.distinct= 1; }
|
||||
| EXCEPT_SYM
|
||||
{ $$.unit_type= EXCEPT_TYPE; $$.distinct= 1; }
|
||||
| INTERSECT_SYM union_option
|
||||
{ $$.unit_type= INTERSECT_TYPE; $$.distinct= $2; }
|
||||
| EXCEPT_SYM union_option
|
||||
{ $$.unit_type= EXCEPT_TYPE; $$.distinct= $2; }
|
||||
;
|
||||
|
||||
/*
|
||||
|
@ -145,21 +145,21 @@ static uchar *next_free_record_pos(HP_SHARE *info)
|
||||
DBUG_PRINT("exit",("Used old position: %p", pos));
|
||||
DBUG_RETURN(pos);
|
||||
}
|
||||
if ((info->records > info->max_records && info->max_records) ||
|
||||
(info->data_length + info->index_length >= info->max_table_size))
|
||||
{
|
||||
DBUG_PRINT("error",
|
||||
("record file full. records: %lu max_records: %lu "
|
||||
"data_length: %llu index_length: %llu "
|
||||
"max_table_size: %llu",
|
||||
info->records, info->max_records,
|
||||
info->data_length, info->index_length,
|
||||
info->max_table_size));
|
||||
my_errno=HA_ERR_RECORD_FILE_FULL;
|
||||
DBUG_RETURN(NULL);
|
||||
}
|
||||
if (!(block_pos=(info->records % info->block.records_in_block)))
|
||||
{
|
||||
if ((info->records > info->max_records && info->max_records) ||
|
||||
(info->data_length + info->index_length >= info->max_table_size))
|
||||
{
|
||||
DBUG_PRINT("error",
|
||||
("record file full. records: %lu max_records: %lu "
|
||||
"data_length: %llu index_length: %llu "
|
||||
"max_table_size: %llu",
|
||||
info->records, info->max_records,
|
||||
info->data_length, info->index_length,
|
||||
info->max_table_size));
|
||||
my_errno=HA_ERR_RECORD_FILE_FULL;
|
||||
DBUG_RETURN(NULL);
|
||||
}
|
||||
if (hp_get_new_block(info, &info->block,&length))
|
||||
DBUG_RETURN(NULL);
|
||||
info->data_length+=length;
|
||||
|
Loading…
x
Reference in New Issue
Block a user