@@ -262,7 +262,6 @@ static Relation AllocateRelationDesc(Form_pg_class relp);
262
262
static void RelationParseRelOptions (Relation relation , HeapTuple tuple );
263
263
static void RelationBuildTupleDesc (Relation relation );
264
264
static void RelationBuildPartitionKey (Relation relation );
265
- static PartitionKey copy_partition_key (PartitionKey fromkey );
266
265
static Relation RelationBuildDesc (Oid targetRelId , bool insertIt );
267
266
static void RelationInitPhysicalAddr (Relation relation );
268
267
static void load_critical_index (Oid indexoid , Oid heapoid );
@@ -847,6 +846,12 @@ RelationBuildPartitionKey(Relation relation)
847
846
if (!HeapTupleIsValid (tuple ))
848
847
return ;
849
848
849
+ partkeycxt = AllocSetContextCreateExtended (CurTransactionContext ,
850
+ RelationGetRelationName (relation ),
851
+ MEMCONTEXT_COPY_NAME ,
852
+ ALLOCSET_SMALL_SIZES );
853
+ oldcxt = MemoryContextSwitchTo (partkeycxt );
854
+
850
855
key = (PartitionKey ) palloc0 (sizeof (PartitionKeyData ));
851
856
852
857
/* Fixed-length attributes */
@@ -984,71 +989,13 @@ RelationBuildPartitionKey(Relation relation)
984
989
985
990
ReleaseSysCache (tuple );
986
991
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 );
992
994
relation -> rd_partkeycxt = partkeycxt ;
993
- oldcxt = MemoryContextSwitchTo (relation -> rd_partkeycxt );
994
- relation -> rd_partkey = copy_partition_key (key );
995
+ relation -> rd_partkey = key ;
995
996
MemoryContextSwitchTo (oldcxt );
996
997
}
997
998
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
-
1052
999
/*
1053
1000
* equalRuleLocks
1054
1001
*
0 commit comments