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

Commit45ae203

Browse files
committed
Propagate lateral-reference information to indirect descendant relations.
create_lateral_join_info() computes a bunch of information about lateralreferences between base relations, and then attempts to propagate thosemarkings to appendrel children of the original base relations. But theoriginal coding neglected the possibility of indirect descendants(grandchildren etc). During v11 development we noticed that this waswrong for partitioned-table cases, but failed to realize that it was justas wrong for any appendrel. While the case can't arise for appendrelsderived from traditional table inheritance (because we make a flatappendrel for that), nested appendrels can arise from nested UNION ALLsubqueries. Failure to mark the lower-level relations as having lateralreferences leads to confusion in add_paths_to_append_rel about whetherunparameterized paths can be built. It's not very clear whether thatleads to any user-visible misbehavior; the lack of field reports suggeststhat it may cause nothing worse than minor cost misestimation. Still,it's a bug, and it leads to failures of Asserts that I intend to addlater.To fix, we need to propagate information from all appendrel parents,not just those that are RELOPT_BASERELs. We can still do it in onepass, if we rely on the append_rel_list to be ordered with ancestorrelationships before descendant ones; add assertions checking that.While fixing this, we can make a small performance improvement bytraversing the append_rel_list just once instead of separately foreach appendrel parent relation.Noted while investigating bug #15613, though this patch does not fixthat (which is why I'm not committing the related Asserts yet).Discussion:https://postgr.es/m/3951.1549403812@sss.pgh.pa.us
1 parent11f11e1 commit45ae203

File tree

1 file changed

+31
-40
lines changed

1 file changed

+31
-40
lines changed

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

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ void
418418
create_lateral_join_info(PlannerInfo*root)
419419
{
420420
boolfound_laterals= false;
421+
Relidsprev_parentsPG_USED_FOR_ASSERTS_ONLY=NULL;
421422
Indexrti;
422423
ListCell*lc;
423424

@@ -626,53 +627,43 @@ create_lateral_join_info(PlannerInfo *root)
626627
* every child anyway, and there's no value in forcing extra
627628
* reparameterize_path() calls. Similarly, a lateral reference to the
628629
* parent prevents use of otherwise-movable join rels for each child.
630+
*
631+
* It's possible for child rels to have their own children, in which case
632+
* the topmost parent's lateral info must be propagated all the way down.
633+
* This code handles that case correctly so long as append_rel_list has
634+
* entries for child relationships before grandchild relationships, which
635+
* is an okay assumption right now, but we'll need to be careful to
636+
* preserve it. The assertions below check for incorrect ordering.
629637
*/
630-
for (rti=1;rti<root->simple_rel_array_size;rti++)
638+
foreach(lc,root->append_rel_list)
631639
{
632-
RelOptInfo*brel=root->simple_rel_array[rti];
633-
RangeTblEntry*brte=root->simple_rte_array[rti];
634-
635-
/*
636-
* Skip empty slots. Also skip non-simple relations i.e. dead
637-
* relations.
638-
*/
639-
if (brel==NULL|| !IS_SIMPLE_REL(brel))
640-
continue;
640+
AppendRelInfo*appinfo= (AppendRelInfo*)lfirst(lc);
641+
RelOptInfo*parentrel=root->simple_rel_array[appinfo->parent_relid];
642+
RelOptInfo*childrel=root->simple_rel_array[appinfo->child_relid];
641643

642644
/*
643-
* In the case of table inheritance, the parent RTE is directly linked
644-
* to every child table via an AppendRelInfo. In the case of table
645-
* partitioning, the inheritance hierarchy is expanded one level at a
646-
* time rather than flattened. Therefore, an other member rel that is
647-
* a partitioned table may have children of its own, and must
648-
* therefore be marked with the appropriate lateral info so that those
649-
* children eventually get marked also.
645+
* If we're processing a subquery of a query with inherited target rel
646+
* (cf. inheritance_planner), append_rel_list may contain entries for
647+
* tables that are not part of the current subquery and hence have no
648+
* RelOptInfo. Ignore them. We can ignore dead rels, too.
650649
*/
651-
Assert(brte);
652-
if (brel->reloptkind==RELOPT_OTHER_MEMBER_REL&&
653-
(brte->rtekind!=RTE_RELATION||
654-
brte->relkind!=RELKIND_PARTITIONED_TABLE))
650+
if (parentrel==NULL|| !IS_SIMPLE_REL(parentrel))
655651
continue;
656652

657-
if (brte->inh)
658-
{
659-
foreach(lc,root->append_rel_list)
660-
{
661-
AppendRelInfo*appinfo= (AppendRelInfo*)lfirst(lc);
662-
RelOptInfo*childrel;
663-
664-
if (appinfo->parent_relid!=rti)
665-
continue;
666-
childrel=root->simple_rel_array[appinfo->child_relid];
667-
Assert(childrel->reloptkind==RELOPT_OTHER_MEMBER_REL);
668-
Assert(childrel->direct_lateral_relids==NULL);
669-
childrel->direct_lateral_relids=brel->direct_lateral_relids;
670-
Assert(childrel->lateral_relids==NULL);
671-
childrel->lateral_relids=brel->lateral_relids;
672-
Assert(childrel->lateral_referencers==NULL);
673-
childrel->lateral_referencers=brel->lateral_referencers;
674-
}
675-
}
653+
/* Verify that children are processed before grandchildren */
654+
#ifdefUSE_ASSERT_CHECKING
655+
prev_parents=bms_add_member(prev_parents,appinfo->parent_relid);
656+
Assert(!bms_is_member(appinfo->child_relid,prev_parents));
657+
#endif
658+
659+
/* OK, propagate info down */
660+
Assert(childrel->reloptkind==RELOPT_OTHER_MEMBER_REL);
661+
Assert(childrel->direct_lateral_relids==NULL);
662+
childrel->direct_lateral_relids=parentrel->direct_lateral_relids;
663+
Assert(childrel->lateral_relids==NULL);
664+
childrel->lateral_relids=parentrel->lateral_relids;
665+
Assert(childrel->lateral_referencers==NULL);
666+
childrel->lateral_referencers=parentrel->lateral_referencers;
676667
}
677668
}
678669

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp