{"Entry":{"collection":"guc","key":"enable_distinct_reordering","name":"enable_distinct_reordering","aliases":[],"metadata":{"baseline":false,"boot_human":"Not specified","boot_val":null,"category":"Query Tuning / Planner Method Configuration","category_zh":"","changed_in":[],"changes":[{"documentation_changed":false,"fields":{},"from":"17","status":"added","to":"18"}],"content_hash":"555b53cb69c4df3c467e5cb0658e3c1f20a1f5193ed5e848375f03a6db2fd11c","context":"","default_changed_in":[],"default_history":[{"from":"18","to":"19","value":"on"}],"editorial":{"advice":{"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."},"mechanism":["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."],"pitfalls":["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."],"references":[{"title":"PostgreSQL 19 Beta 4: enable_distinct_reordering","url":"https://www.postgresql.org/docs/19/runtime-config-query.html#GUC-ENABLE-DISTINCT-REORDERING"},{"title":"PostgreSQL 19 release notes","url":"https://www.postgresql.org/docs/19/release-19.html"}],"related":["enable_sort","enable_incremental_sort","enable_presorted_aggregate","work_mem"],"summary":"enable_distinct_reordering — Enables reordering of DISTINCT keys. Observed in PG18–19 Beta 4; its last measured boot default is on in PG19 Beta 4, with user context. This is a beta-snapshot fact and can change before PostgreSQL 19 GA."},"enumvals":[],"first_version":"18","group":"Query Tuning","group_slug":"query","imported_at":"2026-09-27T17:57:31.174259+08:00","intro_commit":{"authored_at":"2024-11-26T09:25:18+09:00","discussion":["https://postgr.es/m/CAMbWs48dR26cCcX0f=8bja2JKQPcU64136kHk=xekHT9xschiQ@mail.gmail.com"],"hash":"a8ccf4e93a7eeaae66007bbf78cf9183ceb1b371","subject":"Reordering DISTINCT keys to match input path's pathkeys","url":"https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=a8ccf4e93a7eeaae66007bbf78cf9183ceb1b371"},"key":"enable_distinct_reordering","last_version":"20","max_val":"","min_val":"","name":"enable_distinct_reordering","position":114,"present_in":["18","19","20"],"short_desc":"Enables or disables the query planner's ability to reorder DISTINCT keys to match the input path's pathkeys.","short_desc_zh":"","source_rev":"english-manuals:3bd243a6f879d599b4076dcf440dc5e5685cdfd265d95184ed6761e8d95bcc35","unit":"","vartype":"bool"}},"Definition":{"Collection":"guc","Key":"enable_distinct_reordering","SourceDatabase":"center","Version":"18","SourceTable":"guc","SourceKey":"enable_distinct_reordering","SourceRevision":"english-manuals:3bd243a6f879d599b4076dcf440dc5e5685cdfd265d95184ed6761e8d95bcc35","Facts":{"boot_val":"on","category":"Query Tuning / Planner Method Configuration","context":"user","description":"Enables or disables the query planner's ability to reorder DISTINCT keys to match the input path's pathkeys. The default is on.","doc":{"anchor":"GUC-ENABLE-DISTINCT-REORDERING","file":"runtime-config-query.html","lang":"en","sha256":"33456ca7ef52bf28e93e34b932a411db7a1b95800179add2cf867dc6ec9144bc","slug":"18"},"documented":true,"enumvals":null,"extra_desc":null,"lang":"en","max_val":null,"metadata_version":"18","min_val":null,"name":"enable_distinct_reordering","short_desc":"Enables reordering of DISTINCT keys.","source":"pg-settings-source-snapshot","unit":null,"vartype":"bool"},"ManualEvidence":{"doc":{"anchor":"GUC-ENABLE-DISTINCT-REORDERING","file":"runtime-config-query.html","lang":"en","sha256":"33456ca7ef52bf28e93e34b932a411db7a1b95800179add2cf867dc6ec9144bc","slug":"18"}},"MeasuredEvidence":{"metadata_version":"18"}},"Text":{"Collection":"guc","Key":"enable_distinct_reordering","SourceDatabase":"pgweb","Version":"18","Locale":"zh-Hans","Title":"enable_distinct_reordering","Summary":"","BodyHTML":"\u003cp\u003e启用或禁用查询规划器重新排序\u003ccode\u003eDISTINCT\u003c/code\u003e键以匹配输入路径的路径键的能力。默认值为\u003ccode\u003eon\u003c/code\u003e。\u003c/p\u003e","SourceRevision":"2026-09-11@29c86d9","ContentHash":"eda164ee8de3dab63b4d6e5761edf187a052046414cc8fd59ec7094643428043","Payload":{"carried_from":"","carry_reason":"","doc_html":"\u003cp\u003e启用或禁用查询规划器重新排序\u003ccode class=\"literal\"\u003eDISTINCT\u003c/code\u003e键以匹配输入路径的路径键的能力。默认值为\u003ccode class=\"literal\"\u003eon\u003c/code\u003e。\u003c/p\u003e","doc_same_as":""}},"RequestedLocale":"zh-Hans","Fallback":false,"Versions":["18","19","20"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
