DB Internals AtlasPostgreSQL 18.6 Home About

Parameter · Query Tuning / Planner Method Configuration

enable_sort

Enables the planner's use of explicit sort steps.

  • Default: on
  • Type: bool
  • Applies: Session (any user)

In plain words

Many queries need sorted rows (ORDER BY, merge joins, grouping). PostgreSQL either sorts explicitly or reads rows in index order. Turning this off pushes the planner toward index order; a sort still happens if there is no other way.

For DBAs and operators

A Sort node sorts in memory up to work_mem (quicksort, or top-N heapsort for small LIMITs) and otherwise does an external merge sort with temp files: EXPLAIN ANALYZE shows Sort Method: quicksort Memory: …kB or Sort Method: external merge Disk: …kB.

Measured on 18.6: SELECT * FROM u ORDER BY c without a suitable index gives Sort → Seq Scan, cost 10,096. With enable_sort = off the plan is identical but marked Disabled: true, because nothing else can produce the order. The animation uses illustrative costs for a table that also has an index on the sort column.

Turning this off does not affect sorting done inside other nodes: incremental sort has its own switch, and aggregates with ORDER BY sort internally unless enable_presorted_aggregate lets the plan do it. Use it to check whether an index-ordered plan would be faster, especially for ORDER BY … LIMIT, where a sort must read every row before returning the first.

How to change it

Any user can change it for their session with SET.

See it in context

Local (per-backend) memory Planner cost model

Related parameters

enable_incremental_sort work_mem enable_gathermerge enable_presorted_aggregate

All Query Tuning parameters