void MVCandidatesForJBBSubset::setSubGraphMap(QRJoinSubGraphMapPtr querySubGraphMap) { querySubGraphMap_ = querySubGraphMap; // Mark that this subGraph is being used for rewrite instructions, so that // it will not be deleted when the HubIterator is deleted. querySubGraphMap->getSubGraph()->setStillUsed(TRUE); }
//***************************************************************************** //***************************************************************************** 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()
NABoolean MVCandidate::CheckExtraHubTables() { if (extraHubTables_.entries() == 0) return TRUE; // Allocate a new subGraph and subGraphMap for the MV - the one we have is from MVMemo, // so its considered read-only. QRJoinSubGraphMapPtr mvSubGraphMap = new(heap_) QRJoinSubGraphMap(*getMvSubGraphMap(), ADD_MEMCHECK_ARGS(heap_)); // The query subGraph is shared between the MVCandidates that were found // in the same MVMemo group, so work on a copy. QRJoinSubGraphMapPtr querySubGraphMap = new(heap_) QRJoinSubGraphMap(*getJbbSubset()->getQuerySubGraphMap(), ADD_MEMCHECK_ARGS(heap_)); // Loop over the list, each time picking an extra-hub table that is // directly connected to a table already in the matched sub-graph, // until all the tables are checked. do { NABoolean extraHubTableWasAdded = FALSE; // Do the loop backwards because we remove checked extra-hub tables from the list. for (Int32 i=(CollIndex)extraHubTables_.entries()-1; i>=0; i--) { if (CheckAnExtraHubTable(extraHubTables_[i], mvSubGraphMap, // IN/OUT querySubGraphMap, // IN/OUT extraHubTableWasAdded) == FALSE) return FALSE; } // for // Keep looping as long as there are extra-hub tables that are not connected, // and as long as we keep adding them. if (!extraHubTableWasAdded && extraHubTables_.entries() > 0) { logMVWasDisqualified1("Extra hub table %s is needed but cannot be matched.", extraHubTables_[0]->data()); return FALSE; } // assertLogAndThrow(extraHubTableWasAdded, QRLogicException, // "Extra-hub table is not connected to the hub."); } while (extraHubTables_.entries() > 0); // Update the MV new subGraphMap mvSubGraphMap_ = mvSubGraphMap; // We have added at least one extra-hub table - // now we need to reorg the JBBSubsets accordingly. MVCandidatesForJBBPtr jbb = getJbbSubset()->getJbbCandidates(); MVCandidatesForJBBSubsetPtr newJbbSubset = NULL; QRJoinSubGraphPtr querySubGraph = querySubGraphMap->getSubGraph(); if (jbb->contains(querySubGraph)) { // The JBBSubset with the new extra-hub tables already exists. newJbbSubset = jbb->getJbbSubsetFor(querySubGraph); } else { // Need to create a new JBBSubset. newJbbSubset = new (heap_) MVCandidatesForJBBSubset(jbb, ADD_MEMCHECK_ARGS(heap_)); newJbbSubset->setSubGraphMap(querySubGraphMap); // Add the new JbbSubset to the JBB. jbb->insert(newJbbSubset); } // Move the candidate from the current JbbSubset to the new one. getJbbSubset()->remove(this); newJbbSubset->insert(this); setJbbSubset(newJbbSubset); return TRUE; } // CheckExtraHubTables()