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

Commitb4e0741

Browse files
committed
Avoid re-checking for visibility map extension too frequently.
When testing bits (but not when setting or clearing them), we nowwon't check whether the map has been extended. This significantlyimproves performance in the case where the visibility map doesn'texist yet, by avoiding an extra system call per tuple. To makesure backends notice eventually, send an smgr inval on VM extension.Dean Rasheed, with minor modifications by me.
1 parent8a02339 commitb4e0741

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

‎src/backend/access/heap/visibilitymap.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
#include"storage/bufmgr.h"
8989
#include"storage/lmgr.h"
9090
#include"storage/smgr.h"
91+
#include"utils/inval.h"
9192

9293

9394
/*#define TRACE_VISIBILITYMAP */
@@ -482,16 +483,20 @@ vm_readbuf(Relation rel, BlockNumber blkno, bool extend)
482483
{
483484
Bufferbuf;
484485

486+
/*
487+
* We might not have opened the relation at the smgr level yet, or we might
488+
* have been forced to close it by a sinval message. The code below won't
489+
* necessarily notice relation extension immediately when extend = false,
490+
* so we rely on sinval messages to ensure that our ideas about the size of
491+
* the map aren't too far out of date.
492+
*/
485493
RelationOpenSmgr(rel);
486494

487495
/*
488496
* If we haven't cached the size of the visibility map fork yet, check it
489-
* first. Also recheck if the requested block seems to be past end, since
490-
* our cached value might be stale. (We send smgr inval messages on
491-
* truncation, but not on extension.)
497+
* first.
492498
*/
493-
if (rel->rd_smgr->smgr_vm_nblocks==InvalidBlockNumber||
494-
blkno >=rel->rd_smgr->smgr_vm_nblocks)
499+
if (rel->rd_smgr->smgr_vm_nblocks==InvalidBlockNumber)
495500
{
496501
if (smgrexists(rel->rd_smgr,VISIBILITYMAP_FORKNUM))
497502
rel->rd_smgr->smgr_vm_nblocks=smgrnblocks(rel->rd_smgr,
@@ -560,13 +565,23 @@ vm_extend(Relation rel, BlockNumber vm_nblocks)
560565

561566
vm_nblocks_now=smgrnblocks(rel->rd_smgr,VISIBILITYMAP_FORKNUM);
562567

568+
/* Now extend the file */
563569
while (vm_nblocks_now<vm_nblocks)
564570
{
565571
smgrextend(rel->rd_smgr,VISIBILITYMAP_FORKNUM,vm_nblocks_now,
566572
(char*)pg, false);
567573
vm_nblocks_now++;
568574
}
569575

576+
/*
577+
* Send a shared-inval message to force other backends to close any smgr
578+
* references they may have for this rel, which we are about to change.
579+
* This is a useful optimization because it means that backends don't have
580+
* to keep checking for creation or extension of the file, which happens
581+
* infrequently.
582+
*/
583+
CacheInvalidateSmgr(rel->rd_smgr->smgr_rnode);
584+
570585
/* Update local cache with the up-to-date size */
571586
rel->rd_smgr->smgr_vm_nblocks=vm_nblocks_now;
572587

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp