Skip to content

Commit da841aa

Browse files
committed
Revert: Let table AM insertion methods control index insertion
This commit reverts b1484a3 per review by Andres Freund. Discussion: https://postgr.es/m/20240410165236.rwyrny7ihi4ddxw4%40awork3.anarazel.de
1 parent bc1e209 commit da841aa

File tree

12 files changed

+28
-72
lines changed

12 files changed

+28
-72
lines changed

src/backend/access/heap/heapam.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,8 +2257,7 @@ heap_multi_insert_pages(HeapTuple *heaptuples, int done, int ntuples, Size saveF
22572257
*/
22582258
void
22592259
heap_multi_insert(Relation relation, TupleTableSlot **slots, int ntuples,
2260-
CommandId cid, int options, BulkInsertState bistate,
2261-
bool *insert_indexes)
2260+
CommandId cid, int options, BulkInsertState bistate)
22622261
{
22632262
TransactionId xid = GetCurrentTransactionId();
22642263
HeapTuple *heaptuples;
@@ -2607,7 +2606,6 @@ heap_multi_insert(Relation relation, TupleTableSlot **slots, int ntuples,
26072606
slots[i]->tts_tid = heaptuples[i]->t_self;
26082607

26092608
pgstat_count_heap_insert(relation, ntuples);
2610-
*insert_indexes = true;
26112609
}
26122610

26132611
/*

src/backend/access/heap/heapam_handler.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ heapam_tuple_satisfies_snapshot(Relation rel, TupleTableSlot *slot,
245245

246246
static TupleTableSlot *
247247
heapam_tuple_insert(Relation relation, TupleTableSlot *slot, CommandId cid,
248-
int options, BulkInsertState bistate, bool *insert_indexes)
248+
int options, BulkInsertState bistate)
249249
{
250250
bool shouldFree = true;
251251
HeapTuple tuple = ExecFetchSlotHeapTuple(slot, true, &shouldFree);
@@ -261,8 +261,6 @@ heapam_tuple_insert(Relation relation, TupleTableSlot *slot, CommandId cid,
261261
if (shouldFree)
262262
pfree(tuple);
263263

264-
*insert_indexes = true;
265-
266264
return slot;
267265
}
268266

src/backend/access/table/tableam.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,9 @@ table_tuple_get_latest_tid(TableScanDesc scan, ItemPointer tid)
273273
* default command ID and not allowing access to the speedup options.
274274
*/
275275
void
276-
simple_table_tuple_insert(Relation rel, TupleTableSlot *slot,
277-
bool *insert_indexes)
276+
simple_table_tuple_insert(Relation rel, TupleTableSlot *slot)
278277
{
279-
table_tuple_insert(rel, slot, GetCurrentCommandId(true), 0, NULL,
280-
insert_indexes);
278+
table_tuple_insert(rel, slot, GetCurrentCommandId(true), 0, NULL);
281279
}
282280

283281
/*

src/backend/catalog/indexing.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,12 @@ void
273273
CatalogTuplesMultiInsertWithInfo(Relation heapRel, TupleTableSlot **slot,
274274
int ntuples, CatalogIndexState indstate)
275275
{
276-
bool insertIndexes;
277-
278276
/* Nothing to do */
279277
if (ntuples <= 0)
280278
return;
281279

282280
heap_multi_insert(heapRel, slot, ntuples,
283-
GetCurrentCommandId(true), 0, NULL, &insertIndexes);
281+
GetCurrentCommandId(true), 0, NULL);
284282

285283
/*
286284
* There is no equivalent to heap_multi_insert for the catalog indexes, so

src/backend/commands/copyfrom.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,6 @@ CopyMultiInsertBufferFlush(CopyMultiInsertInfo *miinfo,
395395
bool line_buf_valid = cstate->line_buf_valid;
396396
uint64 save_cur_lineno = cstate->cur_lineno;
397397
MemoryContext oldcontext;
398-
bool insertIndexes;
399398

400399
Assert(buffer->bistate != NULL);
401400

@@ -415,8 +414,7 @@ CopyMultiInsertBufferFlush(CopyMultiInsertInfo *miinfo,
415414
nused,
416415
mycid,
417416
ti_options,
418-
buffer->bistate,
419-
&insertIndexes);
417+
buffer->bistate);
420418
MemoryContextSwitchTo(oldcontext);
421419

422420
for (i = 0; i < nused; i++)
@@ -425,7 +423,7 @@ CopyMultiInsertBufferFlush(CopyMultiInsertInfo *miinfo,
425423
* If there are any indexes, update them for all the inserted
426424
* tuples, and run AFTER ROW INSERT triggers.
427425
*/
428-
if (insertIndexes && resultRelInfo->ri_NumIndices > 0)
426+
if (resultRelInfo->ri_NumIndices > 0)
429427
{
430428
List *recheckIndexes;
431429

@@ -1265,14 +1263,11 @@ CopyFrom(CopyFromState cstate)
12651263
}
12661264
else
12671265
{
1268-
bool insertIndexes;
1269-
12701266
/* OK, store the tuple and create index entries for it */
12711267
table_tuple_insert(resultRelInfo->ri_RelationDesc,
1272-
myslot, mycid, ti_options, bistate,
1273-
&insertIndexes);
1268+
myslot, mycid, ti_options, bistate);
12741269

1275-
if (insertIndexes && resultRelInfo->ri_NumIndices > 0)
1270+
if (resultRelInfo->ri_NumIndices > 0)
12761271
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
12771272
myslot,
12781273
estate,

src/backend/commands/createas.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,6 @@ static bool
578578
intorel_receive(TupleTableSlot *slot, DestReceiver *self)
579579
{
580580
DR_intorel *myState = (DR_intorel *) self;
581-
bool insertIndexes;
582581

583582
/* Nothing to insert if WITH NO DATA is specified. */
584583
if (!myState->into->skipData)
@@ -595,8 +594,7 @@ intorel_receive(TupleTableSlot *slot, DestReceiver *self)
595594
slot,
596595
myState->output_cid,
597596
myState->ti_options,
598-
myState->bistate,
599-
&insertIndexes);
597+
myState->bistate);
600598
}
601599

602600
/* We know this is a newly created relation, so there are no indexes */

src/backend/commands/matview.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,6 @@ static bool
476476
transientrel_receive(TupleTableSlot *slot, DestReceiver *self)
477477
{
478478
DR_transientrel *myState = (DR_transientrel *) self;
479-
bool insertIndexes;
480479

481480
/*
482481
* Note that the input slot might not be of the type of the target
@@ -491,8 +490,7 @@ transientrel_receive(TupleTableSlot *slot, DestReceiver *self)
491490
slot,
492491
myState->output_cid,
493492
myState->ti_options,
494-
myState->bistate,
495-
&insertIndexes);
493+
myState->bistate);
496494

497495
/* We know this is a newly created relation, so there are no indexes */
498496

src/backend/commands/tablecmds.c

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6391,12 +6391,8 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap, LOCKMODE lockmode)
63916391

63926392
/* Write the tuple out to the new relation */
63936393
if (newrel)
6394-
{
6395-
bool insertIndexes;
6396-
63976394
table_tuple_insert(newrel, insertslot, mycid,
6398-
ti_options, bistate, &insertIndexes);
6399-
}
6395+
ti_options, bistate);
64006396

64016397
ResetExprContext(econtext);
64026398

@@ -21037,7 +21033,6 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
2103721033
while (table_scan_getnextslot(scan, ForwardScanDirection, srcslot))
2103821034
{
2103921035
bool found = false;
21040-
bool insert_indexes;
2104121036
TupleTableSlot *insertslot;
2104221037

2104321038
/* Extract data from old tuple. */
@@ -21090,12 +21085,9 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar
2109021085
ExecStoreVirtualTuple(insertslot);
2109121086
}
2109221087

21093-
/*
21094-
* Write the tuple out to the new relation. We ignore the
21095-
* 'insert_indexes' flag since newPartRel has no indexes anyway.
21096-
*/
21088+
/* Write the tuple out to the new relation. */
2109721089
(void) table_tuple_insert(pc->partRel, insertslot, mycid,
21098-
ti_options, pc->bistate, &insert_indexes);
21090+
ti_options, pc->bistate);
2109921091

2110021092
ResetExprContext(econtext);
2110121093

@@ -21364,7 +21356,6 @@ moveMergedTablesRows(Relation rel, List *mergingPartitionsList,
2136421356
while (table_scan_getnextslot(scan, ForwardScanDirection, srcslot))
2136521357
{
2136621358
TupleTableSlot *insertslot;
21367-
bool insert_indexes;
2136821359

2136921360
/* Extract data from old tuple. */
2137021361
slot_getallattrs(srcslot);
@@ -21389,12 +21380,9 @@ moveMergedTablesRows(Relation rel, List *mergingPartitionsList,
2138921380
ExecStoreVirtualTuple(insertslot);
2139021381
}
2139121382

21392-
/*
21393-
* Write the tuple out to the new relation. We ignore the
21394-
* 'insert_indexes' flag since newPartRel has no indexes anyway.
21395-
*/
21383+
/* Write the tuple out to the new relation. */
2139621384
(void) table_tuple_insert(newPartRel, insertslot, mycid,
21397-
ti_options, bistate, &insert_indexes);
21385+
ti_options, bistate);
2139821386

2139921387
CHECK_FOR_INTERRUPTS();
2140021388
}

src/backend/executor/execReplication.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,6 @@ ExecSimpleRelationInsert(ResultRelInfo *resultRelInfo,
509509
if (!skip_tuple)
510510
{
511511
List *recheckIndexes = NIL;
512-
bool insertIndexes;
513512

514513
/* Compute stored generated columns */
515514
if (rel->rd_att->constr &&
@@ -524,10 +523,9 @@ ExecSimpleRelationInsert(ResultRelInfo *resultRelInfo,
524523
ExecPartitionCheck(resultRelInfo, slot, estate, true);
525524

526525
/* OK, store the tuple and create index entries for it */
527-
simple_table_tuple_insert(resultRelInfo->ri_RelationDesc, slot,
528-
&insertIndexes);
526+
simple_table_tuple_insert(resultRelInfo->ri_RelationDesc, slot);
529527

530-
if (insertIndexes && resultRelInfo->ri_NumIndices > 0)
528+
if (resultRelInfo->ri_NumIndices > 0)
531529
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
532530
slot, estate, false, false,
533531
NULL, NIL, false);

src/backend/executor/nodeModifyTable.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,15 +1135,13 @@ ExecInsert(ModifyTableContext *context,
11351135
}
11361136
else
11371137
{
1138-
bool insertIndexes;
1139-
11401138
/* insert the tuple normally */
11411139
slot = table_tuple_insert(resultRelationDesc, slot,
11421140
estate->es_output_cid,
1143-
0, NULL, &insertIndexes);
1141+
0, NULL);
11441142

11451143
/* insert index entries for tuple */
1146-
if (insertIndexes && resultRelInfo->ri_NumIndices > 0)
1144+
if (resultRelInfo->ri_NumIndices > 0)
11471145
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
11481146
slot, estate, false,
11491147
false, NULL, NIL,

src/include/access/heapam.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ extern void heap_insert(Relation relation, HeapTuple tup, CommandId cid,
320320
int options, BulkInsertState bistate);
321321
extern void heap_multi_insert(Relation relation, struct TupleTableSlot **slots,
322322
int ntuples, CommandId cid, int options,
323-
BulkInsertState bistate, bool *insert_indexes);
323+
BulkInsertState bistate);
324324
extern TM_Result heap_delete(Relation relation, ItemPointer tid,
325325
CommandId cid, Snapshot crosscheck, int options,
326326
struct TM_FailureData *tmfd, bool changingPart,

src/include/access/tableam.h

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,7 @@ typedef struct TableAmRoutine
519519
/* see table_tuple_insert() for reference about parameters */
520520
TupleTableSlot *(*tuple_insert) (Relation rel, TupleTableSlot *slot,
521521
CommandId cid, int options,
522-
struct BulkInsertStateData *bistate,
523-
bool *insert_indexes);
522+
struct BulkInsertStateData *bistate);
524523

525524
/* see table_tuple_insert_speculative() for reference about parameters */
526525
void (*tuple_insert_speculative) (Relation rel,
@@ -538,8 +537,7 @@ typedef struct TableAmRoutine
538537

539538
/* see table_multi_insert() for reference about parameters */
540539
void (*multi_insert) (Relation rel, TupleTableSlot **slots, int nslots,
541-
CommandId cid, int options, struct BulkInsertStateData *bistate,
542-
bool *insert_indexes);
540+
CommandId cid, int options, struct BulkInsertStateData *bistate);
543541

544542
/* see table_tuple_delete() for reference about parameters */
545543
TM_Result (*tuple_delete) (Relation rel,
@@ -1387,12 +1385,6 @@ table_index_delete_tuples(Relation rel, TM_IndexDeleteOp *delstate)
13871385
* behavior) is also just passed through to RelationGetBufferForTuple. If
13881386
* `bistate` is provided, table_finish_bulk_insert() needs to be called.
13891387
*
1390-
* The table AM's implementation of tuple_insert should set `*insert_indexes`
1391-
* to true if it expects the caller to insert the relevant index tuples
1392-
* (as heap table AM does). It should set `*insert_indexes` to false if
1393-
* it cares about index inserts itself and doesn't want the caller to do
1394-
* index inserts.
1395-
*
13961388
* Returns the slot containing the inserted tuple, which may differ from the
13971389
* given slot. For instance, the source slot may be VirtualTupleTableSlot, but
13981390
* the result slot may correspond to the table AM. On return the slot's
@@ -1402,11 +1394,10 @@ table_index_delete_tuples(Relation rel, TM_IndexDeleteOp *delstate)
14021394
*/
14031395
static inline TupleTableSlot *
14041396
table_tuple_insert(Relation rel, TupleTableSlot *slot, CommandId cid,
1405-
int options, struct BulkInsertStateData *bistate,
1406-
bool *insert_indexes)
1397+
int options, struct BulkInsertStateData *bistate)
14071398
{
14081399
return rel->rd_tableam->tuple_insert(rel, slot, cid, options,
1409-
bistate, insert_indexes);
1400+
bistate);
14101401
}
14111402

14121403
/*
@@ -1458,11 +1449,10 @@ table_tuple_complete_speculative(Relation rel, TupleTableSlot *slot,
14581449
*/
14591450
static inline void
14601451
table_multi_insert(Relation rel, TupleTableSlot **slots, int nslots,
1461-
CommandId cid, int options, struct BulkInsertStateData *bistate,
1462-
bool *insert_indexes)
1452+
CommandId cid, int options, struct BulkInsertStateData *bistate)
14631453
{
14641454
rel->rd_tableam->multi_insert(rel, slots, nslots,
1465-
cid, options, bistate, insert_indexes);
1455+
cid, options, bistate);
14661456
}
14671457

14681458
/*
@@ -2087,8 +2077,7 @@ table_scan_sample_next_tuple(TableScanDesc scan,
20872077
* ----------------------------------------------------------------------------
20882078
*/
20892079

2090-
extern void simple_table_tuple_insert(Relation rel, TupleTableSlot *slot,
2091-
bool *insert_indexes);
2080+
extern void simple_table_tuple_insert(Relation rel, TupleTableSlot *slot);
20922081
extern void simple_table_tuple_delete(Relation rel, ItemPointer tid,
20932082
Snapshot snapshot,
20942083
TupleTableSlot *oldSlot);

0 commit comments

Comments
 (0)