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

Partial index shouldn't do fetch on conditions that are true by the definition of the index

    • Query Optimization
    • Fully Compatible
    • v7.0, v6.3, v6.0, v5.0, v4.4
    • QO 2023-03-06, QO 2023-03-20, QO 2023-04-03, QO 2023-04-17, QO 2023-05-01

      db.xxx.ensureIndex({x:1},{partialFilterExpression:{bin:true}})
      
      > db.xxx.find({bin:true,x:1}).explain()
      {
      	"queryPlanner" : {
      		"plannerVersion" : 1,
      		"namespace" : "test.xxx",
      		"indexFilterSet" : false,
      		"parsedQuery" : {
      			"$and" : [
      				{"bin" : {"$eq" : true}},
      				{"x" : {"$eq" : 1}}
      			]
      		},
      		"winningPlan" : {
      			"stage" : "FETCH",
      			"filter" : {"bin" : {"$eq" : true}},
      			"inputStage" : {
      				"stage" : "IXSCAN",
      				"keyPattern" : {"x" : 1},
      				"indexName" : "x_1",
      				"isMultiKey" : false,
      				"multiKeyPaths" : { "x" : [ ] },
      				"isUnique" : false,
      				"isSparse" : false,
      				"isPartial" : true,
      				"indexVersion" : 2,
      				"direction" : "forward",
      				"indexBounds" : { "x" : [ "[1.0, 1.0]" 	] }
      			}
      		},
      		"rejectedPlans" : [ ]
      	},
      	"serverInfo" : {
      		"host" : "AD-MAC10G.local",
      		"port" : 27017,
      		"version" : "3.4.2",
      		"gitVersion" : "3f76e40c105fc223b3e5aac3e20dcd026b83b38b"
      	},
      	"ok" : 1
      }
      

      There's no need to do the FETCH with a check on bin:true since that condition is already satisfied by the index partial filterexpression

            Assignee:
            milena.ivanova@mongodb.com Milena Ivanova
            Reporter:
            alex.komyagin@mongodb.com Alexander Komyagin (Inactive)
            Votes:
            13 Vote for this issue
            Watchers:
            48 Start watching this issue

              Created:
              Updated:
              Resolved: