Skip to content

Commit

Permalink
infoschema/slow_query: fix parser bug when sql contain # (#10271) (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
crazycs520 authored and Zhang Jian committed Apr 26, 2019
1 parent dd64171 commit 8e550cd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion infoschema/slow_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 17 additions & 0 deletions infoschema/slow_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 8e550cd

Please sign in to comment.