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

Remove plans do not need a FETCH stage

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • None
    • Query Optimization
    • Quint 9 09/18/15, QO 2024-02-19

      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.

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            david.storch@mongodb.com David Storch
            Votes:
            5 Vote for this issue
            Watchers:
            34 Start watching this issue

              Created:
              Updated: