[SERVER-74199] Group stage builder produces a project stage when group id is constant Created: 21/Feb/23  Updated: 29/Oct/23  Resolved: 24/Feb/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.0.0-rc0

Type: Bug Priority: Major - P3
Reporter: Rui Liu Assignee: Rui Liu
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Problem/Incident
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: QE 2023-03-06
Participants:
Linked BF Score: 35

 Description   

Currently, $count aggregation stage will produce a project stage for the group id, even when the group id is constant.

For aggregation:

db.coll.explain().aggregate([{$count: "n"}]).stages[0].$cursor.queryPlanner.winningPlan.slotBasedPlan.stages

It produces:

[2] mkobj s9 [_id = s6, n = s7] true false
[2] group [s6] [s7 = sum(1)] spillSlots[s8] mergingExprs[sum(s8)]
[2] project [s6 = (null ?: null)]
[1] scan s4 s5 none none none none [] @"e8cac054-9809-447e-94d0-1225895e2c70" true false

The project stage is evaluated for every document and is not necessary.



 Comments   
Comment by Githook User [ 24/Feb/23 ]

Author:

{'name': 'Rui Liu', 'email': 'lriuui0x0@gmail.com', 'username': 'lriuui0x0'}

Message: SERVER-74199 Project group id constant after hashagg stage
Branch: master
https://github.com/mongodb/mongo/commit/ffd022d14862c8b3caffcad69d24493db6aa5224

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