@@ -18,79 +18,6 @@ class _LimitSpec(NamedTuple):
18
18
offset : int
19
19
20
20
21
- class _CorrelatedRefCheck :
22
- def __init__ (self , query , node ):
23
- self .query = query
24
- self .ctx = query .context
25
- self .node = node
26
- self .query_roots = frozenset (
27
- an .find_immediate_parent_tables (self .query .table_set )
28
- )
29
- self .has_foreign_root = False
30
- self .has_query_root = False
31
- self .seen = set ()
32
-
33
- def get_result (self ):
34
- self .visit (self .node , in_subquery = False )
35
- return self .has_query_root and self .has_foreign_root
36
-
37
- def visit (self , node , in_subquery ):
38
- if node in self .seen :
39
- return
40
-
41
- in_subquery |= self .is_subquery (node )
42
-
43
- for arg in node .args :
44
- if isinstance (arg , ops .TableNode ):
45
- self .visit_table (arg , in_subquery = in_subquery )
46
- elif isinstance (arg , ops .Node ):
47
- self .visit (arg , in_subquery = in_subquery )
48
- elif isinstance (arg , tuple ):
49
- for item in arg :
50
- self .visit (item , in_subquery = in_subquery )
51
-
52
- self .seen .add (node )
53
-
54
- def is_subquery (self , node ):
55
- return isinstance (
56
- node ,
57
- (
58
- ops .TableArrayView ,
59
- ops .ExistsSubquery ,
60
- ops .NotExistsSubquery ,
61
- ),
62
- ) or (isinstance (node , ops .TableColumn ) and not self .is_root (node .table ))
63
-
64
- def visit_table (self , node , in_subquery ):
65
- if isinstance (node , (ops .PhysicalTable , ops .SelfReference )):
66
- self .ref_check (node , in_subquery = in_subquery )
67
-
68
- for arg in node .args :
69
- if isinstance (arg , tuple ):
70
- for item in arg :
71
- self .visit (item , in_subquery = in_subquery )
72
- elif isinstance (arg , ops .Node ):
73
- self .visit (arg , in_subquery = in_subquery )
74
-
75
- def ref_check (self , node , in_subquery ) -> None :
76
- ctx = self .ctx
77
-
78
- is_root = self .is_root (node )
79
-
80
- self .has_query_root |= is_root and in_subquery
81
- self .has_foreign_root |= not is_root and in_subquery
82
-
83
- if (
84
- not is_root
85
- and not ctx .has_ref (node )
86
- and (not in_subquery or ctx .has_ref (node , parent_contexts = True ))
87
- ):
88
- ctx .make_alias (node )
89
-
90
- def is_root (self , what : ops .TableNode ) -> bool :
91
- return what in self .query_roots
92
-
93
-
94
21
def _get_scalar (field ):
95
22
def scalar_handler (results ):
96
23
return results [field ][0 ]
@@ -149,11 +76,6 @@ def to_select(
149
76
150
77
return select_query
151
78
152
- @staticmethod
153
- def _foreign_ref_check (query , expr ):
154
- checker = _CorrelatedRefCheck (query , expr )
155
- return checker .get_result ()
156
-
157
79
@staticmethod
158
80
def _adapt_operation (node ):
159
81
# Non-table expressions need to be adapted to some well-formed table
0 commit comments