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

Crash when executing prepared statement for a query that uses CTE

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

            igor Igor Babaev (Inactive) created issue -
            igor Igor Babaev (Inactive) made changes -
            Field Original Value New Value
            Status Open [ 1 ] In Progress [ 3 ]

            One can see the same failure after having replace cte for a mergeable one

            MariaDB [test]> prepare stmt from "
                "> with cte as
                "> (select a from t1 where a between 4 and 7)
                "> (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.
            

            igor Igor Babaev (Inactive) added a comment - One can see the same failure after having replace cte for a mergeable one MariaDB [test]> prepare stmt from " "> with cte as "> (select a from t1 where a between 4 and 7) "> (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.
            igor Igor Babaev (Inactive) made changes -
            Assignee Igor Babaev [ igor ] Oleksandr Byelkin [ sanja ]
            Status In Progress [ 3 ] In Review [ 10002 ]
            serg Sergei Golubchik made changes -
            Fix Version/s 10.2 [ 14601 ]
            serg Sergei Golubchik made changes -
            Comment [ Sanja, please review ASAP (needed for DBS). ]
            igor Igor Babaev (Inactive) made changes -

            OK to push

            sanja Oleksandr Byelkin added a comment - OK to push
            sanja Oleksandr Byelkin made changes -
            Status In Review [ 10002 ] Stalled [ 10000 ]
            sanja Oleksandr Byelkin made changes -
            Assignee Oleksandr Byelkin [ sanja ] Igor Babaev [ igor ]
            igor Igor Babaev (Inactive) made changes -
            Status Stalled [ 10000 ] In Progress [ 3 ]

            A fix for this bug was pushed into the 10.2 tree.

            igor Igor Babaev (Inactive) added a comment - A fix for this bug was pushed into the 10.2 tree.
            igor Igor Babaev (Inactive) made changes -
            Fix Version/s 10.2.12 [ 22810 ]
            Fix Version/s 10.2 [ 14601 ]
            Resolution Fixed [ 1 ]
            Status In Progress [ 3 ] Closed [ 6 ]
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 84589 ] MariaDB v4 [ 153426 ]

            People

              igor Igor Babaev (Inactive)
              igor Igor Babaev (Inactive)
              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.