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

Commit53f1ca5

Browse files
committed
Allow hint bits to be set sooner for temporary and unlogged tables.
We need not wait until the commit record is durably on disk, becausein the event of a crash the page we're updating with hint bits willbe gone anyway. Per off-list report from Heikki Linnakangas, thiscan significantly degrade the performance of unlogged tables; I wasable to show a 2x speedup from this patch on a pgbench run with scalefactor 15. In practice, this will mostly help small, heavily updatedtables, because on larger tables you're unlikely to run into the samerow again before the commit record makes it out to disk.
1 parentb6335a3 commit53f1ca5

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,6 +1929,35 @@ RelationGetNumberOfBlocksInFork(Relation relation, ForkNumber forkNum)
19291929
returnsmgrnblocks(relation->rd_smgr,forkNum);
19301930
}
19311931

1932+
/*
1933+
* BufferIsPermanent
1934+
*Determines whether a buffer will potentially still be around after
1935+
*a crash. Caller must hold a buffer pin.
1936+
*/
1937+
bool
1938+
BufferIsPermanent(Bufferbuffer)
1939+
{
1940+
volatileBufferDesc*bufHdr;
1941+
1942+
/* Local buffers are used only for temp relations. */
1943+
if (BufferIsLocal(buffer))
1944+
return false;
1945+
1946+
/* Make sure we've got a real buffer, and that we hold a pin on it. */
1947+
Assert(BufferIsValid(buffer));
1948+
Assert(BufferIsPinned(buffer));
1949+
1950+
/*
1951+
* BM_PERMANENT can't be changed while we hold a pin on the buffer, so
1952+
* we need not bother with the buffer header spinlock. Even if someone
1953+
* else changes the buffer header flags while we're doing this, we assume
1954+
* that changing an aligned 2-byte BufFlags value is atomic, so we'll read
1955+
* the old value or the new value, but not random garbage.
1956+
*/
1957+
bufHdr=&BufferDescriptors[buffer-1];
1958+
return (bufHdr->flags&BM_PERMANENT)!=0;
1959+
}
1960+
19321961
/* ---------------------------------------------------------------------
19331962
*DropRelFileNodeBuffers
19341963
*

‎src/backend/utils/time/tqual.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,12 @@ static bool XidInMVCCSnapshot(TransactionId xid, Snapshot snapshot);
8282
* Set commit/abort hint bits on a tuple, if appropriate at this time.
8383
*
8484
* It is only safe to set a transaction-committed hint bit if we know the
85-
* transaction's commit record has been flushed to disk. We cannot change
86-
* the LSN of the page here because we may hold only a share lock on the
87-
* buffer, so we can't use the LSN to interlock this; we have to just refrain
88-
* from setting the hint bit until some future re-examination of the tuple.
85+
* transaction's commit record has been flushed to disk, or if the table is
86+
* temporary or unlogged and will be obliterated by a crash anyway. We
87+
* cannot change the LSN of the page here because we may hold only a share
88+
* lock on the buffer, so we can't use the LSN to interlock this; we have to
89+
* just refrain from setting the hint bit until some future re-examination
90+
* of the tuple.
8991
*
9092
* We can always set hint bits when marking a transaction aborted.(Some
9193
* code in heapam.c relies on that!)
@@ -113,7 +115,7 @@ SetHintBits(HeapTupleHeader tuple, Buffer buffer,
113115
/* NB: xid must be known committed here! */
114116
XLogRecPtrcommitLSN=TransactionIdGetCommitLSN(xid);
115117

116-
if (XLogNeedsFlush(commitLSN))
118+
if (XLogNeedsFlush(commitLSN)&&BufferIsPermanent(buffer))
117119
return;/* not flushed yet, so don't set hint */
118120
}
119121

‎src/include/storage/bufmgr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ extern void DropDatabaseBuffers(Oid dbid);
192192
#defineRelationGetNumberOfBlocks(reln) \
193193
RelationGetNumberOfBlocksInFork(reln, MAIN_FORKNUM)
194194

195+
externboolBufferIsPermanent(Bufferbuffer);
196+
195197
#ifdefNOT_USED
196198
externvoidPrintPinnedBufs(void);
197199
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp