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

stats: do not wait for data unchanged when auto analyze #7022

Merged
merged 7 commits into from
Jul 10, 2018

Conversation

alivxxx
Copy link
Contributor

@alivxxx alivxxx commented Jul 9, 2018

What have you changed? (mandatory)

Before this PR, if the table is continous updated, we cannot auto analyze the table even if modify count / count is greater than auto-analyze ratio, because we have the limit that the table must not be modified within a time peroid. This PR removes the restriction.

What are the type of the changes (mandatory)?

  • Improvement (non-breaking change which is an improvement to an existing feature)

How has this PR been tested (mandatory)?

Unit test

PTAL @coocood @winoros @zz-jason @fipped

@winoros
Copy link
Member

winoros commented Jul 9, 2018

What will happen if the following scene occur:
The limit is x. The continuous writing row count is more the 2x of it.

Will it trigger multiple analyze in a row?

@@ -533,28 +533,37 @@ const (
// AutoAnalyzeMinCnt means if the count of table is less than this value, we needn't do auto analyze.
var AutoAnalyzeMinCnt int64 = 1000

func tableAnalyzed(tbl *Table) bool {
Copy link
Member

Choose a reason for hiding this comment

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

Need comments.

Copy link
Member

@jackysp jackysp 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 Jul 10, 2018

@winoros Yes.

}
}
for _, idx := range tbl.Indices {
if idx.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.

What is the idx.Len()? The length of histogram?

@alivxxx alivxxx added the type/enhancement The issue or PR belongs to an enhancement. label Jul 10, 2018
analyzed := tableAnalyzed(tbl)
if !analyzed {
t := time.Unix(0, oracle.ExtractPhysical(tbl.Version)*int64(time.Millisecond))
return time.Since(t) >= limit
Copy link
Member

Choose a reason for hiding this comment

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

The AutoAnalyzeMinCnt is not considered?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's considered in line 597.

Copy link
Contributor

@zimulala zimulala left a comment

Choose a reason for hiding this comment

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

LGTM

@zimulala zimulala added the status/LGT2 Indicates that a PR has LGTM 2. label Jul 10, 2018
zimulala
zimulala previously approved these changes Jul 10, 2018
@zimulala zimulala closed this Jul 10, 2018
@zimulala zimulala reopened this Jul 10, 2018
@zimulala
Copy link
Contributor

/run-all-test

@alivxxx
Copy link
Contributor Author

alivxxx commented Jul 10, 2018

/run-all-tests

@@ -587,7 +594,7 @@ func (h *Handle) HandleAutoAnalyze(is infoschema.InfoSchema) error {
for _, tbl := range tbls {
tblInfo := tbl.Meta()
statsTbl := h.GetTableStats(tblInfo)
if statsTbl.Pseudo || statsTbl.Count == 0 {
if statsTbl.Pseudo || statsTbl.Count < AutoAnalyzeMinCnt || statsTbl.ModifyCount == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

We can remove the statsTbl.Pseudo since `statsTble.ModifyCount == 0' covers the case.

Copy link
Member

Choose a reason for hiding this comment

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

When adding an index, ModifyCount may be 0, but we need to analyze the newly added index.

return true
}
}
return false
}

// needAnalyzeTable checks if we need to analyze the table. If the table is not analyzed,
Copy link
Member

Choose a reason for hiding this comment

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

If the table has never been analyzed,

return true
}
}
return false
}

// needAnalyzeTable checks if we need to analyze the table. If the table is not analyzed,
// we need to analyze it when it has not been modified for a time. If the table is analyzed,
Copy link
Member

Choose a reason for hiding this comment

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

If the table had been analyzed before

@alivxxx
Copy link
Contributor Author

alivxxx commented Jul 10, 2018

PTAL @coocood @shenli

@shenli
Copy link
Member

shenli commented Jul 10, 2018

LGTM


// needAnalyzeTable checks if we need to analyze the table. If the table has never been analyzed,
// we need to analyze it when it has not been modified for a time. If the table had been analyzed before,
// we need to analyze it when the `modify count / count` is greater than autoAnalyzeRatio.
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 this:

// needAnalyzeTable checks if we need to analyze the table.
// 1. If the table has never been analyzed, we need to analyze it when it has
//    not been modified for a time.
// 2. If the table had been analyzed before, we need to analyze it when
//    "tbl.ModifyCount/tbl.Count > autoAnalyzeRatio".

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 Jul 10, 2018

/run-all-tests

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.

7 participants