Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor improvments for SQL DML #7854

Merged
merged 4 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions edb/ir/scopetree.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,9 +873,8 @@ def find_visible_ex(
]:
"""Find the visible node with the given *path_id*."""
namespaces: Set[pathid.Namespace] = set()
finfo = FenceInfo(False, False)
found = None

nodes: List[ScopeTreeNode] = []
for node, ans in self.ancestors_and_namespaces:
if (node.path_id is not None
and _paths_equal(node.path_id, path_id, namespaces)):
Expand All @@ -894,7 +893,11 @@ def find_visible_ex(
namespaces |= ans

if node is not self:
finfo |= node.fence_info_ex(path_id, namespaces)
nodes.append(node)

finfo = FenceInfo(False, False)
for node in nodes:
finfo |= node.fence_info_ex(path_id, namespaces)

if found and found.is_group and not allow_group:
found = None
Expand Down
50 changes: 37 additions & 13 deletions edb/pgsql/resolver/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ def _collect_dml_stmts(stmt: pgast.Base) -> List[pgast.DMLQuery]:
return res


ExternalRel = Tuple[pgast.BaseRelation, Tuple[pgce.PathAspect, ...]]


@dataclasses.dataclass(kw_only=True, eq=False, repr=False)
class UncompiledDML:
# the input DML node
Expand All @@ -188,9 +191,7 @@ class UncompiledDML:
ql_returning_shape: List[qlast.ShapeElement]
ql_singletons: Set[irast.PathId]
ql_anchors: Mapping[str, irast.PathId]
external_rels: Mapping[
irast.PathId, Tuple[pgast.BaseRelation, Tuple[str, ...]]
]
external_rels: Mapping[irast.PathId, ExternalRel]

# list of column names of the subject type, along with pointer name
# these columns will be available within RETURNING clause
Expand Down Expand Up @@ -419,7 +420,12 @@ def _uncompile_insert_object_stmt(
ql_returning_shape=ql_returning_shape,
ql_singletons={value_id},
ql_anchors={value_name: value_id},
external_rels={value_id: (value_rel, ('source', 'identity'))},
external_rels={
value_id: (
value_rel,
(pgce.PathAspect.SOURCE,),
)
},
early_result=context.CompiledDML(
value_cte_name=value_cte_name,
value_relation_input=value_relation,
Expand Down Expand Up @@ -683,7 +689,12 @@ def _uncompile_insert_pointer_stmt(
ql_returning_shape=ql_returning_shape,
ql_singletons={source_id},
ql_anchors={value_name: source_id},
external_rels={source_id: (value_rel, ('source', 'identity'))},
external_rels={
source_id: (
value_rel,
(pgce.PathAspect.SOURCE,),
)
},
early_result=context.CompiledDML(
value_cte_name=value_cte_name,
value_relation_input=value_relation,
Expand Down Expand Up @@ -908,7 +919,12 @@ def _uncompile_delete_object_stmt(
ql_returning_shape=ql_returning_shape,
ql_singletons={value_id},
ql_anchors={value_name: value_id},
external_rels={value_id: (value_rel, ('source', 'identity'))},
external_rels={
value_id: (
value_rel,
(pgce.PathAspect.SOURCE,),
)
},
early_result=context.CompiledDML(
value_cte_name=value_cte_name,
value_relation_input=value_relation,
Expand Down Expand Up @@ -1095,7 +1111,12 @@ def _uncompile_delete_pointer_stmt(
ql_returning_shape=ql_returning_shape,
ql_singletons={source_id},
ql_anchors={value_name: source_id},
external_rels={source_id: (value_rel, ('source', 'identity'))},
external_rels={
source_id: (
value_rel,
(pgce.PathAspect.SOURCE,),
)
},
early_result=context.CompiledDML(
value_cte_name=value_cte_name,
value_relation_input=value_relation,
Expand Down Expand Up @@ -1345,7 +1366,12 @@ def is_default(e: pgast.BaseExpr) -> bool:
ql_returning_shape=ql_returning_shape,
ql_singletons={value_id},
ql_anchors={value_name: value_id},
external_rels={value_id: (value_rel, ('source', 'identity'))},
external_rels={
value_id: (
value_rel,
(pgce.PathAspect.SOURCE,),
)
},
early_result=context.CompiledDML(
value_cte_name=value_cte_name,
value_relation_input=value_relation,
Expand Down Expand Up @@ -1397,7 +1423,7 @@ def _compile_uncompiled_dml(
ql_aliases.append(
qlast.AliasedExpr(
alias=name,
expr=qlast.DetachedExpr(expr=stmt.ql_stmt),
expr=stmt.ql_stmt,
)
)
ql_stmt_shape.append(
Expand Down Expand Up @@ -1524,7 +1550,7 @@ def _merge_and_prepare_external_rels(
stmts: List[UncompiledDML],
stmt_names: List[str],
) -> Tuple[
Dict[irast.PathId, Tuple[pgast.BaseRelation, Tuple[str, ...]]],
Mapping[irast.PathId, ExternalRel],
List[irast.MutatingStmt],
]:
"""Construct external rels used for compiling all DML statements at once."""
Expand All @@ -1548,9 +1574,7 @@ def _merge_and_prepare_external_rels(
continue
shape_elements_by_name[rptr_name.name] = b.expr.expr

external_rels: Dict[
irast.PathId, Tuple[pgast.BaseRelation, Tuple[str, ...]]
] = {}
external_rels: Dict[irast.PathId, ExternalRel] = {}
ir_stmts = []
for stmt, name in zip(stmts, stmt_names):
# find the associated binding (this is real funky)
Expand Down