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

Commitefeb12e

Browse files
committed
Don't include outer join relids in lateral_relids bitmapsets.
This avoids an assertion failure when outer joins are rearrangedper identity 3. Listing only the baserels from a PlaceHolderVar'sph_lateral set should be enough to ensure that the required valuesare available when we need to compute the PHV --- it's what wedid before inventing nullingrel sets, after all. It's a bitunsatisfying; but with beta2 hard upon us, there's not time tolook for an aesthetically cleaner fix.Richard Guo and Tom LaneDiscussion:https://postgr.es/m/CAMbWs48Jcw-NvnxT23WiHP324wG44DvzcH1j4hc0Zn+3sR9cfg@mail.gmail.com
1 parent0655c03 commitefeb12e

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

‎src/backend/optimizer/plan/initsplan.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,24 +580,34 @@ create_lateral_join_info(PlannerInfo *root)
580580
{
581581
PlaceHolderInfo*phinfo= (PlaceHolderInfo*)lfirst(lc);
582582
Relidseval_at=phinfo->ph_eval_at;
583+
Relidslateral_refs;
583584
intvarno;
584585

585586
if (phinfo->ph_lateral==NULL)
586587
continue;/* PHV is uninteresting if no lateral refs */
587588

588589
found_laterals= true;
589590

591+
/*
592+
* Include only baserels not outer joins in the evaluation sites'
593+
* lateral relids. This avoids problems when outer join order gets
594+
* rearranged, and it should still ensure that the lateral values are
595+
* available when needed.
596+
*/
597+
lateral_refs=bms_intersect(phinfo->ph_lateral,root->all_baserels);
598+
Assert(!bms_is_empty(lateral_refs));
599+
590600
if (bms_get_singleton_member(eval_at,&varno))
591601
{
592602
/* Evaluation site is a baserel */
593603
RelOptInfo*brel=find_base_rel(root,varno);
594604

595605
brel->direct_lateral_relids=
596606
bms_add_members(brel->direct_lateral_relids,
597-
phinfo->ph_lateral);
607+
lateral_refs);
598608
brel->lateral_relids=
599609
bms_add_members(brel->lateral_relids,
600-
phinfo->ph_lateral);
610+
lateral_refs);
601611
}
602612
else
603613
{
@@ -610,7 +620,7 @@ create_lateral_join_info(PlannerInfo *root)
610620
if (brel==NULL)
611621
continue;/* ignore outer joins in eval_at */
612622
brel->lateral_relids=bms_add_members(brel->lateral_relids,
613-
phinfo->ph_lateral);
623+
lateral_refs);
614624
}
615625
}
616626
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2624,6 +2624,23 @@ select * from int8_tbl t1
26242624
-> Function Scan on generate_series
26252625
(7 rows)
26262626

2627+
explain (costs off)
2628+
select * from int8_tbl t1
2629+
left join int8_tbl t2 on true
2630+
left join lateral
2631+
(select t2.q1 from int8_tbl t3) s
2632+
on t2.q1 = 1;
2633+
QUERY PLAN
2634+
-------------------------------------------
2635+
Nested Loop Left Join
2636+
-> Seq Scan on int8_tbl t1
2637+
-> Materialize
2638+
-> Nested Loop Left Join
2639+
Join Filter: (t2.q1 = 1)
2640+
-> Seq Scan on int8_tbl t2
2641+
-> Seq Scan on int8_tbl t3
2642+
(7 rows)
2643+
26272644
explain (costs off)
26282645
select * from onek t1
26292646
left join onek t2 on true

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,13 @@ select * from int8_tbl t1
528528
(select*from generate_series(t2.q1,100)) s
529529
ont2.q1=1;
530530

531+
explain (costs off)
532+
select*from int8_tbl t1
533+
left join int8_tbl t2on true
534+
left join lateral
535+
(selectt2.q1from int8_tbl t3) s
536+
ont2.q1=1;
537+
531538
explain (costs off)
532539
select*from onek t1
533540
left join onek t2on true

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp