Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit a61f143e2f2276ce21c288aad23ae00559944af9 1 parent 0fabb0e
astaple authored August 30, 2010
1  db/matcher.h
@@ -240,6 +240,7 @@ namespace mongo {
240 240
         shared_ptr< Matcher > _docMatcher;
241 241
         Matcher _keyMatcher;
242 242
         bool _needRecord;
  243
+        bool _useRecordOnly;
243 244
     };
244 245
     
245 246
 } // namespace mongo
18  db/matcher_covered.cpp
@@ -49,9 +49,9 @@ namespace mongo {
49 49
         _needRecord = 
50 50
         alwaysUseRecord || 
51 51
         ! ( _docMatcher->keyMatch() && 
52  
-           _keyMatcher.sameCriteriaCount( *_docMatcher ) &&
53  
-           ! _keyMatcher.hasType( BSONObj::opEXISTS ) );
  52
+           _keyMatcher.sameCriteriaCount( *_docMatcher ) );
54 53
         ;        
  54
+        _useRecordOnly = _keyMatcher.hasType( BSONObj::opEXISTS );
55 55
     }
56 56
     
57 57
     bool CoveredIndexMatcher::matchesCurrent( Cursor * cursor , MatchDetails * details ){
@@ -62,12 +62,16 @@ namespace mongo {
62 62
         if ( details )
63 63
             details->reset();
64 64
         
65  
-        if ( !_keyMatcher.matches(key, details ) ){
66  
-            return false;
67  
-        }
  65
+        if ( !_useRecordOnly ) {
  66
+            
  67
+            if ( !_keyMatcher.matches(key, details ) ){
  68
+                return false;
  69
+            }
68 70
         
69  
-        if ( ! _needRecord ){
70  
-            return true;
  71
+            if ( ! _needRecord ){
  72
+                return true;
  73
+            }
  74
+            
71 75
         }
72 76
 
73 77
         if ( details )
3  jstests/exists.js
@@ -25,7 +25,7 @@ function dotest( n ){
25 25
     assert.eq( 3, t.count( {'a.b': {$exists:true}} ) , n );
26 26
     assert.eq( 2, t.count( {'a.b.c': {$exists:true}} ) , n );
27 27
     assert.eq( 1, t.count( {'a.b.c.d': {$exists:true}} ) , n );
28  
-    
  28
+
29 29
     assert.eq( 1, t.count( {a: {$exists:false}} ) , n );
30 30
     assert.eq( 2, t.count( {'a.b': {$exists:false}} ) , n );
31 31
     assert.eq( 3, t.count( {'a.b.c': {$exists:false}} ) , n );
@@ -38,6 +38,7 @@ t.ensureIndex( { "a.b" : 1 } )
38 38
 t.ensureIndex( { "a.b.c" : 1 } )
39 39
 t.ensureIndex( { "a.b.c.d" : 1 } )
40 40
 dotest( "after index" )
  41
+assert.eq( 1, t.find( {a: {$exists:false}} ).hint( {a:1} ).itcount() );
41 42
     
42 43
 t.drop();
43 44
 

0 notes on commit a61f143

Please sign in to comment.
Something went wrong with that request. Please try again.