<!-- llms-explorer concept facts · https://llms-explorer.com/tree/forcing-plans-with-hint-and-internal-query-knobs/ · pack 2026-10-20 · ~1385 tokens -->

# Forcing plans with hint and internal query knobs

> Source-anchored research for Forcing plans with hint and internal query knobs. Run status: COMPLETED.

Parent: [MongoDB Compound Index Design: ESR, Selectivity, Covering and Multikey Bounds](https://llms-explorer.com/tree/mongodb-compound-index-design-esr-selectivity-covering-and-multikey-bounds/) · 5 facets · 13 facts · page: https://llms-explorer.com/tree/forcing-plans-with-hint-and-internal-query-knobs/

## Structure and components

- If a matching cluster query setting contains indexHints, that setting takes precedence over a command-level hint and MongoDB ignores the command hint. (high confidence) (verified as of 2026-10-20) — [source](https://www.mongodb.com/docs/manual/reference/command/setquerysettings/)

## How it works

- A forced index can perform worse when data distribution changes. Percona advises using hint() only in extreme cases, and OneUptime recommends comparing hinted and unhinted executionStats with explain() before relying on the forced plan. (medium confidence) — [source](https://www.percona.com/blog/mongodb-query-plan-cache-explained-performance-pitfalls-and-re-planning/)
- Percona advises reserving `hint()` for extreme cases: it says production use is not ideal, but a hint can stabilize a pathological query while its cause is investigated. (low confidence) — [source](https://www.percona.com/blog/mongodb-query-plan-cache-explained-performance-pitfalls-and-re-planning/)
- A 2024 study of MongoDB 7.0.1 reports that the first-past-the-post planner sometimes selected an index scan even when a collection scan ran faster. This is evidence of possible plan-choice errors, not a measurement that `hint()` or `queryKnobs` improves production performance. (low confidence) — [source](https://arxiv.org/abs/2409.16544)

## Problems, failure modes and limitations

- `cursor.hint()` forces a specified index by name or key pattern, and `$natural: 1` or `$natural: -1` forces a forward or reverse collection scan. The method rejects a missing or hidden index and cannot specify an index for a `$text` query. (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.hint.md)

## Comparisons and alternatives

- MongoDB deprecated index filters in version 8.0 and recommends query settings as their replacement; query settings provide broader functionality and persist across restarts, unlike index filters. (high confidence) (verified as of 2026-10-20) — [source](https://www.mongodb.com/docs/manual/reference/command/setquerysettings/)
- MongoDB 9.0 `queryKnobs` can override selected internal server parameters for one query shape instead of the whole instance. MongoDB accepts only knobs marked settable for query settings and validates their type, range, enum value, and minimum FCV; a per-shape value takes precedence over `setParameter` and the compiled-in default. (high confidence) (verified as of 2026-10-20) — [source](https://www.mongodb.com/docs/manual/reference/command/setquerysettings/)
- In the MongoDB 9.0 query-knob definitions, `internalQueryForceIntersectionPlans` maps to the per-shape knob `forceIntersectionPlans`; enabling it gives index-intersection plans a large ranking bonus and makes them win when possible. This steers toward a plan class rather than naming one specific index. (high confidence) (verified as of 2026-10-20) — [source](https://github.com/mongodb/mongo/blob/35647d07bc4bc11966c90fe7100eb1db0b0ac1d9/src/mongo/db/query/query_optimization_knobs.idl)

## Facts and statements

- Cluster query settings can attach indexHints to a query shape. They restrict the indexes available to the planner but do not guarantee an index plan; MongoDB may still choose a collection scan. Percona describes the query-shape hinting feature as cluster-wide. (high confidence) (verified as of 2026-10-20) — [source](https://www.mongodb.com/docs/manual/reference/command/setquerysettings/)
- MongoDB 9.0 adds queryKnobs to setQuerySettings for overriding internal server parameters on one query shape; FCV 9.0 or later is required. Only knobs marked as settable through query settings are accepted, and MongoDB validates types, ranges, enum values, and FCV requirements. (high confidence) (verified as of 2026-10-20) — [source](https://www.mongodb.com/docs/manual/reference/command/setquerysettings/)
- MongoDB's query knob IDL describes internalQueryForceIntersectionPlans as giving intersection plans a large ranking bonus and internalQueryPlannerEnableIndexIntersection as controlling whether those plans are generated and considered. These knobs influence planner candidates or ranking; they do not name a particular compound index. (medium confidence) (verified as of 2026-10-20) — [source](https://github.com/mongodb/mongo/blob/35647d07bc4bc11966c90fe7100eb1db0b0ac1d9/src/mongo/db/query/query_optimization_knobs.idl)
- If an index filter exists for a query shape, MongoDB ignores `cursor.hint()`. An index filter only limits the indexes evaluated; the planner can still select a collection scan. (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/method/cursor.hint.md)
- Cluster query settings persist across restarts and apply to executions of a matching query shape. Their `indexHints.allowedIndexes` restricts planner candidates without guaranteeing an index plan, and a matching cluster setting takes precedence over an index hint supplied with the command. (high confidence) — [source](https://www.mongodb.com/docs/manual/reference/command/setquerysettings/)
