Re: Extending Self-Join Elimination to partitioned tables

From: Andrei Lepikhov <lepihov(at)gmail(dot)com>
To: Trương Hoàng Quân <truonghoangquan456(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Extending Self-Join Elimination to partitioned tables
Date: 2026-08-06 17:24:05
Message-ID: e18720ec-2b44-4d38-b821-cc990e08682d@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 11/07/2026 01:44, Trương Hoàng Quân wrote:
> I'd appreciate any feedback. If anyone has objections, or can think of a
> query pattern where this would break (wrong results, crashes, planner
> assertions), please let me know. In the meantime I'll keep expanding the
> test coverage for the corner cases I can think of.

Your patch is a big deal for partitioned configurations. But it still has some
issues. For example, one direct bug:

create table sjo (id int primary key, note text) partition by range (id);
create table sjo_1 partition of sjo for values from (0) to (100);
insert into sjo values (1,'a'), (2,'b');
select p.id from ONLY sjo p, sjo q where p.id = q.id;

This query shouldn't return anything, but I see the output:

id
----
1
2
(2 rows)

After fixing this, I think you should add a regression test that checks correctness.

Next, in config.sgml for enable_self_join_elimination I see the following:
"Takes into consideration only plain tables." — must be updated.

Further in the code, I see a stale comment:
"We only consider ordinary relations as candidates ..."

Performance evidence. It would be nice to see at least a couple of benchmarks:
1. Overhead in case of unsuccessful SJE operation (no unique index present)
2. How much faster (or slower) planning is if SJE has happened. We know it
should be a clear profit for the executor, but what does it cost for the planner?

--
regards, Andrei Lepikhov,
pgEdge

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Hannu Krosing 2026-08-06 17:25:02 Re: [HACKERS] Partitioning performance: cache stringToNode() of pg_constraint.ccbin
Previous Message Corey Huinker 2026-08-06 17:20:33 Re: Credits For v19