Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-80322

$_internalUnpackBucket includes unnecessary fields for reodered match stage

    • Type: Icon: Task Task
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Query Integration

      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.

            Assignee:
            backlog-query-integration [DO NOT USE] Backlog - Query Integration
            Reporter:
            yoonsoo.kim@mongodb.com Yoon Soo Kim
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: