mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
SERVER-109 optimize useless or
This commit is contained in:
parent
ed7cfda35f
commit
d4256a4c9b
@ -595,6 +595,9 @@ namespace mongo {
|
||||
if ( !order.isEmpty() || ( hint && !hint->eoo() ) || !min.isEmpty() || !max.isEmpty() ) {
|
||||
_or = false;
|
||||
}
|
||||
if ( _or && _fros.uselessOr() ) {
|
||||
_or = false;
|
||||
}
|
||||
if ( !_or ) {
|
||||
auto_ptr< FieldRangeSet > frs( new FieldRangeSet( ns, _query ) );
|
||||
_currentQps.reset( new QueryPlanSet( ns, frs, _query, order, hint, honorRecordedPlan, min, max ) );
|
||||
|
@ -654,6 +654,24 @@ namespace mongo {
|
||||
}
|
||||
}
|
||||
|
||||
bool FieldRangeOrSet::uselessOr() const {
|
||||
for( list< FieldRangeSet >::const_iterator i = _orSets.begin(); i != _orSets.end(); ++i ) {
|
||||
bool useful = false;
|
||||
NamespaceDetails::IndexIterator j = nsdetails( _baseSet.ns() )->ii();
|
||||
while( j.more() ) {
|
||||
IndexDetails &id = j.next();
|
||||
if ( id.getSpec().suitability( i->simplifiedQuery(), BSONObj() ) != USELESS ) {
|
||||
useful = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( !useful ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
FieldRange *FieldRangeSet::trivialRange_ = 0;
|
||||
FieldRange &FieldRangeSet::trivialRange() {
|
||||
if ( trivialRange_ == 0 )
|
||||
|
@ -233,15 +233,8 @@ namespace mongo {
|
||||
class FieldRangeOrSet {
|
||||
public:
|
||||
FieldRangeOrSet( const char *ns, const BSONObj &query , bool optimize=true );
|
||||
// if there's a trivial or clause, we won't use or ranges to help with scanning
|
||||
// bool trivialOr() const {
|
||||
// for( list< FieldRangeSet >::const_iterator i = _orSets.begin(); i != _orSets.end(); ++i ) {
|
||||
// if ( i->nNontrivialRanges() == 0 ) {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
// if there's a useless or clause, we won't use or ranges to help with scanning
|
||||
bool uselessOr() const;
|
||||
bool orFinished() const { return _orFound && _orSets.empty(); }
|
||||
// removes first or clause, and removes the field ranges it covers from all subsequent or clauses
|
||||
// this could invalidate the result of the last topFrs()
|
||||
|
8
jstests/or5.js
Normal file
8
jstests/or5.js
Normal file
@ -0,0 +1,8 @@
|
||||
t = db.jstests_or5;
|
||||
t.drop();
|
||||
|
||||
t.ensureIndex( {a:1} );
|
||||
t.ensureIndex( {b:1} );
|
||||
|
||||
assert.eq.automsg( "'BasicCursor'", "t.find( {$or:[{a:2},{b:3},{}]} ).explain().cursor" );
|
||||
assert.eq.automsg( "'BasicCursor'", "t.find( {$or:[{a:2},{b:3},{c:4}]} ).explain().cursor" );
|
@ -462,6 +462,7 @@
|
||||
938E639B110FC66900A8760A /* auth1.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = auth1.js; sourceTree = "<group>"; };
|
||||
938E63D0110FC96B00A8760A /* auth2.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = auth2.js; sourceTree = "<group>"; };
|
||||
9391C9DD1120F9D300292B19 /* newcollection.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = newcollection.js; sourceTree = "<group>"; };
|
||||
939691B411BD61450069E3E5 /* or5.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = or5.js; sourceTree = "<group>"; };
|
||||
93A13A210F4620A500AF1B0D /* commands.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = commands.cpp; sourceTree = "<group>"; };
|
||||
93A13A230F4620A500AF1B0D /* config.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = config.cpp; sourceTree = "<group>"; };
|
||||
93A13A240F4620A500AF1B0D /* config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = "<group>"; };
|
||||
@ -815,6 +816,7 @@
|
||||
934BEB9A10DFFA9600178102 /* jstests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
939691B411BD61450069E3E5 /* or5.js */,
|
||||
932D854611AB912B002749FB /* array_match1.js */,
|
||||
932D854711AB912B002749FB /* capped5.js */,
|
||||
932D854811AB912B002749FB /* datasize2.js */,
|
||||
|
Loading…
Reference in New Issue
Block a user