Thanks for the reply. Ofcourse I tried them a multiple times to ensure the query is coming from memory, so got very consistent results. Here are the explains after a few warmups:
This is through mongos:
mongos> db.testcol2.find({field1: {$gte: 0}},{field1:1,_id:0}).explain();
{
"clusteredType" : "ParallelSort",
"shards" : {
{
"cursor" : "BtreeCursor field1_1",
"isMultiKey" : false,
"n" : 5000000,
"nscannedObjects" : 5000000,
"nscanned" : 5000000,
"nscannedObjectsAllPlans" : 5000000,
"nscannedAllPlans" : 5000000,
"scanAndOrder" : false,
"indexOnly" : true,
"nYields" : 10,
"nChunkSkips" : 0,
"millis" : 10706,
"indexBounds" : {
"field1" : [
[
0,
1.7976931348623157e+308
]
]
},
"server" : "jvangaalen-PC:27020"
}
]
},
"cursor" : "BtreeCursor field1_1",
"n" : 5000000,
"nChunkSkips" : 0,
"nYields" : 10,
"nscanned" : 5000000,
"nscannedAllPlans" : 5000000,
"nscannedObjects" : 5000000,
"nscannedObjectsAllPlans" : 5000000,
"millisShardTotal" : 10706,
"millisShardAvg" : 10706,
"numQueries" : 1,
"numShards" : 1,
"indexBounds" : {
"field1" : [
[
0,
1.7976931348623157e+308
]
]
},
"millis" : 10708
}
Directly on mongod (same machine, same set):
> db.testcol2.find({field1: {$gte: 0}},{field1:1,_id:0}).explain();
{
"cursor" : "BtreeCursor field1_1",
"isMultiKey" : false,
"n" : 5000000,
"nscannedObjects" : 0,
"nscanned" : 5000000,
"nscannedObjectsAllPlans" : 0,
"nscannedAllPlans" : 5000000,
"scanAndOrder" : false,
"indexOnly" : true,
"nYields" : 6,
"nChunkSkips" : 0,
"millis" : 4629,
"indexBounds" : {
"field1" : [
[
0,
1.7976931348623157e+308
]
]
},
"server" : "jvangaalen-PC:27020"
}
I guess the unexpected thing here is, that is is an indexonly query, but still has all documents as nscanneddocuments on the shard. I would expect 0 here. I've read somewhere that on a shard it has the check the document to ensure it is in the proper chunk. Anyway, another very unexpected result is when I do an indexonly false query on the mongod directly, the response times got even significantly better, even when it has to scan every document:
> db.testcol2.find({field1: {$gte: 0}},{field1:1,_id:1}).explain();
{
"cursor" : "BtreeCursor field1_1",
"isMultiKey" : false,
"n" : 5000000,
"nscannedObjects" : 5000000,
"nscanned" : 5000000,
"nscannedObjectsAllPlans" : 5000000,
"nscannedAllPlans" : 5000000,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 3,
"nChunkSkips" : 0,
"millis" : 3669,
"indexBounds" : {
"field1" : [
[
0,
1.7976931348623157e+308
]
]
},
"server" : "jvangaalen-PC:27020"
}
Response time down from 4629 to 3669. More than 20% difference, as I would expect the opposite,
Perhaps this enlighten things