[SERVER-24081] db.collection.explain().count() does not respect hint option Created: 06/May/16  Updated: 19/Nov/16  Resolved: 13/Sep/16

Status: Closed
Project: Core Server
Component/s: Querying, Shell
Affects Version/s: 3.2.0
Fix Version/s: 3.3.14

Type: Bug Priority: Major - P3
Reporter: Kelsey Schubert Assignee: Maria van Keulen
Resolution: Done Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

db.testcounthint.insert({a:1, b:1, c:1});
db.testcounthint.insert({a:1, b:2, c:2});
db.testcounthint.insert({a:2, b:1, c:3});
db.testcounthint.insert({a:2, b:2, c:4});
db.testcounthint.createIndex({a:1, b:1})
db.testcounthint.createIndex({b:1, a:1})
db.testcounthint.createIndex({a:1, b:1, c:1})
db.testcounthint.explain().count({a:1, b:2}, {hint: "a_1_b_1_c_1"})

Sprint: Query 2016-09-19
Participants:

 Description   

The following command generates a plan that does not utilize the a_1_b_1_c_1 index.

> db.testcounthint.explain().count({a:1, b:2}, {hint: "a_1_b_1_c_1"})
{
	"queryPlanner" : {
		"plannerVersion" : 1,
		"namespace" : "test.testcounthint",
		"indexFilterSet" : false,
		"parsedQuery" : {
			"$and" : [
				{
					"a" : {
						"$eq" : 1
					}
				},
				{
					"b" : {
						"$eq" : 2
					}
				}
			]
		},
		"winningPlan" : {
			"stage" : "COUNT",
			"inputStage" : {
				"stage" : "COUNT_SCAN",
				"keyPattern" : {
					"b" : 1,
					"a" : 1
				},
				"indexName" : "b_1_a_1",
				"isMultiKey" : false,
				"isUnique" : false,
				"isSparse" : false,
				"isPartial" : false,
				"indexVersion" : 1
			}
		},
		"rejectedPlans" : [ ]
	},
	"serverInfo" : {
		"host" : "grey.local",
		"port" : 27017,
		"version" : "3.2.5",
		"gitVersion" : "34e65e5383f7ea1726332cb175b73077ec4a1b02"
	},
	"ok" : 1
}

Please note that without the explain, the correct plan is generated.

db.testcounthint.count({a:1, b:2}, {hint: "a_1_b_1_c_1"})

Additionally, note that the following command with explain generates the correct plan:

> db.testcounthint.explain().find({a:1,b:2}).hint("a_1_b_1_c_1").count()
{
	"queryPlanner" : {
		"plannerVersion" : 1,
		"namespace" : "test.testcounthint",
		"indexFilterSet" : false,
		"parsedQuery" : {
			"$and" : [
				{
					"a" : {
						"$eq" : 1
					}
				},
				{
					"b" : {
						"$eq" : 2
					}
				}
			]
		},
		"winningPlan" : {
			"stage" : "COUNT",
			"inputStage" : {
				"stage" : "COUNT_SCAN",
				"keyPattern" : {
					"a" : 1,
					"b" : 1,
					"c" : 1
				},
				"indexName" : "a_1_b_1_c_1",
				"isMultiKey" : false,
				"isUnique" : false,
				"isSparse" : false,
				"isPartial" : false,
				"indexVersion" : 1
			}
		},
		"rejectedPlans" : [ ]
	},
	"serverInfo" : {
		"host" : "grey.local",
		"port" : 27017,
		"version" : "3.2.5",
		"gitVersion" : "34e65e5383f7ea1726332cb175b73077ec4a1b02"
	},
	"ok" : 1
}



 Comments   
Comment by Githook User [ 13/Sep/16 ]

Author:

{u'username': u'mvankeulen94', u'name': u'Maria van Keulen', u'email': u'maria.vankeulen@mongodb.com'}

Message: SERVER-24081 fixed explainable count to respect hint
Branch: master
https://github.com/mongodb/mongo/commit/d222cf41518a58abc631fa6a046aadf9055bf93e

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