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

Allow $indexStats access counters to be manually reset

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Optimization

      Index access counters can only be reset by recreating the index or restarting the mongod. Under certain circumstances such as maintenance activities it is desirable to begin measuring anew how indexes are being accessed.

      Currently this can be accomplished by dropping/recreating the index:

      db.foo.drop();
      db.foo.createIndex({ a: 1 })
      db.foo.insert({ a: 1 })
      db.foo.find({ a: 1 })
      db.foo.find({ a: 1 })
      db.foo.find({ a: 1 })
      var a = db.foo.aggregate({ $indexStats: {} }, { $match: { name: "a_1" } }).toArray()[0].accesses
      assert.eq(a.ops, 3);
      db.foo.dropIndex("a_1")
      db.foo.createIndex({ a: 1 });
      var b = db.foo.aggregate({ $indexStats: {} }, { $match: { name: "a_1" } }).toArray()[0].accesses
      assert.eq(b.ops, 0);
      

      This is undesirable as while the index is being recreated operations that used that index may resort to COLLSCANs instead. An alternate approach of recreating the index with a "dummy" field could be done as well, but this would still incur the cost of building a new index.

      If resetting counters is needed, a new command and shell helper (command: resetIndexCounters / collection helper: db.collection.resetIndexCounters(indexName)) could be introduced to handle this functionality.

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            alex.bevilacqua@mongodb.com Alex Bevilacqua
            Votes:
            2 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: