[SERVER-13986] Creating a sparse index makes the not equals query to return diferent results. Created: 19/May/14  Updated: 11/Jul/16  Resolved: 19/May/14

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.4.10
Fix Version/s: 2.6.0

Type: Bug Priority: Minor - P4
Reporter: David Martin-Borregon Assignee: hari.khalsa@10gen.com
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-12684 incorrect result and index not used f... Closed
is related to SERVER-13324 Sparse index is not used to filter {f... Closed
is related to SERVER-13939 Unexpected behavior of query planner ... Closed
Operating System: ALL
Steps To Reproduce:

in python:

import pymongo
conn = pymongo.MongoClient()
db = conn['spare-test']
col = db['spare-test']
col.drop()
col.insert(

{'_id':0}

)
col.insert(

{'_id':1, 'val':1}

)
col.insert(

{'_id':2, 'val':2}

)
col.insert(

{'_id':3, 'val':3}

)
print col.find({'val':{'$ne':2}}).count()
col.ensure_index([('val',1)], sparse=True)
print col.find({'val':{'$ne':2}}).count()

Participants:

 Description   

The documentationhttp://docs.mongodb.org/manual/reference/operator/query/ne/ descrive the '$ne' function as:

$ne selects the documents where the value of the field is not equal (i.e. !=) to the specified value. This includes documents that do not contain the field.

However this becames is false when the queried value have an sparse index.

I can workarround but is a extrange behaivour when you don't expect it.



 Comments   
Comment by David Storch [ 19/May/14 ]

For more information, see the docs here: http://docs.mongodb.org/master/core/index-sparse/#sparse-index-incomplete-results. Or, see related tickets SERVER-13324, SERVER-13939, and SERVER-12684.

Comment by hari.khalsa@10gen.com [ 19/May/14 ]

This was fixed in 2.6 and was a known issue in 2.4.x. Negations do not use sparse indices in 2.6.

Generated at Thu Feb 08 03:33:30 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.