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

db.collection.explain().count() does not respect hint option

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.3.14
    • Affects Version/s: 3.2.0
    • Component/s: Querying, Shell
    • Fully Compatible
    • ALL
    • Hide
      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"})
      
      Show
      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"})
    • Query 2016-09-19

      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
      }
      

            Assignee:
            maria.vankeulen@mongodb.com Maria van Keulen
            Reporter:
            kelsey.schubert@mongodb.com Kelsey Schubert
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: