diff --git a/edb/edgeql/compiler/expr.py b/edb/edgeql/compiler/expr.py index 359ce6ae9cd..470427573e0 100644 --- a/edb/edgeql/compiler/expr.py +++ b/edb/edgeql/compiler/expr.py @@ -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) diff --git a/edb/pgsql/compiler/relctx.py b/edb/pgsql/compiler/relctx.py index ea86e02b5e7..bfdc53b67d9 100644 --- a/edb/pgsql/compiler/relctx.py +++ b/edb/pgsql/compiler/relctx.py @@ -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 @@ -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 @@ -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