Readyset is contributing source code to MySQL and Percona Server. With our change, START TRANSACTION WITH CONSISTENT SNAPSHOT (STWCS) returns the exact Global Transaction Identifier (GTID) set of the snapshot it just opened. It does this in the same round trip as part of the OK_PACKET, with no global lock and no extra privilege.
Every tool that copies data out of MySQL needs a synchronization point between the data inside its transaction and the binlog engine. Caches, search indexes, data warehouses, Change Data Capture pipelines (CDC), and backup tools all read a consistent copy of the data. Then they follow the binary log from the exact point that copy represents. Getting that point is expensive today.
We presented the proposal at the MySQL Contributor Summit, and have opened a pull request against MySQL. Here is the recording of the talk:
When Readyset starts, it copies every table it caches from MySQL before it can serve a single query. On large databases, that copy is slow, and today Readyset can't skip it, for two reasons.
First, MySQL gives no cheap way to know which transactions a consistent read already contains. To switch from "rows I read" to "changes I apply from the binlog" without losing or duplicating a change, a tool needs the exact GTID set (or binlog file and position) that matches its InnoDB read view. Get it wrong, and the copy is silently out of sync.
Second, because that synchronization point is expensive to get today, tools can't afford to get it often. Readyset could fetch rows on demand, one row for a cache miss or one chunk for a CDC re-read. But each fetch would need its own sync point, every time we hit a miss.
The standard recipe takes four statements:
FLUSH TABLES WITH READ LOCK;
START TRANSACTION WITH CONSISTENT SNAPSHOT;
SHOW BINARY LOG STATUS;
UNLOCK TABLES;
It works, but it costs a lot:
FLUSH TABLES WITH READ LOCK blocks every write on the server.
- It waits for every running query to finish, even a long
SELECT.
- It needs the
RELOAD privilege, which managed services often deny.
- It takes four round trips.
A global lock once a night for a backup is fine. A global lock a thousand times an hour is not. So Readyset, and most CDC tools, copy the whole table once at startup and never ask again.
Our change makes START TRANSACTION WITH CONSISTENT SNAPSHOT return the exact GTID set of the snapshot it opens:
- No global lock. Writes keep flowing.
- No extra privilege. No
RELOAD, so it works on managed services.
- One round trip. The GTID set comes back in the same OK packet as the snapshot.
The GTID set travels in the SESSION_TRACK_GTIDS session tracker, which MySQL clients and connectors already understand. The same snapshot coordinates can also be read back as session variables, including the binlog file and position for setups that don't use GTIDs.
The trick is to find the one moment in a commit when "visible in InnoDB" and "in the GTID set" change together.
InnoDB first prepares the transaction, without taking any binlog lock. Then a group of transactions moves through four stages. Each stage has its own lock, one leader thread moves the whole group, and different groups can be in different stages at once.

MySQL group commit pipeline · 4 stages
Only in the commit stage, under LOCK_commit, does a transaction become visible in InnoDB and join gtid_executed at the same time. Before that, it has a GTID number and may already be on replicas, but no reader can see it.
To open the snapshot, the server holds only LOCK_commit, and only briefly. While holding it, it creates the InnoDB read view and copies gtid_executed. The read view and the GTID set therefore describe exactly the same set of transactions.
- DML keeps running. Only commits and GTID assignment wait for that short moment.
- The GTID set goes back to the client in
SESSION_TRACK_GTIDS, inside the same OK packet.
- With
binlog_order_commits=0, the server forces ordered commits, the same approach MySQL Clone uses.
Here is the prototype in a packet capture. The client sends one ordinary query:
MySQL Protocol
Packet Length: 45
Request Command Query
Command: Query (3)
Statement: START TRANSACTION WITH CONSISTENT SNAPSHOT
The server answers with a single OK packet that carries the snapshot's GTID set:
MySQL Protocol - response OK
Packet Length: 65
Response Code: OK Packet (0x00)
Session tracking data
Session Track
Session tracking type: SESSION_TRACK_GTIDS (3)
GTIDs: c1be1b46-cd58-11f1-923f-962f283cb5d7:1-15
One round trip gives the snapshot and its GTID set. There is no FLUSH TABLES WITH READ LOCK and no extra query.
The same coordinates returned in the OK_Packet from STWCS are available as session variables right after the snapshot opens, including the binlog file and position:
mysql> START TRANSACTION WITH CONSISTENT SNAPSHOT;
Query OK, 0 rows affected (0,001 sec)
mysql> SELECT @@binlog_snapshot_gtid_executed, @@binlog_snapshot_file, @@binlog_snapshot_position\G
*************************** 1. row ***************************
@@binlog_snapshot_gtid_executed: c1be1b46-cd58-11f1-923f-962f283cb5d7:1-15
@@binlog_snapshot_file: binlog.000003
@@binlog_snapshot_position: 735
1 row in set (0,000 sec)
The idea is not new; it is proven in production. Percona Server has exposed Binlog_snapshot_file, Binlog_snapshot_position and Binlog_snapshot_gtid_executed for years, and MariaDB has binlog_snapshot_file and binlog_snapshot_position. Both projects' mysqldump use them to skip FLUSH TABLES WITH READ LOCK. PostgreSQL does the same thing another way: a replication slot exports a snapshot together with its LSN.
For Percona Server, our pull request builds on that existing mechanism. It returns Binlog_snapshot_gtid_executed in the OK packet, saving the extra SHOW STATUS round trip.
For MySQL, we took a different approach and lock only one mutex. Percona Server opens the snapshot while holding two binlog mutexes: LOCK_log, which serializes writes to the binary log, and LOCK_commit. Holding LOCK_log stops the flush stage. The snapshot must wait for any binlog write in progress, such as a large transaction being copied in, and no group can write to the binlog until it is done.
Our MySQL implementation holds only LOCK_commit. Flush and sync keep running; only the commit stage pauses while the read view is created and gtid_executed is copied. The binlog position no longer has to be read under LOCK_log: the commit stage records the position of the last transaction it made visible, and the snapshot picks it up. With binlog_order_commits=0, Percona Server takes a shared lock on every commit, while ours adds two atomic operations per commit group and no new mutex on the commit path (similar to the Clone Plugin).
Once a consistent read and its sync point cost one round trip, tools can ask for them as often as they need.
For Readyset, that means we no longer have to snapshot every table before serving traffic. We can fetch exactly the rows a cache needs, when it needs them, and know precisely which binlog events to apply on top. Startup gets faster, memory goes to the data that is actually queried, and adding a cache no longer means copying a whole table.
The same building block helps the wider ecosystem:
- CDC pipelines can re-read a single chunk to repair or backfill, without a global lock.
- Search indexes and warehouses can resync one table without pausing writes.
- Backup and dump tools can skip
FLUSH TABLES WITH READ LOCK, as they already do on Percona Server and MariaDB.
The work is open and in review upstream:
No global lock, no RELOAD privilege, one round trip. For Readyset, that means an end to the full snapshot at startup.