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