pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Guo <rguo@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Enable use of Memoize for ANTI joins
Date: Thu, 03 Jul 2025 01:58:45 +0000
Message-ID: <E1uX9Dp-004RNE-2f@gemulon.postgresql.org> (raw)

Enable use of Memoize for ANTI joins

Currently, we do not support Memoize for SEMI and ANTI joins because
nested loop SEMI/ANTI joins do not scan the inner relation to
completion, which prevents Memoize from marking the cache entry as
complete.  One might argue that we could mark the cache entry as
complete after fetching the first inner tuple, but that would not be
safe: if the first inner tuple and the current outer tuple do not
satisfy the join clauses, a second inner tuple matching the parameters
would find the cache entry already marked as complete.

However, if the inner side is provably unique, this issue doesn't
arise, since there would be no second matching tuple.  That said, this
doesn't help in the case of SEMI joins, because a SEMI join with a
provably unique inner side would already have been reduced to an inner
join by reduce_unique_semijoins.

Therefore, in this patch, we check whether the inner relation is
provably unique for ANTI joins and enable the use of Memoize in such
cases.

Author: Richard Guo <guofenglinux@gmail.com>
Reviewed-by: wenhui qiu <qiuwenhuifx@gmail.com>
Reviewed-by: Andrei Lepikhov <lepihov@gmail.com>
Discussion: https://postgr.es/m/CAMbWs48FdLiMNrmJL-g6mDvoQVt0yNyJAqMkv4e2Pk-5GKCZLA@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/0da29e4cb161f78a5ef534b3fb4467756a422e25

Modified Files
--------------
src/backend/optimizer/path/joinpath.c | 47 ++++++++++++++-------------
src/test/regress/expected/memoize.out | 60 +++++++++++++++++++++++++++++++++++
src/test/regress/sql/memoize.sql      | 27 ++++++++++++++++
3 files changed, 112 insertions(+), 22 deletions(-)



Message-ID: <E1uX9Dp-004RNE-2f@gemulon.postgresql.org>
Permalink:  ../E1uX9Dp-004RNE-2f@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1uX9Dp-004RNE-2f@gemulon.postgresql.org

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: rguo@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Enable use of Memoize for ANTI joins
  In-Reply-To: <E1uX9Dp-004RNE-2f@gemulon.postgresql.org>

* 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