[SERVER-279] Multi-key indexes with empty arrays may cause incorrect results on queries that don't use the full index Created: 04/Sep/09  Updated: 12/Jul/16  Resolved: 08/Oct/09

Status: Closed
Project: Core Server
Component/s: Index Maintenance
Affects Version/s: 1.0.0
Fix Version/s: 1.1.2

Type: Bug Priority: Major - P3
Reporter: Frank Swiderski Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Any, git hash 644df81d2167628a7a9494a1953f981d148ebfbb


Issue Links:
Depends
depends on SERVER-146 arrays don't match themselves Closed
Participants:

 Description   

If you create a multi-key index that has documents omitted because they have null values or empty arrays, mongo may return incorrect results on other queries that attempt to use part of that index. The query planner will use a multi-key index (take, for example, an index with keys: k0, k1) if you run a query that matches part of the index (for example, searching on k0). However, if some documents are missing because criteria unrelated to the current query causes them to be excluded from the index (for example, where k1 is an array, and the document has an empty array), then searching just on the partial index will not return all documents that should have matched.

Repro follows:

MongoDB shell version: 1.1.0-
url: testdb
connecting to: 127.0.0.1:27001/testdb
type "help" for help
> db.party.save(

{id:1,info:[],str:"hi"}

);
> db.party.save(

{id:1,info:["foo"],str:"hi"}

);
> db.party.find(

{id:1,str:"hi"}

);

{"_id" : ObjectId( "4aa09b10fce2291061418fb1") , "id" : 1 , "info" : [] , "str" : "hi"} {"_id" : ObjectId( "4aa09b1bfce2291061418fb2") , "id" : 1 , "info" : ["foo"] , "str" : "hi"}

> db.party.ensureIndex(

{id:1,info:1}

);
true
> db.party.find(

{id:1,str:"hi"}

);

{"_id" : ObjectId( "4aa09b1bfce2291061418fb2") , "id" : 1 , "info" : ["foo"] , "str" : "hi"}

> db.party.dropIndexes();

{"nIndexesWas" : 2 , "msg" : "all indexes deleted for collection" , "ok" : 1}

> db.party.ensureIndex(

{id:1}

);
true
> db.party.find(

{id:1,str:"hi"}

);

{"_id" : ObjectId( "4aa09b10fce2291061418fb1") , "id" : 1 , "info" : [] , "str" : "hi"} {"_id" : ObjectId( "4aa09b1bfce2291061418fb2") , "id" : 1 , "info" : ["foo"] , "str" : "hi"}

 Comments   
Comment by Eliot Horowitz (Inactive) [ 16/Oct/09 ]

release 10/16/2009

Comment by Eliot Horowitz (Inactive) [ 07/Oct/09 ]

added a specific test jstests/multi2.js

Comment by Eliot Horowitz (Inactive) [ 06/Sep/09 ]


I think this will go away once SERVER-146 is fixed, but not totally sure.

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