[SERVER-73792] Partial index isSubsetOf could be more precise for $or / $in Created: 08/Feb/23 Updated: 24/Feb/23 |
|
| Status: | Open |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | David Percy | Assignee: | Backlog - Query Optimization |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | query-product-scope-1, query-product-urgency-3, query-product-value-2 | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Assigned Teams: |
Query Optimization
|
| Participants: |
| Description |
|
When a partial filter expression uses $or, we sometimes don't recognize that it can satisfy a query using $or. For example:
This query should use the index, because any document matching {a: -1} will be indexed, and any document matching {a: 12} will be indexed. |
| Comments |
| Comment by Ana Meza [ 14/Feb/23 ] |
|
christopher.harris@mongodb.com would you mind looking at this for priority, since Anton thinks this might be one for the backlog. |
| Comment by David Percy [ 08/Feb/23 ] |
|
It looks like we're getting the wrong answer (too conservative) because of how we break up isSubsetOf() with $and/$or into subproblems. There are 4 rules for $and / $or:
Some rules make the subproblems harder, but only one subproblem has to be true. Some rules make the subproblems easier, but all of them have to be true. The reason the example goes wrong, is that we're making the subproblems too hard:
So I think we want to always prefer the rule that makes the subproblems easier. Note that when we compare $and vs $and, we are getting the right answer, because we're preferring to break up the right-hand side first, which makes the subproblems easier. |