[SERVER-80322] $_internalUnpackBucket includes unnecessary fields for reodered match stage Created: 22/Aug/23  Updated: 19/Jan/24  Resolved: 23/Aug/23

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

Type: Task Priority: Major - P3
Reporter: Yoon Soo Kim Assignee: Backlog - Query Integration
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Integration
Participants:

 Description   

Repro, assuming tag is the meta field.

> db.ts2.explain().aggregate([{$project: {tt: {$add: ["$tag", 1]}}}, {$group: {_id: "$tag", x: {$sum: "$tag"}}}, {$match: {_id: 1}}]);
{
	"explainVersion" : "1",
	"stages" : [
		{
			"$cursor" : {
				"queryPlanner" : {
					"namespace" : "test.system.buckets.ts2",
					"indexFilterSet" : false,
					"parsedQuery" : {
 
					},
					"queryHash" : "FCBE9F38",
					"planCacheKey" : "FCBE9F38",
					"maxIndexedOrSolutionsReached" : false,
					"maxIndexedAndSolutionsReached" : false,
					"maxScansToExplodeReached" : false,
					"winningPlan" : {
						"stage" : "COLLSCAN",
						"direction" : "forward"
					},
					"rejectedPlans" : [ ]
				}
			}
		},
		{
			"$addFields" : {
				"tt" : {
					"$add" : [
						"$meta",
						{
							"$const" : 1
						}
					]
				}
			}
		},
		{
			"$_internalUnpackBucket" : {
				"include" : [
					"_id",
					"tt"
				],
				"timeField" : "time",
				"metaField" : "tag",
				"bucketMaxSpanSeconds" : 3600,
				"assumeNoMixedSchemaData" : true,
				"computedMetaProjFields" : [
					"tt"
				],
				"eventFilter" : {
					"tag" : {
						"$eq" : 1
					}
				}
			}
		},
		{
			"$group" : {
				"_id" : "$tag",
				"x" : {
					"$sum" : "$tag"
				}
			}
		}
	],

{$match: {_id: 1}} is reordered to $_internalUnpackBucket's event filter but it's for the computed meta field tt but $_internalUnpackBucket has _id field in its fieldSet.


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