-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add maxAllowedPacket DSN Parameter #489
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
Conversation
I feel this sentence is worth enough to include in README. |
What we currently do is indeed a hack we should maybe avoid in the future. It might be a good idea to just use MySQL's default value by default, allow modification via the Anyway, @xiezhenye please use the PR template (edit you post) and make the necessary additions. |
I prefer maxAllowedPacket to maxPacketAllowed so naming is consistent with the variable in MySQL. But if the name was intentional: for what the reason? |
@@ -43,6 +43,7 @@ Soroush Pour <me at soroushjp.com> | |||
Stan Putrya <root.vagner at gmail.com> | |||
Stanley Gunawan <gunawan.stanley at gmail.com> | |||
Xiaobing Jiang <s7v7nislands at gmail.com> | |||
Zhenye Xie <xiezhenye at gmail.com> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move your entry to the end (alphabetical order)
Default: 0 | ||
``` | ||
|
||
Max MySQL packet size allowed in bytes. Use `maxPacketAllowed` == 0 to fetch the `max_allowed_packet` variable from server. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove "MySQL" and replace "maxPacketAllowed
== 0" with "Use maxPacketAllowed
= 0" (single =).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also add "automatically" before "fetch"
@arnehormann's comment is still valid. The parameter name should be consistent with the variable name ( |
@@ -299,6 +299,15 @@ Default: 0 | |||
I/O write timeout. The value must be a decimal number with an unit suffix ( *"ms"*, *"s"*, *"m"*, *"h"* ), such as *"30s"*, *"0.5m"* or *"1m30s"*. | |||
|
|||
|
|||
##### `maxPacketAllowed` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maxAllowedPacket
also here and in DSN
Default: 0 | ||
``` | ||
|
||
Max packet size allowed in bytes. Use `maxAllowedPacket` = 0 to automatically fetch the `max_allowed_packet` variable from server. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please write it as maxAllowedPacket=0
to make it consistent with other variables.
mc.Close() | ||
return nil, err | ||
if mc.cfg.MaxAllowedPacket > 0 { | ||
mc.maxPacketAllowed = mc.cfg.MaxAllowedPacket |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also change the name here
mc.Close() | ||
return nil, err | ||
} | ||
mc.maxPacketAllowed = stringToInt(maxap) - 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here
} | ||
mc.maxPacketAllowed = stringToInt(maxap) - 1 | ||
if mc.maxPacketAllowed < maxPacketSize { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here
@@ -222,6 +224,17 @@ func (cfg *Config) FormatDSN() string { | |||
buf.WriteString(cfg.WriteTimeout.String()) | |||
} | |||
|
|||
if cfg.MaxAllowedPacket > 0 { | |||
if hasParam { | |||
buf.WriteString("&maxPacketAllowed=") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here
buf.WriteString("&maxPacketAllowed=") | ||
} else { | ||
hasParam = true | ||
buf.WriteString("?maxPacketAllowed=") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here
@@ -496,7 +509,11 @@ func parseDSNParams(cfg *Config, params string) (err error) { | |||
if err != nil { | |||
return | |||
} | |||
|
|||
case "maxPacketAllowed": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here
@@ -39,8 +39,8 @@ var testDSNs = []struct { | |||
"user:password@tcp(localhost:5555)/dbname?charset=utf8mb4,utf8&tls=skip-verify", | |||
&Config{User: "user", Passwd: "password", Net: "tcp", Addr: "localhost:5555", DBName: "dbname", Params: map[string]string{"charset": "utf8mb4,utf8"}, Collation: "utf8_general_ci", Loc: time.UTC, TLSConfig: "skip-verify"}, | |||
}, { | |||
"user:password@/dbname?loc=UTC&timeout=30s&readTimeout=1s&writeTimeout=1s&allowAllFiles=1&clientFoundRows=true&allowOldPasswords=TRUE&collation=utf8mb4_unicode_ci", | |||
&Config{User: "user", Passwd: "password", Net: "tcp", Addr: "127.0.0.1:3306", DBName: "dbname", Collation: "utf8mb4_unicode_ci", Loc: time.UTC, Timeout: 30 * time.Second, ReadTimeout: time.Second, WriteTimeout: time.Second, AllowAllFiles: true, AllowOldPasswords: true, ClientFoundRows: true}, | |||
"user:password@/dbname?loc=UTC&timeout=30s&readTimeout=1s&writeTimeout=1s&allowAllFiles=1&clientFoundRows=true&allowOldPasswords=TRUE&collation=utf8mb4_unicode_ci&maxPacketAllowed=16777216", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here
@@ -51,6 +52,7 @@ type Config struct { | |||
MultiStatements bool // Allow multiple statements in one query | |||
ParseTime bool // Parse time values to time.Time | |||
Strict bool // Return warnings as errors | |||
MaxAllowedPacket int // Max packet size allowed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move it after Loc *time.Location // Location for time.Time values
.
We just put all the bool vars at the end for more efficient struct packing.
Default: 0 | ||
``` | ||
|
||
Max packet size allowed in bytes. Use `maxAllowedPacket`=0 to automatically fetch the `max_allowed_packet` variable from server. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`maxAllowedPacket=0`
Thanks a lot! |
Description
Add a
maxPacketAllowed
DSN param and a config field to set it directly instead of fetch from server.Some mysql proxy implements or other services using mysql protocol may not supports 'select @@max_allowed_packet'.
maxPacketAllowed
param can be used to walk around these problems.It can also be used to limit the max row size returned from server.
Checklist