Github user sureshsubbiah commented on a diff in the pull request:
https://github.com/apache/incubator-trafodion/pull/1051#discussion_r110810480
--- Diff: core/sql/optimizer/RelExpr.cpp ---
@@ -9121,38 +9090,85 @@ NABoolean Scan::updateableIndex(IndexDesc *idx)
{
ItemExpr *updateCol = colUpdated[i].getItemExpr();
CMPASSERT(updateCol->getOperatorType() == ITM_BASECOLUMN);
-
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);
-
- // QSTUFF
- if (getGroupAttr()->isEmbeddedUpdate()){
- if (((BaseColumn*)updateCol)->getColNumber() ==
+ if (((BaseColumn*)updateCol)->getColNumber() ==
((BaseColumn*)baseCol)->getColNumber())
- return FALSE;
- }
- // QSTUFF
+ return FALSE;
+ }
+ }
+ 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".
+ //
- if ((NOT(idx->isUniqueIndex() || idx->isClusteringIndex()))
- ||
- (CmpCommon::getDefault(UPDATE_CLUSTERING_OR_UNIQUE_INDEX_KEY) ==
DF_OFF))
+ // preds are in RangeSpec form
+ ValueIdSet preds = getSelectionPredicates();
+ const ValueIdList colUpdated = getTableDesc()->getColUpdated();
+ const LIST(IndexDesc *) & ixlist = getTableDesc()->getIndexes();
+
+ if ((colUpdated.entries() == 0) || (preds.entries() == 0) ||
--- End diff --
The old updateableIndex would have returned TRUE if there was no predicate
on the SET clause column. That is why I wrote the current method this way. I
agree that we are open to the halloween problem as the case you mentioned.
Since it is an existing bug I would like to address it in my next checkin which
will be in a day or two.
---
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.
---