On connect, set all variables in a single SET statement#1099
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
For faster connection startup this patch use (almost) a single
SETstatement to set all variables at once instead of aSETstatement for each variable.MySQL doc about the
SETstatement: https://dev.mysql.com/doc/refman/8.0/en/set-variable.htmlBefore:
SET <variable1>=<value1>SET NAMES utf8mb4SET <variable2>=<value2>SET <variable3>=<value3>Now:
SET NAMES utf8mb4SET <variable1>=<value1>,<variable2>=<value2>,<variable3>=<value3>This patch should make establishing new connection must faster as it reduce the number of roundtrips necessary before the first query when multiple variables are defined in the DSN.
As a side effect, the
SET NAMESstatement is always executed first. This will fix the possibility of someSETstatements being executed before the right charset is set (for the case where the database default charset is not the one we want to use for the connection, e.g. Latin1).Here is how to test this patch with your own Go project built with Go modules:
Background: on MySQL 5.7 database hosted on Amazon RDS we noticed that in Performance Insights that some costly queries were hidden by
SETstatements. Sometimes we saw aSET time_zone=..., sometimes aSET group_concat_max_len=..., sometimesSET sql_mode='TRADITIONAL'.Checklist