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

parser: add new analyze option SAMPLERATE #28961

Merged
merged 11 commits into from
Oct 25, 2021

Conversation

winoros
Copy link
Member

@winoros winoros commented Oct 19, 2021

What problem does this PR solve?

Issue Number: to #28960

Problem Summary:

Modify parser to support the new analyze option.

What is changed and how it works?

Since the new option needs float value, we not only modified the parser, but also modified the structure of the AnalyzeOption.

Check List

Tests

  • Unit test

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

None

@winoros winoros added the sig/planner SIG: Planner label Oct 19, 2021
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Oct 19, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • time-and-fate
  • xuyifangreeneyes

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Oct 19, 2021
planner/core/planbuilder.go Outdated Show resolved Hide resolved
planner/core/planbuilder.go Outdated Show resolved Hide resolved
planner/core/planbuilder.go Outdated Show resolved Hide resolved
return nil, err
}
if statsVer == statistics.Version1 && v > 0 {
return nil, errors.Errorf("Version 1's statistics doesn't support the SAMPLE RATE option, please set tidb_analyze_version to 2")
Copy link
Contributor

Choose a reason for hiding this comment

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

Any UT to check if these checks work?

Copy link
Member Author

Choose a reason for hiding this comment

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

Current we don't actually support the analyze process for sample rate case, will be added in next pr.

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return nil, errors.Errorf("Version 1's statistics doesn't support the SAMPLE RATE option, please set tidb_analyze_version to 2")
return nil, errors.Errorf("Version 1's statistics doesn't support the SAMPLERATE option, please set tidb_analyze_version to 2.")

Copy link
Contributor

@chrysan chrysan left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot
Copy link
Member

@chrysan: Thanks for your review. The bot only counts approvals from reviewers and higher roles in list, but you're still welcome to leave your comments.

In response to this:

LGTM

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@kennytm
Copy link
Contributor

kennytm commented Oct 20, 2021

Since the new option needs float value, we not only modified the parser, but also modified the structure of the AnalyzeOption.

Technically you could use math.Float64bits/math.Float64frombits to support floats 🙃

@winoros
Copy link
Member Author

winoros commented Oct 20, 2021

Technically you could use math.Float64bits/math.Float64frombits to support floats 🙃

@kennytm
Oh you mean, we use it to store the rate as uint64 in the map[Option]uint64 and convert back to float64 when using it?

@kennytm
Copy link
Contributor

kennytm commented Oct 20, 2021

@winoros yes. though this bit-twiddling hack won't work if in the future you need an option with string value.

Copy link
Member

@time-and-fate time-and-fate left a comment

Choose a reason for hiding this comment

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

Maybe we should change analyze options from a map into a struct someday.

return nil, err
}
if statsVer == statistics.Version1 && v > 0 {
return nil, errors.Errorf("Version 1's statistics doesn't support the SAMPLE RATE option, please set tidb_analyze_version to 2")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return nil, errors.Errorf("Version 1's statistics doesn't support the SAMPLE RATE option, please set tidb_analyze_version to 2")
return nil, errors.Errorf("Version 1's statistics doesn't support the SAMPLERATE option, please set tidb_analyze_version to 2.")

return nil, errors.Errorf("Version 1's statistics doesn't support the SAMPLE RATE option, please set tidb_analyze_version to 2")
}
if v > analyzeOptionLimit[opt.Type].(float64) || v <= 0 {
return nil, errors.Errorf("value of analyze option %s should not larger than %f, and greater than 0", ast.AnalyzeOptionString[opt.Type], analyzeOptionLimit[opt.Type])
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return nil, errors.Errorf("value of analyze option %s should not larger than %f, and greater than 0", ast.AnalyzeOptionString[opt.Type], analyzeOptionLimit[opt.Type])
return nil, errors.Errorf("value of analyze option %s should not be larger than %f, and should be greater than 0", ast.AnalyzeOptionString[opt.Type], analyzeOptionLimit[opt.Type])

switch opt.Type {
case ast.AnalyzeOptNumTopN:
v := datumValue.GetUint64()
if v > analyzeOptionLimit[opt.Type].(uint64) {
return nil, errors.Errorf("value of analyze option %s should not larger than %d", ast.AnalyzeOptionString[opt.Type], analyzeOptionLimit[opt.Type])
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return nil, errors.Errorf("value of analyze option %s should not larger than %d", ast.AnalyzeOptionString[opt.Type], analyzeOptionLimit[opt.Type])
return nil, errors.Errorf("Value of analyze option %s should not be larger than %d", ast.AnalyzeOptionString[opt.Type], analyzeOptionLimit[opt.Type])

optMap[opt.Type] = v
default:
v := datumValue.GetUint64()
if v == 0 || v > analyzeOptionLimit[opt.Type].(uint64) {
return nil, errors.Errorf("value of analyze option %s should be positive and not larger than %d", ast.AnalyzeOptionString[opt.Type], analyzeOptionLimit[opt.Type])
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return nil, errors.Errorf("value of analyze option %s should be positive and not larger than %d", ast.AnalyzeOptionString[opt.Type], analyzeOptionLimit[opt.Type])
return nil, errors.Errorf("Value of analyze option %s should be positive and not larger than %d.", ast.AnalyzeOptionString[opt.Type], analyzeOptionLimit[opt.Type])

@time-and-fate
Copy link
Member

Also please resolve the conflicts.

@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 21, 2021
}
limit := math.Float64frombits(analyzeOptionLimit[opt.Type])
if fVal <= 0 || fVal > limit {
return nil, errors.Errorf("Value of analyze option %s should not larger than %f, and should be greater than 0", limit, analyzeOptionLimit[opt.Type])
Copy link
Member

Choose a reason for hiding this comment

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

The arguments are wrong.

@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 21, 2021
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Oct 21, 2021
@@ -2065,6 +2068,7 @@ var analyzeOptionDefaultV2 = map[ast.AnalyzeOptionType]uint64{
ast.AnalyzeOptCMSketchWidth: 2048,
ast.AnalyzeOptCMSketchDepth: 5,
ast.AnalyzeOptNumSamples: 100000,
ast.AnalyzeOptSampleRate: math.Float64bits(0),
Copy link
Contributor

Choose a reason for hiding this comment

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

The default value of SAMPLE RATE is 0. When users doesn't set either NUM SAMPLES or SAMPLE RATE, the default values would be used. In that case, will ANALYZE execute with 10000 SAMPLES?

Copy link
Contributor

Choose a reason for hiding this comment

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

The next pr will change the default config.

Copy link
Contributor

@xuyifangreeneyes xuyifangreeneyes left a comment

Choose a reason for hiding this comment

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

LGTM

}
limit := math.Float64frombits(analyzeOptionLimit[opt.Type])
if fVal <= 0 || fVal > limit {
return nil, errors.Errorf("Value of analyze option %s should not larger than %f, and should be greater than 0", ast.AnalyzeOptionString[opt.Type], limit)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return nil, errors.Errorf("Value of analyze option %s should not larger than %f, and should be greater than 0", ast.AnalyzeOptionString[opt.Type], limit)
return nil, errors.Errorf("Value of analyze option %s should not be larger than %f, and should be greater than 0", ast.AnalyzeOptionString[opt.Type], limit)

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Oct 22, 2021
@winoros
Copy link
Member Author

winoros commented Oct 23, 2021

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: fb10d8b

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Oct 23, 2021
@tisonkun
Copy link
Contributor

@winoros the GitHub settings require at least 1 approving review which indicate a committer approve (green). You can ask for another committer to approve this PR.

@winoros
Copy link
Member Author

winoros commented Oct 25, 2021

/merge

@ti-chi-bot
Copy link
Member

@winoros: Your PR was out of date, I have automatically updated it for you.

At the same time I will also trigger all tests for you:

/run-all-tests

If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot ti-chi-bot merged commit b332a08 into pingcap:master Oct 25, 2021
@winoros winoros deleted the sample-rate-parser branch October 25, 2021 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants