Repository: incubator-trafodion Updated Branches: refs/heads/master 156829272 -> bf6ed1b94
[TRAFODION-2813] Ignore leading salt columns when checking index compatibility Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/25e64a8f Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/25e64a8f Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/25e64a8f Branch: refs/heads/master Commit: 25e64a8fa6a0c91f9451f7b6fa10e52ac03d58c3 Parents: 19c7544 Author: Dave Birdsall <[email protected]> Authored: Mon Nov 20 23:14:29 2017 +0000 Committer: Dave Birdsall <[email protected]> Committed: Mon Nov 20 23:14:29 2017 +0000 ---------------------------------------------------------------------- core/sql/optimizer/IndexDesc.cpp | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/25e64a8f/core/sql/optimizer/IndexDesc.cpp ---------------------------------------------------------------------- diff --git a/core/sql/optimizer/IndexDesc.cpp b/core/sql/optimizer/IndexDesc.cpp index dfb9593..949308c 100644 --- a/core/sql/optimizer/IndexDesc.cpp +++ b/core/sql/optimizer/IndexDesc.cpp @@ -802,10 +802,30 @@ IndexProperty::compareIndexPromise(const IndexProperty *ixProp) const const IndexDesc * index = getIndexDesc(); const IndexDesc * otherIndex = ixProp->getIndexDesc(); - if ( ((IndexColumn *)(index->getIndexKey()[0]).getItemExpr())->getDefinition() != - ((IndexColumn *)(otherIndex->getIndexKey()[0]).getItemExpr())->getDefinition() ) - - return INCOMPATIBLE; + + // If the two indexes have differing leading columns, consider them incompatible. + // For this check, we ignore the "_SALT_" column if both are salted. + CollIndex columnToCheck = 0; + NABoolean done = FALSE; + while (!done) + { + if (columnToCheck >= index->getIndexKey().entries()) + return INCOMPATIBLE; // must be one of the indexes is just "_SALT_" (seems unlikely actually) + else if (columnToCheck >= otherIndex->getIndexKey().entries()) + return INCOMPATIBLE; // must be one of the indexes is just "_SALT_" (seems unlikely actually) + else + { + IndexColumn * indexCol = (IndexColumn *)(index->getIndexKey()[columnToCheck]).getItemExpr(); + IndexColumn * otherIndexCol = (IndexColumn *)(otherIndex->getIndexKey()[columnToCheck]).getItemExpr(); + if ( indexCol->getNAColumn()->isSaltColumn() && + otherIndexCol->getNAColumn()->isSaltColumn() ) + columnToCheck++; + else if ( indexCol->getDefinition() != otherIndexCol->getDefinition() ) + return INCOMPATIBLE; + else + done = TRUE; // leading column (ignoring "_SALT_" if both have "_SALT_") is different + } + } CostScalar myKbForLPred = index->getKbForLocalPred(); CostScalar othKbForLPred = otherIndex->getKbForLocalPred();
