-
Notifications
You must be signed in to change notification settings - Fork 11.7k
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
MySQL: Support multiple statements #73051
Conversation
This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 2 weeks if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions! |
Is this something that would be useful/will be reviewed? Otherwise I'll close the PR since it will have more and more merge conflicts over time. |
Hey @exul, |
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.
The doc update looks great! Should this be backported to 10.0 and 10.1? There is a check for backporting that will fail unless backports are specified or if no backport is required add the no-backport label.
Hey @zoltanbedi, no worries, it's totally understandable given the amount of PRs this repo has 🙂. |
hi @exul thanks for the PR, one question.. why did you decide to make this a separate setting in the datasource config? do you think just enabling it by-default would cause problems? (i do understand that with this mode, you may receive multiple result sets. but, i don't think that's backward-incompatible, considering such a queries right now return an error-message.) but i may be missing something here. thanks! |
The comment points to the docker-compose file but that one isn't usable on it's own, since it's used to generate the final docker-compose file as part of 'make devenv'.
Add a MySQL specific setting to the datasource configuration that allows users to enable multiple statements support.
b6b13c1
to
a6d4c72
Compare
Hi @gabor, I decided to make it configurable because setting |
an update... i think we'll have to make it so that when multiple queries return data, all the returned data is returned. i know you also mentioned this problem. the reason is, i'm worried about backward compatibility. if we go live with a version where only results from the first query are returned, it will be very hard to release an improvement where all the results are returned, without breaking backward compatiblity. of course, this just makes the problem larger 😿 |
Yes, I totally understand that concern. I'll close this PR, since the support of multiple statements would probably also allow to get rid of this as a setting, which basically only leaves the extension of the connection string from this PR. |
(EDIT: actually multi-result-set-support was added 3 months ago, so the question is not actual anymore, see grafana/grafana-plugin-sdk-go#735 ) @exul i did a little exploration around this area, and.. if i just add the it seems to return "both results" you mentioned |
(NOTE: it seems queries where the number-of-columns differs show an error-message currently, things like |
actually, it seems we are already calling EDIT: support added 3 months ago: grafana/grafana-plugin-sdk-go#735 |
What is this feature?
It allows enabling multiple statement execution for the MySQL data source.
Why do we need this feature?
This allows executing SQL queries that consists of multiple statements like
SET @tags='deploy'; SELECT time_sec, description as text, tags FROM event WHERE tags=@tags
.There are a couple of things that need to be considered when deciding if this should be merged:
rows.NextResultSet
)Summary: While this will enable cases described in #24721 where multiple statements are used to set variables, it doesn't enable support for multiple result sets and I'm unsure if this could cause issues further down the line.
Who is this feature for?
Users who use the MySQL data source.
Which issue(s) does this PR fix?:
Fixes #24721
I'm unsure if the tests are actually helpful since the test DB uses a different connection string that is hard coded (https://github.com/grafana/grafana/blob/main/pkg/services/sqlstore/sqlutil/sqlutil.go#L31 and https://github.com/grafana/grafana/blob/main/pkg/tsdb/mysql/mysql_test.go#L1281-L1282) whereas when the actual data source is used, the connection string is based on the options passed via
DataSourceInfo
(https://github.com/grafana/grafana/blob/main/pkg/tsdb/mysql/mysql.go#L100-L110). I didn't find a way to use the same for both and also didn't find other cases where changes like this are tested.There's a minimal example to reproduce the issue in isolation: https://github.com/exul/xorm-multi-statements and a more detailed analysis in the issue: #24721 (comment).
Special notes for your reviewer:
Please check that: