[MDEV-14755] Crash when executing prepared statement for a query that uses CTE Created: 2017-12-23  Updated: 2018-01-05  Resolved: 2017-12-28

Status: Closed
Project: MariaDB Server
Component/s: Optimizer - CTE
Affects Version/s: 10.2.11
Fix Version/s: 10.2.12

Type: Bug Priority: Major
Reporter: Igor Babaev Assignee: Igor Babaev
Resolution: Fixed Votes: 1
Labels: None

Issue Links:
Relates
relates to MDEV-14777 Crash in MariaDB 10.2.12 on query usi... Closed

 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.



 Comments   
Comment by Igor Babaev [ 2017-12-24 ]

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.

Comment by Oleksandr Byelkin [ 2017-12-27 ]

OK to push

Comment by Igor Babaev [ 2017-12-28 ]

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

Generated at Thu Feb 08 08:16:02 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.