mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
Allow direct lookups of AppendRelInfo by child relid
find_appinfos_by_relids had quite a large overhead when the number of items in the append_rel_list was high, as it had to trawl through the append_rel_list looking for AppendRelInfos belonging to the given childrelids. Since there can only be a single AppendRelInfo for each child rel, it seems much better to store an array in PlannerInfo which indexes these by child relid, making the function O(1) rather than O(N). This function was only called once inside the planner, so just replace that call with a lookup to the new array. find_childrel_appendrelinfo is now unused and thus removed. This fixes a planner performance regression new to v11 reported by Thomas Reiss. Author: David Rowley Reported-by: Thomas Reiss Reviewed-by: Ashutosh Bapat Reviewed-by: Álvaro Herrera Discussion: https://postgr.es/m/94dd7a4b-5e50-0712-911d-2278e055c622@dalibo.com
This commit is contained in:
@ -1163,6 +1163,7 @@ inheritance_planner(PlannerInfo *root)
|
||||
List *final_rtable = NIL;
|
||||
int save_rel_array_size = 0;
|
||||
RelOptInfo **save_rel_array = NULL;
|
||||
AppendRelInfo **save_append_rel_array = NULL;
|
||||
List *subpaths = NIL;
|
||||
List *subroots = NIL;
|
||||
List *resultRelations = NIL;
|
||||
@ -1529,6 +1530,7 @@ inheritance_planner(PlannerInfo *root)
|
||||
}
|
||||
save_rel_array_size = subroot->simple_rel_array_size;
|
||||
save_rel_array = subroot->simple_rel_array;
|
||||
save_append_rel_array = subroot->append_rel_array;
|
||||
|
||||
/* Make sure any initplans from this rel get into the outer list */
|
||||
root->init_plans = subroot->init_plans;
|
||||
@ -1579,6 +1581,8 @@ inheritance_planner(PlannerInfo *root)
|
||||
parse->rtable = final_rtable;
|
||||
root->simple_rel_array_size = save_rel_array_size;
|
||||
root->simple_rel_array = save_rel_array;
|
||||
root->append_rel_array = save_append_rel_array;
|
||||
|
||||
/* Must reconstruct master's simple_rte_array, too */
|
||||
root->simple_rte_array = (RangeTblEntry **)
|
||||
palloc0((list_length(final_rtable) + 1) * sizeof(RangeTblEntry *));
|
||||
|
Reference in New Issue
Block a user