[SERVER-52845] $exists works slowly Created: 13/Nov/20 Updated: 13/Nov/20 Resolved: 13/Nov/20 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Index Maintenance, Querying |
| Affects Version/s: | 4.2.10 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Дмитрий Аганов | Assignee: | Unassigned |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Operating System: | ALL | ||||||||
| Steps To Reproduce: | db.test.insertMany([ {"name" : "0_0", "status" : 2.0 }, {"name" : "0_1", "status" : 2.0 }, {"name" : "0_2"}, {"name" : "0_3", "status" : 2.0}, {"name" : "0_4"}, {"name" : "0_5"}, {"name" : "0_6", "status" : 2.0}, {"name" : "0_7", "status" : 3.0}]); db.test.createIndex({ status: 1}); db.test.find({status: 2}, {}).explain(); db.test.find({status: {$exists: false}}, {}).explain(); |
||||||||
| Participants: | |||||||||
| Description |
|
If you're doing a query with $exists, it takes much more time than doing a query by value. Example query: db.getCollection('test').find({status: {$exists: false}}, {}).count() }}, , , }}, So, there is IXSCAN and next FETCH with filter. Why filter is here? This is explain for db.getCollection('test').find({status: 1}, {}).count(): , , }}, As you can see, there are no filter in FETCH, and this query is faster. |
| Comments |
| Comment by Eric Sedor [ 13/Nov/20 ] |
|
SERVER-12869 describes an improvement that will help with the performance difference you are observing. Please watch that ticket for updates and comment there if you see anything you'd like to add. Thank you, |