All Questions
Database Indexing medium

For query `SELECT * FROM tbl ORDER BY A ASC, B DESC`, what index is required to avoid a sort operation?

  1. A A standard individual index on column A followed by a secondary individual index on column B to allow for independent directional scans.
  2. B A composite index defined with mixed directions: `Index (A ASC, B DESC)` to match the query's required ordering exactly.
  3. C Two strictly independent indexes on A and B that the database optimizer can merge in real-time using a specialized 'Sort Intersection' algorithm.
  4. D A reverse-order composite index `Index (B, A)` that allows the database to perform a backward scan of the entire B-Tree from the final leaf node.

One system design question a day, with spaced repetition so the ones you miss come back.

Get the app

Related questions