mirror of
https://github.com/postgres/postgres.git
synced 2025-07-07 00:36:50 +03:00
Speed up truncation of temporary relations.
Previously, truncating a temporary relation required scanning the entire
local buffer pool once per relation fork to invalidate buffers. This could
be slow, especially with a large local buffers, as the scan was repeated
multiple times.
A similar issue with regular tables (shared buffers) was addressed in
commit 6d05086c0a
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
This commit is contained in:
@ -4550,11 +4550,9 @@ DropRelationBuffers(SMgrRelation smgr_reln, ForkNumber *forkNum,
|
|||||||
if (RelFileLocatorBackendIsTemp(rlocator))
|
if (RelFileLocatorBackendIsTemp(rlocator))
|
||||||
{
|
{
|
||||||
if (rlocator.backend == MyProcNumber)
|
if (rlocator.backend == MyProcNumber)
|
||||||
{
|
DropRelationLocalBuffers(rlocator.locator, forkNum, nforks,
|
||||||
for (j = 0; j < nforks; j++)
|
firstDelBlock);
|
||||||
DropRelationLocalBuffers(rlocator.locator, forkNum[j],
|
|
||||||
firstDelBlock[j]);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -660,10 +660,11 @@ InvalidateLocalBuffer(BufferDesc *bufHdr, bool check_unreferenced)
|
|||||||
* See DropRelationBuffers in bufmgr.c for more notes.
|
* See DropRelationBuffers in bufmgr.c for more notes.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
DropRelationLocalBuffers(RelFileLocator rlocator, ForkNumber forkNum,
|
DropRelationLocalBuffers(RelFileLocator rlocator, ForkNumber *forkNum,
|
||||||
BlockNumber firstDelBlock)
|
int nforks, BlockNumber *firstDelBlock)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
for (i = 0; i < NLocBuffer; i++)
|
for (i = 0; i < NLocBuffer; i++)
|
||||||
{
|
{
|
||||||
@ -672,12 +673,18 @@ DropRelationLocalBuffers(RelFileLocator rlocator, ForkNumber forkNum,
|
|||||||
|
|
||||||
buf_state = pg_atomic_read_u32(&bufHdr->state);
|
buf_state = pg_atomic_read_u32(&bufHdr->state);
|
||||||
|
|
||||||
if ((buf_state & BM_TAG_VALID) &&
|
if (!(buf_state & BM_TAG_VALID) ||
|
||||||
BufTagMatchesRelFileLocator(&bufHdr->tag, &rlocator) &&
|
!BufTagMatchesRelFileLocator(&bufHdr->tag, &rlocator))
|
||||||
BufTagGetForkNum(&bufHdr->tag) == forkNum &&
|
continue;
|
||||||
bufHdr->tag.blockNum >= firstDelBlock)
|
|
||||||
|
for (j = 0; j < nforks; j++)
|
||||||
|
{
|
||||||
|
if (BufTagGetForkNum(&bufHdr->tag) == forkNum[j] &&
|
||||||
|
bufHdr->tag.blockNum >= firstDelBlock[j])
|
||||||
{
|
{
|
||||||
InvalidateLocalBuffer(bufHdr, true);
|
InvalidateLocalBuffer(bufHdr, true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -486,8 +486,8 @@ extern bool StartLocalBufferIO(BufferDesc *bufHdr, bool forInput, bool nowait);
|
|||||||
extern void FlushLocalBuffer(BufferDesc *bufHdr, SMgrRelation reln);
|
extern void FlushLocalBuffer(BufferDesc *bufHdr, SMgrRelation reln);
|
||||||
extern void InvalidateLocalBuffer(BufferDesc *bufHdr, bool check_unreferenced);
|
extern void InvalidateLocalBuffer(BufferDesc *bufHdr, bool check_unreferenced);
|
||||||
extern void DropRelationLocalBuffers(RelFileLocator rlocator,
|
extern void DropRelationLocalBuffers(RelFileLocator rlocator,
|
||||||
ForkNumber forkNum,
|
ForkNumber *forkNum, int nforks,
|
||||||
BlockNumber firstDelBlock);
|
BlockNumber *firstDelBlock);
|
||||||
extern void DropRelationAllLocalBuffers(RelFileLocator rlocator);
|
extern void DropRelationAllLocalBuffers(RelFileLocator rlocator);
|
||||||
extern void AtEOXact_LocalBuffers(bool isCommit);
|
extern void AtEOXact_LocalBuffers(bool isCommit);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user