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 545 of file nodeModifyTable.c.

548{
549 Relation rel = resultRelInfo->ri_RelationDesc;
550 TupleDesc tupdesc = RelationGetDescr(rel);
551 int natts = tupdesc->natts;
552 ExprContext *econtext = GetPerTupleExprContext(estate);
553 ExprState **ri_GeneratedExprs;
554 MemoryContext oldContext;
555 Datum *values;
556 bool *nulls;
557
558 /* We should not be called unless this is true */
559 Assert(tupdesc->constr && tupdesc->constr->has_generated_stored);
560
561 /*
562 * Initialize the expressions if we didn't already, and check whether we
563 * can exit early because nothing needs to be computed.
564 */
565 if (cmdtype == CMD_UPDATE)
566 {
567 if (resultRelInfo->ri_GeneratedExprsU == NULL)
568 ExecInitGenerated(resultRelInfo, estate, cmdtype);
569 if (resultRelInfo->ri_NumGeneratedNeededU == 0)
570 return;
571 ri_GeneratedExprs = resultRelInfo->ri_GeneratedExprsU;
572 }
573 else
574 {
575 if (resultRelInfo->ri_GeneratedExprsI == NULL)
576 ExecInitGenerated(resultRelInfo, estate, cmdtype);
577 /* Early exit is impossible given the prior Assert */
578 Assert(resultRelInfo->ri_NumGeneratedNeededI > 0);
579 ri_GeneratedExprs = resultRelInfo->ri_GeneratedExprsI;
580 }
581
583
584 values = palloc(sizeof(*values) * natts);
585 nulls = palloc(sizeof(*nulls) * natts);
586
587 slot_getallattrs(slot);
588 memcpy(nulls, slot->tts_isnull, sizeof(*nulls) * natts);
589
590 for (int i = 0; i < natts; i++)
591 {
592 CompactAttribute *attr = TupleDescCompactAttr(tupdesc, i);
593
594 if (ri_GeneratedExprs[i])
595 {
596 Datum val;
597 bool isnull;
598
599 Assert(TupleDescAttr(tupdesc, i)->attgenerated == ATTRIBUTE_GENERATED_STORED);
600
601 econtext->ecxt_scantuple = slot;
602
603 val = ExecEvalExpr(ri_GeneratedExprs[i], econtext, &isnull);
604
605 /*
606 * We must make a copy of val as we have no guarantees about where
607 * memory for a pass-by-reference Datum is located.
608 */
609 if (!isnull)
610 val = datumCopy(val, attr->attbyval, attr->attlen);
611
612 values[i] = val;
613 nulls[i] = isnull;
614 }
615 else
616 {
617 if (!nulls[i])
618 values[i] = datumCopy(slot->tts_values[i], attr->attbyval, attr->attlen);
619 }
620 }
621
622 ExecClearTuple(slot);
623 memcpy(slot->tts_values, values, sizeof(*values) * natts);
624 memcpy(slot->tts_isnull, nulls, sizeof(*nulls) * natts);
627
628 MemoryContextSwitchTo(oldContext);
629}
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 5215 of file nodeModifyTable.c.

5216{
5217 int i;
5218
5219 /*
5220 * Allow any FDWs to shut down
5221 */
5222 for (i = 0; i < node->mt_nrels; i++)
5223 {
5224 int j;
5225 ResultRelInfo *resultRelInfo = node->resultRelInfo + i;
5226
5227 if (!resultRelInfo->ri_usesFdwDirectModify &&
5228 resultRelInfo->ri_FdwRoutine != NULL &&
5229 resultRelInfo->ri_FdwRoutine->EndForeignModify != NULL)
5230 resultRelInfo->ri_FdwRoutine->EndForeignModify(node->ps.state,
5231 resultRelInfo);
5232
5233 /*
5234 * Cleanup the initialized batch slots. This only matters for FDWs
5235 * with batching, but the other cases will have ri_NumSlotsInitialized
5236 * == 0.
5237 */
5238 for (j = 0; j < resultRelInfo->ri_NumSlotsInitialized; j++)
5239 {
5240 ExecDropSingleTupleTableSlot(resultRelInfo->ri_Slots[j]);
5242 }
5243 }
5244
5245 /*
5246 * Close all the partitioned tables, leaf partitions, and their indices
5247 * and release the slot used for tuple routing, if set.
5248 */
5250 {
5252
5253 if (node->mt_root_tuple_slot)
5255 }
5256
5257 /*
5258 * Terminate EPQ execution if active
5259 */
5261
5262 /*
5263 * shut down subplan
5264 */
5266}
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 431 of file nodeModifyTable.c.

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

3973{
3974 EState *estate = mtstate->ps.state;
3975
3976 Assert(!resultRelInfo->ri_projectNewInfoValid);
3977
3978 resultRelInfo->ri_oldTupleSlot =
3979 table_slot_create(resultRelInfo->ri_RelationDesc,
3980 &estate->es_tupleTable);
3981 resultRelInfo->ri_newTupleSlot =
3982 table_slot_create(resultRelInfo->ri_RelationDesc,
3983 &estate->es_tupleTable);
3984 resultRelInfo->ri_projectNewInfoValid = true;
3985}
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 4639 of file nodeModifyTable.c.

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

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

References elog, and ERROR.

Referenced by ExecReScan().