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

Consider using a COLLSCAN instead of a full IXSCAN + FETCH

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Optimization
    • 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 Unassigned
            Reporter:
            sopho.kevlishvili@mongodb.com Sopho Kevlishvili
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved:
              None
              None
              None
              None