<!-- llms-explorer concept facts · https://llms-explorer.com/tree/ers-exception-for-selective-range-predicates/ · pack 2026-10-21 · ~528 tokens -->

# ERS exception for selective range predicates

> Source-anchored research for ERS exception for selective range predicates. 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/) · 4 facets · 4 facts · page: https://llms-explorer.com/tree/ers-exception-for-selective-range-predicates/

## How it works

- The selective-range exception changes only the order of the Range and Sort keys: keep Equality fields first, then use ERS when the range narrows results enough to make sorting the smaller set worthwhile; otherwise favor ESR when avoiding an in-memory sort matters. (high confidence) — [source](https://www.mongodb.com/docs/manual/tutorial/equality-sort-range-guideline/)

## Problems, failure modes and limitations

- When a range key precedes a distinct sort key, the compound index generally cannot provide the requested global sort order. ERS trades index-provided order for a blocking in-memory sort after range filtering; ESR avoids that sort but can scan more index keys. (high confidence) — [source](https://www.mongodb.com/docs/manual/tutorial/equality-sort-range-guideline/)

## Comparisons and alternatives

- MongoDB's manual describes the condition qualitatively as a range predicate that is 'very selective' and sets no numeric cutoff on this page. An independent worked example says the winning order depends on the data, so assess the tradeoff on representative data instead of treating ERS as a fixed selectivity threshold. (medium confidence) — [source](https://www.mongodb.com/docs/manual/tutorial/equality-sort-range-guideline/)

## Facts and statements

- In one synthetic 200,000-order example, for total >= 499, the ESR index scanned 2,338 keys to return one order while the ERS index scanned one key and sorted that one result; this illustrates a possible ERS win, not a portable performance ratio. (low confidence) (verified as of 2023-07-09) — [source](https://ozgurgurcan.com/blog/mongodb-compound-indexes-esr-rule)
