# enable_self_join_elimination

> enable_self_join_elimination — Enables removal of unique self-joins. Observed in PG18–19 Beta 3; its last measured boot default is on in PG19 Beta 3, with user context. This is a beta-snapshot fact and can change before PostgreSQL 19 GA.
---

> [!NOTE]
> **Fact — official short description:** “Enables removal of unique self-joins.”

## Identity {#identity}

| Field | Value | Meaning |
| --- | --- | --- |
| Type | `bool` | Upstream pg_settings type |
| Context | `user` | Settable by an ordinary user |
| Unit | — | Raw unit |
| Range | — | Raw limits in the last observed version |
| Enum values | — | — for non-enum types |
| Category | Query Tuning / Planner Method Configuration | Upstream classification |
| Latest boot value | `on` | on |
{.fields meta="-"}

## Lifecycle {#lifecycle}

| Fact | Value |
| --- | --- |
| First observed | PG18 |
| Present in | PG18–19 Beta 3 |
| Removed in | No |
| Introduction commit | [`fc069a3a6319`](https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=fc069a3a6319b5bf40d2f0f1efceae1c9b7a68a8) — Implement Self-Join Elimination |
| Commit date | 2025-02-13 |
| Discussion | [thread 1](https://postgr.es/m/flat/64486b0b-0404-e39e-322d-0801154901f3%40postgrespro.ru) |

## Default history {#default-history}

| Versions | Raw `boot_val` | Unit | Human value |
| --- | --- | --- | --- |
| PG18–19 Beta 3 | `on` | — | on |
{.full-width caption="Measured PG9.0–19 Beta 3 boot defaults"}

## How it works {#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.

## Tuning advice {#tuning-advice}

> [!TIP]
> **Advice.** These are workload-specific starting points and must be validated with measurements.

| Workload | Guidance |
| --- | --- |
| 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. |
| 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. |
| Small nodes | 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. |
{.full-width}

## Pigsty {#pigsty}

Values use the fixed 8-vCPU, 32-GiB, 100-GiB SSD fixture and render the current Pigsty templates for PG19 Beta 3; this does not assert current Pigsty support for that historical or beta release.

| Template | Effective value | Versus upstream boot | Source expression |
| --- | --- | --- | --- |
| OLTP | Unmodified | — | — |
| OLAP | Unmodified | — | — |
| CRIT | Unmodified | — | — |
| TINY | Unmodified | — | — |
{.full-width}

> [!CAUTION]
> **Advice — pending human review.** Fact from the current Pigsty template projection: OLTP: PG18–19 Beta 3 unmodified; OLAP: PG18–19 Beta 3 unmodified; CRIT: PG18–19 Beta 3 unmodified; TINY: PG18–19 Beta 3 unmodified. No Pigsty-specific rationale is inferred from an absent override.

## Common pitfalls {#common-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.

## Related parameters {#related-parameters}

[`join_collapse_limit`](/parameters/join-collapse-limit/) · [`from_collapse_limit`](/parameters/from-collapse-limit/) · [`enable_nestloop`](/parameters/enable-nestloop/) · [`enable_hashjoin`](/parameters/enable-hashjoin/)

## References {#references}

- [PostgreSQL 19 Beta 3 — enable_self_join_elimination](https://www.postgresql.org/docs/19/runtime-config-query.html#GUC-ENABLE-SELF-JOIN-ELIMINATION)
- [PostgreSQL 19 release notes](https://www.postgresql.org/docs/19/release-19.html)
- [Machine-readable GUC export](/data/guc.jsonl)
