[SERVER-50791] Projections appear unoptimized in find explain output Created: 08/Sep/20  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Querying
Affects Version/s: 4.4.1
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Ian Boros Assignee: Backlog - Query Execution
Resolution: Unresolved Votes: 0
Labels: qexec-team
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Execution
Participants:

 Description   

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.



 Comments   
Comment by Ian Boros [ 08/Sep/20 ]

CC anton.korshunov who originally pointed this behavior out.

Generated at Thu Feb 08 05:23:35 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.