[SERVER-42707] $eq should count as a subset of $exists for partialFilterExpression index selection Created: 08/Aug/19 Updated: 15/Aug/19 Resolved: 15/Aug/19 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Index Maintenance |
| Affects Version/s: | 4.0.11 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Ben Rotz | Assignee: | Danny Hatcher (Inactive) |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||
| Participants: | |||||||||||||
| Description |
|
When selecting an index, and the index is sparse (or partialFilterExpression is used), the documentation describes that the query predicate must include the partialFilteredExpression. See https://docs.mongodb.com/manual/core/index-partial/#query-coverage
However, if an index is defined as sparse like so:
Then queries against test do not always select this index when using the $eq operator. Example:
I would think that the $eq operator should be considered a subset of $exists for purposes of index selection, right?
FYI, I originally filed my findings on this google user group: https://groups.google.com/forum/?nomobile=true#!topic/mongodb-user/KxvqiQX17UY
|
| Comments |
| Comment by Danny Hatcher (Inactive) [ 15/Aug/19 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
To clarify, the issue isn't actually $eq. For example, the following command will use a partial index.
That is because it is functionally equivalent to:
The issue is the existence of the $expr operator which triggers the use of expressions. That is the operator that has issues with partial indexes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Ben Rotz [ 15/Aug/19 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Ah yes, I did not realize it was just a blanket `$eq does nto use partial indexes`. Thank you for the clarification, duplicate merge sounds reasonable. Thanks. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Danny Hatcher (Inactive) [ 15/Aug/19 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I believe this is more about the $expr instead of the $eq. As mentioned in SERVER-38799, $expr does not utilize partial indexes. I will close this ticket as a duplicate of SERVER-38799 and I recommend you watch it for future updates. |