From d9be5dde5057b35c294ab8948a2a9a7f09e75651 Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Fri, 9 Jun 2023 00:28:27 +0300 Subject: [PATCH 07/12] Allow table AM tuple_insert() method to return the different slot This allows table AM to return native tuple slot even if VirtualTupleTableSlot is given as an input. Native tuple slot have its knowledge about system attributes, which could be accessed in future. --- src/backend/access/heap/heapam_handler.c | 4 +++- src/backend/executor/nodeModifyTable.c | 6 +++--- src/include/access/tableam.h | 20 +++++++++++--------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/backend/access/heap/heapam_handler.c b/src/backend/access/heap/heapam_handler.c index b9933917a56..ac32698f9d9 100644 --- a/src/backend/access/heap/heapam_handler.c +++ b/src/backend/access/heap/heapam_handler.c @@ -257,7 +257,7 @@ heapam_tuple_satisfies_snapshot(Relation rel, TupleTableSlot *slot, * ---------------------------------------------------------------------------- */ -static void +static TupleTableSlot * heapam_tuple_insert(Relation relation, TupleTableSlot *slot, CommandId cid, int options, BulkInsertState bistate) { @@ -274,6 +274,8 @@ heapam_tuple_insert(Relation relation, TupleTableSlot *slot, CommandId cid, if (shouldFree) pfree(tuple); + + return slot; } static void diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c index 717dc749500..ec1d6499dcc 100644 --- a/src/backend/executor/nodeModifyTable.c +++ b/src/backend/executor/nodeModifyTable.c @@ -1041,9 +1041,9 @@ ExecInsert(ModifyTableContext *context, else { /* insert the tuple normally */ - table_tuple_insert(resultRelationDesc, slot, - estate->es_output_cid, - 0, NULL); + slot = table_tuple_insert(resultRelationDesc, slot, + estate->es_output_cid, + 0, NULL); /* insert index entries for tuple */ if (resultRelInfo->ri_NumIndices > 0) diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h index 4ba44856a2e..6501576e6ce 100644 --- a/src/include/access/tableam.h +++ b/src/include/access/tableam.h @@ -512,9 +512,9 @@ typedef struct TableAmRoutine */ /* see table_tuple_insert() for reference about parameters */ - void (*tuple_insert) (Relation rel, TupleTableSlot *slot, - CommandId cid, int options, - struct BulkInsertStateData *bistate); + TupleTableSlot *(*tuple_insert) (Relation rel, TupleTableSlot *slot, + CommandId cid, int options, + struct BulkInsertStateData *bistate); /* see table_tuple_insert_with_arbiter() for reference about parameters */ TupleTableSlot *(*tuple_insert_with_arbiter) (ResultRelInfo *resultRelInfo, @@ -1390,16 +1390,18 @@ table_index_delete_tuples(Relation rel, TM_IndexDeleteOp *delstate) * behavior) is also just passed through to RelationGetBufferForTuple. If * `bistate` is provided, table_finish_bulk_insert() needs to be called. * - * On return the slot's tts_tid and tts_tableOid are updated to reflect the - * insertion. But note that any toasting of fields within the slot is NOT - * reflected in the slots contents. + * Returns the slot containing the inserted tuple, which may differ from the + * given slot. For instance, source slot may by VirtualTupleTableSlot, but + * the result is corresponding to table AM. On return the slot's tts_tid and + * tts_tableOid are updated to reflect the insertion. But note that any + * toasting of fields within the slot is NOT reflected in the slots contents. */ -static inline void +static inline TupleTableSlot * table_tuple_insert(Relation rel, TupleTableSlot *slot, CommandId cid, int options, struct BulkInsertStateData *bistate) { - rel->rd_tableam->tuple_insert(rel, slot, cid, options, - bistate); + return rel->rd_tableam->tuple_insert(rel, slot, cid, options, + bistate); } /* -- 2.39.3 (Apple Git-145)