diff options
| author | Alexander Korotkov | 2024-03-30 20:39:03 +0000 |
|---|---|---|
| committer | Alexander Korotkov | 2024-03-30 20:53:56 +0000 |
| commit | b1484a3f1910bfd0e254afe40085dfc3351bda8c (patch) | |
| tree | 329e9e84dba07d2b85487c4acb5ebb975836947b /src/include/access | |
| parent | c95c25f9af4bc77f2f66a587735c50da08c12b37 (diff) | |
Let table AM insertion methods control index insertion
Previously, the executor did index insert unconditionally after calling
table AM interface methods tuple_insert() and multi_insert(). This commit
introduces the new parameter insert_indexes for these two methods. Setting
'*insert_indexes' to true saves the current logic. Setting it to false
indicates that table AM cares about index inserts itself and doesn't want the
caller to do that.
Discussion: https://postgr.es/m/CAPpHfdurb9ycV8udYqM%3Do0sPS66PJ4RCBM1g-bBpvzUfogY0EA%40mail.gmail.com
Reviewed-by: Pavel Borisov, Matthias van de Meent, Mark Dilger
Diffstat (limited to 'src/include/access')
| -rw-r--r-- | src/include/access/heapam.h | 2 | ||||
| -rw-r--r-- | src/include/access/tableam.h | 25 |
2 files changed, 19 insertions, 8 deletions
diff --git a/src/include/access/heapam.h b/src/include/access/heapam.h index 91fbc950343..32a3fbce961 100644 --- a/src/include/access/heapam.h +++ b/src/include/access/heapam.h @@ -282,7 +282,7 @@ extern void heap_insert(Relation relation, HeapTuple tup, CommandId cid, int options, BulkInsertState bistate); extern void heap_multi_insert(Relation relation, struct TupleTableSlot **slots, int ntuples, CommandId cid, int options, - BulkInsertState bistate); + BulkInsertState bistate, bool *insert_indexes); extern TM_Result heap_delete(Relation relation, ItemPointer tid, CommandId cid, Snapshot crosscheck, int options, struct TM_FailureData *tmfd, bool changingPart, diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h index cf68ec48ebf..cf76fc29d4b 100644 --- a/src/include/access/tableam.h +++ b/src/include/access/tableam.h @@ -512,7 +512,8 @@ typedef struct TableAmRoutine /* see table_tuple_insert() for reference about parameters */ TupleTableSlot *(*tuple_insert) (Relation rel, TupleTableSlot *slot, CommandId cid, int options, - struct BulkInsertStateData *bistate); + struct BulkInsertStateData *bistate, + bool *insert_indexes); /* see table_tuple_insert_speculative() for reference about parameters */ void (*tuple_insert_speculative) (Relation rel, @@ -530,7 +531,8 @@ typedef struct TableAmRoutine /* see table_multi_insert() for reference about parameters */ void (*multi_insert) (Relation rel, TupleTableSlot **slots, int nslots, - CommandId cid, int options, struct BulkInsertStateData *bistate); + CommandId cid, int options, struct BulkInsertStateData *bistate, + bool *insert_indexes); /* see table_tuple_delete() for reference about parameters */ TM_Result (*tuple_delete) (Relation rel, @@ -1384,6 +1386,12 @@ 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. * + * The table AM's implementation of tuple_insert should set `*insert_indexes` + * to true if it expects the caller to insert the relevant index tuples + * (as heap table AM does). It should set `*insert_indexes` to false if + * it cares about index inserts itself and doesn't want the caller to do + * index inserts. + * * Returns the slot containing the inserted tuple, which may differ from the * given slot. For instance, the source slot may be VirtualTupleTableSlot, but * the result slot may correspond to the table AM. On return the slot's @@ -1393,10 +1401,11 @@ table_index_delete_tuples(Relation rel, TM_IndexDeleteOp *delstate) */ static inline TupleTableSlot * table_tuple_insert(Relation rel, TupleTableSlot *slot, CommandId cid, - int options, struct BulkInsertStateData *bistate) + int options, struct BulkInsertStateData *bistate, + bool *insert_indexes) { return rel->rd_tableam->tuple_insert(rel, slot, cid, options, - bistate); + bistate, insert_indexes); } /* @@ -1448,10 +1457,11 @@ table_tuple_complete_speculative(Relation rel, TupleTableSlot *slot, */ static inline void table_multi_insert(Relation rel, TupleTableSlot **slots, int nslots, - CommandId cid, int options, struct BulkInsertStateData *bistate) + CommandId cid, int options, struct BulkInsertStateData *bistate, + bool *insert_indexes) { rel->rd_tableam->multi_insert(rel, slots, nslots, - cid, options, bistate); + cid, options, bistate, insert_indexes); } /* @@ -2096,7 +2106,8 @@ table_scan_sample_next_tuple(TableScanDesc scan, * ---------------------------------------------------------------------------- */ -extern void simple_table_tuple_insert(Relation rel, TupleTableSlot *slot); +extern void simple_table_tuple_insert(Relation rel, TupleTableSlot *slot, + bool *insert_indexes); extern void simple_table_tuple_delete(Relation rel, ItemPointer tid, Snapshot snapshot, TupleTableSlot *oldSlot); |
