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

Interpolate MySQL query parameters by default #5428

Merged
merged 5 commits into from
Apr 2, 2024

Conversation

tdeebswihart
Copy link
Contributor

@tdeebswihart tdeebswihart commented Feb 16, 2024

What changed?

We now specify interpolateParams by default when using MySQL for our main.

While we don't currently support specifying interpolateParams for MySQL visibility databases, I changed the type returned when serializing VisibilitySearchAttributes as a first step towards doing so (MySQL 8 won't allow binary data within JSON columns, which makes sense).

While we could also have explicitly prepared and reused our statements that requires far more work and it may not be the better approach anyways.

Why?

@mattrobenolt did a good job of explaining why in #5425 but I'll summarize it here anyways.

When interpolateParams is false (the default) the driver will prepare parameterized statements before executing them, meaning we need two round-trips to the database for each query. By setting interpolateParams to true the DB driver will handle interpolation and send the query just once to the database, halving the number of round trips necessary. This should improve the performance of all clusters using MySQL.

How did you test it?

Existing tests.

Potential risks

No

Is hotfix candidate?

This is up for discussion

@tdeebswihart
Copy link
Contributor Author

So this is more complex than we initially though. When interpolateParams=true we get different types back by the call to Query mysql itself; we're getting back []uint8 rather than the integer value of ExecutionStatus. Specifically we're getting the bytes for the ASCII char of the integer value which is bizarre...

@mattrobenolt do you have measurements that show the benefit of enabling interpolateParams=true for a MySQL persistence backend, and if so would you share them? This is turning into more work than we expected.

In the meantime I'm going to put a separate PR up to prevent folks from enabling interpolateParams on a MySQL visibility store. It doesn't currently work and will only lead to confusion

tdeebswihart added a commit that referenced this pull request Feb 20, 2024
There are a number of reasons why this doesn't work right now so we're
going to prevent it from happening while we discuss whether we should
invest in fixing it. The current work to fix this is in #5428
@tdeebswihart
Copy link
Contributor Author

interpolateParams will be disabled for MySQL 8 Visibility databases while we discuss how much effort to put into this by #5441

@tdeebswihart tdeebswihart changed the base branch from main to tds/prevent-mysql8-vis-interpolateParams February 20, 2024 19:33
@tdeebswihart tdeebswihart marked this pull request as ready for review February 20, 2024 19:34
@tdeebswihart tdeebswihart requested a review from a team as a code owner February 20, 2024 19:34
Copy link
Collaborator

@rodrigozhou rodrigozhou left a comment

Choose a reason for hiding this comment

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

Please address @stephanos comments before merging.

tdeebswihart added a commit that referenced this pull request Feb 29, 2024
There are a number of reasons why this doesn't work right now so we're
going to prevent it from happening while we discuss whether we should
invest in fixing it. The current work to fix this is in #5428
@tdeebswihart tdeebswihart force-pushed the tds/prevent-mysql8-vis-interpolateParams branch from b9fa8cc to 302d324 Compare February 29, 2024 00:28
tdeebswihart added a commit that referenced this pull request Mar 6, 2024
There are a number of reasons why this doesn't work right now so we're
going to prevent it from happening while we discuss whether we should
invest in fixing it. The current work to fix this is in #5428
@tdeebswihart tdeebswihart force-pushed the tds/prevent-mysql8-vis-interpolateParams branch from 302d324 to 768fd95 Compare March 6, 2024 22:57
@tdeebswihart tdeebswihart force-pushed the tds/interpolate-mysql8-params branch from 8d4428c to 930c591 Compare March 6, 2024 23:07
Base automatically changed from tds/prevent-mysql8-vis-interpolateParams to main March 8, 2024 20:03
tdeebswihart added a commit that referenced this pull request Mar 8, 2024
## What changed?
Attempting to configure a MySQL 8 Visibility database with
go-sql-driver/mysql's `interpolateParams` option will now fail.

## Why?

There are a number of reasons why this doesn't work right now so we're
going to prevent it from happening while we discuss how much we should
invest in fixing it. The current work to fix this is in
#5428

## How did you test it?
Added a new test

## Potential risks
There should be none. Any user who has currently set up their database
this way will already have encountered exciting errors like `Cannot
create a JSON value from a string with CHARACTER SET 'binary'` and
`Unable to parse ExecutionStatus value from DB`.

## Is hotfix candidate?

That's up for discussion
You can't interpolate a []byte into a JSON field: go-sql-driver/mysql#819
It's useful to know which query failed when multiple are executed in a
single operation
This cuts our queries down to 1 round-trip to the database per
operation. When interpolateParams is false (the default) the mysql
driver will call prepare before executing a query.

Our MySQL 8 visibility code doesn't currently support this option
however, so this is only configured for:

- MySQL 5.7 Main dbs
- MySQL 5.7 Visibility dbs
- MySQL 8.0 Main dbs
@tdeebswihart tdeebswihart force-pushed the tds/interpolate-mysql8-params branch from 930c591 to 3ea2045 Compare March 8, 2024 22:41
stephanos pushed a commit to stephanos/temporal that referenced this pull request Mar 21, 2024
…o#5441)

## What changed?
Attempting to configure a MySQL 8 Visibility database with
go-sql-driver/mysql's `interpolateParams` option will now fail.

## Why?

There are a number of reasons why this doesn't work right now so we're
going to prevent it from happening while we discuss how much we should
invest in fixing it. The current work to fix this is in
temporalio#5428

## How did you test it?
Added a new test

## Potential risks
There should be none. Any user who has currently set up their database
this way will already have encountered exciting errors like `Cannot
create a JSON value from a string with CHARACTER SET 'binary'` and
`Unable to parse ExecutionStatus value from DB`.

## Is hotfix candidate?

That's up for discussion
@tdeebswihart tdeebswihart merged commit 0e3e83d into main Apr 2, 2024
42 checks passed
@tdeebswihart tdeebswihart deleted the tds/interpolate-mysql8-params branch April 2, 2024 23:27
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.

3 participants