<!-- llms-explorer concept facts · https://llms-explorer.com/tree/equality-sort-range-index-ordering/ · pack 2026-10-20 · ~838 tokens -->

# Equality-Sort-Range index ordering

> Source-anchored research for Equality-Sort-Range index ordering. Run status: COMPLETED.

Parent: [MongoDB Explain Plans, Query Planner and Plan Cache](https://llms-explorer.com/tree/mongodb-explain-plans-query-planner-and-plan-cache/) · 3 facets · 8 facts · page: https://llms-explorer.com/tree/equality-sort-range-index-ordering/

## How it works

- ESR is a workload guideline: put all equality predicates first, in any relative order. Put sort fields before range fields when avoiding an in-memory sort matters, or use ERS when a range predicate is very selective and reducing scan work matters more. (high confidence) — [source](https://www.mongodb.com/docs/manual/tutorial/equality-sort-range-guideline.md)
- A compound index orders keys by the declared field sequence. MongoDB can use index order for a requested sort when equality predicates constrain all prefix keys before the sort keys; a non-point range before the sort generally disrupts that order and requires a blocking SORT stage. (high confidence) — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-compound.md)

## Comparisons and alternatives

- The ESR classification treats operators such as $ne, $nin, and $regex as range predicates rather than exact-match equality predicates. (high confidence) — [source](https://www.mongodb.com/docs/manual/tutorial/equality-sort-range-guideline.md)

## Facts and statements

- Compare ESR and ERS on representative data with explain('executionStats') and index hints. A SORT stage identifies an in-memory ordering step; compare totalKeysExamined and totalDocsExamined with nReturned to decide whether avoiding the sort outweighs scanning more index keys. (high confidence) — [source](https://www.mongodb.com/docs/manual/tutorial/equality-sort-range-guideline.md)
- For one query with equality predicates on several fields, the equality keys need not be ordered by selectivity. Their order still controls which leading index prefixes can support other query patterns, so choose an order that preserves useful prefixes. (high confidence) — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-compound.md)
- With $in combined with sort, the current MongoDB guide treats lists with fewer than 201 values as equality probes that can be merged in sort order; lists of 201 or more act like a range and prevent later index keys from supplying the sort. The guide warns that this cutoff can change across versions. (medium confidence) (verified as of 2026-10-14) — [source](https://www.mongodb.com/docs/manual/tutorial/equality-sort-range-guideline.md)
- MongoDB stores compound-index keys in the declared field sequence. The leftmost prefixes determine which query shapes the index supports, and sort use depends on equality constraints on preceding keys. (high confidence) — [source](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-compound.md)
- For a query with equality predicates, a sort, and a range, the baseline ESR order puts equality keys first, sort keys next, and range keys last. Equality keys can appear in any order relative to one another for that query, while their prefixes can affect support for other query shapes. (high confidence) — [source](https://www.mongodb.com/docs/manual/tutorial/equality-sort-range-guideline.md)
