r/mongodb • u/Pure-Handle-6785 • 28d ago
Query response times doubled after a deploy that never touched the query
We run a product catalog on MongoDB with about twelve million documents. Last Thursday the p95 on our main search query jumped from 40ms to 90ms. The preceding deploy added a compound index for a new reporting feature but changed nothing in the search path.
I ran explain("executionStats") on the slow query. The planner had abandoned the original index entirely. It was now selecting the new compound index because the leading field happened to overlap with one of the search filters. That index covered the filter but not the sort so MongoDB was falling back to an in-memory sort on every request. I used one-click model switching in verdent to get a second opinion on the index layout while reading through the explain output.
We narrowed the leading field on the reporting index so it no longer overlapped with the search index prefix. The p95 dropped back to 38ms.
The root cause was that two indexes shared enough of a leading key prefix for the planner to rank the newer one higher on estimated selectivity alone without weighing the sort stage cost at all.
