-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
*: add statistic lock/unlock function #38387
Conversation
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
3135d54
to
2678a7b
Compare
/run-unit-test |
2 similar comments
/run-unit-test |
/run-unit-test |
be1e602
to
bb32af0
Compare
/run-unit-test |
/run-all-tests |
/run-all-tests |
tableID = task.idxIncrementalExec.tableID | ||
} | ||
// skip locked tables | ||
if !statsHandle.IsTableLocked(tableID.TableID) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can use warnings to remind users that the table is locked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. Add it.
statistics/handle/handle.go
Outdated
} | ||
|
||
if len(tids) > 1 { | ||
err = finishTransaction(ctx, exec, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it is better to defer finishTransaction
right after begin begin pessimistic
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if finishTransaction get failed, 'mysql.stats_table_locked' won't be updated, and "h.tableLocked = tableLocked" won't be execute, so h.tableLocked is consistent with table.
if change to defer finishTransaction , if finishTransaction get failed, table won't be updated but h.tableLocked will be updated, data in table and memory is inconsistent.
@pingandb Please solve the conflicting. |
statistics/handle/handle.go
Outdated
} | ||
|
||
// GetTableLockedAndClear for unit test only | ||
func (h *Handle) GetTableLockedAndClear() []int64 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add ForTest
to make its scope clearer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When locking a partition table, add partition IDs to stats_table_locked
. Rest LGTM
statistics/handle/handle.go
Outdated
|
||
exec := h.mu.ctx.(sqlexec.SQLExecutor) | ||
|
||
if len(tids) > 1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now we also have to consider len(pids)
. Maybe we can all use begin pessimistic
for simplicity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok.
statistics/handle/handle.go
Outdated
ctx := kv.WithInternalSourceType(context.Background(), kv.InternalTxnStats) | ||
|
||
exec := h.mu.ctx.(sqlexec.SQLExecutor) | ||
if len(tids) > 1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
/merge |
This pull request has been accepted and is ready to merge. Commit hash: 1d7fdc6
|
TiDB MergeCI notify🔴 Bad News! New failing [3] after this pr merged.
|
What problem does this PR solve?
Issue Number: close #xxx
Problem Summary:
Sometime peformance drop due to the explain change that caused by statistic info change after data changes in table.
So we want to introduce table statistic lock/unlock function to avoid unexpected peformance drop by statistic changes.
What is changed and how it works?
The main idea is adding new table mysql.stats_table_locked to record which table is locked, and when doing manual/auto table analyze, check whether table is locked, if locked, skip analyse. And I also filter the locked table in session stat collector operations, that session stat collector won't collect the statistic data of locked table.
Add SQL syntax 'lock/unlock stats xxx(table name)' to add/remove table name to/from mysql.stats_table_locked.
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.