[SERVER-19323] Compound multikey index doesnt use second key Created: 08/Jul/15  Updated: 08/Jul/15  Resolved: 08/Jul/15

Status: Closed
Project: Core Server
Component/s: Index Maintenance, Querying
Affects Version/s: 3.0.4
Fix Version/s: None

Type: Question Priority: Major - P3
Reporter: Andrey Hohutkin Assignee: Sam Kleinman (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

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.



 Comments   
Comment by Sam Kleinman (Inactive) [ 08/Jul/15 ]

Hello,

Covered queries are not supported for mutikey indexes (docs).

I've opened DOCS-5800 to clarify this point in the documentation, and am going to go ahead and close this ticket for now. Sorry for the misunderstanding.

Cheers,
sam

Generated at Thu Feb 08 03:50:35 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.