RelOptInfo *child_joinrel;
AppendRelInfo **appinfos;
int nappinfos;
+ Relids child_relids;
if (joinrel->partbounds_merged)
{
child_rel2->relids);
/* Find the AppendRelInfo structures */
- appinfos = find_appinfos_by_relids(root,
- bms_union(child_rel1->relids,
- child_rel2->relids),
+ child_relids = bms_union(child_rel1->relids, child_rel2->relids);
+ appinfos = find_appinfos_by_relids(root, child_relids,
&nappinfos);
/*
{
child_joinrel = build_child_join_rel(root, child_rel1, child_rel2,
joinrel, child_restrictlist,
- child_sjinfo);
+ child_sjinfo, nappinfos, appinfos);
joinrel->part_rels[cnt_parts] = child_joinrel;
joinrel->live_parts = bms_add_member(joinrel->live_parts, cnt_parts);
joinrel->all_partrels = bms_add_members(joinrel->all_partrels,
child_joinrel, child_sjinfo,
child_restrictlist);
+ /*
+ * When there are thousands of partitions involved, this loop will
+ * accumulate a significant amount of memory usage from objects that
+ * are only needed within the loop. Free these local objects eagerly
+ * at the end of each iteration.
+ */
pfree(appinfos);
+ bms_free(child_relids);
free_child_join_sjinfo(child_sjinfo);
}
}
* 'restrictlist': list of RestrictInfo nodes that apply to this particular
* pair of joinable relations
* 'sjinfo': child join's join-type details
+ * 'nappinfos' and 'appinfos': AppendRelInfo array for child relids
*/
RelOptInfo *
build_child_join_rel(PlannerInfo *root, RelOptInfo *outer_rel,
RelOptInfo *inner_rel, RelOptInfo *parent_joinrel,
- List *restrictlist, SpecialJoinInfo *sjinfo)
+ List *restrictlist, SpecialJoinInfo *sjinfo,
+ int nappinfos, AppendRelInfo **appinfos)
{
RelOptInfo *joinrel = makeNode(RelOptInfo);
- AppendRelInfo **appinfos;
- int nappinfos;
/* Only joins between "other" relations land here. */
Assert(IS_OTHER_REL(outer_rel) && IS_OTHER_REL(inner_rel));
/* The parent joinrel should have consider_partitionwise_join set. */
Assert(parent_joinrel->consider_partitionwise_join);
- /*
- * Find the AppendRelInfo structures for the child baserels. We'll need
- * these for computing the child join's relid set, and later for mapping
- * Vars to the child rel.
- */
- appinfos = find_appinfos_by_relids(root,
- bms_union(outer_rel->relids,
- inner_rel->relids),
- &nappinfos);
-
joinrel->reloptkind = RELOPT_OTHER_JOINREL;
joinrel->relids = adjust_child_relids(parent_joinrel->relids,
nappinfos, appinfos);
nappinfos, appinfos,
parent_joinrel, joinrel);
- pfree(appinfos);
-
return joinrel;
}
extern RelOptInfo *build_child_join_rel(PlannerInfo *root,
RelOptInfo *outer_rel, RelOptInfo *inner_rel,
RelOptInfo *parent_joinrel, List *restrictlist,
- SpecialJoinInfo *sjinfo);
+ SpecialJoinInfo *sjinfo,
+ int nappinfos, AppendRelInfo **appinfos);
#endif /* PATHNODE_H */