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

Commit78ebda6

Browse files
committed
Speed up truncation of temporary relations.
Previously, truncating a temporary relation required scanning the entirelocal buffer pool once per relation fork to invalidate buffers. This couldbe slow, especially with a large local buffers, as the scan was repeatedmultiple times.A similar issue with regular tables (shared buffers) was addressed incommit6d05086 by scanning the buffer pool only once for all forks.This commit applies the same optimization to temporary relations,improving truncation performance.Author: Daniil Davydov <3danissimo@gmail.com>Reviewed-by: Michael Paquier <michael@paquier.xyz>Reviewed-by: Fujii Masao <masao.fujii@gmail.com>Reviewed-by: Dilip Kumar <dilipbalaut@gmail.com>Reviewed-by: Maxim Orlov <orlovmg@gmail.com>Discussion:https://postgr.es/m/CAJDiXggNqsJOH7C5co4jA8nDk8vw-=sokyh5s1_TENWnC6Ofcg@mail.gmail.com
1 parent931766a commit78ebda6

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

‎src/backend/storage/buffer/bufmgr.c‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4550,11 +4550,9 @@ DropRelationBuffers(SMgrRelation smgr_reln, ForkNumber *forkNum,
45504550
if (RelFileLocatorBackendIsTemp(rlocator))
45514551
{
45524552
if (rlocator.backend==MyProcNumber)
4553-
{
4554-
for (j=0;j<nforks;j++)
4555-
DropRelationLocalBuffers(rlocator.locator,forkNum[j],
4556-
firstDelBlock[j]);
4557-
}
4553+
DropRelationLocalBuffers(rlocator.locator,forkNum,nforks,
4554+
firstDelBlock);
4555+
45584556
return;
45594557
}
45604558

‎src/backend/storage/buffer/localbuf.c‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -660,10 +660,11 @@ InvalidateLocalBuffer(BufferDesc *bufHdr, bool check_unreferenced)
660660
*See DropRelationBuffers in bufmgr.c for more notes.
661661
*/
662662
void
663-
DropRelationLocalBuffers(RelFileLocatorrlocator,ForkNumberforkNum,
664-
BlockNumberfirstDelBlock)
663+
DropRelationLocalBuffers(RelFileLocatorrlocator,ForkNumber*forkNum,
664+
intnforks,BlockNumber*firstDelBlock)
665665
{
666666
inti;
667+
intj;
667668

668669
for (i=0;i<NLocBuffer;i++)
669670
{
@@ -672,12 +673,18 @@ DropRelationLocalBuffers(RelFileLocator rlocator, ForkNumber forkNum,
672673

673674
buf_state=pg_atomic_read_u32(&bufHdr->state);
674675

675-
if ((buf_state&BM_TAG_VALID)&&
676-
BufTagMatchesRelFileLocator(&bufHdr->tag,&rlocator)&&
677-
BufTagGetForkNum(&bufHdr->tag)==forkNum&&
678-
bufHdr->tag.blockNum >=firstDelBlock)
676+
if (!(buf_state&BM_TAG_VALID)||
677+
!BufTagMatchesRelFileLocator(&bufHdr->tag,&rlocator))
678+
continue;
679+
680+
for (j=0;j<nforks;j++)
679681
{
680-
InvalidateLocalBuffer(bufHdr, true);
682+
if (BufTagGetForkNum(&bufHdr->tag)==forkNum[j]&&
683+
bufHdr->tag.blockNum >=firstDelBlock[j])
684+
{
685+
InvalidateLocalBuffer(bufHdr, true);
686+
break;
687+
}
681688
}
682689
}
683690
}

‎src/include/storage/buf_internals.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,8 @@ extern bool StartLocalBufferIO(BufferDesc *bufHdr, bool forInput, bool nowait);
486486
externvoidFlushLocalBuffer(BufferDesc*bufHdr,SMgrRelationreln);
487487
externvoidInvalidateLocalBuffer(BufferDesc*bufHdr,boolcheck_unreferenced);
488488
externvoidDropRelationLocalBuffers(RelFileLocatorrlocator,
489-
ForkNumberforkNum,
490-
BlockNumberfirstDelBlock);
489+
ForkNumber*forkNum,intnforks,
490+
BlockNumber*firstDelBlock);
491491
externvoidDropRelationAllLocalBuffers(RelFileLocatorrlocator);
492492
externvoidAtEOXact_LocalBuffers(boolisCommit);
493493

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp