When a LATERAL UNION ALL subquery is flattened into an appendrel, a child EquivalenceMember's expression can contain lateral references to other relations. create_join_clause() builds a clause from such a member with make_restrictinfo(), which computes clause_relids from the expression, and so includes the relids of the lateral references along with those of any outer joins that null them. Commit03107b4edmade sure that clause_relids include the child's relids, but it only ever added relids. This is a problem when a lateral reference is nullable. The child is parameterized by its lateral_relids, which do not include the outer joins that null the lateral references, so the clause fails the join_clause_is_movable_into() assertion that get_baserel_parampathinfo() applies to EC-derived clauses. To fix, set a child clause's clause_relids from its members' em_relids rather than from their expressions. This matches how adjust_appendrel_attrs() computes clause_relids for a child's other join clauses. The lateral references need not be included, since every path for the child is parameterized by at least its lateral_relids. Also update num_base_rels to match, which commit03107b4edneglected to do. Back-patch to v16, where outer-join relids were added to clause_relids. Before that, the relids of a lateral reference are always part of the child's parameterization, so the problem does not arise. Author: Richard Guo <guofenglinux@gmail.com> Reviewed-by: wenhui qiu <qiuwenhuifx@gmail.com> Discussion: https://postgr.es/m/CAMbWs4-cRxpQNyQJW=PkDagSDGQ=3Rp2t_fSAyROKsDStjKHUQ@mail.gmail.com 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/devel/. In particular, information about building PostgreSQL from the source code can be found at https://www.postgresql.org/docs/devel/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/.