Skip to content

Commit

Permalink
nick comments
Browse files Browse the repository at this point in the history
  • Loading branch information
max-hoffman committed Jan 20, 2024
1 parent 0862a5a commit 7ce96c8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 0 additions & 2 deletions enginetest/join_planning_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -1894,8 +1894,6 @@ func evalJoinOrder(t *testing.T, harness Harness, e QueryEngine, q string, exp [
ctx := NewContext(harness)
ctx = ctx.WithQuery(q)

//e.EngineAnalyzer().Verbose = true
//e.EngineAnalyzer().Debug = true
a, err := analyzeQuery(ctx, e, q)
require.NoError(t, err)

Expand Down
17 changes: 13 additions & 4 deletions sql/memo/rel_props.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,14 @@ func statsForRel(rel RelExpr) sql.Statistic {
for n != nil && !done {
switch n := n.(type) {
case *LookupJoin:
injective = injective || n.Injective
if n.Injective {
injective = true
done = true
}
case *MergeJoin:
// get stats for left/right index
// If the children have filtered index scan execution options, we can
// transfer the filter selectivity estimates from the range scans to
// the merge join indexes.
var leftChildStats, rightChildStats sql.Statistic
if lIdx, ok := n.Left.First.(*IndexScan); ok {
leftChildStats = lIdx.Stats
Expand All @@ -348,14 +353,18 @@ func statsForRel(rel RelExpr) sql.Statistic {
rightChildStats = rIdx.Stats
}

// single prefix always safe for merge join
mStat, err := getJoinStats(n.InnerScan.Stats, n.OuterScan.Stats, leftChildStats, rightChildStats, 1)
// merge join indexes have to be sorted on the prefix, so at
// least the length-1 prefix are comparable.
// todo: better way to find the complete prefix match
prefixLen := 1
mStat, err := getJoinStats(n.InnerScan.Stats, n.OuterScan.Stats, leftChildStats, rightChildStats, prefixLen)
if err != nil {
n.Group().m.HandleErr(err)
}
if mergeStats == nil {
mergeStats = mStat
} else if mStat != nil && mStat.RowCount() < mergeStats.RowCount() {
// keep the most restrictive join cardinality estimation
mergeStats = mStat
}
default:
Expand Down

0 comments on commit 7ce96c8

Please sign in to comment.