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

Commit6130208

Browse files
committed
Avoid useless palloc during transaction commit
We can allocate the initial relations-to-drop array when first needed,instead of at function entry; this avoids allocating it when thefunction is not going to do anything, which is most of the time.Backpatch to 9.3, where this behavior was introduced by commit279628a.There's more that could be done here, such as possible reworking of thecode to avoid having to palloc anything, but that doesn't sound asbackpatchable as this relatively minor change.Per complaint from Noah Misch in20131031145234.GA621493@tornado.leadboat.com
1 parentc32afe5 commit6130208

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

‎src/backend/catalog/storage.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ smgrDoPendingDeletes(bool isCommit)
314314
PendingRelDelete*next;
315315
intnrels=0,
316316
i=0,
317-
maxrels=8;
318-
SMgrRelation*srels=palloc(maxrels*sizeof(SMgrRelation));
317+
maxrels=0;
318+
SMgrRelation*srels=NULL;
319319

320320
prev=NULL;
321321
for (pending=pendingDeletes;pending!=NULL;pending=next)
@@ -340,8 +340,13 @@ smgrDoPendingDeletes(bool isCommit)
340340

341341
srel=smgropen(pending->relnode,pending->backend);
342342

343-
/* extend the array if needed (double the size) */
344-
if (maxrels <=nrels)
343+
/* allocate the initial array, or extend it, if needed */
344+
if (maxrels==0)
345+
{
346+
maxrels=8;
347+
srels=palloc(sizeof(SMgrRelation)*maxrels );
348+
}
349+
elseif (maxrels <=nrels)
345350
{
346351
maxrels *=2;
347352
srels=repalloc(srels,sizeof(SMgrRelation)*maxrels);
@@ -361,10 +366,9 @@ smgrDoPendingDeletes(bool isCommit)
361366

362367
for (i=0;i<nrels;i++)
363368
smgrclose(srels[i]);
364-
}
365-
366-
pfree(srels);
367369

370+
pfree(srels);
371+
}
368372
}
369373

370374
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp