public inbox for [email protected]
help / color / mirror / Atom feedDiscarded adjust_relid_set() return values in remove_self_join_rel
2+ messages / 2 participants
[nested] [flat]
* Discarded adjust_relid_set() return values in remove_self_join_rel
@ 2026-04-25 07:44 SATYANARAYANA NARLAPURAM <[email protected]>
0 siblings, 1 reply; 2+ messages in thread
From: SATYANARAYANA NARLAPURAM @ 2026-04-25 07:44 UTC (permalink / raw)
To: PostgreSQL Hackers <[email protected]>
Hi hackers,
I found that remove_self_join_rel() in analyzejoins.c discards the
return values of two adjust_relid_set() calls when updating
root->all_result_relids and root->leaf_result_relids:
adjust_relid_set(root->all_result_relids, toRemove->relid,
toKeep->relid);
adjust_relid_set(root->leaf_result_relids, toRemove->relid,
toKeep->relid);
adjust_relid_set() does not modify its input in-place. When it finds
the old relid in the set, it calls bms_copy() to create a new
Bitmapset, performs the substitution on the copy, and returns the new
pointer. Without capturing the return value, the original sets are
never updated. Every other call site in the file analyzejoins.c correctly
assigns the return value.
I am not able to craft a query to show it as a problem.
For the current release, these two lines appears to be a no-op?
Attached a patch to assign the returned values.
Thanks,
Satya
Attachments:
[application/octet-stream] 0001-Fix-discarded-adjust_relid_set-return-values-in-SJE.patch (1.7K, 3-0001-Fix-discarded-adjust_relid_set-return-values-in-SJE.patch)
download | inline diff:
From 211caf4d6048c332b613022cb968cdcd05f5c503 Mon Sep 17 00:00:00 2001
From: Satya Narlapuram <[email protected]>
Date: Sat, 25 Apr 2026 07:30:13 +0000
Subject: [PATCH] Fix discarded adjust_relid_set() return values in SJE
remove_self_join_rel() calls adjust_relid_set() to update
root->all_result_relids and root->leaf_result_relids after
eliminating a self-joined relation, but discards the return values.
adjust_relid_set() allocates a new Bitmapset via bms_copy() when
it finds the old relid in the set, so the caller must capture the
returned pointer. Every other call site in the file (20+ instances)
correctly assigns the return value.
---
src/backend/optimizer/plan/analyzejoins.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/backend/optimizer/plan/analyzejoins.c b/src/backend/optimizer/plan/analyzejoins.c
index 03056bdf..4fa3abc7 100644
--- a/src/backend/optimizer/plan/analyzejoins.c
+++ b/src/backend/optimizer/plan/analyzejoins.c
@@ -1994,8 +1994,12 @@ remove_self_join_rel(PlannerInfo *root, PlanRowMark *kmark, PlanRowMark *rmark,
ChangeVarNodesExtended((Node *) root->processed_tlist, toRemove->relid,
toKeep->relid, 0, replace_relid_callback);
- adjust_relid_set(root->all_result_relids, toRemove->relid, toKeep->relid);
- adjust_relid_set(root->leaf_result_relids, toRemove->relid, toKeep->relid);
+ root->all_result_relids = adjust_relid_set(root->all_result_relids,
+ toRemove->relid,
+ toKeep->relid);
+ root->leaf_result_relids = adjust_relid_set(root->leaf_result_relids,
+ toRemove->relid,
+ toKeep->relid);
/*
* There may be references to the rel in root->fkey_list, but if so,
--
2.43.0
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Discarded adjust_relid_set() return values in remove_self_join_rel
@ 2026-04-25 07:53 Tender Wang <[email protected]>
parent: SATYANARAYANA NARLAPURAM <[email protected]>
0 siblings, 0 replies; 2+ messages in thread
From: Tender Wang @ 2026-04-25 07:53 UTC (permalink / raw)
To: SATYANARAYANA NARLAPURAM <[email protected]>; +Cc: PostgreSQL Hackers <[email protected]>
Hi,
SATYANARAYANA NARLAPURAM <[email protected]> 于2026年4月25日周六 15:44写道:
>
> Hi hackers,
>
> I found that remove_self_join_rel() in analyzejoins.c discards the
> return values of two adjust_relid_set() calls when updating
> root->all_result_relids and root->leaf_result_relids:
>
> adjust_relid_set(root->all_result_relids, toRemove->relid, toKeep->relid);
> adjust_relid_set(root->leaf_result_relids, toRemove->relid, toKeep->relid);
>
> adjust_relid_set() does not modify its input in-place. When it finds
> the old relid in the set, it calls bms_copy() to create a new
> Bitmapset, performs the substitution on the copy, and returns the new
> pointer. Without capturing the return value, the original sets are
> never updated. Every other call site in the file analyzejoins.c correctly
> assigns the return value.
>
> I am not able to craft a query to show it as a problem.
> For the current release, these two lines appears to be a no-op?
>
> Attached a patch to assign the returned values.
The topic in [1] seems to be the same issue as your report.
You can take a look at [1] to double-check.
[1] https://www.postgresql.org/message-id/CAMbWs49fYQcqJfJ_Gtn8r1GFNoYtb1%3D2AUab4ieuqY4Zid9ocQ%40mail.g...
(Sorry for not adding pgsql-hackers mail in the last email)
--
Thanks,
Tender Wang
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2026-04-25 07:53 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-04-25 07:44 Discarded adjust_relid_set() return values in remove_self_join_rel SATYANARAYANA NARLAPURAM <[email protected]>
2026-04-25 07:53 ` Tender Wang <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox