[SERVER-31172] index not used when it has partialFilterExpression and $exists on a query subset Created: 19/Sep/17 Updated: 11/Mar/19 Resolved: 20/Sep/17 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | 3.4.9 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Brad Vogel | Assignee: | Mark Agarunov |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | MAREF | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Operating System: | ALL | ||||||||
| Steps To Reproduce: | See above |
||||||||
| Participants: | |||||||||
| Case: | (copied to CRM) | ||||||||
| Description |
|
Consider the following:
Actual: Expected: `. |
| Comments |
| Comment by Mark Agarunov [ 20/Sep/17 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hello brad@mixmax.com, Thank you for the report. Currently when using a partialFilterExpression with a field that is not the index key, the query must include the index key field, as well as the field used in the filter expression. Additionally, to use the same index with both a and a.b, you would need to include the both in the index key. As a workaround, you can use the following index:
and add a match for a to the example queries you provided. Now the index is used for both queries:
Looking over the desired behavior you've described, this looks to be the same as the behavior detailed in SERVER-26580 so I've closed this ticket as a duplicate. Please follow SERVER-26580 for updates on this issue. Thanks, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Brad Vogel [ 19/Sep/17 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Where this is frustrating is that we have two types of queries:
In our database, there are very few documents with key `a` in the `test` collection. So we'd like to create a partialFilterExpression that satisfies both queries. Note that using `sparse: true` (`partialFilterExpression`'s predecessor) handled this correctly. |