When simplify_EXISTS_query removes the GROUP BY clauses from an EXISTS subquery, it previously deleted the RTE_GROUP RTE directly from the subquery's range table. This approach is dangerous because deleting an RTE from the middle of the rtable list shifts the index of any subsequent RTE, which can silently corrupt any Var nodes in the query tree that reference those later relations. (Currently, this direct removal has not caused problems because the RTE_GROUP RTE happens to always be the last entry in the rtable list. However, relying on that is extremely fragile and seems like trouble waiting to happen.) Instead of deleting the RTE_GROUP RTE, this patch converts it in-place to be RTE_RESULT type and clears its groupexprs list. This preserves the length and indexing of the rtable list, ensuring all Var references remain intact. Reported-by: Tom Lane <tgl@sss.pgh.pa.us> Author: Richard Guo <guofenglinux@gmail.com> Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://postgr.es/m/3472344.1771858107@sss.pgh.pa.us Backpatch-through: 18 |
||
|---|---|---|
| .github | ||
| config | ||
| contrib | ||
| doc | ||
| src | ||
| .cirrus.star | ||
| .cirrus.tasks.yml | ||
| .cirrus.yml | ||
| .dir-locals.el | ||
| .editorconfig | ||
| .git-blame-ignore-revs | ||
| .gitattributes | ||
| .gitignore | ||
| .mailmap | ||
| aclocal.m4 | ||
| configure | ||
| configure.ac | ||
| COPYRIGHT | ||
| GNUmakefile.in | ||
| HISTORY | ||
| Makefile | ||
| meson.build | ||
| meson_options.txt | ||
| README.md | ||
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/.