Commit 2e3da03e authored by Andres Freund's avatar Andres Freund

tableam: Add table_get_latest_tid, to wrap heap_get_latest_tid.

This primarily is to allow WHERE CURRENT OF to continue to work as it
currently does. It's not clear to me that these semantics make sense
for every AM, but it works for the in-core heap, and the out of core
zheap. We can refine it further at a later point if necessary.

Author: Andres Freund
Discussion: https://postgr.es/m/20180703070645.wchpu5muyto5n647@alap3.anarazel.de
parent 71bdc99d
...@@ -542,6 +542,7 @@ static const TableAmRoutine heapam_methods = { ...@@ -542,6 +542,7 @@ static const TableAmRoutine heapam_methods = {
.tuple_lock = heapam_tuple_lock, .tuple_lock = heapam_tuple_lock,
.tuple_fetch_row_version = heapam_fetch_row_version, .tuple_fetch_row_version = heapam_fetch_row_version,
.tuple_get_latest_tid = heap_get_latest_tid,
.tuple_satisfies_snapshot = heapam_tuple_satisfies_snapshot, .tuple_satisfies_snapshot = heapam_tuple_satisfies_snapshot,
}; };
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
*/ */
#include "postgres.h" #include "postgres.h"
#include "access/heapam.h"
#include "access/sysattr.h" #include "access/sysattr.h"
#include "access/tableam.h" #include "access/tableam.h"
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
...@@ -308,7 +307,6 @@ TidNext(TidScanState *node) ...@@ -308,7 +307,6 @@ TidNext(TidScanState *node)
ScanDirection direction; ScanDirection direction;
Snapshot snapshot; Snapshot snapshot;
Relation heapRelation; Relation heapRelation;
HeapTuple tuple;
TupleTableSlot *slot; TupleTableSlot *slot;
ItemPointerData *tidList; ItemPointerData *tidList;
int numTids; int numTids;
...@@ -332,12 +330,6 @@ TidNext(TidScanState *node) ...@@ -332,12 +330,6 @@ TidNext(TidScanState *node)
tidList = node->tss_TidList; tidList = node->tss_TidList;
numTids = node->tss_NumTids; numTids = node->tss_NumTids;
/*
* We use node->tss_htup as the tuple pointer; note this can't just be a
* local variable here, as the scan tuple slot will keep a pointer to it.
*/
tuple = &(node->tss_htup);
/* /*
* Initialize or advance scan position, depending on direction. * Initialize or advance scan position, depending on direction.
*/ */
...@@ -365,7 +357,7 @@ TidNext(TidScanState *node) ...@@ -365,7 +357,7 @@ TidNext(TidScanState *node)
while (node->tss_TidPtr >= 0 && node->tss_TidPtr < numTids) while (node->tss_TidPtr >= 0 && node->tss_TidPtr < numTids)
{ {
tuple->t_self = tidList[node->tss_TidPtr]; ItemPointerData tid = tidList[node->tss_TidPtr];
/* /*
* For WHERE CURRENT OF, the tuple retrieved from the cursor might * For WHERE CURRENT OF, the tuple retrieved from the cursor might
...@@ -373,10 +365,9 @@ TidNext(TidScanState *node) ...@@ -373,10 +365,9 @@ TidNext(TidScanState *node)
* current according to our snapshot. * current according to our snapshot.
*/ */
if (node->tss_isCurrentOf) if (node->tss_isCurrentOf)
heap_get_latest_tid(heapRelation, snapshot, &tuple->t_self); table_get_latest_tid(heapRelation, snapshot, &tid);
if (table_fetch_row_version(heapRelation, &tuple->t_self, snapshot, if (table_fetch_row_version(heapRelation, &tid, snapshot, slot))
slot))
return slot; return slot;
/* Bad TID or failed snapshot qual; try next */ /* Bad TID or failed snapshot qual; try next */
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "access/heapam.h" #include "access/heapam.h"
#include "access/sysattr.h" #include "access/sysattr.h"
#include "access/tableam.h"
#include "catalog/namespace.h" #include "catalog/namespace.h"
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
#include "libpq/pqformat.h" #include "libpq/pqformat.h"
...@@ -379,7 +380,7 @@ currtid_byreloid(PG_FUNCTION_ARGS) ...@@ -379,7 +380,7 @@ currtid_byreloid(PG_FUNCTION_ARGS)
ItemPointerCopy(tid, result); ItemPointerCopy(tid, result);
snapshot = RegisterSnapshot(GetLatestSnapshot()); snapshot = RegisterSnapshot(GetLatestSnapshot());
heap_get_latest_tid(rel, snapshot, result); table_get_latest_tid(rel, snapshot, result);
UnregisterSnapshot(snapshot); UnregisterSnapshot(snapshot);
table_close(rel, AccessShareLock); table_close(rel, AccessShareLock);
...@@ -414,7 +415,7 @@ currtid_byrelname(PG_FUNCTION_ARGS) ...@@ -414,7 +415,7 @@ currtid_byrelname(PG_FUNCTION_ARGS)
ItemPointerCopy(tid, result); ItemPointerCopy(tid, result);
snapshot = RegisterSnapshot(GetLatestSnapshot()); snapshot = RegisterSnapshot(GetLatestSnapshot());
heap_get_latest_tid(rel, snapshot, result); table_get_latest_tid(rel, snapshot, result);
UnregisterSnapshot(snapshot); UnregisterSnapshot(snapshot);
table_close(rel, AccessShareLock); table_close(rel, AccessShareLock);
......
...@@ -283,6 +283,14 @@ typedef struct TableAmRoutine ...@@ -283,6 +283,14 @@ typedef struct TableAmRoutine
Snapshot snapshot, Snapshot snapshot,
TupleTableSlot *slot); TupleTableSlot *slot);
/*
* Return the latest version of the tuple at `tid`, by updating `tid` to
* point at the newest version.
*/
void (*tuple_get_latest_tid) (Relation rel,
Snapshot snapshot,
ItemPointer tid);
/* /*
* Does the tuple in `slot` satisfy `snapshot`? The slot needs to be of * Does the tuple in `slot` satisfy `snapshot`? The slot needs to be of
* the appropriate type for the AM. * the appropriate type for the AM.
...@@ -656,6 +664,16 @@ table_fetch_row_version(Relation rel, ...@@ -656,6 +664,16 @@ table_fetch_row_version(Relation rel,
return rel->rd_tableam->tuple_fetch_row_version(rel, tid, snapshot, slot); return rel->rd_tableam->tuple_fetch_row_version(rel, tid, snapshot, slot);
} }
/*
* Return the latest version of the tuple at `tid`, by updating `tid` to
* point at the newest version.
*/
static inline void
table_get_latest_tid(Relation rel, Snapshot snapshot, ItemPointer tid)
{
rel->rd_tableam->tuple_get_latest_tid(rel, snapshot, tid);
}
/* /*
* Return true iff tuple in slot satisfies the snapshot. * Return true iff tuple in slot satisfies the snapshot.
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment