Skip to content

Commit 7645376

Browse files
committed
Rename find_em_expr_usable_for_sorting_rel.
I didn't particularly like this function name, as it fails to express what's going on. Also, returning the sort expression alone isn't too helpful --- typically, a caller would also need some other fields of the EquivalenceMember. But the sole caller really only needs a bool result, so let's make it "bool relation_can_be_sorted_early()". Discussion: https://postgr.es/m/91f3ec99-85a4-fa55-ea74-33f85a5c651f@swarm64.com
1 parent 3753982 commit 7645376

File tree

3 files changed

+28
-27
lines changed

3 files changed

+28
-27
lines changed

src/backend/optimizer/path/allpaths.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,20 +2697,19 @@ get_useful_pathkeys_for_relation(PlannerInfo *root, RelOptInfo *rel,
26972697
EquivalenceClass *pathkey_ec = pathkey->pk_eclass;
26982698

26992699
/*
2700-
* We can only build a sort for pathkeys which contain an EC
2701-
* member in the current relation's target, so ignore any suffix
2702-
* of the list as soon as we find a pathkey without an EC member
2703-
* in the relation.
2700+
* We can only build a sort for pathkeys that contain a
2701+
* safe-to-compute-early EC member computable from the current
2702+
* relation's reltarget, so ignore the remainder of the list as
2703+
* soon as we find a pathkey without such a member.
27042704
*
2705-
* By still returning the prefix of the pathkeys list that does
2706-
* meet criteria of EC membership in the current relation, we
2707-
* enable not just an incremental sort on the entirety of
2708-
* query_pathkeys but also incremental sort below a JOIN.
2705+
* It's still worthwhile to return any prefix of the pathkeys list
2706+
* that meets this requirement, as we may be able to do an
2707+
* incremental sort.
27092708
*
2710-
* If requested, ensure the expression is parallel safe too.
2709+
* If requested, ensure the sort expression is parallel-safe too.
27112710
*/
2712-
if (!find_em_expr_usable_for_sorting_rel(root, pathkey_ec, rel,
2713-
require_parallel_safe))
2711+
if (!relation_can_be_sorted_early(root, rel, pathkey_ec,
2712+
require_parallel_safe))
27142713
break;
27152714

27162715
npathkeys++;

src/backend/optimizer/path/equivclass.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -961,18 +961,21 @@ find_em_expr_for_rel(EquivalenceClass *ec, RelOptInfo *rel)
961961
}
962962

963963
/*
964-
* Find an equivalence class member expression that can be used to build
965-
* a sort node using the provided relation; return NULL if no candidate.
964+
* relation_can_be_sorted_early
965+
* Can this relation be sorted on this EC before the final output step?
966966
*
967967
* To succeed, we must find an EC member that prepare_sort_from_pathkeys knows
968968
* how to sort on, given the rel's reltarget as input. There are also a few
969969
* additional constraints based on the fact that the desired sort will be done
970-
* within the scan/join part of the plan. Also, non-parallel-safe expressions
971-
* are ignored if 'require_parallel_safe'.
970+
* "early", within the scan/join part of the plan. Also, non-parallel-safe
971+
* expressions are ignored if 'require_parallel_safe'.
972+
*
973+
* At some point we might want to return the identified EquivalenceMember,
974+
* but for now, callers only want to know if there is one.
972975
*/
973-
Expr *
974-
find_em_expr_usable_for_sorting_rel(PlannerInfo *root, EquivalenceClass *ec,
975-
RelOptInfo *rel, bool require_parallel_safe)
976+
bool
977+
relation_can_be_sorted_early(PlannerInfo *root, RelOptInfo *rel,
978+
EquivalenceClass *ec, bool require_parallel_safe)
976979
{
977980
PathTarget *target = rel->reltarget;
978981
EquivalenceMember *em;
@@ -982,7 +985,7 @@ find_em_expr_usable_for_sorting_rel(PlannerInfo *root, EquivalenceClass *ec,
982985
* Reject volatile ECs immediately; such sorts must always be postponed.
983986
*/
984987
if (ec->ec_has_volatile)
985-
return NULL;
988+
return false;
986989

987990
/*
988991
* Try to find an EM directly matching some reltarget member.
@@ -1012,7 +1015,7 @@ find_em_expr_usable_for_sorting_rel(PlannerInfo *root, EquivalenceClass *ec,
10121015
!is_parallel_safe(root, (Node *) em->em_expr))
10131016
continue;
10141017

1015-
return em->em_expr;
1018+
return true;
10161019
}
10171020

10181021
/*
@@ -1021,7 +1024,7 @@ find_em_expr_usable_for_sorting_rel(PlannerInfo *root, EquivalenceClass *ec,
10211024
em = find_computable_ec_member(root, ec, target->exprs, rel->relids,
10221025
require_parallel_safe);
10231026
if (!em)
1024-
return NULL;
1027+
return false;
10251028

10261029
/*
10271030
* Reject expressions involving set-returning functions, as those can't be
@@ -1030,9 +1033,9 @@ find_em_expr_usable_for_sorting_rel(PlannerInfo *root, EquivalenceClass *ec,
10301033
* belong to multi-member ECs.)
10311034
*/
10321035
if (IS_SRF_CALL((Node *) em->em_expr))
1033-
return NULL;
1036+
return false;
10341037

1035-
return em->em_expr;
1038+
return true;
10361039
}
10371040

10381041
/*

src/include/optimizer/paths.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,9 @@ extern EquivalenceMember *find_computable_ec_member(PlannerInfo *root,
144144
Relids relids,
145145
bool require_parallel_safe);
146146
extern Expr *find_em_expr_for_rel(EquivalenceClass *ec, RelOptInfo *rel);
147-
extern Expr *find_em_expr_usable_for_sorting_rel(PlannerInfo *root,
148-
EquivalenceClass *ec,
149-
RelOptInfo *rel,
150-
bool require_parallel_safe);
147+
extern bool relation_can_be_sorted_early(PlannerInfo *root, RelOptInfo *rel,
148+
EquivalenceClass *ec,
149+
bool require_parallel_safe);
151150
extern void generate_base_implied_equalities(PlannerInfo *root);
152151
extern List *generate_join_implied_equalities(PlannerInfo *root,
153152
Relids join_relids,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy