Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardSQLthe query planner optimizerSingle-choice MCQ

In PostgreSQL, the planner can choose an 'incremental sort' when a query needs ordering by (a, b) and an index already provides rows ordered by a. What does this actually do at execution time, and why is it cheaper than a full sort?

SELECT * FROM t WHERE a IS NOT NULL ORDER BY a, b; -- index exists on (a)