| From: | Richard Guo <guofenglinux(at)gmail(dot)com> |
|---|---|
| To: | Tender Wang <tndrwang(at)gmail(dot)com> |
| Cc: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Alexander Kuzmenkov <akuzmenkov(at)tigerdata(dot)com> |
| Subject: | Re: assertion failure with unique index + partitioning + join |
| Date: | 2026-06-16 08:27:46 |
| Message-ID: | CAMbWs4825ogS5H3M1JAM6V3Z_r28WsQ76FGzOATGVTWREW-F4w@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Tue, Jun 16, 2026 at 10:58 AM Tender Wang <tndrwang(at)gmail(dot)com> wrote:
> It was distributed to (rel:2, table t), but I think "[phrels]
> Bitmapset [4 3 2]" is incorrect. After leftjoin is removed, we no
> longer need rel=4 (outerjoin) and rel=3 (t r).
> But the qual has already been distributed to the (rel: 2) when
> deconstruct_jointree (). Then the qual is inherited by its child(table
> p)
> It seems that we have no logic to process this distributed
> restrictinfo in remove_useless_joins().
When removing the left join, remove_rel_from_query() fixes up the
relid sets of RestrictInfos and EquivalenceMembers, and the canonical
PlaceHolderVars, but it does not rewrite the PlaceHolderVars embedded
in clause and EC-member expressions. This is usually fine, because
later processing consults those relid sets rather than the embedded
PHVs.
The trouble is that such an expression can later be translated for an
appendrel child and have its relids recomputed by pull_varnos(). If
the embedded PlaceHolderVar's phrels still mentions the removed
relation, pull_varnos() folds it back in, so the rebuilt clause
references a no-longer-existent rel. That produces a parameterized
path keyed on the removed relation, which trips the assertion.
I think we can fix it by stripping the removed relids from the PHVs in
surviving rels' baserestrictinfo and in EquivalenceClass member
expressions. See attached.
(I went back and forth on instead making pull_varnos() robust to the
stale phrels, but that turned out fragile: it can't reliably
distinguish a removed relid from a not-yet-built appendrel child, and
it broke unrelated partitionwise-join plans.)
Thoughts?
- Richard
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Strip-removed-relation-references-from-PlaceHolde.patch | application/octet-stream | 11.4 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Kyotaro Horiguchi | 2026-06-16 08:28:31 | Re: Disable startup progress timeout during standby WAL replay |
| Previous Message | Peter Smith | 2026-06-16 08:23:25 | Re: Support EXCEPT for TABLES IN SCHEMA publications |