Menu

Get the column order right on a composite index

bookings is filtered constantly by route, and about half of those queries add a second filter on status. Nothing ever filters by status alone. Create one composite index that serves both query shapes — filtering on route alone, and filtering on route AND status together — as efficiently as a single index can.

Column order in a composite index isn't arbitrary: an index on (a, b) can be used for a query that filters on a alone, but is far less useful for a query that filters on b alone. Put the columns in the order that matches how these queries actually filter.

Schema

bookings
idINT
routeTEXT
statusTEXT
fareNUMERIC

Example input

bookings
↑ Read the question

Keep going

Company names are trademarks of their respective owners, used here only to describe practice material. mahir_data is not affiliated with, endorsed by, or sponsored by any company named on this site. Terms.