diff --git a/edb/common/debug.py b/edb/common/debug.py index f3d445b741d0..5b719181497b 100644 --- a/edb/common/debug.py +++ b/edb/common/debug.py @@ -116,9 +116,6 @@ class flags(metaclass=FlagsMeta): edgeql_disable_normalization = Flag( doc="Disable EdgeQL normalization (constant extraction etc)") - edgeql_expand_inhviews = Flag( - doc="Force the EdgeQL compiler to expand inhviews *always*") - graphql_compile = Flag( doc="Debug GraphQL compiler.") diff --git a/edb/edgeql/compiler/options.py b/edb/edgeql/compiler/options.py index 11a345b20b2b..a13e0ecf2d4c 100644 --- a/edb/edgeql/compiler/options.py +++ b/edb/edgeql/compiler/options.py @@ -77,10 +77,10 @@ class GlobalCompilerOptions: #: definitions. func_params: Optional[s_func.ParameterLikeList] = None - #: Should the backend compiler expand out inheritance views instead of - #: using them. This is needed by EXPLAIN to maintain alias names in + #: Should the backend compiler expand inheritance CTEs in place. + #: This is needed by EXPLAIN to maintain alias names in #: the query plan. - expand_inhviews: bool = False + is_explain: bool = False #: Should type inheritance be expanded using CTEs. #: When not explaining CTEs can be used to provide access to a type and its diff --git a/edb/edgeql/compiler/typegen.py b/edb/edgeql/compiler/typegen.py index a22026d33219..8751ae6a137d 100644 --- a/edb/edgeql/compiler/typegen.py +++ b/edb/edgeql/compiler/typegen.py @@ -403,7 +403,7 @@ def type_to_typeref( or expr_type is s_types.ExprType.Delete or ( ( - env.options.expand_inhviews or + env.options.is_explain or env.options.use_inheritance_ctes ) and isinstance(t, s_objtypes.ObjectType) diff --git a/edb/pgsql/compiler/__init__.py b/edb/pgsql/compiler/__init__.py index df496c803512..6f9895fec817 100644 --- a/edb/pgsql/compiler/__init__.py +++ b/edb/pgsql/compiler/__init__.py @@ -66,7 +66,7 @@ def compile_ir_to_sql_tree( singleton_mode: bool = False, named_param_prefix: Optional[tuple[str, ...]] = None, expected_cardinality_one: bool = False, - expand_inhviews: bool = False, + is_explain: bool = False, use_inheritance_ctes: bool = False, external_rvars: Optional[ Mapping[Tuple[irast.PathId, pgce.PathAspect], pgast.PathRangeVar] @@ -128,7 +128,7 @@ def compile_ir_to_sql_tree( type_rewrites=type_rewrites, ignore_object_shapes=ignore_shapes, explicit_top_cast=explicit_top_cast, - expand_inhviews=expand_inhviews, + is_explain=is_explain, use_inheritance_ctes=use_inheritance_ctes, singleton_mode=singleton_mode, scope_tree_nodes=scope_tree_nodes, diff --git a/edb/pgsql/compiler/context.py b/edb/pgsql/compiler/context.py index 439609e714ea..e62d23396345 100644 --- a/edb/pgsql/compiler/context.py +++ b/edb/pgsql/compiler/context.py @@ -552,7 +552,7 @@ def __init__( expected_cardinality_one: bool, ignore_object_shapes: bool, singleton_mode: bool, - expand_inhviews: bool, + is_explain: bool, use_inheritance_ctes: bool, explicit_top_cast: Optional[irast.TypeRef], query_params: List[irast.Param], @@ -572,7 +572,7 @@ def __init__( self.expected_cardinality_one = expected_cardinality_one self.ignore_object_shapes = ignore_object_shapes self.singleton_mode = singleton_mode - self.expand_inhviews = expand_inhviews + self.is_explain = is_explain self.use_inheritance_ctes = use_inheritance_ctes self.explicit_top_cast = explicit_top_cast self.query_params = query_params diff --git a/edb/pgsql/compiler/relctx.py b/edb/pgsql/compiler/relctx.py index 3d9dbad417d3..5bd2e0a3a95e 100644 --- a/edb/pgsql/compiler/relctx.py +++ b/edb/pgsql/compiler/relctx.py @@ -1609,10 +1609,10 @@ def range_for_material_objtype( sctx.rel_overlays = context.RelOverlays() dispatch.visit(rewrite, ctx=sctx) - # If we are expanding inhviews, we also expand type + # If we are explaining, 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.is_explain and not is_global: type_rel = sctx.rel else: type_cte = pgast.CommonTableExpr( @@ -1652,9 +1652,9 @@ def range_for_material_objtype( if ( # When we are compiling a query for EXPLAIN, expand out type # references to an explicit union of all the types, rather than - # relying on the inheritance views. This allows postgres to actually - # give us back the alias names that we use for relations, which we - # use to track which parts of the query are being referred to. + # using a CTE. This allows postgres to actually give us back the + # alias names that we use for relations, which we use to track which + # parts of the query are being referred to. not ctx.env.use_inheritance_ctes # Don't use CTEs if there is no inheritance. (ie. There is only a @@ -2214,7 +2214,7 @@ def _range_for_component_ptrref( ) # Add the path to the CTE's query. This allows for the proper - # path mapping ot occur when processing link properties + # path mapping to occur when processing link properties inheritance_qry.path_id = component_ptrref_path_id ptr_cte = pgast.CommonTableExpr( @@ -2272,9 +2272,7 @@ def _range_for_component_ptrref( ctx=sctx ) - # Only fire off the overlays at the end of each expanded inhview. - # This only matters when we are doing expand_inhviews, and prevents - # us from repeating the overlays many times in that case. + # Add overlays at the end of each expanded inheritance. overlays = get_ptr_rel_overlays( component_ptrref, dml_source=dml_source, ctx=ctx) if overlays and not for_mutation: @@ -2357,8 +2355,8 @@ def _get_ptrref_descendants( include_descendants: bool, for_mutation: bool, ) -> list[irast.PointerRef]: - # expand_inhviews helps support EXPLAIN. see - # range_for_material_objtype for details. + # When doing EXPLAIN, don't use CTEs. See range_for_material_objtype for + # details. if ( include_descendants and not for_mutation diff --git a/edb/pgsql/compiler/relgen.py b/edb/pgsql/compiler/relgen.py index 811d350c6189..0bbd8442aac8 100644 --- a/edb/pgsql/compiler/relgen.py +++ b/edb/pgsql/compiler/relgen.py @@ -243,7 +243,7 @@ def get_set_rvar( rvars = _get_expr_set_rvar(ir_set.expr, ir_set, ctx=subctx) relctx.update_scope_masks(ir_set, rvars.main.rvar, ctx=subctx) - if ctx.env.expand_inhviews: + if ctx.env.is_explain: for srvar in rvars.new: if not srvar.rvar.ir_origins: srvar.rvar.ir_origins = [] diff --git a/edb/server/compiler/compiler.py b/edb/server/compiler/compiler.py index a93f93336633..39f23ef2774b 100644 --- a/edb/server/compiler/compiler.py +++ b/edb/server/compiler/compiler.py @@ -1700,11 +1700,7 @@ def _get_compile_options( ctx, 'apply_access_policies'), allow_user_specified_id=_get_config_val( ctx, 'allow_user_specified_id') or ctx.schema_reflection_mode, - expand_inhviews=( - debug.flags.edgeql_expand_inhviews - and not ctx.bootstrap_mode - and not ctx.schema_reflection_mode - ) or is_explain, + is_explain=is_explain, use_inheritance_ctes=( not is_explain and not ctx.bootstrap_mode @@ -1894,7 +1890,7 @@ def _compile_ql_query( expected_cardinality_one=ctx.expected_cardinality_one, output_format=_convert_format(ctx.output_format), backend_runtime_params=ctx.backend_runtime_params, - expand_inhviews=options.expand_inhviews, + is_explain=options.is_explain, use_inheritance_ctes=options.use_inheritance_ctes, detach_params=(use_persistent_cache and cache_mode is config.QueryCacheMode.PgFunc),