[MDEV-15160] Query with CTE hangs if contains straight_join Created: 2018-02-01  Updated: 2018-02-15  Resolved: 2018-02-15

Status: Closed
Project: MariaDB Server
Component/s: Optimizer - CTE
Affects Version/s: 10.2, 10.3
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Alice Sherepa Assignee: Alice Sherepa
Resolution: Not a Bug Votes: 0
Labels: None


 Description   

it should be a restriction to not use straight_join inside the anchor part of cte
testcase:

CREATE TABLE t1(a int);
INSERT INTO t1 VALUES(1),(2);
 
WITH RECURSIVE cte AS
	(SELECT 2 as a FROM t1 UNION ALL
	SELECT 5 FROM t1 straight_join cte)
SELECT * FROM cte;

explain WITH RECURSIVE cte AS
(SELECT 2 as a FROM t1 UNION ALL
SELECT 5 FROM t1 straight_join cte)
SELECT * FROM cte
--------------
 
+------+-----------------+------------+------+---------------+------+---------+------+------+------------------------------------+
| id   | select_type     | table      | type | possible_keys | key  | key_len | ref  | rows | Extra                              |
+------+-----------------+------------+------+---------------+------+---------+------+------+------------------------------------+
|    1 | PRIMARY         | <derived2> | ALL  | NULL          | NULL | NULL    | NULL |    2 |                                    |
|    2 | DERIVED         | t1         | ALL  | NULL          | NULL | NULL    | NULL |    2 |                                    |
|    3 | RECURSIVE UNION | t1         | ALL  | NULL          | NULL | NULL    | NULL |    2 |                                    |
|    3 | RECURSIVE UNION | <derived2> | ALL  | NULL          | NULL | NULL    | NULL |    2 | Using join buffer (flat, BNL join) |
| NULL | UNION RESULT    | <union2,3> | ALL  | NULL          | NULL | NULL    | NULL | NULL |                                    |
+------+-----------------+------------+------+---------------+------+---------+------+------+------------------------------------+
5 rows in set (0.001 sec)



 Comments   
Comment by Igor Babaev [ 2018-02-05 ]

Alice,
The first iteration yields (2),(2).
The second iteration yields (5), (5).
Each next iteration yields twice as many rows as the previous one.

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