feat(mysql,mariadb): add per-source readonly_session_sql - #450
Open
takamasa-loves-mcdonalds wants to merge 1 commit into
Open
takamasa-loves-mcdonalds wants to merge 1 commit into
takamasa-loves-mcdonalds wants to merge 1 commit into
Conversation
Add a `readonly_session_sql` source option holding SET SESSION statements that are run right after each read-only execution opens its read-only transaction. This lets a source carry guardrails the server enforces itself, such as MySQL's max_execution_time, and puts them back on every read-only call even if the pooled connection was changed in the meantime. Statements are validated at config load: only one `SET SESSION name = value` assignment per statement, no subqueries, and no setting that would switch off the read-only transaction. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Part of #449
Summary
readonly_session_sqlTOML option for MySQL and MariaDB sourcesSTART TRANSACTION READ ONLY,so e.g.
max_execution_timeis in effect for every read-only statementSET SESSION name = valuestatements, each with a single assignment andno subquery, checked on comment- and literal-stripped text at config load; settings that
control the surrounding transaction (
transaction_read_only,tx_read_only,autocommit,completion_type) are rejected, so a source setting cannot undo tool-levelreadonly = trueor leave the pooled connection in a broken state
explain_sqland read-only custom tools;behaviour is unchanged when the option is omitted, and for writable executions
SET SESSIONvalues stay on the pooled connection after the execution, so a writable toolsharing the same source may see them; this is documented. I kept it simple rather than
restoring the previous values afterwards; happy to add that if you prefer.
PostgreSQL (
SET LOCAL) builds on this ina follow-up branch;
I will open it separately to keep this one small.
Testing
pnpm test:unitpnpm test:integration(all connectors, including SQL Server and Oracle)containers. The MySQL case checks that the server actually stops
SELECT SLEEP(5)atmax_execution_time = 500.🤖 Generated with Claude Code