[SERVER-1380] support maxScan in count command Created: 08/Jul/10 Updated: 06/Dec/22 Resolved: 14/Feb/18 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Usability |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Minor - P4 |
| Reporter: | Michael Dirolf | Assignee: | Backlog - Query Team (Inactive) |
| Resolution: | Won't Fix | Votes: | 4 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Assigned Teams: |
Query
|
||||||||
| Participants: | |||||||||
| Description |
|
Jay requested this for the Python driver - but really requires server support. Not sure what version to schedule for, so leaving up to you. |
| Comments |
| Comment by David Storch [ 14/Feb/18 ] |
|
The maxScan feature is being deprecated (see |
| Comment by Joakim Berg [ 29/Jan/12 ] |
|
This would be a really good feature, since count() just runs unitil it has nothing left to count (even if you use the 'limit'-parameter in the PHP-driver). If it doesn't scan all documents and runs indexOnly, it may sometimes go way faster to just let the server scan those few documents instead of counting 100% via the index. As an example, if I put a maxScan of 1001 (i.e. if there are more than 1k items, just show the user that there are 1k+ items in this range), it will run much faster than doing a count() via indexOnly, if the counts finishes on, say 40.000 (my benches were like 1-2ms vs. 110-119ms) So the poor-mans-solution for this is to simply run an explain() on a normal find()-query with maxScan enabled, i.e. find({a:1,b:{'$gte':23324 ,'$lte':82409}}).addSpecial('$maxScan', 1001).explain() and simply fetch the 'n'-key from the explain output (which isn't perfect, but it does the job) |