[SERVER-1943] adding an index returns different results when their is an empty array Created: 14/Oct/10  Updated: 12/Jul/16  Resolved: 01/Aug/11

Status: Closed
Project: Core Server
Component/s: Index Maintenance
Affects Version/s: 1.6.2
Fix Version/s: 1.9.2

Type: Bug Priority: Major - P3
Reporter: Alvin Richards (Inactive) Assignee: Aaron Staple
Resolution: Done Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by SERVER-3375 key generation fixes master ticket Closed
Operating System: ALL
Participants:

 Description   

Problem:
A different number of documents are returned if an array is indexed or not.

Reproduce:

> db.perm.save(

{ what : "1", permissions : [ "perm-access-help" ] }

)
> db.perm.save(

{ what : "2", permissions : [ "perm-access-admin-area" ] }

)
> db.perm.save(

{ what : "3", permissions : [ "perm-access-admin-area","perm-access-help" ] }

)
> db.perm.save(

{ what : "4", permissions : [ ] }

)
> db.perm.save(

{ what : "5" }

)

Query with out the index, returns four documents
> db.perm.find( { permissions :

{ $in:["perm-access-help", "perm-access-admin-area", null] }

} )

{ "_id" : ObjectId("4cb64a7540292d4539c3ceeb"), "what" : "1", "permissions" : [ "perm-access-help" ] } { "_id" : ObjectId("4cb64a8040292d4539c3ceec"), "what" : "2", "permissions" : [ "perm-access-admin-area" ] } { "_id" : ObjectId("4cb64a8b40292d4539c3ceed"), "what" : "3", "permissions" : [ "perm-access-admin-area", "perm-access-help" ] } { "_id" : ObjectId("4cb64aa140292d4539c3ceef"), "what" : "5" }

Adding the index returns 5 documents
> db.perm.ensureIndex(

{permissions : 1}

)
> db.perm.find( { permissions :

{ $in:["perm-access-help", "perm-access-admin-area", null] }

} )

{ "_id" : ObjectId("4cb64a9940292d4539c3ceee"), "what" : "4", "permissions" : [ ] } { "_id" : ObjectId("4cb64aa140292d4539c3ceef"), "what" : "5" } { "_id" : ObjectId("4cb64a8040292d4539c3ceec"), "what" : "2", "permissions" : [ "perm-access-admin-area" ] } { "_id" : ObjectId("4cb64a8b40292d4539c3ceed"), "what" : "3", "permissions" : [ "perm-access-admin-area", "perm-access-help" ] } { "_id" : ObjectId("4cb64a7540292d4539c3ceeb"), "what" : "1", "permissions" : [ "perm-access-help" ] }

Business Case:

  • reliability
    The behavior of the query should not change depending on whether an index is present or not.


 Comments   
Comment by auto [ 31/Jul/11 ]

Author:

{u'login': u'astaple', u'name': u'Aaron', u'email': u'aaron@10gen.com'}

Message: SERVER-1943 test key ordering for empty arrays
Branch: master
https://github.com/mongodb/mongo/commit/0141015c83c0fc70f5bb40c55ed62e21aab0cfb7

Comment by auto [ 31/Jul/11 ]

Author:

{u'login': u'astaple', u'name': u'Aaron', u'email': u'aaron@10gen.com'}

Message: SERVER-1943 test
Branch: master
https://github.com/mongodb/mongo/commit/e44abd016d702c43519f2efc091c6a4ca0707994

Comment by auto [ 25/Mar/11 ]

Author:

{u'login': u'astaple', u'name': u'Aaron', u'email': u'aaron@10gen.com'}

Message: SERVER-2343 SERVER-1943 test
https://github.com/mongodb/mongo/commit/02162fa52bccc9314aed2a7f78caee78149d7d7f

Generated at Thu Feb 08 02:58:31 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.