<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>OpenText Analytics Database 26.2.x – WITH clause</title>
    <link>/en/sql-reference/statements/select/with-clause/</link>
    <description>Recent content in WITH clause on OpenText Analytics Database 26.2.x</description>
    <generator>Hugo -- gohugo.io</generator>
    
	  <atom:link href="/en/sql-reference/statements/select/with-clause/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>Sql-Reference: Inline expansion of WITH clause</title>
      <link>/en/sql-reference/statements/select/with-clause/inline-expansion-of-with-clause/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/statements/select/with-clause/inline-expansion-of-with-clause/</guid>
      <description>
        
        
        &lt;p&gt;By default, OpenText™ Analytics Database uses inline expansion to evaluate WITH clauses. The database evaluates each WITH clause every time it is referenced by the primary query. Inline expansion often works best if the query does not reference the same WITH clause multiple times, or if some local optimizations are possible after inline expansion.&lt;/p&gt;
&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;
&lt;p&gt;The following example shows a WITH clause that is a good candidate for inline expansion. The WITH clause is used in a query that obtains order information for all 2007 orders shipped between December 01-07:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
-- Begin WITH
WITH &lt;span class=&#34;code-input&#34;&gt;store_orders_fact_new&lt;/span&gt; AS(
   SELECT * FROM store.store_orders_fact WHERE date_shipped between &amp;#39;2007-12-01&amp;#39; and &amp;#39;2007-12-07&amp;#39;)
-- End WITH
-- Begin primary query
SELECT store_key, product_key, product_version, SUM(quantity_ordered*unit_price) AS total_price
FROM &lt;span class=&#34;code-input&#34;&gt;store_orders_fact_new&lt;/span&gt;
GROUP BY store_key, product_key, product_version
ORDER BY total_price DESC;

 store_key | product_key | product_version | total_price
-----------+-------------+-----------------+-------------
       232 |        1855 |               2 |       29008
       125 |        8500 |               4 |       28812
       139 |        3707 |               2 |       28812
       212 |        3203 |               1 |       28000
       236 |        8023 |               4 |       27548
       123 |       10598 |               2 |       27146
        34 |        8888 |               4 |       27100
       203 |        2243 |               1 |       27027
       117 |       13932 |               2 |       27000
        84 |         768 |               1 |       26936
       123 |        1038 |               1 |       26885
       106 |       18932 |               1 |       26864
        93 |       10395 |               3 |       26790
       162 |       13073 |               1 |       26754
        15 |        3679 |               1 |       26675
        52 |        5957 |               5 |       26656
       190 |        8114 |               3 |       26611
         5 |        7772 |               1 |       26588
       139 |        6953 |               3 |       26572
       202 |       14735 |               1 |       26404
       133 |        2740 |               1 |       26312
       198 |        8545 |               3 |       26287
       221 |        7582 |               2 |       26280
       127 |        9468 |               3 |       26224
        63 |        8115 |               4 |       25960
       171 |        2088 |               1 |       25650
       250 |       11210 |               3 |       25608
...
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The database processes the query as follows:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Expands the WITH clause reference to &lt;code&gt;store_orders_fact_new&lt;/code&gt; within the primary query.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;After expanding the WITH clause, evaluates the primary query.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: Materialization of WITH clause</title>
      <link>/en/sql-reference/statements/select/with-clause/materialization-of-with-clause/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/statements/select/with-clause/materialization-of-with-clause/</guid>
      <description>
        
        
        &lt;p&gt;When materialization is enabled, OpenText™ Analytics Database evaluates each WITH clause once, stores results in a temporary table, and references this table as often as the query requires. The database drops the temporary table after primary query execution completes.

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

If the primary query returns with an error, temporary tables might be dropped only after the client’s session ends.

&lt;/div&gt;&lt;/p&gt;
&lt;p&gt;Materialization can facilitate better performance when WITH clauses are complex—for example, when the WITH clauses contain JOIN and GROUP BY clauses, and are referenced multiple times in the primary query.&lt;/p&gt;
&lt;p&gt;If materialization is enabled, WITH statements perform an auto-commit of the user transaction. This occurs even when using EXPLAIN with the WITH statement.&lt;/p&gt;
&lt;h2 id=&#34;enabling-with-clause-materialization&#34;&gt;Enabling WITH clause materialization&lt;/h2&gt;
&lt;p&gt;WITH materialization is set by configuration parameter WithClauseMaterialization, by default set to 0 (disabled). You can enable and disable materialization by setting WithClauseMaterialization at database and session levels, with &lt;a href=&#34;../../../../../en/sql-reference/statements/alter-statements/alter-db/#&#34;&gt;ALTER DATABASE&lt;/a&gt; and &lt;a href=&#34;../../../../../en/sql-reference/statements/alter-statements/alter-session/#&#34;&gt;ALTER SESSION&lt;/a&gt;, respectively:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Database:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; ALTER DATABASE &lt;span class=&#34;code-variable&#34;&gt;db-spec&lt;/span&gt; SET PARAMETER WithClauseMaterialization={ 0 | 1 };
=&amp;gt; ALTER DATABASE&lt;span class=&#34;code-variable&#34;&gt; db-spec&lt;/span&gt; CLEAR PARAMETER WithClauseMaterialization;
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Session: Parameter setting remains in effect until you explicitly clear it, or the session ends.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; ALTER SESSION SET PARAMETER WithClauseMaterialization={ 0 | 1 };
=&amp;gt; ALTER SESSION CLEAR PARAMETER WithClauseMaterialization;
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can also enable WITH materialization for individual queries with the hint &lt;a href=&#34;../../../../../en/sql-reference/language-elements/hints/enable-with-clause-materialization/#&#34;&gt;ENABLE_WITH_CLAUSE_MATERIALIZATION&lt;/a&gt;. Materialization is automatically cleared when the query returns. For example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; WITH /*+ENABLE_WITH_CLAUSE_MATERIALIZATION */ revenue AS (
      SELECT vendor_key, SUM(total_order_cost) AS total_revenue
      FROM store.store_orders_fact
      GROUP BY vendor_key ORDER BY 1)
     ...
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;processing-with-clauses-using-ee5-temp-relations&#34;&gt;Processing WITH clauses using EE5 temp relations&lt;/h2&gt;
&lt;p&gt;By default, when WITH clause queries are reused, the database saves those WITH clause query outputs in EE5 temp relations. However, this option can be changed. EE5 temp relation support is set by configuration parameter EnableWITHTempRelReuseLimit, which can be set in the following ways:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;0: Disables this feature.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;1: Force-saves all WITH clause queries into EE5 temp relations, whether or not they are reused.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;2 (default): Saves only reused WITH clause queries into EE5 temp relations.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;3 or more: Saves WITH clause queries into EE5 temp relations only when they are used at least this number of times.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;EnableWITHTempRelReuseLimit can be set at database and session levels, with &lt;a href=&#34;../../../../../en/sql-reference/statements/alter-statements/alter-db/#&#34;&gt;ALTER DATABASE&lt;/a&gt; and &lt;a href=&#34;../../../../../en/sql-reference/statements/alter-statements/alter-session/#&#34;&gt;ALTER SESSION&lt;/a&gt;, respectively. When WithClauseMaterialization is set to 1, that setting overrides any EnableWITHTempRelReuseLimit settings.&lt;/p&gt;
&lt;p&gt;Note that for WITH queries with complex types, temp relations are disabled.&lt;/p&gt;
&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;
&lt;p&gt;The following example shows a WITH clause that is a good candidate for materialization. The query obtains data for the vendor who has the highest combined order cost for all orders:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;-- Enable materialization
=&amp;gt; ALTER SESSION SET PARAMETER WithClauseMaterialization=1;

-- Define WITH clause
=&amp;gt; WITH revenue AS (
      SELECT vendor_key, SUM(total_order_cost) AS total_revenue
      FROM store.store_orders_fact
      GROUP BY vendor_key ORDER BY 1)
-- End WITH clause

-- Primary query
=&amp;gt; SELECT vendor_name, vendor_address, vendor_city, total_revenue
FROM vendor_dimension v, &lt;span class=&#34;code-input&#34;&gt;revenue&lt;/span&gt; r
WHERE v.vendor_key = r.vendor_key AND total_revenue = (SELECT MAX(total_revenue) FROM revenue )
ORDER BY vendor_name;
   vendor_name    | vendor_address | vendor_city | total_revenue
------------------+----------------+-------------+---------------
 Frozen Suppliers | 471 Mission St | Peoria      |      49877044
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The database processes this query as follows:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;WITH clause &lt;code&gt;revenue&lt;/code&gt; evaluates its SELECT statement from table &lt;code&gt;store.store_orders_fact&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Results of the &lt;code&gt;revenue&lt;/code&gt; clause are stored in a local temporary table.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Whenever the &lt;code&gt;revenue&lt;/code&gt; clause statement is referenced, the results stored in the table are used.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The temporary table is dropped when query execution is complete.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: WITH clause recursion</title>
      <link>/en/sql-reference/statements/select/with-clause/with-clause-recursion/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/statements/select/with-clause/with-clause-recursion/</guid>
      <description>
        
        
        &lt;p&gt;A WITH clause that includes the RECURSIVE option iterates over its own output through repeated execution of a UNION or UNION ALL query. Recursive queries are useful when working with self-referential data—hierarchies such as manager-subordinate relationships, or tree-structured data such as taxonomies.&lt;/p&gt;
&lt;p&gt;The configuration parameter &lt;a href=&#34;../../../../../en/sql-reference/config-parameters/general-parameters/#WithClauseRecursionLimit&#34;&gt;WithClauseRecursionLimit&lt;/a&gt;—by default set to 8—sets the maximum depth of recursion. You can set this parameter at database and session scopes with ALTER DATABASE and ALTER SESSION, respectively. Recursion continues until it reaches the configured maximum depth, or until the last iteration returns with no data.&lt;/p&gt;
&lt;p&gt;You specify a recursive WITH clause as follows:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;WITH [ /*+ENABLE_WITH_CLAUSE_MATERIALIZATION*/ ] RECURSIVE
   &lt;span class=&#34;code-variable&#34;&gt;cte-identifier&lt;/span&gt; [ ( &lt;span class=&#34;code-variable&#34;&gt;column-aliases&lt;/span&gt; ) ] AS (
     &lt;span class=&#34;code-variable&#34;&gt;non-recursive-term&lt;/span&gt;
     UNION [ ALL ]
     &lt;span class=&#34;code-variable&#34;&gt;recursive-term
&lt;/span&gt;   )
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Non-recursive and recursive terms are separated by UNION or UNION ALL:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The &lt;em&gt;&lt;code&gt;non-recursive-term&lt;/code&gt;&lt;/em&gt; query sets its result set in &lt;em&gt;&lt;code&gt;cte-identifier&lt;/code&gt;&lt;/em&gt;, which is subject to recursion in &lt;em&gt;&lt;code&gt;recursive-term&lt;/code&gt;&lt;/em&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The UNION statement&#39;s &lt;em&gt;&lt;code&gt;recursive-term&lt;/code&gt;&lt;/em&gt; recursively iterates over its own output. When recursion is complete, the results of all iterations are compiled and set in &lt;em&gt;&lt;code&gt;cte-identifier&lt;/code&gt;&lt;/em&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; ALTER SESSION SET PARAMETER WithClauseRecursionLimit=4; -- maximum recursion depth = 4
=&amp;gt; WITH RECURSIVE nums (n) AS (
   SELECT 1 -- non-recursive (base) term
   UNION ALL
     SELECT n+1 FROM nums -- recursive term
  )
SELECT n FROM nums; -- primary query
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This simple query executes as follows:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Executes the WITH RECURSIVE clause:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Evaluates the non-recursive term &lt;em&gt;SELECT 1&lt;/em&gt;, and places the result set—1—in &lt;code&gt;nums&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Iterates over the UNION ALL query (&lt;em&gt;SELECT n+1&lt;/em&gt;) until the number of iterations is greater than the configuration parameter WithClauseRecursionLimit.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Combines the results of all UNION queries and sets the result set in &lt;code&gt;nums&lt;/code&gt;, and then exits to the primary query.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Executes the primary query &lt;em&gt;SELECT n FROM nums&lt;/em&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
 n
---
 1
 2
 3
 4
 5
(5 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;In this case , WITH RECURSIVE clause exits after four iterations as per WithClauseRecursionLimit. If you restore WithClauseRecursionLimit to its default value of 8, then the clause exits after eight iterations:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; ALTER SESSION CLEAR PARAMETER WithClauseRecursionLimit;
=&amp;gt; WITH RECURSIVE nums (n) AS (
   SELECT 1
   UNION ALL
     SELECT n+1 FROM nums
  )
SELECT n FROM nums;
 n
---
 1
 2
 3
 4
 5
 6
 7
 8
 9
(9 rows)
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&#34;admonition important&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Important&lt;/h4&gt;
&lt;p&gt;Be careful to set WithClauseRecursionLimit only as high as needed to traverse the deepest hierarchies. Vertica sets no limit on this parameter; however, a high value can incur considerable overhead that adversely affects performance and exhausts system resources.&lt;/p&gt;
&lt;p&gt;If a high recursion count is required, then consider enabling materialization. For details, see &lt;a href=&#34;../../../../../en/sql-reference/statements/select/with-clause/with-clause-recursion/#WITHRecursionMaterialization&#34;&gt;WITH RECURSIVE Materialization&lt;/a&gt;.&lt;/p&gt;

&lt;/div&gt;

&lt;h2 id=&#34;restrictions&#34;&gt;Restrictions&lt;/h2&gt;
&lt;p&gt;The following restrictions apply:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The SELECT list of a non-recursive term cannot include the wildcard &lt;code&gt;*&lt;/code&gt; (asterisk) or the function &lt;a href=&#34;../../../../../en/sql-reference/functions/match-and-search-functions/regular-expression-functions/match-columns/#&#34;&gt;MATCH_COLUMNS&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A recursive term can reference the target CTE only once.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Recursive reference cannot appear within an outer join.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Recursive reference cannot appear within a subquery.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;WITH clauses do not support UNION options ORDER BY, LIMIT, and OFFSET.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;A small software company maintains the following data on employees and their managers:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT * FROM personnel.employees ORDER BY emp_id;
 emp_id |   fname   |   lname   | section_id |    section_name     |  section_leader  | leader_id
--------+-----------+-----------+------------+---------------------+------------------+-----------
      0 | Stephen   | Mulligan  |          0 |                     |                  |
      1 | Michael   | North     |        201 | Development         | Zoe Black        |         3
      2 | Megan     | Berry     |        202 | QA                  | Richard Chan     |        18
      3 | Zoe       | Black     |        101 | Product Development | Renuka Patil     |        24
      4 | Tim       | James     |        203 | IT                  | Ebuka Udechukwu  |        17
      5 | Bella     | Tucker    |        201 | Development         | Zoe Black        |         3
      6 | Alexandra | Climo     |        202 | QA                  | Richard Chan     |        18
      7 | Leonard   | Gray      |        203 | IT                  | Ebuka Udechukwu  |        17
      8 | Carolyn   | Henderson |        201 | Development         | Zoe Black        |         3
      9 | Ryan      | Henderson |        201 | Development         | Zoe Black        |         3
     10 | Frank     | Tucker    |        205 | Sales               | Benjamin Glover  |        29
     11 | Nathan    | Ferguson  |        102 | Sales Marketing     | Eric Redfield    |        28
     12 | Kevin     | Rampling  |        101 | Product Development | Renuka Patil     |        24
     13 | Tuy Kim   | Duong     |        201 | Development         | Zoe Black        |         3
     14 | Dwipendra | Sing      |        204 | Tech Support        | Sarah Feldman    |        26
     15 | Dylan     | Wijman    |        206 | Documentation       | Kevin Rampling   |        12
     16 | Tamar     | Sasson    |        207 | Marketing           | Nathan Ferguson  |        11
     17 | Ebuka     | Udechukwu |        101 | Product Development | Renuka Patil     |        24
     18 | Richard   | Chan      |        101 | Product Development | Renuka Patil     |        24
     19 | Maria     | del Rio   |        201 | Development         | Zoe Black        |         3
     20 | Hua       | Song      |        204 | Tech Support        | Sarah Feldman    |        26
     21 | Carmen    | Lopez     |        204 | Tech Support        | Sarah Feldman    |        26
     22 | Edgar     | Mejia     |        206 | Documentation       | Kevin Rampling   |        12
     23 | Riad      | Salim     |        201 | Development         | Zoe Black        |         3
     24 | Renuka    | Patil     |        100 | Executive Office    | Stephen Mulligan |         0
     25 | Rina      | Dsouza    |        202 | QA                  | Richard Chan     |        18
     26 | Sarah     | Feldman   |        101 | Product Development | Renuka Patil     |        24
     27 | Max       | Mills     |        102 | Sales Marketing     | Eric Redfield    |        28
     28 | Eric      | Redfield  |        100 | Executive Office    | Stephen Mulligan |         0
     29 | Benjamin  | Glover    |        102 | Sales Marketing     | Eric Redfield    |        28
     30 | Dominic   | King      |        205 | Sales               | Benjamin Glover  |        29
     32 | Ryan      | Metcalfe  |        206 | Documentation       | Kevin Rampling   |        12
     33 | Piers     | Paige     |        201 | Development         | Zoe Black        |         3
     34 | Nicola    | Kelly     |        207 | Marketing           | Nathan Ferguson  |        11
(34 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can query this data for employee-manager relationships through WITH RECURSIVE. For example, the following query&#39;s WITH RECURSIVE clause gets employee-manager relationships for employee Eric Redfield, including all employees who report directly and indirectly to him:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;WITH RECURSIVE managers (employeeID, employeeName, sectionID, section, lead, leadID)
 AS (SELECT emp_id, fname||&amp;#39; &amp;#39;||lname, section_id, section_name, section_leader, leader_id
      FROM personnel.employees WHERE fname||&amp;#39; &amp;#39;||lname = &amp;#39;Eric Redfield&amp;#39;
 UNION
    SELECT emp_id, fname||&amp;#39; &amp;#39;||lname AS employee_name, section_id, section_name, section_leader, leader_id FROM personnel.employees e
      JOIN managers m ON m.employeeID = e.leader_id)
 SELECT employeeID, employeeName, lead AS &amp;#39;Reports to&amp;#39;, section, leadID from managers ORDER BY sectionID, employeeName;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The WITH RECURSIVE clause defines the CTE &lt;code&gt;managers&lt;/code&gt;, and then executes in two phases:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;The non-recursive term populates &lt;code&gt;managers&lt;/code&gt; with data that it queries from &lt;code&gt;personnel.employees&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The recursive term&#39;s UNION query iterates over its own output until, on the fourth cycle, it finds no more data. The results of all iterations are then compiled and set in &lt;code&gt;managers&lt;/code&gt;, and the WITH CLAUSE exits to the primary query.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The primary query returns three levels of data from &lt;code&gt;managers&lt;/code&gt;—one for each recursive iteration:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../../../../../images/concepts-guide/recursive-with.png&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Similarly, the following query iterates over the same data to get all employee-manager relationships for employee Richard Chan, who is one level lower in the company chain of command:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;WITH RECURSIVE managers (employeeID, employeeName, sectionID, section, lead, leadID)
 AS (SELECT emp_id, fname||&amp;#39; &amp;#39;||lname, section_id, section_name, section_leader, leader_id
      FROM personnel.employees WHERE fname||&amp;#39; &amp;#39;||lname = &amp;#39;Richard Chan&amp;#39;
 UNION
    SELECT emp_id, fname||&amp;#39; &amp;#39;||lname AS employee_name, section_id, section_name, section_leader, leader_id FROM personnel.employees e
      JOIN managers m ON m.employeeID = e.leader_id)
 SELECT employeeID, employeeName, lead AS &amp;#39;Reports to&amp;#39;, section, leadID from managers ORDER BY sectionID, employeeName;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The WITH RECURSIVE clause executes as before, except this time it finds no more data after two iterations and exits. Accordingly, the primary query returns two levels of data from &lt;code&gt;managers&lt;/code&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;../../../../../images/concepts-guide/recursive-with2.png&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;&lt;a name=&#34;WITHRecursionMaterialization&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;with-recursive-materialization&#34;&gt;WITH RECURSIVE materialization&lt;/h2&gt;
&lt;p&gt;By default, materialization is disabled. In this case, OpenText™ Analytics Database rewrites the WITH RECURSIVE query into subqueries, as many as necessary for the required level of recursion.&lt;/p&gt;
&lt;p&gt;If recursion is very deep, the high number of query rewrites is liable to incur considerable overhead that adversely affects performance and exhausts system resources. In this case, consider enabling materialization, either with the configuration parameter &lt;a href=&#34;../../../../../en/sql-reference/config-parameters/general-parameters/#WithClauseMaterialization&#34;&gt;WithClauseMaterialization&lt;/a&gt;, or the hint &lt;a href=&#34;../../../../../en/sql-reference/language-elements/hints/enable-with-clause-materialization/#&#34;&gt;ENABLE_WITH_CLAUSE_MATERIALIZATION&lt;/a&gt;. In either case, intermediate result sets from all recursion levels are written to local temporary tables. When recursion is complete, the intermediate results in all temporary tables are compiled and passed on to the primary query.

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

If materialization is not possible, you can improve throughput on a resource pool that handles recursive queries by setting its &lt;a href=&#34;../../../../../en/sql-reference/statements/create-statements/create-resource-pool/#EXECUTIONPARALLELISM&#34;&gt;EXECUTIONPARALLELISM&lt;/a&gt; parameter to 1.

&lt;/div&gt;&lt;/p&gt;

      </description>
    </item>
    
  </channel>
</rss>
