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

Commit0038110

Browse files
committed
Avoid repeated CLOG access from heap_hot_search_buffer.
At the time we check whether the tuple is dead to all runningtransactions, we've already verified that it isn't visible to ourscan, setting hint bits if appropriate. So there's no need torecheck CLOG for the all-dead test we do just a moment later.So, add HeapTupleIsSurelyDead() to test the appropriate conditionunder the assumption that all relevant hit bits are already set.Review by Tom Lane.
1 parent1b4998f commit0038110

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,8 +1609,7 @@ heap_hot_search_buffer(ItemPointer tid, Relation relation, Buffer buffer,
16091609
* transactions.
16101610
*/
16111611
if (all_dead&&*all_dead&&
1612-
HeapTupleSatisfiesVacuum(heapTuple->t_data,RecentGlobalXmin,
1613-
buffer)!=HEAPTUPLE_DEAD)
1612+
!HeapTupleIsSurelyDead(heapTuple->t_data,RecentGlobalXmin))
16141613
*all_dead= false;
16151614

16161615
/*

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,46 @@ HeapTupleSatisfiesVacuum(HeapTupleHeader tuple, TransactionId OldestXmin,
12191219
returnHEAPTUPLE_DEAD;
12201220
}
12211221

1222+
/*
1223+
* HeapTupleIsSurelyDead
1224+
*
1225+
*Determine whether a tuple is surely dead. We sometimes use this
1226+
*in lieu of HeapTupleSatisifesVacuum when the tuple has just been
1227+
*tested by HeapTupleSatisfiesMVCC and, therefore, any hint bits that
1228+
*can be set should already be set. We assume that if no hint bits
1229+
*either for xmin or xmax, the transaction is still running. This is
1230+
*therefore faster than HeapTupleSatisfiesVacuum, because we don't
1231+
*consult CLOG (and also because we don't need to give an exact answer,
1232+
*just whether or not the tuple is surely dead).
1233+
*/
1234+
bool
1235+
HeapTupleIsSurelyDead(HeapTupleHeadertuple,TransactionIdOldestXmin)
1236+
{
1237+
/*
1238+
* If the inserting transaction is marked invalid, then it aborted,
1239+
* and the tuple is definitely dead. If it's marked neither committed
1240+
* nor invalid, then we assume it's still alive (since the presumption
1241+
* is that all relevant hint bits were just set moments ago).
1242+
*/
1243+
if (!(tuple->t_infomask&HEAP_XMIN_COMMITTED))
1244+
return (tuple->t_infomask&HEAP_XMIN_INVALID)!=0 ? true : false;
1245+
1246+
/*
1247+
* If the inserting transaction committed, but any deleting transaction
1248+
* aborted, the tuple is still alive. Likewise, if XMAX is a lock rather
1249+
* than a delete, the tuple is still alive.
1250+
*/
1251+
if (tuple->t_infomask&
1252+
(HEAP_XMAX_INVALID |HEAP_IS_LOCKED |HEAP_XMAX_IS_MULTI))
1253+
return false;
1254+
1255+
/* If deleter isn't known to have committed, assume it's still running. */
1256+
if (!(tuple->t_infomask&HEAP_XMAX_COMMITTED))
1257+
return false;
1258+
1259+
/* Deleter committed, so tuple is dead if the XID is old enough. */
1260+
returnTransactionIdPrecedes(HeapTupleHeaderGetXmax(tuple),OldestXmin);
1261+
}
12221262

12231263
/*
12241264
* XidInMVCCSnapshot

‎src/include/utils/tqual.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ extern HTSU_Result HeapTupleSatisfiesUpdate(HeapTupleHeader tuple,
8383
CommandIdcurcid,Bufferbuffer);
8484
externHTSV_ResultHeapTupleSatisfiesVacuum(HeapTupleHeadertuple,
8585
TransactionIdOldestXmin,Bufferbuffer);
86+
externboolHeapTupleIsSurelyDead(HeapTupleHeadertuple,
87+
TransactionIdOldestXmin);
8688

8789
externvoidHeapTupleSetHintBits(HeapTupleHeadertuple,Bufferbuffer,
8890
uint16infomask,TransactionIdxid);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp