Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-50791

Projections appear unoptimized in find explain output

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 4.4.1
    • Component/s: Querying
    • Query Execution
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      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.

            Assignee:
            backlog-query-execution [DO NOT USE] Backlog - Query Execution
            Reporter:
            ian.boros@mongodb.com Ian Boros
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: