[SERVER-25803] Covered distinct plans do not need a PROJECTION stage Created: 25/Aug/16  Updated: 06/Dec/22

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

Type: Improvement Priority: Major - P3
Reporter: David Storch Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Optimization
Participants:

 Description   

Covered plans used to answer the distinct command currently have a PROJECTION stage as the root:

> db.c.drop();
> db.c.createIndex({a: 1});
> db.c.explain().distinct("a");
{
       	"queryPlanner" : {
       		"plannerVersion" : 1,
       		"namespace" : "test.c",
       		"indexFilterSet" : false,
       		"parsedQuery" : {
 
       		},
       		"winningPlan" : {
       			"stage" : "PROJECTION",
       			"transformBy" : {
       				"_id" : 0,
       				"a" : 1
       			},
       			"inputStage" : {
       				"stage" : "DISTINCT_SCAN",
       				"keyPattern" : {
       					"a" : 1
       				},
       				"indexName" : "a_1",
       				"isMultiKey" : false,
       				"multiKeyPaths" : {
       					"a" : [ ]
       				},
       				"isUnique" : false,
       				"isSparse" : false,
       				"isPartial" : false,
       				"indexVersion" : 1,
       				"direction" : "forward",
       				"indexBounds" : {
       					"a" : [
       						"[MinKey, MaxKey]"
       					]
       				}
       			}
       		},
       		"rejectedPlans" : [ ]
       	},
       	"serverInfo" : {
       		"host" : "dstorch",
       		"port" : 27017,
       		"version" : "0.0.0",
       		"gitVersion" : "unknown"
       	},
       	"ok" : 1
}

This projection stage is not actually needed, since the PlanExecutor can produce the distinct values from WorkingSetMembers in RID_AND_IDX state.


Generated at Thu Feb 08 04:10:16 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.