If a LATERAL subquery references a PlaceHolderVar that must be evaluated at an outer join, the subquery's lateral_relids include that outer join's relid, since the lateral parameter is the outer join's output. join_is_legal() verified that the rels named by a proposed join's minimum parameterization could still be joined to from outside, but it did not consider such outer-join relids. As a result, when identity 3 permitted a commuted join order, we could approve a join that includes part of that outer join's required input, even though the outer join could then be completed only above the proposed join, leaving the lateral parameter forever unsatisfiable. In assert-enabled builds this tripped the backstop Assert in try_nestloop_path(). In production builds the bogus join generated only paths whose parameterization can never be satisfied, so they could never appear in a complete plan. This not only wasted planning effort, but also could mislead the clauseless-join heuristics into thinking that legality of this join means that some other join rel need not be formed, and that could lead to failure to find any plan at all. Such joins used to be rejected by the have_dangerous_phv() check in join_is_legal(), which refused any join where a PlaceHolderVar's eval set overlapped the other side of the join without being contained in it. Commita16ef313fremoved that restriction, exposing this oversight. To fix, teach join_is_legal() to reject a proposed join if its minimum parameterization includes an outer-join relid whose outer join cannot be formed strictly outside the join, that is, when any rel needed to form that outer join must become part of the proposed join's own join tree. Back-patch to v18, where commita16ef313fremoved the have_dangerous_phv() restriction. Author: Richard Guo <guofenglinux@gmail.com> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: Tender Wang <tndrwang@gmail.com> Discussion: https://postgr.es/m/CAMbWs49ZveAYx9T5b0=gxn0pnvqq=MbN-Z4KLbLAE+kH06mWVA@mail.gmail.com Backpatch-through: 18
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/18/. In particular, information about building PostgreSQL from the source code can be found at https://www.postgresql.org/docs/18/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/.