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

*: support auto analyze partition table #7789

Merged
merged 5 commits into from
Oct 12, 2018

Conversation

alivxxx
Copy link
Contributor

@alivxxx alivxxx commented Sep 27, 2018

What problem does this PR solve?

Let auto analyze work for partition table.

What is changed and how it works?

Support analyze table for a specific partition, the syntax is alter table t analyze partition a, b index c, d or analyze table t partition a, b index c, d

Check List

Tests

  • Unit test

Code changes

  • Has exported function/method change

Side effects

  • None

Related changes

  • None

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

alivxxx commented Sep 28, 2018

PTAL @coocood @winoros

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.

lgtm

@winoros winoros added the status/LGT1 Indicates that a PR has LGTM 1. label Sep 29, 2018
sql := fmt.Sprintf("alter table %s analyze partition `%s`", tblName, def.Name.O)
statsTbl := h.GetPartitionStats(tblInfo, def.ID)
analyzed, err := h.autoAnalyzeTable(tblInfo, statsTbl, start, end, autoAnalyzeRatio, sql)
if analyzed {
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 analyze all partitions at once instead of only one partition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think only one partition is better because the partition stats is independent.

@alivxxx
Copy link
Contributor Author

alivxxx commented Oct 10, 2018

PTAL @zz-jason

}
}
if !found {
return nil, errors.New(fmt.Sprintf("Error in list of partitions to %s", tblInfo.Name.O))
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: "can not found the specified partition name xxx in the table definition"?

statsTbl := h.GetPartitionStats(tblInfo, def.ID)
analyzed, err := h.autoAnalyzeTable(tblInfo, statsTbl, start, end, autoAnalyzeRatio, sql)
if analyzed {
return err
Copy link
Member

Choose a reason for hiding this comment

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

if one of the partition is analyzed, the rest of the partitions can never get a change to be analyzed, I think we should continue to analyze other partitions instead just return and terminate the analyze command.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason that we only trigger one analyze once a time is that we can get the most updated auto analyze parameters. The rest of the partition can wait for the next round which is just 3s after.

Copy link
Contributor

Choose a reason for hiding this comment

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

we can get the most updated auto analyze parameters.

What does this mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In https://github.com/pingcap/tidb/blob/master/statistics/update.go#L654, we get the parameters like analyze time period, so if we continue analyze other tables, we may not use the latest parameters.

continue
}
for _, def := range pi.Definitions {
sql := fmt.Sprintf("alter table %s analyze partition `%s`", tblName, def.Name.O)
Copy link
Member

@zz-jason zz-jason Oct 10, 2018

Choose a reason for hiding this comment

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

It's wired that mysql uses the alter table statement to analyze the table partitions... https://dev.mysql.com/doc/refman/5.7/en/partitioning-maintenance.htm

despite the compatible issue, can we also support another syntax to analyze table partitions?

Copy link
Contributor Author

@alivxxx alivxxx Oct 10, 2018

Choose a reason for hiding this comment

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

Yes, we can also support syntax like analyze table t partition p.

@eurekaka
Copy link
Contributor

Conflicts detected with this refactor commit: #7879

Copy link
Contributor

@eurekaka eurekaka left a comment

Choose a reason for hiding this comment

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

LGTM

@eurekaka eurekaka added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Oct 12, 2018
@eurekaka
Copy link
Contributor

/run-all-tests

@zz-jason zz-jason merged commit 7229b32 into pingcap:master Oct 12, 2018
@alivxxx alivxxx deleted the analyze-partition branch October 15, 2018 02:54
alivxxx added a commit to alivxxx/tidb that referenced this pull request Dec 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/statistics 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