void QueryProcessor:: DumpQState( QueryOutcome &qo ) { QueryOutcome::iterator qitr; KeySet::iterator kitr; int elt; printf( "\tResult:\n" ); for( qitr=qo.begin( ); qitr!=qo.end( ); qitr++ ) { printf( "\t %d: " , qitr->first ); kitr.Initialize(qitr->second); while( kitr.Next(elt) ) { printf( "%d ", elt ); } printf( "\n" ); } }
bool QueryProcessor:: DoQuery( Rectangles &window, KeySet &result ) { AllDimensions::iterator aitr; OneDimension::iterator oitr; Indexes::iterator iitr; KeySet deviantExportedSet; KeySet tmpResult; QueryOutcome qo; string demangled; DimRectangleMap::iterator ditr, daxitr; KeySet::iterator ksitr; int tmp; Rectangles *rec = summarize ? &summaries : rectangles; numQueries++; //printf( "Doing query\n" ); // Phase 0: Initialize for( int i = 0; i <= window.rId ; i++ ) { qo[i].MakeUniversal( ); } // Phase 1: Process imported intervals for( aitr=window.importedBoxes.begin( ); aitr!=window.importedBoxes.end( ); aitr++ ) { demangled.assign( aitr->first, 2, aitr->first.size( ) - 2 ); ditr = rec->unexported.find( demangled ); for( oitr=aitr->second.begin( ); oitr!=aitr->second.end( ); oitr++ ) { tmpResult.Clear( ); // include all rectangles whose constraints are satisfied if( ( iitr = exported.find( aitr->first ) ) != exported.end( ) ) { if( !iitr->second->Filter( oitr->second, tmpResult ) ) { printf( "Failed exported index lookup\n" ); return( false ); } } // include deviant exported rectangles and all rectangles // which do not constrain this attribute (if any) if( ditr == rec->unexported.end( ) ) { qo[oitr->first].IntersectWithUnionOf( tmpResult, rec->deviantExported ); } else { qo[oitr->first].IntersectWithUnionOf( tmpResult, ditr->second, rec->deviantExported ); } } } // Phase 2: Remove candidates which constrain absent attributes for(ditr=window.unimported.begin();ditr!=window.unimported.end();ditr++) { // find all rectangles which constrain this particular attribute daxitr = rec->allExported.find( ditr->first ); if( daxitr == rec->allExported.end( ) ) continue; // remove this set from the solution for each query rectangle ksitr.Initialize( ditr->second ); while( ksitr.Next( tmp ) ) { qo[tmp].Subtract( daxitr->second ); } } // Phase 3: Process exported dimensions for( aitr=window.exportedBoxes.begin( ); aitr!=window.exportedBoxes.end( ); aitr++ ) { // need to include rectangles which are deviant on this attribute demangled.assign( aitr->first, 2, aitr->first.size( ) - 2 ); ditr = rec->deviantImported.find( demangled ); for( oitr=aitr->second.begin( ); oitr!=aitr->second.end( ); oitr++ ) { tmpResult.Clear( ); // include all rectangles which satisfy this constraint if( ( iitr = imported.find( aitr->first ) ) != imported.end( ) ) { if( !iitr->second->Filter( oitr->second, tmpResult ) ) { printf( "Failed imported index lookup\n" ); return( false ); } } // check if there are relevant deviant imported rectangles if( ditr == rec->deviantImported.end( ) ) { // ... if not, just intersect with filtered results qo[oitr->first].Intersect( tmpResult ); } else { // ... otherwise, include deviant imported rectangles qo[oitr->first].IntersectWithUnionOf(ditr->second,tmpResult); } } } // Phase 4: Aggregate results for all query rectangles result.Clear( ); for( int i = 0 ; i <= window.rId ; i++ ) { result.Unify( qo[i] ); } // done return( true ); }