-
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
infoschema, util: add table events_statements_summary_by_digest_history
#13813
Conversation
/bench |
Benchmark Report
@@ Benchmark Diff @@
================================================================================
--- tidb: 1c65ab936f270dd831b7923f7e1feb2b7ae6b4d1
+++ tidb: 5ed1ffbb6737f248dcb79dd64a3912194e9ab221
tikv: f6869aff3587ba0bcec47e099e57fdf11f63cbaf
pd: a87c9eb3181eb99cd6ae0128d07bad6d99b0c579
================================================================================
oltp_update_non_index:
* QPS: 4717.87 ± 0.18% (std=5.80) delta: 0.08% (p=0.715)
* Latency p50: 27.13 ± 0.00% (std=0.00) delta: -0.08%
* Latency p99: 41.68 ± 4.11% (std=1.12) delta: -1.83%
oltp_insert:
* QPS: 4779.43 ± 0.45% (std=14.57) delta: -0.03% (p=0.888)
* Latency p50: 26.77 ± 0.47% (std=0.08) delta: 0.04%
* Latency p99: 44.85 ± 8.36% (std=2.63) delta: 1.49%
oltp_read_write:
* QPS: 15459.98 ± 0.58% (std=63.63) delta: 0.14% (p=0.679)
* Latency p50: 165.91 ± 0.64% (std=0.72) delta: -0.17%
* Latency p99: 300.92 ± 6.40% (std=13.55) delta: -1.40%
oltp_update_index:
* QPS: 4267.52 ± 0.33% (std=9.61) delta: 0.32% (p=0.105)
* Latency p50: 29.99 ± 0.32% (std=0.07) delta: -0.22%
* Latency p99: 52.27 ± 2.39% (std=0.88) delta: -2.94%
oltp_point_select:
* QPS: 40097.44 ± 0.25% (std=88.29) delta: 0.87% (p=0.004)
* Latency p50: 3.19 ± 0.31% (std=0.01) delta: -0.85%
* Latency p99: 9.82 ± 0.92% (std=0.09) delta: 0.00%
|
5ed1ffb
to
8e2d491
Compare
8e2d491
to
4a264a5
Compare
/run-all-tests |
/run-unit-test |
Codecov Report
@@ Coverage Diff @@
## master #13813 +/- ##
================================================
- Coverage 80.1862% 80.1738% -0.0125%
================================================
Files 481 481
Lines 120790 120593 -197
================================================
- Hits 96857 96684 -173
+ Misses 16224 16187 -37
- Partials 7709 7722 +13 |
// historySize gets the history size for summaries. | ||
func (ssMap *stmtSummaryByDigestMap) historySize() int { | ||
size := int(atomic.LoadInt32(&ssMap.sysVars.historySize)) | ||
if size <= 0 { |
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.
Redundant check?
Already do the check when setting the value. line#445
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.
Agree, we should set history size in SetHistorySize
at once.
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.
It's normal that SetHistorySize
is always called after bootstrap. But I do the check just in case that there would be any bug that prevents SetHistorySize
be called after bootstrap, and it'll be a big problem.
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 I find out the problem.
If TiDB is just upgraded, global variables stored in TiKV doesn't include tidb_stmt_summary_history_size
, so the loaded GlobalVariableCache
doesn't include this variable, and then historySize
won't be initialized.
I'll fix it.
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.
Addressed.
func (ssMap *stmtSummaryByDigestMap) historySize() int { | ||
size := int(atomic.LoadInt32(&ssMap.sysVars.historySize)) | ||
if size <= 0 { | ||
size = 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.
Why the default value of historySize
is 1? Should be 0?
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.
or DefTiDBStmtSummaryHistorySize
?
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.
Default value is DefTiDBStmtSummaryHistorySize
. Just in case that historySize
is never set.
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.
Addressed. Now I make sure that historySize
is always initialized, so this judgement is removed.
size = 0 | ||
} | ||
} | ||
if size > 0 { |
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.
historySize
will always not set to 0?
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.
after
set @@session.tidb_stmt_summary_history_size=0;
set @@global.tidb_stmt_summary_history_size=0;
, the historySize
still not 0?
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.
Yes. Actually, history includes the current summary. So historySize=1
indicates that there's only the current summary, and historySize=0
makes no sense.
I designed it like this because I wish xxx_history
would be enough to see all the summaries.
What do you think?
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.
Addressed. Now historySize
is allowed to be 0.
return ssbd | ||
} | ||
|
||
func (ssbd *stmtSummaryByDigest) add(sei *StmtExecInfo) { | ||
func (ssbd *stmtSummaryByDigest) add(sei *StmtExecInfo, beginTime int64, historySize int) { | ||
// Enclose this block in a function to ensure the lock will always be released. |
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.
return if historySize == 0
?
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.
Good idea. Addressed.
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.
? how addressed?
eec2e5c
to
09e49b3
Compare
defer ssbd.Unlock() | ||
|
||
var ssElement *stmtSummaryByDigestElement | ||
ok := false |
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 logic is tricky here, please rename this variable and add some comments
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.
Addressed.
|
||
// `historySize` might be modified, so check expiration every time. | ||
if historySize == 0 { | ||
historySize = 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.
This assignment looks weird. Why reassign historySize
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.
If historySize
is 0, displayed history summaries in events_statements_summary_by_digest_history
should be empty, but summary cannot be cleared, because table events_statements_summary_by_digest
still needs it.
Alternatively, I can code for ssbd.history.Len() > historySize && ssbd.history.Len() > 1 {...}
. But it looks also weird.
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.
Addressed.
09e49b3
to
93471b8
Compare
93471b8
to
a5a6baf
Compare
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
a5a6baf
to
6e5fd44
Compare
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
/run-all-tests |
6e5fd44
to
0a164dd
Compare
What problem does this PR solve?
Add a history table for statement summary for storing summaries that expired from
events_statements_summary_by_digest
.What is changed and how it works?
Add a virtual table
events_statements_summary_by_digest_history
. When a summary expires fromevents_statements_summary_by_digest
, put it intoevents_statements_summary_by_digest_history
.There's a system variable
tidb_stmt_summary_history_size
to control the history size for each summary.Check List
Tests
Code changes
Side effects
Related changes
Release note
events_statements_summary_by_digest_history
to store history summaries ofevents_statements_summary_by_digest
.