SERVER-129387ClosedFixed

Optimize $queryStats for top-k metrics.workingTimeMillis.sum sort + limit pattern

We have an observed production pattern where Atlas observability runs a {{$queryStats}} aggregation of the form: This is one of the two {{$queryStats}} pipelines run every 60 seconds, and it has been called out as a recurring expensive shape on large clusters with high query-shape cardinality. In the customer investigation discussed in Slack, a slow query log for this exact pattern showed about 9.8s of CPU / working time for a single invocation. On the same cluster, {{serverStatus.metr

Affected Versions
Versions known to exhibit this issue

No affected versions recorded.

Fixed Versions
Versions that include the fix
9.1.0-rc09.1.0-rc10249.0.7
Components
Server components related to this issue

No components specified.

Labels
Tags and classification
dino-90-desireddino-query-stats