Consider using a COLLSCAN instead of a full IXSCAN + FETCH

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Duplicate
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Optimization
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      For queries that result in index bounds [MinKey, MaxKey], we see "FETCH" and "IXSCAN" stages instead of the "COLLSCAN" stage. Example query and explain output are given below:

      db.foo.find({$expr: {$or: [{$gt: ["$_id", 3]}, {$lt: ["$_id", 5]}]}}).explain()
      
      ...
             "winningPlan" : {
                              "isCached" : false,
                              "stage" : "FETCH",
                              "filter" : {
                                      "$expr" : {
                                              "$or" : [
                                                      {
                                                              "$gt" : [
                                                                      "$_id",
                                                                      {
                                                                              "$const" : 3
                                                                      }
                                                              ]
                                                      },
                                                      {
                                                              "$lt" : [
                                                                      "$_id",
                                                                      {
                                                                              "$const" : 5
                                                                      }
                                                              ]
                                                      }
                                              ]
                                      }
                              },
                              "inputStage" : {
                                      "stage" : "IXSCAN",
                                      "keyPattern" : {
                                              "_id" : 1
                                      },
                                      "indexName" : "_id_",
                                      "isMultiKey" : false,
                                      "isUnique" : true,
                                      "isSparse" : false,
                                      "isPartial" : false,
                                      "indexVersion" : 2,
                                      "direction" : "forward",
                                      "indexBounds" : {
                                              "_id" : [
                                                      "[MinKey, MaxKey]"
                                              ]
                                      }
                              }
                      },
                      "rejectedPlans" : [ ]
              }

       

              Assignee:
              Unassigned
              Reporter:
              Sopho Kevlishvili (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              11 Start watching this issue

                Created:
                Updated:
                Resolved: