Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix exists with index SERVER-708

  • Loading branch information...
commit da4507b7c6fb088f55a368d404e15ce349ada692 1 parent 02d6682
@erh erh authored
Showing with 26 additions and 2 deletions.
  1. +11 −2 db/matcher.cpp
  2. +1 −0  db/matcher.h
  3. +14 −0 jstests/exists2.js
View
13 db/matcher.cpp
@@ -139,8 +139,10 @@ namespace mongo {
{
_needRecord = ! (
_docMatcher.keyMatch() &&
- _keyMatcher.jsobj.nFields() == _docMatcher.jsobj.nFields()
+ _keyMatcher.jsobj.nFields() == _docMatcher.jsobj.nFields() &&
+ ! _keyMatcher.hasType( BSONObj::opEXISTS )
);
+
}
bool CoveredIndexMatcher::matches(const BSONObj &key, const DiskLoc &recLoc , MatchDetails * details ) {
@@ -148,7 +150,7 @@ namespace mongo {
details->reset();
if ( _keyMatcher.keyMatch() ) {
- if ( !_keyMatcher.matches(key) ) {
+ if ( !_keyMatcher.matches(key, details ) ){
return false;
}
}
@@ -710,6 +712,13 @@ namespace mongo {
return true;
}
+ bool Matcher::hasType( BSONObj::MatchType type ) const {
+ for ( unsigned i=0; i<basics.size() ; i++ )
+ if ( basics[i].compareOp == type )
+ return true;
+ return false;
+ }
+
struct JSObj1 js1;
#pragma pack(1)
View
1  db/matcher.h
@@ -140,6 +140,7 @@ namespace mongo {
bool atomic() const { return _atomic; }
+ bool hasType( BSONObj::MatchType type ) const;
private:
void addBasic(const BSONElement &e, int c, bool isNot) {
// TODO May want to selectively ignore these element types based on op type.
View
14 jstests/exists2.js
@@ -0,0 +1,14 @@
+
+t = db.exists2;
+t.drop();
+
+t.save( { a : 1 , b : 1 } )
+t.save( { a : 1 , b : 1 , c : 1 } )
+
+assert.eq( 2 , t.find().itcount() , "A1" );
+assert.eq( 2 , t.find( { a : 1 , b : 1 } ).itcount() , "A2" );
+assert.eq( 1 , t.find( { a : 1 , b : 1 , c : { "$exists" : true } } ).itcount() , "A3" );
+
+t.ensureIndex( { a : 1 , b : 1 , c : 1 } )
+assert.eq( 1 , t.find( { a : 1 , b : 1 , c : { "$exists" : true } } ).itcount() , "B1" );
+
Please sign in to comment.
Something went wrong with that request. Please try again.