Skip to content

Instantly share code, notes, and snippets.

@scottburton11
Created March 1, 2011 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottburton11/849632 to your computer and use it in GitHub Desktop.
Save scottburton11/849632 to your computer and use it in GitHub Desktop.
MongoDB indexed range query slower?
> db.ip_blocks.find({start_address: {$lte: 1665637698}, end_address: {$gte: 1665637698}}).explain()
{
"cursor" : "BasicCursor",
"nscanned" : 3662284,
"nscannedObjects" : 3662284,
"n" : 1,
"millis" : 2645,
"indexBounds" : {
}
}
> db.ip_blocks.ensureIndex({start_address: -1, end_address: 1})
> db.ip_blocks.find({start_address: {$lte: 1665637698}, end_address: {$gte: 1665637698}}).hint({start_address: -1, end_address: 1}).explain()
{
"cursor" : "BtreeCursor start_address_-1_end_address_1",
"nscanned" : 1,
"nscannedObjects" : 1,
"n" : 1,
"millis" : 4336,
"indexBounds" : {
"start_address" : [
[
1665637698,
-1.7976931348623157e+308
]
],
"end_address" : [
[
1665637698,
1.7976931348623157e+308
]
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment