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

Commit03107b4

Browse files
committed
Ensure generated join clauses for child rels have correct relids.
When building a join clause derived from an EquivalenceClass, if theclause is to be used with an appendrel child relation then make sureits clause_relids include the relids of that child relation.Normally this would be true already because the EquivalenceMemberwould be a Var of that relation. However, if the appendrel representsa flattened UNION ALL construct then some child EquivalenceMemberscould be constants with no relids. The resulting under-marked clauseis problematic because it could mislead join_clause_is_movable_intoabout where the clause should be evaluated. We do not have an exampleshowing incorrect plan generation, but there are existing cases inthe regression tests that will fail the Asserts this patch adds toget_baserel_parampathinfo. A similarly wrong conclusion about aclause being considered by get_joinrel_parampathinfo would lead towrong placement of the clause. (This also squares with the waythat clause_relids is calculated for non-equijoin clauses inadjust_appendrel_attrs.)The other reason for wanting these new Asserts is that the previousblithe assumption that the results of generate_join_implied_equalities"necessarily satisfy join_clause_is_movable_into" turns out to bewrong pre-v16. If it's still wrong it'd be good to find out.Per bug #18429 from Benoît Ryder. The bug as filed was fixed bycommit2489d76, but these changes correlate with the fix wewill need to apply in pre-v16 branches.Discussion:https://postgr.es/m/18429-8982d4a348cc86c6@postgresql.org
1 parentf698704 commit03107b4

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,6 +1896,21 @@ create_join_clause(PlannerInfo *root,
18961896
rightem->em_relids),
18971897
ec->ec_min_security);
18981898

1899+
/*
1900+
* If either EM is a child, force the clause's clause_relids to include
1901+
* the relid(s) of the child rel. In normal cases it would already, but
1902+
* not if we are considering appendrel child relations with pseudoconstant
1903+
* translated variables (i.e., UNION ALL sub-selects with constant output
1904+
* items). We must do this so that join_clause_is_movable_into() will
1905+
* think that the clause should be evaluated at the correct place.
1906+
*/
1907+
if (leftem->em_is_child)
1908+
rinfo->clause_relids=bms_add_members(rinfo->clause_relids,
1909+
leftem->em_relids);
1910+
if (rightem->em_is_child)
1911+
rinfo->clause_relids=bms_add_members(rinfo->clause_relids,
1912+
rightem->em_relids);
1913+
18991914
/* If it's a child clause, copy the parent's rinfo_serial */
19001915
if (parent_rinfo)
19011916
rinfo->rinfo_serial=parent_rinfo->rinfo_serial;

‎src/backend/optimizer/util/relnode.c‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,7 @@ get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel,
15601560
ParamPathInfo*ppi;
15611561
Relidsjoinrelids;
15621562
List*pclauses;
1563+
List*eqclauses;
15631564
Bitmapset*pserials;
15641565
doublerows;
15651566
ListCell*lc;
@@ -1595,14 +1596,25 @@ get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel,
15951596

15961597
/*
15971598
* Add in joinclauses generated by EquivalenceClasses, too. (These
1598-
* necessarily satisfy join_clause_is_movable_into.)
1599+
* necessarily satisfy join_clause_is_movable_into; but in assert-enabled
1600+
* builds, let's verify that.)
15991601
*/
1600-
pclauses=list_concat(pclauses,
1601-
generate_join_implied_equalities(root,
1602-
joinrelids,
1603-
required_outer,
1604-
baserel,
1605-
NULL));
1602+
eqclauses=generate_join_implied_equalities(root,
1603+
joinrelids,
1604+
required_outer,
1605+
baserel,
1606+
NULL);
1607+
#ifdefUSE_ASSERT_CHECKING
1608+
foreach(lc,eqclauses)
1609+
{
1610+
RestrictInfo*rinfo= (RestrictInfo*)lfirst(lc);
1611+
1612+
Assert(join_clause_is_movable_into(rinfo,
1613+
baserel->relids,
1614+
joinrelids));
1615+
}
1616+
#endif
1617+
pclauses=list_concat(pclauses,eqclauses);
16061618

16071619
/* Compute set of serial numbers of the enforced clauses */
16081620
pserials=NULL;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp