[DOCS-2977] Doc behavior changes related to indexing negations such as $not and $ne Created: 24/Mar/14  Updated: 02/Apr/14  Resolved: 02/Apr/14

Status: Closed
Project: Documentation
Component/s: manual
Affects Version/s: None
Fix Version/s: v1.3.3

Type: Task Priority: Minor - P4
Reporter: David Storch Assignee: Kay Kim (Inactive)
Resolution: Done Votes: 0
Labels: sprint-slipstream
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-12532 Negate index bounds for $not instead ... Closed
is related to SERVER-13324 Sparse index is not used to filter {f... Closed
Participants:
Days since reply: 9 years, 46 weeks ago

 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.



 Comments   
Comment by Githook User [ 02/Apr/14 ]

Author:

{u'username': u'kay-kim', u'name': u'kay', u'email': u'kay.kim@10gen.com'}

Message: DOCS-2977 clarify not behavior, sparse index compatibility change
Branch: master
https://github.com/mongodb/docs/commit/ee9e1107abfdcb49dfdfbbae35c68ab8b63113e5

Generated at Thu Feb 08 07:44:42 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.