PostgreSQL Source Code git master
nodeModifyTable.h File Reference
#include "nodes/execnodes.h"
Include dependency graph for nodeModifyTable.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void ExecInitGenerated (ResultRelInfo *resultRelInfo, EState *estate, CmdType cmdtype)
 
void ExecComputeStoredGenerated (ResultRelInfo *resultRelInfo, EState *estate, TupleTableSlot *slot, CmdType cmdtype)
 
ModifyTableStateExecInitModifyTable (ModifyTable *node, EState *estate, int eflags)
 
void ExecEndModifyTable (ModifyTableState *node)
 
void ExecReScanModifyTable (ModifyTableState *node)
 
void ExecInitMergeTupleSlots (ModifyTableState *mtstate, ResultRelInfo *resultRelInfo)
 

Function Documentation

◆ ExecComputeStoredGenerated()

void ExecComputeStoredGenerated ( ResultRelInfo resultRelInfo,
EState estate,
TupleTableSlot slot,
CmdType  cmdtype 
)

Definition at line 544 of file nodeModifyTable.c.

547{
548 Relation rel = resultRelInfo->ri_RelationDesc;
549 TupleDesc tupdesc = RelationGetDescr(rel);
550 int natts = tupdesc->natts;
551 ExprContext *econtext = GetPerTupleExprContext(estate);
552 ExprState **ri_GeneratedExprs;
553 MemoryContext oldContext;
554 Datum *values;
555 bool *nulls;
556
557 /* We should not be called unless this is true */
558 Assert(tupdesc->constr && tupdesc->constr->has_generated_stored);
559
560 /*
561 * Initialize the expressions if we didn't already, and check whether we
562 * can exit early because nothing needs to be computed.
563 */
564 if (cmdtype == CMD_UPDATE)
565 {
566 if (resultRelInfo->ri_GeneratedExprsU == NULL)
567 ExecInitGenerated(resultRelInfo, estate, cmdtype);
568 if (resultRelInfo->ri_NumGeneratedNeededU == 0)
569 return;
570 ri_GeneratedExprs = resultRelInfo->ri_GeneratedExprsU;
571 }
572 else
573 {
574 if (resultRelInfo->ri_GeneratedExprsI == NULL)
575 ExecInitGenerated(resultRelInfo, estate, cmdtype);
576 /* Early exit is impossible given the prior Assert */
577 Assert(resultRelInfo->ri_NumGeneratedNeededI > 0);
578 ri_GeneratedExprs = resultRelInfo->ri_GeneratedExprsI;
579 }
580
582
583 values = palloc(sizeof(*values) * natts);
584 nulls = palloc(sizeof(*nulls) * natts);
585
586 slot_getallattrs(slot);
587 memcpy(nulls, slot->tts_isnull, sizeof(*nulls) * natts);
588
589 for (int i = 0; i < natts; i++)
590 {
591 CompactAttribute *attr = TupleDescCompactAttr(tupdesc, i);
592
593 if (ri_GeneratedExprs[i])
594 {
595 Datum val;
596 bool isnull;
597
598 Assert(TupleDescAttr(tupdesc, i)->attgenerated == ATTRIBUTE_GENERATED_STORED);
599
600 econtext->ecxt_scantuple = slot;
601
602 val = ExecEvalExpr(ri_GeneratedExprs[i], econtext, &isnull);
603
604 /*
605 * We must make a copy of val as we have no guarantees about where
606 * memory for a pass-by-reference Datum is located.
607 */
608 if (!isnull)
609 val = datumCopy(val, attr->attbyval, attr->attlen);
610
611 values[i] = val;
612 nulls[i] = isnull;
613 }
614 else
615 {
616 if (!nulls[i])
617 values[i] = datumCopy(slot->tts_values[i], attr->attbyval, attr->attlen);
618 }
619 }
620
621 ExecClearTuple(slot);
622 memcpy(slot->tts_values, values, sizeof(*values) * natts);
623 memcpy(slot->tts_isnull, nulls, sizeof(*nulls) * natts);
626
627 MemoryContextSwitchTo(oldContext);
628}
static Datum values[MAXATTR]
Definition: bootstrap.c:153
Datum datumCopy(Datum value, bool typByVal, int typLen)
Definition: datum.c:132
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
Definition: execTuples.c:1741
#define GetPerTupleExprContext(estate)
Definition: executor.h:656
#define GetPerTupleMemoryContext(estate)
Definition: executor.h:661
static Datum ExecEvalExpr(ExprState *state, ExprContext *econtext, bool *isNull)
Definition: executor.h:393
Assert(PointerIsAligned(start, uint64))
long val
Definition: informix.c:689
int i
Definition: isn.c:77
void * palloc(Size size)
Definition: mcxt.c:1365
void ExecInitGenerated(ResultRelInfo *resultRelInfo, EState *estate, CmdType cmdtype)
@ CMD_UPDATE
Definition: nodes.h:276
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
uint64_t Datum
Definition: postgres.h:70
#define RelationGetDescr(relation)
Definition: rel.h:541
int16 attlen
Definition: tupdesc.h:71
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:273
Relation ri_RelationDesc
Definition: execnodes.h:480
ExprState ** ri_GeneratedExprsI
Definition: execnodes.h:566
int ri_NumGeneratedNeededU
Definition: execnodes.h:571
ExprState ** ri_GeneratedExprsU
Definition: execnodes.h:567
int ri_NumGeneratedNeededI
Definition: execnodes.h:570
bool has_generated_stored
Definition: tupdesc.h:46
TupleConstr * constr
Definition: tupdesc.h:141
bool * tts_isnull
Definition: tuptable.h:126
Datum * tts_values
Definition: tuptable.h:124
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
Definition: tupdesc.h:160
static CompactAttribute * TupleDescCompactAttr(TupleDesc tupdesc, int i)
Definition: tupdesc.h:175
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:457
static void slot_getallattrs(TupleTableSlot *slot)
Definition: tuptable.h:371
static void ExecMaterializeSlot(TupleTableSlot *slot)
Definition: tuptable.h:475

References Assert(), CompactAttribute::attbyval, CompactAttribute::attlen, CMD_UPDATE, TupleDescData::constr, datumCopy(), ExprContext::ecxt_scantuple, ExecClearTuple(), ExecEvalExpr(), ExecInitGenerated(), ExecMaterializeSlot(), ExecStoreVirtualTuple(), GetPerTupleExprContext, GetPerTupleMemoryContext, TupleConstr::has_generated_stored, i, MemoryContextSwitchTo(), TupleDescData::natts, palloc(), RelationGetDescr, ResultRelInfo::ri_GeneratedExprsI, ResultRelInfo::ri_GeneratedExprsU, ResultRelInfo::ri_NumGeneratedNeededI, ResultRelInfo::ri_NumGeneratedNeededU, ResultRelInfo::ri_RelationDesc, slot_getallattrs(), TupleTableSlot::tts_isnull, TupleTableSlot::tts_values, TupleDescAttr(), TupleDescCompactAttr(), val, and values.

Referenced by CopyFrom(), ExecInsert(), ExecSimpleRelationInsert(), ExecSimpleRelationUpdate(), and ExecUpdatePrepareSlot().

◆ ExecEndModifyTable()

void ExecEndModifyTable ( ModifyTableState node)

Definition at line 5213 of file nodeModifyTable.c.

5214{
5215 int i;
5216
5217 /*
5218 * Allow any FDWs to shut down
5219 */
5220 for (i = 0; i < node->mt_nrels; i++)
5221 {
5222 int j;
5223 ResultRelInfo *resultRelInfo = node->resultRelInfo + i;
5224
5225 if (!resultRelInfo->ri_usesFdwDirectModify &&
5226 resultRelInfo->ri_FdwRoutine != NULL &&
5227 resultRelInfo->ri_FdwRoutine->EndForeignModify != NULL)
5228 resultRelInfo->ri_FdwRoutine->EndForeignModify(node->ps.state,
5229 resultRelInfo);
5230
5231 /*
5232 * Cleanup the initialized batch slots. This only matters for FDWs
5233 * with batching, but the other cases will have ri_NumSlotsInitialized
5234 * == 0.
5235 */
5236 for (j = 0; j < resultRelInfo->ri_NumSlotsInitialized; j++)
5237 {
5238 ExecDropSingleTupleTableSlot(resultRelInfo->ri_Slots[j]);
5240 }
5241 }
5242
5243 /*
5244 * Close all the partitioned tables, leaf partitions, and their indices
5245 * and release the slot used for tuple routing, if set.
5246 */
5248 {
5250
5251 if (node->mt_root_tuple_slot)
5253 }
5254
5255 /*
5256 * Terminate EPQ execution if active
5257 */
5259
5260 /*
5261 * shut down subplan
5262 */
5264}
void EvalPlanQualEnd(EPQState *epqstate)
Definition: execMain.c:3182
void ExecCleanupTupleRouting(ModifyTableState *mtstate, PartitionTupleRouting *proute)
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:562
void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)
Definition: execTuples.c:1443
#define outerPlanState(node)
Definition: execnodes.h:1261
int j
Definition: isn.c:78
EndForeignModify_function EndForeignModify
Definition: fdwapi.h:237
ResultRelInfo * resultRelInfo
Definition: execnodes.h:1408
struct PartitionTupleRouting * mt_partition_tuple_routing
Definition: execnodes.h:1439
TupleTableSlot * mt_root_tuple_slot
Definition: execnodes.h:1436
EPQState mt_epqstate
Definition: execnodes.h:1418
PlanState ps
Definition: execnodes.h:1403
EState * state
Definition: execnodes.h:1167
TupleTableSlot ** ri_Slots
Definition: execnodes.h:545
int ri_NumSlotsInitialized
Definition: execnodes.h:543
struct FdwRoutine * ri_FdwRoutine
Definition: execnodes.h:533
TupleTableSlot ** ri_PlanSlots
Definition: execnodes.h:546
bool ri_usesFdwDirectModify
Definition: execnodes.h:539

References FdwRoutine::EndForeignModify, EvalPlanQualEnd(), ExecCleanupTupleRouting(), ExecDropSingleTupleTableSlot(), ExecEndNode(), i, j, ModifyTableState::mt_epqstate, ModifyTableState::mt_nrels, ModifyTableState::mt_partition_tuple_routing, ModifyTableState::mt_root_tuple_slot, outerPlanState, ModifyTableState::ps, ModifyTableState::resultRelInfo, ResultRelInfo::ri_FdwRoutine, ResultRelInfo::ri_NumSlotsInitialized, ResultRelInfo::ri_PlanSlots, ResultRelInfo::ri_Slots, ResultRelInfo::ri_usesFdwDirectModify, and PlanState::state.

Referenced by ExecEndNode().

◆ ExecInitGenerated()

void ExecInitGenerated ( ResultRelInfo resultRelInfo,
EState estate,
CmdType  cmdtype 
)

Definition at line 430 of file nodeModifyTable.c.

433{
434 Relation rel = resultRelInfo->ri_RelationDesc;
435 TupleDesc tupdesc = RelationGetDescr(rel);
436 int natts = tupdesc->natts;
437 ExprState **ri_GeneratedExprs;
438 int ri_NumGeneratedNeeded;
439 Bitmapset *updatedCols;
440 MemoryContext oldContext;
441
442 /* Nothing to do if no generated columns */
443 if (!(tupdesc->constr && (tupdesc->constr->has_generated_stored || tupdesc->constr->has_generated_virtual)))
444 return;
445
446 /*
447 * In an UPDATE, we can skip computing any generated columns that do not
448 * depend on any UPDATE target column. But if there is a BEFORE ROW
449 * UPDATE trigger, we cannot skip because the trigger might change more
450 * columns.
451 */
452 if (cmdtype == CMD_UPDATE &&
454 updatedCols = ExecGetUpdatedCols(resultRelInfo, estate);
455 else
456 updatedCols = NULL;
457
458 /*
459 * Make sure these data structures are built in the per-query memory
460 * context so they'll survive throughout the query.
461 */
462 oldContext = MemoryContextSwitchTo(estate->es_query_cxt);
463
464 ri_GeneratedExprs = (ExprState **) palloc0(natts * sizeof(ExprState *));
465 ri_NumGeneratedNeeded = 0;
466
467 for (int i = 0; i < natts; i++)
468 {
469 char attgenerated = TupleDescAttr(tupdesc, i)->attgenerated;
470
471 if (attgenerated)
472 {
473 Expr *expr;
474
475 /* Fetch the GENERATED AS expression tree */
476 expr = (Expr *) build_column_default(rel, i + 1);
477 if (expr == NULL)
478 elog(ERROR, "no generation expression found for column number %d of table \"%s\"",
479 i + 1, RelationGetRelationName(rel));
480
481 /*
482 * If it's an update with a known set of update target columns,
483 * see if we can skip the computation.
484 */
485 if (updatedCols)
486 {
487 Bitmapset *attrs_used = NULL;
488
489 pull_varattnos((Node *) expr, 1, &attrs_used);
490
491 if (!bms_overlap(updatedCols, attrs_used))
492 continue; /* need not update this column */
493 }
494
495 /* No luck, so prepare the expression for execution */
496 if (attgenerated == ATTRIBUTE_GENERATED_STORED)
497 {
498 ri_GeneratedExprs[i] = ExecPrepareExpr(expr, estate);
499 ri_NumGeneratedNeeded++;
500 }
501
502 /* If UPDATE, mark column in resultRelInfo->ri_extraUpdatedCols */
503 if (cmdtype == CMD_UPDATE)
504 resultRelInfo->ri_extraUpdatedCols =
505 bms_add_member(resultRelInfo->ri_extraUpdatedCols,
507 }
508 }
509
510 if (ri_NumGeneratedNeeded == 0)
511 {
512 /* didn't need it after all */
513 pfree(ri_GeneratedExprs);
514 ri_GeneratedExprs = NULL;
515 }
516
517 /* Save in appropriate set of fields */
518 if (cmdtype == CMD_UPDATE)
519 {
520 /* Don't call twice */
521 Assert(resultRelInfo->ri_GeneratedExprsU == NULL);
522
523 resultRelInfo->ri_GeneratedExprsU = ri_GeneratedExprs;
524 resultRelInfo->ri_NumGeneratedNeededU = ri_NumGeneratedNeeded;
525
526 resultRelInfo->ri_extraUpdatedCols_valid = true;
527 }
528 else
529 {
530 /* Don't call twice */
531 Assert(resultRelInfo->ri_GeneratedExprsI == NULL);
532
533 resultRelInfo->ri_GeneratedExprsI = ri_GeneratedExprs;
534 resultRelInfo->ri_NumGeneratedNeededI = ri_NumGeneratedNeeded;
535 }
536
537 MemoryContextSwitchTo(oldContext);
538}
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition: bitmapset.c:815
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:582
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226
ExprState * ExecPrepareExpr(Expr *node, EState *estate)
Definition: execExpr.c:765
Bitmapset * ExecGetUpdatedCols(ResultRelInfo *relinfo, EState *estate)
Definition: execUtils.c:1382
void pfree(void *pointer)
Definition: mcxt.c:1594
void * palloc0(Size size)
Definition: mcxt.c:1395
#define RelationGetRelationName(relation)
Definition: rel.h:549
Node * build_column_default(Relation rel, int attrno)
MemoryContext es_query_cxt
Definition: execnodes.h:710
Definition: nodes.h:135
TriggerDesc * trigdesc
Definition: rel.h:117
bool ri_extraUpdatedCols_valid
Definition: execnodes.h:500
Bitmapset * ri_extraUpdatedCols
Definition: execnodes.h:498
bool trig_update_before_row
Definition: reltrigger.h:61
bool has_generated_virtual
Definition: tupdesc.h:47
#define FirstLowInvalidHeapAttributeNumber
Definition: sysattr.h:27
void pull_varattnos(Node *node, Index varno, Bitmapset **varattnos)
Definition: var.c:296

References Assert(), bms_add_member(), bms_overlap(), build_column_default(), CMD_UPDATE, TupleDescData::constr, elog, ERROR, EState::es_query_cxt, ExecGetUpdatedCols(), ExecPrepareExpr(), FirstLowInvalidHeapAttributeNumber, TupleConstr::has_generated_stored, TupleConstr::has_generated_virtual, i, MemoryContextSwitchTo(), TupleDescData::natts, palloc0(), pfree(), pull_varattnos(), RelationGetDescr, RelationGetRelationName, ResultRelInfo::ri_extraUpdatedCols, ResultRelInfo::ri_extraUpdatedCols_valid, ResultRelInfo::ri_GeneratedExprsI, ResultRelInfo::ri_GeneratedExprsU, ResultRelInfo::ri_NumGeneratedNeededI, ResultRelInfo::ri_NumGeneratedNeededU, ResultRelInfo::ri_RelationDesc, TriggerDesc::trig_update_before_row, RelationData::trigdesc, and TupleDescAttr().

Referenced by ExecComputeStoredGenerated(), and ExecGetExtraUpdatedCols().

◆ ExecInitMergeTupleSlots()

void ExecInitMergeTupleSlots ( ModifyTableState mtstate,
ResultRelInfo resultRelInfo 
)

Definition at line 3969 of file nodeModifyTable.c.

3971{
3972 EState *estate = mtstate->ps.state;
3973
3974 Assert(!resultRelInfo->ri_projectNewInfoValid);
3975
3976 resultRelInfo->ri_oldTupleSlot =
3977 table_slot_create(resultRelInfo->ri_RelationDesc,
3978 &estate->es_tupleTable);
3979 resultRelInfo->ri_newTupleSlot =
3980 table_slot_create(resultRelInfo->ri_RelationDesc,
3981 &estate->es_tupleTable);
3982 resultRelInfo->ri_projectNewInfoValid = true;
3983}
List * es_tupleTable
Definition: execnodes.h:712
bool ri_projectNewInfoValid
Definition: execnodes.h:509
TupleTableSlot * ri_oldTupleSlot
Definition: execnodes.h:507
TupleTableSlot * ri_newTupleSlot
Definition: execnodes.h:505
TupleTableSlot * table_slot_create(Relation relation, List **reglist)
Definition: tableam.c:92

References Assert(), EState::es_tupleTable, ModifyTableState::ps, ResultRelInfo::ri_newTupleSlot, ResultRelInfo::ri_oldTupleSlot, ResultRelInfo::ri_projectNewInfoValid, ResultRelInfo::ri_RelationDesc, PlanState::state, and table_slot_create().

Referenced by ExecInitMerge(), and ExecInitPartitionInfo().

◆ ExecInitModifyTable()

ModifyTableState * ExecInitModifyTable ( ModifyTable node,
EState estate,
int  eflags 
)

Definition at line 4637 of file nodeModifyTable.c.

4638{
4639 ModifyTableState *mtstate;
4640 Plan *subplan = outerPlan(node);
4641 CmdType operation = node->operation;
4642 int total_nrels = list_length(node->resultRelations);
4643 int nrels;
4644 List *resultRelations = NIL;
4645 List *withCheckOptionLists = NIL;
4646 List *returningLists = NIL;
4647 List *updateColnosLists = NIL;
4648 List *mergeActionLists = NIL;
4649 List *mergeJoinConditions = NIL;
4650 ResultRelInfo *resultRelInfo;
4651 List *arowmarks;
4652 ListCell *l;
4653 int i;
4654 Relation rel;
4655
4656 /* check for unsupported flags */
4657 Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
4658
4659 /*
4660 * Only consider unpruned relations for initializing their ResultRelInfo
4661 * struct and other fields such as withCheckOptions, etc.
4662 *
4663 * Note: We must avoid pruning every result relation. This is important
4664 * for MERGE, since even if every result relation is pruned from the
4665 * subplan, there might still be NOT MATCHED rows, for which there may be
4666 * INSERT actions to perform. To allow these actions to be found, at
4667 * least one result relation must be kept. Also, when inserting into a
4668 * partitioned table, ExecInitPartitionInfo() needs a ResultRelInfo struct
4669 * as a reference for building the ResultRelInfo of the target partition.
4670 * In either case, it doesn't matter which result relation is kept, so we
4671 * just keep the first one, if all others have been pruned. See also,
4672 * ExecDoInitialPruning(), which ensures that this first result relation
4673 * has been locked.
4674 */
4675 i = 0;
4676 foreach(l, node->resultRelations)
4677 {
4678 Index rti = lfirst_int(l);
4679 bool keep_rel;
4680
4681 keep_rel = bms_is_member(rti, estate->es_unpruned_relids);
4682 if (!keep_rel && i == total_nrels - 1 && resultRelations == NIL)
4683 {
4684 /* all result relations pruned; keep the first one */
4685 keep_rel = true;
4686 rti = linitial_int(node->resultRelations);
4687 i = 0;
4688 }
4689
4690 if (keep_rel)
4691 {
4692 resultRelations = lappend_int(resultRelations, rti);
4693 if (node->withCheckOptionLists)
4694 {
4695 List *withCheckOptions = list_nth_node(List,
4697 i);
4698
4699 withCheckOptionLists = lappend(withCheckOptionLists, withCheckOptions);
4700 }
4701 if (node->returningLists)
4702 {
4703 List *returningList = list_nth_node(List,
4704 node->returningLists,
4705 i);
4706
4707 returningLists = lappend(returningLists, returningList);
4708 }
4709 if (node->updateColnosLists)
4710 {
4711 List *updateColnosList = list_nth(node->updateColnosLists, i);
4712
4713 updateColnosLists = lappend(updateColnosLists, updateColnosList);
4714 }
4715 if (node->mergeActionLists)
4716 {
4717 List *mergeActionList = list_nth(node->mergeActionLists, i);
4718
4719 mergeActionLists = lappend(mergeActionLists, mergeActionList);
4720 }
4721 if (node->mergeJoinConditions)
4722 {
4723 List *mergeJoinCondition = list_nth(node->mergeJoinConditions, i);
4724
4725 mergeJoinConditions = lappend(mergeJoinConditions, mergeJoinCondition);
4726 }
4727 }
4728 i++;
4729 }
4730 nrels = list_length(resultRelations);
4731 Assert(nrels > 0);
4732
4733 /*
4734 * create state structure
4735 */
4736 mtstate = makeNode(ModifyTableState);
4737 mtstate->ps.plan = (Plan *) node;
4738 mtstate->ps.state = estate;
4739 mtstate->ps.ExecProcNode = ExecModifyTable;
4740
4741 mtstate->operation = operation;
4742 mtstate->canSetTag = node->canSetTag;
4743 mtstate->mt_done = false;
4744
4745 mtstate->mt_nrels = nrels;
4746 mtstate->resultRelInfo = (ResultRelInfo *)
4747 palloc(nrels * sizeof(ResultRelInfo));
4748
4749 mtstate->mt_merge_pending_not_matched = NULL;
4750 mtstate->mt_merge_inserted = 0;
4751 mtstate->mt_merge_updated = 0;
4752 mtstate->mt_merge_deleted = 0;
4753 mtstate->mt_updateColnosLists = updateColnosLists;
4754 mtstate->mt_mergeActionLists = mergeActionLists;
4755 mtstate->mt_mergeJoinConditions = mergeJoinConditions;
4756
4757 /*----------
4758 * Resolve the target relation. This is the same as:
4759 *
4760 * - the relation for which we will fire FOR STATEMENT triggers,
4761 * - the relation into whose tuple format all captured transition tuples
4762 * must be converted, and
4763 * - the root partitioned table used for tuple routing.
4764 *
4765 * If it's a partitioned or inherited table, the root partition or
4766 * appendrel RTE doesn't appear elsewhere in the plan and its RT index is
4767 * given explicitly in node->rootRelation. Otherwise, the target relation
4768 * is the sole relation in the node->resultRelations list and, since it can
4769 * never be pruned, also in the resultRelations list constructed above.
4770 *----------
4771 */
4772 if (node->rootRelation > 0)
4773 {
4777 node->rootRelation);
4778 }
4779 else
4780 {
4781 Assert(list_length(node->resultRelations) == 1);
4782 Assert(list_length(resultRelations) == 1);
4783 mtstate->rootResultRelInfo = mtstate->resultRelInfo;
4784 ExecInitResultRelation(estate, mtstate->resultRelInfo,
4785 linitial_int(resultRelations));
4786 }
4787
4788 /* set up epqstate with dummy subplan data for the moment */
4789 EvalPlanQualInit(&mtstate->mt_epqstate, estate, NULL, NIL,
4790 node->epqParam, resultRelations);
4791 mtstate->fireBSTriggers = true;
4792
4793 /*
4794 * Build state for collecting transition tuples. This requires having a
4795 * valid trigger query context, so skip it in explain-only mode.
4796 */
4797 if (!(eflags & EXEC_FLAG_EXPLAIN_ONLY))
4798 ExecSetupTransitionCaptureState(mtstate, estate);
4799
4800 /*
4801 * Open all the result relations and initialize the ResultRelInfo structs.
4802 * (But root relation was initialized above, if it's part of the array.)
4803 * We must do this before initializing the subplan, because direct-modify
4804 * FDWs expect their ResultRelInfos to be available.
4805 */
4806 resultRelInfo = mtstate->resultRelInfo;
4807 i = 0;
4808 foreach(l, resultRelations)
4809 {
4810 Index resultRelation = lfirst_int(l);
4811 List *mergeActions = NIL;
4812
4813 if (mergeActionLists)
4814 mergeActions = list_nth(mergeActionLists, i);
4815
4816 if (resultRelInfo != mtstate->rootResultRelInfo)
4817 {
4818 ExecInitResultRelation(estate, resultRelInfo, resultRelation);
4819
4820 /*
4821 * For child result relations, store the root result relation
4822 * pointer. We do so for the convenience of places that want to
4823 * look at the query's original target relation but don't have the
4824 * mtstate handy.
4825 */
4826 resultRelInfo->ri_RootResultRelInfo = mtstate->rootResultRelInfo;
4827 }
4828
4829 /* Initialize the usesFdwDirectModify flag */
4830 resultRelInfo->ri_usesFdwDirectModify =
4832
4833 /*
4834 * Verify result relation is a valid target for the current operation
4835 */
4836 CheckValidResultRel(resultRelInfo, operation, node->onConflictAction,
4837 mergeActions);
4838
4839 resultRelInfo++;
4840 i++;
4841 }
4842
4843 /*
4844 * Now we may initialize the subplan.
4845 */
4846 outerPlanState(mtstate) = ExecInitNode(subplan, estate, eflags);
4847
4848 /*
4849 * Do additional per-result-relation initialization.
4850 */
4851 for (i = 0; i < nrels; i++)
4852 {
4853 resultRelInfo = &mtstate->resultRelInfo[i];
4854
4855 /* Let FDWs init themselves for foreign-table result rels */
4856 if (!resultRelInfo->ri_usesFdwDirectModify &&
4857 resultRelInfo->ri_FdwRoutine != NULL &&
4858 resultRelInfo->ri_FdwRoutine->BeginForeignModify != NULL)
4859 {
4860 List *fdw_private = (List *) list_nth(node->fdwPrivLists, i);
4861
4862 resultRelInfo->ri_FdwRoutine->BeginForeignModify(mtstate,
4863 resultRelInfo,
4864 fdw_private,
4865 i,
4866 eflags);
4867 }
4868
4869 /*
4870 * For UPDATE/DELETE/MERGE, find the appropriate junk attr now, either
4871 * a 'ctid' or 'wholerow' attribute depending on relkind. For foreign
4872 * tables, the FDW might have created additional junk attr(s), but
4873 * those are no concern of ours.
4874 */
4875 if (operation == CMD_UPDATE || operation == CMD_DELETE ||
4876 operation == CMD_MERGE)
4877 {
4878 char relkind;
4879
4880 relkind = resultRelInfo->ri_RelationDesc->rd_rel->relkind;
4881 if (relkind == RELKIND_RELATION ||
4882 relkind == RELKIND_MATVIEW ||
4883 relkind == RELKIND_PARTITIONED_TABLE)
4884 {
4885 resultRelInfo->ri_RowIdAttNo =
4886 ExecFindJunkAttributeInTlist(subplan->targetlist, "ctid");
4887 if (!AttributeNumberIsValid(resultRelInfo->ri_RowIdAttNo))
4888 elog(ERROR, "could not find junk ctid column");
4889 }
4890 else if (relkind == RELKIND_FOREIGN_TABLE)
4891 {
4892 /*
4893 * We don't support MERGE with foreign tables for now. (It's
4894 * problematic because the implementation uses CTID.)
4895 */
4896 Assert(operation != CMD_MERGE);
4897
4898 /*
4899 * When there is a row-level trigger, there should be a
4900 * wholerow attribute. We also require it to be present in
4901 * UPDATE and MERGE, so we can get the values of unchanged
4902 * columns.
4903 */
4904 resultRelInfo->ri_RowIdAttNo =
4906 "wholerow");
4907 if ((mtstate->operation == CMD_UPDATE || mtstate->operation == CMD_MERGE) &&
4908 !AttributeNumberIsValid(resultRelInfo->ri_RowIdAttNo))
4909 elog(ERROR, "could not find junk wholerow column");
4910 }
4911 else
4912 {
4913 /* Other valid target relkinds must provide wholerow */
4914 resultRelInfo->ri_RowIdAttNo =
4916 "wholerow");
4917 if (!AttributeNumberIsValid(resultRelInfo->ri_RowIdAttNo))
4918 elog(ERROR, "could not find junk wholerow column");
4919 }
4920 }
4921 }
4922
4923 /*
4924 * If this is an inherited update/delete/merge, there will be a junk
4925 * attribute named "tableoid" present in the subplan's targetlist. It
4926 * will be used to identify the result relation for a given tuple to be
4927 * updated/deleted/merged.
4928 */
4929 mtstate->mt_resultOidAttno =
4930 ExecFindJunkAttributeInTlist(subplan->targetlist, "tableoid");
4931 Assert(AttributeNumberIsValid(mtstate->mt_resultOidAttno) || total_nrels == 1);
4932 mtstate->mt_lastResultOid = InvalidOid; /* force lookup at first tuple */
4933 mtstate->mt_lastResultIndex = 0; /* must be zero if no such attr */
4934
4935 /* Get the root target relation */
4936 rel = mtstate->rootResultRelInfo->ri_RelationDesc;
4937
4938 /*
4939 * Build state for tuple routing if it's a partitioned INSERT. An UPDATE
4940 * or MERGE might need this too, but only if it actually moves tuples
4941 * between partitions; in that case setup is done by
4942 * ExecCrossPartitionUpdate.
4943 */
4944 if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE &&
4945 operation == CMD_INSERT)
4947 ExecSetupPartitionTupleRouting(estate, rel);
4948
4949 /*
4950 * Initialize any WITH CHECK OPTION constraints if needed.
4951 */
4952 resultRelInfo = mtstate->resultRelInfo;
4953 foreach(l, withCheckOptionLists)
4954 {
4955 List *wcoList = (List *) lfirst(l);
4956 List *wcoExprs = NIL;
4957 ListCell *ll;
4958
4959 foreach(ll, wcoList)
4960 {
4961 WithCheckOption *wco = (WithCheckOption *) lfirst(ll);
4962 ExprState *wcoExpr = ExecInitQual((List *) wco->qual,
4963 &mtstate->ps);
4964
4965 wcoExprs = lappend(wcoExprs, wcoExpr);
4966 }
4967
4968 resultRelInfo->ri_WithCheckOptions = wcoList;
4969 resultRelInfo->ri_WithCheckOptionExprs = wcoExprs;
4970 resultRelInfo++;
4971 }
4972
4973 /*
4974 * Initialize RETURNING projections if needed.
4975 */
4976 if (returningLists)
4977 {
4978 TupleTableSlot *slot;
4979 ExprContext *econtext;
4980
4981 /*
4982 * Initialize result tuple slot and assign its rowtype using the plan
4983 * node's declared targetlist, which the planner set up to be the same
4984 * as the first (before runtime pruning) RETURNING list. We assume
4985 * all the result rels will produce compatible output.
4986 */
4988 slot = mtstate->ps.ps_ResultTupleSlot;
4989
4990 /* Need an econtext too */
4991 if (mtstate->ps.ps_ExprContext == NULL)
4992 ExecAssignExprContext(estate, &mtstate->ps);
4993 econtext = mtstate->ps.ps_ExprContext;
4994
4995 /*
4996 * Build a projection for each result rel.
4997 */
4998 resultRelInfo = mtstate->resultRelInfo;
4999 foreach(l, returningLists)
5000 {
5001 List *rlist = (List *) lfirst(l);
5002
5003 resultRelInfo->ri_returningList = rlist;
5004 resultRelInfo->ri_projectReturning =
5005 ExecBuildProjectionInfo(rlist, econtext, slot, &mtstate->ps,
5006 resultRelInfo->ri_RelationDesc->rd_att);
5007 resultRelInfo++;
5008 }
5009 }
5010 else
5011 {
5012 /*
5013 * We still must construct a dummy result tuple type, because InitPlan
5014 * expects one (maybe should change that?).
5015 */
5016 ExecInitResultTypeTL(&mtstate->ps);
5017
5018 mtstate->ps.ps_ExprContext = NULL;
5019 }
5020
5021 /* Set the list of arbiter indexes if needed for ON CONFLICT */
5022 resultRelInfo = mtstate->resultRelInfo;
5023 if (node->onConflictAction != ONCONFLICT_NONE)
5024 {
5025 /* insert may only have one relation, inheritance is not expanded */
5026 Assert(total_nrels == 1);
5027 resultRelInfo->ri_onConflictArbiterIndexes = node->arbiterIndexes;
5028 }
5029
5030 /*
5031 * If needed, Initialize target list, projection and qual for ON CONFLICT
5032 * DO UPDATE.
5033 */
5035 {
5037 ExprContext *econtext;
5038 TupleDesc relationDesc;
5039
5040 /* already exists if created by RETURNING processing above */
5041 if (mtstate->ps.ps_ExprContext == NULL)
5042 ExecAssignExprContext(estate, &mtstate->ps);
5043
5044 econtext = mtstate->ps.ps_ExprContext;
5045 relationDesc = resultRelInfo->ri_RelationDesc->rd_att;
5046
5047 /* create state for DO UPDATE SET operation */
5048 resultRelInfo->ri_onConflict = onconfl;
5049
5050 /* initialize slot for the existing tuple */
5051 onconfl->oc_Existing =
5052 table_slot_create(resultRelInfo->ri_RelationDesc,
5053 &mtstate->ps.state->es_tupleTable);
5054
5055 /*
5056 * Create the tuple slot for the UPDATE SET projection. We want a slot
5057 * of the table's type here, because the slot will be used to insert
5058 * into the table, and for RETURNING processing - which may access
5059 * system attributes.
5060 */
5061 onconfl->oc_ProjSlot =
5062 table_slot_create(resultRelInfo->ri_RelationDesc,
5063 &mtstate->ps.state->es_tupleTable);
5064
5065 /* build UPDATE SET projection state */
5066 onconfl->oc_ProjInfo =
5068 true,
5069 node->onConflictCols,
5070 relationDesc,
5071 econtext,
5072 onconfl->oc_ProjSlot,
5073 &mtstate->ps);
5074
5075 /* initialize state to evaluate the WHERE clause, if any */
5076 if (node->onConflictWhere)
5077 {
5078 ExprState *qualexpr;
5079
5080 qualexpr = ExecInitQual((List *) node->onConflictWhere,
5081 &mtstate->ps);
5082 onconfl->oc_WhereClause = qualexpr;
5083 }
5084 }
5085
5086 /*
5087 * If we have any secondary relations in an UPDATE or DELETE, they need to
5088 * be treated like non-locked relations in SELECT FOR UPDATE, i.e., the
5089 * EvalPlanQual mechanism needs to be told about them. This also goes for
5090 * the source relations in a MERGE. Locate the relevant ExecRowMarks.
5091 */
5092 arowmarks = NIL;
5093 foreach(l, node->rowMarks)
5094 {
5096 ExecRowMark *erm;
5097 ExecAuxRowMark *aerm;
5098
5099 /*
5100 * Ignore "parent" rowmarks, because they are irrelevant at runtime.
5101 * Also ignore the rowmarks belonging to child tables that have been
5102 * pruned in ExecDoInitialPruning().
5103 */
5104 if (rc->isParent ||
5105 !bms_is_member(rc->rti, estate->es_unpruned_relids))
5106 continue;
5107
5108 /* Find ExecRowMark and build ExecAuxRowMark */
5109 erm = ExecFindRowMark(estate, rc->rti, false);
5110 aerm = ExecBuildAuxRowMark(erm, subplan->targetlist);
5111 arowmarks = lappend(arowmarks, aerm);
5112 }
5113
5114 /* For a MERGE command, initialize its state */
5115 if (mtstate->operation == CMD_MERGE)
5116 ExecInitMerge(mtstate, estate);
5117
5118 EvalPlanQualSetPlan(&mtstate->mt_epqstate, subplan, arowmarks);
5119
5120 /*
5121 * If there are a lot of result relations, use a hash table to speed the
5122 * lookups. If there are not a lot, a simple linear search is faster.
5123 *
5124 * It's not clear where the threshold is, but try 64 for starters. In a
5125 * debugging build, use a small threshold so that we get some test
5126 * coverage of both code paths.
5127 */
5128#ifdef USE_ASSERT_CHECKING
5129#define MT_NRELS_HASH 4
5130#else
5131#define MT_NRELS_HASH 64
5132#endif
5133 if (nrels >= MT_NRELS_HASH)
5134 {
5135 HASHCTL hash_ctl;
5136
5137 hash_ctl.keysize = sizeof(Oid);
5138 hash_ctl.entrysize = sizeof(MTTargetRelLookup);
5139 hash_ctl.hcxt = CurrentMemoryContext;
5140 mtstate->mt_resultOidHash =
5141 hash_create("ModifyTable target hash",
5142 nrels, &hash_ctl,
5144 for (i = 0; i < nrels; i++)
5145 {
5146 Oid hashkey;
5147 MTTargetRelLookup *mtlookup;
5148 bool found;
5149
5150 resultRelInfo = &mtstate->resultRelInfo[i];
5151 hashkey = RelationGetRelid(resultRelInfo->ri_RelationDesc);
5152 mtlookup = (MTTargetRelLookup *)
5153 hash_search(mtstate->mt_resultOidHash, &hashkey,
5154 HASH_ENTER, &found);
5155 Assert(!found);
5156 mtlookup->relationIndex = i;
5157 }
5158 }
5159 else
5160 mtstate->mt_resultOidHash = NULL;
5161
5162 /*
5163 * Determine if the FDW supports batch insert and determine the batch size
5164 * (a FDW may support batching, but it may be disabled for the
5165 * server/table).
5166 *
5167 * We only do this for INSERT, so that for UPDATE/DELETE the batch size
5168 * remains set to 0.
5169 */
5170 if (operation == CMD_INSERT)
5171 {
5172 /* insert may only have one relation, inheritance is not expanded */
5173 Assert(total_nrels == 1);
5174 resultRelInfo = mtstate->resultRelInfo;
5175 if (!resultRelInfo->ri_usesFdwDirectModify &&
5176 resultRelInfo->ri_FdwRoutine != NULL &&
5177 resultRelInfo->ri_FdwRoutine->GetForeignModifyBatchSize &&
5178 resultRelInfo->ri_FdwRoutine->ExecForeignBatchInsert)
5179 {
5180 resultRelInfo->ri_BatchSize =
5181 resultRelInfo->ri_FdwRoutine->GetForeignModifyBatchSize(resultRelInfo);
5182 Assert(resultRelInfo->ri_BatchSize >= 1);
5183 }
5184 else
5185 resultRelInfo->ri_BatchSize = 1;
5186 }
5187
5188 /*
5189 * Lastly, if this is not the primary (canSetTag) ModifyTable node, add it
5190 * to estate->es_auxmodifytables so that it will be run to completion by
5191 * ExecPostprocessPlan. (It'd actually work fine to add the primary
5192 * ModifyTable node too, but there's no need.) Note the use of lcons not
5193 * lappend: we need later-initialized ModifyTable nodes to be shut down
5194 * before earlier ones. This ensures that we don't throw away RETURNING
5195 * rows that need to be seen by a later CTE subplan.
5196 */
5197 if (!mtstate->canSetTag)
5198 estate->es_auxmodifytables = lcons(mtstate,
5199 estate->es_auxmodifytables);
5200
5201 return mtstate;
5202}
#define AttributeNumberIsValid(attributeNumber)
Definition: attnum.h:34
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:510
unsigned int Index
Definition: c.h:624
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:952
HTAB * hash_create(const char *tabname, int64 nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:358
ProjectionInfo * ExecBuildProjectionInfo(List *targetList, ExprContext *econtext, TupleTableSlot *slot, PlanState *parent, TupleDesc inputDesc)
Definition: execExpr.c:370
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:229
ProjectionInfo * ExecBuildUpdateProjection(List *targetList, bool evalTargetList, List *targetColnos, TupleDesc relDesc, ExprContext *econtext, TupleTableSlot *slot, PlanState *parent)
Definition: execExpr.c:547
AttrNumber ExecFindJunkAttributeInTlist(List *targetlist, const char *attrName)
Definition: execJunk.c:222
ExecRowMark * ExecFindRowMark(EState *estate, Index rti, bool missing_ok)
Definition: execMain.c:2556
ExecAuxRowMark * ExecBuildAuxRowMark(ExecRowMark *erm, List *targetlist)
Definition: execMain.c:2579
void CheckValidResultRel(ResultRelInfo *resultRelInfo, CmdType operation, OnConflictAction onConflictAction, List *mergeActions)
Definition: execMain.c:1050
void EvalPlanQualInit(EPQState *epqstate, EState *parentestate, Plan *subplan, List *auxrowmarks, int epqParam, List *resultRelations)
Definition: execMain.c:2718
void EvalPlanQualSetPlan(EPQState *epqstate, Plan *subplan, List *auxrowmarks)
Definition: execMain.c:2760
PartitionTupleRouting * ExecSetupPartitionTupleRouting(EState *estate, Relation rel)
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:142
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:84
void ExecInitResultTypeTL(PlanState *planstate)
Definition: execTuples.c:1944
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1988
void ExecInitResultRelation(EState *estate, ResultRelInfo *resultRelInfo, Index rti)
Definition: execUtils.c:880
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:485
#define EXEC_FLAG_BACKWARD
Definition: executor.h:69
#define EXEC_FLAG_EXPLAIN_ONLY
Definition: executor.h:66
#define EXEC_FLAG_MARK
Definition: executor.h:70
@ HASH_ENTER
Definition: hsearch.h:114
#define HASH_CONTEXT
Definition: hsearch.h:102
#define HASH_ELEM
Definition: hsearch.h:95
#define HASH_BLOBS
Definition: hsearch.h:97
List * lappend(List *list, void *datum)
Definition: list.c:339
List * lappend_int(List *list, int datum)
Definition: list.c:357
List * lcons(void *datum, List *list)
Definition: list.c:495
MemoryContext CurrentMemoryContext
Definition: mcxt.c:160
static void ExecSetupTransitionCaptureState(ModifyTableState *mtstate, EState *estate)
static TupleTableSlot * ExecModifyTable(PlanState *pstate)
struct MTTargetRelLookup MTTargetRelLookup
#define MT_NRELS_HASH
static void ExecInitMerge(ModifyTableState *mtstate, EState *estate)
@ ONCONFLICT_NONE
Definition: nodes.h:428
@ ONCONFLICT_UPDATE
Definition: nodes.h:430
CmdType
Definition: nodes.h:273
@ CMD_MERGE
Definition: nodes.h:279
@ CMD_INSERT
Definition: nodes.h:277
@ CMD_DELETE
Definition: nodes.h:278
#define makeNode(_type_)
Definition: nodes.h:161
#define lfirst(lc)
Definition: pg_list.h:172
#define lfirst_node(type, lc)
Definition: pg_list.h:176
static int list_length(const List *l)
Definition: pg_list.h:152
#define NIL
Definition: pg_list.h:68
#define lfirst_int(lc)
Definition: pg_list.h:173
#define linitial_int(l)
Definition: pg_list.h:179
static void * list_nth(const List *list, int n)
Definition: pg_list.h:299
#define list_nth_node(type, list, n)
Definition: pg_list.h:327
#define outerPlan(node)
Definition: plannodes.h:261
#define InvalidOid
Definition: postgres_ext.h:37
unsigned int Oid
Definition: postgres_ext.h:32
#define RelationGetRelid(relation)
Definition: rel.h:515
Bitmapset * es_unpruned_relids
Definition: execnodes.h:673
List * es_auxmodifytables
Definition: execnodes.h:727
BeginForeignModify_function BeginForeignModify
Definition: fdwapi.h:231
ExecForeignBatchInsert_function ExecForeignBatchInsert
Definition: fdwapi.h:233
GetForeignModifyBatchSize_function GetForeignModifyBatchSize
Definition: fdwapi.h:234
Size keysize
Definition: hsearch.h:75
Size entrysize
Definition: hsearch.h:76
MemoryContext hcxt
Definition: hsearch.h:86
Definition: pg_list.h:54
List * mt_mergeJoinConditions
Definition: execnodes.h:1472
CmdType operation
Definition: execnodes.h:1404
TupleTableSlot * mt_merge_pending_not_matched
Definition: execnodes.h:1458
double mt_merge_deleted
Definition: execnodes.h:1463
List * mt_updateColnosLists
Definition: execnodes.h:1470
double mt_merge_inserted
Definition: execnodes.h:1461
double mt_merge_updated
Definition: execnodes.h:1462
List * mt_mergeActionLists
Definition: execnodes.h:1471
HTAB * mt_resultOidHash
Definition: execnodes.h:1430
ResultRelInfo * rootResultRelInfo
Definition: execnodes.h:1416
List * updateColnosLists
Definition: plannodes.h:344
List * arbiterIndexes
Definition: plannodes.h:364
List * onConflictCols
Definition: plannodes.h:368
List * mergeJoinConditions
Definition: plannodes.h:378
CmdType operation
Definition: plannodes.h:334
int epqParam
Definition: plannodes.h:360
List * resultRelations
Definition: plannodes.h:342
Bitmapset * fdwDirectModifyPlans
Definition: plannodes.h:356
List * onConflictSet
Definition: plannodes.h:366
List * mergeActionLists
Definition: plannodes.h:376
bool canSetTag
Definition: plannodes.h:336
List * fdwPrivLists
Definition: plannodes.h:354
List * returningLists
Definition: plannodes.h:352
List * withCheckOptionLists
Definition: plannodes.h:346
Index rootRelation
Definition: plannodes.h:340
Node * onConflictWhere
Definition: plannodes.h:370
List * rowMarks
Definition: plannodes.h:358
OnConflictAction onConflictAction
Definition: plannodes.h:362
TupleTableSlot * oc_ProjSlot
Definition: execnodes.h:434
TupleTableSlot * oc_Existing
Definition: execnodes.h:433
ExprState * oc_WhereClause
Definition: execnodes.h:436
ProjectionInfo * oc_ProjInfo
Definition: execnodes.h:435
bool isParent
Definition: plannodes.h:1604
Plan * plan
Definition: execnodes.h:1165
ExprContext * ps_ExprContext
Definition: execnodes.h:1204
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:1203
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1171
List * targetlist
Definition: plannodes.h:229
TupleDesc rd_att
Definition: rel.h:112
Form_pg_class rd_rel
Definition: rel.h:111
OnConflictSetState * ri_onConflict
Definition: execnodes.h:583
List * ri_onConflictArbiterIndexes
Definition: execnodes.h:580
struct ResultRelInfo * ri_RootResultRelInfo
Definition: execnodes.h:618
List * ri_WithCheckOptions
Definition: execnodes.h:549
List * ri_WithCheckOptionExprs
Definition: execnodes.h:552
ProjectionInfo * ri_projectReturning
Definition: execnodes.h:577
List * ri_returningList
Definition: execnodes.h:574
AttrNumber ri_RowIdAttNo
Definition: execnodes.h:495
int ri_BatchSize
Definition: execnodes.h:544

References ModifyTable::arbiterIndexes, Assert(), AttributeNumberIsValid, FdwRoutine::BeginForeignModify, bms_is_member(), ModifyTableState::canSetTag, ModifyTable::canSetTag, CheckValidResultRel(), CMD_DELETE, CMD_INSERT, CMD_MERGE, CMD_UPDATE, CurrentMemoryContext, elog, HASHCTL::entrysize, ModifyTable::epqParam, ERROR, EState::es_auxmodifytables, EState::es_tupleTable, EState::es_unpruned_relids, EvalPlanQualInit(), EvalPlanQualSetPlan(), EXEC_FLAG_BACKWARD, EXEC_FLAG_EXPLAIN_ONLY, EXEC_FLAG_MARK, ExecAssignExprContext(), ExecBuildAuxRowMark(), ExecBuildProjectionInfo(), ExecBuildUpdateProjection(), ExecFindJunkAttributeInTlist(), ExecFindRowMark(), FdwRoutine::ExecForeignBatchInsert, ExecInitMerge(), ExecInitNode(), ExecInitQual(), ExecInitResultRelation(), ExecInitResultTupleSlotTL(), ExecInitResultTypeTL(), ExecModifyTable(), PlanState::ExecProcNode, ExecSetupPartitionTupleRouting(), ExecSetupTransitionCaptureState(), ModifyTable::fdwDirectModifyPlans, ModifyTable::fdwPrivLists, ModifyTableState::fireBSTriggers, FdwRoutine::GetForeignModifyBatchSize, HASH_BLOBS, HASH_CONTEXT, hash_create(), HASH_ELEM, HASH_ENTER, hash_search(), HASHCTL::hcxt, i, InvalidOid, PlanRowMark::isParent, HASHCTL::keysize, lappend(), lappend_int(), lcons(), lfirst, lfirst_int, lfirst_node, linitial_int, list_length(), list_nth(), list_nth_node, makeNode, ModifyTable::mergeActionLists, ModifyTable::mergeJoinConditions, ModifyTableState::mt_done, ModifyTableState::mt_epqstate, ModifyTableState::mt_lastResultIndex, ModifyTableState::mt_lastResultOid, ModifyTableState::mt_merge_deleted, ModifyTableState::mt_merge_inserted, ModifyTableState::mt_merge_pending_not_matched, ModifyTableState::mt_merge_updated, ModifyTableState::mt_mergeActionLists, ModifyTableState::mt_mergeJoinConditions, ModifyTableState::mt_nrels, MT_NRELS_HASH, ModifyTableState::mt_partition_tuple_routing, ModifyTableState::mt_resultOidAttno, ModifyTableState::mt_resultOidHash, ModifyTableState::mt_updateColnosLists, NIL, OnConflictSetState::oc_Existing, OnConflictSetState::oc_ProjInfo, OnConflictSetState::oc_ProjSlot, OnConflictSetState::oc_WhereClause, ONCONFLICT_NONE, ONCONFLICT_UPDATE, ModifyTable::onConflictAction, ModifyTable::onConflictCols, ModifyTable::onConflictSet, ModifyTable::onConflictWhere, ModifyTableState::operation, ModifyTable::operation, outerPlan, outerPlanState, palloc(), PlanState::plan, ModifyTableState::ps, PlanState::ps_ExprContext, PlanState::ps_ResultTupleSlot, WithCheckOption::qual, RelationData::rd_att, RelationData::rd_rel, RelationGetRelid, MTTargetRelLookup::relationIndex, ModifyTable::resultRelations, ModifyTableState::resultRelInfo, ModifyTable::returningLists, ResultRelInfo::ri_BatchSize, ResultRelInfo::ri_FdwRoutine, ResultRelInfo::ri_onConflict, ResultRelInfo::ri_onConflictArbiterIndexes, ResultRelInfo::ri_projectReturning, ResultRelInfo::ri_RelationDesc, ResultRelInfo::ri_returningList, ResultRelInfo::ri_RootResultRelInfo, ResultRelInfo::ri_RowIdAttNo, ResultRelInfo::ri_usesFdwDirectModify, ResultRelInfo::ri_WithCheckOptionExprs, ResultRelInfo::ri_WithCheckOptions, ModifyTable::rootRelation, ModifyTableState::rootResultRelInfo, ModifyTable::rowMarks, PlanRowMark::rti, PlanState::state, table_slot_create(), Plan::targetlist, TTSOpsVirtual, ModifyTable::updateColnosLists, and ModifyTable::withCheckOptionLists.

Referenced by ExecInitNode().

◆ ExecReScanModifyTable()

void ExecReScanModifyTable ( ModifyTableState node)

Definition at line 5267 of file nodeModifyTable.c.

5268{
5269 /*
5270 * Currently, we don't need to support rescan on ModifyTable nodes. The
5271 * semantics of that would be a bit debatable anyway.
5272 */
5273 elog(ERROR, "ExecReScanModifyTable is not implemented");
5274}

References elog, and ERROR.

Referenced by ExecReScan().