const BaseTableDetailsPtr MVCandidate::getQueryTableForMvID(const NAString& id, NABoolean assertOnFailure)
{
  QRJoinSubGraphMapPtr mvMap = getMvSubGraphMap();
  if (!mvMap->contains(id))
  {
    if (assertOnFailure)
    {
      assertLogAndThrow(CAT_MVCAND, LL_MVQR_FAIL,
                        FALSE, QRLogicException, 
			"Matching Query table not found in JoinGraphMap.");
    }
    return NULL;    
  }
  Int32 hashKeyIndex = mvMap->getIndexForTable(id);
  if (hashKeyIndex == -1)
  {
    assertLogAndThrow(CAT_MVCAND, LL_MVQR_FAIL,
                      assertOnFailure, QRLogicException, 
		      "Matching Query table not found in JoinGraphMap.");
    return NULL;
  }

  const JoinGraphTablePtr queryTable = getQuerySubGraphMap()->getTableForIndex(hashKeyIndex);
  if (queryTable == NULL)
  {
    assertLogAndThrow(CAT_MVCAND, LL_MVQR_FAIL,
                      assertOnFailure, QRLogicException, 
		      "Matching Query table not found in JoinGraphMap.");
    return NULL;
  }

  return queryTable->getBaseTable();
}