With the introduction of the data dictionary, the following 随着数据字典的引入,以下INFORMATION_SCHEMA
tables are implemented as views on data dictionary tables:INFORMATION_SCHEMA
表作为数据字典表的视图实现:
KEYWORDS
Queries on those tables are now more efficient because they obtain information from data dictionary tables rather than by other, slower means. 对这些表的查询现在效率更高,因为它们从数据字典表中获取信息,而不是通过其他较慢的方式。In particular, for each 特别是,对于作为数据字典表视图的每个INFORMATION_SCHEMA
table that is a view on data dictionary tables:INFORMATION_SCHEMA
表:
The server no longer must create a temporary table for each query of the 服务器不再需要为每个INFORMATION_SCHEMA
table.INFORMATION_SCHEMA
表查询创建临时表。
When the underlying data dictionary tables store values previously obtained by directory scans (for example, to enumerate database names or table names within databases) or file-opening operations (for example, to read information from 当基础数据字典表存储以前通过目录扫描(例如,枚举数据库名称或数据库中的表名称)或文件打开操作(例如,从.frm
files), INFORMATION_SCHEMA
queries for those values now use table lookups instead.
文件读取信息)获得的值时,这些值的.frm
INFORMATION_SCHEMA
查询现在改为使用表查找。(Additionally, even for a non-view (此外,即使对于非视图INFORMATION_SCHEMA
table, values such as database and table names are retrieved by lookups from the data dictionary and do not require directory or file scans.)INFORMATION_SCHEMA
表,也可以通过从数据字典中查找来检索数据库和表名等值,而不需要进行目录或文件扫描。)
Indexes on the underlying data dictionary tables permit the optimizer to construct efficient query execution plans, something not true for the previous implementation that processed the 底层数据字典表上的索引允许优化器构建高效的查询执行计划,这对于以前使用每个查询的临时表处理INFORMATION_SCHEMA
table using a temporary table per query.INFORMATION_SCHEMA
表的实现来说是不正确的。
The preceding improvements also apply to 前面的改进也适用于SHOW
statements that display information corresponding to the INFORMATION_SCHEMA
tables that are views on data dictionary tables. SHOW
语句,这些语句显示与作为数据字典表视图的INFORMATION_SCHEMA
表相对应的信息。For example, 例如,SHOW DATABASES
displays the same information as the SCHEMATA
table.SHOW DATABASES
显示与SCHEMATA
表相同的信息。
In addition to the introduction of views on data dictionary tables, table statistics contained in the 除了引入数据字典表的视图外,现在还缓存了STATISTICS
and TABLES
tables is now cached to improve INFORMATION_SCHEMA
query performance. STATISTICS
和TABLES
表中包含的表统计信息,以提高INFORMATION_SCHEMA
查询性能。The information_schema_stats_expiry
system variable defines the period of time before cached table statistics expire. information_schema_stats_expiry
系统变量定义了缓存表统计数据过期之前的时间段。The default is 86400 seconds (24 hours). 默认值为86400秒(24小时)。If there are no cached statistics or statistics have expired, statistics are retrieved from storage engine when querying table statistics columns. 如果没有缓存的统计信息或统计信息已过期,则在查询表统计信息列时,将从存储引擎中检索统计信息。To update cached values at any time for a given table, use 要随时更新给定表的缓存值,请使用ANALYZE TABLE
ANALYZE TABLE
。
information_schema_stats_expiry
can be set to 0
to have INFORMATION_SCHEMA
queries retrieve the latest statistics directly from the storage engine, which is not as fast as retrieving cached statistics.information_schema_stats_expiry
可以设置为0
,以使INFORMATION_SCHEMA
查询直接从存储引擎检索最新的统计信息,这不如检索缓存的统计信息快。
For more information, see Section 8.2.3, “Optimizing INFORMATION_SCHEMA Queries”.有关更多信息,请参阅第8.2.3节,“优化信息和模式查询”。
MySQL 8.0中的INFORMATION_SCHEMA
tables in MySQL 8.0 are closely tied to the data dictionary, resulting in several usage differences. INFORMATION_SCHEMA
表与数据字典紧密相连,导致了一些使用差异。See Section 14.7, “Data Dictionary Usage Differences”.请参阅第14.7节,“数据字典使用差异”。