Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release-22.1: opt: don't drop LeftJoin filter during join ordering #92103

Merged
merged 2 commits into from Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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