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

    https://github.com/apache/incubator-trafodion/pull/132#discussion_r42520005
  
    --- Diff: core/sql/optimizer/ValueDesc.cpp ---
    @@ -6397,3 +6400,111 @@ Lng32 ValueIdList::findPrefixLength(const 
ValueIdSet& x) const
       return ct;
     }
     
    +// -----------------------------------------------------------------------
    +// replace any ColReference (of the given column name) in of this value
    +// expression with the given expression.
    +// used in ValueId::computeEncodedKey() to assign key values into the
    +// salt/DivisionByto expression.
    +// ----------------------------------------------------------------------
    +void ValueId::replaceColReferenceWithExpr(const NAString& colName,
    +                                          const ValueId & vid)
    +{
    +  ItemExpr* thisItemExpr = getItemExpr();
    +  for( Lng32 i = 0; i < thisItemExpr->getArity(); i++ )
    +  {
    +    ValueId childValueId = thisItemExpr->child(i).getValueId();
    +    ItemExpr* childItemExpr = childValueId.getItemExpr();
    +
    +    if( childItemExpr->getOperatorType() == ITM_REFERENCE)
    +    {
    +      if( ((ColReference*)childItemExpr)->getColRefNameObj().getColName() 
== colName )
    +        thisItemExpr->setChild( i, vid.getItemExpr() );
    +    }
    +    childValueId.replaceColReferenceWithExpr( colName, vid );
    +  }
    +}
    +
    +
    +char*
    +ValueIdList::computeEncodedKey(const TableDesc* tDesc, NABoolean isMaxKey, 
    +                               char*& encodedKeyBuffer, Int32& keyBufLen) 
const
    +{
    +   const NATable*  naTable = tDesc->getNATable();
    +
    +
    +   CollIndex count = entries();
    +   NAString** inputStrings = new (STMTHEAP) NAStringPtr[count];
    +
    +   for (Int32 j=0; j<count; j++ ) 
    +       inputStrings[j] = NULL;
    +
    +   for (Int32 j=0; j<count; j++ ) {
    +
    +      ValueId vid = (*this)[j];
    +      ItemExpr* ie = vid.getItemExpr();
    +
    +      if ( ie->getOperatorType() != ITM_CONSTANT ) {
    +          ConstValue* value = ie->compute(STMTHEAP);
    +          if ( !value )
    +             return NULL;
    +
    +          inputStrings[j] = new (STMTHEAP) 
NAString(value->getConstStr(FALSE));
    --- End diff --
    
    As so often in the compiler we go through complicated paths to get to our 
goal, here we already have the binary value, then make it into a string, then 
make it back into a binary in encodeKeyValues below. Just an observation, I 
don't have a better solution. I wonder whether we should use this compute() 
method and ItemExpr::doesExprEvaluateToConstant() in ItemExpr::foldConstants() 
to make that method better. Again, just a thought, not a suggestion to change 
anything right now, but if we did that, we could just use constantFold() in 
this method.


---
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.
---

Reply via email to