enable_distinct_reordering
Read PG 18 manual ↗Enables or disables the query planner's ability to reorder DISTINCT keys to match the input path's pathkeys.
- Type
- bool
- Context
- user
- Measured default
- on
- Unit
- —
- Metadata snapshot
- 18
Definition PG 18 manual
Enables or disables the query planner's ability to reorder DISTINCT keys to match the input path's pathkeys. The default is on.
Measured default history
| Version interval | Default |
|---|---|
| 18 – 19 | on |
Authored guidance from the GUC source snapshot; the version-specific manual above is the definition reference. View source ↗
How it works
enable_distinct_reordering controls whether the planner may choose reordering DISTINCT keys to match useful input pathkeys and avoid or reduce sorting.
It is consulted while a plan is built. A session-level change is useful for comparing EXPLAIN alternatives, but an already cached plan is not retroactively rewritten; invalidation or replanning is required to observe a different choice.
The switch changes which candidate paths the planner may cost; it does not make the chosen method faster by itself. Its user context permits session- or transaction-local changes; newly performed or newly planned work sees the value.
Operational considerations
Treating enable_distinct_reordering as a query hint even though it affects every plan built in its scope.
Testing an already cached prepared plan and concluding that the setting has no effect.
Masking stale statistics or cardinality errors by disabling a plan method globally.
The switch changes which candidate paths the planner may cost; it does not make the chosen method faster by itself.
Workload guidance
OLAP: Large DISTINCT operations can benefit when reordering exploits index, merge, or existing sort order. Measure sort memory, spill volume, planning time, and total execution rather than disabling the optimization globally after one plan.
OLTP: Keep the PG18 default on. For a suspected regression, compare session-local plans and verify whether reordered DISTINCT keys actually match useful input pathkeys or merely trade one sort for another.
SMALL: Keep on unless a reproducible plan regression is demonstrated. If sorts spill, correct work_mem and plan inputs before treating this planner switch as a permanent hint.
Version history 1
- PG 17 → 18added
Related entries
Further reading
Definition snapshot: english-manuals:32c38bf6c420cd4aa220687d721… · English manual source