Skip to content

Commit f7b14fb

Browse files
committed
opt: lazily initialize helper data in join reordering
Some equivalence groups and column sets are used during join reordering only when there are inner-join edges. These data structures are no longer initialized if there are no inner-join edges. Release note: None
1 parent 034a4cb commit f7b14fb

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

pkg/sql/opt/xform/join_order_builder.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -616,17 +616,22 @@ func (jb *JoinOrderBuilder) addJoins(s1, s2 vertexSet) {
616616
// Keep track of which edges are applicable to this join.
617617
var appliedEdges edgeSet
618618

619-
jb.equivs.Reset()
620-
jb.equivs.AddFromFDs(&jb.plans[s1].Relational().FuncDeps)
621-
jb.equivs.AddFromFDs(&jb.plans[s2].Relational().FuncDeps)
622-
623-
notNullCols := jb.plans[s1].Relational().NotNullCols.Copy()
624-
notNullCols.UnionWith(jb.plans[s2].Relational().NotNullCols)
619+
// Lazily initialize jb.equivs and notNullCols.
620+
innerEdgeReady := false
621+
var notNullCols opt.ColSet
625622

626623
// Gather all inner edges that connect the left and right relation sets.
627624
var innerJoinFilters memo.FiltersExpr
628625
for i, ok := jb.innerEdges.Next(0); ok; i, ok = jb.innerEdges.Next(i + 1) {
629626
e := &jb.edges[i]
627+
if !innerEdgeReady {
628+
jb.equivs.Reset()
629+
jb.equivs.AddFromFDs(&jb.plans[s1].Relational().FuncDeps)
630+
jb.equivs.AddFromFDs(&jb.plans[s2].Relational().FuncDeps)
631+
notNullCols.UnionWith(jb.plans[s1].Relational().NotNullCols)
632+
notNullCols.UnionWith(jb.plans[s2].Relational().NotNullCols)
633+
innerEdgeReady = true
634+
}
630635

631636
// Ensure that this edge forms a valid connection between the two sets. See
632637
// the checkNonInnerJoin and checkInnerJoin comments for more information.

0 commit comments

Comments
 (0)