File tree 1 file changed +14
-5
lines changed
1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ type mysqlConn struct {
47
47
48
48
// Handles parameters set in DSN after the connection is established
49
49
func (mc * mysqlConn ) handleParams () (err error ) {
50
- var params []string
50
+ var cmdSet []byte
51
51
for param , val := range mc .cfg .Params {
52
52
switch param {
53
53
// Charset: character_set_connection, character_set_client, character_set_results
@@ -64,14 +64,23 @@ func (mc *mysqlConn) handleParams() (err error) {
64
64
return
65
65
}
66
66
67
- // Other system vars
67
+ // Other system vars accumulated in a single SET command
68
68
default :
69
- params = append (params , param + "=" + val )
69
+ if cmdSet == nil {
70
+ // Heuristic: 29 chars for each other key=value to reduce reallocations
71
+ cmdSet = make ([]byte , 0 , 4 + len (param )+ 1 + len (val )+ 30 * (len (mc .cfg .Params )- 1 ))
72
+ cmdSet = append (cmdSet , "SET " ... )
73
+ } else {
74
+ cmdSet = append (cmdSet , ',' )
75
+ }
76
+ cmdSet = append (cmdSet , param ... )
77
+ cmdSet = append (cmdSet , '=' )
78
+ cmdSet = append (cmdSet , val ... )
70
79
}
71
80
}
72
81
73
- if len ( params ) > 0 {
74
- err = mc .exec ("SET " + strings . Join ( params , "," ))
82
+ if cmdSet != nil {
83
+ err = mc .exec (string ( cmdSet ))
75
84
if err != nil {
76
85
return
77
86
}
You can’t perform that action at this time.
0 commit comments