标签:information_schema

共 2 篇相关文章

IT 累计浏览 2,734

给MySQL的show table status结果做过滤

MySQL 的 show table status 可以查看表状态,但不能像 select 语句那样对结果做过滤。

解决办法是改从 information_schema 库的 tables 表查询:用 SELECT 选出 table_name、Engine、Version、Row_format、table_rows、Avg_row_length、Data_length、Index_length、Auto_increment、Create_time、Update_time 等字段,并以 Table_Schema='MyDataBaseName' 作为查询条件(需替换为实际库名),即可完全模拟 show table status 的输出,同时还能方便地在 WHERE 部分添加各种过滤条件。

IT 累计浏览 2,778

思考mysql内核之初级系列5---information_schema不是innodb数据字典

这篇文章延续"MySQL 内核之初级系列"的对话体风格,由 bingxi 和 alex 探讨一个核心问题:information_schema 不是 innodb 数据字典。文章先以 information_schema.statistics 为例说明——虽然它能看到表的索引信息,但仅供用户从外部查看,无法供 MySQL 内核使用,因为它不含索引根页等关键信息;真正的 innodb 数据字典在 dict0mem.h 中的 dict_index_struct、dict_tree_struct 里记录了 space 和 page,凭此才能实实在在地访问索引。此外,通过 show create table 可以看到 information_schema 中的表其实是 ENGINE=MEMORY 的临时表。innodb 一直有数据字典的概念,而 information_schema 是 MySQL 5 之后才出现的,二者并非一回事。

第二部分转向 information_schema 的代码实现,主要在 sql_show.h 和 sql_show.cpp 中(show status、show variables、show processlist 等语句也在此执行)。核心数据结构是 schema_tables 数组(26 个成员,其中部分如 STATUS、VARIABLES 不属于 information_schema 的 22 个表)和 ST_SCHEMA_TABLE 结构(含 create_table、fill_table 等函数指针)。执行流程为:mysql_schema_table 调用 create_schema_table,依据 fields_info 创建临时表;查询执行时 JOIN::exec 中的 get_schema_tables_result 调用 fill_status,再由 show_status_array 遍历全局变量并将记录插入表中,完成数据填充。不同表的差异主要在于填充方式,如 TABLES 需要扫描数据文件夹。最后建议读者对该 cpp 文件中的函数逐一设置断点调试,把 22 个表和各类 show 语句测试一遍。