| From: | Richard Guo <guofenglinux(at)gmail(dot)com> |
|---|---|
| To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
| Cc: | Thom Brown <thom(at)linux(dot)com>, Jacob Brazeal <jacob(dot)brazeal(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | Re: remove_useless_joins vs. bug #19560 |
| Date: | 2026-08-27 05:46:18 |
| Message-ID: | CAMbWs4-wxRAFx8RcsRBJ6mawf7mbOp9J-ms5n3Di0U8T=SxCHg@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Thu, Aug 27, 2026 at 10:57 AM Richard Guo <guofenglinux(at)gmail(dot)com> wrote:
> That is a fair point. The only rels we can remove are plain relations
> and subqueries, and the subqueries are now set to NULL, so a Var of a
> removed rel should never be left in the tree. It is good to have the
> Asserts to check that.
I found one more place where the new Assert fires. If the removed rel
has RLS policies, its RTE still carries the RLS quals, and those quals
contain Vars of the rel. ChangeVarNodes walks RTE.securityQuals, so
we hit the Assert. As an example, run the query below in
rowsecurity.sql:
EXPLAIN (COSTS OFF)
SELECT c.cid FROM category c LEFT JOIN document d ON c.cid = d.did;
I think we can fix it by setting securityQuals to NIL next to where we
set subquery to NULL for the removed RTE.
I checked the other fields of RangeTblEntry and did not find any
similar issue. The only other expression field that seems suspicious
is tablesample, but I believe it's safe, as its arguments cannot refer
to any rel of the same query level, so they never contain Vars we need
to change.
I've updated the delta patch to include the fix to this issue, along
with a test case.
- Richard
| Attachment | Content-Type | Size |
|---|---|---|
| nocfbot.delta-v6.patch | application/octet-stream | 7.7 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Rui Zhao | 2026-08-27 05:55:04 | Re: [PATCH] Preserve replication origin OIDs in pg_upgrade |
| Previous Message | Chao Li | 2026-08-27 05:38:07 | Re: tablecmds: fix bug where index rebuild loses replica identity on partitions |