{"Entry":{"collection":"guc","key":"enable_self_join_elimination","name":"enable_self_join_elimination","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":"9d8fc0b0c5a50a1fe725250fe59797040579ded983ad812589fa952e0988fbf0","context":"","default_changed_in":[],"default_history":[{"from":"18","to":"19","value":"on"}],"editorial":{"advice":{"olap":"Self-join elimination can reduce scans and join work in generated analytical SQL. Validate plan shape and result equivalence on representative statements, remembering that the optimization is limited to plain tables and provable uniqueness.","oltp":"Keep the PG18 default on. If a regression is suspected, compare on and off in one session and inspect whether uniqueness proofs and predicates allow a redundant plain-table self-join to be removed; do not disable it cluster-wide to mask bad estimates.","small":"Keep on unless a reproducible PG18 planner regression is isolated. The switch does not remove arbitrary self-joins, so query and index design remain necessary when the proof conditions are absent."},"mechanism":["enable_self_join_elimination controls whether the planner may choose removing provably redundant self-joins on plain tables when uniqueness and predicates preserve semantics.","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 optimization is limited to plain tables and requires proofs that removing the duplicate relation preserves results. Its user context permits session- or transaction-local changes; newly performed or newly planned work sees the value."],"pitfalls":["Treating enable_self_join_elimination 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 optimization is limited to plain tables and requires proofs that removing the duplicate relation preserves results."],"references":[{"title":"PostgreSQL 19 Beta 4: enable_self_join_elimination","url":"https://www.postgresql.org/docs/19/runtime-config-query.html#GUC-ENABLE-SELF-JOIN-ELIMINATION"},{"title":"PostgreSQL 19 release notes","url":"https://www.postgresql.org/docs/19/release-19.html"}],"related":["join_collapse_limit","from_collapse_limit","enable_nestloop","enable_hashjoin"],"summary":"enable_self_join_elimination — Enables removal of unique self-joins. 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.236646+08:00","intro_commit":{"authored_at":"2025-02-13T00:56:03+02:00","discussion":["https://postgr.es/m/flat/64486b0b-0404-e39e-322d-0801154901f3%40postgrespro.ru"],"hash":"fc069a3a6319b5bf40d2f0f1efceae1c9b7a68a8","subject":"Implement Self-Join Elimination","url":"https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=fc069a3a6319b5bf40d2f0f1efceae1c9b7a68a8"},"key":"enable_self_join_elimination","last_version":"20","max_val":"","min_val":"","name":"enable_self_join_elimination","position":134,"present_in":["18","19","20"],"short_desc":"Enables or disables the query planner's optimization which analyses the query tree and replaces self joins with semantically equivalent single scans.","short_desc_zh":"","source_rev":"english-manuals:5f1f4539ef66533e326666948106ed7470cfc9702876355709e982b0122cfa73","unit":"","vartype":"bool"}},"Definition":{"Collection":"guc","Key":"enable_self_join_elimination","SourceDatabase":"center","Version":"18","SourceTable":"guc","SourceKey":"enable_self_join_elimination","SourceRevision":"english-manuals:5f1f4539ef66533e326666948106ed7470cfc9702876355709e982b0122cfa73","Facts":{"boot_val":"on","category":"Query Tuning / Planner Method Configuration","context":"user","description":"Enables or disables the query planner's optimization which analyses the query tree and replaces self joins with semantically equivalent single scans. Takes into consideration only plain tables. The default is on.","doc":{"anchor":"GUC-ENABLE-SELF-JOIN-ELIMINATION","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_self_join_elimination","short_desc":"Enables removal of unique self-joins.","source":"pg-settings-source-snapshot","unit":null,"vartype":"bool"},"ManualEvidence":{"doc":{"anchor":"GUC-ENABLE-SELF-JOIN-ELIMINATION","file":"runtime-config-query.html","lang":"en","sha256":"33456ca7ef52bf28e93e34b932a411db7a1b95800179add2cf867dc6ec9144bc","slug":"18"}},"MeasuredEvidence":{"metadata_version":"18"}},"Text":{"Collection":"guc","Key":"enable_self_join_elimination","SourceDatabase":"pgweb","Version":"18","Locale":"zh-Hans","Title":"enable_self_join_elimination","Summary":"","BodyHTML":"\u003cp\u003e启用或禁用查询规划器的一项优化，该优化会分析查询树并将自连接替换为语义等价的单次扫描。目前只考虑普通表。默认值为\u003ccode\u003eon\u003c/code\u003e。\u003c/p\u003e","SourceRevision":"2026-09-11@29c86d9","ContentHash":"0ce9939ee9217727f9d64851e4cdf5d80f930fef6bc118e77e87f9be3cd4341a","Payload":{"carried_from":"","carry_reason":"","doc_html":"\u003cp\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}
