Skip to content

Commit 1d98fda

Browse files
committed
Avoid creating a RESULT RTE that's marked LATERAL.
Commit 7266d09 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
1 parent 5620ec8 commit 1d98fda

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

src/backend/optimizer/prep/prepjointree.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1801,10 +1801,13 @@ pull_up_constant_function(PlannerInfo *root, Node *jtnode,
18011801

18021802
/*
18031803
* Convert the RTE to be RTE_RESULT type, signifying that we don't need to
1804-
* scan it anymore, and zero out RTE_FUNCTION-specific fields.
1804+
* scan it anymore, and zero out RTE_FUNCTION-specific fields. Also make
1805+
* sure the RTE is not marked LATERAL, since elsewhere we don't expect
1806+
* RTE_RESULTs to be LATERAL.
18051807
*/
18061808
rte->rtekind = RTE_RESULT;
18071809
rte->functions = NIL;
1810+
rte->lateral = false;
18081811

18091812
/*
18101813
* We can reuse the RangeTblRef node.

src/test/regress/expected/join.out

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3469,6 +3469,14 @@ select unique1 from tenk1, lateral f_immutable_int4(1) x where x = unique1;
34693469
Index Cond: (unique1 = 1)
34703470
(2 rows)
34713471

3472+
explain (costs off)
3473+
select unique1 from tenk1, lateral f_immutable_int4(1) x where x in (select 17);
3474+
QUERY PLAN
3475+
--------------------------
3476+
Result
3477+
One-Time Filter: false
3478+
(2 rows)
3479+
34723480
explain (costs off)
34733481
select unique1, x from tenk1 join f_immutable_int4(1) x on unique1 = x;
34743482
QUERY PLAN

src/test/regress/sql/join.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,9 @@ select unique1 from tenk1, f_immutable_int4(1) x where x = unique1;
11131113
explain (costs off)
11141114
select unique1 from tenk1, lateral f_immutable_int4(1) x where x = unique1;
11151115

1116+
explain (costs off)
1117+
select unique1 from tenk1, lateral f_immutable_int4(1) x where x in (select 17);
1118+
11161119
explain (costs off)
11171120
select unique1, x from tenk1 join f_immutable_int4(1) x on unique1 = x;
11181121

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy