Re: Removing unneeded self joins

From: Andrei Lepikhov <lepihov(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Alexander Korotkov <aekorotkov(at)gmail(dot)com>, Alena Rybakina <a(dot)rybakina(at)postgrespro(dot)ru>, Richard Guo <guofenglinux(at)gmail(dot)com>, Ranier Vilela <ranier(dot)vf(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robert Haas <robertmhaas(at)gmail(dot)com>, Alexander Lakhin <exclusion(at)gmail(dot)com>, "Gregory Stark (as CFM)" <stark(dot)cfm(at)gmail(dot)com>, Michał Kłeczek <michal(at)kleczek(dot)org>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Subject: Re: Removing unneeded self joins
Date: 2025-06-27 06:46:29
Message-ID: 6e17d257-68d7-44f0-a54b-0ea49bfd1dbd@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 27/6/2025 02:26, Michael Paquier wrote:
> The point regarding the search join hook may stand, though. Perhaps
> somebody should check if we're still OK with this change in the
> context of the self-join work. I tend to think that we are and I
> agree that removing the joins when calling the hook can show benefits,
> but it may be surprising and users tend to be very noisy with plan
> stability, particularly if some of the FROM aliases get silenced by
> the backend without the module knowing about that. At least there is
> the trick with SET enable_self_join_elimination available as a last
> resort method.
Parse tree transformation (pull-ups, flattenings) adds joins, constant
clause evaluation or partition pruning may smash whole subtrees - the
optimisation process is quite unstable from the query structure's point
of view.
If I understand correctly, pg_hint_plan needs to differentiate 'never
existed' relations and removed ones. In that sense, up to v.15, Postgres
saved RelOptInfo after removing the join (see e9a20e4).

--
regards, Andrei Lepikhov

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message jian he 2025-06-27 07:14:38 Re: speedup COPY TO for partitioned table.
Previous Message Dmitry 2025-06-27 06:41:19 Re: IPC/MultixactCreation on the Standby server