[COMPASS-4587] The initial document count (with empty filter) is very slow Created: 26/Jan/21  Updated: 27/Oct/23  Resolved: 02/Sep/22

Status: Closed
Project: Compass
Component/s: Collection, CRUD, Query
Affects Version/s: 1.25.0
Fix Version/s: No version

Type: Bug Priority: Major - P3
Reporter: Maurizio Casimirri Assignee: Unassigned
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Story Points: 3
Documentation Changes: Not Needed

 Description   

The initial document count is very slow since the server seems to be scanning the whole collection.

To reproduce: try to load a big collection, the first load will take seconds. Moving to next page afterwards (which does not involve re-counting) is almost instantaneous.

I'd expect the first page load to be as fast as the next page since the same amount of documents are loaded.

Possible fixes:

  • Make the count independent from the find and only report the result in the ui when is ready.
  • Use the id field as hint if query is empty: countDocuments({}, {hint: '_id_'}

    ). For what i could test this speeds up the count a tons, the server seems to do an index scan in this case.


Generated at Wed Feb 07 22:36:51 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.