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

Prevent plans with unhelpful ("no-op") full index scans

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Query Optimization

      Consider the following:
       

      > db.foo.find({z:1, $or:[{x:{$in:[1]}},{x:{ $nin:[1]}}]}).explain().queryPlanner.winningPlan
      {
          "stage" : "FETCH",
          "filter" : {
              "z" : {
                  "$eq" : 1
              }
          },
          "inputStage" : {
              "stage" : "IXSCAN",
              "keyPattern" : {
                  "x" : 1
              },
              "indexName" : "x_1",
              "isMultiKey" : false,
              "multiKeyPaths" : {
                  "x" : [ ]
              },
              "isUnique" : false,
              "isSparse" : false,
              "isPartial" : false,
              "indexVersion" : 2,
              "direction" : "forward",
              "indexBounds" : {
                  "x" : [
                      "[MinKey, MaxKey]"
                  ]
              }
          }
      }
      

      Here the database is performing a full index scan which is providing no value. Apart from the scan being unbounded, there is no filter being applied in the IXSCAN stage nor is the index supporting a sort order requested from a client. Such a plan does nothing but slow down the query and therefore should not be considered.

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            christopher.harris@mongodb.com Chris Harris
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: