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

planner, statistics: build new histogram using range information #7921

Merged
merged 32 commits into from
Jan 14, 2019

Conversation

winoros
Copy link
Member

@winoros winoros commented Oct 16, 2018

What problem does this PR solve?

Not a problem. To enhance the histColl held by DataSoure's StatsInfo if we will hold it.

What is changed and how it works?

Cut the histograms' buckets by the given range information.
Currently only numeric column's bucket' bound will be changed during this process.
Other column and index will only remove the bucket that have no intersection with ranges.

Check List

Tests

  • Unit test

Code changes

  • Has exported function/method change
  • Has exported variable/fields change

Side effects

  • Possible performance regression
  • Increased code complexity

Related changes

  • Need to update the documentation
  • Need to be included in the release note

This change is Reviewable

@winoros winoros added type/enhancement The issue or PR belongs to an enhancement. sig/planner SIG: Planner component/statistics labels Oct 16, 2018
@winoros winoros changed the title Selectivity planner, statistics: build new histogram using range information Oct 16, 2018
planner/core/stats.go Outdated Show resolved Hide resolved
statistics/feedback.go Outdated Show resolved Hide resolved
statistics/histogram.go Outdated Show resolved Hide resolved
statistics/histogram.go Outdated Show resolved Hide resolved
statistics/histogram.go Outdated Show resolved Hide resolved
statistics/histogram.go Outdated Show resolved Hide resolved
statistics/scalar.go Outdated Show resolved Hide resolved
statistics/table.go Outdated Show resolved Hide resolved
@zz-jason
Copy link
Member

@winoros any update?

@winoros
Copy link
Member Author

winoros commented Oct 24, 2018

Updated @lamxTyler

@winoros
Copy link
Member Author

winoros commented Oct 25, 2018

Please take a look at Histogram.CalcRangeFraction.... Any better idea to do it?

statistics/histogram.go Outdated Show resolved Hide resolved
@winoros
Copy link
Member Author

winoros commented Nov 12, 2018

For index, we need to encode ranges if we want to split them by bucket bound while we need to use non-encode ranges to call GetRowCountByIndexRanges.
So we need to encode it, decode it then encode it again to get the result. It's a little inefficiency. So keep it in original logic.

@winoros
Copy link
Member Author

winoros commented Nov 12, 2018

@lamxTyler PTAL

statistics/selectivity.go Outdated Show resolved Hide resolved
statistics/histogram.go Show resolved Hide resolved
statistics/histogram.go Outdated Show resolved Hide resolved
statistics/histogram.go Outdated Show resolved Hide resolved
statistics/histogram.go Outdated Show resolved Hide resolved
statistics/histogram.go Outdated Show resolved Hide resolved
@@ -24,7 +24,7 @@ type StatsInfo struct {
RowCount float64
Cardinality []float64

HistColl statistics.HistColl
HistColl *statistics.HistColl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it may be nil now? We should check all the places that use it to avoid nil pointer reference.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this pr, it's safe. DataSource always holds a histogram.

statistics/histogram.go Outdated Show resolved Hide resolved
planner/core/stats.go Outdated Show resolved Hide resolved
planner/core/stats.go Show resolved Hide resolved
statistics/histogram.go Outdated Show resolved Hide resolved
statistics/histogram.go Outdated Show resolved Hide resolved
statistics/histogram.go Show resolved Hide resolved
statistics/histogram.go Show resolved Hide resolved
@alivxxx alivxxx removed the status/LGT2 Indicates that a PR has LGTM 2. label Jan 7, 2019
@winoros winoros requested review from alivxxx and zz-jason January 8, 2019 05:50
zz-jason
zz-jason previously approved these changes Jan 11, 2019
Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -465,10 +466,17 @@ func (hg *Histogram) totalRowCount() float64 {
return float64(hg.Buckets[hg.Len()-1].Count + hg.NullCount)
}

func (hg *Histogram) notNullCount() float64 {
if hg.Len() == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@winoros OK. Could you simplify totalRowCount() in this PR?

@zz-jason zz-jason dismissed their stale review January 11, 2019 07:36

Oh, there is a leaving comment

@zz-jason
Copy link
Member

@winoros Please merge master and resolve conflicts.

@winoros winoros dismissed a stale review via 3a9aa6c January 11, 2019 12:21
@zz-jason
Copy link
Member

@winoros CI failed, PTAL

@winoros
Copy link
Member Author

winoros commented Jan 14, 2019

@zz-jason It's the thing i mentioned internally. Statistics' feedback has something wrong with UINT range.

@winoros
Copy link
Member Author

winoros commented Jan 14, 2019

/run-all-tests

@winoros
Copy link
Member Author

winoros commented Jan 14, 2019

@lamxTyler I changed the place where calling the SplitRange for feedback. You can see the subset changes for details.

@winoros
Copy link
Member Author

winoros commented Jan 14, 2019

Also, add some code when doing ColumnPrune to make sure that if the table has unsigned pk, the generated extra rowid is also unsigned.

Copy link
Contributor

@alivxxx alivxxx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alivxxx alivxxx added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jan 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/statistics sig/planner SIG: Planner status/LGT2 Indicates that a PR has LGTM 2. type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants