[SERVER-14915] Inconsistent query result for documents when an index for field it doesn't have is used Created: 15/Aug/14  Updated: 10/Dec/14  Resolved: 18/Aug/14

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

Type: Bug Priority: Major - P3
Reporter: Randolph Tan 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   

In the sample session below, the document will be returned if you queried using the full range, but if you split the query into 2 parts, you will never get the document as part of the result.

> db.user.insert({ y: 1 });
> db.user.ensureIndex({ x: 1 });
> db.user.find({ x: { $gte: MinKey, $lt: MaxKey }})
{ "_id" : ObjectId("53ee2d5188dc69e2793b705b"), "y" : 1 }
> db.user.find({ x: { $gte: 0, $lt: MaxKey }})
> db.user.find({ x: { $gte: MinKey, $lt: 0 }})
> db.user.find({ x: { $gte: MinKey, $lt: MaxKey }}).explain()
{
	"cursor" : "BtreeCursor x_1",
	"isMultiKey" : false,
	"n" : 1,
	"nscannedObjects" : 1,
	"nscanned" : 1,
	"nscannedObjectsAllPlans" : 1,
	"nscannedAllPlans" : 1,
	"scanAndOrder" : false,
	"indexOnly" : false,
	"nYields" : 0,
	"nChunkSkips" : 0,
	"millis" : 0,
	"indexBounds" : {
		"x" : [
			[
				{
					"$minElement" : 1
				},
				{
					"$maxElement" : 1
				}
			]
		]
	},
	"server" : "ren-desktop:27017"
}
> db.user.find({ x: { $gte: MinKey, $lt: 0 }}).explain()
{
	"cursor" : "BtreeCursor x_1",
	"isMultiKey" : false,
	"n" : 0,
	"nscannedObjects" : 0,
	"nscanned" : 0,
	"nscannedObjectsAllPlans" : 0,
	"nscannedAllPlans" : 0,
	"scanAndOrder" : false,
	"indexOnly" : false,
	"nYields" : 0,
	"nChunkSkips" : 0,
	"millis" : 0,
	"indexBounds" : {
		"x" : [
			[
				-Infinity,
				0
			]
		]
	},
	"server" : "ren-desktop:27017"
}
> db.user.find({ x: { $gte: 0, $lt: MaxKey }}).explain()
{
	"cursor" : "BtreeCursor x_1",
	"isMultiKey" : false,
	"n" : 0,
	"nscannedObjects" : 0,
	"nscanned" : 0,
	"nscannedObjectsAllPlans" : 0,
	"nscannedAllPlans" : 0,
	"scanAndOrder" : false,
	"indexOnly" : false,
	"nYields" : 0,
	"nChunkSkips" : 0,
	"millis" : 0,
	"indexBounds" : {
		"x" : [
			[
				0,
				Infinity
			]
		]
	},
	"server" : "ren-desktop:27017"
}



 Comments   
Comment by J Rassi [ 15/Aug/14 ]

I believe this is per design. Query predicates of the form {field: {$gt: <numeric>}} (or $lt/$gte/$lte) are only satisfied by documents where "field" has a numeric type.

Comment by J Rassi [ 15/Aug/14 ]

renctan, what server version was used in the posted session from the description?

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