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

Function ExecInitInsertProjection

src/backend/executor/nodeModifyTable.c:451–502  ·  view source on GitHub ↗

* ExecInitInsertProjection * Do one-time initialization of projection data for INSERT tuples. * * INSERT queries may need a projection to filter out junk attrs in the tlist. * * This is also a convenient place to verify that the * output of an INSERT matches the target table. */

Source from the content-addressed store, hash-verified

449 * output of an INSERT matches the target table.
450 */
451static void
452ExecInitInsertProjection(ModifyTableState *mtstate,
453 ResultRelInfo *resultRelInfo)
454{
455 ModifyTable *node = (ModifyTable *) mtstate->ps.plan;
456 Plan *subplan = outerPlan(node);
457 EState *estate = mtstate->ps.state;
458 List *insertTargetList = NIL;
459 bool need_projection = false;
460 ListCell *l;
461
462 /* Extract non-junk columns of the subplan's result tlist. */
463 foreach(l, subplan->targetlist)
464 {
465 TargetEntry *tle = (TargetEntry *) lfirst(l);
466
467 if (!tle->resjunk)
468 insertTargetList = lappend(insertTargetList, tle);
469 else
470 need_projection = true;
471 }
472
473 /*
474 * The junk-free list must produce a tuple suitable for the result
475 * relation.
476 */
477 ExecCheckPlanOutput(resultRelInfo->ri_RelationDesc, insertTargetList);
478
479 /* We'll need a slot matching the table's format. */
480 resultRelInfo->ri_newTupleSlot =
481 table_slot_create(resultRelInfo->ri_RelationDesc,
482 &estate->es_tupleTable);
483
484 /* Build ProjectionInfo if needed (it probably isn't). */
485 if (need_projection)
486 {
487 TupleDesc relDesc = RelationGetDescr(resultRelInfo->ri_RelationDesc);
488
489 /* need an expression context to do the projection */
490 if (mtstate->ps.ps_ExprContext == NULL)
491 ExecAssignExprContext(estate, &mtstate->ps);
492
493 resultRelInfo->ri_projectNew =
494 ExecBuildProjectionInfo(insertTargetList,
495 mtstate->ps.ps_ExprContext,
496 resultRelInfo->ri_newTupleSlot,
497 &mtstate->ps,
498 relDesc);
499 }
500
501 resultRelInfo->ri_projectNewInfoValid = true;
502}
503
504/*
505 * ExecInitUpdateProjection

Callers 1

ExecModifyTableFunction · 0.85

Calls 6

lappendFunction · 0.85
ExecCheckPlanOutputFunction · 0.85
table_slot_createFunction · 0.85
ExecAssignExprContextFunction · 0.85
ExecBuildProjectionInfoFunction · 0.85
foreachFunction · 0.50

Tested by

no test coverage detected