SQL-ADVANCED5 MIN READ
Index for ORDER BY ... LIMIT on Purpose
Choose an index shape that matches a filtered, ordered, limited query instead of indexing columns in an arbitrary sequence.
The best index is the one that lets PostgreSQL both find the right subset and read it in the needed order. Separate indexes often still leave a large sort. A purpose-built multicolumn B-tree can let the engine stop early once the LIMIT is satisfied.
Read the full lesson
Sign up free — one personalized lesson every day, matched to your role and goals.
Already have an account? Sign in