Skip to content
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

Support TRILOGY_CAPABILITIES_MULTI_RESULTS #57

Merged

Conversation

adrianna-chang-shopify
Copy link
Collaborator

@adrianna-chang-shopify adrianna-chang-shopify commented Mar 13, 2023

Proposed Changes

The MySQL client library enables CLIENT_MULTI_RESULTS either by passing the CLIENT_MULTI_RESULTS flag itself, or implicitly by passing CLIENT_MULTI_STATEMENTS (which also enables CLIENT_MULTI_RESULTS). CLIENT_MULTI_RESULTS is enabled by default.

Consequently, we should set the TRILOGY_CAPABILITIES_MULTI_RESULTS client flag along with TRILOGY_CAPABILITIES_MULTI_STATEMENTS when the Trilogy client is initialized with multi_statement: true.

Since the client flag can be set explicitly as well, this PR allows TRILOGY_CAPABILITIES_MULTI_RESULTS to be set independently via multi_result: true. This enables multi-result processing without allowing the client to send multi-statement queries, which is useful for stored procedures, dynamic SQL in init files, etc.

To match Mysql2's behaviour, we enable TRILOGY_CAPABILITIES_MULTI_RESULTS by default. There shouldn't be any downsides to enabling this flag; it essentially specifies that the client is capable of multi-result set processing, which it is thanks to Paarth's changes in #35.

Motivation for Change

At Shopify, this change is important for us as we attempt to migrate from Mysql2 to Trilogy, because ProxySQL treats the two drivers differently if they have different client flags set. This results in a lot of COM_CHANGE_USER commands if the two clients are running simultaneously.

This is where ProxySQL compares the client flags and this is where ProxySQL determines whether it can use the cached connections, or whether it needs to perform a COM_CHANGE_USER command. The issue for us was that running both of the adapters at 50% resulted in a ton of COM_CHANGE_USER commands as the connection pool was handed off between these two users, and we overloaded MySQL.

We could, of course, just configure the flag ourselves, but it makes sense to me to match Mysql2's behaviour.

cc @byroot @paarthmadan @eileencodes

The TRILOGY_CAPABILITIES_MULTI_RESULTS client flag should be set
along with TRILOGY_CAPABILITIES_MULTI_STATEMENTS when the Trilogy
client is initialized with `multi_statement: true`. The TRILOGY_CAPABILITIES_MULTI_RESULTS
flag can also be set independently via `multi_result: true` to enable
multi-result processing without allowing the client to send multi-statement
queries. This is useful for stored procedures, dynamic SQL in init files, etc.

To match behaviour with libmysqlclient, TRILOGY_CAPABILITIES_MULTI_RESULTS
is enabled by default.
Copy link
Contributor

@casperisfine casperisfine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Patch looks great 👍

Copy link
Member

@eileencodes eileencodes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HParker HParker merged commit 80c1a55 into trilogy-libraries:main Mar 15, 2023
@adrianna-chang-shopify adrianna-chang-shopify deleted the ac-multi-results branch March 15, 2023 18:39
composerinteralia added a commit that referenced this pull request Apr 26, 2023
#57 set multi-results as a
default.

To safely upgrade to the latest version of Trilogy, we want to turn that
off for now, and then turn it on one cluster at a time.

This commit removes the default from the C library and into the Ruby C
extension so we can disable it as needed. (We had an option to enable
multi results, but removed it in
#68 because the option was always
a no-op. This PR adds the option back, with some modification).
luanzeba added a commit that referenced this pull request May 17, 2023
#57 set multi-results capability
as a default.

To safely upgrade to the latest version of Trilogy, we want to turn that
option off and then turn it on one cluster at a time.

This commit removes the multi-results capability default from
TRILOGY_CAPABILITIES_CLIENT but will still set it unless the client is
initialized with `multi_results: false`.

We had an option to enable
multi results, but removed it in
#68 because the option was always
a no-op. This PR adds the option back, with some modification.

Co-authored-by: Daniel Colson <composerinteralia@github.com>
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.

4 participants