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

Commit77a94c3

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 parentad3fb04 commit77a94c3

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
@@ -3090,6 +3090,7 @@ remove_result_refs(PlannerInfo *root, int varno, Node *newjtloc)
30903090
subrelids=get_relids_in_jointree(newjtloc, false);
30913091
Assert(!bms_is_empty(subrelids));
30923092
substitute_phv_relids((Node*)root->parse,varno,subrelids);
3093+
fix_append_rel_relids(root->append_rel_list,varno,subrelids);
30933094
}
30943095

30953096
/*

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

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

3333+
-- Test proper handling of appendrel PHVs during useless-RTE removal
3334+
explain (costs off)
3335+
select * from
3336+
(select 0 as z) as t1
3337+
left join
3338+
(select true as a) as t2
3339+
on true,
3340+
lateral (select true as b
3341+
union all
3342+
select a as b) as t3
3343+
where b;
3344+
QUERY PLAN
3345+
---------------------------------------
3346+
Nested Loop
3347+
-> Result
3348+
-> Append
3349+
-> Result
3350+
-> Result
3351+
One-Time Filter: (true)
3352+
(6 rows)
3353+
3354+
select * from
3355+
(select 0 as z) as t1
3356+
left join
3357+
(select true as a) as t2
3358+
on true,
3359+
lateral (select true as b
3360+
union all
3361+
select a as b) as t3
3362+
where b;
3363+
z | a | b
3364+
---+---+---
3365+
0 | t | t
3366+
0 | t | t
3367+
(2 rows)
3368+
33333369
--
33343370
-- test extraction of restriction OR clauses from join OR clause
33353371
-- (we used to only do this for indexable clauses)

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

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

1055+
-- Test proper handling of appendrel PHVs during useless-RTE removal
1056+
explain (costs off)
1057+
select*from
1058+
(select0as z)as t1
1059+
left join
1060+
(select trueas a)as t2
1061+
on true,
1062+
lateral (select trueas b
1063+
union all
1064+
select aas b)as t3
1065+
where b;
1066+
1067+
select*from
1068+
(select0as z)as t1
1069+
left join
1070+
(select trueas a)as t2
1071+
on true,
1072+
lateral (select trueas b
1073+
union all
1074+
select aas b)as t3
1075+
where b;
1076+
10551077
--
10561078
-- test extraction of restriction OR clauses from join OR clause
10571079
-- (we used to only do this for indexable clauses)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp