Discarded adjust_relid_set() return values in remove_self_join_rel

Started by SATYANARAYANA NARLAPURAM7 months ago2 messageshackers

Thread notes

1 note#bug
hackorum-bot#bug
hackorum-bot
2 days ago

@global #bug

#bug
Jump to latest
#1SATYANARAYANA NARLAPURAM
satyanarlapuram@gmail.com

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:

t139482_1
0001-Fix-discarded-adjust_relid_set-return-values-in-SJE.patchapplication/octet-stream; name=0001-Fix-discarded-adjust_relid_set-return-values-in-SJE.patchDownload+6-3
#2Tender Wang
tndrwang@gmail.com
In reply to: SATYANARAYANA NARLAPURAM (#1)
Re: Discarded adjust_relid_set() return values in remove_self_join_rel

Hi,

SATYANARAYANA NARLAPURAM <satyanarlapuram@gmail.com> 于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]/messages/by-id/CAMbWs49fYQcqJfJ_Gtn8r1GFNoYtb1=2AUab4ieuqY4Zid9ocQ@mail.gmail.com (Sorry for not adding pgsql-hackers mail in the last email) seems to be the same issue as your report.
You can take a look at [1]/messages/by-id/CAMbWs49fYQcqJfJ_Gtn8r1GFNoYtb1=2AUab4ieuqY4Zid9ocQ@mail.gmail.com (Sorry for not adding pgsql-hackers mail in the last email) to double-check.

[1]: /messages/by-id/CAMbWs49fYQcqJfJ_Gtn8r1GFNoYtb1=2AUab4ieuqY4Zid9ocQ@mail.gmail.com (Sorry for not adding pgsql-hackers mail in the last email)
(Sorry for not adding pgsql-hackers mail in the last email)

--
Thanks,
Tender Wang