top | item 45423708

(no title)

boramalper | 5 months ago

I find MongoDB's ESR (Equality, Sort, Range) Guideline[0] quite helpful in that regard, which applies to SQL databases as well (since nearly all of them too use B-trees).

> Index keys correspond to document fields. In most cases, applying the ESR (Equality, Sort, Range) Guideline to arrange the index keys helps to create a more efficient compound index.

> Ensure that equality fields always come first. Applying equality to the leading field(s) of the compound index allows you to take advantage of the rest of the field values being in sorted order. Choose whether to use a sort or range field next based on your index's specific needs:

> * If avoiding in-memory sorts is critical, place sort fields before range fields (ESR)

> * If your range predicate in the query is very selective, then put it before sort fields (ERS)

[0] https://www.mongodb.com/docs/manual/tutorial/equality-sort-r...

discuss

order

No comments yet.