文档首页
MySQL 8.4 参考手册
8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

29.4.5 按对象预过滤29.4.5 Pre-Filtering by Object

setup_objects表控制 Performance Schema 是否监控特定的表和存储程序对象。初始的setup_objects内容如下:The setup_objects table controls whether the Performance Schema monitors particular table and stored program objects. The initial setup_objects contents look like this:

mysql> SELECT * FROM performance_schema.setup_objects;
+-------------+--------------------+-------------+---------+-------+
| OBJECT_TYPE | OBJECT_SCHEMA      | OBJECT_NAME | ENABLED | TIMED |
+-------------+--------------------+-------------+---------+-------+
| EVENT       | mysql              | %           | NO      | NO    |
| EVENT       | performance_schema | %           | NO      | NO    |
| EVENT       | information_schema | %           | NO      | NO    |
| EVENT       | %                  | %           | YES     | YES   |
| FUNCTION    | mysql              | %           | NO      | NO    |
| FUNCTION    | performance_schema | %           | NO      | NO    |
| FUNCTION    | information_schema | %           | NO      | NO    |
| FUNCTION    | %                  | %           | YES     | YES   |
| PROCEDURE   | mysql              | %           | NO      | NO    |
| PROCEDURE   | performance_schema | %           | NO      | NO    |
| PROCEDURE   | information_schema | %           | NO      | NO    |
| PROCEDURE   | %                  | %           | YES     | YES   |
| TABLE       | mysql              | %           | NO      | NO    |
| TABLE       | performance_schema | %           | NO      | NO    |
| TABLE       | information_schema | %           | NO      | NO    |
| TABLE       | %                  | %           | YES     | YES   |
| TRIGGER     | mysql              | %           | NO      | NO    |
| TRIGGER     | performance_schema | %           | NO      | NO    |
| TRIGGER     | information_schema | %           | NO      | NO    |
| TRIGGER     | %                  | %           | YES     | YES   |
+-------------+--------------------+-------------+---------+-------+

对 setup_objects 表的修改会立即影响对象监控。Modifications to the setup_objects table affect object monitoring immediately.

OBJECT_TYPE 列表示该行适用的对象类型。TABLE 筛选会影响表 I/O 事件(wait/io/table/sql/handler 仪器)和表锁事件(wait/lock/table/sql/handler 仪器)。The OBJECT_TYPE column indicates the type of object to which a row applies. TABLE filtering affects table I/O events (wait/io/table/sql/handler instrument) and table lock events (wait/lock/table/sql/handler instrument).

OBJECT_SCHEMA 和 OBJECT_NAME 列应包含字面上的 schema 或对象名称,或者使用 '%' 来匹配任意名称。The OBJECT_SCHEMA and OBJECT_NAME columns should contain a literal schema or object name, or '%' to match any name.

ENABLED 列表示匹配的对象是否被监控,而 TIMED 表示是否收集时间信息。设置 TIMED 列会影响性能模式表的内容,如 第 29.4.1 节,“性能模式事件计时” 中所述。The ENABLED column indicates whether matching objects are monitored, and TIMED indicates whether to collect timing information. Setting the TIMED column affects Performance Schema table contents as described in Section 29.4.1, “Performance Schema Event Timing”.

默认对象配置的效果是对所有对象进行监控,但不包括 mysql、INFORMATION_SCHEMA 和 performance_schema 数据库中的对象。(无论 setup_objects 的内容如何,INFORMATION_SCHEMA 数据库中的表都不会被监控;information_schema.% 的行只是明确了这个默认设置。)The effect of the default object configuration is to instrument all objects except those in the mysql, INFORMATION_SCHEMA, and performance_schema databases. (Tables in the INFORMATION_SCHEMA database are not instrumented regardless of the contents of setup_objects; the row for information_schema.% simply makes this default explicit.)

当性能模式在setup_objects中检查匹配时,它会先尝试找到更具体的匹配。对于匹配给定OBJECT_TYPE的行,性能模式按以下顺序检查行:When the Performance Schema checks for a match in setup_objects, it tries to find more specific matches first. For rows that match a given OBJECT_TYPE, the Performance Schema checks rows in this order:

  • 行中OBJECT_SCHEMA='literal'且OBJECT_NAME='literal'的行。Rows with OBJECT_SCHEMA='literal' and OBJECT_NAME='literal'.

  • 行中OBJECT_SCHEMA='literal'且OBJECT_NAME='%'的行。Rows with OBJECT_SCHEMA='literal' and OBJECT_NAME='%'.

  • 行中OBJECT_SCHEMA='%'且OBJECT_NAME='%'的行。Rows with OBJECT_SCHEMA='%' and OBJECT_NAME='%'.

例如,对于一个表 db1.t1,性能模式会在 TABLE 行中查找匹配 'db1' 和 't1' 的项,然后查找 'db1' 和 '%' 的项,再然后查找 '%' 和 '%' 的项。匹配的顺序很重要,因为不同的匹配 setup_objects 行可以有不同的 ENABLED 和 TIMED 值。For example, with a table db1.t1, the Performance Schema looks in TABLE rows for a match for 'db1' and 't1', then for 'db1' and '%', then for '%' and '%'. The order in which matching occurs matters because different matching setup_objects rows can have different ENABLED and TIMED values.

对于与表相关的事件,性能模式将 setup_objects 的内容与 setup_instruments 的内容结合起来,以确定是否启用工具以及是否为已启用的工具计时:For table-related events, the Performance Schema combines the contents of setup_objects with setup_instruments to determine whether to enable instruments and whether to time enabled instruments:

  • 对于在 setup_objects 中匹配一行的表,表仪器仅当 ENABLED 在 setup_instruments 和 setup_objects 中均为 YES 时才会生成事件。For tables that match a row in setup_objects, table instruments produce events only if ENABLED is YES in both setup_instruments and setup_objects.

  • 两个表中的 TIMED 值会被组合,因此仅当两个值均为 YES 时才会收集时间信息。The TIMED values in the two tables are combined, so that timing information is collected only when both values are YES.

对于存储程序对象,性能模式直接从 setup_objects 行获取 ENABLED 和 TIMED 列。不会与 setup_instruments 的值进行合并。For stored program objects, the Performance Schema takes the ENABLED and TIMED columns directly from the setup_objects row. There is no combining of values with setup_instruments.

假设 setup_objects 包含以下适用于 db1、db2 和 db3 的 TABLE 行:Suppose that setup_objects contains the following TABLE rows that apply to db1, db2, and db3:

+-------------+---------------+-------------+---------+-------+
| OBJECT_TYPE | OBJECT_SCHEMA | OBJECT_NAME | ENABLED | TIMED |
+-------------+---------------+-------------+---------+-------+
| TABLE       | db1           | t1          | YES     | YES   |
| TABLE       | db1           | t2          | NO      | NO    |
| TABLE       | db2           | %           | YES     | YES   |
| TABLE       | db3           | %           | NO      | NO    |
| TABLE       | %             | %           | YES     | YES   |
+-------------+---------------+-------------+---------+-------+

如果 setup_instruments 中与对象相关的工具的 ENABLED 值为 NO,则不会监控该对象的事件。如果 ENABLED 值为 YES,则根据相关 setup_objects 行中的 ENABLED 值进行事件监控:If an object-related instrument in setup_instruments has an ENABLED value of NO, events for the object are not monitored. If the ENABLED value is YES, event monitoring occurs according to the ENABLED value in the relevant setup_objects row:

  • db1.t1 事件已监控db1.t1 events are monitored

  • db1.t2 事件未监控db1.t2 events are not monitored

  • db2.t3 事件已监控db2.t3 events are monitored

  • db3.t4 事件未监控db3.t4 events are not monitored

  • db4.t5 事件被监控db4.t5 events are monitored

类似的逻辑适用于将 setup_instruments 表和 setup_objects 表中的 TIMED 列进行组合,以确定是否收集事件时间信息。Similar logic applies for combining the TIMED columns from the setup_instruments and setup_objects tables to determine whether to collect event timing information.

如果一个持久表和一个临时表同名,则匹配 setup_objects 行的方式对两者相同。无法只为一张表启用监控而不启用另一张表。但每张表都是单独设置检测的。If a persistent table and a temporary table have the same name, matching against setup_objects rows occurs the same way for both. It is not possible to enable monitoring for one table but not the other. However, each table is instrumented separately.