[SERVER-13434] Record does not seem to be indexed correctly Created: 01/Apr/14  Updated: 10/Dec/14  Resolved: 01/Apr/14

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 2.2.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Ian Martin Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

I have a record in my database but it doesn't seem to be indexed correctly.
I have a compound index
{
"v" : 1,
"key" :

{ "device" : 1, "time" : -1 }

,
"ns" : "loco.history",
"name" : "device_1_time_-1"
},

and this is used to run the query.

locobase:SECONDARY> db.history.find({device:357207050859404,"time":{"$gt":start,"$lt":end}}).explain()
{
"cursor" : "BtreeCursor device_1_time_-1",
"isMultiKey" : false,
"n" : 19,
"nscannedObjects" : 19,
"nscanned" : 19,
"nscannedObjectsAllPlans" : 19,
"nscannedAllPlans" : 19,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 0,
"indexBounds" :

{ "device" : [ [ 357207050859404, 357207050859404 ] ], "time" : [ [ ISODate("2015-04-01T00:00:00Z"), ISODate("2010-04-01T00:00:00Z") ] ] }

,
"server" : "uk4.loco-pos.net:27017"
}

note: there are 19 items found

but if I give a hint to not use the time field in the index I get

locobase:SECONDARY> db.history.find({device:357207050859404,"time":{"$gt":start,"$lt":end}}).hint(

{device:1}

).explain()
{
"cursor" : "BtreeCursor device_1",
"isMultiKey" : false,
"n" : 19,
"nscannedObjects" : 20,
"nscanned" : 20,
"nscannedObjectsAllPlans" : 20,
"nscannedAllPlans" : 20,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 0,
"indexBounds" :

{ "device" : [ [ 357207050859404, 357207050859404 ] ] }

,
"server" : "uk4.loco-pos.net:27017"
}

now there are 20 items.

The missing item has
locobase:SECONDARY> db.history.findOne({_id:ObjectId("533a8bf3d6e909b3c29e6e38")}).time
ISODate("2014-04-01T09:50:43.487Z")

as far as I know, There are no other records with this problem and everything else seems normal.
I realise 2.2.2 is quite old but this may still be relevant.



 Comments   
Comment by Ian Martin [ 01/Apr/14 ]

Oh Yes,
I think I probably just saw what I was expecting to see there because.

locobase:SECONDARY> db.history.find({device:357207050859404,"time":{"$gt":start,"$lt":end}}).count()
20
locobase:SECONDARY> db.history.find(

{device:357207050859404}

).count()
21

however, I have a record without a time field which would explain that.

I am still seeing fewer records from my java program though but that problem must be elsewhere.
I'll make sure I have my java driver up to date and test it again.

Sorry for the misleading report.

Comment by Andy Schwerin [ 01/Apr/14 ]

Both plans return 19 results (n: 19). The first plan uses the more selective index to only examine the 19 matching documents, while the second plan uses the less selective index to visit the 20 documents matching the device component of the query, and then filters out the one of those 20 documents that does not match the time bounds. Can you confirm the values of the "start" and "end" times you're using?

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