Re: Simplify the uniqueness proof for self-join elimination

From: Ayoub Kazar <ayoub(dot)kazar(at)data-bene(dot)io>
To: wenhui qiu <qiuwenhuifx(at)gmail(dot)com>
Cc: Richard Guo <guofenglinux(at)gmail(dot)com>, Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Simplify the uniqueness proof for self-join elimination
Date: 2026-11-27 09:57:42
Message-ID: ffaa3536-c5ce-47ed-8a3b-10706e1df778@data-bene.io
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On 27/11/2026 04:41, wenhui qiu wrote:
>
> 1. Canonicalize parameterized TidScan quals in
> BuildParameterizedTidPaths() so that the scanned relation's ctid is
> always on the left (via commute_restrictinfo(rinfo, TIDEqualOperator),
> similar to what match_opclause_to_indexcol() does for index scans).
> That way, parameterized TidScans consistently produce "TID Cond:
> (ctid = t1.ctid)" regardless of which relation populated
> ec_derives_list first.
>
> Doing this only in BuildParameterizedTidPaths() leaves single-rel
> cases
> like "WHERE '(0,1)' = ctid" alone (preserving test coverage for the
> commuted OpExpr branch in nodeTidscan.c and avoiding breaking the
> OR-clause list_difference() check in create_tidscan_plan()), and only
> changes the two join plans in expected/tidscan.out.  Note that
> create_tidscan_plan() would also need to check rinfo_serial rather
> than
> list_member_ptr(tidquals, rinfo) when removing duplicate scan_clauses,
> otherwise a commuted non-EC join clause (such as the LEFT JOIN test in
> tidscan.sql) would be left behind as a redundant Filter.
>
> 2. Alternatively, handle PGS_TIDSCAN via disabled_nodes in
> cost_tidscan() / cost_tidrangescan() instead of skipping path
> generation in create_tidscan_paths(), matching PGS_SEQSCAN,
> PGS_INDEXSCAN, and PGS_BITMAPSCAN.  That avoids changing tidscan.out,
> though as noted in pathnodes.h, skipping path generation was chosen to
> preserve the historical behavior of enable_tidscan = off (e.g., when
> enable_seqscan is also off).
>
> Between the two, (1) feels cleaner to me since it removes the
> EXPLAIN output's sensitivity to EC derivation order altogether,
> but I'd
> be interested to hear what others think.
>
Agree, option 1 seems fine.

Regards,
Ayoub Kazar

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2026-11-27 09:59:48 Re: pg_upgrade's get_rel_infos_query() query can sometimes be slow
Previous Message Nikhil Sontakke 2026-11-27 09:56:34 Re: Dropping a composite attribute causes data integrity violations