virtual bool advance() { if ( _takeover ) { return _takeover->advance(); } // Ok to advance if currOp in an error state due to failed yield recovery. // This may be the case when advance() is called by recoverFromYield(). if ( !( _currOp && _currOp->error() ) && !ok() ) { return false; } _currOp = 0; shared_ptr<QueryOp> op = _mps->nextOp(); rethrowOnError( op ); QueryOptimizerCursorOp *qocop = dynamic_cast<QueryOptimizerCursorOp*>( op.get() ); if ( !op->complete() ) { // 'qocop' will be valid until we call _mps->nextOp() again. _currOp = qocop; } else if ( op->stopRequested() ) { if ( qocop->cursor() ) { _takeover.reset( new MultiCursor( _mps, qocop->cursor(), op->matcher( qocop->cursor() ), *op, _nscanned - qocop->cursor()->nscanned() ) ); } } return ok(); }
void QueryOptimizerCursorImpl::init( bool explain ) { _mps->initialRunner( _originalRunner ); if ( explain ) { _explainQueryInfo = _mps->generateExplainInfo(); } shared_ptr<QueryPlanRunner> runner = _mps->nextRunner(); rethrowOnError( runner ); if ( !runner->complete() ) { _currRunner = runner.get(); } }
QueryOptimizerCursor( auto_ptr<MultiPlanScanner> &mps ) : _mps( mps ), _originalOp( new QueryOptimizerCursorOp( _nscanned ) ), _currOp(), _nscanned() { _mps->initialOp( _originalOp ); shared_ptr<QueryOp> op = _mps->nextOp(); rethrowOnError( op ); if ( !op->complete() ) { _currOp = dynamic_cast<QueryOptimizerCursorOp*>( op.get() ); } }
bool QueryOptimizerCursorImpl::_advance( bool force ) { if ( _takeover ) { return _takeover->advance(); } if ( !force && !ok() ) { return false; } _currRunner = 0; shared_ptr<QueryPlanRunner> runner = _mps->nextRunner(); rethrowOnError( runner ); if ( !runner->complete() ) { // The 'runner' will be valid until we call _mps->nextOp() again. We return 'current' // values from this op. _currRunner = runner.get(); } else if ( runner->stopRequested() ) { if ( runner->cursor() ) { _takeover.reset( new MultiCursor( _mps, runner->cursor(), runner->queryPlan().matcher(), runner->explainInfo(), *runner, _nscanned - runner->cursor()->nscanned() ) ); } } else { if ( _initialCandidatePlans.hybridPlanSet() ) { _completePlanOfHybridSetScanAndOrderRequired = runner->queryPlan().scanAndOrderRequired(); } } return ok(); }