|
The [MULTI_ITERATOR] stage used as part of $sample execution reports all zeros in place of real execution stats:
MongoDB Enterprise > db.c.drop()
|
false
|
MongoDB Enterprise > for (let i = 0; i < 1000; i++) { db.c.insert({_id: i}); }
|
WriteResult({ "nInserted" : 1 })
|
MongoDB Enterprise > db.c.explain(true).aggregate([{$sample: {size: 10}}])
|
{
|
"stages" : [
|
{
|
"$cursor" : {
|
"query" : {
|
|
},
|
"queryPlanner" : {
|
"plannerVersion" : 1,
|
"namespace" : "test.c",
|
"indexFilterSet" : false,
|
"winningPlan" : {
|
"stage" : "MULTI_ITERATOR"
|
},
|
"rejectedPlans" : [ ]
|
},
|
"executionStats" : {
|
"executionSuccess" : true,
|
"nReturned" : 0,
|
"executionTimeMillis" : 43,
|
"totalKeysExamined" : 0,
|
"totalDocsExamined" : 0,
|
"executionStages" : {
|
"stage" : "MULTI_ITERATOR",
|
"nReturned" : 0,
|
"executionTimeMillisEstimate" : 0,
|
"works" : 0,
|
"advanced" : 0,
|
"needTime" : 0,
|
"needYield" : 0,
|
"saveState" : 0,
|
"restoreState" : 0,
|
"isEOF" : 0,
|
"invalidates" : 0
|
},
|
"allPlansExecution" : [ ]
|
}
|
}
|
},
|
{
|
"$sampleFromRandomCursor" : {
|
"size" : NumberLong(10)
|
}
|
}
|
],
|
"ok" : 1
|
}
|
Notice that the counts ("works", "advanced", "nReturned", etc.) associated with MULTI_ITERATOR in the "executionStats" section are all zeros. This is a reporting issue in the server; the query clearly returns results when run without explain:
MongoDB Enterprise > db.c.aggregate([{$sample: {size: 10}}])
|
{ "_id" : 266 }
|
{ "_id" : 789 }
|
{ "_id" : 999 }
|
{ "_id" : 987 }
|
{ "_id" : 685 }
|
{ "_id" : 979 }
|
{ "_id" : 633 }
|
{ "_id" : 484 }
|
{ "_id" : 847 }
|
{ "_id" : 22 }
|
It looks like the issue is that MultiIterator::getStats() is not implemented correctly.
|