Re: Simplify the uniqueness proof for self-join elimination

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: wenhui qiu <qiuwenhuifx(at)gmail(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Simplify the uniqueness proof for self-join elimination
Date: 2026-11-25 04:37:19
Message-ID: CAMbWs48w1E=LmVMR3GoKdeoWd_NsgzreC1ipYTQ1DJk=mJRNKA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Nov 23, 2026 at 7:28 PM wenhui qiu <qiuwenhuifx(at)gmail(dot)com> wrote:
>> Since all relations in remove_self_joins_one_group() share the same
>> reloid (and have !rte->inh), would it be worth checking
>> rel_supports_distinctness() once in remove_self_joins_one_group() so that
>> we can skip the whole group early if the table has no suitable unique
>> index?

Thanks for the review!

Good point. I've added the check at the top of
remove_self_joins_one_group(), so that we skip the whole group if the
relation has no usable unique index.

>> Perhaps we can drop otherjoinquals and simplify split_selfjoin_quals() to
>> just return the list of self-join quals (similar to
>> get_shared_restrictions())?

Agreed. Nothing uses the other quals anymore, so I've changed the
function to return just the self-join quals, and renamed it to
get_selfjoin_quals().

Attached is the updated patch.

- Richard

Attachment Content-Type Size
v2-0001-Simplify-the-uniqueness-proof-for-self-join-elimi.patch application/octet-stream 26.9 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andreas Karlsson 2026-11-25 04:38:49 Re: [PATCH] pg_input_is_valid() reuses the first type name inside a PL/pgSQL loop
Previous Message Michael Paquier 2026-11-25 04:33:08 Re: Redesign per-backend statistics