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()

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Gone away
    • Affects Version/s: 3.2.5
    • Fix Version/s: None
    • Component/s: Querying
    • Labels:
      None
    • 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.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 }

      Attachments

        Activity

          People

          Assignee:
          kelsey.schubert Kelsey T Schubert
          Reporter:
          dmitry.ryabtsev Dmitry Ryabtsev
          Participants:
          Votes:
          0 Vote for this issue
          Watchers:
          8 Start watching this issue

            Dates

            Created:
            Updated:
            Resolved: