[SERVER-79066] Investigate why $group rewrite based on controls in TS isn't lowered to SBE Created: 18/Jul/23  Updated: 29/Oct/23  Resolved: 05/Sep/23

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

Type: Task Priority: Major - P3
Reporter: Irina Yatsenko (Inactive) Assignee: Irina Yatsenko (Inactive)
Resolution: Fixed Votes: 0
Labels: auto-reverted
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Problem/Incident
Assigned Teams:
Query Integration
Backwards Compatibility: Fully Compatible
Sprint: QI 2023-08-21, QI 2023-09-04, QI 2023-09-18
Participants:
Linked BF Score: 0

 Description   

A query like ts.aggregate({$group: {_id: "$meta", m: {$min: "$control.min.value"}}}) should be optimized to take advantage of the bucket's control data instead of unpacking the buckets.

When all queries against TS namespace are forced to run in classic, both ts.aggregate({$group: {_id: "$meta", m: {$min: "$value"}}}) and system.buckets.ts..aggregate({$group: {_id: "$meta", m: {$min: "$control.min.value"}}}) generate the following plan:

"stages" : [
	{
		"$cursor" : {
			"queryPlanner" : {
				"namespace" : "my.system.buckets.ts",
				"indexFilterSet" : false,
				"parsedQuery" : {
	},
	"queryHash" : "0D1EB9EE",
	"planCacheKey" : "0D1EB9EE",
	"maxIndexedOrSolutionsReached" : false,
	"maxIndexedAndSolutionsReached" : false,
	"maxScansToExplodeReached" : false,
	"winningPlan" : {
		"stage" : "PROJECTION_DEFAULT",
		"transformBy" : {"control.min.value" : 1, "meta" : 1, "_id" : 0},
		"inputStage" : {"stage" : "COLLSCAN", "direction" : "forward"}
	},
	"rejectedPlans" : [ ]	}}},
	{ "$group" : {"_id" : "$meta", "m" : {"$min" : "$control.min.value"}}}
],

But if SBE lowered is allowed for TS namespaces, the query against the view only lowers the access (PROJECTION_DEFAULT + COLLSCAN) but not GROUP while the query against the backing collection is lowered fully (GROUP + COLLSCAN). This needs to be investigated because not lowering the $group properly is likely to affect performance.



 Comments   
Comment by Githook User [ 01/Sep/23 ]

Author:

{'name': 'Irina Yatsenko', 'email': 'irina.yatsenko@mongodb.com', 'username': 'IrinaYatsenko'}

Message: SERVER-79066 Set SBE compatibility on the re-written group over time-series
Branch: master
https://github.com/mongodb/mongo/commit/0b1fc0f43345061bcdad23357af8a517e49b60a7

Comment by xgen-buildbaron-user [ 12/Aug/23 ]

Ticket re-opened due to revert. session_jscore_passthrough began a consistent failure of jstests/core/timeseries/timeseries_index_partial.js,jstests/core/write/bulk/bulk_write_timeseries_basic.js,jstests/core/timeseries/timeseries_groupby_reorder.js,jstests/core/timeseries/bucket_unpacking_group_reorder_fixed_buckets.js

Comment by Githook User [ 12/Aug/23 ]

Author:

{'name': 'auto-revert-processor', 'email': 'dev-prod-dag@mongodb.com', 'username': ''}

Message: Revert "SERVER-79066 Mark rewritten $group against the bucket collection as SBE-compatible"

This reverts commit 4a00fc6432e76b6b5a6d718000b3384db637c82b.
Branch: master
https://github.com/mongodb/mongo/commit/8970d68e4844c7b6783af7c4197f9459595d9ad7

Comment by Githook User [ 11/Aug/23 ]

Author:

{'name': 'Irina Yatsenko', 'email': 'irina.yatsenko@mongodb.com', 'username': 'IrinaYatsenko'}

Message: SERVER-79066 Mark rewritten $group against the bucket collection as SBE-compatible
Branch: master
https://github.com/mongodb/mongo/commit/4a00fc6432e76b6b5a6d718000b3384db637c82b

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