Initialize collections related to CTEs only if a CTE is located, to save on the overhead of these collections otherwise.
(self)
| 1613 | |
| 1614 | @util.memoized_instancemethod |
| 1615 | def _init_cte_state(self) -> MutableMapping[CTE, str]: |
| 1616 | """Initialize collections related to CTEs only if |
| 1617 | a CTE is located, to save on the overhead of |
| 1618 | these collections otherwise. |
| 1619 | |
| 1620 | """ |
| 1621 | # collect CTEs to tack on top of a SELECT |
| 1622 | # To store the query to print - Dict[cte, text_query] |
| 1623 | ctes: MutableMapping[CTE, str] = util.OrderedDict() |
| 1624 | self.ctes = ctes |
| 1625 | |
| 1626 | # Detect same CTE references - Dict[(level, name), cte] |
| 1627 | # Level is required for supporting nesting |
| 1628 | self.ctes_by_level_name = {} |
| 1629 | |
| 1630 | # To retrieve key/level in ctes_by_level_name - |
| 1631 | # Dict[cte_reference, (level, cte_name, cte_opts)] |
| 1632 | self.level_name_by_cte = {} |
| 1633 | |
| 1634 | self.ctes_recursive = False |
| 1635 | |
| 1636 | return ctes |
| 1637 | |
| 1638 | @contextlib.contextmanager |
| 1639 | def _nested_result(self): |