Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7d43b76

Browse files
committed
Fix missed step in removal of useless RESULT RTEs in the planner.
Commit4be058f forgot that the append_rel_list would already bepopulated at the time we remove useless result RTEs, and it might containPlaceHolderVars that need to be adjusted like the ones in the main parsetree. This could lead to "no relation entry for relid N" failures lateron, when the planner tries to do something with an unadjusted PHV.Per report from Tom Ellis. Back-patch to v12 where the bug came in.Discussion:https://postgr.es/m/20201205173056.GF30712@cloudinit-builder
1 parente41a2ef commit7d43b76

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

‎src/backend/optimizer/prep/prepjointree.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3256,6 +3256,7 @@ remove_result_refs(PlannerInfo *root, int varno, Node *newjtloc)
32563256
subrelids=get_relids_in_jointree(newjtloc, false);
32573257
Assert(!bms_is_empty(subrelids));
32583258
substitute_phv_relids((Node*)root->parse,varno,subrelids);
3259+
fix_append_rel_relids(root->append_rel_list,varno,subrelids);
32593260
}
32603261

32613262
/*

‎src/test/regress/expected/join.out

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3332,6 +3332,42 @@ select * from
33323332
1 | 2 | 2
33333333
(1 row)
33343334

3335+
-- Test proper handling of appendrel PHVs during useless-RTE removal
3336+
explain (costs off)
3337+
select * from
3338+
(select 0 as z) as t1
3339+
left join
3340+
(select true as a) as t2
3341+
on true,
3342+
lateral (select true as b
3343+
union all
3344+
select a as b) as t3
3345+
where b;
3346+
QUERY PLAN
3347+
---------------------------------------
3348+
Nested Loop
3349+
-> Result
3350+
-> Append
3351+
-> Result
3352+
-> Result
3353+
One-Time Filter: (true)
3354+
(6 rows)
3355+
3356+
select * from
3357+
(select 0 as z) as t1
3358+
left join
3359+
(select true as a) as t2
3360+
on true,
3361+
lateral (select true as b
3362+
union all
3363+
select a as b) as t3
3364+
where b;
3365+
z | a | b
3366+
---+---+---
3367+
0 | t | t
3368+
0 | t | t
3369+
(2 rows)
3370+
33353371
--
33363372
-- test inlining of immutable functions
33373373
--

‎src/test/regress/sql/join.sql

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,28 @@ select * from
10551055
(select1as x) ss1left join (select2as y) ss2on (true),
10561056
lateral (selectss2.yas zlimit1) ss3;
10571057

1058+
-- Test proper handling of appendrel PHVs during useless-RTE removal
1059+
explain (costs off)
1060+
select*from
1061+
(select0as z)as t1
1062+
left join
1063+
(select trueas a)as t2
1064+
on true,
1065+
lateral (select trueas b
1066+
union all
1067+
select aas b)as t3
1068+
where b;
1069+
1070+
select*from
1071+
(select0as z)as t1
1072+
left join
1073+
(select trueas a)as t2
1074+
on true,
1075+
lateral (select trueas b
1076+
union all
1077+
select aas b)as t3
1078+
where b;
1079+
10581080
--
10591081
-- test inlining of immutable functions
10601082
--

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp