Permalink
Browse files

SERVER-1701 don't use index key to resolve exists query

  • Loading branch information...
astaple committed Aug 30, 2010
1 parent 0fabb0e commit a61f143e2f2276ce21c288aad23ae00559944af9
Showing with 14 additions and 8 deletions.
  1. +1 −0 db/matcher.h
  2. +11 −7 db/matcher_covered.cpp
  3. +2 −1 jstests/exists.js
View
@@ -240,6 +240,7 @@ namespace mongo {
shared_ptr< Matcher > _docMatcher;
Matcher _keyMatcher;
bool _needRecord;
+ bool _useRecordOnly;
};
} // namespace mongo
View
@@ -49,9 +49,9 @@ namespace mongo {
_needRecord =
alwaysUseRecord ||
! ( _docMatcher->keyMatch() &&
- _keyMatcher.sameCriteriaCount( *_docMatcher ) &&
- ! _keyMatcher.hasType( BSONObj::opEXISTS ) );
+ _keyMatcher.sameCriteriaCount( *_docMatcher ) );
;
+ _useRecordOnly = _keyMatcher.hasType( BSONObj::opEXISTS );
}
bool CoveredIndexMatcher::matchesCurrent( Cursor * cursor , MatchDetails * details ){
@@ -62,12 +62,16 @@ namespace mongo {
if ( details )
details->reset();
- if ( !_keyMatcher.matches(key, details ) ){
- return false;
- }
+ if ( !_useRecordOnly ) {
+
+ if ( !_keyMatcher.matches(key, details ) ){
+ return false;
+ }
- if ( ! _needRecord ){
- return true;
+ if ( ! _needRecord ){
+ return true;
+ }
+
}
if ( details )
View
@@ -25,7 +25,7 @@ function dotest( n ){
assert.eq( 3, t.count( {'a.b': {$exists:true}} ) , n );
assert.eq( 2, t.count( {'a.b.c': {$exists:true}} ) , n );
assert.eq( 1, t.count( {'a.b.c.d': {$exists:true}} ) , n );
-
+
assert.eq( 1, t.count( {a: {$exists:false}} ) , n );
assert.eq( 2, t.count( {'a.b': {$exists:false}} ) , n );
assert.eq( 3, t.count( {'a.b.c': {$exists:false}} ) , n );
@@ -38,6 +38,7 @@ t.ensureIndex( { "a.b" : 1 } )
t.ensureIndex( { "a.b.c" : 1 } )
t.ensureIndex( { "a.b.c.d" : 1 } )
dotest( "after index" )
+assert.eq( 1, t.find( {a: {$exists:false}} ).hint( {a:1} ).itcount() );
t.drop();

0 comments on commit a61f143

Please sign in to comment.