[SERVER-60101] Eliminate intermediate mkobj stage from $group plans Created: 20/Sep/21  Updated: 29/Oct/23  Resolved: 30/Sep/21

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

Type: Task Priority: Major - P3
Reporter: Eric Cox (Inactive) Assignee: Eric Cox (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File group_sbe_sum.svg    
Backwards Compatibility: Fully Compatible
Sprint: QE 2021-10-04
Participants:

 Description   

Initial performance investigations have shown that pushing $group into the find layer with SBE on have a perf benefit over the classic engine when the $group stage has no accumulators. Pushdown of $group and $sum into the find system performs about the same or worse than the classic engine.

We have identified some improvements that can be made and one of those is to eliminate a project above the collection scan in a plan such as,
group_sbe_sum.svg

> coll.explain().aggregate([{$group: {_id: '$_idMod10', s: {$sum: '$price'}}}]);
{
	"explainVersion" : "2",
	"queryPlanner" : {
		"namespace" : "test.group_pushdown",
		"indexFilterSet" : false,
		"parsedQuery" : {
 
		},
		"queryHash" : "32904A1C",
		"planCacheKey" : "7DEED33E",
		"optimizedPipeline" : true,
		"maxIndexedOrSolutionsReached" : false,
		"maxIndexedAndSolutionsReached" : false,
		"maxScansToExplodeReached" : false,
		"winningPlan" : {
			"queryPlan" : {
				"stage" : "GROUP",
				"planNodeId" : 3,
				"inputStage" : {
					"stage" : "PROJECTION_SIMPLE",  <--- eliminate this stage
					"planNodeId" : 2,
					"transformBy" : {
						"_idMod10" : true,
						"price" : true,
						"_id" : false
					},
					"inputStage" : {
						"stage" : "COLLSCAN",
						"planNodeId" : 1,
						"filter" : {
 
						},
						"direction" : "forward"
					}
				}
			},

The sbe plan for the above query plan,

[3] mkbson s11 [_id = s9, s = s10] true false
[3] project [s9 = fillEmpty (s6, null), s10 = if (! exists (s8) || typeMatch (s8, 0x00000440), 0, doubleDoubleSumFinalize (s8))]
[3] group [s6] [s8 = aggDoubleDoubleSum (s7)]
[3] project [s7 = getField (s5, "price")]
[3] project [s6 = getField (s5, "_idMod10")]
[2] mkbson s5 s3 [_idMod10, price] keep [] true false <--- From PROJECTION_SIMPLE
[1] scan s3 s4 none none none none [] @"75ca0299-5f72-4af8-87f2-fb63ac59a4fb" true false

This stage should be removed.



 Comments   
Comment by Vivian Ge (Inactive) [ 06/Oct/21 ]

Updating the fixversion since branching activities occurred yesterday. This ticket will be in rc0 when it’s been triggered. For more active release information, please keep an eye on #server-release. Thank you!

Comment by Githook User [ 29/Sep/21 ]

Author:

{'name': 'Eric Cox', 'email': 'eric.cox@mongodb.com', 'username': 'ericox'}

Message: SERVER-60101 Eliminate intermediate mkobj stage from $group plans
Branch: master
https://github.com/mongodb/mongo/commit/a10b82783a88737d2870ae591184d9a6dd932665

Generated at Thu Feb 08 05:48:57 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.