From 81d8337760be175b37b5ffe84df06903173787c5 Mon Sep 17 00:00:00 2001 From: amit Date: Tue, 10 Apr 2018 15:38:19 +0900 Subject: [PATCH v1] Fix a memory context bug in RelationBuildPartitionKey We should pass rd_partkeycxt to set fn_mcxt, not CurrentMemoryContex. --- src/backend/utils/cache/relcache.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index a69b078f91..be7d5b7eef 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -849,6 +849,10 @@ RelationBuildPartitionKey(Relation relation) if (!HeapTupleIsValid(tuple)) return; + partkeycxt = AllocSetContextCreate(CacheMemoryContext, + RelationGetRelationName(relation), + ALLOCSET_SMALL_SIZES); + key = (PartitionKey) palloc0(sizeof(PartitionKeyData)); /* Fixed-length attributes */ @@ -951,7 +955,7 @@ RelationBuildPartitionKey(Relation relation) BTORDER_PROC, opclassform->opcintype, opclassform->opcintype, opclassform->opcfamily); - fmgr_info(funcid, &key->partsupfunc[i]); + fmgr_info_cxt(funcid, &key->partsupfunc[i], partkeycxt); /* Collation */ key->partcollation[i] = collation->values[i]; @@ -985,9 +989,6 @@ RelationBuildPartitionKey(Relation relation) ReleaseSysCache(tuple); /* Success --- now copy to the cache memory */ - partkeycxt = AllocSetContextCreate(CacheMemoryContext, - RelationGetRelationName(relation), - ALLOCSET_SMALL_SIZES); relation->rd_partkeycxt = partkeycxt; oldcxt = MemoryContextSwitchTo(relation->rd_partkeycxt); relation->rd_partkey = copy_partition_key(key); -- 2.11.0