Github user zellerh commented on a diff in the pull request:
https://github.com/apache/incubator-trafodion/pull/1051#discussion_r111206198
--- Diff: core/sql/optimizer/RelExpr.cpp ---
@@ -9093,79 +9109,83 @@ NABoolean Scan::updateableIndex(IndexDesc *idx)
for (CollIndex j = 0; j < indexKey.entries(); j++)
{
ItemExpr *keyCol = indexKey[j].getItemExpr();
- ItemExpr *baseCol =
- ((IndexColumn*)keyCol)->getDefinition().getItemExpr();
+ ItemExpr *baseCol =
((IndexColumn*)keyCol)->getDefinition().getItemExpr();
CMPASSERT(baseCol->getOperatorType() == ITM_BASECOLUMN);
- if (((BaseColumn*)updateCol)->getColNumber() ==
- ((BaseColumn*)baseCol)->getColNumber())
- return FALSE;
- }
- }
+ if (getGroupAttr()->isEmbeddedUpdate()){
+ if (((BaseColumn*)updateCol)->getColNumber() ==
+ ((BaseColumn*)baseCol)->getColNumber())
+ return FALSE;
+ }
+ if ((NOT(idx->isUniqueIndex() || idx->isClusteringIndex()) &&
+ (CmpCommon::getDefault(UPDATE_CLUSTERING_OR_UNIQUE_INDEX_KEY)
!= DF_AGGRESSIVE))
+ ||
+ (CmpCommon::getDefault(UPDATE_CLUSTERING_OR_UNIQUE_INDEX_KEY) ==
DF_OFF))
+ {
+ if (((BaseColumn*)updateCol)->getColNumber() ==
+ ((BaseColumn*)baseCol)->getColNumber())
+ {
+ if (preds.containsAsEquiLocalPred(baseCol->getValueId()))
+ continue;
+ else if (preds.containsAsRangeLocalPred(baseCol->getValueId()))
+ needsHalloweenProtection = TRUE;
+ else {
+ needsHalloweenProtection = FALSE;
+ return FALSE;
+ }
+ } // index key col is being updated
+ } // not a clustering or unique index
+ } // loop over index key cols
+ } // loop over cols being updated
+
return TRUE;
} // Scan::updateableIndex
NABoolean Scan::requiresHalloweenForUpdateUsingIndexScan()
-{
-
- // Returns TRUE if any non clustering index can be used for a scan
- // during an UPDATE and a key column of that index is in the SET
- // clause of the update. If this method returns TRUE we will use a
- // sort node to prevent the "Halloween Update Problem".
- //
+{
+ // Returns TRUE if any index that is in the list of indexes that will be
+ // added later in addIndexInfo() to drive the scan for an UPDATE
requires
+ // Halloween protection. This is decided by using
Scan::updateableIndex().
+ // If this method returns TRUE we will use a sort node to prevent the
+ // "Halloween Update Problem".
--- End diff --
Thanks, that comment really helps.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---