From 787b1d165cfcc2226d31bb9dd6dce38e4135c561 Mon Sep 17 00:00:00 2001 From: Hangjie Mo Date: Sat, 8 Feb 2025 20:00:53 +0800 Subject: [PATCH 1/2] update --- pkg/executor/slow_query.go | 5 ++++- pkg/executor/slow_query_test.go | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/pkg/executor/slow_query.go b/pkg/executor/slow_query.go index 572d83e6b7947..5d768c88b3e88 100644 --- a/pkg/executor/slow_query.go +++ b/pkg/executor/slow_query.go @@ -701,9 +701,12 @@ func (e *slowQueryRetriever) parseLog(ctx context.Context, sctx sessionctx.Conte valid = e.setColumnValue(sctx, row, tz, variable.SlowLogHostStr, host, e.checker, fileLine) } else if strings.HasPrefix(line, variable.SlowLogCopBackoffPrefix) { valid = e.setColumnValue(sctx, row, tz, variable.SlowLogBackoffDetail, line, e.checker, fileLine) - } else if strings.HasPrefix(line, variable.SlowLogWarnings) { + } else if strings.HasPrefix(line, variable.SlowLogWarnings+variable.SlowLogSpaceMarkStr) { line = line[len(variable.SlowLogWarnings+variable.SlowLogSpaceMarkStr):] valid = e.setColumnValue(sctx, row, tz, variable.SlowLogWarnings, line, e.checker, fileLine) + } else if strings.HasPrefix(line, variable.SlowLogDBStr+variable.SlowLogSpaceMarkStr) { + line = line[len(variable.SlowLogDBStr+variable.SlowLogSpaceMarkStr):] + valid = e.setColumnValue(sctx, row, tz, variable.SlowLogDBStr, line, e.checker, fileLine) } else { fields, values := splitByColon(line) for i := 0; i < len(fields); i++ { diff --git a/pkg/executor/slow_query_test.go b/pkg/executor/slow_query_test.go index 74be371cbb151..5d9dde144595a 100644 --- a/pkg/executor/slow_query_test.go +++ b/pkg/executor/slow_query_test.go @@ -258,6 +258,20 @@ select * from t; warnings := ctx.GetSessionVars().StmtCtx.GetWarnings() require.Len(t, warnings, 1) require.Equal(t, warnings[0].Err.Error(), "Parse slow log at line 2, failed field is Succ, failed value is abc, error is strconv.ParseBool: parsing \"abc\": invalid syntax") + + // issue 39940 + slowLog = bytes.NewBufferString( + `# Time: 2019-04-28T15:24:04.309074+08:00 +# DB: a: b +# Succ: true +select * from t; +`) + reader = bufio.NewReader(slowLog) + rows, err = parseSlowLog(ctx, reader) + require.NoError(t, err) + require.Len(t, rows, 1) + value, _ := rows[0][41].ToString() + require.Equal(t, value, "a: b") } // It changes variable.MaxOfMaxAllowedPacket, so must be stayed in SerialSuite. From 067114adc0566380cbb955cdc430aaa9311bf9ed Mon Sep 17 00:00:00 2001 From: Hangjie Mo Date: Sat, 8 Feb 2025 20:03:43 +0800 Subject: [PATCH 2/2] update --- pkg/executor/slow_query_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/executor/slow_query_test.go b/pkg/executor/slow_query_test.go index 5d9dde144595a..52ca050b6f7bb 100644 --- a/pkg/executor/slow_query_test.go +++ b/pkg/executor/slow_query_test.go @@ -263,6 +263,7 @@ select * from t; slowLog = bytes.NewBufferString( `# Time: 2019-04-28T15:24:04.309074+08:00 # DB: a: b +# Index_names: [t:i: a] # Succ: true select * from t; `) @@ -272,6 +273,8 @@ select * from t; require.Len(t, rows, 1) value, _ := rows[0][41].ToString() require.Equal(t, value, "a: b") + value, _ = rows[0][42].ToString() + require.Equal(t, value, "[t:i: a]") } // It changes variable.MaxOfMaxAllowedPacket, so must be stayed in SerialSuite.