diff --git a/src/backend/optimizer/path/equivclass.c b/src/backend/optimizer/path/equivclass.c index 8f6f005ecb..1c0deab0f6 100644 --- a/src/backend/optimizer/path/equivclass.c +++ b/src/backend/optimizer/path/equivclass.c @@ -833,12 +841,13 @@ find_computable_ec_member(PlannerInfo *root, bool require_parallel_safe) { ListCell *lc; + Relids r; + + r = pull_varnos(root, (Node *) exprs); foreach(lc, ec->ec_members) { EquivalenceMember *em = (EquivalenceMember *) lfirst(lc); - List *exprvars; - ListCell *lc2; /* * We shouldn't be trying to sort by an equivalence class that @@ -854,21 +863,8 @@ find_computable_ec_member(PlannerInfo *root, !bms_is_subset(em->em_relids, relids)) continue; - /* - * Match if all Vars and quasi-Vars are available in "exprs". - */ - exprvars = pull_var_clause((Node *) em->em_expr, - PVC_INCLUDE_AGGREGATES | - PVC_INCLUDE_WINDOWFUNCS | - PVC_INCLUDE_PLACEHOLDERS); - foreach(lc2, exprvars) - { - if (!is_exprlist_member(lfirst(lc2), exprs)) - break; - } - list_free(exprvars); - if (lc2) - continue; /* we hit a non-available Var */ + if (!bms_is_subset(em->em_relids, r)) + continue; /* * If requested, reject expressions that are not parallel-safe. We @@ -884,31 +880,6 @@ find_computable_ec_member(PlannerInfo *root, return NULL; } -/* - * is_exprlist_member - * Subroutine for find_computable_ec_member: is "node" in "exprs"? - * - * Per the requirements of that function, "exprs" might or might not have - * TargetEntry superstructure. - */ -static bool -is_exprlist_member(Expr *node, List *exprs) -{ - ListCell *lc; - - foreach(lc, exprs) - { - Expr *expr = (Expr *) lfirst(lc); - - if (expr && IsA(expr, TargetEntry)) - expr = ((TargetEntry *) expr)->expr; - - if (equal(node, expr)) - return true; - } - return false; -} - /* * relation_can_be_sorted_early * Can this relation be sorted on this EC before the final output step?