Repository: pingcap/tidb (Go)

Issue:
Performance improvement in the SetProcessInfo
## Performance Questions

https://github.com/pingcap/tidb/blob/ddbf60f6d013aadaba29676ccc47765a592b8841/session/session.go#L868 

```
func (s *session) SetProcessInfo(sql string, t time.Time, command byte) {
	pi := util.ProcessInfo{
		ID:      s.sessionVars.ConnectionID,
		DB:      s.sessionVars.CurrentDB,
		Command: mysql.Command2Str[command],
		Time:    t,
		State:   s.Status(),
		Info:    sql,
	}
	if s.sessionVars.User != nil {
		pi.User = s.sessionVars.User.Username
		pi.Host = s.sessionVars.User.Hostname
	}
	s.processInfo.Store(pi)
}
```
we can store the command byte directly, normally, the command(byte) need to change to a string only when the client exec `show processlist`. So we can do the transition in the function https://github.com/pingcap/tidb/blob/ddbf60f6d013aadaba29676ccc47765a592b8841/session/session.go#L1617:

```
func (s *session) ShowProcess() util.ProcessInfo {
	var pi util.ProcessInfo
	tmp := s.processInfo.Load()
	if tmp != nil {
		pi = tmp.(util.ProcessInfo)
	}
	return pi
}
```

Because of the SetProcessInfo is the main statement execution path, so the improvement is worth.





Discussion:
@lkk2003rty 
I'm so sorry that when I file the PR, I found you are handling this issue.
How is your work doing?


> @lkk2003rty
> I'm so sorry that when I file the PR, I found you are handling this issue.
> How is your work doing?

I'm almost done. But it's ok now. I'll find other issue I can help.Thank you,
@lkk2003rty 
Feel free to file the PR.
Because my PR is not good enough, I'm looking forward for you PR.
My PR will be closed.
And when you file PR, I was wondering if you could @me and let me learn it.
Thanks a lot!
@xiekeyi98 
Your PR is the same as mine. You can reopen your PR. 
I just have one question, may be change `executor/show.go` 252 line to use map to do  the transition work would be better? But I worried that modification will affect other part function.





Patch:
diff --git a/executor/show.go b/executor/show.go
index 2a053f19dddfb..9b953da493802 100644
--- a/executor/show.go
+++ b/executor/show.go
@@ -249,7 +249,7 @@ func (e *ShowExec) fetchShowProcessList() error {
 			pi.User,
 			pi.Host,
 			pi.DB,
-			pi.Command,
+			mysql.Command2Str[pi.Command],
 			uint64(time.Since(pi.Time) / time.Second),
 			fmt.Sprintf("%d", pi.State),
 			info,
diff --git a/session/session.go b/session/session.go
index 465a55860ff80..422d10530ccf9 100644
--- a/session/session.go
+++ b/session/session.go
@@ -865,7 +865,7 @@ func (s *session) SetProcessInfo(sql string, t time.Time, command byte) {
 	pi := util.ProcessInfo{
 		ID:      s.sessionVars.ConnectionID,
 		DB:      s.sessionVars.CurrentDB,
-		Command: mysql.Command2Str[command],
+		Command: command,
 		Time:    t,
 		State:   s.Status(),
 		Info:    sql,
diff --git a/util/processinfo.go b/util/processinfo.go
index 7ff4a77e1ad4e..0965b2249530d 100644
--- a/util/processinfo.go
+++ b/util/processinfo.go
@@ -23,7 +23,7 @@ type ProcessInfo struct {
 	User    string
 	Host    string
 	DB      string
-	Command string
+	Command byte
 	Time    time.Time
 	State   uint16
 	Info    string


Test patch:
diff --git a/executor/executor_pkg_test.go b/executor/executor_pkg_test.go
index d6287d36d52ab..612f9edaf1b28 100644
--- a/executor/executor_pkg_test.go
+++ b/executor/executor_pkg_test.go
@@ -69,7 +69,7 @@ func (s *testExecSuite) TestShowProcessList(c *C) {
 		User:    "test",
 		Host:    "127.0.0.1",
 		DB:      "test",
-		Command: "select * from t",
+		Command: 't',
 		State:   1,
 		Info:    "",
 	}