Exemplo n.º 1
0
// change literals of a cacheable query into ConstantParameters and save
// true root into cachewa so we can "bind" ConstantParameters as "inputvars"
RelExpr* RelRoot::normalizeForCache(CacheWA& cwa, BindWA& bindWA)
{
  if (nodeIsNormalizedForCache()) { 
    return this; 
  }
  if (isTrueRoot()) { 
    cwa.setTopRoot(this); 
  }
  if (cwa.getPhase() >= CmpMain::BIND) {
    // replace any select list literals into constant parameters
    if (compExprTree_) {
      compExprTree_ = compExprTree_->normalizeForCache(cwa, bindWA);
    }
    else {
      compExpr_.normalizeForCache(cwa, bindWA);
    }
  }
  // replace descendants' literals into ConstantParameters
  RelExpr *result = RelExpr::normalizeForCache(cwa, bindWA);
  if (cwa.getPhase() >= CmpMain::BIND) {
    // query tree has undergone BINDing, but RelExpr::normalizeForCache
    // may have introduced new ConstantParameters in place of ConstValues;
    // we want to BIND these new ConstantParameters but a RelRoot::bindNode()
    // call here would be overkill; we just want these new ConstantParameters
    // to be "bound" as "inputvars"; so, we selectively cut and paste code
    // from BindRelExpr.cpp RelRoot::bindNode into here to "bind" any new 
    // ConstantParameters as "inputvars".
    ItemExpr *inputVarTree = removeInputVarTree();
    if (inputVarTree) {
      inputVarTree->convertToValueIdList(inputVars(), &bindWA, ITM_ITEM_LIST);
      if (bindWA.errStatus()) {
        return NULL;
      }
    }
  }
  return result;
}