From 9c9d2f973152277ca334f945cb27b7a065191260 Mon Sep 17 00:00:00 2001 From: amit Date: Mon, 4 Mar 2019 16:03:49 +0900 Subject: [PATCH v34 9/9] 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 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index 2b22dff690..b8f01269be 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -2082,13 +2082,11 @@ set_relation_partition_info(PlannerInfo *root, RelOptInfo *rel, Relation relation) { PartitionDesc partdesc; - PartitionKey partkey; Assert(relation->rd_rel->relkind == RELKIND_PARTITIONED_TABLE); partdesc = PartitionDirectoryLookup(root->glob->partition_directory, relation); - partkey = RelationGetPartitionKey(relation); rel->part_scheme = find_partition_scheme(root, relation); Assert(partdesc != NULL && rel->part_scheme != NULL); /* @@ -2098,7 +2096,13 @@ set_relation_partition_info(PlannerInfo *root, RelOptInfo *rel, * only lazily updated as far as dropped partitions are concerned. */ if (partdesc->nparts > 0) - rel->boundinfo = partition_bounds_copy(partdesc->boundinfo, partkey); + { + /* + * 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. + */ + rel->boundinfo = partdesc->boundinfo; + } rel->nparts = partdesc->nparts; set_baserel_partition_key_exprs(relation, rel); rel->partition_qual = RelationGetPartitionQual(relation); -- 2.11.0