-
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
*: record previous statement when commit is slow #11908
Conversation
Signed-off-by: Shuaipeng Yu <jackysp@gmail.com>
/run-check_dev_2 |
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
Codecov Report
@@ Coverage Diff @@
## master #11908 +/- ##
===========================================
Coverage 81.5251% 81.5251%
===========================================
Files 445 445
Lines 96071 96071
===========================================
Hits 78322 78322
Misses 12231 12231
Partials 5518 5518 |
infoschema/slow_log.go
Outdated
@@ -87,6 +88,7 @@ func parseSlowLogFile(tz *time.Location, filePath string) ([][]types.Datum, erro | |||
func ParseSlowLog(tz *time.Location, reader *bufio.Reader) ([][]types.Datum, error) { | |||
var rows [][]types.Datum | |||
startFlag := false | |||
prevStmtPrefix := variable.SlowLogPrevStmt + variable.SlowLogSpaceMarkStr |
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.
Make this to be a global const .
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
Signed-off-by: Shuaipeng Yu <jackysp@gmail.com>
@@ -712,38 +719,28 @@ func (a *ExecStmt) LogSlowQuery(txnTS uint64, succ bool) { | |||
copTaskInfo := sessVars.StmtCtx.CopTasksDetails() | |||
statsInfos := plannercore.GetStatsInfo(a.Plan) | |||
memMax := sessVars.StmtCtx.MemTracker.MaxConsumed() | |||
_, digest := sessVars.StmtCtx.SQLDigest() | |||
slowItems := &variable.SlowQueryLogItems{ |
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 better to be put inside the if...else...
branch? If the log level is higher than debug
, we can save an object allocation?
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 think it will return at https://github.com/pingcap/tidb/pull/11908/files#diff-350127760839dbfd52d23927f7ff2d95R706 if the log level is higher than debug.
Succ: succ, | ||
} | ||
if _, ok := a.StmtNode.(*ast.CommitStmt); ok { | ||
slowItems.PrevStmt = FormatSQL(sessVars.PrevStmt, sessVars) |
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.
PrevStmt
only records the last executed statement, it's not enough to find which sql in the transaction is slow.
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 all what we could do :)
PTAL @crazycs520 @zz-jason |
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 |
cherry pick to release-2.1 failed |
cherry pick to release-3.0 failed |
…gcap#12180) Conflicts: session/tidb.go sessionctx/variable/session.go
Signed-off-by: Shuaipeng Yu jackysp@gmail.com
What problem does this PR solve?
If
commit
is slow, the user is hard to know which statement was executed in the slow log.What is changed and how it works?
Add the previous statement for
commit
ifcommit
is slow.Check List
Tests
Code changes
Related changes
Release note
Record the previous statement in the slow log when
commit
is slow.