Skip to content

Commit

Permalink
Revert "Compile single globals into materialized CTEs (#6613)"
Browse files Browse the repository at this point in the history
This reverts commit 4c4ee28.
  • Loading branch information
msullivan committed Mar 15, 2024
1 parent 25d9e3b commit f17c217
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 32 deletions.
24 changes: 1 addition & 23 deletions edb/edgeql/compiler/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,29 +573,7 @@ def compile_GlobalExpr(
):
qry.limit = qlast.IntegerConstant(value='1')

target = dispatch.compile(qry, ctx=ctx)

# If the global is single, use type_rewrites to make sure it
# is computed only once in the SQL query.
if glob.get_cardinality(ctx.env.schema).is_single():
key = (setgen.get_set_type(target, ctx=ctx), False)
if not ctx.env.type_rewrites.get(key):
ctx.env.type_rewrites[key] = target
rewrite_target = ctx.env.type_rewrites[key]

# We need to have the set with expr=None, so that the rewrite
# will be applied, but we also need to wrap it with a
# card_inference_override so that we use the real cardinality
# instead of assuming it is MANY.
assert isinstance(rewrite_target, irast.Set)
target = setgen.new_set_from_set(target, expr=None, ctx=ctx)
wrap = irast.SelectStmt(
result=target,
card_inference_override=rewrite_target,
)
target = setgen.new_set_from_set(target, expr=wrap, ctx=ctx)

return target
return dispatch.compile(qry, ctx=ctx)

default = glob.get_default(ctx.env.schema)

Expand Down
13 changes: 4 additions & 9 deletions edb/pgsql/compiler/relctx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1395,12 +1395,7 @@ def range_for_material_objtype(

env = ctx.env

# If this is a view type, but it still appears in rewrites, that is
# because it is a global that we are caching.
if (
typeref.material_type is not None
and (typeref.id, include_descendants) not in ctx.env.type_rewrites
):
if typeref.material_type is not None:
typeref = typeref.material_type
is_global = typeref.material_type is not None

Expand All @@ -1418,7 +1413,7 @@ def range_for_material_objtype(
key = rw_key + (dml_source_key,)
force_cte = _needs_cte(typeref)
if (
(not ignore_rewrites or is_global)
not ignore_rewrites
and (
(rewrite := ctx.env.type_rewrites.get(rw_key)) is not None
or force_cte
Expand Down Expand Up @@ -1464,13 +1459,13 @@ def range_for_material_objtype(
# If we are expanding inhviews, we also expand type
# rewrites, so don't populate type_ctes. The normal
# case is to stick it in a CTE and cache that, though.
if ctx.env.expand_inhviews and not is_global:
if ctx.env.expand_inhviews:
type_rel = sctx.rel
else:
type_cte = pgast.CommonTableExpr(
name=ctx.env.aliases.get(f't_{typeref.name_hint}'),
query=sctx.rel,
materialized=is_global or force_cte,
materialized=force_cte,
)
ctx.type_ctes[key] = type_cte
type_rel = type_cte
Expand Down

0 comments on commit f17c217

Please sign in to comment.