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

Compound multikey index doesnt use second key

    • Type: Icon: Question Question
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.0.4
    • Component/s: Index Maintenance, Querying
    • Labels:
      None

      1. Create two documents in collection "test"

      {
        "time": [
          {
            "hour": 17
          },
          {
            "hour": 18
          },
          {
            "day": 0
          }
        ]
      },
      {
        "time": [
          {
            "hour": 17
          },
          {
            "hour": 19
          },
          {
            "day": 1
          }
        ]
      }
      

      2. Build an index:

      db.test.ensureIndex({
          "time.hour" : 1, 
          "time.day" : 1
      }, { 
          "name" : "time.hour_1_time.day_1", 
          "background" : true, 
      })
      

      3. Now run a query:

      db.test.find({
      	'time.hour': 17,
      	'time.day': 1,
      }).explain(true)
      

      4. See that winningPlan includes a filter on 'time.day' field and index bounds do not use a value from the query

      "winningPlan" : {
          "stage" : "FETCH", 
          "filter" : {
              "time.day" : {
                  "$eq" : NumberInt(1)
              }
          }, 
          "inputStage" : {
              "stage" : "IXSCAN", 
              "keyPattern" : {
                  "time.hour" : NumberInt(1), 
                  "time.day" : NumberInt(1)
              }, 
              "indexName" : "time.hour_1_time.day_1", 
              "isMultiKey" : true, 
              "direction" : "forward", 
              "indexBounds" : {
                  "time.hour" : [
                      "[17.0, 17.0]"
                  ], 
                  "time.day" : [
                      "[MinKey, MaxKey]"
                  ]
              }
          }
      }
      

      The question is: why query is not fully covered by the index.

            Assignee:
            sam.kleinman Sam Kleinman (Inactive)
            Reporter:
            andrey.hohutkin@gmail.com Andrey Hohutkin
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: