diff --git a/infoschema/slow_log.go b/infoschema/slow_log.go index f92eed51d9f1e..4abd35a7f2de1 100644 --- a/infoschema/slow_log.go +++ b/infoschema/slow_log.go @@ -93,7 +93,7 @@ func ParseSlowLog(tz *time.Location, scanner *bufio.Scanner) ([][]types.Datum, e if startFlag { // Parse slow log field. - if strings.Contains(line, variable.SlowLogPrefixStr) { + if strings.HasPrefix(line, variable.SlowLogPrefixStr) { line = line[len(variable.SlowLogPrefixStr):] fieldValues := strings.Split(line, " ") for i := 0; i < len(fieldValues)-1; i += 2 { diff --git a/infoschema/slow_log_test.go b/infoschema/slow_log_test.go index f05eb28d7077b..a619f4b532642 100644 --- a/infoschema/slow_log_test.go +++ b/infoschema/slow_log_test.go @@ -50,6 +50,23 @@ select * from t;`) } expectRecordString := "2019-01-24 22:32:29.313255,405888132465033227,,0,0.216905,0.021,0,0,1,637,0,,,1,42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772,t1:1,t2:2,select * from t;" c.Assert(expectRecordString, Equals, recordString) + + // fix sql contain '# ' bug + slowLog = bytes.NewBufferString( + `# Time: 2019-01-24-22:32:29.313255 +0800 +select a# from t; +# Time: 2019-01-24-22:32:29.313255 +0800 +# Txn_start_ts: 405888132465033227 +# Query_time: 0.216905 +# Process_time: 0.021 Request_count: 1 Total_keys: 637 Processed_keys: 436 +# Is_internal: true +# Digest: 42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772 +# Stats: t1:1,t2:2 +select * from t; +`) + scanner = bufio.NewScanner(slowLog) + _, err = infoschema.ParseSlowLog(loc, scanner) + c.Assert(err, IsNil) } func (s *testSuite) TestSlowLogParseTime(c *C) {