Github user DaveBirdsall commented on a diff in the pull request:

    
https://github.com/apache/incubator-trafodion/pull/1306#discussion_r152352674
  
    --- Diff: 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() )
    --- End diff --
    
    It depends. Suppose the DIVISION BY clause is on C. Should we think of ix1 
as an index on C, A or just on A? If I have a query, select c from table where 
c = value, then ix1 and ix2 are compatible for that query. Today, 
IndexProperty::compareIndexPromise doesn't take the select predicates into 
account; it is just looking for the "best" index on C. (And on A. And on B.)


---

Reply via email to