|
Example:
db.c.find({}, {easyToOptimize: {$add: [1,2]}}).explain()
|
The explain output shows an unoptimized projection:
"queryPlanner" : {
|
"plannerVersion" : 1,
|
"namespace" : "test.c",
|
"indexFilterSet" : false,
|
"parsedQuery" : {
|
|
},
|
"queryHash" : "27732203",
|
"planCacheKey" : "27732203",
|
"winningPlan" : {
|
"stage" : "PROJECTION_DEFAULT",
|
"transformBy" : {
|
"f" : {
|
"$add" : [
|
1,
|
2
|
]
|
}
|
},
|
"inputStage" : {
|
"stage" : "COLLSCAN",
|
"direction" : "forward"
|
}
|
},
|
"rejectedPlans" : [ ]
|
},
|
That is, the $add has not been constant folded.
The cause of this bug is that the ProjectionStage reports the original BSON for the "transformBy" field, rather than a serialized version of the ProjectionExecutor. See here. The actual projection executor used for answering the query does get optimized.
Unfortunately, because of the way $slice and positional projection are implemented using "root replacement" expressions, serializing the executor back to MQL may not always be possible with the code in its current state.
|