INFORMATION_SCHEMA subsystem design in MySQL 8.0. In this post I will first go through our legacy implementation as it has stood since MySQL 5.1, and then cover what’s changed.INFORMATION_SCHEMA 子系统设计中,我们做了一些很有用的增强。在这篇文章中,我将会介绍自MySQL 5.1以来的旧的实现方式,然后介绍我们做了什么改变。INFORMATION_SCHEMA was first introduced into MySQL 5.0, as a standards compliant way of retrieving meta data from a running MySQL server. When we look at the history of
INFORMATION_SCHEMA there have been a number of complaints about the performance of certain queries, particularly in the case that there are many database objects (schemas, tables etc).INFORMATION_SCHEMA 首次引入MySQL 5.0,作为一种从正在运行的MySQL服务器检索元数据的标准兼容方式。当我们回顾
INFORMATION_SCHEMA 的历史时,对于某些特定查询性能总是有很多的抱怨,特别是在有许多数据库对象(schema,表等)的情况下。INFORMATION_SCHEMA queries. The optimizations are described in the MySQL manual, and apply when the user provides an explicit schema name or table name in the query.INFORMATION_SCHEMA 查询的执行速度。MySQL手册 <链接1> 中描述了这些优化,当用户在查询中提供显式schema名称或表名时,将会应用这些。INFORMATION_SCHEMA performance is still a major pain point for many of our users. The key reason behind these performance issues in the current
INFORMATION_SCHEMA implementation is that
INFORMATION_SCHEMA tables are implemented as temporary tables that are created on-the-fly during query execution. These temporary tables are populated via:INFORMATION_SCHEMA的 性能仍然是我们许多用户的主要痛点。在当前
INFORMATION_SCHEMA 实现方式下产生的性能问题背后的关键原因是,
INFORMATION_SCHEMA 表的查询实现方式是在查询执行期间创建临时表。这些临时表通过以下方式填充:INFORMATION_SCHEMA query would end-up doing lot of I/O reading each individual FRM files from the file system. And it would also end-up using more CPU cycles in effort to open the table and prepare related in-memory data structures. It does attempt to use the MySQL server table cache (the system variable ‘
table_definition_cache ‘), however in large server instances it’s very rare to have a table cache that is large enough to accommodate all of these tables.INFORMATION_SCHEMA 查询最终会从文件系统中读取每个单独的FRM文件,造成很多I/O读取。 并且最终还会消耗更多的CPU来打开表并准备相关的内存数据结构。 它确实尝试使用MySQL server层的表缓存(系统变量
table_definition_cache ),但是在大型实例中,很少有一个足够大的表缓存来容纳所有的表。INFORMATION_SCHEMA query. For example, let us consider the two queries belowINFORMATION_SCHEMA 查询未使用优化,则可以很容易碰到上面的性能问题。 例如,让我们考虑下面的两个查询EXPLAIN output, we see that the former query would use the values provided in
WHERE clause for the
TABLE_SCHEMA and
TABLE_NAME field as a key to read the desired
FRM files from the file system. However, the latter query would end up reading all the
FRM in the entire data directory, which is very costly and does not scale.EXPLAIN 的输出可以看到。 我们看到前一个查询将使用
WHERE 子句中为
TABLE_SCHEMA 和
TABLE_NAME 字段提供的值作为键,从文件系统读取所需
FRM 文件。 但是,后一个查询最终将读取整个数据目录中的所有
FRM ,这非常昂贵且无法扩展。FRM files) and also help MySQL to move towards supporting transactional DDL. For more details on introduction of data dictionary feature in 8.0 and its benefits, please look at Staale’s post here.FRM 文件),并帮助MySQL转向支持事务DDL。有关在8.0中引入数据字典功能及其优点的更多详细信息,请在此处查看Staale的文章 <链接2> 。INFORMATION_SCHEMA table as a database VIEW over the data dictionary tables. This eliminates costs such as the creation of temporary tables for each
INFORMATION_SCHEMA query during execution on-the-fly, and also scanning file-system directories to find FRM files. It is also now possible to utilize the full power of the MySQL optimizer to prepare better query execution plans using indexes on data dictionary tables.INFORMATION_SCHEMA 查询创建临时表,以及扫描文件系统目录以查找FRM文件。 现在还可以利用MySQL优化器的全部功能,使用数据字典表上的索引来获得更好的执行计划。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29797838/viewspace-2774790/ ,如需转载,请注明出处,否则将追究法律责任。