Bug #92857 | Support LIMIT inside definition of recursive CTE | ||
---|---|---|---|
Submitted: | 19 Oct 2018 9:22 | Modified: | 7 Jan 2020 2:38 |
Reporter: | Guilhem Bichot | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S4 (Feature request) |
Version: | 8.0.14 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[19 Oct 2018 9:22]
Guilhem Bichot
[7 Jan 2020 2:38]
Jon Stephens
Documented fix as follows in the MySQL 8.0.19 changelog: Previously, it was not possible to use LIMIT in the recursive SELECT part of a recursive common table expression (CTE). LIMIT is now supported in such cases, along with an optional OFFSET clause. An example of such a recursive CTE is shown here: WITH RECURSIVE cte AS ( SELECT CAST("x" AS CHAR(100)) AS a FROM DUAL UNION ALL SELECT CONCAT("x",cte.a) FROM qn WHERE LENGTH(cte.a) < 10 LIMIT 3 OFFSET 2; ) SELECT * FROM cte; Specifying LIMIT in this fashion can make execution of the CTE more efficient than doing so in the outermost SELECT, since only the requested number of rows is generated. For more information, see "Recursive Common Table Expressions". Closed.