Skip to content

Instantly share code, notes, and snippets.

@cank
Created March 16, 2012 19:14
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 cank/0c9b9b74655ddab7f820 to your computer and use it in GitHub Desktop.
Save cank/0c9b9b74655ddab7f820 to your computer and use it in GitHub Desktop.
// First query. Notice n = 6758. The second OR condition by definition includes the first.
> db.contacts.find(
... {
...
... $or: [
... {'foo': 32}
... ,{'foo': 32, 'bar' : 151629}
... ]
... }
... ).explain();
{
"cursor" : "BtreeCursor foo_1_bar_1",
"nscanned" : 6758,
"nscannedObjects" : 6758,
"n" : 6758,
"millis" : 7,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
"foo" : [
[
32,
32
]
],
"bar" : [
[
{
"$minElement" : 1
},
{
"$maxElement" : 1
}
]
]
}
}
// Second query. Notice n = 6761.
> db.contacts.find(
... {
...
... $or: [
... {'foo': 32, 'bar' : 151629},
... {'foo': 32}
... ]
... }
... ).explain();
{
"clauses" : [
{
"cursor" : "BtreeCursor foo_1_bar_1",
"nscanned" : 3,
"nscannedObjects" : 3,
"n" : 3,
"millis" : 0,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
"foo" : [
[
32,
32
]
],
"bar" : [
[
151629,
151629
]
]
}
},
{
"cursor" : "BtreeCursor foo_1_bar_1",
"nscanned" : 6758,
"nscannedObjects" : 6758,
"n" : 6755,
"millis" : 33,
"nYields" : 0,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
"foo" : [
[
32,
32
]
],
"bar" : [
[
{
"$minElement" : 1
},
{
"$maxElement" : 1
}
]
]
}
}
],
"nscanned" : 6761,
"nscannedObjects" : 6761,
"n" : 6758,
"millis" : 33
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment