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

Projections appear unoptimized in find explain output

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Major - P3 Major - P3
    • None
    • 4.4.1
    • Querying
    • Query Execution

    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.

      Attachments

        Activity

          People

            backlog-query-execution Backlog - Query Execution
            ian.boros@mongodb.com Ian Boros
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: