Details
-
Task
-
Status: Closed
-
Minor - P4
-
Resolution: Fixed
-
None
-
4
-
true
Description
There have been a few behavior changes in v2.6 related to negations. These should probably go into the 2.6 release notes? See SERVER-13324 and SERVER-12532 or come talk to me for details.
1) In 2.4 it is possible to get different results for negations depending on whether or not an indexed plan is used:
> t.drop()
|
true
|
> t.save({a: 1})
|
> t.save({b: 1})
|
> t.find({a: {$not: {$gt: 3}}})
|
{ "_id" : ObjectId("5330803029b74d493d375e46"), "a" : 1 }
|
{ "_id" : ObjectId("5330803529b74d493d375e47"), "b" : 1 }
|
> t.ensureIndex({a: 1})
|
> t.find({a: {$not: {$gt: 3}}})
|
{ "_id" : ObjectId("5330803029b74d493d375e46"), "a" : 1 }
|
In 2.6, the results will always be the same regardless of whether or not there is an index:
> t.drop()
|
true
|
> t.save({a: 1})
|
WriteResult({ "nInserted" : 1 })
|
> t.save({b: 1})
|
WriteResult({ "nInserted" : 1 })
|
> t.find({a: {$not: {$gt: 3}}})
|
{ "_id" : ObjectId("5330808b3a40985f27706d1e"), "a" : 1 }
|
{ "_id" : ObjectId("5330808d3a40985f27706d1f"), "b" : 1 }
|
> t.ensureIndex({a: 1})
|
{
|
"createdCollectionAutomatically" : false,
|
"numIndexesBefore" : 1,
|
"numIndexesAfter" : 2,
|
"ok" : 1
|
}
|
> t.find({a: {$not: {$gt: 3}}})
|
{ "_id" : ObjectId("5330808d3a40985f27706d1f"), "b" : 1 }
|
{ "_id" : ObjectId("5330808b3a40985f27706d1e"), "a" : 1 }
|
2) Negation predicates will no longer use sparse indices. This is necessary in order to preserve the invariant from (1), namely that a negation query should return the same results for indexed and unindexed plans. See SERVER-13324.
Attachments
Issue Links
- is related to
-
SERVER-12532 Negate index bounds for $not instead of defaulting to a collection scan
-
- Closed
-
-
SERVER-13324 Sparse index is not used to filter {field: {$ne: null}} queries
-
- Closed
-