-
Notifications
You must be signed in to change notification settings - Fork 111
extract_table_from_file_name()
xiaoboluo768 edited this page Jun 9, 2020
·
2 revisions
-
从给定文件路径名中提取表名,该函数在x$ps_schema_table_statistics_io视图中调用,当然你也可以在自定义视图中调用
- 该函数在拥有一个数据文件的完整路径时用这个路径作为传入参数提取performance_schema中的文件I/O信息非常实用, 它提供了一种便捷的方式来获取表名,比完整路径名更容易理解,并且该返回的表名称字符串值后续可以用于联结查询
-
参数:
- path VARCHAR(512):一个用于提取表名称的完整数据文件路径
-
返回值:是一个VARCHAR(64)字符串,即表名称字符串
-
定义语句
DROP FUNCTION IF EXISTS extract_table_from_file_name;
DELIMITER $$
CREATE DEFINER='root'@'localhost' FUNCTION extract_table_from_file_name (
path VARCHAR(512)
)
RETURNS VARCHAR(64)
COMMENT '
Description
-----------
Takes a raw file path, and extracts the table name from it.
Useful for when interacting with Performance Schema data
concerning IO statistics, for example.
Parameters
-----------
path (VARCHAR(512)):
The full file path to a data file to extract the table name from.
Returns
-----------
VARCHAR(64)
Example
-----------
mysql> SELECT sys.extract_table_from_file_name(\'/var/lib/mysql/employees/employee.ibd\');
+---------------------------------------------------------------------------+
| sys.extract_table_from_file_name(\'/var/lib/mysql/employees/employee.ibd\') |
+---------------------------------------------------------------------------+
| employee |
+---------------------------------------------------------------------------+
1 row in set (0.02 sec)
'
SQL SECURITY INVOKER
DETERMINISTIC
NO SQL
BEGIN
RETURN LEFT(SUBSTRING_INDEX(REPLACE(SUBSTRING_INDEX(REPLACE(path, '\\', '/'), '/', -1), '@0024', '$'), '.', 1), 64);
END$$
DELIMITER ;
上一篇: extract_schema_from_file_name()函数 | 下一篇: format_bytes()函数
- 验证、测试、整理:罗小波
- QQ:309969177
- 提示:本系列文章的主体结构遵循Oracle MySQL 官方 5.7 手册中,关于information_schema、mysql schema、performance_schema、sys schema的章节结构体系,并额外添加了一些验证、测试数据。鉴于本人精力和能力有限,难免出现一些纰漏,欢迎大家踊跃指正!