def _infer_stmt_cardinality( ir: irast.FilteredStmt, *, scope_tree: irast.ScopeTreeNode, ctx: inference_context.InfCtx, ) -> qltypes.Cardinality: result_card = infer_cardinality( ir.subject if isinstance(ir, irast.MutatingStmt) else ir.result, is_mutation=isinstance(ir, irast.MutatingStmt), scope_tree=scope_tree, ctx=ctx, ) if ir.where: ir.where_card = infer_cardinality( ir.where, scope_tree=scope_tree, ctx=ctx, ) # Cross with AT_MOST_ONE to ensure result can be empty result_card = cartesian_cardinality([result_card, AT_MOST_ONE]) if result_card.is_multi() and ir.where: result_card = _analyse_filter_clause(ir.result, result_card, ir.where, scope_tree, ctx) _infer_matset_cardinality(ir.materialized_sets, scope_tree=scope_tree, ctx=ctx) return result_card
def compile_where_clause(ir_stmt: irast.FilteredStmt, where: Optional[qlast.Base], *, ctx: context.ContextLevel) -> None: if where is None: return with ctx.newscope(fenced=True) as subctx: subctx.path_scope.unnest_fence = True ir_expr = dispatch.compile(where, ctx=subctx) bool_t = ctx.env.get_track_schema_type(sn.QualName('std', 'bool')) ir_set = setgen.scoped_set(ir_expr, typehint=bool_t, ctx=subctx) ir_stmt.where = ir_set
def compile_where_clause(ir_stmt: irast.FilteredStmt, where: qlast.Base, *, ctx: context.ContextLevel) -> None: if where is None: return with ctx.newscope(fenced=True) as subctx: subctx.path_scope.unnest_fence = True ir_expr = dispatch.compile(where, ctx=subctx) bool_t = ctx.env.get_track_schema_type('std::bool') ir_set = setgen.scoped_set(ir_expr, typehint=bool_t, ctx=subctx) ir_stmt.where = ir_set stmtctx.get_expr_cardinality_later(target=ir_stmt, field='where_card', irexpr=ir_set, ctx=ctx)
def compile_where_clause( ir_stmt: irast.FilteredStmt, where: qlast.Base, *, ctx: context.ContextLevel) -> typing.Optional[irast.Base]: if where is None: return None else: with ctx.newscope(fenced=True) as subctx: subctx.path_scope.unnest_fence = True subctx.clause = 'where' if subctx.stmt.parent_stmt is None: subctx.toplevel_clause = subctx.clause ir_expr = dispatch.compile(where, ctx=subctx) bool_t = ctx.env.get_track_schema_object('std::bool') ir_set = setgen.scoped_set(ir_expr, typehint=bool_t, ctx=subctx) ir_stmt.where = ir_set stmtctx.get_expr_cardinality_later(target=ir_stmt, field='where_card', irexpr=ir_set, ctx=ctx)
def _infer_stmt_cardinality( ir: irast.FilteredStmt, *, scope_tree: irast.ScopeTreeNode, ctx: inference_context.InfCtx, ) -> qltypes.Cardinality: result_card = infer_cardinality( ir.subject if isinstance(ir, irast.MutatingStmt) else ir.result, is_mutation=isinstance(ir, irast.MutatingStmt), scope_tree=scope_tree, ctx=ctx, ) if ir.where: ir.where_card = infer_cardinality( ir.where, scope_tree=scope_tree, ctx=ctx, ) if result_card.is_multi() and ir.where: result_card = _analyse_filter_clause( ir.result, result_card, ir.where, scope_tree, ctx) return result_card