From f7269c054b9b515c1528ecd368527d916257a8c4 Mon Sep 17 00:00:00 2001 From: amit Date: Mon, 4 Mar 2019 16:03:49 +0900 Subject: [PATCH v29 7/7] 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 82bb3c6f04..d9039c888b 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -2082,17 +2082,19 @@ 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); + /* + * 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