diff --git a/docs/_docs/SQL/sql-calcite.adoc b/docs/_docs/SQL/sql-calcite.adoc index 1bc5aa0d50956..7c4825337e60a 100644 --- a/docs/_docs/SQL/sql-calcite.adoc +++ b/docs/_docs/SQL/sql-calcite.adoc @@ -189,6 +189,52 @@ The new SQL engine mostly inherits data manipulation language (DML) statements s In most cases, statement syntax is compliant with the old SQL engine. But there are still some differences between DML dialects in H2-based engine and Calcite-based engine. For example, note the `MERGE` statement syntax has changed. +=== Recursive CTEs + +The Calcite-based SQL engine supports recursive common table expressions (CTEs) that use `WITH RECURSIVE` and `UNION ALL`. +Recursive CTEs can be used to express hierarchical traversals, graph-style parent-child walks, and sequence generation queries. + +[source,sql] +---- +WITH RECURSIVE employee_hierarchy (id, manager_id, name, depth) AS ( + SELECT id, manager_id, name, 0 + FROM employee + WHERE manager_id IS NULL + + UNION ALL + + SELECT e.id, e.manager_id, e.name, h.depth + 1 + FROM employee e + JOIN employee_hierarchy h ON e.manager_id = h.id +) +SELECT id, manager_id, name, depth +FROM employee_hierarchy +ORDER BY depth, id; +---- + +The recursive part can reference the recursive CTE more than once and can contain multiple recursive branches. +`UNION DISTINCT` recursive CTEs are not supported. + +Recursive CTE execution keeps the recursive delta on the query coordinator. +The delta memory is included into the Calcite query memory quota. See <> for details about memory quota configuration. + +To protect the cluster from accidentally unbounded recursion, Ignite limits the number of recursive CTE iterations to `100` by default. +You can change the limit with the `sql.calcite.recursiveCteIterationLimit` distributed property. A negative value disables the limit. + +[tabs] +-- +tab:Unix[] +[source,shell] +---- +control.sh --property set --name sql.calcite.recursiveCteIterationLimit --val 1000 +---- +tab:Windows[] +[source,shell] +---- +control.bat --property set --name sql.calcite.recursiveCteIterationLimit --val 1000 +---- +-- + === Transactions The Calcite-based SQL engine supports SQL savepoint commands for explicit transactions. See link:sql-reference/transactions[Transactions, window=_blank] for syntax and usage details. diff --git a/docs/_docs/sql-reference/sql-conformance.adoc b/docs/_docs/sql-reference/sql-conformance.adoc index 7cc2ed5c61043..6ddf7f3ba50e5 100644 --- a/docs/_docs/sql-reference/sql-conformance.adoc +++ b/docs/_docs/sql-reference/sql-conformance.adoc @@ -162,7 +162,7 @@ Ignite does not support the following sub-feature: `E071–06` Table operators in subqueries -Note that there is no support for non-recursive WITH clause in H2 and Ignite. According to link:http://www.h2database.com/html/grammar.html#with[the H2 docs, window=_blank] there is support for recursive WITH clause, but it fails in Ignite. +The H2-based SQL engine does not support non-recursive `WITH` clauses. The Calcite-based SQL engine supports recursive CTEs with `WITH RECURSIVE` and `UNION ALL`; see link:SQL/sql-calcite#recursive-ctes[Recursive CTEs, window=_blank]. | E081 Basic Privileges | Ignite does not support the following sub-feature: