Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 10f1ab2

Browse files
Fix misuse of table_index_fetch_tuple_check().
Commit 0d861bb, which added deduplication to nbtree, had _bt_check_unique() pass a TID to table_index_fetch_tuple_check() that isn't safe to mutate. table_index_fetch_tuple_check()'s tid argument is modified when the TID in question is not the latest visible tuple in a hot chain, though this wasn't documented. To fix, go back to using a local copy of the TID in _bt_check_unique(), and update comments above table_index_fetch_tuple_check(). Backpatch: 13-, where B-Tree deduplication was introduced.
1 parent 463b808 commit 10f1ab2

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

src/backend/access/nbtree/nbtinsert.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,8 @@ _bt_check_unique(Relation rel, BTInsertState insertstate, Relation heapRel,
597597
* not part of this chain because it had a different index
598598
* entry.
599599
*/
600-
if (table_index_fetch_tuple_check(heapRel, &itup->t_tid,
600+
htid = itup->t_tid;
601+
if (table_index_fetch_tuple_check(heapRel, &htid,
601602
SnapshotSelf, NULL))
602603
{
603604
/* Normal case --- it's still live */

src/backend/access/table/tableam.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ table_beginscan_parallel(Relation relation, ParallelTableScanDesc parallel_scan)
196196
* optimized, but is unlikely to matter from a performance POV. If there
197197
* frequently are live index pointers also matching a unique index key, the
198198
* CPU overhead of this routine is unlikely to matter.
199+
*
200+
* Note that *tid may be modified when we return true if the AM supports
201+
* storing multiple row versions reachable via a single index entry (like
202+
* heap's HOT).
199203
*/
200204
bool
201205
table_index_fetch_tuple_check(Relation rel,

src/include/access/tableam.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,9 @@ table_index_fetch_end(struct IndexFetchTableData *scan)
989989
/*
990990
* Fetches, as part of an index scan, tuple at `tid` into `slot`, after doing
991991
* a visibility test according to `snapshot`. If a tuple was found and passed
992-
* the visibility test, returns true, false otherwise.
992+
* the visibility test, returns true, false otherwise. Note that *tid may be
993+
* modified when we return true (see later remarks on multiple row versions
994+
* reachable via a single index entry).
993995
*
994996
* *call_again needs to be false on the first call to table_index_fetch_tuple() for
995997
* a tid. If there potentially is another tuple matching the tid, *call_again

0 commit comments

Comments
 (0)