[SERVER-9277] Ranged index bounds do not permit retrieving Infinity or -Infinity Created: 08/Apr/13  Updated: 11/Jul/16  Resolved: 04/Dec/13

Status: Closed
Project: Core Server
Component/s: Index Maintenance, Querying
Affects Version/s: None
Fix Version/s: 2.5.5

Type: Bug Priority: Major - P3
Reporter: Antonio Angelino Assignee: Benety Goh
Resolution: Done Votes: 1
Labels: query_triage
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

GNU/Linux Debian 6 x64,


Attachments: File server9277.js    
Issue Links:
Depends
depends on SERVER-11617 Sorting with value of Infinity causes... Closed
Related
is related to SERVER-984 Invalid sorting of infinity and -infi... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

Querying on an indexed field which contains Infinity and -Infinity does not produce expected results when using range predicates.

Note the upper bound on the second query is equal to max double value, which compares as less than infinity. If you do an equality search, it will use the index just fine.

Here's an example with explain output.

t = db.infinity
t.drop()
t.ensureIndex({number:1})
 
t.save({number: 3});
t.save({number: 4});
t.save({number: Infinity});
t.save({number: -Infinity});
 
t.find({"number": Infinity}).explain();
{
	"cursor" : "BtreeCursor number_1",
	"isMultiKey" : false,
	"n" : 1,
	"nscannedObjects" : 1,
	"nscanned" : 1,
	"nscannedObjectsAllPlans" : 1,
	"nscannedAllPlans" : 1,
	"scanAndOrder" : false,
	"indexOnly" : false,
	"nYields" : 0,
	"nChunkSkips" : 0,
	"millis" : 0,
	"indexBounds" : {
		"number" : [
			[
				Infinity,
				Infinity
			]
		]
	},
	"server" : "crucible-2.local:27017"
}
 
t.find({"number": {$gte: 2}}).explain())
{
	"cursor" : "BtreeCursor number_1",
	"isMultiKey" : false,
	"n" : 3,
	"nscannedObjects" : 3,
	"nscanned" : 3,
	"nscannedObjectsAllPlans" : 3,
	"nscannedAllPlans" : 3,
	"scanAndOrder" : false,
	"indexOnly" : false,
	"nYields" : 0,
	"nChunkSkips" : 0,
	"millis" : 0,
	"indexBounds" : {
		"number" : [
			[
				2,
				1.7976931348623157e+308
			]
		]
	},
	"server" : "crucible-2.local:27017"
}



 Comments   
Comment by Antonio Angelino [ 22/Apr/13 ]

Hello,

any news here?

The bug still persist and the only way to query the database and fetch the right documents is to add an or in each query instead of a simple $gte statement...
Do you have any ETA for this bug resolution?

Kind Regards,
Antonio.

Comment by Antonio Angelino [ 09/Apr/13 ]

Hello All,

if you add an index on the field, you can reproduce the issue.

db.foo.ensureIndex(

{x: 1}

)

Kind Regards,
Antonio.

Comment by Randolph Tan [ 09/Apr/13 ]

Was able to reproduce in master (commit cc155a6fb38cb8509047e772187f23bd44bb7cb4) only if you pass sort(

{ x: 1 }

) to the query. Setup: index only on _id field.

Example shell session:

> db.user.find({ x: { $gt: 0 }}).sort({ x: 1 })
{ "_id" : ObjectId("5164316b8348620d688265d1"), "x" : 1 }
> db.user.find({ x: { $gt: 0 }})
{ "_id" : ObjectId("5164316b8348620d688265d1"), "x" : 1 }
{ "_id" : ObjectId("516431a28348620d688265d4"), "x" : Infinity }
> db.user.find({ x: { $gt: -Infinity }}).sort({ x: 1 })
{ "_id" : ObjectId("516431748348620d688265d2"), "x" : -1000 }
{ "_id" : ObjectId("5164316b8348620d688265d1"), "x" : 1 }
> db.user.find({ x: { $gt: -Infinity }})
{ "_id" : ObjectId("5164316b8348620d688265d1"), "x" : 1 }
{ "_id" : ObjectId("516431748348620d688265d2"), "x" : -1000 }
{ "_id" : ObjectId("516431a28348620d688265d4"), "x" : Infinity }

Comment by Jeremy Mikola [ 09/Apr/13 ]

Antonio,

I cannot reproduce this:

$ mongo
MongoDB shell version: 2.4.1
connecting to: test
> db.foo.drop();
> db.foo.insert({x:0})
> db.foo.insert({x:1})
> db.foo.insert({x:-1})
> db.foo.insert({x:Infinity})
> db.foo.insert({x:-Infinity})
 
> db.foo.find({x:{$lte:0}})
{ "_id" : ObjectId("51642e52e895feb19421d1b6"), "x" : 0 }
{ "_id" : ObjectId("51642e58e895feb19421d1b8"), "x" : -1 }
{ "_id" : ObjectId("51642e5ee895feb19421d1ba"), "x" : -Infinity }
 
> db.foo.find({x:{$gte:0}})
{ "_id" : ObjectId("51642e52e895feb19421d1b6"), "x" : 0 }
{ "_id" : ObjectId("51642e57e895feb19421d1b7"), "x" : 1 }
{ "_id" : ObjectId("51642e5ce895feb19421d1b9"), "x" : Infinity }
 
> db.foo.find({x:{$lt:0}})
{ "_id" : ObjectId("51642e58e895feb19421d1b8"), "x" : -1 }
{ "_id" : ObjectId("51642e5ee895feb19421d1ba"), "x" : -Infinity }
 
> db.foo.find({x:{$gt:0}})
{ "_id" : ObjectId("51642e57e895feb19421d1b7"), "x" : 1 }
{ "_id" : ObjectId("51642e5ce895feb19421d1b9"), "x" : Infinity }
 
> db.foo.find({x:{$lt:-1}})
{ "_id" : ObjectId("51642e5ee895feb19421d1ba"), "x" : -Infinity }
 
> db.foo.find({x:{$gt:1}})
{ "_id" : ObjectId("51642e5ce895feb19421d1b9"), "x" : Infinity }

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