mirror of
https://github.com/postgres/postgres.git
synced 2026-10-23 13:29:09 +03:00
60b2a2f5264d9cb2e34b725453e3f8315dba5054
If a proposed join has lateral references to rels outside it, join_is_legal() checks that those rels can still be joined to from outside. To do that it collects the rels that must end up on the inner side of an outer join with the proposed join, directly or indirectly, and rejects the join if any of its lateral references point to one of them. That search followed only outer joins, from min_lefthand to min_righthand. It failed to notice that a rel that laterally references the proposed join, or any rel found by the search, cannot supply a parameter to the proposed join either, and that the same holds for rels on the inner side of an outer join with such a rel. As a result, we could approve a join whose lateral references could never be satisfied. Such a join can never appear in a complete plan. Worse, as the existing comment warns, its apparent legality could mislead the clauseless-join heuristics into thinking that some other join rel need not be formed. In particular, have_join_order_restriction() would not force a clauseless outer join if one of its input rels appeared to have a legal clause join elsewhere, and if that outer join was required, we would fail with "failed to build any N-way joins". To fix, also include in the search any input rel of the current join search that laterally references a rel already found. The input rels are taken from root->initial_rels rather than from the query's base rels, because an input can be the joinrel of a sub-joinlist, as happens for a full join or when from_collapse_limit or join_collapse_limit prevents flattening. Such a joinrel is joined as a unit, so it has to be included as a whole. Back-patch to all supported branches. Author: Richard Guo <guofenglinux@gmail.com> Reviewed-by: Tender Wang <tndrwang@gmail.com> Reviewed-by: wenhui qiu <qiuwenhuifx@gmail.com> Discussion: https://postgr.es/m/CAMbWs4_p6iWbsjNcYpd6-6mWFnog3UJ2fZKrxWAQTsyNoyeQTw@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. PostgreSQL has many language interfaces, many of which are listed here: https://www.postgresql.org/download/ See the file INSTALL for instructions on how to build and install PostgreSQL. That file also lists supported operating systems and hardware platforms and contains information regarding any other software packages that are required to build or run the PostgreSQL system. Copyright and license information can be found in the file COPYRIGHT. A comprehensive documentation set is included in this distribution; it can be read as described in the installation instructions. The latest version of this software may be obtained at https://www.postgresql.org/download/. For more information look at our web site located at https://www.postgresql.org/.
Languages
C
83.9%
PLpgSQL
6.2%
Perl
5.4%
Yacc
1.2%
Meson
0.7%
Other
2.4%