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

Remove plans do not need a FETCH stage

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: Backlog
    • Component/s: Querying
    • Labels:
      None
    • Sprint:
      Quint 9 09/18/15

      Description

      Currently, indexed .remove() plans will always fetch the documents associated with the index keys before performing the remove:

      > t.drop()
      true
      > t.ensureIndex({x: 1})
      {
      	"createdCollectionAutomatically" : true,
      	"numIndexesBefore" : 1,
      	"numIndexesAfter" : 2,
      	"ok" : 1
      }
      > t.explain().remove({x: {$gte: 5, $lte: 10}})
      {
      	"queryPlanner" : {
      		"plannerVersion" : 1,
      		"namespace" : "test.t",
      		"indexFilterSet" : false,
      		"parsedQuery" : {
      			"$and" : [
      				{
      					"x" : {
      						"$lte" : 10
      					}
      				},
      				{
      					"x" : {
      						"$gte" : 5
      					}
      				}
      			]
      		},
      		"winningPlan" : {
      			"stage" : "DELETE",
      			"inputStage" : {
      				"stage" : "FETCH", // This stage is not needed!
      				"inputStage" : {
      					"stage" : "IXSCAN",
      					"keyPattern" : {
      						"x" : 1
      					},
      					"indexName" : "x_1",
      					"isMultiKey" : false,
      					"direction" : "forward",
      					"indexBounds" : {
      						"x" : [
      							"[5.0, 10.0]"
      						]
      					}
      				}
      			}
      		},
      		"rejectedPlans" : [ ]
      	},
      	"serverInfo" : {
      		"host" : "dstorch-desktop",
      		"port" : 27017,
      		"version" : "3.1.0-pre-",
      		"gitVersion" : "ee4db2a36eb894e2694fea781ab70f0cca33d0b8"
      	},
      	"ok" : 1
      }
      

      As an optimization, we could change the query planner to generate indexed .remove() plans without the FETCH stage.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              backlog-query-optimization Backlog - Query Optimization
              Reporter:
              david.storch David Storch
              Participants:
              Votes:
              5 Vote for this issue
              Watchers:
              24 Start watching this issue

                Dates

                Created:
                Updated: