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

    https://github.com/apache/trafodion/pull/1414#discussion_r163895532
  
    --- Diff: core/sql/optimizer/OptPhysRelExpr.cpp ---
    @@ -15499,6 +15499,95 @@ GenericUtilExpr::synthPhysicalProperty(const 
Context* myContext,
       return sppForMe;
     } //  GenericUtilExpr::synthPhysicalProperty()
     
    +// -----------------------------------------------------------------------
    +// FirstN::createContextForAChild()
    +// The FirstN node may have an order by requirement that it needs to
    +// pass to its child context. Other than that, this method is quite
    +// similar to the default implementation, RelExpr::createContextForAChild.
    +// The arity of FirstN is always 1, so some logic from the default
    +// implementation that deals with childIndex > 0 is unnecessary and has
    +// been removed.
    +// -----------------------------------------------------------------------
    +Context * FirstN::createContextForAChild(Context* myContext,
    +                                 PlanWorkSpace* pws,
    +                                 Lng32& childIndex)
    +{
    +  const ReqdPhysicalProperty* rppForMe =
    +                                    myContext->getReqdPhysicalProperty();
    +
    +  CMPASSERT(getArity() == 1);
    +
    +  childIndex = getArity() - pws->getCountOfChildContexts() - 1;
    +
    +  // return if we are done
    +  if (childIndex < 0)
    +    return NULL;
    +
    +  RequirementGenerator rg(child(childIndex), rppForMe);
    +
    +  if (reqdOrder().entries() > 0)
    +    {
    +      // replace our sort requirement with that implied by our ORDER BY 
clause
    +
    +      rg.removeSortKey();
    +
    +      ValueIdList sortKey;
    +      sortKey.insert(reqdOrder());
    +
    +      // Shouldn't/Can't add a sort order type requirement
    +      // if we are in DP2
    +      if (rppForMe->executeInDP2())
    +        rg.addSortKey(sortKey,NO_SOT);
    +      else
    +        rg.addSortKey(sortKey,ESP_SOT);
    +    }
    +
    +  if (NOT pws->isEmpty())
    --- End diff --
    
    I don't think we need this code (line 15545 - 15559). We already returned 
from this method if pws contains previous contexts (line 15524), so this if 
condition should never be true.


---

Reply via email to