From eb55d6d2a3e039ae8b0f197ede757c27358a0128 Mon Sep 17 00:00:00 2001 From: shihao zhong Date: Tue, 13 Oct 2026 09:00:57 -0400 Subject: [PATCH v2 2/3] Clear securityQuals of a rel removed by self-join elimination. Self-join elimination left the removed rel's securityQuals in its RTE, with their Vars now pointing at the kept rel. If a later pass removes the kept rel as the inner side of a left join, ChangeVarNodes finds those Vars and hits an Assert. Clear them, as outer join removal does. --- src/backend/optimizer/plan/analyzejoins.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/backend/optimizer/plan/analyzejoins.c b/src/backend/optimizer/plan/analyzejoins.c index 4d13e9e9717..668d5178bdc 100644 --- a/src/backend/optimizer/plan/analyzejoins.c +++ b/src/backend/optimizer/plan/analyzejoins.c @@ -1270,6 +1270,13 @@ remove_self_join_rel(PlannerInfo *root, ChangeVarNodes((Node *) root->append_rel_list, toRemove->relid, toKeep->relid, 0); + /* + * As in remove_useless_outer_joins, discard the securityQuals of the + * removed rel, so that later passes don't visit them. The kept rel has + * the same ones. + */ + root->simple_rte_array[toRemove->relid]->securityQuals = NIL; + /* Clean up the quals that the substitution has messed with */ fixup_selfjoin_jointree(root, (Node *) root->parse->jointree, toKeep->relid, -- 2.37.1 (Apple Git-137.1)