MCPcopy Create free account
hub / github.com/apache/cloudberry / ExecInitUpdateProjection

Function ExecInitUpdateProjection

src/backend/executor/nodeModifyTable.c:521–571  ·  view source on GitHub ↗

* ExecInitUpdateProjection * Do one-time initialization of projection data for UPDATE tuples. * * UPDATE always needs a projection, because (1) there's always some junk * attrs, and (2) we may need to merge values of not-updated columns from * the old tuple into the final tuple. In UPDATE, the tuple arriving from * the subplan contains only new values for the changed columns, plus row * i

Source from the content-addressed store, hash-verified

519 * matches the target table (ExecBuildUpdateProjection does that).
520 */
521static void
522ExecInitUpdateProjection(ModifyTableState *mtstate,
523 ResultRelInfo *resultRelInfo)
524{
525 ModifyTable *node = (ModifyTable *) mtstate->ps.plan;
526 Plan *subplan = outerPlan(node);
527 EState *estate = mtstate->ps.state;
528 TupleDesc relDesc = RelationGetDescr(resultRelInfo->ri_RelationDesc);
529 int whichrel;
530 List *updateColnos;
531
532 /*
533 * Usually, mt_lastResultIndex matches the target rel. If it happens not
534 * to, we can get the index the hard way with an integer division.
535 */
536 whichrel = mtstate->mt_lastResultIndex;
537 if (resultRelInfo != mtstate->resultRelInfo + whichrel)
538 {
539 whichrel = resultRelInfo - mtstate->resultRelInfo;
540 Assert(whichrel >= 0 && whichrel < mtstate->mt_nrels);
541 }
542
543 updateColnos = (List *) list_nth(node->updateColnosLists, whichrel);
544
545 /*
546 * For UPDATE, we use the old tuple to fill up missing values in the tuple
547 * produced by the subplan to get the new tuple. We need two slots, both
548 * matching the table's desired format.
549 */
550 resultRelInfo->ri_oldTupleSlot =
551 table_slot_create(resultRelInfo->ri_RelationDesc,
552 &estate->es_tupleTable);
553 resultRelInfo->ri_newTupleSlot =
554 table_slot_create(resultRelInfo->ri_RelationDesc,
555 &estate->es_tupleTable);
556
557 /* need an expression context to do the projection */
558 if (mtstate->ps.ps_ExprContext == NULL)
559 ExecAssignExprContext(estate, &mtstate->ps);
560
561 resultRelInfo->ri_projectNew =
562 ExecBuildUpdateProjection(subplan->targetlist,
563 false, /* subplan did the evaluation */
564 updateColnos,
565 relDesc,
566 mtstate->ps.ps_ExprContext,
567 resultRelInfo->ri_newTupleSlot,
568 &mtstate->ps);
569
570 resultRelInfo->ri_projectNewInfoValid = true;
571}
572
573/*
574 * ExecGetInsertNewTuple

Callers 3

ExecCrossPartitionUpdateFunction · 0.85
ExecUpdateFunction · 0.85
ExecModifyTableFunction · 0.85

Calls 4

list_nthFunction · 0.85
table_slot_createFunction · 0.85
ExecAssignExprContextFunction · 0.85

Tested by

no test coverage detected