-
Notifications
You must be signed in to change notification settings - Fork 111
ps_is_consumer_enabled()
xiaoboluo768 edited this page Jun 9, 2020
·
2 revisions
-
检查指定的consumers知否真正生效。根据setup_consumers表中所有consumers的enabled字段设置值,按照consumers生效优先级依次检查指定consumers所依赖的consumers配置项是否启用,如果所依赖的consumers都启用时才会返回该consumers为YES,而不仅仅是返回该指定的consumers在setup_consumers中的enabled字段值设置
- 如果指定的consumers名称无效,则返回NULL
-
参数:
- in_consumer VARCHAR(64):要检查是否启用的consumers名称字符串
-
返回值:一个ENUM('YES','NO') 值
-
定义语句
DROP FUNCTION IF EXISTS ps_is_consumer_enabled;
DELIMITER $$
CREATE DEFINER='root'@'localhost' FUNCTION ps_is_consumer_enabled (
in_consumer varchar(64)
)
RETURNS enum('YES', 'NO')
COMMENT '
Determines whether a consumer is enabled (taking the consumer hierarchy into consideration)
within the Performance Schema.
Parameters
-----------
in_consumer VARCHAR(64):
The name of the consumer to check.
Returns
-----------
ENUM(\'YES\', \'NO\')
Example
-----------
mysql> SELECT sys.ps_is_consumer_enabled(\'events_stages_history\');
+-----------------------------------------------------+
| sys.ps_is_consumer_enabled(\'events_stages_history\') |
+-----------------------------------------------------+
| NO |
+-----------------------------------------------------+
1 row in set (0.00 sec)
'
SQL SECURITY INVOKER
DETERMINISTIC
READS SQL DATA
BEGIN
RETURN (
SELECT (CASE
WHEN c.NAME = 'global_instrumentation' THEN c.ENABLED
WHEN c.NAME = 'thread_instrumentation' THEN IF(cg.ENABLED = 'YES' AND c.ENABLED = 'YES', 'YES', 'NO')
WHEN c.NAME LIKE '%\_digest' THEN IF(cg.ENABLED = 'YES' AND c.ENABLED = 'YES', 'YES', 'NO')
WHEN c.NAME LIKE '%\_current' THEN IF(cg.ENABLED = 'YES' AND ct.ENABLED = 'YES' AND c.ENABLED = 'YES', 'YES', 'NO')
ELSE IF(cg.ENABLED = 'YES' AND ct.ENABLED = 'YES' AND c.ENABLED = 'YES'
AND ( SELECT cc.ENABLED FROM performance_schema.setup_consumers cc WHERE NAME = CONCAT(SUBSTRING_INDEX(c.NAME, '_', 2), '_current')
) = 'YES', 'YES', 'NO')
END) AS IsEnabled
FROM performance_schema.setup_consumers c
INNER JOIN performance_schema.setup_consumers cg
INNER JOIN performance_schema.setup_consumers ct
WHERE cg.NAME = 'global_instrumentation'
AND ct.NAME = 'thread_instrumentation'
AND c.NAME = in_consumer
);
END$$
DELIMITER ;
上一篇: ps_is_account_enabled()函数 | 下一篇: ps_is_instrument_default_enabled()函数
- 验证、测试、整理:罗小波
- QQ:309969177
- 提示:本系列文章的主体结构遵循Oracle MySQL 官方 5.7 手册中,关于information_schema、mysql schema、performance_schema、sys schema的章节结构体系,并额外添加了一些验证、测试数据。鉴于本人精力和能力有限,难免出现一些纰漏,欢迎大家踊跃指正!