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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 3.2.0
    • Fix Version/s: 3.3.14
    • Component/s: Querying, Shell
    • Labels:
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL
    • Steps To Reproduce:
      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"})
    • Sprint:
      Query 2016-09-19

      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
      }
      

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: