How MySQL 8 reduced contention for metadata locks?

MySQL 8 introduced several improvements to reduce contention for metadata locks, which are locks that are used to manage access to database objects such as tables and indexes. Here are a few ways in which MySQL 8 reduces contention for metadata locks:

  1. Lock-Free DDL: In previous versions of MySQL, creating or dropping a table or index required an exclusive metadata lock on the affected object, which could cause contention and slow down the operation. In MySQL 8, DDL operations are performed using a lock-free algorithm, which allows multiple operations to occur concurrently without requiring exclusive metadata locks.
  2. Data Dictionary Scaling: MySQL 8 introduces several improvements to the data dictionary, which is a set of tables that store information about database objects. The data dictionary now uses a scalable storage engine, and metadata operations are distributed across multiple instances of the dictionary cache, reducing contention and improving scalability.
  3. Background DDL: MySQL 8 introduces support for background DDL, which allows DDL operations to be performed without blocking concurrent queries. When a DDL operation is initiated, it is added to a queue and processed in the background, allowing other queries to continue executing.
  4. Lock Granularity: MySQL 8 introduces finer-grained metadata locks, which reduce contention by allowing multiple transactions to hold locks on different parts of a database object simultaneously. For example, a transaction can hold a lock on a specific index page without blocking other transactions from accessing other parts of the index.

These improvements help to reduce contention for metadata locks and improve the scalability and performance of MySQL 8 in high-concurrency environments.

Conclusion

This helps in enhancements, including lock-free DDL, scalable data dictionary, background DDL, and finer lock granularity, significantly reduce contention for metadata locks. These improvements bolster MySQL’s scalability and performance, making it more efficient in high-concurrency environments and streamlining MySQL DBA operations.

About Shiv Iyer 446 Articles
Open Source Database Systems Engineer with a deep understanding of Optimizer Internals, Performance Engineering, Scalability and Data SRE. Shiv currently is the Founder, Investor, Board Member and CEO of multiple Database Systems Infrastructure Operations companies in the Transaction Processing Computing and ColumnStores ecosystem. He is also a frequent speaker in open source software conferences globally.