This is an automated email from the ASF dual-hosted git repository.

avamingli pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git

commit 0f65387744f53a7fb5be9fba9f082b15f88f72db
Author: Zhenghua Lyu <[email protected]>
AuthorDate: Fri Dec 16 07:20:20 2022 +0800

    Remove handle RangeSubselect in checkWellFormedRecursionWalker.
    
    Keep align with upstream.
---
 src/backend/parser/parse_cte.c                 | 12 ------------
 src/test/regress/expected/gp_recursive_cte.out | 25 +++++++++++++++++++++++++
 src/test/regress/expected/with.out             |  6 +++---
 src/test/regress/sql/gp_recursive_cte.sql      | 12 ++++++++++++
 4 files changed, 40 insertions(+), 15 deletions(-)

diff --git a/src/backend/parser/parse_cte.c b/src/backend/parser/parse_cte.c
index ecc27df766..beb0345d39 100644
--- a/src/backend/parser/parse_cte.c
+++ b/src/backend/parser/parse_cte.c
@@ -1137,19 +1137,7 @@ checkWellFormedRecursionWalker(Node *node, CteState 
*cstate)
                checkWellFormedRecursionWalker(sl->testexpr, cstate);
                return false;
        }
-       if (IsA(node, RangeSubselect))
-       {
-               RangeSubselect *rs = (RangeSubselect *) node;
 
-               /*
-                * we intentionally override outer context, since subquery is
-                * independent
-                */
-               cstate->context = RECURSION_SUBLINK;
-               checkWellFormedRecursionWalker(rs->subquery, cstate);
-               cstate->context = save_context;
-               return false;
-       }
        return raw_expression_tree_walker(node,
                                                                          
checkWellFormedRecursionWalker,
                                                                          (void 
*) cstate);
diff --git a/src/test/regress/expected/gp_recursive_cte.out 
b/src/test/regress/expected/gp_recursive_cte.out
index 72f493b88a..00b08e4b84 100644
--- a/src/test/regress/expected/gp_recursive_cte.out
+++ b/src/test/regress/expected/gp_recursive_cte.out
@@ -770,4 +770,29 @@ select id,name from cte;
   4 | AAA>B1>C1_2
   5 | AAA>B1>C1_3
 (9 rows)
+-- WTIH RECURSIVE and subquery
+with recursive cte (n) as
+(
+  select 1
+  union all
+  select * from
+  (
+    with x(n) as (select n from cte)
+    select n + 1 from x where n < 10
+  ) q
+)
+select * from cte;
+ n  
+----
+  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+(10 rows)
 
diff --git a/src/test/regress/expected/with.out 
b/src/test/regress/expected/with.out
index 14944834c8..9077579ea0 100644
--- a/src/test/regress/expected/with.out
+++ b/src/test/regress/expected/with.out
@@ -1955,9 +1955,9 @@ WITH RECURSIVE foo(i) AS
           UNION ALL
        SELECT i+1 FROM foo WHERE i < 5) AS t
 ) SELECT * FROM foo;
-ERROR:  recursive reference to query "foo" must not appear within a subquery
-LINE 5:        (SELECT i+1 FROM foo WHERE i < 10
-                                ^
+ERROR:  recursive reference to query "foo" must not appear more than once
+LINE 7:        SELECT i+1 FROM foo WHERE i < 5) AS t
+                               ^
 WITH RECURSIVE foo(i) AS
     (values (1)
     UNION ALL
diff --git a/src/test/regress/sql/gp_recursive_cte.sql 
b/src/test/regress/sql/gp_recursive_cte.sql
index 5d98221020..90aeda8814 100644
--- a/src/test/regress/sql/gp_recursive_cte.sql
+++ b/src/test/regress/sql/gp_recursive_cte.sql
@@ -506,3 +506,15 @@ with RECURSIVE cte as (
 )
 select id,name from cte;
 
+-- WTIH RECURSIVE and subquery
+with recursive cte (n) as
+(
+  select 1
+  union all
+  select * from
+  (
+    with x(n) as (select n from cte)
+    select n + 1 from x where n < 10
+  ) q
+)
+select * from cte;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to