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

Recursive CTE: view usage between 2 same query executions changes explain NOTE

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 13.1
    • 13.1
    • Optimizer - CTE
    • None
    • Unexpected results
    • Q3/2026 Server Maintenance

    Description

      At a high level, although generated plan is same in steps 2, and 5, the NOTE (Code 1003) is different.

      create table t1; insert into table ...
      explain exended with_recursive_query;
      create view v1 as with_recursive_query; select * from v1;
      drop view v1;
      explain extended with_recursive_query;
      

      Exact table definitions, and queries (taken from main.cte_recursive) are as follows: -

      set default_storage_engine=myisam;
       
      create table  folks(id int, name char(32), dob date, father int, mother int) charset=latin1;
      insert into folks values
      (100, 'Me', '2000-01-01', 20, 30),
      (20, 'Dad', '1970-02-02', 10, 9),
      (30, 'Mom', '1975-03-03', 8, 7),
      (10, 'Grandpa Bill', '1940-04-05', null, null),
      (9, 'Grandma Ann', '1941-10-15', null, null),
      (25, 'Uncle Jim', '1968-11-18', 8, 7),
      (98, 'Sister Amy', '2001-06-20', 20, 30),
      (7, 'Grandma Sally', '1943-08-23', null, 6),
      (8, 'Grandpa Ben', '1940-10-21', null, null),
      (6, 'Grandgrandma Martha', '1923-05-17', null, null),
      (67, 'Cousin Eddie', '1992-02-28', 25, 27),
      (27, 'Auntie Melinda', '1971-03-29', null, null);
       
      let $q= with recursive 
      ancestors
      as
      (
        select *
          from folks
            where name = 'Me' and dob = '2000-01-01'
        union 
        select p.id, p.name, p.dob, p.father, p.mother
          from folks as p, ancestors AS a
            where p.id = a.father or p.id = a.mother
      )
      select * from ancestors;
       
      eval explain extended $q;
       
      eval create view v1 as $q;
      show create view v1;
      select * from v1;
      drop view v1;
       
      eval explain extended $q;
       
      drop table folks;
      

      Attachments

        Activity

          People

            bsrikanth Srikanth Bondalapati
            bsrikanth Srikanth Bondalapati
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.