find_var_for_subquery_tle() searches a subquery rel's targetlist for a Var referencing a given subquery output column, and asserted that any Var it finds there belongs to that rel. That does not hold for an appendrel child. set_append_rel_size() builds the child's targetlist by translating the parent's, and as noted there the result can contain arbitrary expressions. In particular, when a member of a LATERAL UNION ALL subquery is pulled up and its output is a lateral reference, the translated expression is a Var of the laterally referenced rel. If the child is itself a subquery with sorted paths, convert_subquery_pathkeys() would trip the Assert. In non-assert builds, the function went on to compare such a Var's varattno with the subquery column's resno, and so could match a Var of an unrelated rel. To fix, ignore Vars that do not belong to the subquery rel, the same way set_rel_width() already does. Also correct the adjacent comment, which claimed that the only non-Var entries are placeholders. Back-patch to all supported branches. Author: Richard Guo <guofenglinux@gmail.com> Reviewed-by: shihao zhong <zhong950419@gmail.com> Discussion: https://postgr.es/m/CAMbWs48fFiPi7Q5yJCoM_nAs47zd5XgvPHd9nZyM_ewq+k_jpQ@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.
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/17/. In particular, information about building PostgreSQL from the source code can be found at https://www.postgresql.org/docs/17/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/.