@@ -191,7 +191,7 @@ select * from t;`
191191 `0.1,0.2,0.03,127.0.0.1:20160,0.05,0.6,0.8,0.0.0.0:20160,70724,23333,65536,0,0,0,30000,3000,10000,1000,500000,500005,300000,300005,0,0,,` +
192192 `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,` +
193193 `0,0,1,0,1,1,0,default,2.158,2.123,0.05,0.01,0.021,1,1,,60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4,` +
194- `,update t set i = 1;,select * from t;`
194+ `,update t set i = 1;,null, select * from t;`
195195 require .Equal (t , expectRecordString , recordString )
196196
197197 // Issue 20928
@@ -214,7 +214,7 @@ select * from t;`
214214 `0.1,0.2,0.03,127.0.0.1:20160,0.05,0.6,0.8,0.0.0.0:20160,70724,23333,65536,0,0,0,30000,3000,10000,1000,500000,500005,300000,300005,0,0,,` +
215215 `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,` +
216216 `0,0,1,0,1,1,0,default,2.158,2.123,0.05,0.01,0.021,1,1,,60e9378c746d9a2be1c791047e008967cf252eb6de9167ad3aa6098fa2d523f4,` +
217- `,update t set i = 1;,select * from t;`
217+ `,update t set i = 1;,null, select * from t;`
218218 require .Equal (t , expectRecordString , recordString )
219219
220220 // fix sql contain '# ' bug
@@ -284,6 +284,62 @@ select * from t;
284284 require .Equal (t , value , "[t:i: a]" )
285285}
286286
287+ func TestParseSlowLogSessionConnectAttrs (t * testing.T ) {
288+ // Slow log entry that includes Session_connect_attrs JSON.
289+ slowLogStr := `# Time: 2019-04-28T15:24:04.309074+08:00
290+ # Txn_start_ts: 405888132465033227
291+ # User@Host: root[root] @ localhost [127.0.0.1]
292+ # Query_time: 0.216905
293+ # Digest: 42a1c8aae6f133e934d4bf0147491709a8812ea05ff8819ec522780fe657b772
294+ # Is_internal: false
295+ # Succ: true
296+ # Session_connect_attrs: {"_client_name":"Go-MySQL-Driver","_os":"linux","app_name":"test_app"}
297+ # Prev_stmt: begin;
298+ select * from t;
299+ `
300+ loc , err := time .LoadLocation ("Asia/Shanghai" )
301+ require .NoError (t , err )
302+ ctx := mock .NewContext ()
303+ ctx .ResetSessionAndStmtTimeZone (loc )
304+
305+ // Use the retriever directly (without initialize) to avoid reading
306+ // from actual slow log files on disk, which can produce extra rows.
307+ retriever , err := newSlowQueryRetriever ()
308+ require .NoError (t , err )
309+ retriever .columnValueFactoryMap = make (map [string ]slowQueryColumnValueFactory , len (retriever .outputCols ))
310+ for idx , col := range retriever .outputCols {
311+ factory , err := getColumnValueFactoryByName (col .Name .O , idx )
312+ require .NoError (t , err )
313+ require .NotNil (t , factory , "column %s should have a factory" , col .Name .O )
314+ retriever .columnValueFactoryMap [col .Name .O ] = factory
315+ }
316+
317+ reader := bufio .NewReader (bytes .NewBufferString (slowLogStr ))
318+ rows , err := parseLog (retriever , ctx , reader )
319+ require .NoError (t , err )
320+ require .Len (t , rows , 1 )
321+
322+ // Find the Session_connect_attrs column.
323+ colIdx := - 1
324+ for i , col := range retriever .outputCols {
325+ if col .Name .L == strings .ToLower (variable .SlowLogSessionConnectAttrs ) {
326+ colIdx = i
327+ break
328+ }
329+ }
330+ require .NotEqual (t , - 1 , colIdx , "Session_connect_attrs column should exist" )
331+
332+ // Verify the parsed JSON contains the expected keys.
333+ bj := rows [0 ][colIdx ].GetMysqlJSON ()
334+ bjStr := bj .String ()
335+ require .Contains (t , bjStr , `"_client_name"` )
336+ require .Contains (t , bjStr , `"Go-MySQL-Driver"` )
337+ require .Contains (t , bjStr , `"_os"` )
338+ require .Contains (t , bjStr , `"linux"` )
339+ require .Contains (t , bjStr , `"app_name"` )
340+ require .Contains (t , bjStr , `"test_app"` )
341+ }
342+
287343// It changes variable.MaxOfMaxAllowedPacket, so must be stayed in SerialSuite.
288344func TestParseSlowLogFileSerial (t * testing.T ) {
289345 loc , err := time .LoadLocation ("Asia/Shanghai" )
0 commit comments