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

The "hint" option does not have any effect on the index selected by db.collection.count()

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.2.5
    • Component/s: Querying
    • Labels:
      None
    • 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.count({a:1, b:2}, {hint: "a_1_b_1"})
      

      In the log:

      2016-05-06T14:09:26.241+1000 D QUERY    [conn56] Relevant index 0 is kp: { a: 1.0, b: 1.0 } name: 'a_1_b_1' io: { v: 1, key: { a: 1.0, b: 1.0 }, name: "a_1_b_1", ns: "test.testcounthint" }
      2016-05-06T14:09:26.241+1000 D QUERY    [conn56] Relevant index 1 is kp: { b: 1.0, a: 1.0 } name: 'b_1_a_1' io: { v: 1, key: { b: 1.0, a: 1.0 }, name: "b_1_a_1", ns: "test.testcounthint" }
      2016-05-06T14:09:26.241+1000 D QUERY    [conn56] Relevant index 2 is kp: { a: 1.0, b: 1.0, c: 1.0 } name: 'a_1_b_1_c_1' io: { v: 1, key: { a: 1.0, b: 1.0, c: 1.0 }, name: "a_1_b_1_c_1", ns: "test.testcounthint" }
      2016-05-06T14:09:26.241+1000 D QUERY    [conn56] Using fast count: query: { a: 1.0, b: 2.0 } sort: {} projection: {}, planSummary: COUNT_SCAN { b: 1.0, a: 1.0 }
      
      db.testcounthint.count({a:1, b:2}, {hint: "a_1_b_1_c_1"});

      In the log:

      2016-05-06T14:08:42.997+1000 D QUERY    [conn56] Relevant index 0 is kp: { a: 1.0, b: 1.0 } name: 'a_1_b_1' io: { v: 1, key: { a: 1.0, b: 1.0 }, name: "a_1_b_1", ns: "test.testcounthint" }
      2016-05-06T14:08:42.997+1000 D QUERY    [conn56] Relevant index 1 is kp: { b: 1.0, a: 1.0 } name: 'b_1_a_1' io: { v: 1, key: { b: 1.0, a: 1.0 }, name: "b_1_a_1", ns: "test.testcounthint" }
      2016-05-06T14:08:42.997+1000 D QUERY    [conn56] Relevant index 2 is kp: { a: 1.0, b: 1.0, c: 1.0 } name: 'a_1_b_1_c_1' io: { v: 1, key: { a: 1.0, b: 1.0, c: 1.0 }, name: "a_1_b_1_c_1", ns: "test.testcounthint" }
      2016-05-06T14:08:42.997+1000 D QUERY    [conn56] Using fast count: query: { a: 1.0, b: 2.0 } sort: {} projection: {}, planSummary: COUNT_SCAN { b: 1.0, a: 1.0 }
      
      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.count({a:1, b:2}, {hint: "a_1_b_1" }) In the log: 2016-05-06T14:09:26.241+1000 D QUERY [conn56] Relevant index 0 is kp: { a: 1.0, b: 1.0 } name: 'a_1_b_1' io: { v: 1, key: { a: 1.0, b: 1.0 }, name: "a_1_b_1", ns: "test.testcounthint" } 2016-05-06T14:09:26.241+1000 D QUERY [conn56] Relevant index 1 is kp: { b: 1.0, a: 1.0 } name: 'b_1_a_1' io: { v: 1, key: { b: 1.0, a: 1.0 }, name: "b_1_a_1", ns: "test.testcounthint" } 2016-05-06T14:09:26.241+1000 D QUERY [conn56] Relevant index 2 is kp: { a: 1.0, b: 1.0, c: 1.0 } name: 'a_1_b_1_c_1' io: { v: 1, key: { a: 1.0, b: 1.0, c: 1.0 }, name: "a_1_b_1_c_1", ns: "test.testcounthint" } 2016-05-06T14:09:26.241+1000 D QUERY [conn56] Using fast count: query: { a: 1.0, b: 2.0 } sort: {} projection: {}, planSummary: COUNT_SCAN { b: 1.0, a: 1.0 } db.testcounthint.count({a:1, b:2}, {hint: "a_1_b_1_c_1" }); In the log: 2016-05-06T14:08:42.997+1000 D QUERY [conn56] Relevant index 0 is kp: { a: 1.0, b: 1.0 } name: 'a_1_b_1' io: { v: 1, key: { a: 1.0, b: 1.0 }, name: "a_1_b_1", ns: "test.testcounthint" } 2016-05-06T14:08:42.997+1000 D QUERY [conn56] Relevant index 1 is kp: { b: 1.0, a: 1.0 } name: 'b_1_a_1' io: { v: 1, key: { b: 1.0, a: 1.0 }, name: "b_1_a_1", ns: "test.testcounthint" } 2016-05-06T14:08:42.997+1000 D QUERY [conn56] Relevant index 2 is kp: { a: 1.0, b: 1.0, c: 1.0 } name: 'a_1_b_1_c_1' io: { v: 1, key: { a: 1.0, b: 1.0, c: 1.0 }, name: "a_1_b_1_c_1", ns: "test.testcounthint" } 2016-05-06T14:08:42.997+1000 D QUERY [conn56] Using fast count: query: { a: 1.0, b: 2.0 } sort: {} projection: {}, planSummary: COUNT_SCAN { b: 1.0, a: 1.0 }

          Assignee:
          kelsey.schubert@mongodb.com Kelsey Schubert
          Reporter:
          dmitry.ryabtsev@mongodb.com Dmitry Ryabtsev
          Votes:
          0 Vote for this issue
          Watchers:
          7 Start watching this issue

            Created:
            Updated:
            Resolved: