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

Index doesn't cover a query for a partial filter expression index under certain circumstances

    XMLWordPrintableJSON

Details

    • Question
    • Status: Closed
    • Major - P3
    • Resolution: Duplicate
    • 3.2.17
    • None
    • Index Maintenance
    • None

    Description

      The partial filter expression contains a scalar equality expression : "bool" : true

      db.coll.getIndexes()
      [
              ...
              {
                      "v" : 1,
                      "key" : {
                              "timestamp" : 1,
                              "userId" : 1
                      },
                      "name" : "timestamp_1_userId_1",
                      "ns" : "...",
                      "background" : true,
                      "partialFilterExpression" : {
                              "bool" : true
                      }
              }
      ]
      

      A query contains the index fields, projects the index field and uses the single possible value for the partial expression:

      db.coll.explain("executionStats").find({ timestamp: { $gte: 1511041284 }, userId: { $in: [ 1,2,3,4 ]}, bool: true },{timestamp: 1, userId:1, _id:0 })
      {
              ...
              "executionStats" : {
                      "executionSuccess" : true,
                      "nReturned" : 2,
                      "executionTimeMillis" : 14,
                      "totalKeysExamined" : 294,
                      "totalDocsExamined" : 2,
                      "executionStages" : {
                              "stage" : "PROJECTION",
                              "nReturned" : 2,
                              "executionTimeMillisEstimate" : 0,
                              "works" : 296,
                              "advanced" : 2,
                              "needTime" : 292,
                              "needYield" : 0,
                              "saveState" : 4,
                              "restoreState" : 4,
                              "isEOF" : 1,
                              "invalidates" : 0,
                              "transformBy" : {
                                      "timestamp" : 1,
                                      "userId" : 1,
                                      "_id" : 0
                              },
                              "inputStage" : {
                                      "stage" : "FETCH",
                                      "filter" : {
                                              "bool" : {
                                                      "$eq" : true
                                              }
                                      },
                                      "nReturned" : 2,
                                      "executionTimeMillisEstimate" : 0,
                                      "works" : 296,
                                      "advanced" : 2,
                                      "needTime" : 292,
                                      "needYield" : 0,
                                      "saveState" : 4,
                                      "restoreState" : 4,
                                      "isEOF" : 1,
                                      "invalidates" : 0,
                                      "docsExamined" : 2,
                                      "alreadyHasObj" : 0,
                                      "inputStage" : {
                                              "stage" : "IXSCAN",
                                              "nReturned" : 2,
                                              "executionTimeMillisEstimate" : 0,
                                              "works" : 295,
                                              "advanced" : 2,
                                              "needTime" : 292,
                                              "needYield" : 0,
                                              "saveState" : 4,
                                              "restoreState" : 4,
                                              "isEOF" : 1,
                                              "invalidates" : 0,
                                              "keyPattern" : {
                                                      "timestamp" : 1,
                                                      "userId" : 1
                                              },
                                              "indexName" : "timestamp_1_userId_1",
                                              "isMultiKey" : false,
                                              "isUnique" : false,
                                              "isSparse" : false,
                                              "isPartial" : true,
                                              "indexVersion" : 1,
                                              "direction" : "forward",
                                              "indexBounds" : {
                                                      "timestamp" : [
                                                              "[1511041284.0, inf.0]"
                                                      ],
                                                      "userId" : [
                                                              ...
      

      Under such conditions, shouldn't it be enough for the index to cover the query?

      Attachments

        Issue Links

          Activity

            People

              mark.agarunov Mark Agarunov
              orid@trainologic.com Ori Dar
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: