return syntax error when order by or limit before union in mysql mode
This commit is contained in:
parent
bf0272041a
commit
6d8fedae8b
@ -8363,14 +8363,6 @@ select_clause_set set_type select_clause_set_right
|
||||
select_node->children_[PARSE_SELECT_LATER] = $3;
|
||||
$$ = select_node;
|
||||
}
|
||||
| select_clause_set_with_order_and_limit set_type select_clause_set_right {
|
||||
ParseNode *select_node = NULL;
|
||||
malloc_select_node(select_node, result->malloc_pool_);
|
||||
select_node->children_[PARSE_SELECT_SET] = $2;
|
||||
select_node->children_[PARSE_SELECT_FORMER] = $1;
|
||||
select_node->children_[PARSE_SELECT_LATER] = $3;
|
||||
$$ = select_node;
|
||||
}
|
||||
| select_clause_set_left set_type select_clause_set_right {
|
||||
ParseNode *select_node = NULL;
|
||||
malloc_select_node(select_node, result->malloc_pool_);
|
||||
@ -8401,15 +8393,7 @@ no_table_select
|
||||
;
|
||||
|
||||
select_clause_set_left:
|
||||
no_table_select_with_order_and_limit
|
||||
{
|
||||
$$ = $1;
|
||||
}
|
||||
| simple_select_with_order_and_limit
|
||||
{
|
||||
$$ = $1;
|
||||
}
|
||||
| select_clause_set_right
|
||||
select_clause_set_right
|
||||
{
|
||||
$$ = $1;
|
||||
}
|
||||
|
@ -1735,7 +1735,7 @@ CREATE TABLE T1 (PK INT PRIMARY KEY, C1 INT, C2 INT);
|
||||
CREATE TABLE T2 (PK INT PRIMARY KEY, C1 INT, C2 INT);
|
||||
CREATE TABLE T3 (PK INT PRIMARY KEY, C1 INT, C2 INT);
|
||||
|
||||
EXPLAIN SELECT C1, C2, PK FROM T1 ORDER BY PK DESC LIMIT 1 UNION (SELECT C1, C2, PK FROM T2 UNION SELECT C1, C2 ,PK FROM T3);
|
||||
EXPLAIN (SELECT C1, C2, PK FROM T1 ORDER BY PK DESC LIMIT 1) UNION (SELECT C1, C2, PK FROM T2 UNION SELECT C1, C2 ,PK FROM T3);
|
||||
Query Plan
|
||||
==========================================================
|
||||
|ID|OPERATOR |NAME |EST.ROWS|EST.TIME(us)|
|
||||
@ -1763,7 +1763,7 @@ Outputs & filters:
|
||||
access([t3.PK], [t3.C1], [t3.C2]), partitions(p0)
|
||||
is_index_back=false, is_global_index=false,
|
||||
range_key([t3.PK]), range(MIN ; MAX)always true
|
||||
SELECT C1, C2, PK FROM T1 ORDER BY PK DESC LIMIT 1 UNION (SELECT C1, C2, PK FROM T2 UNION SELECT C1, C2 ,PK FROM T3);
|
||||
(SELECT C1, C2, PK FROM T1 ORDER BY PK DESC LIMIT 1) UNION (SELECT C1, C2, PK FROM T2 UNION SELECT C1, C2 ,PK FROM T3);
|
||||
+------+------+----+
|
||||
| C1 | C2 | PK |
|
||||
+------+------+----+
|
||||
|
@ -227,7 +227,8 @@ INSERT/**/ INTO T3 VALUES (1, 1, 1);
|
||||
INSERT/**/ INTO T3 VALUES (2, 1, 1);
|
||||
--enable_query_log
|
||||
|
||||
SELECT C1, C2, PK FROM T1 ORDER BY PK DESC LIMIT 1 UNION (SELECT C1, C2, PK FROM T2 UNION SELECT C1, C2 ,PK FROM T3);
|
||||
EXPLAIN (SELECT C1, C2, PK FROM T1 ORDER BY PK DESC LIMIT 1) UNION (SELECT C1, C2, PK FROM T2 UNION SELECT C1, C2 ,PK FROM T3);
|
||||
(SELECT C1, C2, PK FROM T1 ORDER BY PK DESC LIMIT 1) UNION (SELECT C1, C2, PK FROM T2 UNION SELECT C1, C2 ,PK FROM T3);
|
||||
|
||||
CREATE TABLE table2_bigint (
|
||||
col_decimal_20_0_signed decimal(20,0) signed,
|
||||
|
@ -956,7 +956,7 @@ Outputs & filters:
|
||||
access([t2.x], [t2.y], [t2.z]), partitions(p0)
|
||||
is_index_back=false, is_global_index=false,
|
||||
range_key([t2.x], [t2.y], [t2.z], [t2.pk2]), range(MIN,MIN,MIN,MIN ; MAX,MAX,MAX,MAX)always true
|
||||
explain select a, b, c from t1 order by c, b, a union select x, y, z from t2;
|
||||
explain (select a, b, c from t1 order by c, b, a )union select x, y, z from t2;
|
||||
Query Plan
|
||||
=============================================================
|
||||
|ID|OPERATOR |NAME |EST.ROWS|EST.TIME(us)|
|
||||
@ -2707,7 +2707,7 @@ Outputs & filters:
|
||||
is_index_back=false, is_global_index=false,
|
||||
range_key([t6.b], [t6.a], [t6.c], [t6.pk]), range(1,2,MAX,MAX ; 1,MAX,MAX,MAX),
|
||||
range_cond([t6.b = 1], [t6.a > 2])
|
||||
explain select c from t6 where b = 1 limit 9 union select pk from tmp;
|
||||
explain (select c from t6 where b = 1 limit 9) union select pk from tmp;
|
||||
Query Plan
|
||||
===========================================================
|
||||
|ID|OPERATOR |NAME |EST.ROWS|EST.TIME(us)|
|
||||
@ -2728,7 +2728,7 @@ Outputs & filters:
|
||||
access([tmp.pk]), partitions(p0)
|
||||
is_index_back=false, is_global_index=false,
|
||||
range_key([tmp.pk]), range(MIN ; MAX)always true
|
||||
explain select /*+index(t6 idx_b_c)*/ c from t6 where b = 1 limit 9 union select pk from tmp;
|
||||
explain (select /*+index(t6 idx_b_c)*/ c from t6 where b = 1 limit 9) union select pk from tmp;
|
||||
Query Plan
|
||||
===========================================================
|
||||
|ID|OPERATOR |NAME |EST.ROWS|EST.TIME(us)|
|
||||
@ -2749,7 +2749,7 @@ Outputs & filters:
|
||||
access([tmp.pk]), partitions(p0)
|
||||
is_index_back=false, is_global_index=false,
|
||||
range_key([tmp.pk]), range(MIN ; MAX)always true
|
||||
explain select /*+index(t6 idx_b_a_c)*/ c from t6 where b = 1 limit 9 union select pk from tmp;
|
||||
explain (select /*+index(t6 idx_b_a_c)*/ c from t6 where b = 1 limit 9) union select pk from tmp;
|
||||
Query Plan
|
||||
=============================================================
|
||||
|ID|OPERATOR |NAME |EST.ROWS|EST.TIME(us)|
|
||||
|
@ -1467,7 +1467,7 @@ Outputs & filters:
|
||||
access([other.c2], [other.c3]), partitions(p0)
|
||||
is_index_back=false, is_global_index=false,
|
||||
range_key([other.c2], [other.c3], [other.c1]), range(MIN,MIN,MIN ; MAX,MAX,MAX)always true
|
||||
explain select v3, v4 from skyline_int order by v3, v4 union select distinct c2, c3 from other order by v3, v4;
|
||||
explain (select v3, v4 from skyline_int order by v3, v4) union select distinct c2, c3 from other order by v3, v4;
|
||||
Query Plan
|
||||
=========================================================================
|
||||
|ID|OPERATOR |NAME |EST.ROWS|EST.TIME(us)|
|
||||
|
@ -150,7 +150,7 @@ explain select a, b, c from t2 left join t1 on t1.b = t2.x order by b, c;
|
||||
|
||||
##set
|
||||
explain select a, b, c from t1 union select x, y, z from t2;
|
||||
explain select a, b, c from t1 order by c, b, a union select x, y, z from t2;
|
||||
explain (select a, b, c from t1 order by c, b, a )union select x, y, z from t2;
|
||||
explain select b, c, a from t1 where b > 100 union select x, y, z from t2 where x > 100;
|
||||
explain select b, c, a from t1 where b > 100 and b < 200 union select x, y, z from t2 where x > 100 and x < 200;
|
||||
|
||||
@ -296,9 +296,9 @@ explain select /*+index(t6 idx_b_e_d_c_a)*/ distinct b, d, a from t6 where e =
|
||||
explain select distinct c from t6 where b = 1 and a > 2;
|
||||
|
||||
## union
|
||||
explain select c from t6 where b = 1 limit 9 union select pk from tmp;
|
||||
explain select /*+index(t6 idx_b_c)*/ c from t6 where b = 1 limit 9 union select pk from tmp;
|
||||
explain select /*+index(t6 idx_b_a_c)*/ c from t6 where b = 1 limit 9 union select pk from tmp;
|
||||
explain (select c from t6 where b = 1 limit 9) union select pk from tmp;
|
||||
explain (select /*+index(t6 idx_b_c)*/ c from t6 where b = 1 limit 9) union select pk from tmp;
|
||||
explain (select /*+index(t6 idx_b_a_c)*/ c from t6 where b = 1 limit 9) union select pk from tmp;
|
||||
|
||||
explain select b, c from t6 where a = 1 union select c1, c2 from tmp;
|
||||
explain select /*+index(t6 idx_b_c)*/ b, c from t6 where a = 1 union select c1, c2 from tmp;
|
||||
|
@ -199,7 +199,7 @@ explain select distinct v3, v4, v5 from skyline_int order by v3, v4, v5, v6;
|
||||
explain select distinct v3, v4 from skyline_int union select distinct c2, c3 from other;
|
||||
|
||||
## order by会消除或者能被union所用
|
||||
explain select v3, v4 from skyline_int order by v3, v4 union select distinct c2, c3 from other order by v3, v4;
|
||||
explain (select v3, v4 from skyline_int order by v3, v4) union select distinct c2, c3 from other order by v3, v4;
|
||||
explain (select v3, v4 from skyline_int order by v3, v4) union (select distinct c2, c3 from other order by c2, c3) order by 1,2;
|
||||
|
||||
## 强制走 nestloop,保左表的序,group by的序能被用
|
||||
|
@ -1820,7 +1820,7 @@ select c,d from cte2;
|
||||
+------+------+
|
||||
|
||||
with RECURSIVE
|
||||
cte2(c,d) AS (select c1, c2 + 1 as c3 from t1 order by c2 union all select c+1, d+1 from cte2 where c < 30)
|
||||
cte2(c,d) AS ((select c1, c2 + 1 as c3 from t1 order by c2) union all select c+1, d+1 from cte2 where c < 30)
|
||||
select c,d from cte2;
|
||||
+------+------+
|
||||
| c | d |
|
||||
@ -1828,12 +1828,12 @@ select c,d from cte2;
|
||||
+------+------+
|
||||
|
||||
explain basic with RECURSIVE
|
||||
cte2(c,d) AS (select * from t1 left join t2 on t1.c1=t2.c1 order by t1.c1 union all select c+1, d+1 from cte2 where c < 30)
|
||||
cte2(c,d) AS ((select * from t1 left join t2 on t1.c1=t2.c1 order by t1.c1) union all select c+1, d+1 from cte2 where c < 30)
|
||||
select c1 from cte2;
|
||||
ERROR HY000: View's SELECT and view's field list have different column counts
|
||||
|
||||
with RECURSIVE
|
||||
cte2(c,d) AS (select t1.c1, t2.c2 from t1 left join t2 on t1.c1=t2.c1 order by t1.c1 union all select c+1, d+1 from cte2 where c < 30)
|
||||
cte2(c,d) AS ((select t1.c1, t2.c2 from t1 left join t2 on t1.c1=t2.c1 order by t1.c1) union all select c+1, d+1 from cte2 where c < 30)
|
||||
select c from cte2;
|
||||
+------+
|
||||
| c |
|
||||
|
@ -1197,7 +1197,7 @@ select c,d from cte2;
|
||||
|
||||
## 带有order
|
||||
with RECURSIVE
|
||||
cte2(c,d) AS ( select c1, c2 + 1 as c3 from t1 order by c2 union all select c+1, d+1 from cte2 where c < 30)
|
||||
cte2(c,d) AS ( (select c1, c2 + 1 as c3 from t1 order by c2) union all select c+1, d+1 from cte2 where c < 30)
|
||||
select c,d from cte2;
|
||||
+------+------+
|
||||
| c | d |
|
||||
@ -1352,7 +1352,7 @@ select c,d from cte2;
|
||||
+------+------+
|
||||
|
||||
with RECURSIVE
|
||||
cte2(c,d) AS (select t1.c1, t2.c2 from t1 left join t2 on t1.c1=t2.c1 order by t1.c1 union all select c+1, d+1 from cte2 where c < 30)
|
||||
cte2(c,d) AS ((select t1.c1, t2.c2 from t1 left join t2 on t1.c1=t2.c1 order by t1.c1) union all select c+1, d+1 from cte2 where c < 30)
|
||||
select c from cte2;
|
||||
+------+
|
||||
| c |
|
||||
|
@ -1150,16 +1150,16 @@ select c,d from cte2;
|
||||
|
||||
|
||||
with RECURSIVE
|
||||
cte2(c,d) AS (select c1, c2 + 1 as c3 from t1 order by c2 union all select c+1, d+1 from cte2 where c < 30)
|
||||
cte2(c,d) AS ((select c1, c2 + 1 as c3 from t1 order by c2) union all select c+1, d+1 from cte2 where c < 30)
|
||||
select c,d from cte2;
|
||||
|
||||
--error 1353
|
||||
explain basic with RECURSIVE
|
||||
cte2(c,d) AS (select * from t1 left join t2 on t1.c1=t2.c1 order by t1.c1 union all select c+1, d+1 from cte2 where c < 30)
|
||||
cte2(c,d) AS ((select * from t1 left join t2 on t1.c1=t2.c1 order by t1.c1) union all select c+1, d+1 from cte2 where c < 30)
|
||||
select c1 from cte2;
|
||||
|
||||
with RECURSIVE
|
||||
cte2(c,d) AS (select t1.c1, t2.c2 from t1 left join t2 on t1.c1=t2.c1 order by t1.c1 union all select c+1, d+1 from cte2 where c < 30)
|
||||
cte2(c,d) AS ((select t1.c1, t2.c2 from t1 left join t2 on t1.c1=t2.c1 order by t1.c1) union all select c+1, d+1 from cte2 where c < 30)
|
||||
select c from cte2;
|
||||
|
||||
|
||||
|
@ -290,11 +290,11 @@ select c,d from cte2;
|
||||
|
||||
## 带有order
|
||||
with RECURSIVE
|
||||
cte2(c,d) AS ( select c1, c2 + 1 as c3 from t1 order by c2 union all select c+1, d+1 from cte2 where c < 30)
|
||||
cte2(c,d) AS ( (select c1, c2 + 1 as c3 from t1 order by c2) union all select c+1, d+1 from cte2 where c < 30)
|
||||
select c,d from cte2;
|
||||
|
||||
with RECURSIVE
|
||||
cte2(c,d) AS (select t1.c1, t2.c2 from t1 left join t2 on t1.c1=t2.c1 order by t1.c1 union all select c+1, d+1 from cte2 where c < 30)
|
||||
cte2(c,d) AS ((select t1.c1, t2.c2 from t1 left join t2 on t1.c1=t2.c1 order by t1.c1) union all select c+1, d+1 from cte2 where c < 30)
|
||||
select c from cte2;
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user