//*****************************************************************************
// thisSubgraph and otherSubGraph are equivalent subgraphs (from the MV and
// query join graphs). This method checks if they will continue to match
// if an extra-hub table is added. It checks that ALL predicates connecting 
// this table to the subgraph match those of the other table/subgraph.
// The assumption is that this is the MV table/subgraph, while the other 
// is the query table/subgraph, so the query can have additional join
// predicates over those in the MV. Those extra predicates are returned as 
// rewrite instructions.
//*****************************************************************************
NABoolean MVCandidate::matchPredsFromTableToSubGraph(const QRJoinSubGraphPtr mvSubGraph,
						     const QRJoinSubGraphPtr querySubGraph, 
						     const JoinGraphTablePtr mvGraphTable,
						     const JoinGraphTablePtr queryGraphTable)
{
  // For each join pred on this table
  CollIndex maxEntries = mvGraphTable->getEqualitySets().entries();
  for (CollIndex i=0; i<maxEntries; i++)
  {
    // Find the column its using
    const JoinGraphEqualitySetPtr mvEqSet = mvGraphTable->getEqualitySets()[i];
    const JoinGraphHalfPredicatePtr mvHalfPred = mvEqSet->findHalfPredTo(mvGraphTable);

    // Get the corresponding eqSet from the other join graph
    const JoinGraphEqualitySetPtr queryEqSet = queryGraphTable->getEqSetUsing(mvHalfPred);
    if (queryEqSet == NULL)
    {
      // Corresponding eqSet not found - match failed.
      return FALSE;
    }

    // Verify that the half-pred to the EQ set matches.
    const JoinGraphHalfPredicatePtr queryHalfPred = queryEqSet->findHalfPredTo(queryGraphTable);
    if (mvHalfPred->match(queryHalfPred) == FALSE)
      return FALSE;

    // Let the JoinPredMatching object continue with the matching from the EQ set to the subgraph.
    if (matchPredsFromEQSetToSubGraph(mvSubGraph, 
      				      querySubGraph, 
				      mvEqSet, 
				      queryEqSet,
				      mvHalfPred->getID()) == FALSE)
      return FALSE;
  }

  return TRUE;
}  // matchPredsFromTableToSubGraph()