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

Crash when executing prepared statement for a query that uses CTE

    XMLWordPrintable

Details

    Description

      Execution of the prepared statement for the query

      with cte as
      (select a from t1 where a between 4 and 7 group by a)
      (select a from cte where exists( select a from t1 where cte.a=t1.a )) 
      union
      (select a from t1 where a < 2);
      

      works fine while the execution this query that is equivalent to the first one

      with cte as
      (select a from t1 where a between 4 and 7 group by a)
      (select a from t1 where a < 2)
      union
      (select a from cte where exists( select a from t1 where cte.a=t1.a )); 
      

      causes an assertion failure for debug builds and most probably crashes for release builds

      MariaDB [test]> create table t1 (a int);
       MariaDB [test]> insert into t1 values
          ->   (7), (2), (8), (1), (3), (2), (7), (5), (4), (7), (9), (8);
      MariaDB [test]> prepare stmt from "
      with cte as
      (select a from t1 where a between 4 and 7 group by a)
      (select a from cte where exists( select a from t1 where cte.a=t1.a )) 
      union
      (select a from t1 where a < 2); 
      ";
      Statement prepared
       MariaDB [test]> execute stmt;      
      +------+
      | a    |
      +------+
      |    7 |
      |    5 |
      |    4 |
      |    1 |
      +------+
      MariaDB [test]> execute stmt;
      +------+
      | a    |
      +------+
      |    7 |
      |    5 |
      |    4 |
      |    1 |
      +------+
      MariaDB [test]> prepare stmt from "
          "> with cte as
          "> (select a from t1 where a between 4 and 7 group by a)
          "> (select a from t1 where a < 2)
          "> union
          "> (select a from cte where exists( select a from t1 where cte.a=t1.a )) 
          "> ";
      Statement prepared
      MariaDB [test]> execute stmt;
       
      mysqld: /home/igor/maria-git/10.2/sql/sql_prepare.cc:2949: void reinit_stmt_before_use(THD*, LEX*): Assertion `sl->join == 0' failed.
      

      Attachments

        Issue Links

          Activity

            People

              igor Igor Babaev
              igor Igor Babaev
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

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