Skip to content

[9.x] Support connection to MySql with minimal interactions #43020

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

Closed
wants to merge 2 commits into from

Conversation

coppolafab
Copy link

@coppolafab coppolafab commented Jun 30, 2022

Reducing configuration statements issued to MySql Server on connect, like 'use db' or 'set names', helps taking full advantage of a connection proxy, minimizing chances of connection pinning [1].
Such configuration statements can also be executed once per connection, via proxy's initialization query, instead of once per Request lifecycle.

A support for a minimal interaction upon connection can also be useful in some conditions (es: tests, low resources).

Actually, on connect, MySqlConnector executes:

  • Connect (via new PDO)
  • use db query (if set $database)
  • SET SESSION TRANSACTION ISOLATION (if set $isolation_level, as prepared statement)
  • set names (if set $charset, as prepared statement)
  • set time_zone (if set $timezone, as prepared statement)
  • set session sql_mode (if set $modes or $strict, as prepared statement)

This PR:

  • removes the 'use db' query, already specified into the DSN
  • adds the charset (if set) into the DSN, with the same effect of 'set names' [2],
    also ensuring proper PDO::quote functionality, not affected by 'set names' statement [3].
    'set names' will be executed necessarily if a collation is set but not as prepared statement, useful when not using the default one, but unsetting it allows skipping this step.
  • adapts existing tests to reflect changes

Setting these database options to NULL (isolation_level, collation, timezone, modes and strict) allows having a minimal interaction on a connect, like:

2020-07-24T12:51:18.507740Z	    2 Connect	db_user@127.0.0.1 on db_schema using TCP/IP
2020-07-24T12:51:18.509693Z	    2 Query	select true

[1] - https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/rds-proxy-managing.html#rds-proxy-pinning
[2] - https://dev.mysql.com/doc/refman/8.0/en/charset-connection.html
[3] - https://www.php.net/manual/en/mysqlinfo.concepts.charset.php

@taylorotwell
Copy link
Member

Going to hold off on this for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants