//*****************************************************************************
//*****************************************************************************
NABoolean MVCandidate::CheckAnExtraHubTable(const NAString*      tableID, 
					    QRJoinSubGraphMapPtr mvSubGraphMap,
					    QRJoinSubGraphMapPtr querySubGraphMap,
					    NABoolean&		 extraHubTableWasAdded)
{
  QRJoinSubGraphPtr mvSubGraph    = mvSubGraphMap->getSubGraph();
  QRJoinSubGraphPtr querySubGraph = querySubGraphMap->getSubGraph();

  const QRTablePtr queryTableElement = 
    getQueryDetails()->getElementForID(*tableID)->downCastToQRTable();
  const JoinGraphTablePtr queryGraphTable = 
    querySubGraph->getParentGraph()->getTableByID(queryTableElement->getID());

  // If this extra-hub table is not directly connected to the rest of 
  // the subgraph, skip it for now.
  if (queryGraphTable->isConnectedTo(querySubGraph) == FALSE)
  {
    // Add additional needed extra-hub tables here...

    return TRUE;
  }

  // Find the corresponding MV table
  const QRTablePtr mvTableElement = getMvDetails()->getTableFromName(queryTableElement->getTableName());
  const JoinGraphTablePtr mvGraphTable = 
    mvSubGraph->getParentGraph()->getTableByID(mvTableElement->getID());

  if (matchPredsFromTableToSubGraph(mvSubGraph, 
				    querySubGraph, 
				    mvGraphTable, 
				    queryGraphTable) == FALSE)
  {
    // Match failed.
    // Release the sandbox subgraphs and disqualify the MVCandidate.
    deletePtr(mvSubGraphMap);
    deletePtr(querySubGraphMap);
    logMVWasDisqualified1("Extra hub table %s is needed but cannot be matched.", 
			  queryTableElement->getTableName().data());
    return FALSE;
  }

  // Add the table to both MV and query subgraphs.
  querySubGraph->addTable(queryGraphTable);
  mvSubGraph->addTable(mvGraphTable);

  // To make sure that Pass 2 matching and result desxcriptor generation will 
  // work correctly, add the tables to the SubGraphMaps (they will have the same index).
  CollIndex index = querySubGraph->entries();
  querySubGraphMap->addTable(index, queryGraphTable);
  mvSubGraphMap->addTable(index, mvGraphTable);

  // We are done with this table, remove it from the list.
  extraHubTables_.remove(tableID);

  extraHubTableWasAdded = TRUE;
  QRLogger::log(CAT_MVCAND, LL_DEBUG,
    "ExtraHub table %s was matched for MV %s.",
  	        queryTableElement->getTableName().data(),
  	        mvDetails_->getMVName().data());

  return TRUE;
}  // MVCandidate::CheckAnExtraHubTable()