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

[memo] assume self-join stats cardinality continuity #2606

Merged
merged 2 commits into from
Jul 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions sql/memo/rel_props.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,16 @@ func getJoinStats(leftIdx, rightIdx, leftChild, rightChild sql.Statistic, prefix
if stats.Empty(rightIdx) || stats.Empty(leftIdx) {
return nil, nil
}
if leftIdx.Qualifier() == rightIdx.Qualifier() {
expandRatio := leftIdx.RowCount() / leftIdx.DistinctCount()
if expandRatio == 1 {
return leftIdx, nil
} else {
// ths undershoots the estimate, but is directionally correct and faster
// than squaring every bucket
return leftIdx.WithRowCount(leftIdx.RowCount() * expandRatio), nil
}
}
// if either child is not nil, try to interpolate join index stats from child
if !stats.Empty(leftChild) {
leftIdx = stats.InterpolateNewCounts(leftIdx, leftChild)
Expand Down