Github user zellerh commented on a diff in the pull request:
https://github.com/apache/incubator-trafodion/pull/380#discussion_r56226976
--- Diff: core/sql/optimizer/BindRelExpr.cpp ---
@@ -10171,17 +10164,26 @@ matched clause of merge). If the upsert caused a
row to be updated in the
base table then the old version of the row will have to be deleted from
indexes, and a new version inserted. Upsert is being transformed to merge
so that we can delete the old version of an updated row from the index.
+
+Upsert is also converted into merge when there are omitted cols with
default values and
+TRAF_UPSERT_WITH_INSERT_DEFAULT_SEMANTICS is set to OFF in case of
aligned format table or
+omitted current timestamp cols in case of non-aligned row format
*/
-NABoolean Insert::isUpsertThatNeedsMerge() const
+NABoolean Insert::isUpsertThatNeedsMerge(NABoolean isAlignedRowFormat,
NABoolean omittedDefaultCols,
+ NABoolean
omittedCurrentDefaultClassCols) const
{
- if (!isUpsert() || getIsTrafLoadPrep() ||
- (getTableDesc()->isIdentityColumnGeneratedAlways() &&
- getTableDesc()->hasIdentityColumnInClusteringKey()) ||
- getTableDesc()->getClusteringIndex()->getNAFileSet()->hasSyskey() ||
- !(getTableDesc()->hasSecondaryIndexes()))
- return FALSE;
-
- return TRUE;
+ if (isUpsert() &&
+ (NOT getIsTrafLoadPrep()) &&
+ (NOT (getTableDesc()->isIdentityColumnGeneratedAlways() &&
getTableDesc()->hasIdentityColumnInClusteringKey())) &&
+ (NOT
(getTableDesc()->getClusteringIndex()->getNAFileSet()->hasSyskey())) &&
+ ((getTableDesc()->hasSecondaryIndexes()) ||
--- End diff --
The indentation isn't correct on this line, it should start at the same
space as the previous line. I find this if condition very hard to read. Here is
a formatted version, the only change is indentation and comments:
if ( // problem only happens for upsert
isUpsert() &&
( // load prep avoids the problem by having its only index update
logic
NOT getIsTrafLoadPrep()) &&
( // with identity columns in the clustering key we never update
existing rows
NOT (getTableDesc()->isIdentityColumnGeneratedAlways() &&
getTableDesc()->hasIdentityColumnInClusteringKey())) &&
( // same with SYSKEY, we never update existing rows
NOT
(getTableDesc()->getClusteringIndex()->getNAFileSet()->hasSyskey())) &&
( // problem only occurs if we have secondary indexes...
getTableDesc()->hasSecondaryIndexes() ||
( // ...or we omit "current" default columns in a non-aligned
format
( NOT isAlignedRowFormat) && omittedCurrentDefaultClassCols) ||
( // ...or we omit any default column in aligned format and the
override CQD is not set
(isAlignedRowFormat && omittedDefaultCols
&&
(CmpCommon::getDefault(TRAF_UPSERT_WITH_INSERT_DEFAULT_SEMANTICS) == DF_OFF)))
)
)
---
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.
---