[SERVER-31269] Too many documents examined when using an index and $first/$last in $group stage Created: 26/Sep/17  Updated: 27/Sep/17  Resolved: 27/Sep/17

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Angly Cat Assignee: David Storch
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-9507 Optimize $sort+$group+$first pipeline... Closed
Participants:

 Description   

Let's say I have two documents in a collection:
{_id: 0, a: 1, b: 1} and {_id: 1, a: 1, b: 2}
and index on {a: 1}.
Aggregation pipeline [{$sort: {a: 1}}, {$group: {_id: '$a'}] will be covered by the index, however pipeline [{$sort: {a: 1}}, {$group: {_id: '$a', b: {$first: '$b'}}}], according to execution stats, will examine both 2 documents despite only needing 1 value for $first operator.
So this seems like a place for aggregation optimization.



 Comments   
Comment by David Storch [ 27/Sep/17 ]

Hi angly,

Thanks for reporting this improvement request! If I'm reading this correctly, this is a duplicate of SERVER-9507. Feel free to vote for SERVER-9507 and watch for updates.

Best,
Dave

Generated at Thu Feb 08 04:26:30 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.