aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor
diff options
context:
space:
mode:
authorAlexander Korotkov <akorotkov@postgresql.org>2024-03-21 23:00:43 +0200
committerAlexander Korotkov <akorotkov@postgresql.org>2024-03-21 23:00:43 +0200
commit0997e0af273d80add75bcf5616eee000d0a78397 (patch)
tree199c96b60baaead3d37a9918ee63f256f2f21410 /src/backend/executor
parentc35a3fb5e067fc95f13206418e3785d2cb059da1 (diff)
downloadpostgresql-0997e0af273d80add75bcf5616eee000d0a78397.tar.gz
postgresql-0997e0af273d80add75bcf5616eee000d0a78397.zip
Add TupleTableSlotOps.is_current_xact_tuple() method
This allows us to abstract how/whether table AM uses transaction identifiers. A custom table AM can use a custom slot, which may not store xmin directly, but determine the tuple belonging to the current transaction in the other way. Discussion: https://postgr.es/m/CAPpHfdurb9ycV8udYqM%3Do0sPS66PJ4RCBM1g-bBpvzUfogY0EA%40mail.gmail.com Reviewed-by: Matthias van de Meent, Mark Dilger, Pavel Borisov Reviewed-by: Nikita Malakhov, Japin Li
Diffstat (limited to 'src/backend/executor')
-rw-r--r--src/backend/executor/execTuples.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/backend/executor/execTuples.c b/src/backend/executor/execTuples.c
index a7aa2ee02b1..7a7c7860416 100644
--- a/src/backend/executor/execTuples.c
+++ b/src/backend/executor/execTuples.c
@@ -60,6 +60,7 @@
#include "access/heaptoast.h"
#include "access/htup_details.h"
#include "access/tupdesc_details.h"
+#include "access/xact.h"
#include "catalog/pg_type.h"
#include "funcapi.h"
#include "nodes/nodeFuncs.h"
@@ -149,6 +150,22 @@ tts_virtual_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
}
/*
+ * VirtualTupleTableSlots never have storage tuples. We generally
+ * shouldn't get here, but provide a user-friendly message if we do.
+ */
+static bool
+tts_virtual_is_current_xact_tuple(TupleTableSlot *slot)
+{
+ Assert(!TTS_EMPTY(slot));
+
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("don't have a storage tuple in this context")));
+
+ return false; /* silence compiler warnings */
+}
+
+/*
* To materialize a virtual slot all the datums that aren't passed by value
* have to be copied into the slot's memory context. To do so, compute the
* required size, and allocate enough memory to store all attributes. That's
@@ -354,6 +371,29 @@ tts_heap_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
slot->tts_tupleDescriptor, isnull);
}
+static bool
+tts_heap_is_current_xact_tuple(TupleTableSlot *slot)
+{
+ HeapTupleTableSlot *hslot = (HeapTupleTableSlot *) slot;
+ TransactionId xmin;
+
+ Assert(!TTS_EMPTY(slot));
+
+ /*
+ * In some code paths it's possible to get here with a non-materialized
+ * slot, in which case we can't check if tuple is created by the current
+ * transaction.
+ */
+ if (!hslot->tuple)
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("don't have a storage tuple in this context")));
+
+ xmin = HeapTupleHeaderGetRawXmin(hslot->tuple->t_data);
+
+ return TransactionIdIsCurrentTransactionId(xmin);
+}
+
static void
tts_heap_materialize(TupleTableSlot *slot)
{
@@ -521,6 +561,18 @@ tts_minimal_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
return 0; /* silence compiler warnings */
}
+static bool
+tts_minimal_is_current_xact_tuple(TupleTableSlot *slot)
+{
+ Assert(!TTS_EMPTY(slot));
+
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("don't have a storage tuple in this context")));
+
+ return false; /* silence compiler warnings */
+}
+
static void
tts_minimal_materialize(TupleTableSlot *slot)
{
@@ -714,6 +766,29 @@ tts_buffer_heap_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)
slot->tts_tupleDescriptor, isnull);
}
+static bool
+tts_buffer_is_current_xact_tuple(TupleTableSlot *slot)
+{
+ BufferHeapTupleTableSlot *bslot = (BufferHeapTupleTableSlot *) slot;
+ TransactionId xmin;
+
+ Assert(!TTS_EMPTY(slot));
+
+ /*
+ * In some code paths it's possible to get here with a non-materialized
+ * slot, in which case we can't check if tuple is created by the current
+ * transaction.
+ */
+ if (!bslot->base.tuple)
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("don't have a storage tuple in this context")));
+
+ xmin = HeapTupleHeaderGetRawXmin(bslot->base.tuple->t_data);
+
+ return TransactionIdIsCurrentTransactionId(xmin);
+}
+
static void
tts_buffer_heap_materialize(TupleTableSlot *slot)
{
@@ -1029,6 +1104,7 @@ const TupleTableSlotOps TTSOpsVirtual = {
.getsomeattrs = tts_virtual_getsomeattrs,
.getsysattr = tts_virtual_getsysattr,
.materialize = tts_virtual_materialize,
+ .is_current_xact_tuple = tts_virtual_is_current_xact_tuple,
.copyslot = tts_virtual_copyslot,
/*
@@ -1048,6 +1124,7 @@ const TupleTableSlotOps TTSOpsHeapTuple = {
.clear = tts_heap_clear,
.getsomeattrs = tts_heap_getsomeattrs,
.getsysattr = tts_heap_getsysattr,
+ .is_current_xact_tuple = tts_heap_is_current_xact_tuple,
.materialize = tts_heap_materialize,
.copyslot = tts_heap_copyslot,
.get_heap_tuple = tts_heap_get_heap_tuple,
@@ -1065,6 +1142,7 @@ const TupleTableSlotOps TTSOpsMinimalTuple = {
.clear = tts_minimal_clear,
.getsomeattrs = tts_minimal_getsomeattrs,
.getsysattr = tts_minimal_getsysattr,
+ .is_current_xact_tuple = tts_minimal_is_current_xact_tuple,
.materialize = tts_minimal_materialize,
.copyslot = tts_minimal_copyslot,
@@ -1082,6 +1160,7 @@ const TupleTableSlotOps TTSOpsBufferHeapTuple = {
.clear = tts_buffer_heap_clear,
.getsomeattrs = tts_buffer_heap_getsomeattrs,
.getsysattr = tts_buffer_heap_getsysattr,
+ .is_current_xact_tuple = tts_buffer_is_current_xact_tuple,
.materialize = tts_buffer_heap_materialize,
.copyslot = tts_buffer_heap_copyslot,
.get_heap_tuple = tts_buffer_heap_get_heap_tuple,