Skip to content

Commit

Permalink
bail out or clause checking if we do an unpredicted table scan
Browse files Browse the repository at this point in the history
  • Loading branch information
astaple committed Jul 20, 2010
1 parent 4760c02 commit decb87e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 5 additions & 1 deletion db/queryoptimizer.cpp
Expand Up @@ -641,7 +641,8 @@ namespace mongo {
_honorRecordedPlan( honorRecordedPlan ), _honorRecordedPlan( honorRecordedPlan ),
_bestGuessOnly( bestGuessOnly ), _bestGuessOnly( bestGuessOnly ),
_hint( ( hint && !hint->eoo() ) ? hint->wrap() : BSONObj() ), _hint( ( hint && !hint->eoo() ) ? hint->wrap() : BSONObj() ),
_mayYield( mayYield ) _mayYield( mayYield ),
_tableScanned()
{ {
if ( !order.isEmpty() || !min.isEmpty() || !max.isEmpty() || !_fros.getSpecial().empty() ) { if ( !order.isEmpty() || !min.isEmpty() || !max.isEmpty() || !_fros.getSpecial().empty() ) {
_or = false; _or = false;
Expand Down Expand Up @@ -670,6 +671,9 @@ namespace mongo {
BSONElement hintElt = _hint.firstElement(); BSONElement hintElt = _hint.firstElement();
_currentQps.reset( new QueryPlanSet( _ns, frs, _query, BSONObj(), &hintElt, _honorRecordedPlan, BSONObj(), BSONObj(), _bestGuessOnly, _mayYield ) ); _currentQps.reset( new QueryPlanSet( _ns, frs, _query, BSONObj(), &hintElt, _honorRecordedPlan, BSONObj(), BSONObj(), _bestGuessOnly, _mayYield ) );
shared_ptr< QueryOp > ret( _currentQps->runOp( op ) ); shared_ptr< QueryOp > ret( _currentQps->runOp( op ) );
if ( ret->qp().willScanTable() ) {
_tableScanned = true;
}
_fros.popOrClause(); _fros.popOrClause();
return ret; return ret;
} }
Expand Down
4 changes: 3 additions & 1 deletion db/queryoptimizer.h
Expand Up @@ -55,6 +55,7 @@ namespace mongo {
shared_ptr<Cursor> newCursor( const DiskLoc &startLoc = DiskLoc() , int numWanted=0 ) const; shared_ptr<Cursor> newCursor( const DiskLoc &startLoc = DiskLoc() , int numWanted=0 ) const;
shared_ptr<Cursor> newReverseCursor() const; shared_ptr<Cursor> newReverseCursor() const;
BSONObj indexKey() const; BSONObj indexKey() const;
bool willScanTable() const { return !index_ && fbs_.matchPossible(); }
const char *ns() const { return fbs_.ns(); } const char *ns() const { return fbs_.ns(); }
NamespaceDetails *nsd() const { return d; } NamespaceDetails *nsd() const { return d; }
BSONObj originalQuery() const { return _originalQuery; } BSONObj originalQuery() const { return _originalQuery; }
Expand Down Expand Up @@ -275,7 +276,7 @@ namespace mongo {
shared_ptr< T > runOpOnce( T &op ) { shared_ptr< T > runOpOnce( T &op ) {
return dynamic_pointer_cast< T >( runOpOnce( static_cast< QueryOp& >( op ) ) ); return dynamic_pointer_cast< T >( runOpOnce( static_cast< QueryOp& >( op ) ) );
} }
bool mayRunMore() const { return _or ? !_fros.orFinished() : _i == 0; } bool mayRunMore() const { return _or ? ( !_tableScanned && !_fros.orFinished() ) : _i == 0; }
BSONObj oldExplain() const { assertNotOr(); return _currentQps->explain(); } BSONObj oldExplain() const { assertNotOr(); return _currentQps->explain(); }
// just report this when only one query op // just report this when only one query op
bool usingPrerecordedPlan() const { bool usingPrerecordedPlan() const {
Expand All @@ -298,6 +299,7 @@ namespace mongo {
bool _bestGuessOnly; bool _bestGuessOnly;
BSONObj _hint; BSONObj _hint;
bool _mayYield; bool _mayYield;
bool _tableScanned;
}; };


class MultiCursor : public Cursor { class MultiCursor : public Cursor {
Expand Down
2 changes: 1 addition & 1 deletion jstests/or9.js
Expand Up @@ -24,7 +24,7 @@ check( 1, 2, { $or: [ { a: { $gt:2,$lte:3 } }, { a: 2 } ] } );


check( 1, 1, { $or: [ { b: { $gte:1,$lte:3 } }, { b: 2 } ] } ); check( 1, 1, { $or: [ { b: { $gte:1,$lte:3 } }, { b: 2 } ] } );
check( 1, 1, { $or: [ { b: { $gte:2,$lte:3 } }, { b: 2 } ] } ); check( 1, 1, { $or: [ { b: { $gte:2,$lte:3 } }, { b: 2 } ] } );
//check( 1, 2, { $or: [ { b: { $gt:2,$lte:3 } }, { b: 2 } ] } ); check( 1, 1, { $or: [ { b: { $gt:2,$lte:3 } }, { b: 2 } ] } );


check( 1, 1, { $or: [ { a: { $gte:1,$lte:3 } }, { a: 2, b: 2 } ] } ); check( 1, 1, { $or: [ { a: { $gte:1,$lte:3 } }, { a: 2, b: 2 } ] } );
check( 1, 2, { $or: [ { a: { $gte:1,$lte:3 }, b:3 }, { a: 2 } ] } ); check( 1, 2, { $or: [ { a: { $gte:1,$lte:3 }, b:3 }, { a: 2 } ] } );
Expand Down

0 comments on commit decb87e

Please sign in to comment.