flâneur — a map of the web's best reading

PostgreSQL: Documentation: 16: 11.4. Indexes and ORDER BY

postgresql.org · 666 words · saved by 1 readers

In addition to simply finding the rows to be returned by a query, an index may be able to deliver them in a specific sorted order. This allows a query's ORDER BY specification to be honored without a separate sorting step. Of the index types currently supported by PostgreSQL, only B-tree can produce sorted output — the other index types return matching rows in an unspecified, implementation-dependent order. The planner will consider satisfying an ORDER BY specification either by scanning an available index that matches the specification, or by scanning the table in physical order and doing an explicit sort. For a query that requires scanning a large fraction of the table, an explicit sort is likely to be faster than using an index because it requires less disk I/O due to following a sequential access pattern. Indexes are more useful when only a few rows need be fetched. An important special case is ORDER BY in combination with LIMIT n: an explicit sort will have to process all the data

PostgreSQL: Documentation: 18: 11.4. Indexes and ORDER BY July 16, 2026: PostgreSQL 19 Beta 2 Released! Documentation → PostgreSQL 18 Supported Versions: Current ( 18 ) / 17 / 16 / 15 / 14 Development Versions: 19 / devel Unsupported versions: 13 / 12 / 11 / 10 / 9.6 / 9.5 / 9.4 / 9.3 / 9.2 / 9.1 / 9.0 / 8.4 / 8.3 11.4. Indexes and ORDER BY Prev Up Chapter 11. Indexes Home Next 11.4. Indexes and ORDER BY # In addition to simply finding the rows to be returned by a query, an index may be able to deliver them in a specific sorted order. This allows a query's ORDER BY specification to be hon

Explore this link on the map →

related reading