@@ -262,7 +262,6 @@ static Relation AllocateRelationDesc(Form_pg_class relp);
262262static void RelationParseRelOptions (Relation relation , HeapTuple tuple );
263263static void RelationBuildTupleDesc (Relation relation );
264264static void RelationBuildPartitionKey (Relation relation );
265- static PartitionKey copy_partition_key (PartitionKey fromkey );
266265static Relation RelationBuildDesc (Oid targetRelId , bool insertIt );
267266static void RelationInitPhysicalAddr (Relation relation );
268267static void load_critical_index (Oid indexoid , Oid heapoid );
@@ -847,6 +846,12 @@ RelationBuildPartitionKey(Relation relation)
847846 if (!HeapTupleIsValid (tuple ))
848847 return ;
849848
849+ partkeycxt = AllocSetContextCreateExtended (CurTransactionContext ,
850+ RelationGetRelationName (relation ),
851+ MEMCONTEXT_COPY_NAME ,
852+ ALLOCSET_SMALL_SIZES );
853+ oldcxt = MemoryContextSwitchTo (partkeycxt );
854+
850855 key = (PartitionKey ) palloc0 (sizeof (PartitionKeyData ));
851856
852857 /* Fixed-length attributes */
@@ -984,71 +989,13 @@ RelationBuildPartitionKey(Relation relation)
984989
985990 ReleaseSysCache (tuple );
986991
987- /* Success --- now copy to the cache memory */
988- partkeycxt = AllocSetContextCreateExtended (CacheMemoryContext ,
989- RelationGetRelationName (relation ),
990- MEMCONTEXT_COPY_NAME ,
991- ALLOCSET_SMALL_SIZES );
992+ /* Success --- make the relcache point to the newly constructed key */
993+ MemoryContextSetParent (partkeycxt , CacheMemoryContext );
992994 relation -> rd_partkeycxt = partkeycxt ;
993- oldcxt = MemoryContextSwitchTo (relation -> rd_partkeycxt );
994- relation -> rd_partkey = copy_partition_key (key );
995+ relation -> rd_partkey = key ;
995996 MemoryContextSwitchTo (oldcxt );
996997}
997998
998- /*
999- * copy_partition_key
1000- *
1001- * The copy is allocated in the current memory context.
1002- */
1003- static PartitionKey
1004- copy_partition_key (PartitionKey fromkey )
1005- {
1006- PartitionKey newkey ;
1007- int n ;
1008-
1009- newkey = (PartitionKey ) palloc (sizeof (PartitionKeyData ));
1010-
1011- newkey -> strategy = fromkey -> strategy ;
1012- newkey -> partnatts = n = fromkey -> partnatts ;
1013-
1014- newkey -> partattrs = (AttrNumber * ) palloc (n * sizeof (AttrNumber ));
1015- memcpy (newkey -> partattrs , fromkey -> partattrs , n * sizeof (AttrNumber ));
1016-
1017- newkey -> partexprs = copyObject (fromkey -> partexprs );
1018-
1019- newkey -> partopfamily = (Oid * ) palloc (n * sizeof (Oid ));
1020- memcpy (newkey -> partopfamily , fromkey -> partopfamily , n * sizeof (Oid ));
1021-
1022- newkey -> partopcintype = (Oid * ) palloc (n * sizeof (Oid ));
1023- memcpy (newkey -> partopcintype , fromkey -> partopcintype , n * sizeof (Oid ));
1024-
1025- newkey -> partsupfunc = (FmgrInfo * ) palloc (n * sizeof (FmgrInfo ));
1026- memcpy (newkey -> partsupfunc , fromkey -> partsupfunc , n * sizeof (FmgrInfo ));
1027-
1028- newkey -> partcollation = (Oid * ) palloc (n * sizeof (Oid ));
1029- memcpy (newkey -> partcollation , fromkey -> partcollation , n * sizeof (Oid ));
1030-
1031- newkey -> parttypid = (Oid * ) palloc (n * sizeof (Oid ));
1032- memcpy (newkey -> parttypid , fromkey -> parttypid , n * sizeof (Oid ));
1033-
1034- newkey -> parttypmod = (int32 * ) palloc (n * sizeof (int32 ));
1035- memcpy (newkey -> parttypmod , fromkey -> parttypmod , n * sizeof (int32 ));
1036-
1037- newkey -> parttyplen = (int16 * ) palloc (n * sizeof (int16 ));
1038- memcpy (newkey -> parttyplen , fromkey -> parttyplen , n * sizeof (int16 ));
1039-
1040- newkey -> parttypbyval = (bool * ) palloc (n * sizeof (bool ));
1041- memcpy (newkey -> parttypbyval , fromkey -> parttypbyval , n * sizeof (bool ));
1042-
1043- newkey -> parttypalign = (char * ) palloc (n * sizeof (bool ));
1044- memcpy (newkey -> parttypalign , fromkey -> parttypalign , n * sizeof (char ));
1045-
1046- newkey -> parttypcoll = (Oid * ) palloc (n * sizeof (Oid ));
1047- memcpy (newkey -> parttypcoll , fromkey -> parttypcoll , n * sizeof (Oid ));
1048-
1049- return newkey ;
1050- }
1051-
1052999/*
10531000 * equalRuleLocks
10541001 *
0 commit comments