-
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
planner,executor: support admin show slow
command
#7785
Conversation
admin show slow
commandadmin show slow
command
Please fix ci. |
executor/executor.go
Outdated
|
||
dom := domain.GetDomain(e.ctx) | ||
slowQueries := dom.ShowSlowQuery(e.ShowSlow) | ||
for _, slow := range slowQueries { |
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 number of rows appended to chk
should be smaller than max_chunk_size
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 if the result is larger than max_chunk_size
, it has to be split into multiple batches?
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.
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 have to use a cursor to record how many slow queries have been returned to the client.
planner/core/planbuilder.go
Outdated
@@ -746,6 +750,23 @@ func buildShowDDLJobQueriesFields() *expression.Schema { | |||
return schema | |||
} | |||
|
|||
func buildShowSlowSchema() *expression.Schema { | |||
schema := expression.NewSchema(make([]*expression.Column, 0, 11)...) | |||
schema.Append(buildColumn("", "SQL", mysql.TypeVarchar, 256)) |
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.
length is too small.
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 1024?
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.
1024 still too small.
planner/core/planbuilder.go
Outdated
schema.Append(buildColumn("", "TRANSACTION_TS", mysql.TypeLonglong, 4)) | ||
schema.Append(buildColumn("", "USER", mysql.TypeVarchar, 32)) | ||
schema.Append(buildColumn("", "DB", mysql.TypeVarchar, 64)) | ||
schema.Append(buildColumn("", "TABLE_IDS", mysql.TypeVarchar, 64)) |
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.
length is too small.
planner/core/planbuilder.go
Outdated
schema.Append(buildColumn("", "USER", mysql.TypeVarchar, 32)) | ||
schema.Append(buildColumn("", "DB", mysql.TypeVarchar, 64)) | ||
schema.Append(buildColumn("", "TABLE_IDS", mysql.TypeVarchar, 64)) | ||
schema.Append(buildColumn("", "INDEX_IDS", mysql.TypeVarchar, 64)) |
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.
length is too small.
planner/core/planbuilder.go
Outdated
schema.Append(buildColumn("", "DETAILS", mysql.TypeVarchar, 256)) | ||
schema.Append(buildColumn("", "SUCC", mysql.TypeTiny, 2)) | ||
schema.Append(buildColumn("", "CONN_ID", mysql.TypeLonglong, 4)) | ||
schema.Append(buildColumn("", "TRANSACTION_TS", mysql.TypeLonglong, 4)) |
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.
length is too small
planner/core/planbuilder.go
Outdated
schema.Append(buildColumn("", "DURATION", mysql.TypeDuration, 64)) | ||
schema.Append(buildColumn("", "DETAILS", mysql.TypeVarchar, 256)) | ||
schema.Append(buildColumn("", "SUCC", mysql.TypeTiny, 2)) | ||
schema.Append(buildColumn("", "CONN_ID", mysql.TypeLonglong, 4)) |
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.
length is too small.
planner/core/planbuilder.go
Outdated
func buildShowSlowSchema() *expression.Schema { | ||
schema := expression.NewSchema(make([]*expression.Column, 0, 11)...) | ||
schema.Append(buildColumn("", "SQL", mysql.TypeVarchar, 256)) | ||
schema.Append(buildColumn("", "START", mysql.TypeTimestamp, 64)) |
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.
length is too big
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.
32?
planner/core/planbuilder.go
Outdated
schema := expression.NewSchema(make([]*expression.Column, 0, 11)...) | ||
schema.Append(buildColumn("", "SQL", mysql.TypeVarchar, 256)) | ||
schema.Append(buildColumn("", "START", mysql.TypeTimestamp, 64)) | ||
schema.Append(buildColumn("", "DURATION", mysql.TypeDuration, 64)) |
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.
length is too big
@@ -381,6 +381,12 @@ func (a *ExecStmt) logSlowQuery(txnTS uint64, succ bool) { | |||
if user != nil { | |||
userString = user.String() | |||
} | |||
if len(tableIDs) > 10 { |
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.
what about if len(tableIDs) > len("table_ids:")
?
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.
There is a comment for it already.
executor/show_test.go
Outdated
tk.MustQuery(`select sleep(1)`) | ||
|
||
// Collecting slow queries is asynchronous, wait a while to ensure it's done. | ||
time.Sleep(5 * time.Millisecond) |
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 5ms enough?
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 add a retry to make the test stable?
executor/show_test.go
Outdated
tk.MustExec("use test") | ||
tk.MustExec(`drop table if exists t`) | ||
tk.MustExec(`create table t(a bigint)`) | ||
tk.MustQuery(`select sleep(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.
We can't assume sleep 1s is a slow query, we need to use cfg.Log.SlowThreshold?
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
/run-all-tests |
I just started playing with this today :-) @tiancaiamao Is it possible to change the duration to be in |
What problem does this PR solve?
After this PR, together with #7688 and #7692, we can use
admin show slow
now.What is changed and how it works?
Build
ShowSlow
plan andShowSlowExec
executor.It works like this:
Check List
Tests
As the result fields always change, it's hard to put it into unit test.
I manually check the result to assure that works.
Related changes