[SERVER-52814] queryPlanner.winningPlan.inputStage is undefined for a specific query Created: 12/Nov/20  Updated: 29/Oct/23  Resolved: 25/Jan/21

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

Type: Bug Priority: Major - P3
Reporter: Tanay Abhra Assignee: Ted Tuckman
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Problem/Incident
is caused by SERVER-25023 no way to index the same fields with ... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Query 2020-12-28, Query 2021-01-11, Query 2021-01-25, Query 2021-02-08
Participants:

 Description   

We are going to run atlas proxy with mongodb 4.9+ version in the future. While trying to run the test harness with a new mongod in dev, I found a breaking change. We have this test in the test suite:

 

    log("Index all paths that includes _id");
    db.test5.insert({name: "foo", type: "bar", v: 1, _id: {a: 1, b: 2}});
    db.test5.createIndex({"$**": 1},{wildcardProjection: {name: 0, type: 0, _id: 1}});
    assert.eq("IXSCAN", db.test5.find({"_id.a": 1}).explain(true).queryPlanner.winningPlan.inputStage.stage);
    assert.eq("COLLSCAN", db.test5.find({"name": "foo"}).explain(true).queryPlanner.winningPlan.stage);

which started failing with this error: `TypeError: db.test5.find(...).explain(...).queryPlanner.winningPlan.inputStage is undefined`

We have similar tests that pass without a hitch, for example:

 

    log("Index all with excluded subtrees");
    db.test4.insert({name: "foo", type: "bar", v: 1});
    db.test4.createIndex({"$**": 1},{wildcardProjection: {name: 0, type: 0}});
    assert.eq("IXSCAN", db.test4.find({"v": 1}).explain(true).queryPlanner.winningPlan.inputStage.stage);
    assert.eq("COLLSCAN", db.test4.find({"name": "foo"}).explain(true).queryPlanner.winningPlan.stage);
    db.test4.drop();

 



 Comments   
Comment by Githook User [ 25/Jan/21 ]

Author:

{'name': 'Ted Tuckman', 'email': 'ted.tuckman@mongodb.com', 'username': 'TedTuckman'}

Message: SERVER-52814 Serialize projection _id field to always equivalent projection spec
Branch: master
https://github.com/mongodb/mongo/commit/2497bf18a4f2959501582f4084ad27212698b574

Comment by Githook User [ 25/Jan/21 ]

Author:

{'name': 'Ted Tuckman', 'email': 'ted.tuckman@mongodb.com', 'username': 'TedTuckman'}

Message: SERVER-52814 Serialize projection _id field to always equivalent projection spec
Branch: master
https://github.com/10gen/mongo-enterprise-modules/commit/dccdc861e192d173d419eb714fbcb0d618293166

Comment by Edwin Zhou [ 20/Nov/20 ]

I reproduced the issue for test5 in both 4.4.2 and 4.9+ and noticed a discrepancy in how the indexes were being created.
In 4.9+ when the index is created, the wildcardProjection isn't correctly added and all fields are false:

> db.test5.getIndexes()
[
	{
		"v" : 2,
		"key" : {
			"_id" : 1
		},
		"name" : "_id_"
	},
	{
		"v" : 2,
		"key" : {
			"$**" : 1
		},
		"name" : "$**_1",
		"wildcardProjection" : {
			"name" : false,
			"type" : false
		}
	}
]

This is the correct result that I get in 4.4.2:

> db.test5.getIndexes()
[
	{
		"v" : 2,
		"key" : {
			"_id" : 1
		},
		"name" : "_id_"
	},
	{
		"v" : 2,
		"key" : {
			"$**" : 1
		},
		"name" : "$**_1",
		"wildcardProjection" : {
			"name" : 0,
			"type" : 0,
			"_id" : 1
		}
	}
]

I used the reproduction provided in the description without the assertion.

db.test5.insert({ name: "foo", type: "bar", v: 1, _id: { a: 1, b: 2 } });
db.test5.createIndex(
  { "$**": 1 },
  { wildcardProjection: { name: 0, type: 0, _id: 1 } }
);
 
db.test5.find({ "_id.a": 1 }).explain(true).queryPlanner.winningPlan;

Is this adequate information to isolate the the cause?

Comment by Ana Meza [ 17/Nov/20 ]

Query is wondering if someone from Triage team can reproduce this one, please

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