Skip to content

Commit

Permalink
Replace expand_inhview flag with is_explain and update comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
dnwpark committed Jul 8, 2024
1 parent 64a46c1 commit 8f4b050
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 29 deletions.
3 changes: 0 additions & 3 deletions edb/common/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand Down
6 changes: 3 additions & 3 deletions edb/edgeql/compiler/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion edb/edgeql/compiler/typegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions edb/pgsql/compiler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions edb/pgsql/compiler/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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
Expand Down
20 changes: 9 additions & 11 deletions edb/pgsql/compiler/relctx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion edb/pgsql/compiler/relgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
8 changes: 2 additions & 6 deletions edb/server/compiler/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 8f4b050

Please sign in to comment.