diff --git a/infoschema/slow_log.go b/infoschema/slow_log.go index 68a0053eb81d4..9f1014c07fe91 100644 --- a/infoschema/slow_log.go +++ b/infoschema/slow_log.go @@ -37,6 +37,7 @@ var slowQueryCols = []columnInfo{ {variable.SlowLogTimeStr, mysql.TypeTimestamp, 26, 0, nil, nil}, {variable.SlowLogTxnStartTSStr, mysql.TypeLonglong, 20, mysql.UnsignedFlag, nil, nil}, {variable.SlowLogUserStr, mysql.TypeVarchar, 64, 0, nil, nil}, + {variable.SlowLogHostStr, mysql.TypeVarchar, 64, 0, nil, nil}, {variable.SlowLogConnIDStr, mysql.TypeLonglong, 20, mysql.UnsignedFlag, nil, nil}, {variable.SlowLogQueryTimeStr, mysql.TypeDouble, 22, 0, nil, nil}, {execdetails.ProcessTimeStr, mysql.TypeDouble, 22, 0, nil, nil}, @@ -162,6 +163,7 @@ type slowQueryTuple struct { time time.Time txnStartTs uint64 user string + host string connID uint64 queryTime float64 processTime float64 @@ -205,7 +207,13 @@ func (st *slowQueryTuple) setFieldValue(tz *time.Location, field, value string) } st.txnStartTs = num case variable.SlowLogUserStr: - st.user = value + fields := strings.SplitN(value, "@", 2) + if len(field) > 0 { + st.user = fields[0] + } + if len(field) > 1 { + st.host = fields[1] + } case variable.SlowLogConnIDStr: num, err := strconv.ParseUint(value, 10, 64) if err != nil { @@ -325,6 +333,7 @@ func (st *slowQueryTuple) convertToDatumRow() []types.Datum { })) record = append(record, types.NewUintDatum(st.txnStartTs)) record = append(record, types.NewStringDatum(st.user)) + record = append(record, types.NewStringDatum(st.host)) record = append(record, types.NewUintDatum(st.connID)) record = append(record, types.NewFloat64Datum(st.queryTime)) record = append(record, types.NewFloat64Datum(st.processTime)) diff --git a/infoschema/slow_log_test.go b/infoschema/slow_log_test.go index 5692f609c8a47..1dc076af79948 100644 --- a/infoschema/slow_log_test.go +++ b/infoschema/slow_log_test.go @@ -53,7 +53,7 @@ select * from t;`) } recordString += str } - expectRecordString := "2019-04-28 15:24:04.309074,405888132465033227,,0,0.216905,0.021,0,0,1,637,0,,,1,42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772,t1:1,t2:2,0.1,0.2,0.03,127.0.0.1:20160,0.05,0.6,0.8,0.0.0.0:20160,70724,select * from t;" + expectRecordString := "2019-04-28 15:24:04.309074,405888132465033227,,,0,0.216905,0.021,0,0,1,637,0,,,1,42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772,t1:1,t2:2,0.1,0.2,0.03,127.0.0.1:20160,0.05,0.6,0.8,0.0.0.0:20160,70724,select * from t;" c.Assert(expectRecordString, Equals, recordString) // fix sql contain '# ' bug diff --git a/infoschema/tables_test.go b/infoschema/tables_test.go index 31020e99ed846..18f42d78d0948 100644 --- a/infoschema/tables_test.go +++ b/infoschema/tables_test.go @@ -352,10 +352,10 @@ select * from t_slim;`)) tk.MustExec("set time_zone = '+08:00';") re := tk.MustQuery("select * from information_schema.slow_query") re.Check(testutil.RowsWithSep("|", - "2019-02-12 19:33:56.571953|406315658548871171|root@127.0.0.1|6|4.895492|0.161|0.101|0.092|1|100001|100000|test||0|42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772|t1:1,t2:2|0.1|0.2|0.03|127.0.0.1:20160|0.05|0.6|0.8|0.0.0.0:20160|70724|select * from t_slim;")) + "2019-02-12 19:33:56.571953|406315658548871171|root|127.0.0.1|6|4.895492|0.161|0.101|0.092|1|100001|100000|test||0|42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772|t1:1,t2:2|0.1|0.2|0.03|127.0.0.1:20160|0.05|0.6|0.8|0.0.0.0:20160|70724|select * from t_slim;")) tk.MustExec("set time_zone = '+00:00';") re = tk.MustQuery("select * from information_schema.slow_query") - re.Check(testutil.RowsWithSep("|", "2019-02-12 11:33:56.571953|406315658548871171|root@127.0.0.1|6|4.895492|0.161|0.101|0.092|1|100001|100000|test||0|42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772|t1:1,t2:2|0.1|0.2|0.03|127.0.0.1:20160|0.05|0.6|0.8|0.0.0.0:20160|70724|select * from t_slim;")) + re.Check(testutil.RowsWithSep("|", "2019-02-12 11:33:56.571953|406315658548871171|root|127.0.0.1|6|4.895492|0.161|0.101|0.092|1|100001|100000|test||0|42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772|t1:1,t2:2|0.1|0.2|0.03|127.0.0.1:20160|0.05|0.6|0.8|0.0.0.0:20160|70724|select * from t_slim;")) } func (s *testTableSuite) TestForAnalyzeStatus(c *C) { diff --git a/sessionctx/variable/session.go b/sessionctx/variable/session.go index 1d27574a76875..6202a8f3cb7e7 100644 --- a/sessionctx/variable/session.go +++ b/sessionctx/variable/session.go @@ -949,6 +949,8 @@ const ( SlowLogTxnStartTSStr = "Txn_start_ts" // SlowLogUserStr is slow log field name. SlowLogUserStr = "User" + // SlowLogHostStr only for slow_query table usage. + SlowLogHostStr = "Host" // SlowLogConnIDStr is slow log field name. SlowLogConnIDStr = "Conn_ID" // SlowLogQueryTimeStr is slow log field name.