Skip to content

Commit

Permalink
Merge pull request #92103 from DrewKimball/backport22.1-91425
Browse files Browse the repository at this point in the history
release-22.1: opt: don't drop LeftJoin filter during join ordering
  • Loading branch information
DrewKimball committed Nov 28, 2022
2 parents 6b3f19a + 4f4e4e3 commit 35009f8
Show file tree
Hide file tree
Showing 3 changed files with 465 additions and 235 deletions.
18 changes: 8 additions & 10 deletions pkg/sql/opt/testutils/opttester/reorder_joins.go
Expand Up @@ -37,6 +37,9 @@ import (
func (ot *OptTester) ReorderJoins() (string, error) {
ot.builder.Reset()
o := ot.makeOptimizer()
o.NotifyOnMatchedRule(func(ruleName opt.RuleName) bool {
return !ot.Flags.DisableRules.Contains(int(ruleName))
})
jof := newJoinOrderFormatter(o)

// joinsConsidered counts the number of joins which joinOrderBuilder attempts
Expand Down Expand Up @@ -106,16 +109,15 @@ func (ot *OptTester) ReorderJoins() (string, error) {
type joinOrderFormatter struct {
o *xform.Optimizer

// relLabels is a map from the first ColumnID of each base relation to its
// assigned label.
relLabels map[opt.ColumnID]string
// relLabels is a map from each base relation to its assigned label.
relLabels map[memo.RelExpr]string
}

// newJoinOrderFormatter returns an initialized joinOrderFormatter.
func newJoinOrderFormatter(o *xform.Optimizer) *joinOrderFormatter {
return &joinOrderFormatter{
o: o,
relLabels: make(map[opt.ColumnID]string),
relLabels: make(map[memo.RelExpr]string),
}
}

Expand Down Expand Up @@ -188,11 +190,7 @@ func (jof *joinOrderFormatter) formatRules(rules []xform.OnReorderRuleParam) str
// relLabel returns the label for the given relation. Labels will follow the
// pattern A, B, ..., Z, A1, B1, etc.
func (jof *joinOrderFormatter) relLabel(e memo.RelExpr) string {
firstCol, ok := e.Relational().OutputCols.Next(0)
if !ok {
panic(errors.AssertionFailedf("failed to retrieve column from %v", e.Op()))
}
if label, ok := jof.relLabels[firstCol]; ok {
if label, ok := jof.relLabels[e]; ok {
return label
}
const lenAlphabet = 26
Expand All @@ -203,7 +201,7 @@ func (jof *joinOrderFormatter) relLabel(e memo.RelExpr) string {
// Names will follow the pattern: A, B, ..., Z, A1, B1, etc.
label += strconv.Itoa(number)
}
jof.relLabels[firstCol] = label
jof.relLabels[e] = label
return label
}

Expand Down

0 comments on commit 35009f8

Please sign in to comment.