Re: Pathify RHS unique-ification for semijoin planning

wenhui qiu <qiuwenhuifx@gmail.com>

From: wenhui qiu <qiuwenhuifx@gmail.com>
To: Richard Guo <guofenglinux@gmail.com>
Cc: Alexandra Wang <alexandra.wang.oss@gmail.com>, Álvaro Herrera <alvherre@kurilemu.de>, PostgreSQL-development <pgsql-hackers@postgresql.org>, Tom Lane <tgl@sss.pgh.pa.us>, Andy Fan <zhihuifan1213@163.com>
Date: 2025-08-07T09:04:41Z
Lists: pgsql-hackers

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Simplify relation_has_unique_index_for()

  2. Pathify RHS unique-ification for semijoin planning

  3. Convert varatt.h access macros to static inline functions.

  4. Re-export a few of createplan.c's make_xxx() functions.

HI Richard Guo
+/*
+ * Is given relation unique-ified?
+ *
+ * When the nominal jointype is JOIN_INNER, sjinfo->jointype is JOIN_SEMI,
and
+ * the given rel is exactly the RHS of the semijoin, it indicates that the
rel
+ * has been unique-ified.
+ */
+#define IS_UNIQUEIFIED_REL(rel, sjinfo, nominal_jointype) \
+ ((nominal_jointype) == JOIN_INNER && (sjinfo)->jointype == JOIN_SEMI && \
+ bms_equal((sjinfo)->syn_righthand, (rel)->relids))
+

In light of this commit (
https://github.com/postgres/postgres/commit/e035863c9a04beeecc254c3bfe48dab58e389e10),
I also recommend changing the macro to a static inline function. Macros are
harder to debug and lack type safety.
static inline bool
is_uniqueified_rel(RelOptInfo *rel, SpecialJoinInfo *sjinfo, JoinType
nominal_jointype)
{
    return nominal_jointype == JOIN_INNER &&
           sjinfo->jointype == JOIN_SEMI &&
           bms_equal(sjinfo->syn_righthand, rel->relids);
}

Thanks

On Mon, Aug 4, 2025 at 10:08 AM Richard Guo <guofenglinux@gmail.com> wrote:

> The v5 patch does not apply anymore, and here is a new rebase.  There
> are two main changes in v6:
>
> * I choose to use the check I proposed earlier to determine whether a
> relation has been unique-ified in costsize.c.
>
> * Now that the only call to relation_has_unique_index_for() that
> supplied an exprlist and oprlist has been removed, the loop handling
> those lists is effectively dead code.  0002 removes that loop and
> simplifies the function accordingly.
>
> Thanks
> Richard
>