Richard Guo <guofengli...@gmail.com> writes: > On Tue, May 30, 2023 at 10:28 AM Richard Guo <guofengli...@gmail.com> wrote: >> I haven't thought through how to fix it, but I suspect that we may need >> to do more checking before we decide to remove PHVs in >> remove_rel_from_query.
Oh, I like this example! It shows a place where we are now smarter than we used to be, because v15 and earlier fail to recognize that the join could be removed. But we do have to clean up the query properly afterwards. > Hmm, maybe we can additionally check if the PHV needs to be evaluated > above the join. If so it cannot be removed. Yeah, that seems to make sense, and it squares with the existing comment saying that PHVs used above the join can't be removed. Pushed that way. regards, tom lane