[SERVER-44478] Allow $indexStats access counters to be manually reset Created: 07/Nov/19  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Alex Bevilacqua Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 2
Labels: qopt-team
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Optimization
Participants:
Case:

 Description   

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.



 Comments   
Comment by Taras Mykhailovych [ 29/May/21 ]

> Isn't it incredibly easy just to get the delta of the counter before the index creation and after?
it's not incredibly easy for secondaries, as u can't forward the `$indexStats` to the same secondary twice and must repeat collecting everything to dictionary until u get the needed replica coverage. unless i'm missing something, for sure

Comment by Carl Champain (Inactive) [ 08/Nov/19 ]

Passing this ticket along to the Query team.

Comment by Alex Bevilacqua [ 07/Nov/19 ]

That would be the currently recommended method.

The goal here is to remove the need for external tracking of changes (though this could technically just be written to a collection within the database for stats ...).

Comment by Danny Hatcher (Inactive) [ 07/Nov/19 ]

Isn't it incredibly easy just to get the delta of the counter before the index creation and after?

Generated at Thu Feb 08 05:06:06 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.