Skip to content
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

*: add session alias field in slowlog, general log and extension framework #46273

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1260,17 +1260,19 @@ func TestLogAndShowSlowLog(t *testing.T) {
_, dom := testkit.CreateMockStoreAndDomainWithSchemaLease(t, dbTestLease)

dom.LogSlowQuery(&domain.SlowQueryInfo{SQL: "aaa", Duration: time.Second, Internal: true})
dom.LogSlowQuery(&domain.SlowQueryInfo{SQL: "bbb", Duration: 3 * time.Second})
dom.LogSlowQuery(&domain.SlowQueryInfo{SQL: "bbb", Duration: 3 * time.Second, SessAlias: "alias1"})
dom.LogSlowQuery(&domain.SlowQueryInfo{SQL: "ccc", Duration: 2 * time.Second})
// Collecting slow queries is asynchronous, wait a while to ensure it's done.
time.Sleep(5 * time.Millisecond)

result := dom.ShowSlowQuery(&ast.ShowSlow{Tp: ast.ShowSlowTop, Count: 2})
require.Len(t, result, 2)
require.Equal(t, "bbb", result[0].SQL)
require.Equal(t, "alias1", result[0].SessAlias)
require.Equal(t, 3*time.Second, result[0].Duration)
require.Equal(t, "ccc", result[1].SQL)
require.Equal(t, 2*time.Second, result[1].Duration)
require.Empty(t, result[1].SessAlias)

result = dom.ShowSlowQuery(&ast.ShowSlow{Tp: ast.ShowSlowTop, Count: 2, Kind: ast.ShowSlowKindInternal})
require.Len(t, result, 1)
Expand All @@ -1282,18 +1284,23 @@ func TestLogAndShowSlowLog(t *testing.T) {
require.Len(t, result, 3)
require.Equal(t, "bbb", result[0].SQL)
require.Equal(t, 3*time.Second, result[0].Duration)
require.Equal(t, "alias1", result[0].SessAlias)
require.Equal(t, "ccc", result[1].SQL)
require.Equal(t, 2*time.Second, result[1].Duration)
require.Empty(t, result[1].SessAlias)
require.Equal(t, "aaa", result[2].SQL)
require.Equal(t, time.Second, result[2].Duration)
require.True(t, result[2].Internal)
require.Empty(t, result[2].SessAlias)

result = dom.ShowSlowQuery(&ast.ShowSlow{Tp: ast.ShowSlowRecent, Count: 2})
require.Len(t, result, 2)
require.Equal(t, "ccc", result[0].SQL)
require.Equal(t, 2*time.Second, result[0].Duration)
require.Empty(t, result[0].SessAlias)
require.Equal(t, "bbb", result[1].SQL)
require.Equal(t, 3*time.Second, result[1].Duration)
require.Equal(t, "alias1", result[1].SessAlias)
}

func TestReportingMinStartTimestamp(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions domain/topn_slow_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ type SlowQueryInfo struct {
Duration time.Duration
Detail execdetails.ExecDetails
ConnID uint64
SessAlias string
TxnTS uint64
User string
DB string
Expand Down
1 change: 1 addition & 0 deletions executor/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1648,6 +1648,7 @@ func (a *ExecStmt) LogSlowQuery(txnTS uint64, succ bool, hasMoreResults bool) {
Detail: stmtCtx.GetExecDetails(),
Succ: succ,
ConnID: sessVars.ConnectionID,
SessAlias: sessVars.SessionAlias,
TxnTS: txnTS,
User: userString,
DB: sessVars.CurrentDB,
Expand Down
1 change: 1 addition & 0 deletions executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,7 @@ func (e *ShowSlowExec) Next(_ context.Context, req *chunk.Chunk) error {
req.AppendInt64(11, 0)
}
req.AppendString(12, slow.Digest)
req.AppendString(13, slow.SessAlias)
e.cursor++
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion executor/slow_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ func getColumnValueFactoryByName(colName string, columnIdx int) (slowQueryColumn
}, nil
case variable.SlowLogUserStr, variable.SlowLogHostStr, execdetails.BackoffTypesStr, variable.SlowLogDBStr, variable.SlowLogIndexNamesStr, variable.SlowLogDigestStr,
variable.SlowLogStatsInfoStr, variable.SlowLogCopProcAddr, variable.SlowLogCopWaitAddr, variable.SlowLogPlanDigest,
variable.SlowLogPrevStmt, variable.SlowLogQuerySQLStr, variable.SlowLogWarnings:
variable.SlowLogPrevStmt, variable.SlowLogQuerySQLStr, variable.SlowLogWarnings, variable.SlowLogSessAliasStr:
return func(row []types.Datum, value string, tz *time.Location, checker *slowLogChecker) (valid bool, err error) {
row[columnIdx] = types.NewStringDatum(value)
return true, nil
Expand Down
30 changes: 30 additions & 0 deletions executor/slow_query_sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,36 @@ func TestLogSlowLogIndex(t *testing.T) {
Check(testkit.Rows("[t:idx]"))
}

func TestSlowQuerySessionAlias(t *testing.T) {
originCfg := config.GetGlobalConfig()
newCfg := *originCfg

f, err := os.CreateTemp("", "tidb-slow-*.log")
require.NoError(t, err)
require.NoError(t, f.Close())
newCfg.Log.SlowQueryFile = f.Name()
config.StoreGlobalConfig(&newCfg)
defer func() {
config.StoreGlobalConfig(originCfg)
require.NoError(t, os.Remove(newCfg.Log.SlowQueryFile))
}()
require.NoError(t, logutil.InitLogger(newCfg.Log.ToLogConfig()))
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
defer func() {
tk.MustExec("set tidb_slow_log_threshold=300;")
tk.MustExec("set tidb_redact_log=0;")
}()

tk.MustExec(fmt.Sprintf("set @@tidb_slow_query_file='%v'", f.Name()))
tk.MustExec("set tidb_slow_log_threshold=0;")
tk.MustExec("set @@tidb_session_alias='alias123'")
tk.MustQuery("select sleep(0.0123);")
tk.MustQuery("select Session_alias from `information_schema`.`slow_query` " +
"where Query='select sleep(0.0123);' limit 1").
Check(testkit.Rows("alias123"))
}

func TestSlowQuery(t *testing.T) {
f, err := os.CreateTemp("", "tidb-slow-*.log")
require.NoError(t, err)
Expand Down
5 changes: 3 additions & 2 deletions executor/slow_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func TestParseSlowLogFile(t *testing.T) {
`# Time: 2019-04-28T15:24:04.309074+08:00
# Txn_start_ts: 405888132465033227
# User@Host: root[root] @ localhost [127.0.0.1]
# Session_alias: alias123
# Exec_retry_time: 0.12 Exec_retry_count: 57
# Query_time: 0.216905
# Cop_time: 0.38 Process_time: 0.021 Request_count: 1 Total_keys: 637 Processed_keys: 436
Expand Down Expand Up @@ -159,7 +160,7 @@ select * from t;`
recordString += str
}
expectRecordString := `2019-04-28 15:24:04.309074,` +
`405888132465033227,root,localhost,0,57,0.12,0.216905,` +
`405888132465033227,root,localhost,0,alias123,57,0.12,0.216905,` +
`0,0,0,0,0,0,0,0,0,0,0,0,,0,0,0,0,0,0,0.38,0.021,0,0,0,1,637,0,10,10,10,10,100,,,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,65536,0,0,0,0,0,,` +
`Cop_backoff_regionMiss_total_times: 200 Cop_backoff_regionMiss_total_time: 0.2 Cop_backoff_regionMiss_max_time: 0.2 Cop_backoff_regionMiss_max_addr: 127.0.0.1 Cop_backoff_regionMiss_avg_time: 0.2 Cop_backoff_regionMiss_p90_time: 0.2 Cop_backoff_rpcPD_total_times: 200 Cop_backoff_rpcPD_total_time: 0.2 Cop_backoff_rpcPD_max_time: 0.2 Cop_backoff_rpcPD_max_addr: 127.0.0.1 Cop_backoff_rpcPD_avg_time: 0.2 Cop_backoff_rpcPD_p90_time: 0.2 Cop_backoff_rpcTiKV_total_times: 200 Cop_backoff_rpcTiKV_total_time: 0.2 Cop_backoff_rpcTiKV_max_time: 0.2 Cop_backoff_rpcTiKV_max_addr: 127.0.0.1 Cop_backoff_rpcTiKV_avg_time: 0.2 Cop_backoff_rpcTiKV_p90_time: 0.2,` +
Expand All @@ -182,7 +183,7 @@ select * from t;`
recordString += str
}
expectRecordString = `2019-04-28 15:24:04.309074,` +
`405888132465033227,root,localhost,0,57,0.12,0.216905,` +
`405888132465033227,root,localhost,0,alias123,57,0.12,0.216905,` +
`0,0,0,0,0,0,0,0,0,0,0,0,,0,0,0,0,0,0,0.38,0.021,0,0,0,1,637,0,10,10,10,10,100,,,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,65536,0,0,0,0,0,,` +
`Cop_backoff_regionMiss_total_times: 200 Cop_backoff_regionMiss_total_time: 0.2 Cop_backoff_regionMiss_max_time: 0.2 Cop_backoff_regionMiss_max_addr: 127.0.0.1 Cop_backoff_regionMiss_avg_time: 0.2 Cop_backoff_regionMiss_p90_time: 0.2 Cop_backoff_rpcPD_total_times: 200 Cop_backoff_rpcPD_total_time: 0.2 Cop_backoff_rpcPD_max_time: 0.2 Cop_backoff_rpcPD_max_addr: 127.0.0.1 Cop_backoff_rpcPD_avg_time: 0.2 Cop_backoff_rpcPD_p90_time: 0.2 Cop_backoff_rpcTiKV_total_times: 200 Cop_backoff_rpcTiKV_total_time: 0.2 Cop_backoff_rpcTiKV_max_time: 0.2 Cop_backoff_rpcTiKV_max_addr: 127.0.0.1 Cop_backoff_rpcTiKV_avg_time: 0.2 Cop_backoff_rpcTiKV_p90_time: 0.2,` +
Expand Down
24 changes: 24 additions & 0 deletions extension/event_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type stmtEventRecord struct {
redactText string
params []types.Datum
connInfo *variable.ConnectionInfo
sessionAlias string
err string
tables []stmtctx.TableEntry
affectedRows uint64
Expand All @@ -67,6 +68,7 @@ func (h *sessionHandler) OnStmtEvent(tp extension.StmtEventTp, info extension.St
redactText: redactText,
params: info.PreparedParams(),
connInfo: info.ConnectionInfo(),
sessionAlias: info.SessionAlias(),
tables: tables,
affectedRows: info.AffectedRows(),
stmtNode: info.StmtNode(),
Expand Down Expand Up @@ -121,6 +123,7 @@ type stmtEventCase struct {
prepareNotFound bool
multiQueryCases []stmtEventCase
dispatchData []byte
sessionAlias string
}

func TestExtensionStmtEvents(t *testing.T) {
Expand Down Expand Up @@ -336,6 +339,26 @@ func TestExtensionStmtEvents(t *testing.T) {
redactText: "use `noexistdb`",
err: "[schema:1049]Unknown database 'noexistdb'",
},
{
sql: "set @@tidb_session_alias='alias123'",
redactText: "set @@tidb_session_alias = ?",
sessionAlias: "alias123",
},
{
sql: "select 123",
redactText: "select ?",
sessionAlias: "alias123",
},
{
sql: "set @@tidb_session_alias=''",
redactText: "set @@tidb_session_alias = ?",
sessionAlias: "",
},
{
sql: "select 123",
redactText: "select ?",
sessionAlias: "",
},
}

for i, c := range cases {
Expand Down Expand Up @@ -407,6 +430,7 @@ func TestExtensionStmtEvents(t *testing.T) {
require.Equal(t, "localhost", record.user.Hostname)
require.Equal(t, "root", record.user.AuthUsername)
require.Equal(t, "%", record.user.AuthHostname)
require.Equal(t, subCase.sessionAlias, record.sessionAlias)

require.Equal(t, subCase.originalText, record.originalText)
require.Equal(t, subCase.redactText, record.redactText)
Expand Down
7 changes: 5 additions & 2 deletions extension/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ import (
// ConnEventInfo is the connection info for the event
type ConnEventInfo struct {
*variable.ConnectionInfo
ActiveRoles []*auth.RoleIdentity
Error error
SessionAlias string
ActiveRoles []*auth.RoleIdentity
Error error
}

// ConnEventTp is the type of the connection event
Expand Down Expand Up @@ -66,6 +67,8 @@ type StmtEventInfo interface {
CurrentDB() string
// ConnectionInfo returns the connection info of the current session
ConnectionInfo() *variable.ConnectionInfo
// SessionAlias returns the session alias value set by user
SessionAlias() string
// StmtNode returns the parsed ast of the statement
// When parse error, this method will return a nil value
StmtNode() ast.StmtNode
Expand Down
1 change: 1 addition & 0 deletions infoschema/internal/testkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ select * from t_slim;
# Txn_start_ts: 427578666238083075
# User@Host: root[root] @ 172.16.0.0 [172.16.0.0]
# Conn_ID: 40507
# Session_alias: alias123
# Query_time: 25.571605962
# Parse_time: 0.002923536
# Compile_time: 0.006800973
Expand Down
1 change: 1 addition & 0 deletions infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,7 @@ var slowQueryCols = []columnInfo{
{name: variable.SlowLogUserStr, tp: mysql.TypeVarchar, size: 64},
{name: variable.SlowLogHostStr, tp: mysql.TypeVarchar, size: 64},
{name: variable.SlowLogConnIDStr, tp: mysql.TypeLonglong, size: 20, flag: mysql.UnsignedFlag},
{name: variable.SlowLogSessAliasStr, tp: mysql.TypeVarchar, size: 64},
{name: variable.SlowLogExecRetryCount, tp: mysql.TypeLonglong, size: 20, flag: mysql.UnsignedFlag},
{name: variable.SlowLogExecRetryTime, tp: mysql.TypeDouble, size: 22},
{name: variable.SlowLogQueryTimeStr, tp: mysql.TypeDouble, size: 22},
Expand Down
3 changes: 2 additions & 1 deletion infoschema/test/clustertablestest/cluster_tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ func TestSelectClusterTable(t *testing.T) {
tk.MustQuery("select count(*) from `CLUSTER_PROCESSLIST`").Check(testkit.Rows("1"))
// skip instance and host column because it now includes the TCP socket details (unstable)
tk.MustQuery("select id, user, db, command, time, state, info, digest, mem, disk, txnstart from `CLUSTER_PROCESSLIST`").Check(testkit.Rows(fmt.Sprintf("1 root <nil> Query 9223372036 %s <nil> 0 0 ", "")))
tk.MustQuery("select query_time, conn_id from `CLUSTER_SLOW_QUERY` order by time limit 1").Check(testkit.Rows("4.895492 6"))
tk.MustQuery("select query_time, conn_id, session_alias from `CLUSTER_SLOW_QUERY` order by time limit 1").Check(testkit.Rows("4.895492 6 "))
tk.MustQuery("select query_time, conn_id, session_alias from `CLUSTER_SLOW_QUERY` order by time desc limit 1").Check(testkit.Rows("25.571605962 40507 alias123"))
tk.MustQuery("select count(*) from `CLUSTER_SLOW_QUERY` group by digest").Check(testkit.Rows("1", "1"))
tk.MustQuery("select digest, count(*) from `CLUSTER_SLOW_QUERY` group by digest order by digest").Check(testkit.Rows("124acb3a0bec903176baca5f9da00b4e7512a41c93b417923f26502edeb324cc 1", "42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772 1"))
tk.MustQuery(`select length(query) as l,time from information_schema.cluster_slow_query where time > "2019-02-12 19:33:56" order by abs(l) desc limit 10;`).Check(testkit.Rows("21 2019-02-12 19:33:56.571953"))
Expand Down
2 changes: 2 additions & 0 deletions infoschema/test/clustertablestest/tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ func TestSlowQuery(t *testing.T) {
"root",
"localhost",
"6",
"",
"57",
"0.12",
"4.895492",
Expand Down Expand Up @@ -556,6 +557,7 @@ func TestSlowQuery(t *testing.T) {
"root",
"172.16.0.0",
"40507",
"alias123",
"0",
"0",
"25.571605962",
Expand Down
1 change: 1 addition & 0 deletions planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3301,6 +3301,7 @@ func buildShowSlowSchema() (*expression.Schema, types.NameSlice) {
schema.Append(buildColumnWithName("", "INDEX_IDS", mysql.TypeVarchar, 256))
schema.Append(buildColumnWithName("", "INTERNAL", mysql.TypeTiny, tinySize))
schema.Append(buildColumnWithName("", "DIGEST", mysql.TypeVarchar, 64))
schema.Append(buildColumnWithName("", "SESSION_ALIAS", mysql.TypeVarchar, 64))
return schema.col2Schema(), schema.names
}

Expand Down
7 changes: 7 additions & 0 deletions server/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ func (cc *clientConn) onExtensionConnEvent(tp extension.ConnEventTp, err error)

var connInfo *variable.ConnectionInfo
var activeRoles []*auth.RoleIdentity
var sessionAlias string
if ctx := cc.getCtx(); ctx != nil {
sessVars := ctx.GetSessionVars()
connInfo = sessVars.ConnectionInfo
sessionAlias = sessVars.SessionAlias
activeRoles = sessVars.ActiveRoles
}

Expand All @@ -47,6 +49,7 @@ func (cc *clientConn) onExtensionConnEvent(tp extension.ConnEventTp, err error)

info := &extension.ConnEventInfo{
ConnectionInfo: connInfo,
SessionAlias: sessionAlias,
ActiveRoles: activeRoles,
Error: err,
}
Expand Down Expand Up @@ -135,6 +138,10 @@ func (e *stmtEventInfo) ConnectionInfo() *variable.ConnectionInfo {
return e.sessVars.ConnectionInfo
}

func (e *stmtEventInfo) SessionAlias() string {
return e.sessVars.SessionAlias
}

func (e *stmtEventInfo) StmtNode() ast.StmtNode {
return e.stmtNode
}
Expand Down
7 changes: 7 additions & 0 deletions server/tests/tidb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2751,13 +2751,15 @@ func TestExtensionConnEvent(t *testing.T) {
require.NotEmpty(t, conn1.ConnectionID)
require.Nil(t, conn1.ActiveRoles)
require.NoError(t, conn1.Error)
require.Empty(t, conn1.SessionAlias)

expectedConn2 = *(conn1.ConnectionInfo)
expectedConn2.User = "root"
expectedConn2.DB = "test"
require.Equal(t, []*auth.RoleIdentity{}, logs.infos[1].ActiveRoles)
require.Nil(t, logs.infos[1].Error)
require.Equal(t, expectedConn2, *(logs.infos[1].ConnectionInfo))
require.Empty(t, logs.infos[1].SessionAlias)
})

_, err = conn.ExecContext(context.TODO(), "create role r1@'%'")
Expand All @@ -2766,6 +2768,8 @@ func TestExtensionConnEvent(t *testing.T) {
require.NoError(t, err)
_, err = conn.ExecContext(context.TODO(), "set role all")
require.NoError(t, err)
_, err = conn.ExecContext(context.TODO(), "set @@tidb_session_alias='alias123'")
require.NoError(t, err)

require.NoError(t, conn.Close())
require.NoError(t, db.Close())
Expand All @@ -2779,6 +2783,7 @@ func TestExtensionConnEvent(t *testing.T) {
}, *logs.infos[2].ActiveRoles[0])
require.Nil(t, logs.infos[2].Error)
require.Equal(t, expectedConn2, *(logs.infos[2].ConnectionInfo))
require.Equal(t, "alias123", logs.infos[2].SessionAlias)
})

// test for login failed
Expand Down Expand Up @@ -2814,13 +2819,15 @@ func TestExtensionConnEvent(t *testing.T) {
require.NotEmpty(t, conn1.ConnectionID)
require.Nil(t, conn1.ActiveRoles)
require.NoError(t, conn1.Error)
require.Empty(t, conn1.SessionAlias)

expectedConn2 = *(conn1.ConnectionInfo)
expectedConn2.User = "noexist"
expectedConn2.DB = "test"
require.Equal(t, []*auth.RoleIdentity{}, logs.infos[1].ActiveRoles)
require.EqualError(t, logs.infos[1].Error, "[server:1045]Access denied for user 'noexist'@'127.0.0.1' (using password: NO)")
require.Equal(t, expectedConn2, *(logs.infos[1].ConnectionInfo))
require.Empty(t, logs.infos[2].SessionAlias)
})
}

Expand Down
1 change: 1 addition & 0 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -3956,6 +3956,7 @@ func logGeneralQuery(execStmt *executor.ExecStmt, s *session, isPrepared bool) {
}
logutil.BgLogger().Info("GENERAL_LOG",
zap.Uint64("conn", vars.ConnectionID),
zap.String("session_alias", vars.SessionAlias),
zap.String("user", vars.User.LoginString()),
zap.Int64("schemaVersion", s.GetInfoSchema().SchemaMetaVersion()),
zap.Uint64("txnStartTS", vars.TxnCtx.StartTS),
Expand Down
5 changes: 5 additions & 0 deletions sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -2955,6 +2955,8 @@ const (
SlowLogHostStr = "Host"
// SlowLogConnIDStr is slow log field name.
SlowLogConnIDStr = "Conn_ID"
// SlowLogSessAliasStr is the session alias set by user
SlowLogSessAliasStr = "Session_alias"
// SlowLogQueryTimeStr is slow log field name.
SlowLogQueryTimeStr = "Query_time"
// SlowLogParseTimeStr is the parse sql time.
Expand Down Expand Up @@ -3157,6 +3159,9 @@ func (s *SessionVars) SlowLogFormat(logItems *SlowQueryLogItems) string {
if s.ConnectionID != 0 {
writeSlowLogItem(&buf, SlowLogConnIDStr, strconv.FormatUint(s.ConnectionID, 10))
}
if s.SessionAlias != "" {
writeSlowLogItem(&buf, SlowLogSessAliasStr, s.SessionAlias)
}
if logItems.ExecRetryCount > 0 {
buf.WriteString(SlowLogRowPrefixStr)
buf.WriteString(SlowLogExecRetryTime)
Expand Down
2 changes: 2 additions & 0 deletions sessionctx/variable/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func TestSlowLogFormat(t *testing.T) {
seVar.User = &auth.UserIdentity{Username: "root", Hostname: "192.168.0.1"}
seVar.ConnectionInfo = &variable.ConnectionInfo{ClientIP: "192.168.0.1"}
seVar.ConnectionID = 1
seVar.SessionAlias = "aliasabc"
// the out put of the loged CurrentDB should be 'test', should be to lower cased.
seVar.CurrentDB = "TeST"
seVar.InRestrictedSQL = true
Expand Down Expand Up @@ -223,6 +224,7 @@ func TestSlowLogFormat(t *testing.T) {
# Keyspace_ID: 1
# User@Host: root[root] @ 192.168.0.1 [192.168.0.1]
# Conn_ID: 1
# Session_alias: aliasabc
# Exec_retry_time: 5.1 Exec_retry_count: 3
# Query_time: 1
# Parse_time: 0.00000001
Expand Down