-
Notifications
You must be signed in to change notification settings - Fork 111
ps_thread_id()
xiaoboluo768 edited this page Jun 9, 2020
·
2 revisions
-
在threads表中查询给定连接ID(processlist_id)的内部线程ID,如果给定连接ID为NULL值,则返回当前连接的内部线程ID
-
参数:
- in_connection_id BIGINT UNSIGNED:要返回内部线程ID的连接的ID。 对应performance_schema.threads表中的PROCESSLIST_ID列或SHOW PROCESSLIST输出的Id列值
-
返回值:一个BIGINT UNSIGNED值
-
定义语句
DROP FUNCTION IF EXISTS ps_thread_id;
DELIMITER $$
CREATE DEFINER='root'@'localhost' FUNCTION ps_thread_id (
in_connection_id BIGINT UNSIGNED
) RETURNS BIGINT UNSIGNED
COMMENT '
Description
-----------
Return the Performance Schema THREAD_ID for the specified connection ID.
Parameters
-----------
in_connection_id (BIGINT UNSIGNED):
The id of the connection to return the thread id for. If NULL, the current
connection thread id is returned.
Example
-----------
mysql> SELECT sys.ps_thread_id(79);
+----------------------+
| sys.ps_thread_id(79) |
+----------------------+
| 98 |
+----------------------+
1 row in set (0.00 sec)
mysql> SELECT sys.ps_thread_id(CONNECTION_ID());
+-----------------------------------+
| sys.ps_thread_id(CONNECTION_ID()) |
+-----------------------------------+
| 98 |
+-----------------------------------+
1 row in set (0.00 sec)
'
SQL SECURITY INVOKER
NOT DETERMINISTIC
READS SQL DATA
BEGIN
RETURN (SELECT THREAD_ID
FROM `performance_schema`.`threads`
WHERE PROCESSLIST_ID = IFNULL(in_connection_id, CONNECTION_ID())
);
END$$
DELIMITER ;
上一篇: ps_thread_account()函数 | 下一篇: ps_thread_stack()函数
- 验证、测试、整理:罗小波
- QQ:309969177
- 提示:本系列文章的主体结构遵循Oracle MySQL 官方 5.7 手册中,关于information_schema、mysql schema、performance_schema、sys schema的章节结构体系,并额外添加了一些验证、测试数据。鉴于本人精力和能力有限,难免出现一些纰漏,欢迎大家踊跃指正!