From: Tom Lane <tgl@sss.pgh.pa.us>
To: William Bernbaum <wbernbaum@dwdev.com>
Cc: pgsql-hackers@lists.postgresql.org <pgsql-hackers@lists.postgresql.org>
Subject: Re: Plan a filtering inner join as a semijoin
Date: Tue, 25 Aug 2026 23:31:18 -0400
Message-ID: <661904.1787715078@sss.pgh.pa.us> (raw)
In-Reply-To: <PH0PR18MB444307FAC570FFD7F2457D4DA6AE2@PH0PR18MB4443.namprd18.prod.outlook.com>
References: <PH0PR18MB444307FAC570FFD7F2457D4DA6AE2@PH0PR18MB4443.namprd18.prod.outlook.com>
William Bernbaum <wbernbaum@dwdev.com> writes:
> Recently I improved a dynamic SQL compiler (an ORM-like layer) using a
> pattern that seems to generalize to the Postgres planner. I taught the
> layer to emit an EXISTS subquery when the target relation only served to
> filter, rather than fanning out a join whose extra rows were discarded.
> That led me into the join elimination machinery, and to the attached draft
> patch. It adds convert_joins_to_semijoins(), which recognizes an inner
> join that only restricts which rows survive and adds a JOIN_SEMI
> SpecialJoinInfo for the filtering relation.
I find myself a bit astonished by this proposal. Normally we try
to convert semijoins to inner joins in order to gain join-order
flexibility. I can't see a good reason to go in the other direction.
There might be a reason to install some special case for the query
pattern you have in mind, but I really doubt that this particular
special case is the best option.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: tgl@sss.pgh.pa.us, wbernbaum@dwdev.com
Subject: Re: Plan a filtering inner join as a semijoin
In-Reply-To: <661904.1787715078@sss.pgh.pa.us>
References: <PH0PR18MB444307FAC570FFD7F2457D4DA6AE2@PH0PR18MB4443.namprd18.prod.outlook.com> <661904.1787715078@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox