Permalink
Browse files

fix exists with index SERVER-708

  • Loading branch information...
erh committed Mar 6, 2010
1 parent 02d6682 commit da4507b7c6fb088f55a368d404e15ce349ada692
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
@@ -139,16 +139,18 @@ 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 ) {
if ( details )
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
@@ -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
@@ -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" );
+

0 comments on commit da4507b

Please sign in to comment.