Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

bail out or clause checking if we do an unpredicted table scan

  • Loading branch information...
commit decb87e5b7360a963cd0ec4ea3dd7361212e45b1 1 parent 4760c02
@astaple astaple authored
Showing with 9 additions and 3 deletions.
  1. +5 −1 db/queryoptimizer.cpp
  2. +3 −1 db/queryoptimizer.h
  3. +1 −1  jstests/or9.js
View
6 db/queryoptimizer.cpp
@@ -641,7 +641,8 @@ namespace mongo {
_honorRecordedPlan( honorRecordedPlan ),
_bestGuessOnly( bestGuessOnly ),
_hint( ( hint && !hint->eoo() ) ? hint->wrap() : BSONObj() ),
- _mayYield( mayYield )
+ _mayYield( mayYield ),
+ _tableScanned()
{
if ( !order.isEmpty() || !min.isEmpty() || !max.isEmpty() || !_fros.getSpecial().empty() ) {
_or = false;
@@ -670,6 +671,9 @@ namespace mongo {
BSONElement hintElt = _hint.firstElement();
_currentQps.reset( new QueryPlanSet( _ns, frs, _query, BSONObj(), &hintElt, _honorRecordedPlan, BSONObj(), BSONObj(), _bestGuessOnly, _mayYield ) );
shared_ptr< QueryOp > ret( _currentQps->runOp( op ) );
+ if ( ret->qp().willScanTable() ) {
+ _tableScanned = true;
+ }
_fros.popOrClause();
return ret;
}
View
4 db/queryoptimizer.h
@@ -55,6 +55,7 @@ namespace mongo {
shared_ptr<Cursor> newCursor( const DiskLoc &startLoc = DiskLoc() , int numWanted=0 ) const;
shared_ptr<Cursor> newReverseCursor() const;
BSONObj indexKey() const;
+ bool willScanTable() const { return !index_ && fbs_.matchPossible(); }
const char *ns() const { return fbs_.ns(); }
NamespaceDetails *nsd() const { return d; }
BSONObj originalQuery() const { return _originalQuery; }
@@ -275,7 +276,7 @@ namespace mongo {
shared_ptr< T > runOpOnce( T &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(); }
// just report this when only one query op
bool usingPrerecordedPlan() const {
@@ -298,6 +299,7 @@ namespace mongo {
bool _bestGuessOnly;
BSONObj _hint;
bool _mayYield;
+ bool _tableScanned;
};
class MultiCursor : public Cursor {
View
2  jstests/or9.js
@@ -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: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, 2, { $or: [ { a: { $gte:1,$lte:3 }, b:3 }, { a: 2 } ] } );
Please sign in to comment.
Something went wrong with that request. Please try again.