<!-- llms-explorer concept facts · https://llms-explorer.com/tree/query-settings-and-index-filters-as-plan-pinning/ · pack 2026-10-30 · ~1392 tokens -->

# Query settings and index filters as plan pinning

> Source-anchored research for Query settings and index filters as plan pinning. Run status: COMPLETED.

Parent: [Replanning loops and replanReason](https://llms-explorer.com/tree/replanning-loops-and-replanreason/) · 3 facets · 16 facts · page: https://llms-explorer.com/tree/query-settings-and-index-filters-as-plan-pinning/

## How it works

- Index hints in query settings restrict the planner's available indexes but do not guarantee an index scan; legacy index filters likewise allow a collection scan. Neither mechanism guarantees an exact execution plan. (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/command/setQuerySettings.md)
- Before interpreting an index-hiding trial, inspect restrictions that reference the candidate or exclude alternatives. This is a methodological inference: a legacy filter restricted to the hidden index can produce a collection scan even when another visible index could otherwise support the query. (medium confidence) — [source](https://www.mongodb.com/docs/manual/reference/command/planCacheSetFilter.md)
- Tencent recommends restricting only critical queries whose plan drift would cause an incident and reconsidering settings when data distribution changes. MinervaDB similarly presents query settings as a mitigation and recommends removing the setting after a durable indexing correction. (medium confidence) — [source](https://proxy-hk.tencentcloud.com/document/product/240/81407)
- Legacy index filters last only for the server process. Campbell independently reported rejecting filters in a 2017 production incident because they did not survive restarts. (medium confidence) — [source](https://www.mongodb.com/docs/manual/reference/command/planCacheSetFilter.md)

## Problems, failure modes and limitations

- MongoDB 8.0 introduced setQuerySettings and deprecated index filters; query settings apply to matching query shapes across the cluster and persist across restarts, while legacy index filters are process-local and disappear at shutdown. (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/command/setQuerySettings.md)
- If the indexes named by a legacy index filter do not exist or are hidden, MongoDB documents a collection scan. A hidden index is unavailable to the planner and cannot be selected with cursor.hint(). (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/command/planCacheSetFilter.md)
- If matching query settings contain index hints, MongoDB ignores command-level index hints. A client hint alone therefore cannot prove which index candidates the planner received. (low confidence) — [source](https://www.mongodb.com/docs/manual/reference/command/setQuerySettings.md)
- SERVER-60710 reports indexFilterSet remaining false with executionStats verbosity despite an applied filter, tested on 4.4.9 and 5.0.2; the issue lists fix version 6.0.0-rc0. On those historical versions, that flag alone cannot establish that a filter is absent. (low confidence) — [source](https://jira.mongodb.org/browse/SERVER-60710)
- MongoDB introduced query settings in 8.0 and deprecated legacy index filters in 8.0. Query settings apply to matching query shapes cluster-wide and persist across restarts. (medium confidence) — [source](https://www.mongodb.com/docs/manual/reference/command/setQuerySettings.md)
- MongoDB 8.0 hidden indexes cannot support queries and cannot be selected with cursor.hint(); unhiding a maintained index makes it immediately available again. (low confidence) — [source](https://www.mongodb.com/docs/v8.0/core/index-hidden/)

## Facts and statements

- Inspect configured query settings with db.aggregate([{ $querySettings: {} }]); remove obsolete settings with removeQuerySettings. Verify applied settings and the actual winning plan with explain. (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/command/setQuerySettings.md)
- SERVER-33303 reproduces MongoDB 3.6.2 retaining a legacy filter after dropping its target index but temporarily not applying it; creating another index makes the filter apply again and selects COLLSCAN. The issue lists fix version 4.1.5. This is historical evidence, not a claim that current releases retain the bug. (low confidence) — [source](https://jira.mongodb.org/browse/SERVER-33303)
- If all indexes specified by a legacy filter are hidden or absent, the optimizer uses a collection scan. A removal rehearsal must therefore inspect filters, not just index usage. (medium confidence) — [source](https://www.mongodb.com/docs/manual/reference/command/planCacheSetFilter.md)
- For legacy filters, check explain.indexFilterSet. Their shape includes query, sort, projection and collation; predicate literal values do not distinguish matching shapes. (low confidence) — [source](https://www.mongodb.com/docs/manual/reference/command/planCacheSetFilter.md)
- Tencent recommends restricting index choices only for critical queries, testing representative parameters, and revisiting restrictions after data-distribution changes. This is operational guidance, not an execution-plan guarantee. (low confidence) — [source](https://proxy-hk.tencentcloud.com/document/product/240/81407)
- Campbell reported that a frequent outlier literal caused an index choice unsuitable for most queries sharing its shape. This historical incident motivates testing parameter diversity before applying shape-wide restrictions. (low confidence) — [source](https://youdidwhatwithtsql.com/mongodb-occasionally-naughty-query/2284/)
