-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
-
Query Optimization
-
(copied to CRM)
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.