Initialize collections related to CTEs only if a CTE is located, to save on the overhead of these collections otherwise.
(self)
| 1669 | |
| 1670 | @util.memoized_instancemethod |
| 1671 | def _init_cte_state(self) -> MutableMapping[CTE, str]: |
| 1672 | """Initialize collections related to CTEs only if |
| 1673 | a CTE is located, to save on the overhead of |
| 1674 | these collections otherwise. |
| 1675 | |
| 1676 | """ |
| 1677 | # collect CTEs to tack on top of a SELECT |
| 1678 | # To store the query to print - Dict[cte, text_query] |
| 1679 | ctes: MutableMapping[CTE, str] = util.OrderedDict() |
| 1680 | self.ctes = ctes |
| 1681 | |
| 1682 | # Detect same CTE references - Dict[(level, name), cte] |
| 1683 | # Level is required for supporting nesting |
| 1684 | self.ctes_by_level_name = {} |
| 1685 | |
| 1686 | # To retrieve key/level in ctes_by_level_name - |
| 1687 | # Dict[cte_reference, (level, cte_name, cte_opts)] |
| 1688 | self.level_name_by_cte = {} |
| 1689 | |
| 1690 | self.ctes_recursive = False |
| 1691 | |
| 1692 | return ctes |
| 1693 | |
| 1694 | @contextlib.contextmanager |
| 1695 | def _nested_result(self): |