[SERVER-60234] Implement plumbing for getField() pushdown in the SBE stage builder Created: 27/Sep/21  Updated: 29/Oct/23  Resolved: 31/Oct/22

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

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

Issue Links:
Depends
depends on SERVER-70509 [SBE] Pass input/output slots to Unio... Closed
depends on SERVER-70476 Refactor buildSort() in "sbe_stage_bu... Closed
is depended on by SERVER-69260 [SBE] Improve how optimizeFieldPaths(... Closed
is depended on by SERVER-70972 Push simple getField() expressions in... Closed
Duplicate
is duplicated by SERVER-60484 Optimize field paths more generally Closed
is duplicated by SERVER-69542 Refactor how we track metadata slots Closed
is duplicated by SERVER-69647 Refactor how $group optimizes itself ... Closed
Backwards Compatibility: Fully Compatible
Sprint: QE 2022-09-19, QE 2022-10-03, QE 2022-10-17, QE 2022-10-31
Participants:
Story Points: 5

 Description   

In SERVER-60101, we are now able to eliminate the `mkbson` stage directly below a `group` stage. The query solution tree is of the form,

> db.t.explain().aggregate([{$group: {_id: {$add: ["$a", "$b", "$z"]}, s: {$sum: "$b"}}}]).queryPlanner.winningPlan
{
	"queryPlan" : {
		"stage" : "GROUP",
		"planNodeId" : 3,
		"inputStage" : {
			"stage" : "COLLSCAN",
			"planNodeId" : 1,
			"filter" : {
 
			},
			"direction" : "forward"
		}
	},

And the generated sbe plan is,

> db.t.explain().aggregate([{$group: {_id: "$a", s: {$sum: "$b"}}}]).queryPlanner.winningPlan.slotBasedPlan.stages
[3] mkbson s10 [_id = s6, s = s9] true false
[3] project [s9 = if (! exists (s8) || typeMatch (s8, 0x00000440), 0, doubleDoubleSumFinalize (s8))]
[3] group [s6] [s8 = aggDoubleDoubleSum (s7)]
[3] project [s7 = getField (s3, "b") #this is not needed
[3] project [s6 = fillEmpty (s5, null)]
[3] project [s5 = getField (s3, "a")] #this is not needed
[1] scan s3 s4 none none none none [] @"36bd379a-c864-43a6-9814-11025007ba75" true false

Each getField() on fields "a" and "b" will do a linear scan over the bson obj in slot s3. If we push the getFields into the scan stage we will be able to extract both "a" and "b" in a single pass. A rough plan after the optimization could be,

[3] mkbson s11 [_id = s7, p = s10] true false
[3] project [s10 = if (! exists (s9) || typeMatch (s9, 0x00000440), 0, doubleDoubleSumFinalize (s8))]
[3] group [s7] [s9 = aggDoubleDoubleSum (s8)]
[3] project [s7 = fillEmpty (s6, null)]
[1] scan s3 s4 none none none none [] @"3765f3f5-86ac-49e9-857f-d513b3112d74" true false lookup s6="a" s7="b"



 Comments   
Comment by Githook User [ 31/Oct/22 ]

Author:

{'name': 'Drew Paroski', 'email': 'drew.paroski@mongodb.com', 'username': 'paroski'}

Message: SERVER-60234 Implement plumbing for getField() pushdown in the SBE stage builder
Branch: master
https://github.com/mongodb/mongo/commit/c44135cca044b087f529a3024bea8e2c2f1866f4

Comment by Drew Paroski [ 13/Oct/22 ]

Code review (draft): https://github.com/10gen/mongo/pull/8044

Comment by Ethan Zhang (Inactive) [ 18/May/22 ]

yoonsoo.kim@mongodb.com I am moving this to the SBE performance epic for it to be re-discussed per our chat in today's 1-1.

Comment by Yoon Soo Kim [ 19/Oct/21 ]

Working on making a separate PR.

Comment by Yoon Soo Kim [ 19/Oct/21 ]

Reopen this ticket because we've decided to divide the PR for SERVER-60484 into 3 PRs.

Comment by Yoon Soo Kim [ 08/Oct/21 ]

Closing this ticket in favor of SERVER-60484. SERVER-60494 has the bigger scope including this ticket.

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