← Lessons

quiz vs the machine

Gold1340

Databases

Descending Indexes

Why declaring sort direction per column speeds up mixed order queries.

4 min read · core · beat Gold to climb

Direction Per Column

By default an index stores keys in ascending order. A descending index stores one or more columns in reverse order. This matters most for ORDER BY clauses that mix directions across columns.

Why Mixed Order Needs It

An index can be read forward or backward, so a single column sort either way is free. But consider an ORDER BY on column a ascending and column b descending. A plain ascending index on a, b cannot satisfy this by reading in either direction, because no single traversal produces ascending a with descending b.

An index declared as a ascending and b descending matches the request exactly, letting the engine return rows in order without a separate sort step.

Practical Notes

  • Descending indexes help top N queries that need the highest or lowest values first.
  • They are only valuable when the query order mixes directions or when backward scans are awkward for the engine.
  • The leading column choice and prefix rules still apply.

Key idea

Descending indexes set sort direction per column so the engine can serve mixed direction ORDER BY clauses directly without an extra sort.

Check yourself

Answer to earn rating on the learn ladder.

1. When is a descending index most valuable?

2. Why can a plain ascending index handle a single column descending sort without help?