diff options
author | Aaron <aaron@10gen.com> | 2012-10-14 20:48:04 -0700 |
---|---|---|
committer | Aaron <aaron@10gen.com> | 2012-10-23 16:36:58 -0700 |
commit | 87204cc9de8578fff716ef1b0bb0b707a0b2d04a (patch) | |
tree | 5fdd911b5ee18268ec856fdb953118a120d91c73 /jstests | |
parent | c0355ccbf0a3e242fe2db1427989bcd22311ac4c (diff) | |
download | mongo-87204cc9de8578fff716ef1b0bb0b707a0b2d04a.tar.gz |
SERVER-1752 SERVER-4529 Do not incorrectly use fast count mode when matching against a null value.
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/indexy.js | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/jstests/indexy.js b/jstests/indexy.js index 3f52f16590d..def63743785 100644 --- a/jstests/indexy.js +++ b/jstests/indexy.js @@ -1,16 +1,35 @@ -// Test count matching when null key is generated even though it should not be matched in a standard query. SERVER-4529 +// Null index keys may be generated for documents that do not match null. In particular, for index +// { 'a.c':1 } the document { a:[ {}, { c:10 } ] } generates index keys { '':null } and { '':10 }. +// While the query { a:{ $elemMatch:{ c:null } } } has been designated to match this document, the +// query { 'a.c':null } has been designated to not match this document. +// +// Because the above and similar queries do not match the document but do match documents lacking +// any 'a.c' field (which also generate a { '':null } key), a Matcher is required when it is +// necessary to select matching documents for these queries. As a result, the fast count in which +// the matcher is bypassed (SERVER-1752) cannot be used for such queries. The following tests check +// that the count is calculated correctly in cases where fast count mode should not be applied. +// +// SERVER-4529 t = db.jstests_indexy; t.drop(); -t.save({a:[{},{c:10}]}); +function assertNoMatch( query ) { + // Check that no results are returned by a find. + assert.eq( 0, t.find( query ).itcount() ); + // Check that no results are counted by a count. + assert.eq( 0, t.find( query ).count() ); +} -assert.eq( 0, t.find({'a.c':null}).itcount() ); -assert.eq( 0, t.find({'a.c':null}).count() ); +t.save({a:[{},{c:10}]}); +assertNoMatch( { 'a.c':null } ); t.ensureIndex({'a.c':1}); - -assert.eq( 0, t.find({'a.c':null}).itcount() ); -if( 0 ) { // SERVER-4529 -assert.eq( 0, t.find({'a.c':null}).count() ); -} +// No equality match against null. +assertNoMatch( { 'a.c':null } ); +// No $in match against null. +assertNoMatch( { 'a.c':{ $in:[ null ] } } ); +assertNoMatch( { 'a.c':{ $in:[ null, 1 ] } } ); +// No match for a query generating the field range [[ minkey, {} ]], which includes the value null, +// on the field 'a.c'. +assertNoMatch( { 'a.c':{ $lt:{} } } ); |