---
title: "All Your GUCs in a Row: enable_distinct_reordering and enable_group_by_reordering"
url: https://daily.dev/posts/all-your-gucs-in-a-row-enable-distinct-reordering-and-enable-group-by-reordering-xhdvyn0ky
source_url: https://postgr.es/p/9nj
type: article
source: "Planet PostgreSQL"
published: 2026-06-25T01:04:30.604Z
updated: 2026-06-25T01:05:04.500Z
tags: ["database", "postgresql"]
reading_time: 5
upvotes: 0
comments: 0
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# All Your GUCs in a Row: enable_distinct_reordering and enable_group_by_reordering

**[Planet PostgreSQL](https://daily.dev/sources/planet-postgresql)** · 5 min read · 0 upvotes · 0 comments

## Summary

PostgreSQL 17 and 18 introduced two planner GUCs — enable_group_by_reordering and enable_distinct_reordering — that allow the query planner to permute the keys of GROUP BY and SELECT DISTINCT operations to minimize comparison costs and avoid redundant sorts. Since column order in these clauses carries no semantic meaning, the planner can reorder keys based on cardinality and comparison cost statistics, or align them with existing sort orders to skip explicit sorts. Both default to on and are micro-optimizations that matter mainly for large multi-key operations. The primary diagnostic use case is a query that regressed after upgrading to PostgreSQL 17 or 18, where the plan shows a key order different from what was written. The recommended fix is usually improving statistics via ANALYZE rather than disabling the GUC permanently.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://postgr.es/p/9nj>

## Similar posts on daily.dev

- [All Your GUCs in a Row: enable\_incremental\_sort](https://daily.dev/posts/all-your-gucs-in-a-row-enable-incremental-sort-xf4skwqco) · Planet PostgreSQL · 0 upvotes · 0 comments
- [All Your GUCs in a Row: enable\_sort](https://daily.dev/posts/all-your-gucs-in-a-row-enable-sort-0rm81treg) · Planet PostgreSQL · 0 upvotes · 0 comments
- [All Your GUCs in a Row: enable\_partitionwise\_aggregate](https://daily.dev/posts/all-your-gucs-in-a-row-enable-partitionwise-aggregate-ueyio1g1l) · Planet PostgreSQL · 0 upvotes · 0 comments
- [All Your GUCs in a Row: enable\_partitionwise\_join](https://daily.dev/posts/all-your-gucs-in-a-row-enable-partitionwise-join-h9fl73to0) · Planet PostgreSQL · 0 upvotes · 0 comments
- [All Your GUCs in a Row: enable\_gathermerge](https://daily.dev/posts/all-your-gucs-in-a-row-enable-gathermerge-2y7lebrae) · Planet PostgreSQL · 0 upvotes · 0 comments

---

Tags: [#database](https://daily.dev/tags/database), [#postgresql](https://daily.dev/tags/postgresql)

[View this post on daily.dev](https://daily.dev/posts/all-your-gucs-in-a-row-enable-distinct-reordering-and-enable-group-by-reordering-xhdvyn0ky)
