* ExecBuildUpdateProjection * * Build a ProjectionInfo node for constructing a new tuple during UPDATE. * The projection will be executed in the given econtext and the result will * be stored into the given tuple slot. (Caller must have ensured that tuple * slot has a descriptor matching the target rel!) * * When evalTargetList is false, targetList contains the UPDATE ... SET * expressio
| 522 | * ExecCheckPlanOutput, so we must do our safety checks here. |
| 523 | */ |
| 524 | ProjectionInfo * |
| 525 | ExecBuildUpdateProjection(List *targetList, |
| 526 | bool evalTargetList, |
| 527 | List *targetColnos, |
| 528 | TupleDesc relDesc, |
| 529 | ExprContext *econtext, |
| 530 | TupleTableSlot *slot, |
| 531 | PlanState *parent) |
| 532 | { |
| 533 | ProjectionInfo *projInfo = makeNode(ProjectionInfo); |
| 534 | ExprState *state; |
| 535 | int nAssignableCols; |
| 536 | bool sawJunk; |
| 537 | Bitmapset *assignedCols; |
| 538 | LastAttnumInfo deform = {0, 0, 0}; |
| 539 | ExprEvalStep scratch = {0}; |
| 540 | int outerattnum; |
| 541 | ListCell *lc, |
| 542 | *lc2; |
| 543 | |
| 544 | projInfo->pi_exprContext = econtext; |
| 545 | /* We embed ExprState into ProjectionInfo instead of doing extra palloc */ |
| 546 | projInfo->pi_state.tag = T_ExprState; |
| 547 | state = &projInfo->pi_state; |
| 548 | if (evalTargetList) |
| 549 | state->expr = (Expr *) targetList; |
| 550 | else |
| 551 | state->expr = NULL; /* not used */ |
| 552 | state->parent = parent; |
| 553 | state->ext_params = NULL; |
| 554 | |
| 555 | state->resultslot = slot; |
| 556 | |
| 557 | /* |
| 558 | * Examine the targetList to see how many non-junk columns there are, and |
| 559 | * to verify that the non-junk columns come before the junk ones. |
| 560 | */ |
| 561 | nAssignableCols = 0; |
| 562 | sawJunk = false; |
| 563 | foreach(lc, targetList) |
| 564 | { |
| 565 | TargetEntry *tle = lfirst_node(TargetEntry, lc); |
| 566 | |
| 567 | if (tle->resjunk) |
| 568 | sawJunk = true; |
| 569 | else |
| 570 | { |
| 571 | if (sawJunk) |
| 572 | elog(ERROR, "subplan target list is out of order"); |
| 573 | nAssignableCols++; |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | /* We should have one targetColnos entry per non-junk column */ |
| 578 | if (nAssignableCols != list_length(targetColnos)) |
| 579 | elog(ERROR, "targetColnos does not match subplan target list"); |
| 580 | |
| 581 | /* |
no test coverage detected