[SERVER-9094] Optimize $or queries to perform like $in if all clauses are on the same field Created: 22/Mar/13 Updated: 25/Jun/15 Resolved: 29/Jan/15 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Osmar Olivo | Assignee: | David Storch |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||
| Participants: | |||||||||||||
| Description |
|
For performance reasons, you would generally decide to use $in in scenarios where they apply over $or. However, some scenarios apply that you would be forced to use a $or in order to add more complex clauses or ranges to your query. For something like find all values of a where a > 10 and a < 20 or a > 30 and a < 50, you would be forced to use a $or query even though the only field being used in the index is a. $or should be able to detect when it does not need to run as multiple queries and perhaps handle single field cases like this in a performant way. |
| Comments |
| Comment by David Storch [ 29/Jan/15 ] |
|
SERVER-12024 provides a much more straightforward description of the work involved here. The query optimizer already rewrites an $all to an $and. By the same token, $in should be rewritten to an $or. These two query operators should be syntactic sugar with the same query optimizer semantics. Closing as a duplicate. |