1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-03 15:22:11 +03:00

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
This commit is contained in:
Tom Lane
2021-07-09 13:38:24 -04:00
parent 5620ec8336
commit 1d98fdaed8
3 changed files with 15 additions and 1 deletions

View File

@@ -3469,6 +3469,14 @@ select unique1 from tenk1, lateral f_immutable_int4(1) x where x = unique1;
Index Cond: (unique1 = 1)
(2 rows)
explain (costs off)
select unique1 from tenk1, lateral f_immutable_int4(1) x where x in (select 17);
QUERY PLAN
--------------------------
Result
One-Time Filter: false
(2 rows)
explain (costs off)
select unique1, x from tenk1 join f_immutable_int4(1) x on unique1 = x;
QUERY PLAN

View File

@@ -1113,6 +1113,9 @@ select unique1 from tenk1, f_immutable_int4(1) x where x = unique1;
explain (costs off)
select unique1 from tenk1, lateral f_immutable_int4(1) x where x = unique1;
explain (costs off)
select unique1 from tenk1, lateral f_immutable_int4(1) x where x in (select 17);
explain (costs off)
select unique1, x from tenk1 join f_immutable_int4(1) x on unique1 = x;