Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a04daa9

Browse files
committed
Remove es_result_relation_info from EState.
Maintaining 'es_result_relation_info' correctly at all times has become cumbersome, especially with partitioning where each partition gets its own result relation info. Having to set and reset it across arbitrary operations has caused bugs in the past. This changes all the places that used 'es_result_relation_info', to receive the currently active ResultRelInfo via function parameters instead. Author: Amit Langote Discussion: https://www.postgresql.org/message-id/CA%2BHiwqGEmiib8FLiHMhKB%2BCH5dRgHSLc5N5wnvc4kym%2BZYpQEQ%40mail.gmail.com
1 parent 178f2d5 commit a04daa9

File tree

13 files changed

+131
-177
lines changed

13 files changed

+131
-177
lines changed

src/backend/commands/copy.c

+6-13
Original file line numberDiff line numberDiff line change
@@ -2489,9 +2489,6 @@ CopyMultiInsertBufferFlush(CopyMultiInsertInfo *miinfo,
24892489
ResultRelInfo *resultRelInfo = buffer->resultRelInfo;
24902490
TupleTableSlot **slots = buffer->slots;
24912491

2492-
/* Set es_result_relation_info to the ResultRelInfo we're flushing. */
2493-
estate->es_result_relation_info = resultRelInfo;
2494-
24952492
/*
24962493
* Print error context information correctly, if one of the operations
24972494
* below fail.
@@ -2524,7 +2521,8 @@ CopyMultiInsertBufferFlush(CopyMultiInsertInfo *miinfo,
25242521

25252522
cstate->cur_lineno = buffer->linenos[i];
25262523
recheckIndexes =
2527-
ExecInsertIndexTuples(buffer->slots[i], estate, false, NULL,
2524+
ExecInsertIndexTuples(resultRelInfo,
2525+
buffer->slots[i], estate, false, NULL,
25282526
NIL);
25292527
ExecARInsertTriggers(estate, resultRelInfo,
25302528
slots[i], recheckIndexes,
@@ -2839,8 +2837,6 @@ CopyFrom(CopyState cstate)
28392837

28402838
ExecOpenIndices(resultRelInfo, false);
28412839

2842-
estate->es_result_relation_info = resultRelInfo;
2843-
28442840
/*
28452841
* Set up a ModifyTableState so we can let FDW(s) init themselves for
28462842
* foreign-table result relation(s).
@@ -3108,11 +3104,6 @@ CopyFrom(CopyState cstate)
31083104
prevResultRelInfo = resultRelInfo;
31093105
}
31103106

3111-
/*
3112-
* For ExecInsertIndexTuples() to work on the partition's indexes
3113-
*/
3114-
estate->es_result_relation_info = resultRelInfo;
3115-
31163107
/*
31173108
* If we're capturing transition tuples, we might need to convert
31183109
* from the partition rowtype to root rowtype.
@@ -3217,7 +3208,8 @@ CopyFrom(CopyState cstate)
32173208
/* Compute stored generated columns */
32183209
if (resultRelInfo->ri_RelationDesc->rd_att->constr &&
32193210
resultRelInfo->ri_RelationDesc->rd_att->constr->has_generated_stored)
3220-
ExecComputeStoredGenerated(estate, myslot, CMD_INSERT);
3211+
ExecComputeStoredGenerated(resultRelInfo, estate, myslot,
3212+
CMD_INSERT);
32213213

32223214
/*
32233215
* If the target is a plain table, check the constraints of
@@ -3288,7 +3280,8 @@ CopyFrom(CopyState cstate)
32883280
myslot, mycid, ti_options, bistate);
32893281

32903282
if (resultRelInfo->ri_NumIndices > 0)
3291-
recheckIndexes = ExecInsertIndexTuples(myslot,
3283+
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
3284+
myslot,
32923285
estate,
32933286
false,
32943287
NULL,

src/backend/commands/tablecmds.c

-2
Original file line numberDiff line numberDiff line change
@@ -1820,7 +1820,6 @@ ExecuteTruncateGuts(List *explicit_rels, List *relids, List *relids_logged,
18201820
resultRelInfo = resultRelInfos;
18211821
foreach(cell, rels)
18221822
{
1823-
estate->es_result_relation_info = resultRelInfo;
18241823
ExecBSTruncateTriggers(estate, resultRelInfo);
18251824
resultRelInfo++;
18261825
}
@@ -1950,7 +1949,6 @@ ExecuteTruncateGuts(List *explicit_rels, List *relids, List *relids_logged,
19501949
resultRelInfo = resultRelInfos;
19511950
foreach(cell, rels)
19521951
{
1953-
estate->es_result_relation_info = resultRelInfo;
19541952
ExecASTruncateTriggers(estate, resultRelInfo);
19551953
resultRelInfo++;
19561954
}

src/backend/executor/execIndexing.c

+3-6
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,15 @@ ExecCloseIndices(ResultRelInfo *resultRelInfo)
270270
* ----------------------------------------------------------------
271271
*/
272272
List *
273-
ExecInsertIndexTuples(TupleTableSlot *slot,
273+
ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
274+
TupleTableSlot *slot,
274275
EState *estate,
275276
bool noDupErr,
276277
bool *specConflict,
277278
List *arbiterIndexes)
278279
{
279280
ItemPointer tupleid = &slot->tts_tid;
280281
List *result = NIL;
281-
ResultRelInfo *resultRelInfo;
282282
int i;
283283
int numIndices;
284284
RelationPtr relationDescs;
@@ -293,7 +293,6 @@ ExecInsertIndexTuples(TupleTableSlot *slot,
293293
/*
294294
* Get information from the result relation info structure.
295295
*/
296-
resultRelInfo = estate->es_result_relation_info;
297296
numIndices = resultRelInfo->ri_NumIndices;
298297
relationDescs = resultRelInfo->ri_IndexRelationDescs;
299298
indexInfoArray = resultRelInfo->ri_IndexRelationInfo;
@@ -479,11 +478,10 @@ ExecInsertIndexTuples(TupleTableSlot *slot,
479478
* ----------------------------------------------------------------
480479
*/
481480
bool
482-
ExecCheckIndexConstraints(TupleTableSlot *slot,
481+
ExecCheckIndexConstraints(ResultRelInfo *resultRelInfo, TupleTableSlot *slot,
483482
EState *estate, ItemPointer conflictTid,
484483
List *arbiterIndexes)
485484
{
486-
ResultRelInfo *resultRelInfo;
487485
int i;
488486
int numIndices;
489487
RelationPtr relationDescs;
@@ -501,7 +499,6 @@ ExecCheckIndexConstraints(TupleTableSlot *slot,
501499
/*
502500
* Get information from the result relation info structure.
503501
*/
504-
resultRelInfo = estate->es_result_relation_info;
505502
numIndices = resultRelInfo->ri_NumIndices;
506503
relationDescs = resultRelInfo->ri_IndexRelationDescs;
507504
indexInfoArray = resultRelInfo->ri_IndexRelationInfo;

src/backend/executor/execMain.c

-4
Original file line numberDiff line numberDiff line change
@@ -827,9 +827,6 @@ InitPlan(QueryDesc *queryDesc, int eflags)
827827

828828
estate->es_plannedstmt = plannedstmt;
829829

830-
/* es_result_relation_info is NULL except when within ModifyTable */
831-
estate->es_result_relation_info = NULL;
832-
833830
/*
834831
* Next, build the ExecRowMark array from the PlanRowMark(s), if any.
835832
*/
@@ -2694,7 +2691,6 @@ EvalPlanQualStart(EPQState *epqstate, Plan *planTree)
26942691
* subplans themselves are initialized.
26952692
*/
26962693
parentestate->es_result_relations = NULL;
2697-
/* es_result_relation_info must NOT be copied */
26982694
/* es_trig_target_relations must NOT be copied */
26992695
rcestate->es_top_eflags = parentestate->es_top_eflags;
27002696
rcestate->es_instrument = parentestate->es_instrument;

src/backend/executor/execReplication.c

+14-10
Original file line numberDiff line numberDiff line change
@@ -404,10 +404,10 @@ RelationFindReplTupleSeq(Relation rel, LockTupleMode lockmode,
404404
* Caller is responsible for opening the indexes.
405405
*/
406406
void
407-
ExecSimpleRelationInsert(EState *estate, TupleTableSlot *slot)
407+
ExecSimpleRelationInsert(ResultRelInfo *resultRelInfo,
408+
EState *estate, TupleTableSlot *slot)
408409
{
409410
bool skip_tuple = false;
410-
ResultRelInfo *resultRelInfo = estate->es_result_relation_info;
411411
Relation rel = resultRelInfo->ri_RelationDesc;
412412

413413
/* For now we support only tables. */
@@ -430,7 +430,8 @@ ExecSimpleRelationInsert(EState *estate, TupleTableSlot *slot)
430430
/* Compute stored generated columns */
431431
if (rel->rd_att->constr &&
432432
rel->rd_att->constr->has_generated_stored)
433-
ExecComputeStoredGenerated(estate, slot, CMD_INSERT);
433+
ExecComputeStoredGenerated(resultRelInfo, estate, slot,
434+
CMD_INSERT);
434435

435436
/* Check the constraints of the tuple */
436437
if (rel->rd_att->constr)
@@ -442,7 +443,8 @@ ExecSimpleRelationInsert(EState *estate, TupleTableSlot *slot)
442443
simple_table_tuple_insert(resultRelInfo->ri_RelationDesc, slot);
443444

444445
if (resultRelInfo->ri_NumIndices > 0)
445-
recheckIndexes = ExecInsertIndexTuples(slot, estate, false, NULL,
446+
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
447+
slot, estate, false, NULL,
446448
NIL);
447449

448450
/* AFTER ROW INSERT Triggers */
@@ -466,11 +468,11 @@ ExecSimpleRelationInsert(EState *estate, TupleTableSlot *slot)
466468
* Caller is responsible for opening the indexes.
467469
*/
468470
void
469-
ExecSimpleRelationUpdate(EState *estate, EPQState *epqstate,
471+
ExecSimpleRelationUpdate(ResultRelInfo *resultRelInfo,
472+
EState *estate, EPQState *epqstate,
470473
TupleTableSlot *searchslot, TupleTableSlot *slot)
471474
{
472475
bool skip_tuple = false;
473-
ResultRelInfo *resultRelInfo = estate->es_result_relation_info;
474476
Relation rel = resultRelInfo->ri_RelationDesc;
475477
ItemPointer tid = &(searchslot->tts_tid);
476478

@@ -496,7 +498,8 @@ ExecSimpleRelationUpdate(EState *estate, EPQState *epqstate,
496498
/* Compute stored generated columns */
497499
if (rel->rd_att->constr &&
498500
rel->rd_att->constr->has_generated_stored)
499-
ExecComputeStoredGenerated(estate, slot, CMD_UPDATE);
501+
ExecComputeStoredGenerated(resultRelInfo, estate, slot,
502+
CMD_UPDATE);
500503

501504
/* Check the constraints of the tuple */
502505
if (rel->rd_att->constr)
@@ -508,7 +511,8 @@ ExecSimpleRelationUpdate(EState *estate, EPQState *epqstate,
508511
&update_indexes);
509512

510513
if (resultRelInfo->ri_NumIndices > 0 && update_indexes)
511-
recheckIndexes = ExecInsertIndexTuples(slot, estate, false, NULL,
514+
recheckIndexes = ExecInsertIndexTuples(resultRelInfo,
515+
slot, estate, false, NULL,
512516
NIL);
513517

514518
/* AFTER ROW UPDATE Triggers */
@@ -527,11 +531,11 @@ ExecSimpleRelationUpdate(EState *estate, EPQState *epqstate,
527531
* Caller is responsible for opening the indexes.
528532
*/
529533
void
530-
ExecSimpleRelationDelete(EState *estate, EPQState *epqstate,
534+
ExecSimpleRelationDelete(ResultRelInfo *resultRelInfo,
535+
EState *estate, EPQState *epqstate,
531536
TupleTableSlot *searchslot)
532537
{
533538
bool skip_tuple = false;
534-
ResultRelInfo *resultRelInfo = estate->es_result_relation_info;
535539
Relation rel = resultRelInfo->ri_RelationDesc;
536540
ItemPointer tid = &searchslot->tts_tid;
537541

src/backend/executor/execUtils.c

-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ CreateExecutorState(void)
125125

126126
estate->es_result_relations = NULL;
127127
estate->es_opened_result_relations = NIL;
128-
estate->es_result_relation_info = NULL;
129128
estate->es_tuple_routing_result_relations = NIL;
130129
estate->es_trig_target_relations = NIL;
131130

0 commit comments

Comments
 (0)