Skip to content

feat(mysql,mariadb): add per-source readonly_session_sql - #450

Open
takamasa-loves-mcdonalds wants to merge 1 commit into
bytebase:mainfrom
takamasa-loves-mcdonalds:feat/session-sql-mysql
Open

takamasa-loves-mcdonalds wants to merge 1 commit into
bytebase:mainfrom
takamasa-loves-mcdonalds:feat/session-sql-mysql

Conversation

@takamasa-loves-mcdonalds

@takamasa-loves-mcdonalds takamasa-loves-mcdonalds commented Oct 1, 2026 •

Copy link
Copy Markdown

Part of #449

Summary

  • add a readonly_session_sql TOML option for MySQL and MariaDB sources
  • run its statements right after each read-only execution opens START TRANSACTION READ ONLY,
    so e.g. max_execution_time is in effect for every read-only statement
  • accept any number of SET SESSION name = value statements, each with a single assignment and
    no 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-level readonly = true
    or leave the pooled connection in a broken state
  • apply to every read-only execution, including explain_sql and read-only custom tools;
    behaviour is unchanged when the option is omitted, and for writable executions

SET SESSION values stay on the pooled connection after the execution, so a writable tool
sharing 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 in
a follow-up branch;
I will open it separately to keep this one small.

Testing

  • pnpm test:unit
  • pnpm test:integration (all connectors, including SQL Server and Oracle)
  • new integration cases are added to the existing MySQL and MariaDB suites, reusing their
    containers. The MySQL case checks that the server actually stops SELECT SLEEP(5) at
    max_execution_time = 500.
  • with the statements disabled, all four new integration cases fail

🤖 Generated with Claude Code

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>
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.

1 participant