{"Entry":{"collection":"guc","key":"enable_sort","name":"enable_sort","aliases":[],"metadata":{"baseline":true,"boot_human":"Not specified","boot_val":null,"category":"Query Tuning / Planner Method Configuration","category_zh":"","changed_in":[],"changes":[{"documentation_changed":true,"fields":{},"from":"7.4","status":"changed","to":"8.0"},{"documentation_changed":true,"fields":{},"from":"8.4","status":"changed","to":"9.0"}],"content_hash":"a924d50adadb7648c11973cb1211aeb7424d563c8fef782aaac18d3160261438","context":"","default_changed_in":[],"default_history":[{"from":"9.0","to":"19","value":"on"}],"editorial":{"advice":{"olap":"Benchmark representative analytical plans with and without enable_sort. Judge planning time, memory, spill, and execution time together; a win for one report is not evidence for a global setting.","oltp":"Keep the upstream default for routine OLTP. Use a transaction- or session-local change to diagnose whether choosing explicit Sort nodes when no usable input order satisfies the requested pathkeys explains a regression, then repair statistics, indexes, estimates, or query shape instead of leaving a cluster-wide method ban.","small":"Do not use enable_sort as a permanent hint on a small host. Resource pressure may change the best method, so verify with EXPLAIN (ANALYZE, BUFFERS) and keep the change scoped to the affected workload if it is still needed."},"mechanism":["enable_sort controls whether the planner may choose explicit Sort nodes when no usable input order satisfies the requested pathkeys.","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.","Turning it off only discourages explicit sorting because correctness can still require a sort. Its user context permits session- or transaction-local changes; newly performed or newly planned work sees the value."],"pitfalls":["Treating enable_sort 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.","Turning it off only discourages explicit sorting because correctness can still require a sort."],"references":[{"title":"PostgreSQL 19 Beta 4: enable_sort","url":"https://www.postgresql.org/docs/19/runtime-config-query.html#GUC-ENABLE-SORT"},{"title":"PostgreSQL 19 release notes","url":"https://www.postgresql.org/docs/19/release-19.html"}],"related":["work_mem","temp_file_limit","enable_incremental_sort","enable_gathermerge","trace_sort"],"summary":"enable_sort — Enables the planner's use of explicit sort steps. Observed in PG9.0–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":"7.4","group":"Query Tuning","group_slug":"query","imported_at":"2026-09-27T17:57:31.243638+08:00","intro_commit":{},"key":"enable_sort","last_version":"20","max_val":"","min_val":"","name":"enable_sort","position":136,"present_in":["7.4","8.0","8.1","8.2","8.3","8.4","9.0","9.1","9.2","9.3","9.4","9.5","9.6","10","11","12","13","14","15","16","17","18","19","20"],"short_desc":"Enables or disables the query planner's use of explicit sort steps.","short_desc_zh":"","source_rev":"english-manuals:5c02c99f6b3f0081f7d74f02a573aec6d577ca258e63424fcbb8466b227180ff","unit":"","vartype":"bool"}},"Definition":{"Collection":"guc","Key":"enable_sort","SourceDatabase":"center","Version":"18","SourceTable":"guc","SourceKey":"enable_sort","SourceRevision":"english-manuals:5c02c99f6b3f0081f7d74f02a573aec6d577ca258e63424fcbb8466b227180ff","Facts":{"boot_val":"on","category":"Query Tuning / Planner Method Configuration","context":"user","description":"Enables or disables the query planner's use of explicit sort steps. It is impossible to suppress explicit sorts entirely, but turning this variable off discourages the planner from using one if there are other methods available. The default is on.","doc":{"anchor":"GUC-ENABLE-SORT","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_sort","short_desc":"Enables the planner's use of explicit sort steps.","source":"pg-settings-source-snapshot","unit":null,"vartype":"bool"},"ManualEvidence":{"doc":{"anchor":"GUC-ENABLE-SORT","file":"runtime-config-query.html","lang":"en","sha256":"33456ca7ef52bf28e93e34b932a411db7a1b95800179add2cf867dc6ec9144bc","slug":"18"}},"MeasuredEvidence":{"metadata_version":"18"}},"Text":{"Collection":"guc","Key":"enable_sort","SourceDatabase":"center","Version":"18","Locale":"en","Title":"enable_sort","Summary":"Enables or disables the query planner's use of explicit sort steps. It is impossible to suppress explicit sorts entirely, but turning this variable off discourages the planner from using one if there are other methods available. The default is on.","BodyHTML":"\u003cp\u003eEnables or disables the query planner\u0026#39;s use of explicit sort steps. It is impossible to suppress explicit sorts entirely, but turning this variable off discourages the planner from using one if there are other methods available. The default is on.\u003c/p\u003e","SourceRevision":"english-manuals:5c02c99f6b3f0081f7d74f02a573aec6d577ca258e63424fcbb8466b227180ff","ContentHash":"3b956fb3b2a0cbf2ca2e890ff80a518eb98a72daa0a6eb798a3056e3f79cb352","Payload":{"description":"Enables or disables the query planner's use of explicit sort steps. It is impossible to suppress explicit sorts entirely, but turning this variable off discourages the planner from using one if there are other methods available. The default is on."}},"RequestedLocale":"zh-Hans","Fallback":true,"Versions":["10","11","12","13","14","15","16","17","18","19","20","7.4","8.0","8.1","8.2","8.3","8.4","9.0","9.1","9.2","9.3","9.4","9.5","9.6"],"Locales":["en"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
