[SERVER-31932] The existence of index affects the type of projection field. Created: 13/Nov/17  Updated: 07/Dec/17  Resolved: 13/Nov/17

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 3.4.10
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Itzhak Kagan Assignee: Mark Agarunov
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 2012 (64 bit), windows 7 sp1 (64 bit)


Attachments: Zip Archive appTasks.zip    
Issue Links:
Duplicate
duplicates SERVER-5580 covered indexes are improperly applie... Closed
Operating System: ALL
Steps To Reproduce:

Unzip the appTasks.zip -> appTasks.json
Import the appTasks.json file:

mongoimport -h localhost:27017 -u <user> -p <password> --authenticationDatabase <db> -d test -c appTasks --drop --file appTasks.json

Enter the data base with mongo shell.

run the query:

db.appTasks.find({ "taskState" : 1, "isFolderLocking" : true, "affectedFolders" : { "$in" : [NumberLong("1000000000000114891")] } },{"affectedFolders":1, "_id":0})

The result is:

{ "affectedFolders" : [ NumberLong("1000000000000114891") ] }

This result is correct because the field 'affectedFolders' is an array of int64.

create the following index:

db.appTasks.createIndex({"taskState":1, "isFolderLocking":1, "affectedFolders":1})

run the query again:

db.appTasks.createIndex({"taskState":1, "isFolderLocking":1, "affectedFolders":1})

The result is:

{ "affectedFolders" : NumberLong("1000000000000114891") }

This result is incorrect because the returned type is int64 instead of an array of int64.

Participants:

 Description   

A field that is an array of int64 is projected as int64 if an index that include the field exists.



 Comments   
Comment by Mark Agarunov [ 13/Nov/17 ]

Hello itzikkg,

Thank you for the report. Looking over the behavior described, I believe this behavior is due to the same underlying cause as the behavior described in SERVER-5580 where the index is not marked as multikey when all arrays are singletons, so I've closed this ticket as a duplicate. Fortunately, this is fixed in the upcoming version 3.6 release, which I verified on 3.6.0-rc3 with the dataset you provided:

> db.appTasks.find({ "taskState" : 1, "isFolderLocking" : true, "affectedFolders" : { "$in" : [NumberLong("1000000000000114891")] } },{"affectedFolders":1, "_id":0})
{ "affectedFolders" : [ NumberLong("1000000000000114891") ] }
> db.appTasks.createIndex({"taskState":1, "isFolderLocking":1, "affectedFolders":1})
{
	"createdCollectionAutomatically" : false,
	"numIndexesBefore" : 1,
	"numIndexesAfter" : 2,
	"ok" : 1
}
> db.appTasks.find({ "taskState" : 1, "isFolderLocking" : true, "affectedFolders" : { "$in" : [NumberLong("1000000000000114891")] } },{"affectedFolders":1, "_id":0})
{ "affectedFolders" : [ NumberLong("1000000000000114891") ] }

Thanks,
Mark

Generated at Thu Feb 08 04:28:38 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.