find_dependent_phvs() and find_dependent_phvs_in_jointree() decide whether a PlaceHolderVar depends on the RTE_RESULT rel we're considering removing by comparing the PHV's phrels to a singleton set containing that rel's RT index, reasoning that if phrels contains any other relid bits then those define an appropriate place where we can evaluate the PHV. But since this code was originally written, we've redefined phrels to include outer-join relids, and that breaks this logic, potentially allowing us to remove an RTE_RESULT that leaves no valid place to evaluate the PHV. The planner doesn't throw an error when that happens, but it does produce an incorrect plan that will not replace the PHV's value with NULL when needed. In the known test case for this bug, the "extra" OJ relid is one that we've actually decided to remove but haven't yet cleaned out of the query's PHVs. It's not entirely clear though that that would always be the case. Let's restore this code to the way it was designed to work, by considering only base relids within the PHV's phrels. Bug: #19553 Reported-by: Viktor Leis <leis@in.tum.de> Author: Matheus Alcantara <matheusssilv97@gmail.com> Co-authored-by: Richard Guo <guofenglinux@gmail.com> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/19553-4561747f93f368a7@postgresql.org Backpatch-through: 16
PostgreSQL Database Management System
This directory contains the source code distribution of the PostgreSQL database management system.
PostgreSQL is an advanced object-relational database management system that supports an extended subset of the SQL standard, including transactions, foreign keys, subqueries, triggers, user-defined types and functions. This distribution also contains C language bindings.
Copyright and license information can be found in the file COPYRIGHT.
General documentation about this version of PostgreSQL can be found at https://www.postgresql.org/docs/19/. In particular, information about building PostgreSQL from the source code can be found at https://www.postgresql.org/docs/19/installation.html.
The latest version of this software, and related software, may be obtained at https://www.postgresql.org/download/. For more information look at our web site located at https://www.postgresql.org/.