Skip to content

Commit d1c9c86

Browse files
committed
Further tighten nullingrel marking rules in build_joinrel_tlist().
The code I added in fee7b77 could misbehave if commute_above_r contains multiple relids. While adding too many relids here is probably harmless (pre-fee7b77b9, we did it all the time), it's not very expensive to be accurate: we just have to intersect commute_above_r with the join's relids. Discussion: https://postgr.es/m/17781-c0405c8b3cd5e072@postgresql.org
1 parent 798c017 commit d1c9c86

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/backend/optimizer/util/relnode.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,9 +1051,9 @@ min_join_parameterization(PlannerInfo *root,
10511051
* A leftjoin (B leftjoin C on (Pbc)) on (Pab)
10521052
* Here the now-upper A/B join must not mark C columns as nulled by itself.
10531053
*
1054-
* Second, if sjinfo->commute_above_r is already part of the joinrel then
1055-
* it is added to the nulling bitmaps of nullable Vars. This takes care of
1056-
* the reverse case where we implement
1054+
* Second, any relid in sjinfo->commute_above_r that is already part of
1055+
* the joinrel is added to the nulling bitmaps of nullable Vars and PHVs.
1056+
* This takes care of the reverse case where we implement
10571057
* A leftjoin (B leftjoin C on (Pbc)) on (Pab)
10581058
* as
10591059
* (A leftjoin B on (Pab)) leftjoin C on (Pbc)
@@ -1100,9 +1100,10 @@ build_joinrel_tlist(PlannerInfo *root, RelOptInfo *joinrel,
11001100
bms_is_subset(phv->phrels, sjinfo->syn_lefthand))))
11011101
phv->phnullingrels = bms_add_member(phv->phnullingrels,
11021102
sjinfo->ojrelid);
1103-
if (bms_overlap(sjinfo->commute_above_r, joinrel->relids))
1104-
phv->phnullingrels = bms_add_members(phv->phnullingrels,
1105-
sjinfo->commute_above_r);
1103+
phv->phnullingrels =
1104+
bms_join(phv->phnullingrels,
1105+
bms_intersect(sjinfo->commute_above_r,
1106+
relids));
11061107
}
11071108

11081109
joinrel->reltarget->exprs = lappend(joinrel->reltarget->exprs,
@@ -1164,9 +1165,10 @@ build_joinrel_tlist(PlannerInfo *root, RelOptInfo *joinrel,
11641165
bms_is_member(var->varno, sjinfo->syn_lefthand))))
11651166
var->varnullingrels = bms_add_member(var->varnullingrels,
11661167
sjinfo->ojrelid);
1167-
if (bms_overlap(sjinfo->commute_above_r, joinrel->relids))
1168-
var->varnullingrels = bms_add_members(var->varnullingrels,
1169-
sjinfo->commute_above_r);
1168+
var->varnullingrels =
1169+
bms_join(var->varnullingrels,
1170+
bms_intersect(sjinfo->commute_above_r,
1171+
relids));
11701172
}
11711173

11721174
joinrel->reltarget->exprs = lappend(joinrel->reltarget->exprs,

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