0002-change-function-name.patch
text/x-diff
Filename: 0002-change-function-name.patch
Type: text/x-diff
Part: 1
Patch
Format: unified
Series: patch 0002
| File | + | − |
|---|---|---|
| src/backend/optimizer/path/allpaths.c | 9 | 10 |
| src/backend/optimizer/path/equivclass.c | 18 | 15 |
| src/include/optimizer/paths.h | 3 | 4 |
diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c
index edba5e49a8..286052e3d6 100644
--- a/src/backend/optimizer/path/allpaths.c
+++ b/src/backend/optimizer/path/allpaths.c
@@ -2697,20 +2697,19 @@ get_useful_pathkeys_for_relation(PlannerInfo *root, RelOptInfo *rel,
EquivalenceClass *pathkey_ec = pathkey->pk_eclass;
/*
- * We can only build a sort for pathkeys which contain an EC
- * member in the current relation's target, so ignore any suffix
- * of the list as soon as we find a pathkey without an EC member
- * in the relation.
+ * We can only build a sort for pathkeys that contain a safe EC
+ * member computable from the current relation's reltarget, so
+ * ignore the remainder of the list as soon as we find a pathkey
+ * without such a member.
*
- * By still returning the prefix of the pathkeys list that does
- * meet criteria of EC membership in the current relation, we
- * enable not just an incremental sort on the entirety of
- * query_pathkeys but also incremental sort below a JOIN.
+ * It's still worthwhile to return any prefix of the pathkeys list
+ * that meets this requirement, as we may be able to do an
+ * incremental sort.
*
* If requested, ensure the expression is parallel safe too.
*/
- if (!find_em_expr_usable_for_sorting_rel(root, pathkey_ec, rel,
- require_parallel_safe))
+ if (!relation_has_safe_ec_member(root, rel, pathkey_ec,
+ require_parallel_safe))
break;
npathkeys++;
diff --git a/src/backend/optimizer/path/equivclass.c b/src/backend/optimizer/path/equivclass.c
index 5f7e505950..9d2d1022d1 100644
--- a/src/backend/optimizer/path/equivclass.c
+++ b/src/backend/optimizer/path/equivclass.c
@@ -943,17 +943,20 @@ find_em_expr_for_rel(EquivalenceClass *ec, RelOptInfo *rel)
}
/*
- * Find an equivalence class member expression that can be used to build
- * a sort node using the provided relation; return NULL if no candidate.
+ * relation_has_safe_ec_member
+ * Can this relation be sorted on a "safe" member of this EC?
*
- * The selected expression must be one that prepare_sort_from_pathkeys knows
- * how to deal with, and we also apply a few additional constraints based on
- * the fact that the desired sort will be done within the scan/join part of
- * the plan.
+ * To succeed, we must find an EC member that prepare_sort_from_pathkeys knows
+ * how to sort on, given the rel's reltarget as input. There are also a few
+ * additional constraints based on the fact that the desired sort will be done
+ * within the scan/join part of the plan.
+ *
+ * At some point we might want to return the identified EquivalenceMember,
+ * but for now, callers only want to know if there is one.
*/
-Expr *
-find_em_expr_usable_for_sorting_rel(PlannerInfo *root, EquivalenceClass *ec,
- RelOptInfo *rel, bool require_parallel_safe)
+bool
+relation_has_safe_ec_member(PlannerInfo *root, RelOptInfo *rel,
+ EquivalenceClass *ec, bool require_parallel_safe)
{
PathTarget *target = rel->reltarget;
EquivalenceMember *em;
@@ -963,7 +966,7 @@ find_em_expr_usable_for_sorting_rel(PlannerInfo *root, EquivalenceClass *ec,
* Reject volatile ECs immediately; such sorts must always be postponed.
*/
if (ec->ec_has_volatile)
- return NULL;
+ return false;
/*
* Try to find an EM directly matching some reltarget member.
@@ -990,7 +993,7 @@ find_em_expr_usable_for_sorting_rel(PlannerInfo *root, EquivalenceClass *ec,
(Node *) em->em_expr))
continue;
- return em->em_expr;
+ return true;
}
/*
@@ -998,7 +1001,7 @@ find_em_expr_usable_for_sorting_rel(PlannerInfo *root, EquivalenceClass *ec,
*/
em = find_computable_ec_member(ec, target->exprs, rel->relids);
if (!em)
- return NULL;
+ return false;
/*
* Reject expressions involving set-returning functions, as those can't be
@@ -1006,7 +1009,7 @@ find_em_expr_usable_for_sorting_rel(PlannerInfo *root, EquivalenceClass *ec,
* member that isn't a SRF, but it's quite unlikely there'd be one.)
*/
if (IS_SRF_CALL((Node *) em->em_expr))
- return NULL;
+ return false;
/*
* If requested, reject expressions that are not parallel-safe. (Again,
@@ -1014,9 +1017,9 @@ find_em_expr_usable_for_sorting_rel(PlannerInfo *root, EquivalenceClass *ec,
*/
if (require_parallel_safe && !is_parallel_safe(root,
(Node *) em->em_expr))
- return NULL;
+ return false;
- return em->em_expr;
+ return true;
}
/*
diff --git a/src/include/optimizer/paths.h b/src/include/optimizer/paths.h
index 1d2a608ad9..f13b9a37e9 100644
--- a/src/include/optimizer/paths.h
+++ b/src/include/optimizer/paths.h
@@ -142,10 +142,9 @@ extern EquivalenceMember *find_computable_ec_member(EquivalenceClass *ec,
List *exprs,
Relids relids);
extern Expr *find_em_expr_for_rel(EquivalenceClass *ec, RelOptInfo *rel);
-extern Expr *find_em_expr_usable_for_sorting_rel(PlannerInfo *root,
- EquivalenceClass *ec,
- RelOptInfo *rel,
- bool require_parallel_safe);
+extern bool relation_has_safe_ec_member(PlannerInfo *root, RelOptInfo *rel,
+ EquivalenceClass *ec,
+ bool require_parallel_safe);
extern void generate_base_implied_equalities(PlannerInfo *root);
extern List *generate_join_implied_equalities(PlannerInfo *root,
Relids join_relids,