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

*: make analyze buckets number configurable #7619

Merged
merged 5 commits into from
Sep 6, 2018
Merged

Conversation

alivxxx
Copy link
Contributor

@alivxxx alivxxx commented Sep 5, 2018

What problem does this PR solve?

Make analyze buckets number configurable.

What is changed and how it works?

Extend the syntax of analyze, so we can use statement like analyze table t with 4 buckets to configure the bucket number.

Check List

Tests

  • Unit test

Code changes

  • Has exported function/method change

Side effects

  • None

Related changes

  • Need to update the documentation

PTAL @coocood @zz-jason @winoros

@alivxxx alivxxx added component/statistics type/enhancement The issue or PR belongs to an enhancement. labels Sep 5, 2018
Copy link
Member

@shenli shenli left a comment

Choose a reason for hiding this comment

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

How could users choose bucket number?

@@ -890,7 +886,7 @@ func (s *testStatsUpdateSuite) TestLogDetailedInfo(c *C) {
for i := 0; i < 20; i++ {
testKit.MustExec(fmt.Sprintf("insert into t values (%d, %d, %d)", i, i, i))
}
testKit.MustExec("analyze table t")
testKit.MustExec("analyze table t limit 4 buckets")
Copy link
Member

Choose a reason for hiding this comment

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

Why use 4 buckets here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is the test's requirement. Each bucket should contain more than 1 values.

parser/parser.y Outdated
{
$$ = uint64(0)
}
| "LIMIT" NUM "BUCKETS"
Copy link
Member

Choose a reason for hiding this comment

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

how about change the syntax to analyze table xx with xx buckets?

maybe we can lean from mysql: https://dev.mysql.com/doc/refman/8.0/en/analyze-table.html

@@ -1385,10 +1387,14 @@ func (b *executorBuilder) buildAnalyze(v *plan.Analyze) Executor {
baseExecutor: newBaseExecutor(b.ctx, v.Schema(), v.ExplainID()),
tasks: make([]*analyzeTask, 0, len(v.ColTasks)+len(v.IdxTasks)),
}
maxNumBuckets := v.MaxNumBuckets
if maxNumBuckets == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

IMHO, it's better to more this validation to the parser or planner.

@alivxxx
Copy link
Contributor Author

alivxxx commented Sep 6, 2018

@shenli It depends on the user. Maybe the user wants to limit the stats memory usage, or just want to try and see if the plan gets better. Anyway, it is optional.

@coocood
Copy link
Member

coocood commented Sep 6, 2018

@lamxTyler
Seems the bucket number is not persistent, will the buckets gets splitted or merged by feedback?

@alivxxx
Copy link
Contributor Author

alivxxx commented Sep 6, 2018

@coocood Yes, it will. We can fix it in the following pr.

Copy link
Member

@winoros winoros left a comment

Choose a reason for hiding this comment

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

rest lgtm

@@ -680,7 +680,12 @@ func (b *planBuilder) buildAnalyzeAllIndex(as *ast.AnalyzeTableStmt) Plan {
return p
}

const defaultNumBuckets = 256
Copy link
Member

Choose a reason for hiding this comment

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

defaultMax?

@coocood
Copy link
Member

coocood commented Sep 6, 2018

LGTM

func (b *planBuilder) buildAnalyze(as *ast.AnalyzeTableStmt) (Plan, error) {
if as.MaxNumBuckets == 0 {
as.MaxNumBuckets = defaultMaxNumBuckets
Copy link
Member

Choose a reason for hiding this comment

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

should we set an upper limit for the MaxNumBuckets

Copy link
Contributor

@winkyao winkyao left a comment

Choose a reason for hiding this comment

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

LGTM

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

@alivxxx
Copy link
Contributor Author

alivxxx commented Sep 6, 2018

/run-all-tests

@alivxxx alivxxx added status/LGT3 The PR has already had 3 LGTM. status/all tests passed labels Sep 6, 2018
@alivxxx alivxxx merged commit e7afbb2 into pingcap:master Sep 6, 2018
@alivxxx alivxxx deleted the analyze branch September 6, 2018 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/statistics status/LGT3 The PR has already had 3 LGTM. type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants