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

ModifyTableStateExecInitModifyTable (ModifyTable *node, EState *estate, int eflags)
 
void ExecEndModifyTable (ModifyTableState *node)
 
void ExecReScanModifyTable (ModifyTableState *node)
 

Function Documentation

◆ ExecEndModifyTable()

void ExecEndModifyTable ( ModifyTableState node)

Definition at line 2650 of file nodeModifyTable.c.

References FdwRoutine::EndForeignModify, EvalPlanQualEnd(), ExecCleanupTupleRouting(), ExecClearTuple(), ExecEndNode(), ExecFreeExprContext(), i, ModifyTableState::mt_epqstate, ModifyTableState::mt_nplans, ModifyTableState::mt_partition_tuple_routing, ModifyTableState::mt_plans, ModifyTableState::ps, PlanState::ps_ResultTupleSlot, ModifyTableState::resultRelInfo, ResultRelInfo::ri_FdwRoutine, ResultRelInfo::ri_usesFdwDirectModify, and PlanState::state.

Referenced by ExecEndNode().

2651 {
2652  int i;
2653 
2654  /*
2655  * Allow any FDWs to shut down
2656  */
2657  for (i = 0; i < node->mt_nplans; i++)
2658  {
2659  ResultRelInfo *resultRelInfo = node->resultRelInfo + i;
2660 
2661  if (!resultRelInfo->ri_usesFdwDirectModify &&
2662  resultRelInfo->ri_FdwRoutine != NULL &&
2663  resultRelInfo->ri_FdwRoutine->EndForeignModify != NULL)
2664  resultRelInfo->ri_FdwRoutine->EndForeignModify(node->ps.state,
2665  resultRelInfo);
2666  }
2667 
2668  /* Close all the partitioned tables, leaf partitions, and their indices */
2669  if (node->mt_partition_tuple_routing)
2671 
2672  /*
2673  * Free the exprcontext
2674  */
2675  ExecFreeExprContext(&node->ps);
2676 
2677  /*
2678  * clean out the tuple table
2679  */
2681 
2682  /*
2683  * Terminate EPQ execution if active
2684  */
2685  EvalPlanQualEnd(&node->mt_epqstate);
2686 
2687  /*
2688  * shut down subplans
2689  */
2690  for (i = 0; i < node->mt_nplans; i++)
2691  ExecEndNode(node->mt_plans[i]);
2692 }
struct PartitionTupleRouting * mt_partition_tuple_routing
Definition: execnodes.h:1054
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:538
ResultRelInfo * resultRelInfo
Definition: execnodes.h:1043
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:475
EState * state
Definition: execnodes.h:914
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:566
void EvalPlanQualEnd(EPQState *epqstate)
Definition: execMain.c:3256
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:946
PlanState ps
Definition: execnodes.h:1036
void ExecCleanupTupleRouting(ModifyTableState *mtstate, PartitionTupleRouting *proute)
bool ri_usesFdwDirectModify
Definition: execnodes.h:427
EPQState mt_epqstate
Definition: execnodes.h:1047
struct FdwRoutine * ri_FdwRoutine
Definition: execnodes.h:421
EndForeignModify_function EndForeignModify
Definition: fdwapi.h:213
PlanState ** mt_plans
Definition: execnodes.h:1040
int i

◆ ExecInitModifyTable()

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

Definition at line 2176 of file nodeModifyTable.c.

References ModifyTable::arbiterIndexes, Assert, AttributeNumberIsValid, FdwRoutine::BeginForeignModify, bms_is_member(), ModifyTable::canSetTag, ModifyTableState::canSetTag, CheckValidResultRel(), CMD_DELETE, CMD_INSERT, CMD_UPDATE, elog, ModifyTable::epqParam, ERROR, EState::es_auxmodifytables, EState::es_result_relation_info, EState::es_result_relations, EState::es_root_result_relations, EState::es_trig_tuple_slot, EvalPlanQualInit(), EvalPlanQualSetPlan(), ModifyTable::exclRelTlist, EXEC_FLAG_BACKWARD, EXEC_FLAG_EXPLAIN_ONLY, EXEC_FLAG_MARK, ExecAssignExprContext(), ExecBuildAuxRowMark(), ExecBuildProjectionInfo(), ExecCheckPlanOutput(), ExecFindJunkAttribute(), ExecFindRowMark(), ExecInitExtraTupleSlot(), ExecInitJunkFilter(), ExecInitNode(), ExecInitQual(), ExecInitResultTupleSlotTL(), ExecModifyTable(), ExecOpenIndices(), PlanState::ExecProcNode, ExecSetupChildParentMapForSubplan(), ExecSetupPartitionTupleRouting(), ExecSetupTransitionCaptureState(), ExecTypeFromTL(), ModifyTable::fdwDirectModifyPlans, ModifyTable::fdwPrivLists, ModifyTableState::fireBSTriggers, getTargetResultRelInfo(), i, PlanRowMark::isParent, JunkFilter::jf_junkAttNo, lappend(), lcons(), lfirst, lfirst_node, linitial, list_length(), list_nth(), makeNode, ModifyTableState::mt_arowmarks, ModifyTableState::mt_conflproj, ModifyTableState::mt_done, ModifyTableState::mt_epqstate, ModifyTableState::mt_excludedtlist, ModifyTableState::mt_existing, ModifyTableState::mt_nplans, ModifyTableState::mt_partition_tuple_routing, ModifyTableState::mt_plans, ModifyTableState::mt_whichplan, NIL, OnConflictSetState::oc_ProjInfo, OnConflictSetState::oc_ProjTupdesc, OnConflictSetState::oc_WhereClause, ONCONFLICT_NONE, ONCONFLICT_UPDATE, ModifyTable::onConflictAction, ModifyTable::onConflictSet, ModifyTable::onConflictWhere, ModifyTable::operation, ModifyTableState::operation, palloc0(), ModifyTable::partColsUpdated, PlanState::plan, ModifyTable::plans, ModifyTableState::ps, PlanState::ps_ExprContext, PlanState::ps_ResultTupleSlot, WithCheckOption::qual, RelationData::rd_att, RelationData::rd_rel, relkind, TargetEntry::resjunk, ModifyTable::resultRelIndex, ModifyTableState::resultRelInfo, ModifyTable::returningLists, ResultRelInfo::ri_FdwRoutine, ResultRelInfo::ri_IndexRelationDescs, ResultRelInfo::ri_junkFilter, ResultRelInfo::ri_onConflict, ResultRelInfo::ri_onConflictArbiterIndexes, ResultRelInfo::ri_projectReturning, ResultRelInfo::ri_RelationDesc, ResultRelInfo::ri_returningList, ResultRelInfo::ri_TrigDesc, ResultRelInfo::ri_usesFdwDirectModify, ResultRelInfo::ri_WithCheckOptionExprs, ResultRelInfo::ri_WithCheckOptions, ModifyTable::rootResultRelIndex, ModifyTableState::rootResultRelInfo, ModifyTable::rowMarks, PlanRowMark::rti, PlanState::state, Plan::targetlist, tupleDesc::tdhasoid, TriggerDesc::trig_update_before_row, and ModifyTable::withCheckOptionLists.

Referenced by ExecInitNode().

2177 {
2178  ModifyTableState *mtstate;
2179  CmdType operation = node->operation;
2180  int nplans = list_length(node->plans);
2181  ResultRelInfo *saved_resultRelInfo;
2182  ResultRelInfo *resultRelInfo;
2183  Plan *subplan;
2184  ListCell *l;
2185  int i;
2186  Relation rel;
2187  bool update_tuple_routing_needed = node->partColsUpdated;
2188 
2189  /* check for unsupported flags */
2190  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
2191 
2192  /*
2193  * create state structure
2194  */
2195  mtstate = makeNode(ModifyTableState);
2196  mtstate->ps.plan = (Plan *) node;
2197  mtstate->ps.state = estate;
2198  mtstate->ps.ExecProcNode = ExecModifyTable;
2199 
2200  mtstate->operation = operation;
2201  mtstate->canSetTag = node->canSetTag;
2202  mtstate->mt_done = false;
2203 
2204  mtstate->mt_plans = (PlanState **) palloc0(sizeof(PlanState *) * nplans);
2205  mtstate->resultRelInfo = estate->es_result_relations + node->resultRelIndex;
2206 
2207  /* If modifying a partitioned table, initialize the root table info */
2208  if (node->rootResultRelIndex >= 0)
2209  mtstate->rootResultRelInfo = estate->es_root_result_relations +
2210  node->rootResultRelIndex;
2211 
2212  mtstate->mt_arowmarks = (List **) palloc0(sizeof(List *) * nplans);
2213  mtstate->mt_nplans = nplans;
2214 
2215  /* set up epqstate with dummy subplan data for the moment */
2216  EvalPlanQualInit(&mtstate->mt_epqstate, estate, NULL, NIL, node->epqParam);
2217  mtstate->fireBSTriggers = true;
2218 
2219  /*
2220  * call ExecInitNode on each of the plans to be executed and save the
2221  * results into the array "mt_plans". This is also a convenient place to
2222  * verify that the proposed target relations are valid and open their
2223  * indexes for insertion of new index entries. Note we *must* set
2224  * estate->es_result_relation_info correctly while we initialize each
2225  * sub-plan; ExecContextForcesOids depends on that!
2226  */
2227  saved_resultRelInfo = estate->es_result_relation_info;
2228 
2229  resultRelInfo = mtstate->resultRelInfo;
2230  i = 0;
2231  foreach(l, node->plans)
2232  {
2233  subplan = (Plan *) lfirst(l);
2234 
2235  /* Initialize the usesFdwDirectModify flag */
2236  resultRelInfo->ri_usesFdwDirectModify = bms_is_member(i,
2237  node->fdwDirectModifyPlans);
2238 
2239  /*
2240  * Verify result relation is a valid target for the current operation
2241  */
2242  CheckValidResultRel(resultRelInfo, operation);
2243 
2244  /*
2245  * If there are indices on the result relation, open them and save
2246  * descriptors in the result relation info, so that we can add new
2247  * index entries for the tuples we add/update. We need not do this
2248  * for a DELETE, however, since deletion doesn't affect indexes. Also,
2249  * inside an EvalPlanQual operation, the indexes might be open
2250  * already, since we share the resultrel state with the original
2251  * query.
2252  */
2253  if (resultRelInfo->ri_RelationDesc->rd_rel->relhasindex &&
2254  operation != CMD_DELETE &&
2255  resultRelInfo->ri_IndexRelationDescs == NULL)
2256  ExecOpenIndices(resultRelInfo,
2258 
2259  /*
2260  * If this is an UPDATE and a BEFORE UPDATE trigger is present, the
2261  * trigger itself might modify the partition-key values. So arrange
2262  * for tuple routing.
2263  */
2264  if (resultRelInfo->ri_TrigDesc &&
2265  resultRelInfo->ri_TrigDesc->trig_update_before_row &&
2266  operation == CMD_UPDATE)
2267  update_tuple_routing_needed = true;
2268 
2269  /* Now init the plan for this result rel */
2270  estate->es_result_relation_info = resultRelInfo;
2271  mtstate->mt_plans[i] = ExecInitNode(subplan, estate, eflags);
2272 
2273  /* Also let FDWs init themselves for foreign-table result rels */
2274  if (!resultRelInfo->ri_usesFdwDirectModify &&
2275  resultRelInfo->ri_FdwRoutine != NULL &&
2276  resultRelInfo->ri_FdwRoutine->BeginForeignModify != NULL)
2277  {
2278  List *fdw_private = (List *) list_nth(node->fdwPrivLists, i);
2279 
2280  resultRelInfo->ri_FdwRoutine->BeginForeignModify(mtstate,
2281  resultRelInfo,
2282  fdw_private,
2283  i,
2284  eflags);
2285  }
2286 
2287  resultRelInfo++;
2288  i++;
2289  }
2290 
2291  estate->es_result_relation_info = saved_resultRelInfo;
2292 
2293  /* Get the target relation */
2294  rel = (getTargetResultRelInfo(mtstate))->ri_RelationDesc;
2295 
2296  /*
2297  * If it's not a partitioned table after all, UPDATE tuple routing should
2298  * not be attempted.
2299  */
2300  if (rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
2301  update_tuple_routing_needed = false;
2302 
2303  /*
2304  * Build state for tuple routing if it's an INSERT or if it's an UPDATE of
2305  * partition key.
2306  */
2307  if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE &&
2308  (operation == CMD_INSERT || update_tuple_routing_needed))
2309  mtstate->mt_partition_tuple_routing =
2310  ExecSetupPartitionTupleRouting(mtstate, rel);
2311 
2312  /*
2313  * Build state for collecting transition tuples. This requires having a
2314  * valid trigger query context, so skip it in explain-only mode.
2315  */
2316  if (!(eflags & EXEC_FLAG_EXPLAIN_ONLY))
2317  ExecSetupTransitionCaptureState(mtstate, estate);
2318 
2319  /*
2320  * Construct mapping from each of the per-subplan partition attnos to the
2321  * root attno. This is required when during update row movement the tuple
2322  * descriptor of a source partition does not match the root partitioned
2323  * table descriptor. In such a case we need to convert tuples to the root
2324  * tuple descriptor, because the search for destination partition starts
2325  * from the root. Skip this setup if it's not a partition key update.
2326  */
2327  if (update_tuple_routing_needed)
2329 
2330  /*
2331  * Initialize any WITH CHECK OPTION constraints if needed.
2332  */
2333  resultRelInfo = mtstate->resultRelInfo;
2334  i = 0;
2335  foreach(l, node->withCheckOptionLists)
2336  {
2337  List *wcoList = (List *) lfirst(l);
2338  List *wcoExprs = NIL;
2339  ListCell *ll;
2340 
2341  foreach(ll, wcoList)
2342  {
2343  WithCheckOption *wco = (WithCheckOption *) lfirst(ll);
2344  ExprState *wcoExpr = ExecInitQual((List *) wco->qual,
2345  mtstate->mt_plans[i]);
2346 
2347  wcoExprs = lappend(wcoExprs, wcoExpr);
2348  }
2349 
2350  resultRelInfo->ri_WithCheckOptions = wcoList;
2351  resultRelInfo->ri_WithCheckOptionExprs = wcoExprs;
2352  resultRelInfo++;
2353  i++;
2354  }
2355 
2356  /*
2357  * Initialize RETURNING projections if needed.
2358  */
2359  if (node->returningLists)
2360  {
2361  TupleTableSlot *slot;
2362  ExprContext *econtext;
2363 
2364  /*
2365  * Initialize result tuple slot and assign its rowtype using the first
2366  * RETURNING list. We assume the rest will look the same.
2367  */
2368  mtstate->ps.plan->targetlist = (List *) linitial(node->returningLists);
2369 
2370  /* Set up a slot for the output of the RETURNING projection(s) */
2371  ExecInitResultTupleSlotTL(estate, &mtstate->ps);
2372  slot = mtstate->ps.ps_ResultTupleSlot;
2373 
2374  /* Need an econtext too */
2375  if (mtstate->ps.ps_ExprContext == NULL)
2376  ExecAssignExprContext(estate, &mtstate->ps);
2377  econtext = mtstate->ps.ps_ExprContext;
2378 
2379  /*
2380  * Build a projection for each result rel.
2381  */
2382  resultRelInfo = mtstate->resultRelInfo;
2383  foreach(l, node->returningLists)
2384  {
2385  List *rlist = (List *) lfirst(l);
2386 
2387  resultRelInfo->ri_returningList = rlist;
2388  resultRelInfo->ri_projectReturning =
2389  ExecBuildProjectionInfo(rlist, econtext, slot, &mtstate->ps,
2390  resultRelInfo->ri_RelationDesc->rd_att);
2391  resultRelInfo++;
2392  }
2393  }
2394  else
2395  {
2396  /*
2397  * We still must construct a dummy result tuple type, because InitPlan
2398  * expects one (maybe should change that?).
2399  */
2400  mtstate->ps.plan->targetlist = NIL;
2401  ExecInitResultTupleSlotTL(estate, &mtstate->ps);
2402 
2403  mtstate->ps.ps_ExprContext = NULL;
2404  }
2405 
2406  /* Set the list of arbiter indexes if needed for ON CONFLICT */
2407  resultRelInfo = mtstate->resultRelInfo;
2408  if (node->onConflictAction != ONCONFLICT_NONE)
2409  resultRelInfo->ri_onConflictArbiterIndexes = node->arbiterIndexes;
2410 
2411  /*
2412  * If needed, Initialize target list, projection and qual for ON CONFLICT
2413  * DO UPDATE.
2414  */
2415  if (node->onConflictAction == ONCONFLICT_UPDATE)
2416  {
2417  ExprContext *econtext;
2418  TupleDesc relationDesc;
2419  TupleDesc tupDesc;
2420 
2421  /* insert may only have one plan, inheritance is not expanded */
2422  Assert(nplans == 1);
2423 
2424  /* already exists if created by RETURNING processing above */
2425  if (mtstate->ps.ps_ExprContext == NULL)
2426  ExecAssignExprContext(estate, &mtstate->ps);
2427 
2428  econtext = mtstate->ps.ps_ExprContext;
2429  relationDesc = resultRelInfo->ri_RelationDesc->rd_att;
2430 
2431  /*
2432  * Initialize slot for the existing tuple. If we'll be performing
2433  * tuple routing, the tuple descriptor to use for this will be
2434  * determined based on which relation the update is actually applied
2435  * to, so we don't set its tuple descriptor here.
2436  */
2437  mtstate->mt_existing =
2438  ExecInitExtraTupleSlot(mtstate->ps.state,
2439  mtstate->mt_partition_tuple_routing ?
2440  NULL : relationDesc);
2441 
2442  /* carried forward solely for the benefit of explain */
2443  mtstate->mt_excludedtlist = node->exclRelTlist;
2444 
2445  /* create state for DO UPDATE SET operation */
2446  resultRelInfo->ri_onConflict = makeNode(OnConflictSetState);
2447 
2448  /*
2449  * Create the tuple slot for the UPDATE SET projection.
2450  *
2451  * Just like mt_existing above, we leave it without a tuple descriptor
2452  * in the case of partitioning tuple routing, so that it can be
2453  * changed by ExecPrepareTupleRouting. In that case, we still save
2454  * the tupdesc in the parent's state: it can be reused by partitions
2455  * with an identical descriptor to the parent.
2456  */
2457  tupDesc = ExecTypeFromTL((List *) node->onConflictSet,
2458  relationDesc->tdhasoid);
2459  mtstate->mt_conflproj =
2460  ExecInitExtraTupleSlot(mtstate->ps.state,
2461  mtstate->mt_partition_tuple_routing ?
2462  NULL : tupDesc);
2463  resultRelInfo->ri_onConflict->oc_ProjTupdesc = tupDesc;
2464 
2465  /* build UPDATE SET projection state */
2466  resultRelInfo->ri_onConflict->oc_ProjInfo =
2467  ExecBuildProjectionInfo(node->onConflictSet, econtext,
2468  mtstate->mt_conflproj, &mtstate->ps,
2469  relationDesc);
2470 
2471  /* initialize state to evaluate the WHERE clause, if any */
2472  if (node->onConflictWhere)
2473  {
2474  ExprState *qualexpr;
2475 
2476  qualexpr = ExecInitQual((List *) node->onConflictWhere,
2477  &mtstate->ps);
2478  resultRelInfo->ri_onConflict->oc_WhereClause = qualexpr;
2479  }
2480  }
2481 
2482  /*
2483  * If we have any secondary relations in an UPDATE or DELETE, they need to
2484  * be treated like non-locked relations in SELECT FOR UPDATE, ie, the
2485  * EvalPlanQual mechanism needs to be told about them. Locate the
2486  * relevant ExecRowMarks.
2487  */
2488  foreach(l, node->rowMarks)
2489  {
2491  ExecRowMark *erm;
2492 
2493  /* ignore "parent" rowmarks; they are irrelevant at runtime */
2494  if (rc->isParent)
2495  continue;
2496 
2497  /* find ExecRowMark (same for all subplans) */
2498  erm = ExecFindRowMark(estate, rc->rti, false);
2499 
2500  /* build ExecAuxRowMark for each subplan */
2501  for (i = 0; i < nplans; i++)
2502  {
2503  ExecAuxRowMark *aerm;
2504 
2505  subplan = mtstate->mt_plans[i]->plan;
2506  aerm = ExecBuildAuxRowMark(erm, subplan->targetlist);
2507  mtstate->mt_arowmarks[i] = lappend(mtstate->mt_arowmarks[i], aerm);
2508  }
2509  }
2510 
2511  /* select first subplan */
2512  mtstate->mt_whichplan = 0;
2513  subplan = (Plan *) linitial(node->plans);
2514  EvalPlanQualSetPlan(&mtstate->mt_epqstate, subplan,
2515  mtstate->mt_arowmarks[0]);
2516 
2517  /*
2518  * Initialize the junk filter(s) if needed. INSERT queries need a filter
2519  * if there are any junk attrs in the tlist. UPDATE and DELETE always
2520  * need a filter, since there's always at least one junk attribute present
2521  * --- no need to look first. Typically, this will be a 'ctid' or
2522  * 'wholerow' attribute, but in the case of a foreign data wrapper it
2523  * might be a set of junk attributes sufficient to identify the remote
2524  * row.
2525  *
2526  * If there are multiple result relations, each one needs its own junk
2527  * filter. Note multiple rels are only possible for UPDATE/DELETE, so we
2528  * can't be fooled by some needing a filter and some not.
2529  *
2530  * This section of code is also a convenient place to verify that the
2531  * output of an INSERT or UPDATE matches the target table(s).
2532  */
2533  {
2534  bool junk_filter_needed = false;
2535 
2536  switch (operation)
2537  {
2538  case CMD_INSERT:
2539  foreach(l, subplan->targetlist)
2540  {
2541  TargetEntry *tle = (TargetEntry *) lfirst(l);
2542 
2543  if (tle->resjunk)
2544  {
2545  junk_filter_needed = true;
2546  break;
2547  }
2548  }
2549  break;
2550  case CMD_UPDATE:
2551  case CMD_DELETE:
2552  junk_filter_needed = true;
2553  break;
2554  default:
2555  elog(ERROR, "unknown operation");
2556  break;
2557  }
2558 
2559  if (junk_filter_needed)
2560  {
2561  resultRelInfo = mtstate->resultRelInfo;
2562  for (i = 0; i < nplans; i++)
2563  {
2564  JunkFilter *j;
2565 
2566  subplan = mtstate->mt_plans[i]->plan;
2567  if (operation == CMD_INSERT || operation == CMD_UPDATE)
2568  ExecCheckPlanOutput(resultRelInfo->ri_RelationDesc,
2569  subplan->targetlist);
2570 
2571  j = ExecInitJunkFilter(subplan->targetlist,
2572  resultRelInfo->ri_RelationDesc->rd_att->tdhasoid,
2573  ExecInitExtraTupleSlot(estate, NULL));
2574 
2575  if (operation == CMD_UPDATE || operation == CMD_DELETE)
2576  {
2577  /* For UPDATE/DELETE, find the appropriate junk attr now */
2578  char relkind;
2579 
2580  relkind = resultRelInfo->ri_RelationDesc->rd_rel->relkind;
2581  if (relkind == RELKIND_RELATION ||
2582  relkind == RELKIND_MATVIEW ||
2583  relkind == RELKIND_PARTITIONED_TABLE)
2584  {
2585  j->jf_junkAttNo = ExecFindJunkAttribute(j, "ctid");
2587  elog(ERROR, "could not find junk ctid column");
2588  }
2589  else if (relkind == RELKIND_FOREIGN_TABLE)
2590  {
2591  /*
2592  * When there is a row-level trigger, there should be
2593  * a wholerow attribute.
2594  */
2595  j->jf_junkAttNo = ExecFindJunkAttribute(j, "wholerow");
2596  }
2597  else
2598  {
2599  j->jf_junkAttNo = ExecFindJunkAttribute(j, "wholerow");
2601  elog(ERROR, "could not find junk wholerow column");
2602  }
2603  }
2604 
2605  resultRelInfo->ri_junkFilter = j;
2606  resultRelInfo++;
2607  }
2608  }
2609  else
2610  {
2611  if (operation == CMD_INSERT)
2613  subplan->targetlist);
2614  }
2615  }
2616 
2617  /*
2618  * Set up a tuple table slot for use for trigger output tuples. In a plan
2619  * containing multiple ModifyTable nodes, all can share one such slot, so
2620  * we keep it in the estate.
2621  */
2622  if (estate->es_trig_tuple_slot == NULL)
2623  estate->es_trig_tuple_slot = ExecInitExtraTupleSlot(estate, NULL);
2624 
2625  /*
2626  * Lastly, if this is not the primary (canSetTag) ModifyTable node, add it
2627  * to estate->es_auxmodifytables so that it will be run to completion by
2628  * ExecPostprocessPlan. (It'd actually work fine to add the primary
2629  * ModifyTable node too, but there's no need.) Note the use of lcons not
2630  * lappend: we need later-initialized ModifyTable nodes to be shut down
2631  * before earlier ones. This ensures that we don't throw away RETURNING
2632  * rows that need to be seen by a later CTE subplan.
2633  */
2634  if (!mtstate->canSetTag)
2635  estate->es_auxmodifytables = lcons(mtstate,
2636  estate->es_auxmodifytables);
2637 
2638  return mtstate;
2639 }
AttrNumber jf_junkAttNo
Definition: execnodes.h:365
#define NIL
Definition: pg_list.h:69
JunkFilter * ri_junkFilter
Definition: execnodes.h:439
List * arbiterIndexes
Definition: plannodes.h:237
Relation ri_RelationDesc
Definition: execnodes.h:397
Bitmapset * fdwDirectModifyPlans
Definition: plannodes.h:233
static ResultRelInfo * getTargetResultRelInfo(ModifyTableState *node)
bool tdhasoid
Definition: tupdesc.h:85
struct PartitionTupleRouting * mt_partition_tuple_routing
Definition: execnodes.h:1054
List * withCheckOptionLists
Definition: plannodes.h:230
int resultRelIndex
Definition: plannodes.h:227
ResultRelInfo * resultRelInfo
Definition: execnodes.h:1043
AttrNumber ExecFindJunkAttribute(JunkFilter *junkfilter, const char *attrName)
Definition: execJunk.c:209
ExprContext * ps_ExprContext
Definition: execnodes.h:947
TupleTableSlot * mt_conflproj
Definition: execnodes.h:1051
bool partColsUpdated
Definition: plannodes.h:225
bool canSetTag
Definition: plannodes.h:221
CmdType operation
Definition: execnodes.h:1037
ResultRelInfo * rootResultRelInfo
Definition: execnodes.h:1044
void EvalPlanQualSetPlan(EPQState *epqstate, Plan *subplan, List *auxrowmarks)
Definition: execMain.c:2852
EState * state
Definition: execnodes.h:914
Form_pg_class rd_rel
Definition: rel.h:84
List * plans
Definition: plannodes.h:229
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc)
Definition: execTuples.c:931
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:205
char relkind
Definition: pg_class.h:51
List * onConflictSet
Definition: plannodes.h:238
int rootResultRelIndex
Definition: plannodes.h:228
void ExecOpenIndices(ResultRelInfo *resultRelInfo, bool speculative)
Definition: execIndexing.c:149
TupleTableSlot * mt_existing
Definition: execnodes.h:1049
PartitionTupleRouting * ExecSetupPartitionTupleRouting(ModifyTableState *mtstate, Relation rel)
Definition: execPartition.c:76
List * ri_WithCheckOptionExprs
Definition: execnodes.h:433
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:946
static void ExecSetupChildParentMapForSubplan(ModifyTableState *mtstate)
List * rowMarks
Definition: plannodes.h:234
bool resjunk
Definition: primnodes.h:1382
#define linitial(l)
Definition: pg_list.h:111
#define ERROR
Definition: elog.h:43
PlanState ps
Definition: execnodes.h:1036
ProjectionInfo * oc_ProjInfo
Definition: execnodes.h:377
bool ri_usesFdwDirectModify
Definition: execnodes.h:427
static void ExecSetupTransitionCaptureState(ModifyTableState *mtstate, EState *estate)
void CheckValidResultRel(ResultRelInfo *resultRelInfo, CmdType operation)
Definition: execMain.c:1104
#define EXEC_FLAG_BACKWARD
Definition: executor.h:60
#define lfirst_node(type, lc)
Definition: pg_list.h:109
void * list_nth(const List *list, int n)
Definition: list.c:410
ResultRelInfo * es_result_relations
Definition: execnodes.h:490
JunkFilter * ExecInitJunkFilter(List *targetList, bool hasoid, TupleTableSlot *slot)
Definition: execJunk.c:61
List * fdwPrivLists
Definition: plannodes.h:232
EPQState mt_epqstate
Definition: execnodes.h:1047
bool trig_update_before_row
Definition: reltrigger.h:60
ProjectionInfo * ri_projectReturning
Definition: execnodes.h:445
struct FdwRoutine * ri_FdwRoutine
Definition: execnodes.h:421
ExprState * oc_WhereClause
Definition: execnodes.h:379
TupleTableSlot * es_trig_tuple_slot
Definition: execnodes.h:512
TriggerDesc * ri_TrigDesc
Definition: execnodes.h:409
TupleDesc ExecTypeFromTL(List *targetList, bool hasoid)
Definition: execTuples.c:965
List * lappend(List *list, void *datum)
Definition: list.c:128
PlanState ** mt_plans
Definition: execnodes.h:1040
OnConflictSetState * ri_onConflict
Definition: execnodes.h:451
#define AttributeNumberIsValid(attributeNumber)
Definition: attnum.h:34
static TupleTableSlot * ExecModifyTable(PlanState *pstate)
void * palloc0(Size size)
Definition: mcxt.c:955
List * es_auxmodifytables
Definition: execnodes.h:540
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:918
List * ri_WithCheckOptions
Definition: execnodes.h:430
void ExecInitResultTupleSlotTL(EState *estate, PlanState *planstate)
Definition: execTuples.c:890
TupleDesc rd_att
Definition: rel.h:85
void EvalPlanQualInit(EPQState *epqstate, EState *estate, Plan *subplan, List *auxrowmarks, int epqParam)
Definition: execMain.c:2833
Plan * plan
Definition: execnodes.h:912
List * lcons(void *datum, List *list)
Definition: list.c:259
#define makeNode(_type_)
Definition: nodes.h:564
static void ExecCheckPlanOutput(Relation resultRel, List *targetList)
#define Assert(condition)
Definition: c.h:699
#define lfirst(lc)
Definition: pg_list.h:106
#define EXEC_FLAG_MARK
Definition: executor.h:61
OnConflictAction onConflictAction
Definition: plannodes.h:236
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:428
static int list_length(const List *l)
Definition: pg_list.h:89
List * targetlist
Definition: plannodes.h:147
List * mt_excludedtlist
Definition: execnodes.h:1050
ProjectionInfo * ExecBuildProjectionInfo(List *targetList, ExprContext *econtext, TupleTableSlot *slot, PlanState *parent, TupleDesc inputDesc)
Definition: execExpr.c:349
CmdType operation
Definition: plannodes.h:220
ResultRelInfo * es_root_result_relations
Definition: execnodes.h:501
int i
List * returningLists
Definition: plannodes.h:231
bool isParent
Definition: plannodes.h:1045
#define elog
Definition: elog.h:219
BeginForeignModify_function BeginForeignModify
Definition: fdwapi.h:209
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:139
Definition: pg_list.h:45
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:486
#define EXEC_FLAG_EXPLAIN_ONLY
Definition: executor.h:58
TupleDesc oc_ProjTupdesc
Definition: execnodes.h:378
List * ri_onConflictArbiterIndexes
Definition: execnodes.h:448
CmdType
Definition: nodes.h:656
RelationPtr ri_IndexRelationDescs
Definition: execnodes.h:403
ExecAuxRowMark * ExecBuildAuxRowMark(ExecRowMark *erm, List *targetlist)
Definition: execMain.c:2433
List * exclRelTlist
Definition: plannodes.h:241
List * ri_returningList
Definition: execnodes.h:442
List ** mt_arowmarks
Definition: execnodes.h:1046
int epqParam
Definition: plannodes.h:235
Node * onConflictWhere
Definition: plannodes.h:239
ExecRowMark * ExecFindRowMark(EState *estate, Index rti, bool missing_ok)
Definition: execMain.c:2409
ResultRelInfo * es_result_relation_info
Definition: execnodes.h:492

◆ ExecReScanModifyTable()

void ExecReScanModifyTable ( ModifyTableState node)

Definition at line 2695 of file nodeModifyTable.c.

References elog, and ERROR.

Referenced by ExecReScan().

2696 {
2697  /*
2698  * Currently, we don't need to support rescan on ModifyTable nodes. The
2699  * semantics of that would be a bit debatable anyway.
2700  */
2701  elog(ERROR, "ExecReScanModifyTable is not implemented");
2702 }
#define ERROR
Definition: elog.h:43
#define elog
Definition: elog.h:219