mirror of
https://github.com/postgres/postgres.git
synced 2026-10-23 13:29:09 +03:00
d87257b2cddc9a0f80bbb80d3190686aa983d9cd
When remove_useless_result_rtes() removes an RTE_RESULT, any PlaceHolderVars that were to be evaluated there must be evaluated somewhere else. If the RTE_RESULT is the nullable side of an outer join, there is no other place that would preserve the PHVs' nulling behavior, so find_dependent_phvs() refuses the removal if any such PHV exists anywhere in the query. If the RTE_RESULT is a child of an inner join, its PHVs can instead be evaluated at the join of all its sibling rels, unless a sibling needs them before that join is formed. find_dependent_phvs_in_jointree() checks for that by looking for such PHVs in the join quals and LATERAL RTEs of the siblings. That misses a PHV that is evaluated at some but not all of the sibling rels and contains one of the RTE_RESULT's PHVs. Such a PHV can appear anywhere in the query, such as in the targetlist. This can happen when pulled-up expressions are wrapped in PHVs because of outer joins or grouping sets. Once the RTE_RESULT is removed, the outer PHV needs a value that is only available at a join above its own evaluation level. The outer PHV's rel thus becomes laterally dependent on the other sibling rels. If one of those rels laterally references it in turn, we end up with a rel that is laterally dependent on itself, causing an assertion failure in create_lateral_join_info(). To fix, also search the whole query for PHVs that are evaluated at some but not all of the sibling rels, and refuse to remove the RTE_RESULT if any of them contains one of its PHVs. An outer PHV that is evaluated at all of the sibling rels is not a problem, since the moved PHV is available there, so we don't block removal in that common case. Back-patch to all supported branches. Author: Richard Guo <guofenglinux@gmail.com> Reviewed-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com> Discussion: https://postgr.es/m/CAMbWs4_hLOsW8_SePp_3EmYTLX8Oc4zEZEvypyPRszpoMhDdGQ@mail.gmail.com Backpatch-through: 14
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. PostgreSQL has many language interfaces, many of which are listed here: https://www.postgresql.org/download/ See the file INSTALL for instructions on how to build and install PostgreSQL. That file also lists supported operating systems and hardware platforms and contains information regarding any other software packages that are required to build or run the PostgreSQL system. Copyright and license information can be found in the file COPYRIGHT. A comprehensive documentation set is included in this distribution; it can be read as described in the installation instructions. The latest version of this software may be obtained at https://www.postgresql.org/download/. For more information look at our web site located at https://www.postgresql.org/.
Languages
C
83.9%
PLpgSQL
6.2%
Perl
5.4%
Yacc
1.2%
Meson
0.7%
Other
2.4%