From 9a8ee1dc650be623c32b1df103254847be974d01 Mon Sep 17 00:00:00 2001 From: Andres Freund Date: Mon, 25 Mar 2019 00:13:42 -0700 Subject: tableam: Add and use table_fetch_row_version(). This is essentially the tableam version of heapam_fetch(), i.e. fetching a tuple identified by a tid, performing visibility checks. Note that this different from table_index_fetch_tuple(), which is for index lookups. It therefore has to handle a tid pointing to an earlier version of a tuple if the AM uses an optimization like heap's HOT. Add comments to that end. This commit removes the stats_relation argument from heap_fetch, as it's been unused for a long time. Author: Andres Freund Reviewed-By: Haribabu Kommi Discussion: https://postgr.es/m/20180703070645.wchpu5muyto5n647@alap3.anarazel.de --- src/backend/access/heap/heapam_handler.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src/backend/access/heap/heapam_handler.c') diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c index fcd4acb5aa3..00ca71a3d2a 100644 --- a/src/backend/access/heap/heapam_handler.c +++ b/src/backend/access/heap/heapam_handler.c @@ -148,6 +148,30 @@ heapam_index_fetch_tuple(struct IndexFetchTableData *scan, * ------------------------------------------------------------------------ */ +static bool +heapam_fetch_row_version(Relation relation, + ItemPointer tid, + Snapshot snapshot, + TupleTableSlot *slot) +{ + BufferHeapTupleTableSlot *bslot = (BufferHeapTupleTableSlot *) slot; + Buffer buffer; + + Assert(TTS_IS_BUFFERTUPLE(slot)); + + bslot->base.tupdata.t_self = *tid; + if (heap_fetch(relation, snapshot, &bslot->base.tupdata, &buffer)) + { + /* store in slot, transferring existing pin */ + ExecStorePinnedBufferHeapTuple(&bslot->base.tupdata, slot, buffer); + slot->tts_tableOid = RelationGetRelid(relation); + + return true; + } + + return false; +} + static bool heapam_tuple_satisfies_snapshot(Relation rel, TupleTableSlot *slot, Snapshot snapshot) @@ -338,7 +362,7 @@ tuple_lock_retry: errmsg("tuple to be locked was already moved to another partition due to concurrent update"))); tuple->t_self = *tid; - if (heap_fetch(relation, &SnapshotDirty, tuple, &buffer, NULL)) + if (heap_fetch(relation, &SnapshotDirty, tuple, &buffer)) { /* * If xmin isn't what we're expecting, the slot must have @@ -517,6 +541,7 @@ static const TableAmRoutine heapam_methods = { .tuple_update = heapam_tuple_update, .tuple_lock = heapam_tuple_lock, + .tuple_fetch_row_version = heapam_fetch_row_version, .tuple_satisfies_snapshot = heapam_tuple_satisfies_snapshot, }; -- cgit v1.2.3