18 for subquery in rqlst.with_: |
18 for subquery in rqlst.with_: |
19 annotator._annotate_union(subquery.query) |
19 annotator._annotate_union(subquery.query) |
20 #if server.DEBUG: |
20 #if server.DEBUG: |
21 # print '-------- sql annotate', repr(rqlst) |
21 # print '-------- sql annotate', repr(rqlst) |
22 getrschema = annotator.schema.rschema |
22 getrschema = annotator.schema.rschema |
23 has_text_query = False |
23 has_text_query = need_intersect = False |
24 need_distinct = rqlst.distinct |
24 need_distinct = rqlst.distinct |
25 for rel in rqlst.iget_nodes(Relation): |
25 for rel in rqlst.iget_nodes(Relation): |
26 if rel.neged(strict=True): |
26 if rel.neged(strict=True): |
27 if rel.is_types_restriction(): |
27 if rel.is_types_restriction(): |
28 need_distinct = True |
28 need_distinct = True |
29 else: |
29 else: |
30 rschema = getrschema(rel.r_type) |
30 rschema = getrschema(rel.r_type) |
31 if rschema.inlined: |
31 if not rschema.is_final(): |
32 try: |
32 # if one of the relation's variable is ambiguous, an intersection |
33 var = rel.children[1].children[0].variable |
33 # will be necessary |
34 except AttributeError: |
34 for vref in rel.get_nodes(VariableRef): |
35 pass # rewritten variable |
35 var = vref.variable |
|
36 if not var.stinfo['selected'] and len(var.stinfo['possibletypes']) > 1: |
|
37 need_intersect = True |
|
38 break |
36 else: |
39 else: |
37 if not var.stinfo['constnode']: |
40 if rschema.inlined: |
38 need_distinct = True |
41 try: |
|
42 var = rel.children[1].children[0].variable |
|
43 except AttributeError: |
|
44 pass # rewritten variable |
|
45 else: |
|
46 if not var.stinfo['constnode']: |
|
47 need_distinct = True |
39 elif getrschema(rel.r_type).symetric: |
48 elif getrschema(rel.r_type).symetric: |
40 for vref in rel.iget_nodes(VariableRef): |
49 for vref in rel.iget_nodes(VariableRef): |
41 stinfo = vref.variable.stinfo |
50 stinfo = vref.variable.stinfo |
42 if not stinfo['constnode'] and stinfo['selected']: |
51 if not stinfo['constnode'] and stinfo['selected']: |
43 need_distinct = True |
52 need_distinct = True |
137 try: |
146 try: |
138 stinfo['principal'] = _select_principal(var.sqlscope, joins) |
147 stinfo['principal'] = _select_principal(var.sqlscope, joins) |
139 except CantSelectPrincipal: |
148 except CantSelectPrincipal: |
140 stinfo['invariant'] = False |
149 stinfo['invariant'] = False |
141 rqlst.need_distinct = need_distinct |
150 rqlst.need_distinct = need_distinct |
|
151 rqlst.need_intersect = need_intersect |
142 return has_text_query |
152 return has_text_query |
143 |
153 |
144 |
154 |
145 |
155 |
146 class CantSelectPrincipal(Exception): pass |
156 class CantSelectPrincipal(Exception): pass |