When left-join removal deletes a relation, remove_rel_from_query() updates the relid sets attached to RestrictInfos and EquivalenceMembers, and the canonical PlaceHolderVar held in each PlaceHolderInfo, but it does not rewrite the PlaceHolderVars embedded in clause and EquivalenceClass member expressions. That has been fine, because later processing consults those relid sets rather than the embedded PlaceHolderVars. However, such an expression may afterwards be translated for an appendrel child and have its relids recomputed from scratch by pull_varnos(). If the embedded PlaceHolderVar's phrels still mentions the removed relation, pull_varnos() folds it back in, so the rebuilt clause's relids reference a no-longer-existent relation. That yields a parameterized path keyed on the removed relation, tripping the Assert on root->outer_join_rels in get_eclass_indexes_for_relids(). Fix by stripping the removed relids from the PlaceHolderVars in surviving rels' baserestrictinfo and in EquivalenceClass member expressions, keeping them consistent with the canonical PlaceHolderVars. This is only reachable on v18 and later, where match_index_to_operand() began ignoring PlaceHolderVars; before that, the wrapping PlaceHolderVar prevented the index match that exposes the stale relids. Reported-by: Alexander Kuzmenkov <akuzmenkov@tigerdata.com> Author: Richard Guo <guofenglinux@gmail.com> Reviewed-by: Tender Wang <tndrwang@gmail.com> Discussion: https://postgr.es/m/CALzhyqwryL2QywgO03VQr_237Sq3MEVgTTT2_A9G3nGT5-SRZg@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/.