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

Commit53c6daf

Browse files
committed
Fix two latent(?) bugs in equivclass.c.
get_eclass_for_sort_expr() computes expr_relids and nullable_relidsearly on, even though they won't be needed unless we make a newEquivalenceClass, which we often don't. Aside from the probably-minorinefficiency, there's a memory management problem: these bitmapsets willbe built in the caller's context, leading to dangling pointers if thatis shorter-lived than root->planner_cxt. This would be a live bug ifget_eclass_for_sort_expr() could be called with create_it = true duringGEQO join planning. So far as I can find, the core code never doesthat, but it's hard to be sure that no extensions do, especially sincethe comments make it clear that that's supposed to be a supported case.Fix by not computing these values until we've switched into planner_cxtto build the new EquivalenceClass.generate_join_implied_equalities() uses inner_rel->relids to look uprelevant eclasses, but it ought to be using nominal_inner_relids.This is presently harmless because a child RelOptInfo will always haveexactly the same eclass_indexes as its topmost parent; but that mightnot be true forever, and anyway it makes the code confusing.The first of these is old (introduced by me inf3b3b8d), so back-patchto all supported branches. The second only dates to v13, but we mightas well back-patch it to keep the code looking similar across branches.Discussion:https://postgr.es/m/1508010.1601832581@sss.pgh.pa.us
1 parent9cc3d61 commit53c6daf

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

‎src/backend/optimizer/path/equivclass.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -634,12 +634,6 @@ get_eclass_for_sort_expr(PlannerInfo *root,
634634
*/
635635
expr=canonicalize_ec_expression(expr,opcintype,collation);
636636

637-
/*
638-
* Get the precise set of nullable relids appearing in the expression.
639-
*/
640-
expr_relids=pull_varnos((Node*)expr);
641-
nullable_relids=bms_intersect(nullable_relids,expr_relids);
642-
643637
/*
644638
* Scan through the existing EquivalenceClasses for a match
645639
*/
@@ -716,6 +710,12 @@ get_eclass_for_sort_expr(PlannerInfo *root,
716710
if (newec->ec_has_volatile&&sortref==0)/* should not happen */
717711
elog(ERROR,"volatile EquivalenceClass has no sortref");
718712

713+
/*
714+
* Get the precise set of nullable relids appearing in the expression.
715+
*/
716+
expr_relids=pull_varnos((Node*)expr);
717+
nullable_relids=bms_intersect(nullable_relids,expr_relids);
718+
719719
newem=add_eq_member(newec,copyObject(expr),expr_relids,
720720
nullable_relids, false,opcintype);
721721

@@ -1171,9 +1171,9 @@ generate_join_implied_equalities(PlannerInfo *root,
11711171
}
11721172

11731173
/*
1174-
* Get all eclassesin common between inner_rel's relidsandouter_relids
1174+
* Get all eclassesthat mention both innerandouter sides of the join
11751175
*/
1176-
matching_ecs=get_common_eclass_indexes(root,inner_rel->relids,
1176+
matching_ecs=get_common_eclass_indexes(root,nominal_inner_relids,
11771177
outer_relids);
11781178

11791179
i=-1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp