Github user zellerh commented on a diff in the pull request: https://github.com/apache/incubator-trafodion/pull/1253#discussion_r142546324 --- Diff: core/sql/generator/GenRelUpdate.cpp --- @@ -292,8 +292,85 @@ static short genUpdExpr( return 0; } -static short genUpdConstraintExpr(Generator *generator) +// Used to generate update or insert constraint expressions for update operators +static short genUpdConstraintExpr(Generator * generator, + ItemExpr * constrTree, + const ValueIdSet & constraintColumns, + ValueIdArray & targetRecExprArray, + ex_expr ** targetExpr /* out */) { + ExpGenerator * expGen = generator->getExpGenerator(); + + // The Attributes for the table columns refer to the old values of the column. + // The constraints must operate on the new values, though. So we must do a + // switcheroo on the Attributes for the update expression. The target value IDs + // come from targetRecExprArray. + + ValueIdList savedSourceVIDlist; + NAList<Attributes*> savedSourceAttrsList(generator->wHeap()); + + for (ValueId sourceValId = constraintColumns.init(); + constraintColumns.next(sourceValId); + constraintColumns.advance(sourceValId)) + { + NAColumn * sourceCol = ((IndexColumn*)sourceValId.getItemExpr())->getNAColumn(); + ValueId targetValId; + NABoolean found = FALSE; + for (CollIndex ni = 0; (!found) && (ni < targetRecExprArray.entries()); ni++) + { + const ItemExpr *assignExpr = targetRecExprArray[ni].getItemExpr(); + targetValId = assignExpr->child(0)->castToItemExpr()->getValueId(); + NAColumn *targetCol = NULL; + if (targetValId.getItemExpr()->getOperatorType() == ITM_BASECOLUMN) + targetCol = ((BaseColumn*)targetValId.getItemExpr())->getNAColumn(); + else if (targetValId.getItemExpr()->getOperatorType() == ITM_INDEXCOLUMN) + targetCol = ((IndexColumn*)targetValId.getItemExpr())->getNAColumn(); + + if ((targetCol) && --- End diff -- Yes, sorry to comment on surround code. If both source and target share the same NATable, then wouldn't the following be sufficient: ```c++ if ((targetCol) && courceCol == targetCol) ... ``` Another option would be to compare their column number: ```c++ CMPASSERT(sourceCol->getNATable() == targetCol->getNATable()); if (targetCol && sourceCol->getPosition() == targetCol->getPosition()) ... ``` One thing might be a problem: I wonder whether in some cases we might suppress caching of the NATable on the insert side and allow it on the select side or vice versa. I wonder whether @sureshsubbiah has any additional comments on this topic.
---