-
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
executor: add ru details in slow log and INFORMATION_SCHEMA.SLOW_QUERY #49067
Changes from 1 commit
7d635be
1c9d27e
92b3482
6f38169
c4b5c80
0c822fa
d041b03
ee4f0a0
939a297
58b6731
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -138,6 +138,10 @@ func TestParseSlowLogFile(t *testing.T) { | |||||
# Plan_from_binding: true | ||||||
# Succ: false | ||||||
# IsExplicitTxn: true | ||||||
# Resource_group: default | ||||||
# Request_unit_read: 2.158 | ||||||
# Request_unit_write: 2.158 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use distinct value too. |
||||||
# Time_queued_by_rc: 0.05 | ||||||
# Plan_digest: 60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4 | ||||||
# Prev_stmt: update t set i = 1; | ||||||
use test; | ||||||
|
@@ -165,7 +169,7 @@ select * from t;` | |||||
`0.1,0.2,0.03,127.0.0.1:20160,0.05,0.6,0.8,0.0.0.0:20160,70724,65536,0,0,0,0,0,,` + | ||||||
`Cop_backoff_regionMiss_total_times: 200 Cop_backoff_regionMiss_total_time: 0.2 Cop_backoff_regionMiss_max_time: 0.2 Cop_backoff_regionMiss_max_addr: 127.0.0.1 Cop_backoff_regionMiss_avg_time: 0.2 Cop_backoff_regionMiss_p90_time: 0.2 Cop_backoff_rpcPD_total_times: 200 Cop_backoff_rpcPD_total_time: 0.2 Cop_backoff_rpcPD_max_time: 0.2 Cop_backoff_rpcPD_max_addr: 127.0.0.1 Cop_backoff_rpcPD_avg_time: 0.2 Cop_backoff_rpcPD_p90_time: 0.2 Cop_backoff_rpcTiKV_total_times: 200 Cop_backoff_rpcTiKV_total_time: 0.2 Cop_backoff_rpcTiKV_max_time: 0.2 Cop_backoff_rpcTiKV_max_addr: 127.0.0.1 Cop_backoff_rpcTiKV_avg_time: 0.2 Cop_backoff_rpcTiKV_p90_time: 0.2,` + | ||||||
`0,0,1,0,1,1,0,,60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4,` + | ||||||
`,update t set i = 1;,select * from t;` | ||||||
`,update t set i = 1;,select * from t;,default,2.158,2.158,0.05` | ||||||
require.Equal(t, expectRecordString, recordString) | ||||||
|
||||||
// Issue 20928 | ||||||
|
@@ -188,7 +192,7 @@ select * from t;` | |||||
`0.1,0.2,0.03,127.0.0.1:20160,0.05,0.6,0.8,0.0.0.0:20160,70724,65536,0,0,0,0,0,,` + | ||||||
`Cop_backoff_regionMiss_total_times: 200 Cop_backoff_regionMiss_total_time: 0.2 Cop_backoff_regionMiss_max_time: 0.2 Cop_backoff_regionMiss_max_addr: 127.0.0.1 Cop_backoff_regionMiss_avg_time: 0.2 Cop_backoff_regionMiss_p90_time: 0.2 Cop_backoff_rpcPD_total_times: 200 Cop_backoff_rpcPD_total_time: 0.2 Cop_backoff_rpcPD_max_time: 0.2 Cop_backoff_rpcPD_max_addr: 127.0.0.1 Cop_backoff_rpcPD_avg_time: 0.2 Cop_backoff_rpcPD_p90_time: 0.2 Cop_backoff_rpcTiKV_total_times: 200 Cop_backoff_rpcTiKV_total_time: 0.2 Cop_backoff_rpcTiKV_max_time: 0.2 Cop_backoff_rpcTiKV_max_addr: 127.0.0.1 Cop_backoff_rpcTiKV_avg_time: 0.2 Cop_backoff_rpcTiKV_p90_time: 0.2,` + | ||||||
`0,0,1,0,1,1,0,,60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4,` + | ||||||
`,update t set i = 1;,select * from t;` | ||||||
`,update t set i = 1;,select * from t;,default,2.158,2.158,0.05` | ||||||
require.Equal(t, expectRecordString, recordString) | ||||||
|
||||||
// fix sql contain '# ' bug | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3096,6 +3096,14 @@ const ( | |
SlowLogIsWriteCacheTable = "IsWriteCacheTable" | ||
// SlowLogIsSyncStatsFailed is used to indicate whether any failure happen during sync stats | ||
SlowLogIsSyncStatsFailed = "IsSyncStatsFailed" | ||
// SlowLogResourceGroup is the resource group name that the current session bind. | ||
SlowLogResourceGroup = "Resource_group" | ||
// SlowLogRRU is the read request_unit(RU) cost | ||
SlowLogRRU = "Request_unit_read" | ||
// SlowLogRRU is the write request_unit(RU) cost | ||
SlowLogWRU = "Request_unit_write" | ||
// SlowLogWaitRUDuration is the total duration for kv requests to wait available request-units. | ||
SlowLogWaitRUDuration = "Time_queued_by_rc" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe we need to add tikv side wait duration in the future. |
||
) | ||
|
||
// GenerateBinaryPlan decides whether we should record binary plan in slow log and stmt summary. | ||
|
@@ -3151,6 +3159,10 @@ type SlowQueryLogItems struct { | |
UsedStats map[int64]*stmtctx.UsedStatsInfoForTable | ||
IsSyncStatsFailed bool | ||
Warnings []JSONSQLWarnForSlowLog | ||
ResourceGroupName string | ||
RRU float64 | ||
WRU float64 | ||
WaitRUDuration time.Duration | ||
} | ||
|
||
// SlowLogFormat uses for formatting slow log. | ||
|
@@ -3348,6 +3360,20 @@ func (s *SessionVars) SlowLogFormat(logItems *SlowQueryLogItems) string { | |
if len(logItems.BinaryPlan) != 0 { | ||
writeSlowLogItem(&buf, SlowLogBinaryPlan, logItems.BinaryPlan) | ||
} | ||
|
||
if s.ResourceGroupName != "" { | ||
writeSlowLogItem(&buf, SlowLogResourceGroup, logItems.ResourceGroupName) | ||
} | ||
if logItems.WaitRUDuration > time.Duration(0) { | ||
writeSlowLogItem(&buf, SlowLogWaitRUDuration, strconv.FormatFloat(logItems.KVTotal.Seconds(), 'f', -1, 64)) | ||
} | ||
if logItems.RRU > 0.0 { | ||
writeSlowLogItem(&buf, SlowLogRRU, strconv.FormatFloat(logItems.RRU, 'f', -1, 64)) | ||
} | ||
if logItems.WRU > 0.0 { | ||
writeSlowLogItem(&buf, SlowLogWRU, strconv.FormatFloat(logItems.WRU, 'f', -1, 64)) | ||
} | ||
|
||
if logItems.PrevStmt != "" { | ||
writeSlowLogItem(&buf, SlowLogPrevStmt, logItems.PrevStmt) | ||
} | ||
|
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 run
make bazel_prepare
and upload the dependencies.