-
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
stats: reduce conflict for updating column size #7124
Conversation
statistics/update.go
Outdated
if err != nil { | ||
return | ||
} | ||
values = append(values, fmt.Sprintf("(%d, 0, %d, 0, %d)", id, key, val)) |
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.
The val
is delta, we need to insert the new value.
statistics/update.go
Outdated
|
||
sql := fmt.Sprintf("select * from mysql.stats_histograms where table_id = %d and is_index = 0 for update", id) |
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.
We should select needed columns instead of *
for compatibility.
statistics/update.go
Outdated
@@ -344,17 +345,16 @@ func (h *Handle) dumpTableStatColSizeToKV(id int64, delta variable.TableDelta) ( | |||
err = finishTransaction(ctx, exec, err) | |||
}() | |||
version := h.mu.ctx.Txn().StartTS() | |||
|
|||
values := make([]string, 0, len(delta.ColSize)) | |||
for key, val := range delta.ColSize { |
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.
rename to histID, deltaColSize
would be more clear.
/run-all-tests |
/run-integration-ddl-test |
How to know that it is effective? |
@lamxTyler we need to do a manual test and verify that the conflict is reduced. |
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.
LGTM
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.
LGTM
What have you changed? (mandatory)
By using
insert ... on duplicate
, we can reduce the possibility of conflict because of less execution time.Fix #7079.
PTAL @coocood @zz-jason @winoros
What is the type of the changes? (mandatory)
How has this PR been tested? (mandatory)
Existing unit test.
Does this PR affect documentation (docs/docs-cn) update? (mandatory)
No.
Does this PR affect tidb-ansible update? (mandatory)
No.
Does this PR need to be added to the release notes? (mandatory)
No.