From 4a6048ced9bd94aa2f0f544737a0d1acc2b7c806 Mon Sep 17 00:00:00 2001 From: amit Date: Mon, 4 Mar 2019 16:03:49 +0900 Subject: [PATCH v26 6/6] Don't copy PartitionBoundInfo in set_relation_partition_info As long as we hold a lock on the table, it shouldn't change, so seems pointless to copy, which can get really expensive as the number of partitions grows beyond thousands. --- src/backend/optimizer/util/plancat.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index 549af9dc6e..b75b761033 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -2082,16 +2082,18 @@ set_relation_partition_info(PlannerInfo *root, RelOptInfo *rel, Relation relation) { PartitionDesc partdesc; - PartitionKey partkey; Assert(relation->rd_rel->relkind == RELKIND_PARTITIONED_TABLE); partdesc = RelationGetPartitionDesc(relation); - partkey = RelationGetPartitionKey(relation); rel->part_scheme = find_partition_scheme(root, relation); Assert(partdesc != NULL && rel->part_scheme != NULL); + /* + * Holding onto the relcache pointer should be OK, as it won't change + * under us as long as we're holding the lock on the relation. + */ if (partdesc->nparts > 0) - rel->boundinfo = partition_bounds_copy(partdesc->boundinfo, partkey); + rel->boundinfo = partdesc->boundinfo; rel->nparts = partdesc->nparts; set_baserel_partition_key_exprs(relation, rel); rel->partition_qual = RelationGetPartitionQual(relation); -- 2.11.0