aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/prep/prepjointree.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2021-07-09 13:38:24 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2021-07-09 13:38:24 -0400
commit1d98fdaed89c00465ef68fa2804967ea27b03abc (patch)
treeb656031eae66d73a82faeb4fa4e40d707557f366 /src/backend/optimizer/prep/prepjointree.c
parent5620ec83362d08b9f86c90c97c0a70031c4d0b2c (diff)
downloadpostgresql-1d98fdaed89c00465ef68fa2804967ea27b03abc.tar.gz
postgresql-1d98fdaed89c00465ef68fa2804967ea27b03abc.zip
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
Diffstat (limited to 'src/backend/optimizer/prep/prepjointree.c')
-rw-r--r--src/backend/optimizer/prep/prepjointree.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 62a16687963..b164866c729 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -1801,10 +1801,13 @@ pull_up_constant_function(PlannerInfo *root, Node *jtnode,
/*
* Convert the RTE to be RTE_RESULT type, signifying that we don't need to
- * scan it anymore, and zero out RTE_FUNCTION-specific fields.
+ * scan it anymore, and zero out RTE_FUNCTION-specific fields. Also make
+ * sure the RTE is not marked LATERAL, since elsewhere we don't expect
+ * RTE_RESULTs to be LATERAL.
*/
rte->rtekind = RTE_RESULT;
rte->functions = NIL;
+ rte->lateral = false;
/*
* We can reuse the RangeTblRef node.