Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8a0596c

Browse files
committed
Get rid of copy_partition_key
That function currently exists to avoid leaking memory inCacheMemoryContext in case of trouble while the partition key is beingbuilt, but there's a better way: allocate everything in a memcxt thatgoes away if the current (sub)transaction fails, and once the partitionkey is built and no further errors can occur, make the memcxt permanentby making it a child of CacheMemoryContext.Reviewed-by: Tom LaneDiscussion:https://postgr.es/m/20171027172730.eh2domlkpn4ja62m@alvherre.pgsql
1 parent9ef6aba commit8a0596c

File tree

1 file changed

+9
-62
lines changed

1 file changed

+9
-62
lines changed

‎src/backend/utils/cache/relcache.c

Lines changed: 9 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ static Relation AllocateRelationDesc(Form_pg_class relp);
262262
staticvoidRelationParseRelOptions(Relationrelation,HeapTupletuple);
263263
staticvoidRelationBuildTupleDesc(Relationrelation);
264264
staticvoidRelationBuildPartitionKey(Relationrelation);
265-
staticPartitionKeycopy_partition_key(PartitionKeyfromkey);
266265
staticRelationRelationBuildDesc(OidtargetRelId,boolinsertIt);
267266
staticvoidRelationInitPhysicalAddr(Relationrelation);
268267
staticvoidload_critical_index(Oidindexoid,Oidheapoid);
@@ -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-
staticPartitionKey
1004-
copy_partition_key(PartitionKeyfromkey)
1005-
{
1006-
PartitionKeynewkey;
1007-
intn;
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-
returnnewkey;
1050-
}
1051-
1052999
/*
10531000
*equalRuleLocks
10541001
*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp