After I looked at the logic of SJE, considering that the replace_relid function chooses whether or not to replace the oldId with a newId from the relid by determining if the oldId is less than 0, I'm guessing that this could be caused by a lack of test in replacing the references to the the self-join from the PlannerInfo->placeholder_list. I think it is straightforward to modify the judgment logic here, as shown in the attachment.