1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

Make PlaceHolderInfo lookup O(1).

Up to now we've just searched the placeholder_list when we want to
find the PlaceHolderInfo with a given ID.  While there's no evidence
of that being a problem in the field, an upcoming patch will add
find_placeholder_info() calls in build_joinrel_tlist(), which seems
likely to make it more of an issue: a joinrel emitting lots of
PlaceHolderVars would incur O(N^2) cost, and we might be building
a lot of joinrels in complex queries.  Hence, add an array that
can be indexed directly by phid to make the lookups constant-time.

Discussion: https://postgr.es/m/1405792.1660677844@sss.pgh.pa.us
This commit is contained in:
Tom Lane
2022-08-17 15:35:51 -04:00
parent efd0c16bec
commit 6569ca4397
5 changed files with 50 additions and 14 deletions

View File

@@ -388,8 +388,11 @@ remove_rel_from_query(PlannerInfo *root, int relid, Relids joinrelids)
Assert(!bms_is_member(relid, phinfo->ph_lateral));
if (bms_is_subset(phinfo->ph_needed, joinrelids) &&
bms_is_member(relid, phinfo->ph_eval_at))
{
root->placeholder_list = foreach_delete_current(root->placeholder_list,
l);
root->placeholder_array[phinfo->phid] = NULL;
}
else
{
phinfo->ph_eval_at = bms_del_member(phinfo->ph_eval_at, relid);

View File

@@ -75,6 +75,8 @@ query_planner(PlannerInfo *root,
root->full_join_clauses = NIL;
root->join_info_list = NIL;
root->placeholder_list = NIL;
root->placeholder_array = NULL;
root->placeholder_array_size = 0;
root->fkey_list = NIL;
root->initial_rels = NIL;