postgres/src/backend
Tom Lane 6ea364e7e7 Prevent overly-aggressive collapsing of joins to RTE_RESULT relations.
The RTE_RESULT simplification logic added by commit 4be058fe9 had a
flaw: it would collapse out a RTE_RESULT that is due to compute a
PlaceHolderVar, and reassign the PHV to the parent join level, even if
another input relation of the join contained a lateral reference to
the PHV.  That can't work because the PHV would be computed too late.
In practice it led to failures of internal sanity checks later in
planning (either assertion failures or errors such as "failed to
construct the join relation").

To fix, add code to check for the presence of such PHVs in relevant
portions of the query tree.  Notably, this required refactoring
range_table_walker so that a caller could ask to walk individual RTEs
not the whole list.  (It might be a good idea to refactor
range_table_mutator in the same way, if only to keep those functions
looking similar; but I didn't do so here as it wasn't necessary for
the bug fix.)

This exercise also taught me that find_dependent_phvs(), as it stood,
could only safely be used on the entire Query, not on subtrees.
Adjust its API to reflect that; which in passing allows it to have
a fast path for the common case of no PHVs anywhere.

Per report from Will Leinweber.  Back-patch to v12 where the bug
was introduced.

Discussion: https://postgr.es/m/CALLb-4xJMd4GZt2YCecMC95H-PafuWNKcmps4HLRx2NHNBfB4g@mail.gmail.com
2019-12-14 13:49:15 -05:00
..
access Fix crash when a page was split during GiST index creation. 2019-12-13 23:58:10 +02:00
bootstrap Remove configure --disable-float4-byval 2019-11-21 18:29:21 +01:00
catalog Fix misbehavior with expression indexes on ON COMMIT DELETE ROWS tables. 2019-12-01 13:09:26 -05:00
commands Further adjust EXPLAIN's choices of table alias names. 2019-12-11 17:05:18 -05:00
executor Allow executor startup pruning to prune all child nodes. 2019-12-11 17:05:30 -05:00
foreign Split all OBJS style lines in makefiles into one-line-per-entry style. 2019-11-05 14:41:07 -08:00
jit Remove useless "return;" lines 2019-11-28 16:48:37 -03:00
lib Make StringInfo available to frontend code. 2019-11-05 14:56:40 -08:00
libpq Fix memory leak when initializing DH parameters in backend 2019-12-14 18:17:31 +09:00
main Split all OBJS style lines in makefiles into one-line-per-entry style. 2019-11-05 14:41:07 -08:00
nodes Prevent overly-aggressive collapsing of joins to RTE_RESULT relations. 2019-12-14 13:49:15 -05:00
optimizer Prevent overly-aggressive collapsing of joins to RTE_RESULT relations. 2019-12-14 13:49:15 -05:00
parser Disallow non-default collation in ADD PRIMARY KEY/UNIQUE USING INDEX. 2019-12-06 11:25:09 -05:00
partitioning Remove extra parenthesis from comment. 2019-12-12 15:45:00 +09:00
po Translation updates 2019-06-17 15:30:20 +02:00
port Use only one thread to handle incoming signals on Windows. 2019-12-11 15:09:54 -05:00
postmaster Use procsignal_sigusr1_handler for auxiliary processes. 2019-11-25 16:16:27 -05:00
regex Split all OBJS style lines in makefiles into one-line-per-entry style. 2019-11-05 14:41:07 -08:00
replication Remove XLogFileNameP() from the tree 2019-12-03 15:06:04 +09:00
rewrite Remove useless "return;" lines 2019-11-28 16:48:37 -03:00
snowball Split all OBJS style lines in makefiles into one-line-per-entry style. 2019-11-05 14:41:07 -08:00
statistics Remove unnecessary clauses_attnums variable 2019-11-28 23:25:14 +01:00
storage Fix mdsyncfiletag(), take II. 2019-12-14 18:35:58 +13:00
tcop Emit parameter values during query bind/execute errors 2019-12-11 18:03:35 -03:00
tsearch Make the order of the header file includes consistent in backend modules. 2019-11-12 08:30:16 +05:30
utils Fix EXTRACT(ISOYEAR FROM timestamp) for years BC. 2019-12-12 12:30:43 -05:00
.gitignore
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
Makefile Split all OBJS style lines in makefiles into one-line-per-entry style. 2019-11-05 14:41:07 -08:00
nls.mk Translation updates 2019-05-20 16:00:53 +02:00