[SERVER-27522] query optimizer does not choose appropriate partial index when matching "expression" is in $elemMatch Created: 27/Dec/16  Updated: 06/Dec/22  Resolved: 22/Feb/18

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Asya Kamsky Assignee: Backlog - Query Team (Inactive)
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-32540 Make partial index subset analysis co... Backlog
Assigned Teams:
Query
Operating System: ALL
Participants:

 Description   

Example involves index on array of key/value structures.

db.foo.drop();
db.foo.insert({"a":[ {"k":"x", "v":"y"},  {"k":"z", "v":1} ] })
db.foo.createIndex({"a.k":1, "a.v":1},{partialFilterExpression:{"a.k":{$exists:true}}})
db.foo.explain().find({"a":{$elemMatch:{"k":"x","v":"y"}}})
// results in collection scan
db.foo.explain().find({"a":{$elemMatch:{"k":"x","v":"y"}},"a.k":"x"})
// does use partial index as expected, but the redundant condition should not be necessary


Generated at Thu Feb 08 04:15:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.