-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
Query Optimization
-
Query 2019-07-29
-
(copied to CRM)
A very common use of an aggregation is to count elements by group:
db.items.aggregate([ {$group: {_id: "$category", count: {$sum: 1}}}])
If there is an index over category, this pipeline could be covered and no document retrieval is necessary.
Since this is a quite common pattern, you may take it into account and make use of indexes.
- is related to
-
SERVER-57518 16% performance loss switching from Count to CountDocuments
- Backlog
-
SERVER-20066 Query planner should consider index scans on empty query predicates
- Closed
- related to
-
SERVER-69257 COUNT_SCAN plan not selected when unfiltered $group + $sum on _id performed
- Blocked
-
SERVER-4507 aggregation: optimize $group to take advantage of sorted sequences
- Backlog