Permalink
Browse files

$ operator and indexed fields SERVER-1055

  • Loading branch information...
1 parent 4a40ae3 commit 4ea65d35986af7bdafdca7cc9ec6a67b24e63bf5 @erh erh committed May 10, 2010
Showing with 21 additions and 19 deletions.
  1. +2 −2 db/matcher.h
  2. +7 −6 db/matcher_covered.cpp
  3. +5 −4 db/update.cpp
  4. +7 −7 jstests/update_arraymatch4.js
View
@@ -199,12 +199,12 @@ namespace mongo {
// If match succeeds on index key, then attempt to match full document.
class CoveredIndexMatcher : boost::noncopyable {
public:
- CoveredIndexMatcher(const BSONObj &pattern, const BSONObj &indexKeyPattern);
+ CoveredIndexMatcher(const BSONObj &pattern, const BSONObj &indexKeyPattern , bool alwaysUseRecord=false );
bool matches(const BSONObj &o){ return _docMatcher.matches( o ); }
bool matches(const BSONObj &key, const DiskLoc &recLoc , MatchDetails * details = 0 );
bool matchesCurrent( Cursor * cursor , MatchDetails * details = 0 );
bool needRecord(){ return _needRecord; }
-
+
Matcher& docMatcher() { return _docMatcher; }
private:
Matcher _keyMatcher;
View
@@ -31,16 +31,17 @@
namespace mongo {
- CoveredIndexMatcher::CoveredIndexMatcher(const BSONObj &jsobj, const BSONObj &indexKeyPattern) :
+ CoveredIndexMatcher::CoveredIndexMatcher(const BSONObj &jsobj, const BSONObj &indexKeyPattern, bool alwaysUseRecord) :
_keyMatcher(jsobj.filterFieldsUndotted(indexKeyPattern, true),
indexKeyPattern),
_docMatcher(jsobj)
{
- _needRecord = ! (
- _docMatcher.keyMatch() &&
- _keyMatcher.jsobj.nFields() == _docMatcher.jsobj.nFields() &&
- ! _keyMatcher.hasType( BSONObj::opEXISTS )
- );
+ _needRecord =
+ alwaysUseRecord ||
+ ! ( _docMatcher.keyMatch() &&
+ _keyMatcher.jsobj.nFields() == _docMatcher.jsobj.nFields() &&
+ ! _keyMatcher.hasType( BSONObj::opEXISTS ) );
+ ;
}
View
@@ -679,14 +679,14 @@ namespace mongo {
class UpdateOp : public QueryOp {
public:
- UpdateOp() : _nscanned() {}
+ UpdateOp( bool hasPositionalField ) : _nscanned(), _hasPositionalField( hasPositionalField ){}
virtual void init() {
BSONObj pattern = qp().query();
_c = qp().newCursor();
if ( ! _c->ok() )
setComplete();
else
- _matcher.reset( new CoveredIndexMatcher( pattern, qp().indexKey() ) );
+ _matcher.reset( new CoveredIndexMatcher( pattern, qp().indexKey() , _hasPositionalField ) );
}
virtual void next() {
if ( ! _c->ok() ) {
@@ -710,7 +710,7 @@ namespace mongo {
virtual bool mayRecordPlan() const { return false; }
virtual QueryOp *clone() const {
- return new UpdateOp();
+ return new UpdateOp( _hasPositionalField );
}
shared_ptr< Cursor > c() { return _c; }
@@ -720,6 +720,7 @@ namespace mongo {
private:
shared_ptr< Cursor > _c;
long long _nscanned;
+ bool _hasPositionalField;
auto_ptr< CoveredIndexMatcher > _matcher;
MatchDetails _details;
};
@@ -756,7 +757,7 @@ namespace mongo {
set<DiskLoc> seenObjects;
QueryPlanSet qps( ns, patternOrig, BSONObj() );
- UpdateOp original;
+ UpdateOp original( mods.get() && mods->hasDynamicArray() );
shared_ptr< UpdateOp > u = qps.runOp( original );
massert( 10401 , u->exceptionMessage(), u->complete() );
@@ -2,17 +2,17 @@
t = db.update_arraymatch4
t.drop()
-x = { _id : 1 , cast : ["John","Hugh","Halle"] , movie:"Swordfish" }
+x = { _id : 1 , arr : ["A1","B1","C1"] }
t.insert( x )
assert.eq( x , t.findOne() , "A1" )
-x.cast[0] = "John Travolta"
-t.update( { cast : "John" } , { $set : { "cast.$" : "John Travolta" } } )
+x.arr[0] = "A2"
+t.update( { arr : "A1" } , { $set : { "arr.$" : "A2" } } )
assert.eq( x , t.findOne() , "A2" )
-t.ensureIndex( { cast : 1 } )
-x.cast[0] = "xxx"
-t.update( { cast : "John Travolta" } , { $set : { "cast.$" : "xxx" } } )
-//assert.eq( x , t.findOne() , "A3" ); // SERVER-1055
+t.ensureIndex( { arr : 1 } )
+x.arr[0] = "A3"
+t.update( { arr : "A2" } , { $set : { "arr.$" : "A3" } } )
+assert.eq( x , t.findOne() , "A3" ); // SERVER-1055

0 comments on commit 4ea65d3

Please sign in to comment.