[SERVER-47374] Query with empty in clause performs collection scan Created: 06/Apr/20 Updated: 06/Dec/22 |
|
| Status: | Backlog |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | 4.0.17 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Peter Williamson | Assignee: | Backlog - Query Optimization |
| Resolution: | Unresolved | Votes: | 1 |
| Labels: | qopt-team | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
||||||||
| Issue Links: |
|
||||||||
| Assigned Teams: |
Query Optimization
|
||||||||
| Operating System: | ALL | ||||||||
| Steps To Reproduce: | db.collection.explain().aggregate([{$match: {Field: {$in: []}}}]) or db.collection.find({Field: {$in: []}}).explain("executionStats") Where there is no index on Field |
||||||||
| Participants: | |||||||||
| Description |
|
Both find and aggregate will perform a scan when the search criteria is {$in: [ ]} and the searched field is not indexed. IMHO the query should either immediately return zero documents or throw an error due to the empty array. |