Bugfix46540552:fix mapping bugs for cte error code

This commit is contained in:
obdev
2022-12-13 14:07:55 +00:00
committed by ob-robot
parent d1e99a65ab
commit 2c1b2f160d
14 changed files with 93 additions and 85 deletions

View File

@ -148,10 +148,10 @@ with cte(a,b) as (select 1,1 from dual) select * from cte;
+---+---+
with cte(a,b) as (select 1 from dual) select * from cte;
ERROR HY000: number of WITH clause column names does not match number of elements in select list
ERROR HY000: View's SELECT and view's field list have different column counts
with cte(a,b,c) as (select 1, 2, 3, 4 from dual) select * from cte;
ERROR HY000: number of WITH clause column names does not match number of elements in select list
ERROR HY000: View's SELECT and view's field list have different column counts
## PART 2.2.2 不使用定义列使用原来的列
with cte(a,b) as (select c1,c2 from t1) select c1 from cte;
@ -2251,7 +2251,7 @@ ERROR 23000: Column 'c21' in group statement is ambiguous
with
cte1 (c22, c21) AS (select * from t1)
select c22 as c21, c21 from cte1 group by c21;
ERROR HY000: number of WITH clause column names does not match number of elements in select list
ERROR HY000: View's SELECT and view's field list have different column counts
## cte的列名已经无法在被使用了,这种用法比较特殊
explain basic with cte as (select count(*) as k from t1) select * from cte where k = 1;

View File

@ -3,7 +3,7 @@ create database cte_st;
use cte_st;
result_format: 4
with cte(a,b) as (select 1 from dual) select * from cte;
ERROR HY000: number of WITH clause column names does not match number of elements in select list
ERROR HY000: View's SELECT and view's field list have different column counts
with cte(a,b) as (with cte2(a,b) as (select 1,1 from dual) select a,b from cte) select * from cte;
ERROR 42S02: Table doesn't exist
@ -78,18 +78,18 @@ with cte(n) AS (select 1 from dual UNION ALL select n+1 from cte where n < 3 ord
ERROR 42S02: Table doesn't exist
with RECURSIVE cte(n) as (select 1 union all select (select n+1 from cte where n < 1) ) select n from cte;
ERROR HY000: recursive WITH clause must reference itself directly in one of the UNION ALL branches
ERROR HY000: In recursive query block of Recursive Common Table Expression, the recursive table must be referenced only once, and not in any subquery
with RECURSIVE cte(n) as (select 1 from dual union all select 1 + (select n+1 from cte where n < 1) from dual) select n from cte;
ERROR HY000: recursive WITH clause must reference itself directly in one of the UNION ALL branches
ERROR HY000: In recursive query block of Recursive Common Table Expression, the recursive table must be referenced only once, and not in any subquery
with RECURSIVE cte(n) as (select 1 from dual union all select -(select n+1 from cte where n < 1) from dual) select n from cte;
ERROR HY000: recursive WITH clause must reference itself directly in one of the UNION ALL branches
ERROR HY000: In recursive query block of Recursive Common Table Expression, the recursive table must be referenced only once, and not in any subquery
with RECURSIVE cte(n) as (select 1 from dual union all select 2 as c1 from dual where c1 in (select n + 1 from cte where n < 10)) select n from cte;
ERROR HY000: recursive WITH clause must reference itself directly in one of the UNION ALL branches
ERROR HY000: In recursive query block of Recursive Common Table Expression, the recursive table must be referenced only once, and not in any subquery
with RECURSIVE cte(n) as (select 1 from dual union all select 2 from dual where EXISTS(select n + 1 from cte where n < 10)) select n from cte;
ERROR HY000: recursive WITH clause must reference itself directly in one of the UNION ALL branches
ERROR HY000: In recursive query block of Recursive Common Table Expression, the recursive table must be referenced only once, and not in any subquery
drop database cte_st;

View File

@ -1028,11 +1028,11 @@ SELECT * FROM x;
with RECURSIVE x(n) AS (SELECT 1 from dual UNION ALL SELECT count(*) FROM x)
SELECT * FROM x;
ERROR HY000: unsupported operation in recursive branch of recursive WITH clause
ERROR HY000: Recursive Common Table Expression can contain neither aggregation nor window functions in recursive query block
with RECURSIVE x(n) AS (SELECT 1 from dual UNION ALL SELECT sum(n) FROM x)
SELECT * FROM x;
ERROR HY000: unsupported operation in recursive branch of recursive WITH clause
ERROR HY000: Recursive Common Table Expression can contain neither aggregation nor window functions in recursive query block
with RECURSIVE x(n) AS (SELECT 1 from dual UNION ALL SELECT n+1 FROM x where n < 10 ORDER BY 1 ) SELECT * FROM x;
+------+

View File

@ -458,7 +458,7 @@ with RECURSIVE qn () as (select 1) select * from qn, qn qn1;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your OceanBase version for the right syntax to use near ') as (select 1) select * from qn, qn qn1' at line 1
# Materialization
with RECURSIVE qn (foo, bar) as (select 1 from dual) select * from qn, qn qn1;
ERROR HY000: number of WITH clause column names does not match number of elements in select list
ERROR HY000: View's SELECT and view's field list have different column counts
with RECURSIVE qn (foo, bar) as (select 1 as col, 2 as coll from dual union all
select a,b from t1) select qn1.bar from qn qn1;
@ -472,7 +472,7 @@ with RECURSIVE qn (foo, bar) as (select 1 as col, 2 as coll from dual union all
# Merge
with RECURSIVE qn (foo, bar) as (select 1 from t1) select * from qn, qn qn1;
ERROR HY000: number of WITH clause column names does not match number of elements in select list
ERROR HY000: View's SELECT and view's field list have different column counts
with RECURSIVE qn (foo, bar) as (select 1, 2 from t1) select * from qn, qn qn1;
+-----+-----+-----+-----+
| foo | bar | foo | bar |
@ -1666,9 +1666,9 @@ with RECURSIVE cte(a,b) as (select 1,1 from dual union all select a+1, a+1 from
| 9 | 9 |
+------+------+
with RECURSIVE cte(a,b,c) as (select 1,1 from dual union all select a+1, a+1 from cte where a+1 < 10) select * from cte;
ERROR HY000: number of WITH clause column names does not match number of elements in select list
ERROR HY000: View's SELECT and view's field list have different column counts
with RECURSIVE cte(a) as (select 1,1 from dual union all select a+1, a+1 from cte where a+1 < 10) select * from cte;
ERROR HY000: number of WITH clause column names does not match number of elements in select list
ERROR HY000: View's SELECT and view's field list have different column counts
with RECURSIVE cte(a,b,c) as
(
select c1,c2,c3 from t1 where t1.c1 < 20
@ -1752,7 +1752,7 @@ with RECURSIVE cte(n) AS ( select 1 from cte) select * from cte;
ERROR HY000: recursive WITH clause must use a UNION ALL operation
set @@ob_query_timeout=1000000;
with RECURSIVE cte(n) AS ( select 1 from dual UNION ALL select sum(n+1) from cte) select * from cte;
ERROR HY000: unsupported operation in recursive branch of recursive WITH clause
ERROR HY000: Recursive Common Table Expression can contain neither aggregation nor window functions in recursive query block
set @@ob_query_timeout=10000000;
with RECURSIVE cte(n) AS (select 1 from dual UNION ALL select n+1 from cte where n < 3 union all select n+1 from cte where n < 2) select * from cte;
ERROR HY000: UNION ALL operation in recursive WITH clause must have only two branches
@ -1865,16 +1865,16 @@ with RECURSIVE cte(n) as (select '1' from dual union all select n+1 from cte whe
+------+
with RECURSIVE cte(n) as (select n from (select 1 from dual union all select n+1 from cte) tmp) select * from cte;
ERROR HY000: recursive WITH clause must reference itself directly in one of the UNION ALL branches
ERROR HY000: In recursive query block of Recursive Common Table Expression, the recursive table must be referenced only once, and not in any subquery
set @@ob_query_timeout=1000000;
with RECURSIVE cte(n) AS (select c1 from t1 UNION ALL select n+1 from cte right join t2 on cte.n < 3 and t2.c1 < 22) select * from cte;
ERROR HY000: unsupported join in recursive WITH query
ERROR HY000: In recursive query block of Recursive Common Table Expression, the recursive table must neither be in the right argument of a LEFT JOIN, nor be forced to be non-first with join order hints
with RECURSIVE cte(n) AS (select c1 from t1 UNION ALL select n+1 from t2 left join cte on cte.n < 3 and t2.c1 < 22) select * from cte;
ERROR HY000: unsupported join in recursive WITH query
ERROR HY000: In recursive query block of Recursive Common Table Expression, the recursive table must neither be in the right argument of a LEFT JOIN, nor be forced to be non-first with join order hints
with RECURSIVE cte(n) AS (select c1 from t1 UNION ALL select n+1 from t2 full join cte on cte.n < 3 and t2.c1 < 22) select * from cte;
ERROR HY000: unsupported join in recursive WITH query
ERROR HY000: In recursive query block of Recursive Common Table Expression, the recursive table must neither be in the right argument of a LEFT JOIN, nor be forced to be non-first with join order hints
with RECURSIVE cte(n) AS (select c1 from t1 UNION ALL select n+1 from cte full join t2 on cte.n < 3 and t2.c1 < 22) select * from cte;
ERROR HY000: unsupported join in recursive WITH query
ERROR HY000: In recursive query block of Recursive Common Table Expression, the recursive table must neither be in the right argument of a LEFT JOIN, nor be forced to be non-first with join order hints
set @@ob_query_timeout=10000000;
with RECURSIVE cte(n) AS (select 1 from dual UNION ALL select n+1 from cte where n < 3 order by n ) select * from cte;
@ -1929,7 +1929,7 @@ 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)
select c1 from cte2;
ERROR HY000: number of WITH clause column names does not match number of elements in select list
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)

View File

@ -158,9 +158,9 @@ with RECURSIVE cte(a,b) as (select 1,1 from dual union all select a+1, a+1 from
+------+------+
with RECURSIVE cte(a,b,c) as (select 1,1 from dual union all select a+1, a+1 from cte where a+1 < 10) select * from cte;
ERROR HY000: number of WITH clause column names does not match number of elements in select list
ERROR HY000: View's SELECT and view's field list have different column counts
with RECURSIVE cte(a) as (select 1,1 from dual union all select a+1, a+1 from cte where a+1 < 10) select * from cte;
ERROR HY000: number of WITH clause column names does not match number of elements in select list
ERROR HY000: View's SELECT and view's field list have different column counts
## PART 2.2.2 不使用定义列使用原来的列
with RECURSIVE cte(a,b,c) as
@ -981,7 +981,7 @@ ERROR HY000: recursive WITH clause must use a UNION ALL operation
set @@ob_query_timeout=1000000;
with RECURSIVE cte(n) AS ( select 1 from dual UNION ALL select sum(n+1) from cte) select * from cte;
ERROR HY000: unsupported operation in recursive branch of recursive WITH clause
ERROR HY000: Recursive Common Table Expression can contain neither aggregation nor window functions in recursive query block
set @@ob_query_timeout=10000000;
@ -993,17 +993,17 @@ with RECURSIVE cte(n) as (select 1 from dual union all select c1 from t1 union a
ERROR HY000: cycle detected while executing recursive WITH query
with RECURSIVE cte(n) as (select n from (select 1 from dual union all select n+1 from cte) tmp) select * from cte;
ERROR HY000: recursive WITH clause must reference itself directly in one of the UNION ALL branches
ERROR HY000: In recursive query block of Recursive Common Table Expression, the recursive table must be referenced only once, and not in any subquery
## 不能出现在right join的左边,left join的右边,full join的两边
with RECURSIVE cte(n) AS (select c1 from t1 UNION ALL select n+1 from cte right join t2 on cte.n < 3 and t2.c1 < 22) select * from cte;
ERROR HY000: unsupported join in recursive WITH query
ERROR HY000: In recursive query block of Recursive Common Table Expression, the recursive table must neither be in the right argument of a LEFT JOIN, nor be forced to be non-first with join order hints
with RECURSIVE cte(n) AS (select c1 from t1 UNION ALL select n+1 from t2 left join cte on cte.n < 3 and t2.c1 < 22) select * from cte;
ERROR HY000: unsupported join in recursive WITH query
ERROR HY000: In recursive query block of Recursive Common Table Expression, the recursive table must neither be in the right argument of a LEFT JOIN, nor be forced to be non-first with join order hints
with RECURSIVE cte(n) AS (select c1 from t1 UNION ALL select n+1 from t2 full join cte on cte.n < 3 and t2.c1 < 22) select * from cte;
ERROR HY000: unsupported join in recursive WITH query
ERROR HY000: In recursive query block of Recursive Common Table Expression, the recursive table must neither be in the right argument of a LEFT JOIN, nor be forced to be non-first with join order hints
with RECURSIVE cte(n) AS (select c1 from t1 UNION ALL select n+1 from cte full join t2 on cte.n < 3 and t2.c1 < 22) select * from cte;
ERROR HY000: unsupported join in recursive WITH query
ERROR HY000: In recursive query block of Recursive Common Table Expression, the recursive table must neither be in the right argument of a LEFT JOIN, nor be forced to be non-first with join order hints
set @@ob_query_timeout=10000000;
## PART 4.2 左支不停的变化

View File

@ -117,10 +117,10 @@ with cte(a,a) as (select 1,1 from dual) select * from cte;
explain basic with cte(a,b) as (select 1,1 from dual) select * from cte;
with cte(a,b) as (select 1,1 from dual) select * from cte;
--error 5740
--error 1353
with cte(a,b) as (select 1 from dual) select * from cte;
--error 5740
--error 1353
with cte(a,b,c) as (select 1, 2, 3, 4 from dual) select * from cte;
--echo ## PART 2.2.2 不使用定义列使用原来的列
@ -690,7 +690,7 @@ select c22 as c21, c21 from cte1 having c21 > 0;
with
cte1 (c22, c21) AS (select c1, c2 from t1)
select c22 as c21, c21 from cte1 group by c21;
--error 5740
--error 1353
with
cte1 (c22, c21) AS (select * from t1)
select c22 as c21, c21 from cte1 group by c21;

View File

@ -9,7 +9,7 @@ create database cte_st;
use cte_st;
--result_format 4
--error 5740
--error 1353
with cte(a,b) as (select 1 from dual) select * from cte;
--error 1146
@ -80,19 +80,19 @@ with cte(n) AS ( select 1 from cte) select * from cte;
--error 1146
with cte(n) AS (select 1 from dual UNION ALL select n+1 from cte where n < 3 order by n ) select * from cte;
--error 5744
--error 3577
with RECURSIVE cte(n) as (select 1 union all select (select n+1 from cte where n < 1) ) select n from cte;
--error 5744
--error 3577
with RECURSIVE cte(n) as (select 1 from dual union all select 1 + (select n+1 from cte where n < 1) from dual) select n from cte;
--error 5744
--error 3577
with RECURSIVE cte(n) as (select 1 from dual union all select -(select n+1 from cte where n < 1) from dual) select n from cte;
--error 5744
--error 3577
with RECURSIVE cte(n) as (select 1 from dual union all select 2 as c1 from dual where c1 in (select n + 1 from cte where n < 10)) select n from cte;
--error 5744
--error 3577
with RECURSIVE cte(n) as (select 1 from dual union all select 2 from dual where EXISTS(select n + 1 from cte where n < 10)) select n from cte;
drop database cte_st;

View File

@ -547,11 +547,11 @@ with RECURSIVE x(n) AS (SELECT a FROM y WHERE a = 1
SELECT x.n+1 FROM y RIGHT JOIN x ON x.n = y.a WHERE n < 10)
SELECT * FROM x;
--error 5758
--error 3575
with RECURSIVE x(n) AS (SELECT 1 from dual UNION ALL SELECT count(*) FROM x)
SELECT * FROM x;
--error 5758
--error 3575
with RECURSIVE x(n) AS (SELECT 1 from dual UNION ALL SELECT sum(n) FROM x)
SELECT * FROM x;

View File

@ -60,7 +60,7 @@ qn AS (SELECT b as a FROM qn2)
SELECT qn.a FROM qn;
--echo # recursive
--error 5742
--error 3573
with recursive qn AS (SELECT a FROM qn)
SELECT qn.a FROM qn;
@ -233,7 +233,7 @@ select * from t1 where t1.a in (select a+0 from cte);
--error 1064
with RECURSIVE qn () as (select 1) select * from qn, qn qn1;
--echo # Materialization
--error 5740
--error 1353
with RECURSIVE qn (foo, bar) as (select 1 from dual) select * from qn, qn qn1;
with RECURSIVE qn (foo, bar) as (select 1 as col, 2 as coll from dual union all
@ -241,7 +241,7 @@ with RECURSIVE qn (foo, bar) as (select 1 as col, 2 as coll from dual union all
--echo # Merge
--error 5740
--error 1353
with RECURSIVE qn (foo, bar) as (select 1 from t1) select * from qn, qn qn1;
with RECURSIVE qn (foo, bar) as (select 1, 2 from t1) select * from qn, qn qn1;
@ -1032,9 +1032,9 @@ with RECURSIVE t4(a) as (select 1 from dual union all select a+1 from t4 where a
--error 5751
with RECURSIVE cte(a,a) as (select 1,1 from dual union all select a+1, a+1 from cte where a+1 < 10) select * from cte;
with RECURSIVE cte(a,b) as (select 1,1 from dual union all select a+1, a+1 from cte where a+1 < 10) select * from cte;
--error 5740
--error 1353
with RECURSIVE cte(a,b,c) as (select 1,1 from dual union all select a+1, a+1 from cte where a+1 < 10) select * from cte;
--error 5740
--error 1353
with RECURSIVE cte(a) as (select 1,1 from dual union all select a+1, a+1 from cte where a+1 < 10) select * from cte;
--error 1054
with RECURSIVE cte(a,b,c) as
@ -1095,10 +1095,10 @@ select * from cte;
with RECURSIVE cte(a) as (select 1 from dual union all select 2 from dual), cte_1(b) as (select 1 from dual union all select * from cte) select * from cte_1;
--error 5743
with RECURSIVE cte(n) AS (select 1 from dual UNION ALL select n+1 from cte where n < 3 UNION ALL select 2 from dual) select * from cte;
--error 5742
--error 3573
with RECURSIVE cte(n) AS ( select 1 from cte) select * from cte;
set @@ob_query_timeout=1000000;
--error 5758
--error 3575
with RECURSIVE cte(n) AS ( select 1 from dual UNION ALL select sum(n+1) from cte) select * from cte;
set @@ob_query_timeout=10000000;
--error 5743
@ -1107,16 +1107,16 @@ with RECURSIVE cte(n) AS (select 1 from dual UNION ALL select n+1 from cte where
with RECURSIVE cte(n) as (select 1 from dual union all select c1 from t1 union all (with RECURSIVE cte(n) as (select c1 from t1) select * from cte)) select * from cte;
with RECURSIVE cte(n) as (select '1' from dual union all select n+1 from cte where n < 100) select * from cte;
--error 5744
--error 3577
with RECURSIVE cte(n) as (select n from (select 1 from dual union all select n+1 from cte) tmp) select * from cte;
set @@ob_query_timeout=1000000;
--error 5759
--error 3576
with RECURSIVE cte(n) AS (select c1 from t1 UNION ALL select n+1 from cte right join t2 on cte.n < 3 and t2.c1 < 22) select * from cte;
--error 5759
--error 3576
with RECURSIVE cte(n) AS (select c1 from t1 UNION ALL select n+1 from t2 left join cte on cte.n < 3 and t2.c1 < 22) select * from cte;
--error 5759
--error 3576
with RECURSIVE cte(n) AS (select c1 from t1 UNION ALL select n+1 from t2 full join cte on cte.n < 3 and t2.c1 < 22) select * from cte;
--error 5759
--error 3576
with RECURSIVE cte(n) AS (select c1 from t1 UNION ALL select n+1 from cte full join t2 on cte.n < 3 and t2.c1 < 22) select * from cte;
set @@ob_query_timeout=10000000;
@ -1153,7 +1153,7 @@ 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)
select c,d from cte2;
--error 5740
--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)
select c1 from cte2;

View File

@ -141,9 +141,9 @@ with RECURSIVE cte(a,a) as (select 1,1 from dual union all select a+1, a+1 from
## PART 2.2.1 定义列数量与查询产生列一致或不一致
with RECURSIVE cte(a,b) as (select 1,1 from dual union all select a+1, a+1 from cte where a+1 < 10) select * from cte;
--error 5740
--error 1353
with RECURSIVE cte(a,b,c) as (select 1,1 from dual union all select a+1, a+1 from cte where a+1 < 10) select * from cte;
--error 5740
--error 1353
with RECURSIVE cte(a) as (select 1,1 from dual union all select a+1, a+1 from cte where a+1 < 10) select * from cte;
## PART 2.2.2 不使用定义列使用原来的列
@ -238,11 +238,11 @@ with RECURSIVE cte(a) as (select 1 from dual union all select 2 from dual), cte_
with RECURSIVE cte(n) AS (select 1 from dual UNION ALL select n+1 from cte where n < 3 UNION ALL select 2 from dual) select * from cte;
## 递归必须包含union all
--error 5742
--error 3573
with RECURSIVE cte(n) AS ( select 1 from cte) select * from cte;
set @@ob_query_timeout=1000000;
--error 5758
--error 3575
with RECURSIVE cte(n) AS ( select 1 from dual UNION ALL select sum(n+1) from cte) select * from cte;
set @@ob_query_timeout=10000000;
@ -254,17 +254,17 @@ with RECURSIVE cte(n) AS (select 1 from dual UNION ALL select n+1 from cte where
--error 5746
with RECURSIVE cte(n) as (select 1 from dual union all select c1 from t1 union all (with RECURSIVE cte(n) as (select c1 from t1) select * from cte)) select * from cte;
--error 5744
--error 3577
with RECURSIVE cte(n) as (select n from (select 1 from dual union all select n+1 from cte) tmp) select * from cte;
## 不能出现在right join的左边,left join的右边,full join的两边
--error 5759
--error 3576
with RECURSIVE cte(n) AS (select c1 from t1 UNION ALL select n+1 from cte right join t2 on cte.n < 3 and t2.c1 < 22) select * from cte;
--error 5759
--error 3576
with RECURSIVE cte(n) AS (select c1 from t1 UNION ALL select n+1 from t2 left join cte on cte.n < 3 and t2.c1 < 22) select * from cte;
--error 5759
--error 3576
with RECURSIVE cte(n) AS (select c1 from t1 UNION ALL select n+1 from t2 full join cte on cte.n < 3 and t2.c1 < 22) select * from cte;
--error 5759
--error 3576
with RECURSIVE cte(n) AS (select c1 from t1 UNION ALL select n+1 from cte full join t2 on cte.n < 3 and t2.c1 < 22) select * from cte;
set @@ob_query_timeout=10000000;