-
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, session: support for events_statements_summary_by_digest #12017
Conversation
Codecov Report
@@ Coverage Diff @@
## master #12017 +/- ##
================================================
- Coverage 81.4122% 81.1907% -0.2215%
================================================
Files 454 454
Lines 99291 97973 -1318
================================================
- Hits 80835 79545 -1290
- Misses 12664 12707 +43
+ Partials 5792 5721 -71 |
c012f4f
to
3e63c5b
Compare
ce890f4
to
e1e3cf3
Compare
/bench |
@@ Benchmark Diff @@
================================================================================
--- tidb: 1ef81a8620997103dd81fa2f74fd09a3a0683c1b
+++ tidb: e1e3cf3127b3e1eeb6d25aa507d0b541b1bbade1
tikv: 5ad30cba22f80853279c990b4030fb247f32b3ad
pd: c7c572a7dc9710aca57cb0bddf4d9bca6c4a111b
================================================================================
test-1: < oltp_insert >
* QPS : 21432.92 ± 0.3035% (std=48.71) delta: 0.12%
* AvgMs : 11.94 ± 0.2933% (std=0.03) delta: -0.14%
* PercentileMs99 : 42.61 ± 0.0000% (std=0.00) delta: 0.00%
test-2: < oltp_update_non_index >
* QPS : 29627.64 ± 0.3367% (std=62.74) delta: 0.05%
* AvgMs : 8.64 ± 0.3241% (std=0.02) delta: -0.05%
* PercentileMs99 : 30.59 ± 1.0788% (std=0.27) delta: -0.71%
test-3: < oltp_read_write >
* QPS : 36883.62 ± 0.2365% (std=61.13) delta: -0.24%
* AvgMs : 139.37 ± 0.2188% (std=0.21) delta: 0.24%
* PercentileMs99 : 257.95 ± 0.0000% (std=0.00) delta: 0.00%
test-4: < oltp_point_select >
* QPS : 74881.82 ± 3.0726% (std=1336.49) delta: -0.92%
* AvgMs : 3.42 ± 3.2768% (std=0.06) delta: 0.97%
* PercentileMs99 : 7.43 ± 0.0000% (std=0.00) delta: -0.70%
test-5: < oltp_update_index >
* QPS : 17080.78 ± 0.2005% (std=22.25) delta: -0.02%
* AvgMs : 14.98 ± 0.2169% (std=0.02) delta: -0.01%
* PercentileMs99 : 47.99 ± 1.0877% (std=0.43) delta: 0.00%
|
@@ Benchmark Diff @@
================================================================================
--- tidb: bb5bfa4bd7f9b3bb67e06d3de14a82c61c2eb9d8
+++ tidb: e1e3cf3127b3e1eeb6d25aa507d0b541b1bbade1
tikv: 5ad30cba22f80853279c990b4030fb247f32b3ad
pd: c7c572a7dc9710aca57cb0bddf4d9bca6c4a111b
================================================================================
tidb_max_cpu: 19.40, delta: -0.50%
tikv_max_cpu: 13.15, delta: 3.45%
tidb_max_memory: 1784.65 MiB, delta: -1.13%
tikv_max_memory: 59841.52 MiB, delta: -0.02%
Measured tpmC (NewOrders): 21981.93, delta: 0.49% |
e1e3cf3
to
d15dbd2
Compare
infoschema/perfschema/tables.go
Outdated
@@ -14,10 +14,19 @@ | |||
package perfschema | |||
|
|||
import ( | |||
"fmt" |
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.
Plz add a blank line below this.
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.
) | ||
|
||
const ( | ||
tableNameEventsStatementsSummaryByDigest = "events_statements_summary_by_digest" |
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.
I am not sure if we should resurrect perf_schema, maybe we can put it to info_schema?
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.
Some table names are the same, like tables.go.
And performance schema is independent with information schema in MySQL.
So I prefer the directory to be like this:
--virtual_table
----infoschema
----perfschema
----sys
But now, I prefer not to change the directory structure in this PR. Maybe fixing it in another PR is better, if needed.
@@ -0,0 +1,198 @@ | |||
// Copyright 2016 PingCAP, Inc. |
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 is 2019 now.
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.
@@ -0,0 +1,303 @@ | |||
package stmtsummary |
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 license and format imports.
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.
infoschema/perfschema/tables.go
Outdated
|
||
// AddRecord implements table.Table AddRecord interface. | ||
func (vt *perfSchemaTable) AddRecord(ctx sessionctx.Context, r []types.Datum, opts ...table.AddRecordOption) (recordID int64, err error) { | ||
fmt.Println("add record") |
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.
Please remove this manual-debugging code
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.
infoschema/perfschema/tables.go
Outdated
|
||
// UpdateRecord implements table.Table UpdateRecord interface. | ||
func (vt *perfSchemaTable) UpdateRecord(ctx sessionctx.Context, h int64, oldData, newData []types.Datum, touched []bool) error { | ||
fmt.Println("update record") |
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.
Ditto
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 NewStmtSummaryByDigest() *stmtSummaryByDigest { | ||
maxStmtCount := config.GetGlobalConfig().StmtSummary.MaxStmtCount | ||
return &stmtSummaryByDigest{ | ||
summaryMap: kvcache.NewSimpleLRUCache(maxStmtCount, 0, 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.
Is it possible that we still need memory quota, say, if the maxStmtCount is set to be very very large?
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 complicates the configuration of statement summary, which makes users more confusing. If the user sets max-stmt-count to a very large value, he can also set the quota to a very large value.
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
5d66398
to
2c6dcc7
Compare
infoschema/perfschema/tables.go
Outdated
return table.VirtualTable | ||
} | ||
|
||
func dataForEventsStatementsSummaryByDigest(ctx sessionctx.Context) [][]types.Datum { |
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 can inline this method.
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.
infoschema/perfschema/tables.go
Outdated
} | ||
|
||
// RowWithCols implements table.Table RowWithCols interface. | ||
func (vt *perfSchemaTable) RowWithCols(ctx sessionctx.Context, h int64, cols []*table.Column) ([]types.Datum, error) { |
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.
Those unsupported methods are already implemented by dummy VirtualTable
which is embedded in perfSchemaTable
, we can remove those methods for perfSchemaTable
.
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.
|
||
// A LRU cache that stores statement summary. | ||
type stmtSummaryByDigest struct { | ||
// It's rare to read concurrently, so RWMutex is not needed. |
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 comment contradicts the implementation.
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.
I mean, we need Mutex
instead of RWMutex
.
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.
Then why use RWMutex
?
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.
I'm not using RWMutex
.
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.
ss.Unlock() | ||
|
||
// Lock a single entry, not the whole cache. | ||
if summary != nil { |
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.
Seems summary
can not be nil.
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 an entry is not found in the cache, we create newSummary
, so summary
stays nil.
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.
Then why not define summary
and addStmtExecInfoToSummary
in the ok
block?
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 we can create a new summary without adding the stats, call addStmtExecInfoToSummary later.
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.
Separate addStmtExecInfoToSummary
and the ok
block because I want to move addStmtExecInfoToSummary
out of the big cache lock, and add a smaller lock to it.
Why do I need to create a new summary?
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.
So we can remove the if summary != nil
check
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 code is simplified a little.
if sei.TotalLatency < ss.minLatency { | ||
ss.minLatency = sei.TotalLatency | ||
} | ||
// TODO: uint64 overflow |
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 don't need to worry about 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.
8d1c9f0
to
f29aad4
Compare
} | ||
|
||
// Add a new StmtExecInfo to stmtSummary | ||
func addStmtExecInfoToSummary(sei *StmtExecInfo, ss *stmtSummary) { |
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 about that we make this function a method of stmtSummary
?
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.
- change the function name to
NewStmtSummary(sei *StmtExecInfo)
ss := new(stmtSummary); ss.convertFromExecInfo(sei)
which one?
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.
func (ss *stmtSummary) add(sei *StmtExecInfo)
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.
…y is set to false
d8ce20f
to
5e59a41
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 |
/run-all-tests |
cherry pick to release-3.0 failed |
…ingcap#12017) cherry-pick 12217 to release-3.0
…ingcap#12017) cherry-pick 12017 to release-3.1
…_digest pingcap#12017 (pingcap#12306)" This reverts commit a3e1d01.
It seems that, not for sure, we failed to cherry-pick this commit to release-3.0. Please comment '/run-cherry-picker' to try to trigger the cherry-picker if we did fail to cherry-pick this commit before. @djshow832 PTAL. |
What problem does this PR solve?
Support system table
events_statements_summary_by_digest
, which is used to summary statements by digest.What is changed and how it works?
perfSchemaTable
, and add a new tableevents_statements_summary_by_digest
.tidb_enable_stmt_summary
and add configurationsmax-stmt-count
&max-sql-length
.StmtSummary
after a SQL runs.StmtSummary
when the user queriesevents_statements_summary_by_digest
.Check List
Tests
Code changes
Side effects
Related changes