Databases 21 min read

MySQL Internals: Group Commit, DDL Fast‑Fail, GTID Optimization, Auto‑Increment Persistence, and Replication Improvements

This article explains MySQL's Group Commit mechanism, DDL fast‑fail enhancements, GTID allocation optimizations, fixes for InnoDB auto‑increment duplication after restart, and the evolution of replication performance from 5.5 to 5.7, including detailed code snippets and benchmark results.

Qunar Tech Salon
Qunar Tech Salon
Qunar Tech Salon
MySQL Internals: Group Commit, DDL Fast‑Fail, GTID Optimization, Auto‑Increment Persistence, and Replication Improvements

Background – Prior to MySQL 5.6 the Binlog and InnoDB XA phases were serialized, causing a bottleneck when sync_binlog=1 . MariaDB introduced a Binlog Group Commit queue, and MySQL 5.6 adopted a similar three‑stage approach (flush, sync, commit) that can run concurrently.

XA Recover – With Binlog enabled MySQL uses MySQL_BIN_LOG as the XA coordinator. It scans the last Binlog file for XIDs, compares them with InnoDB’s prepared‑transaction list, and commits or rolls back accordingly, ensuring crash‑safe recovery without an explicit redo‑log write/fsync at commit time.

Optimization of Group Commit – By moving the redo‑log write/fsync to the first stage of Group Commit, the implementation reduces log_sys‑mutex contention. The steps are: Step1. InnoDB Prepare, record LSN; Step2. Flush stage – leader gathers queue and determines max LSN; Step3. Write/FSYNC redo log to that LSN; Step4. Write Binlog and perform sync/commit. Performance tests (sysbench, 100‑table workload) show TPS improvements from ~25k to ~38k as concurrency rises.

DDL Fast‑Fail – To avoid full‑system blockage when a DDL statement cannot acquire an exclusive MDL lock, Aliyun RDS adds NO_WAIT/WAIT 1 syntax. If lock acquisition fails, the client receives a timeout error, preventing other sessions from being queued behind the DDL.

Comparison with Oracle – Oracle 10g reports ORA‑00054 for lock‑wait timeouts; MySQL’s fast‑fail provides a similar early‑exit mechanism without waiting for the lock.

GTID Allocation – MySQL 5.6+ supports automatic GTID assignment during the Group Commit flush stage. The original design kept a gtid_owned set that required a mutex at commit time, causing contention under high concurrency. The optimization removes this set and directly inserts the GTID into gtid_executed , eliminating the lock and improving TPS.

InnoDB Auto‑Increment Duplication Bug – After a server restart, InnoDB recomputes the next AUTO_INCREMENT value using SELECT MAX(id)+1 , which can reuse IDs that were previously allocated but not persisted, leading to duplicate primary keys. MyISAM stores the value in the .MYI file and does not suffer this issue.

Fix – The solution persists the AUTO_INCREMENT counter in the clustered index root page’s trx_id field, writing a tiny redo‑log entry on each increment. A new global variable innodb_autoinc_persistent (ON/OFF) controls this behavior, and innodb_autoinc_persistent_interval controls how often the value is flushed. Benchmarks show less than 1% performance overhead.

Replication Performance Improvements (5.5 → 5.7) – 5.5 used a single SQL thread; 5.6 introduced multi‑threaded parallel replication with a coordinator thread that distributes events to worker threads based on database name. 5.7 adds a second parallelism level by tagging events with a common seqno , allowing transactions with the same timestamp to execute concurrently regardless of database, simplifying the model and further boosting throughput. The article also lists known bugs in the 5.6 implementation.

Overall, the article provides a deep dive into MySQL’s internal concurrency mechanisms, the motivations behind recent optimizations, and concrete performance data demonstrating their impact.

performanceMySQLReplicationauto-incrementDDLGTIDgroup commit
Qunar Tech Salon
Written by

Qunar Tech Salon

Qunar Tech Salon is a learning and exchange platform for Qunar engineers and industry peers. We share cutting-edge technology trends and topics, providing a free platform for mid-to-senior technical professionals to exchange and learn.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.