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
This commit is contained in:
parent
3753982441
commit
7645376774
@ -2697,20 +2697,19 @@ get_useful_pathkeys_for_relation(PlannerInfo *root, RelOptInfo *rel,
|
|||||||
EquivalenceClass *pathkey_ec = pathkey->pk_eclass;
|
EquivalenceClass *pathkey_ec = pathkey->pk_eclass;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We can only build a sort for pathkeys which contain an EC
|
* We can only build a sort for pathkeys that contain a
|
||||||
* member in the current relation's target, so ignore any suffix
|
* safe-to-compute-early EC member computable from the current
|
||||||
* of the list as soon as we find a pathkey without an EC member
|
* relation's reltarget, so ignore the remainder of the list as
|
||||||
* in the relation.
|
* soon as we find a pathkey without such a member.
|
||||||
*
|
*
|
||||||
* By still returning the prefix of the pathkeys list that does
|
* It's still worthwhile to return any prefix of the pathkeys list
|
||||||
* meet criteria of EC membership in the current relation, we
|
* that meets this requirement, as we may be able to do an
|
||||||
* enable not just an incremental sort on the entirety of
|
* incremental sort.
|
||||||
* query_pathkeys but also incremental sort below a JOIN.
|
|
||||||
*
|
*
|
||||||
* If requested, ensure the expression is parallel safe too.
|
* If requested, ensure the sort expression is parallel-safe too.
|
||||||
*/
|
*/
|
||||||
if (!find_em_expr_usable_for_sorting_rel(root, pathkey_ec, rel,
|
if (!relation_can_be_sorted_early(root, rel, pathkey_ec,
|
||||||
require_parallel_safe))
|
require_parallel_safe))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
npathkeys++;
|
npathkeys++;
|
||||||
|
@ -961,18 +961,21 @@ find_em_expr_for_rel(EquivalenceClass *ec, RelOptInfo *rel)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Find an equivalence class member expression that can be used to build
|
* relation_can_be_sorted_early
|
||||||
* a sort node using the provided relation; return NULL if no candidate.
|
* Can this relation be sorted on this EC before the final output step?
|
||||||
*
|
*
|
||||||
* To succeed, we must find an EC member that prepare_sort_from_pathkeys knows
|
* 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
|
* 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
|
* additional constraints based on the fact that the desired sort will be done
|
||||||
* within the scan/join part of the plan. Also, non-parallel-safe expressions
|
* "early", within the scan/join part of the plan. Also, non-parallel-safe
|
||||||
* are ignored if 'require_parallel_safe'.
|
* expressions are ignored if 'require_parallel_safe'.
|
||||||
|
*
|
||||||
|
* At some point we might want to return the identified EquivalenceMember,
|
||||||
|
* but for now, callers only want to know if there is one.
|
||||||
*/
|
*/
|
||||||
Expr *
|
bool
|
||||||
find_em_expr_usable_for_sorting_rel(PlannerInfo *root, EquivalenceClass *ec,
|
relation_can_be_sorted_early(PlannerInfo *root, RelOptInfo *rel,
|
||||||
RelOptInfo *rel, bool require_parallel_safe)
|
EquivalenceClass *ec, bool require_parallel_safe)
|
||||||
{
|
{
|
||||||
PathTarget *target = rel->reltarget;
|
PathTarget *target = rel->reltarget;
|
||||||
EquivalenceMember *em;
|
EquivalenceMember *em;
|
||||||
@ -982,7 +985,7 @@ find_em_expr_usable_for_sorting_rel(PlannerInfo *root, EquivalenceClass *ec,
|
|||||||
* Reject volatile ECs immediately; such sorts must always be postponed.
|
* Reject volatile ECs immediately; such sorts must always be postponed.
|
||||||
*/
|
*/
|
||||||
if (ec->ec_has_volatile)
|
if (ec->ec_has_volatile)
|
||||||
return NULL;
|
return false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Try to find an EM directly matching some reltarget member.
|
* 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,
|
|||||||
!is_parallel_safe(root, (Node *) em->em_expr))
|
!is_parallel_safe(root, (Node *) em->em_expr))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
return em->em_expr;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1021,7 +1024,7 @@ find_em_expr_usable_for_sorting_rel(PlannerInfo *root, EquivalenceClass *ec,
|
|||||||
em = find_computable_ec_member(root, ec, target->exprs, rel->relids,
|
em = find_computable_ec_member(root, ec, target->exprs, rel->relids,
|
||||||
require_parallel_safe);
|
require_parallel_safe);
|
||||||
if (!em)
|
if (!em)
|
||||||
return NULL;
|
return false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Reject expressions involving set-returning functions, as those can't be
|
* 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,
|
|||||||
* belong to multi-member ECs.)
|
* belong to multi-member ECs.)
|
||||||
*/
|
*/
|
||||||
if (IS_SRF_CALL((Node *) em->em_expr))
|
if (IS_SRF_CALL((Node *) em->em_expr))
|
||||||
return NULL;
|
return false;
|
||||||
|
|
||||||
return em->em_expr;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -144,10 +144,9 @@ extern EquivalenceMember *find_computable_ec_member(PlannerInfo *root,
|
|||||||
Relids relids,
|
Relids relids,
|
||||||
bool require_parallel_safe);
|
bool require_parallel_safe);
|
||||||
extern Expr *find_em_expr_for_rel(EquivalenceClass *ec, RelOptInfo *rel);
|
extern Expr *find_em_expr_for_rel(EquivalenceClass *ec, RelOptInfo *rel);
|
||||||
extern Expr *find_em_expr_usable_for_sorting_rel(PlannerInfo *root,
|
extern bool relation_can_be_sorted_early(PlannerInfo *root, RelOptInfo *rel,
|
||||||
EquivalenceClass *ec,
|
EquivalenceClass *ec,
|
||||||
RelOptInfo *rel,
|
bool require_parallel_safe);
|
||||||
bool require_parallel_safe);
|
|
||||||
extern void generate_base_implied_equalities(PlannerInfo *root);
|
extern void generate_base_implied_equalities(PlannerInfo *root);
|
||||||
extern List *generate_join_implied_equalities(PlannerInfo *root,
|
extern List *generate_join_implied_equalities(PlannerInfo *root,
|
||||||
Relids join_relids,
|
Relids join_relids,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user