Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-26095

Infinite recursion when processing embedded recursive CTE with missing RECURSIVE

    XMLWordPrintable

    Details

      Description

      If the definition of a recursive CTE r is used in the WITH clause without RECURSIVE and this clause is part of the query expression that defines another CTE then the server falls into an infinite recursion calling With_element::clone_parsed_spec() again and again. Ultimately it causes a crash of the server.
      Here's a test case that causes such crash:

      create table t1 (a int);
      insert into t1 values (5), (7);
      with cte_e as (
         with cte_r as ( 
            select a from t1   union  select a+1 as a from cte_r r where a < 10
         )   select * from cte_r 
      ) select * from cte_e;
      

      It should be noted that the definition of cte_r is not considered as the definition of a recursive CTE. Rather it is considered as the definition of a non-recursive CTE referencing the base table or view with the name cte_r. This is because the WITH clause containing this definition lacks the keyword RECURSIVE.
      So the expected reaction of the server should be similar to this:

      MariaDB [test]>    with cte_r as ( 
          ->       select a from t1   union  select a+1 as a from cte_r r where a < 10
          ->    )   select * from cte_r 
          -> ;
      ERROR 1146 (42S02): Table 'test.cte_r' doesn't exist
      

        Attachments

          Activity

            People

            Assignee:
            igor Igor Babaev
            Reporter:
            igor Igor Babaev
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Git Integration