Skip to content

perf(mysql): cut USE, row cap and column read round trips - #4341

Merged
datlechin merged 12 commits into
mainfrom
perf/mysql-session-round-trips
Nov 19, 2026
Merged

datlechin merged 12 commits into
mainfrom
perf/mysql-session-round-trips

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

  • P4: the USE the host sends before each statement is left out while the session is proven on that database. The proof lives on the connection and advances on its serial queue: only a statement headed SELECT, INSERT, UPDATE, DELETE, REPLACE, SHOW, DESC, EXPLAIN, WITH, VALUES, TABLE or DO, with no executable comment and no second statement, keeps it. Anything else sends the USE. The skip also needs the driver's active database to match and a clean footprint, on MySQL and MariaDB only, never behind a proxy that names itself.
  • P4: MySQLSessionFootprint now sees USE`db`, USE/* c */db, /*!40101 */ /*!40101 USE db */, CALL with no space, MariaDB EXECUTE IMMEDIATE and compound blocks, so mysqlMayReplay no longer replays after a move it missed. One forward pass, no recursion; past 32 version comments a statement counts as opaque.
  • P4: a left-out USE no longer resets ROW_COUNT() or the warning list, so they answer for the user's own last statement. With a row cap installed, the next statement still gets the reset that USE used to trigger.
  • P3: a capped read on a session that already accepted a cap sends SET SQL_SELECT_LIMIT and the read in one flight. Which SET goes out is unchanged from main, so diagnostics read the same. A refused cap reads the statement's own answer, as main does, and Stop keeps killing until the read is done.
  • P5: fetchColumns sends SHOW FULL COLUMNS, the catalog read, MariaDB's LEVEL probe and the check clauses in one flight. Stop never ends the session: it sends the same KILL QUERY again every 250 ms until every reply is read, under the connection's queue, so a queued COMMIT waits. Each reply's error comes from that reply. Only a client error retires the session. A session in a transaction or holding anything in its footprint reads one by one.
  • DatabaseManager+ScopedDriver.swift: the comment on the database switch says the driver now decides whether USE goes out.
  • check-column-type-corpus.sh: links the products and shared files the MySQL plugin and the export plugins need, so the MySQL and MariaDB corpus builds again.

Measured through a 200 ms round trip proxy, scratch MariaDB 13.0.2 and MySQL 8.4.11. Milliseconds, then statements sent.

Gesture MariaDB main branch MySQL main branch
Open, first table 1284, 6 647, 6 895, 4 634, 4
Open, second table 1256, 6 632, 5 858, 4 412, 3
Open, same table again 1052, 5 419, 4 838, 4 413, 3
Next page 423, 2 209, 1 423, 2 209, 1
Run with LIMIT, repeated 825, 4 204, 2 825, 4 206, 2
Capped run, repeated 840, 4 225, 2 842, 4 221, 2
Uncapped run after a cap 629, 3 417, 2 666, 3 413, 2
Session holding a user variable 874, 4 615, 4 840, 4 626, 4

Test plan

  • New: MySQLDatabaseMoveScanTests, MySQLColumnFlightTests. Added cases in MySQLSelectLimitTests and MySQLServerVersionTests. The footprint cases for the four USE spellings and EXECUTE IMMEDIATE fail on main.
  • No existing test changed.
  • Live harness on both scratch servers: every USE spelling, init_connect, the session's own and another client's DROP DATABASE, a stored function that moves the limit, ROW_COUNT(), SHOW WARNINGS and FOUND_ROWS() compared with main, a refused read inside a flight, a session killed mid-flight, temporary tables, transactions, NO_BACKSLASH_ESCAPES, Stop on queued SLEEP reads and on capped reads, Stop mid-flight through the proxy.
  • Column type corpus at UTC: all checks hold on MariaDB 13.0.2 and MySQL 8.4.11.

@datlechin
datlechin merged commit 02504f1 into main Nov 19, 2026
11 checks passed
@datlechin
datlechin deleted the perf/mysql-session-round-trips branch November 19, 2026 15:54
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