I feel like questions about indexOnly have been beaten to death on these forums / the internet, but after searching I wasn't able to find any info. See this question on SO from July (I'm not the original asker, but there hasn't been an answer):
In my case, a query that's very quick, and index only locally, is not so through MongoS. Maybe this is a limitation of MongoS I'm not aware of, or just a bug in the explain and I'm missing something?
Note: I redacted some info (server names, ids, etc), if I mis-named something, my bad, but the queries both run, etc.
The shard key for the below queries is {userId, event}
Thanks!
Here's the query:
db.entities.find({userId: "blahblah"}, {userId: 1, _id: 0}).explain()
Here's the explain directly against mongo:
{
"cursor" : "BtreeCursor userId_1_event_1",
"isMultiKey" : false,
"n" : 147132,
"nscannedObjects" : 0,
"nscanned" : 147132,
"nscannedObjectsAllPlans" : 0,
"nscannedAllPlans" : 147233,
"scanAndOrder" : false,
"indexOnly" : true,
"nYields" : 1156,
"nChunkSkips" : 0,
"millis" : 2129,
"indexBounds" : {
"userId" : [
[
"blahblah",
"blahblah"
]
],
"event" : [
[
{
"$minElement" : 1
},
{
"$maxElement" : 1
}
]
]
},
"server" : "server_2:36000",
"filterSet" : false
}
Here's the explain through mongos:
mongos>
{
"clusteredType" : "ParallelSort",
"shards" : {
"shard_0/server_1:36000,server_2:36000,server_3:36000" : [
{
"cursor" : "BtreeCursor userId_1_event_1",
"isMultiKey" : false,
"n" : 147132,
"nscannedObjects" : 147132,
"nscanned" : 147132,
"nscannedObjectsAllPlans" : 147233,
"nscannedAllPlans" : 147233,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 12170,
"nChunkSkips" : 0,
"millis" : 372554,
"indexBounds" : {
"userId" : [
[
"blahblah",
"blahblah"
]
],
"event" : [
[
{
"$minElement" : 1
},
{
"$maxElement" : 1
}
]
]
},
"server" : "server_2:36000",
"filterSet" : false
}
]
},
"cursor" : "BtreeCursor userId_1_event_1",
"n" : 147132,
"nChunkSkips" : 0,
"nYields" : 12170,
"nscanned" : 147132,
"nscannedAllPlans" : 147233,
"nscannedObjects" : 147132,
"nscannedObjectsAllPlans" : 147233,
"millisShardTotal" : 372554,
"millisShardAvg" : 372554,
"numQueries" : 1,
"numShards" : 1,
"indexBounds" : {
"connectionId" : [
[
"blahblah",
"blahblah"
]
],
"event" : [
[
{
"$minElement" : 1
},
{
"$maxElement" : 1
}
]
]
},
"millis" : 372556
}