Avoid creating a RESULT RTE that's marked LATERAL.
authorTom Lane
Fri, 9 Jul 2021 17:38:24 +0000 (13:38 -0400)
committerTom Lane
Fri, 9 Jul 2021 17:38:24 +0000 (13:38 -0400)
commit1d98fdaed89c00465ef68fa2804967ea27b03abc
treeb656031eae66d73a82faeb4fa4e40d707557f366
parent5620ec83362d08b9f86c90c97c0a70031c4d0b2c
Avoid creating a RESULT RTE that's marked LATERAL.

Commit 7266d0997 added code to pull up simple constant function
results, converting the RTE_FUNCTION RTE to a dummy RTE_RESULT
RTE since it no longer need be scanned.  But I forgot to clear
the LATERAL flag if the RTE has it set.  If the function reduced
to a constant, it surely contains no lateral references so this
simplification is logically OK.  It's needed because various other
places will Assert that RESULT RTEs aren't LATERAL.

Per bug #17097 from Yaoguang Chen.  Back-patch to v13 where the
faulty code came in.

Discussion: https://postgr.es/m/17097-3372ef9f798fc94f@postgresql.org
src/backend/optimizer/prep/prepjointree.c
src/test/regress/expected/join.out
src/test/regress/sql/join.sql