2017-07-26 21:46:16 +02:00
|
|
|
create table t1 (a int, b int);
|
2017-08-29 16:58:32 +02:00
|
|
|
insert into t1 values (1,2),(4,6),(9,7),
|
|
|
|
(1,1),(2,5),(7,8);
|
2017-07-26 21:46:16 +02:00
|
|
|
# just VALUES
|
|
|
|
values (1,2);
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
values (1,2), (3,4), (5.6,0);
|
|
|
|
1 2
|
|
|
|
1.0 2
|
|
|
|
3.0 4
|
|
|
|
5.6 0
|
|
|
|
values ("abc", "def");
|
|
|
|
abc def
|
|
|
|
abc def
|
2017-08-29 02:32:39 +02:00
|
|
|
# UNION that uses VALUES structure(s)
|
|
|
|
select 1,2
|
|
|
|
union
|
|
|
|
values (1,2);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2)
|
|
|
|
union
|
|
|
|
select 1,2;
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
2017-08-29 02:32:39 +02:00
|
|
|
select 1,2
|
|
|
|
union
|
|
|
|
values (1,2),(3,4),(5,6),(7,8);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
5 6
|
|
|
|
7 8
|
2017-08-29 02:32:39 +02:00
|
|
|
select 3,7
|
|
|
|
union
|
|
|
|
values (1,2),(3,4),(5,6);
|
2017-07-26 21:46:16 +02:00
|
|
|
3 7
|
|
|
|
3 7
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
5 6
|
2017-08-29 02:32:39 +02:00
|
|
|
select 3,7,4
|
|
|
|
union
|
|
|
|
values (1,2,5),(4,5,6);
|
2017-07-26 21:46:16 +02:00
|
|
|
3 7 4
|
|
|
|
3 7 4
|
|
|
|
1 2 5
|
|
|
|
4 5 6
|
2017-08-29 02:32:39 +02:00
|
|
|
select 1,2
|
|
|
|
union
|
|
|
|
values (1,7),(3,6.5);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2.0
|
|
|
|
1 7.0
|
|
|
|
3 6.5
|
2017-08-29 02:32:39 +02:00
|
|
|
select 1,2
|
|
|
|
union
|
|
|
|
values (1,2.0),(3,6);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2.0
|
|
|
|
3 6.0
|
2017-08-29 02:32:39 +02:00
|
|
|
select 1.8,2
|
|
|
|
union
|
|
|
|
values (1,2),(3,6);
|
2017-07-26 21:46:16 +02:00
|
|
|
1.8 2
|
|
|
|
1.8 2
|
|
|
|
1.0 2
|
|
|
|
3.0 6
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2.4),(3,6)
|
|
|
|
union
|
|
|
|
select 2.8,9;
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2.4
|
|
|
|
1.0 2.4
|
|
|
|
3.0 6.0
|
|
|
|
2.8 9.0
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2),(3,4),(5,6),(7,8)
|
|
|
|
union
|
|
|
|
select 5,6;
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
5 6
|
|
|
|
7 8
|
2017-08-29 02:32:39 +02:00
|
|
|
select "ab","cdf"
|
|
|
|
union
|
|
|
|
values ("al","zl"),("we","q");
|
2017-07-26 21:46:16 +02:00
|
|
|
ab cdf
|
|
|
|
ab cdf
|
|
|
|
al zl
|
|
|
|
we q
|
2017-08-29 02:32:39 +02:00
|
|
|
values ("ab", "cdf")
|
|
|
|
union
|
|
|
|
select "ab","cdf";
|
2017-07-26 21:46:16 +02:00
|
|
|
ab cdf
|
|
|
|
ab cdf
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2)
|
|
|
|
union
|
|
|
|
values (1,2),(5,6);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
5 6
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2)
|
|
|
|
union
|
|
|
|
values (3,4),(5,6);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
5 6
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2)
|
|
|
|
union
|
|
|
|
values (1,2)
|
|
|
|
union values (4,5);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
4 5
|
2017-08-29 02:32:39 +02:00
|
|
|
# UNION ALL that uses VALUES structure
|
|
|
|
values (1,2),(3,4)
|
|
|
|
union all
|
|
|
|
select 5,6;
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
5 6
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2),(3,4)
|
|
|
|
union all
|
|
|
|
select 1,2;
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
1 2
|
2017-08-29 02:32:39 +02:00
|
|
|
select 5,6
|
|
|
|
union all
|
|
|
|
values (1,2),(3,4);
|
2017-07-26 21:46:16 +02:00
|
|
|
5 6
|
|
|
|
5 6
|
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
select 1,2
|
|
|
|
union all
|
|
|
|
values (1,2),(3,4);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2)
|
|
|
|
union all
|
|
|
|
values (1,2),(5,6);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
5 6
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2)
|
|
|
|
union all
|
|
|
|
values (3,4),(5,6);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
5 6
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2)
|
|
|
|
union all
|
|
|
|
values (1,2)
|
|
|
|
union all
|
|
|
|
values (4,5);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
4 5
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2)
|
|
|
|
union all
|
|
|
|
values (1,2)
|
|
|
|
union values (1,2);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2)
|
|
|
|
union
|
|
|
|
values (1,2)
|
|
|
|
union all
|
|
|
|
values (1,2);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
1 2
|
2017-08-29 02:32:39 +02:00
|
|
|
# EXCEPT that uses VALUES structure(s)
|
|
|
|
select 1,2
|
|
|
|
except
|
|
|
|
values (3,4),(5,6);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
2017-08-29 02:32:39 +02:00
|
|
|
select 1,2
|
|
|
|
except
|
|
|
|
values (1,2),(3,4);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2),(3,4)
|
|
|
|
except
|
|
|
|
select 5,6;
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2),(3,4)
|
|
|
|
except
|
|
|
|
select 1,2;
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2),(3,4)
|
|
|
|
except
|
|
|
|
values (5,6);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2),(3,4)
|
|
|
|
except
|
|
|
|
values (1,2);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
# INTERSECT that uses VALUES structure(s)
|
|
|
|
select 1,2
|
|
|
|
intersect
|
|
|
|
values (3,4),(5,6);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
2017-08-29 02:32:39 +02:00
|
|
|
select 1,2
|
|
|
|
intersect
|
|
|
|
values (1,2),(3,4);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2),(3,4)
|
|
|
|
intersect
|
|
|
|
select 5,6;
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2),(3,4)
|
|
|
|
intersect
|
|
|
|
select 1,2;
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2),(3,4)
|
|
|
|
intersect
|
|
|
|
values (5,6);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2),(3,4)
|
|
|
|
intersect
|
|
|
|
values (1,2);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
2017-08-29 02:32:39 +02:00
|
|
|
# combination of different structures that uses VALUES structures : UNION + EXCEPT
|
|
|
|
values (1,2),(3,4)
|
|
|
|
except
|
|
|
|
select 1,2
|
|
|
|
union values (1,2);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2),(3,4)
|
|
|
|
except
|
|
|
|
values (1,2)
|
|
|
|
union
|
|
|
|
values (1,2);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2),(3,4)
|
|
|
|
except
|
|
|
|
values (1,2)
|
|
|
|
union
|
|
|
|
values (3,4);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2),(3,4)
|
|
|
|
union
|
|
|
|
values (1,2)
|
|
|
|
except
|
|
|
|
values (1,2);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
# combination of different structures that uses VALUES structures : UNION ALL + EXCEPT
|
|
|
|
values (1,2),(3,4)
|
|
|
|
except
|
|
|
|
select 1,2
|
|
|
|
union all
|
|
|
|
values (1,2);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2),(3,4)
|
|
|
|
except
|
|
|
|
values (1,2)
|
|
|
|
union all
|
|
|
|
values (1,2);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2),(3,4)
|
|
|
|
except
|
|
|
|
values (1,2)
|
|
|
|
union all
|
|
|
|
values (3,4);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2),(3,4)
|
|
|
|
union all
|
|
|
|
values (1,2)
|
|
|
|
except
|
|
|
|
values (1,2);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
# combination of different structures that uses VALUES structures : UNION + INTERSECT
|
|
|
|
values (1,2),(3,4)
|
|
|
|
intersect
|
|
|
|
select 1,2
|
|
|
|
union
|
|
|
|
values (1,2);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2),(3,4)
|
|
|
|
intersect
|
|
|
|
values (1,2)
|
|
|
|
union
|
|
|
|
values (1,2);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2),(3,4)
|
|
|
|
intersect
|
|
|
|
values (1,2)
|
|
|
|
union
|
|
|
|
values (3,4);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2),(3,4)
|
|
|
|
union
|
|
|
|
values (1,2)
|
|
|
|
intersect
|
|
|
|
values (1,2);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
# combination of different structures that uses VALUES structures : UNION ALL + INTERSECT
|
|
|
|
values (1,2),(3,4)
|
|
|
|
intersect
|
|
|
|
select 1,2
|
|
|
|
union all
|
|
|
|
values (1,2);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
1 2
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2),(3,4)
|
|
|
|
intersect
|
|
|
|
values (1,2)
|
|
|
|
union all
|
|
|
|
values (1,2);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
1 2
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2),(3,4)
|
|
|
|
intersect
|
|
|
|
values (1,2)
|
|
|
|
union all
|
|
|
|
values (3,4);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2),(3,4)
|
|
|
|
union all
|
|
|
|
values (1,2)
|
|
|
|
intersect
|
|
|
|
values (1,2);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
1 2
|
2017-08-29 02:32:39 +02:00
|
|
|
# combination of different structures that uses VALUES structures : UNION + UNION ALL
|
|
|
|
values (1,2),(3,4)
|
|
|
|
union all
|
|
|
|
select 1,2
|
|
|
|
union
|
|
|
|
values (1,2);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2),(3,4)
|
|
|
|
union all
|
|
|
|
values (1,2)
|
|
|
|
union
|
|
|
|
values (1,2);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2),(3,4)
|
|
|
|
union all
|
|
|
|
values (1,2)
|
|
|
|
union
|
|
|
|
values (3,4);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2),(3,4)
|
|
|
|
union
|
|
|
|
values (1,2)
|
|
|
|
union all
|
|
|
|
values (1,2);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
1 2
|
2017-08-29 02:32:39 +02:00
|
|
|
values (1,2)
|
|
|
|
union
|
|
|
|
values (1,2)
|
|
|
|
union all
|
|
|
|
values (1,2);
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
1 2
|
2017-08-29 02:32:39 +02:00
|
|
|
# CTE that uses VALUES structure(s) : non-recursive CTE
|
|
|
|
with t2 as
|
|
|
|
(
|
|
|
|
values (1,2),(3,4)
|
|
|
|
)
|
|
|
|
select * from t2;
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
with t2 as
|
|
|
|
(
|
|
|
|
select 1,2
|
|
|
|
union
|
|
|
|
values (1,2)
|
|
|
|
)
|
|
|
|
select * from t2;
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
2017-08-29 02:32:39 +02:00
|
|
|
with t2 as
|
|
|
|
(
|
|
|
|
select 1,2
|
|
|
|
union
|
|
|
|
values (1,2),(3,4)
|
|
|
|
)
|
|
|
|
select * from t2;
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
with t2 as
|
|
|
|
(
|
|
|
|
values (1,2)
|
|
|
|
union
|
|
|
|
select 1,2
|
|
|
|
)
|
|
|
|
select * from t2;
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
2017-08-29 02:32:39 +02:00
|
|
|
with t2 as
|
|
|
|
(
|
|
|
|
values (1,2),(3,4)
|
|
|
|
union
|
|
|
|
select 1,2
|
|
|
|
)
|
|
|
|
select * from t2;
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
with t2 as
|
|
|
|
(
|
|
|
|
values (5,6)
|
|
|
|
union
|
|
|
|
values (1,2),(3,4)
|
|
|
|
)
|
|
|
|
select * from t2;
|
2017-07-26 21:46:16 +02:00
|
|
|
5 6
|
|
|
|
5 6
|
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
with t2 as
|
|
|
|
(
|
|
|
|
values (1,2)
|
|
|
|
union
|
|
|
|
values (1,2),(3,4)
|
|
|
|
)
|
|
|
|
select * from t2;
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
with t2 as
|
|
|
|
(
|
|
|
|
select 1,2
|
|
|
|
union all
|
|
|
|
values (1,2),(3,4)
|
|
|
|
)
|
|
|
|
select * from t2;
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
with t2 as
|
|
|
|
(
|
|
|
|
values (1,2),(3,4)
|
|
|
|
union all
|
|
|
|
select 1,2
|
|
|
|
)
|
|
|
|
select * from t2;
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
1 2
|
2017-08-29 02:32:39 +02:00
|
|
|
with t2 as
|
|
|
|
(
|
|
|
|
values (1,2)
|
|
|
|
union all
|
|
|
|
values (1,2),(3,4)
|
|
|
|
)
|
|
|
|
select * from t2;
|
2017-07-26 21:46:16 +02:00
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
# recursive CTE that uses VALUES structure(s) : singe VALUES structure as anchor
|
|
|
|
with recursive t2(a,b) as
|
|
|
|
(
|
|
|
|
values(1,1)
|
|
|
|
union
|
|
|
|
select t1.a, t1.b
|
|
|
|
from t1,t2
|
|
|
|
where t1.a=t2.a
|
|
|
|
)
|
|
|
|
select * from t2;
|
|
|
|
a b
|
|
|
|
1 1
|
|
|
|
1 2
|
|
|
|
with recursive t2(a,b) as
|
|
|
|
(
|
|
|
|
values(1,1)
|
|
|
|
union
|
|
|
|
select t1.a+1, t1.b
|
|
|
|
from t1,t2
|
|
|
|
where t1.a=t2.a
|
|
|
|
)
|
|
|
|
select * from t2;
|
|
|
|
a b
|
|
|
|
1 1
|
|
|
|
2 2
|
|
|
|
2 1
|
|
|
|
3 5
|
|
|
|
# recursive CTE that uses VALUES structure(s) : several VALUES structures as anchors
|
|
|
|
with recursive t2(a,b) as
|
|
|
|
(
|
|
|
|
values(1,1)
|
|
|
|
union
|
|
|
|
values (3,4)
|
|
|
|
union
|
|
|
|
select t2.a+1, t1.b
|
|
|
|
from t1,t2
|
|
|
|
where t1.a=t2.a
|
|
|
|
)
|
|
|
|
select * from t2;
|
|
|
|
a b
|
|
|
|
1 1
|
|
|
|
3 4
|
|
|
|
2 2
|
|
|
|
2 1
|
|
|
|
3 5
|
|
|
|
# recursive CTE that uses VALUES structure(s) : that uses UNION ALL
|
|
|
|
with recursive t2(a,b,st) as
|
|
|
|
(
|
|
|
|
values(1,1,1)
|
|
|
|
union all
|
|
|
|
select t2.a, t1.b, t2.st+1
|
|
|
|
from t1,t2
|
|
|
|
where t1.a=t2.a and st<3
|
|
|
|
)
|
|
|
|
select * from t2;
|
|
|
|
a b st
|
|
|
|
1 1 1
|
|
|
|
1 2 2
|
|
|
|
1 1 2
|
|
|
|
1 2 3
|
|
|
|
1 2 3
|
|
|
|
1 1 3
|
|
|
|
1 1 3
|
|
|
|
# recursive CTE that uses VALUES structure(s) : computation of factorial (first 10 elements)
|
|
|
|
with recursive fact(n,f) as
|
|
|
|
(
|
|
|
|
values(1,1)
|
|
|
|
union
|
|
|
|
select n+1,f*n from fact where n < 10
|
|
|
|
)
|
|
|
|
select * from fact;
|
|
|
|
n f
|
|
|
|
1 1
|
|
|
|
2 1
|
|
|
|
3 2
|
|
|
|
4 6
|
|
|
|
5 24
|
|
|
|
6 120
|
|
|
|
7 720
|
|
|
|
8 5040
|
|
|
|
9 40320
|
|
|
|
10 362880
|
|
|
|
# Derived table that uses VALUES structure(s) : singe VALUES structure
|
2017-07-26 21:46:16 +02:00
|
|
|
select * from (values (1,2),(3,4)) as t2;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
# Derived table that uses VALUES structure(s) : UNION with VALUES structure(s)
|
2017-07-26 21:46:16 +02:00
|
|
|
select * from (select 1,2 union values (1,2)) as t2;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
select * from (select 1,2 union values (1,2),(3,4)) as t2;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
select * from (values (1,2) union select 1,2) as t2;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
select * from (values (1,2),(3,4) union select 1,2) as t2;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
select * from (values (5,6) union values (1,2),(3,4)) as t2;
|
|
|
|
5 6
|
|
|
|
5 6
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
select * from (values (1,2) union values (1,2),(3,4)) as t2;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
# Derived table that uses VALUES structure(s) : UNION ALL with VALUES structure(s)
|
2017-07-26 21:46:16 +02:00
|
|
|
select * from (select 1,2 union all values (1,2),(3,4)) as t2;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
select * from (values (1,2),(3,4) union all select 1,2) as t2;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
1 2
|
|
|
|
select * from (values (1,2) union all values (1,2),(3,4)) as t2;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
2017-08-29 02:32:39 +02:00
|
|
|
# CREATE VIEW that uses VALUES structure(s) : singe VALUES structure
|
2017-07-26 21:46:16 +02:00
|
|
|
create view v1 as values (1,2),(3,4);
|
|
|
|
select * from v1;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
drop view v1;
|
2017-08-29 02:32:39 +02:00
|
|
|
# CREATE VIEW that uses VALUES structure(s) : UNION with VALUES structure(s)
|
|
|
|
create view v1 as
|
|
|
|
select 1,2
|
|
|
|
union
|
|
|
|
values (1,2);
|
2017-07-26 21:46:16 +02:00
|
|
|
select * from v1;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
drop view v1;
|
2017-08-29 02:32:39 +02:00
|
|
|
create view v1 as
|
|
|
|
select 1,2
|
|
|
|
union
|
|
|
|
values (1,2),(3,4);
|
2017-07-26 21:46:16 +02:00
|
|
|
select * from v1;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
drop view v1;
|
2017-08-29 02:32:39 +02:00
|
|
|
create view v1 as
|
|
|
|
values (1,2)
|
|
|
|
union
|
|
|
|
select 1,2;
|
2017-07-26 21:46:16 +02:00
|
|
|
select * from v1;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
drop view v1;
|
2017-08-29 02:32:39 +02:00
|
|
|
create view v1 as
|
|
|
|
values (1,2),(3,4)
|
|
|
|
union
|
|
|
|
select 1,2;
|
2017-07-26 21:46:16 +02:00
|
|
|
select * from v1;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
drop view v1;
|
2017-08-29 02:32:39 +02:00
|
|
|
create view v1 as
|
|
|
|
values (5,6)
|
|
|
|
union
|
|
|
|
values (1,2),(3,4);
|
2017-07-26 21:46:16 +02:00
|
|
|
select * from v1;
|
|
|
|
5 6
|
|
|
|
5 6
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
drop view v1;
|
2017-08-29 02:32:39 +02:00
|
|
|
# CREATE VIEW that uses VALUES structure(s) : UNION ALL with VALUES structure(s)
|
|
|
|
create view v1 as
|
|
|
|
values (1,2)
|
|
|
|
union
|
|
|
|
values (1,2),(3,4);
|
2017-07-26 21:46:16 +02:00
|
|
|
select * from v1;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
drop view v1;
|
2017-08-29 02:32:39 +02:00
|
|
|
create view v1 as
|
|
|
|
select 1,2
|
|
|
|
union all
|
|
|
|
values (1,2),(3,4);
|
2017-07-26 21:46:16 +02:00
|
|
|
select * from v1;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
drop view v1;
|
2017-08-29 02:32:39 +02:00
|
|
|
create view v1 as
|
|
|
|
values (1,2),(3,4)
|
|
|
|
union all
|
|
|
|
select 1,2;
|
2017-07-26 21:46:16 +02:00
|
|
|
select * from v1;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
1 2
|
|
|
|
drop view v1;
|
2017-08-29 02:32:39 +02:00
|
|
|
create view v1 as
|
|
|
|
values (1,2)
|
|
|
|
union all
|
|
|
|
values (1,2),(3,4);
|
2017-07-26 21:46:16 +02:00
|
|
|
select * from v1;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
drop view v1;
|
2017-08-29 02:32:39 +02:00
|
|
|
# prepare statement that uses VALUES structure(s): single VALUES structure
|
|
|
|
prepare stmt1 from "
|
|
|
|
values (1,2);
|
|
|
|
";
|
|
|
|
execute stmt1;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
execute stmt1;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
deallocate prepare stmt1;
|
|
|
|
# prepare statement that uses VALUES structure(s): UNION with VALUES structure(s)
|
|
|
|
prepare stmt1 from "
|
|
|
|
select 1,2
|
|
|
|
union
|
|
|
|
values (1,2),(3,4);
|
|
|
|
";
|
|
|
|
execute stmt1;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
execute stmt1;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
deallocate prepare stmt1;
|
|
|
|
prepare stmt1 from "
|
|
|
|
values (1,2),(3,4)
|
|
|
|
union
|
|
|
|
select 1,2;
|
|
|
|
";
|
|
|
|
execute stmt1;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
execute stmt1;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
deallocate prepare stmt1;
|
|
|
|
prepare stmt1 from "
|
|
|
|
select 1,2
|
|
|
|
union
|
|
|
|
values (3,4)
|
|
|
|
union
|
|
|
|
values (1,2);
|
|
|
|
";
|
|
|
|
execute stmt1;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
execute stmt1;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
deallocate prepare stmt1;
|
|
|
|
prepare stmt1 from "
|
|
|
|
values (5,6)
|
|
|
|
union
|
|
|
|
values (1,2),(3,4);
|
|
|
|
";
|
|
|
|
execute stmt1;
|
|
|
|
5 6
|
|
|
|
5 6
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
execute stmt1;
|
|
|
|
5 6
|
|
|
|
5 6
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
deallocate prepare stmt1;
|
|
|
|
# prepare statement that uses VALUES structure(s): UNION ALL with VALUES structure(s)
|
|
|
|
prepare stmt1 from "
|
|
|
|
select 1,2
|
|
|
|
union
|
|
|
|
values (1,2),(3,4);
|
|
|
|
";
|
|
|
|
execute stmt1;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
execute stmt1;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
deallocate prepare stmt1;
|
|
|
|
prepare stmt1 from "
|
|
|
|
values (1,2),(3,4)
|
|
|
|
union all
|
|
|
|
select 1,2;
|
|
|
|
";
|
|
|
|
execute stmt1;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
1 2
|
|
|
|
execute stmt1;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
1 2
|
|
|
|
deallocate prepare stmt1;
|
|
|
|
prepare stmt1 from "
|
|
|
|
select 1,2
|
|
|
|
union all
|
|
|
|
values (3,4)
|
|
|
|
union all
|
|
|
|
values (1,2);
|
|
|
|
";
|
|
|
|
execute stmt1;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
1 2
|
|
|
|
execute stmt1;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
1 2
|
|
|
|
deallocate prepare stmt1;
|
|
|
|
prepare stmt1 from "
|
|
|
|
values (1,2)
|
|
|
|
union all
|
|
|
|
values (1,2),(3,4);
|
|
|
|
";
|
|
|
|
execute stmt1;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
execute stmt1;
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
1 2
|
|
|
|
3 4
|
|
|
|
deallocate prepare stmt1;
|
|
|
|
# explain query that uses VALUES structure(s): single VALUES structure
|
|
|
|
explain
|
|
|
|
values (1,2);
|
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
|
|
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
explain format=json
|
|
|
|
values (1,2);
|
|
|
|
EXPLAIN
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"union_result": {
|
|
|
|
"table_name": "<unit1>",
|
|
|
|
"access_type": "ALL",
|
|
|
|
"query_specifications": [
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 1,
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# explain query that uses VALUES structure(s): UNION with VALUES structure(s)
|
|
|
|
explain
|
|
|
|
select 1,2
|
|
|
|
union
|
|
|
|
values (1,2),(3,4);
|
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
|
|
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
2 UNION NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL
|
|
|
|
explain
|
|
|
|
values (1,2),(3,4)
|
|
|
|
union
|
|
|
|
select 1,2;
|
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
|
|
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
2 UNION NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL
|
|
|
|
explain
|
|
|
|
values (5,6)
|
|
|
|
union
|
|
|
|
values (1,2),(3,4);
|
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
|
|
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
2 UNION NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL
|
|
|
|
explain format=json
|
|
|
|
select 1,2
|
|
|
|
union
|
|
|
|
values (1,2),(3,4);
|
|
|
|
EXPLAIN
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"union_result": {
|
|
|
|
"table_name": "<union1,2>",
|
|
|
|
"access_type": "ALL",
|
|
|
|
"query_specifications": [
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 1,
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 2,
|
|
|
|
"operation": "UNION",
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
explain format=json
|
|
|
|
values (1,2),(3,4)
|
|
|
|
union
|
|
|
|
select 1,2;
|
|
|
|
EXPLAIN
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"union_result": {
|
|
|
|
"table_name": "<union1,2>",
|
|
|
|
"access_type": "ALL",
|
|
|
|
"query_specifications": [
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 1,
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 2,
|
|
|
|
"operation": "UNION",
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
explain format=json
|
|
|
|
values (5,6)
|
|
|
|
union
|
|
|
|
values (1,2),(3,4);
|
|
|
|
EXPLAIN
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"union_result": {
|
|
|
|
"table_name": "<union1,2>",
|
|
|
|
"access_type": "ALL",
|
|
|
|
"query_specifications": [
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 1,
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 2,
|
|
|
|
"operation": "UNION",
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
explain
|
|
|
|
select 1,2
|
|
|
|
union
|
|
|
|
values (3,4)
|
|
|
|
union
|
|
|
|
values (1,2);
|
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
|
|
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
2 UNION NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
3 UNION NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
NULL UNION RESULT <union1,2,3> ALL NULL NULL NULL NULL NULL
|
|
|
|
explain format=json
|
|
|
|
select 1,2
|
|
|
|
union
|
|
|
|
values (3,4)
|
|
|
|
union
|
|
|
|
values (1,2);
|
|
|
|
EXPLAIN
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"union_result": {
|
|
|
|
"table_name": "<union1,2,3>",
|
|
|
|
"access_type": "ALL",
|
|
|
|
"query_specifications": [
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 1,
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 2,
|
|
|
|
"operation": "UNION",
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 3,
|
|
|
|
"operation": "UNION",
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# explain query that uses VALUES structure(s): UNION ALL with VALUES structure(s)
|
|
|
|
explain
|
|
|
|
select 1,2
|
|
|
|
union
|
|
|
|
values (1,2),(3,4);
|
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
|
|
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
2 UNION NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL
|
|
|
|
explain
|
|
|
|
values (1,2),(3,4)
|
|
|
|
union all
|
|
|
|
select 1,2;
|
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
|
|
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
2 UNION NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
explain
|
|
|
|
values (1,2)
|
|
|
|
union all
|
|
|
|
values (1,2),(3,4);
|
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
|
|
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
2 UNION NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
explain format=json
|
|
|
|
values (1,2),(3,4)
|
|
|
|
union all
|
|
|
|
select 1,2;
|
|
|
|
EXPLAIN
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"union_result": {
|
|
|
|
"table_name": "<union1,2>",
|
|
|
|
"access_type": "ALL",
|
|
|
|
"query_specifications": [
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 1,
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 2,
|
|
|
|
"operation": "UNION",
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
explain format=json
|
|
|
|
select 1,2
|
|
|
|
union
|
|
|
|
values (1,2),(3,4);
|
|
|
|
EXPLAIN
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"union_result": {
|
|
|
|
"table_name": "<union1,2>",
|
|
|
|
"access_type": "ALL",
|
|
|
|
"query_specifications": [
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 1,
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 2,
|
|
|
|
"operation": "UNION",
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
explain format=json
|
|
|
|
values (1,2)
|
|
|
|
union all
|
|
|
|
values (1,2),(3,4);
|
|
|
|
EXPLAIN
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"union_result": {
|
|
|
|
"table_name": "<union1,2>",
|
|
|
|
"access_type": "ALL",
|
|
|
|
"query_specifications": [
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 1,
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 2,
|
|
|
|
"operation": "UNION",
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
explain
|
|
|
|
select 1,2
|
|
|
|
union all
|
|
|
|
values (3,4)
|
|
|
|
union all
|
|
|
|
values (1,2);
|
|
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
|
|
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
2 UNION NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
3 UNION NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
explain format=json
|
|
|
|
select 1,2
|
|
|
|
union all
|
|
|
|
values (3,4)
|
|
|
|
union all
|
|
|
|
values (1,2);
|
|
|
|
EXPLAIN
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"union_result": {
|
|
|
|
"table_name": "<union1,2,3>",
|
|
|
|
"access_type": "ALL",
|
|
|
|
"query_specifications": [
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 1,
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 2,
|
|
|
|
"operation": "UNION",
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 3,
|
|
|
|
"operation": "UNION",
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# analyze query that uses VALUES structure(s): single VALUES structure
|
|
|
|
analyze
|
|
|
|
values (1,2);
|
|
|
|
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
|
|
|
|
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
analyze format=json
|
|
|
|
values (1,2);
|
|
|
|
ANALYZE
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"union_result": {
|
|
|
|
"table_name": "<unit1>",
|
|
|
|
"access_type": "ALL",
|
|
|
|
"r_loops": 0,
|
|
|
|
"r_rows": null,
|
|
|
|
"query_specifications": [
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 1,
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# analyze query that uses VALUES structure(s): UNION with VALUES structure(s)
|
|
|
|
analyze
|
|
|
|
select 1,2
|
|
|
|
union
|
|
|
|
values (1,2),(3,4);
|
|
|
|
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
|
|
|
|
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
2 UNION NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL 2.00 NULL NULL
|
|
|
|
analyze
|
|
|
|
values (1,2),(3,4)
|
|
|
|
union
|
|
|
|
select 1,2;
|
|
|
|
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
|
|
|
|
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
2 UNION NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL 2.00 NULL NULL
|
|
|
|
analyze
|
|
|
|
values (5,6)
|
|
|
|
union
|
|
|
|
values (1,2),(3,4);
|
|
|
|
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
|
|
|
|
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
2 UNION NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL 3.00 NULL NULL
|
|
|
|
analyze format=json
|
|
|
|
select 1,2
|
|
|
|
union
|
|
|
|
values (1,2),(3,4);
|
|
|
|
ANALYZE
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"union_result": {
|
|
|
|
"table_name": "<union1,2>",
|
|
|
|
"access_type": "ALL",
|
|
|
|
"r_loops": 1,
|
|
|
|
"r_rows": 2,
|
|
|
|
"query_specifications": [
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 1,
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 2,
|
|
|
|
"operation": "UNION",
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
analyze format=json
|
|
|
|
values (1,2),(3,4)
|
|
|
|
union
|
|
|
|
select 1,2;
|
|
|
|
ANALYZE
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"union_result": {
|
|
|
|
"table_name": "<union1,2>",
|
|
|
|
"access_type": "ALL",
|
|
|
|
"r_loops": 1,
|
|
|
|
"r_rows": 2,
|
|
|
|
"query_specifications": [
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 1,
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 2,
|
|
|
|
"operation": "UNION",
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
analyze format=json
|
|
|
|
values (5,6)
|
|
|
|
union
|
|
|
|
values (1,2),(3,4);
|
|
|
|
ANALYZE
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"union_result": {
|
|
|
|
"table_name": "<union1,2>",
|
|
|
|
"access_type": "ALL",
|
|
|
|
"r_loops": 1,
|
|
|
|
"r_rows": 3,
|
|
|
|
"query_specifications": [
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 1,
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 2,
|
|
|
|
"operation": "UNION",
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
analyze
|
|
|
|
select 1,2
|
|
|
|
union
|
|
|
|
values (3,4)
|
|
|
|
union
|
|
|
|
values (1,2);
|
|
|
|
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
|
|
|
|
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
2 UNION NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
3 UNION NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
NULL UNION RESULT <union1,2,3> ALL NULL NULL NULL NULL NULL 2.00 NULL NULL
|
|
|
|
analyze format=json
|
|
|
|
select 1,2
|
|
|
|
union
|
|
|
|
values (3,4)
|
|
|
|
union
|
|
|
|
values (1,2);
|
|
|
|
ANALYZE
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"union_result": {
|
|
|
|
"table_name": "<union1,2,3>",
|
|
|
|
"access_type": "ALL",
|
|
|
|
"r_loops": 1,
|
|
|
|
"r_rows": 2,
|
|
|
|
"query_specifications": [
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 1,
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 2,
|
|
|
|
"operation": "UNION",
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 3,
|
|
|
|
"operation": "UNION",
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# analyze query that uses VALUES structure(s): UNION ALL with VALUES structure(s)
|
|
|
|
analyze
|
|
|
|
select 1,2
|
|
|
|
union
|
|
|
|
values (1,2),(3,4);
|
|
|
|
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
|
|
|
|
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
2 UNION NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL 2.00 NULL NULL
|
|
|
|
analyze
|
|
|
|
values (1,2),(3,4)
|
|
|
|
union all
|
|
|
|
select 1,2;
|
|
|
|
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
|
|
|
|
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
2 UNION NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
analyze
|
|
|
|
values (1,2)
|
|
|
|
union all
|
|
|
|
values (1,2),(3,4);
|
|
|
|
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
|
|
|
|
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
2 UNION NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
analyze format=json
|
|
|
|
values (1,2),(3,4)
|
|
|
|
union all
|
|
|
|
select 1,2;
|
|
|
|
ANALYZE
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"union_result": {
|
|
|
|
"table_name": "<union1,2>",
|
|
|
|
"access_type": "ALL",
|
|
|
|
"r_loops": 0,
|
|
|
|
"r_rows": null,
|
|
|
|
"query_specifications": [
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 1,
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 2,
|
|
|
|
"operation": "UNION",
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
analyze format=json
|
|
|
|
select 1,2
|
|
|
|
union
|
|
|
|
values (1,2),(3,4);
|
|
|
|
ANALYZE
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"union_result": {
|
|
|
|
"table_name": "<union1,2>",
|
|
|
|
"access_type": "ALL",
|
|
|
|
"r_loops": 1,
|
|
|
|
"r_rows": 2,
|
|
|
|
"query_specifications": [
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 1,
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 2,
|
|
|
|
"operation": "UNION",
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
analyze format=json
|
|
|
|
values (1,2)
|
|
|
|
union all
|
|
|
|
values (1,2),(3,4);
|
|
|
|
ANALYZE
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"union_result": {
|
|
|
|
"table_name": "<union1,2>",
|
|
|
|
"access_type": "ALL",
|
|
|
|
"r_loops": 0,
|
|
|
|
"r_rows": null,
|
|
|
|
"query_specifications": [
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 1,
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 2,
|
|
|
|
"operation": "UNION",
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
analyze
|
|
|
|
select 1,2
|
|
|
|
union all
|
|
|
|
values (3,4)
|
|
|
|
union all
|
|
|
|
values (1,2);
|
|
|
|
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
|
|
|
|
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
2 UNION NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
3 UNION NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used
|
|
|
|
analyze format=json
|
|
|
|
select 1,2
|
|
|
|
union all
|
|
|
|
values (3,4)
|
|
|
|
union all
|
|
|
|
values (1,2);
|
|
|
|
ANALYZE
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"union_result": {
|
|
|
|
"table_name": "<union1,2,3>",
|
|
|
|
"access_type": "ALL",
|
|
|
|
"r_loops": 0,
|
|
|
|
"r_rows": null,
|
|
|
|
"query_specifications": [
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 1,
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 2,
|
|
|
|
"operation": "UNION",
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"query_block": {
|
|
|
|
"select_id": 3,
|
|
|
|
"operation": "UNION",
|
|
|
|
"table": {
|
|
|
|
"message": "No tables used"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-26 21:46:16 +02:00
|
|
|
drop table t1;
|