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

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

MySQL 8.4 参考手册 / 29 MySQL Performance Schema / 29.9 Performance Schema Tables for Current and Historical Events
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

29.9 当前和历史事件的性能模式表29.9 Performance Schema Tables for Current and Historical Events

对于等待、阶段、语句和事务事件,性能架构可以监控并存储当前事件。此外,当事件结束时,性能架构可以将其存储在历史表中。对于每种事件类型,性能架构使用三个表来存储当前和历史事件。这些表的名称形式如下,其中 xxx 表示事件类型(waits、stages、statements、transactions):For wait, stage, statement, and transaction events, the Performance Schema can monitor and store current events. In addition, when events end, the Performance Schema can store them in history tables. For each event type, the Performance Schema uses three tables for storing current and historical events. The tables have names of the following forms, where xxx indicates the event type (waits, stages, statements, transactions):

  • events_xxx_current:“当前事件” 表存储每个线程的当前监控事件(每个线程一行)。events_xxx_current: The “current events” table stores the current monitored event for each thread (one row per thread).

  • events_xxx_history:“最近历史” 表存储每个线程中已结束的最新事件(每个线程最多存储一定数量的行)。events_xxx_history: The “recent history” table stores the most recent events that have ended per thread (up to a maximum number of rows per thread).

  • events_xxx_history_long:“长期历史” 表存储全局(跨所有线程)已结束的最新事件(每个表最多存储一定数量的行)。events_xxx_history_long: The “long history” table stores the most recent events that have ended globally (across all threads, up to a maximum number of rows per table).

每个事件类型的 _current 表包含每个线程的一行,因此没有系统变量可以配置其最大大小。Performance Schema 会自动调整历史表的大小,或者可以在服务器启动时使用表特定的系统变量显式配置其大小,如描述各个历史表的部分所示。典型的自动调整值是每个线程的 _history 表为 10 行,总共 _history_long 表为 10,000 行。The _current table for each event type contains one row per thread, so there is no system variable for configuring its maximum size. The Performance Schema autosizes the history tables, or the sizes can be configured explicitly at server startup using table-specific system variables, as indicated in the sections that describe the individual history tables. Typical autosized values are 10 rows per thread for _history tables, and 10,000 rows total for _history_long tables.

对于每个事件类型,_current、_history 和 _history_long 表具有相同的列。_current 和 _history 表具有相同的索引。_history_long 表没有索引。For each event type, the _current, _history, and _history_long tables have the same columns. The _current and _history tables have the same indexing. The _history_long table has no indexing.

_current 表显示服务器中当前正在发生的情况。当当前事件结束时,它会从其 _current 表中移除。The _current tables show what is currently happening within the server. When a current event ends, it is removed from its _current table.

_history 和 _history_long 表显示最近发生的事件。当历史表已满时,旧事件会在新事件添加时被丢弃。_history 和 _history_long 表中的行过期方式不同,因为这些表的用途不同:The _history and _history_long tables show what has happened in the recent past. When the history tables become full, old events are discarded as new events are added. Rows expire from the _history and _history_long tables in different ways because the tables serve different purposes:

  • _history 用于独立于全局服务器负载调查各个线程。_history is meant to investigate individual threads, independently of the global server load.

  • _history_long 用于全局调查服务器,而不是每个线程。_history_long is meant to investigate the server globally, not each thread.

这两种历史表的区别与数据保留策略有关。两张表在首次检测到事件时包含相同的数据。然而,每张表中的数据随时间到期的方式不同,因此数据在每张表中可能保存的时间长短不同:The difference between the two types of history tables relates to the data retention policy. Both tables contains the same data when an event is first seen. However, data within each table expires differently over time, so that data might be preserved for a longer or shorter time in each table:

  • 对于 _history,当表中某个线程的行数达到最大值时,当为该线程添加新行时,最旧的线程行将被丢弃。For _history, when the table contains the maximum number of rows for a given thread, the oldest thread row is discarded when a new row for that thread is added.

  • 对于 _history_long,当表满时,无论哪条线程生成了行,添加新行时都会丢弃最旧的行。For _history_long, when the table becomes full, the oldest row is discarded when a new row is added, regardless of which thread generated either row.

当线程结束时,其所有行将从 _history 表中删除,但不会从 _history_long 表中删除。When a thread ends, all its rows are discarded from the _history table but not from the _history_long table.

以下示例说明了事件在两种类型的历史表中是如何添加和丢弃的差异。原则同样适用于所有事件类型。该示例基于以下假设:The following example illustrates the differences in how events are added to and discarded from the two types of history tables. The principles apply equally to all event types. The example is based on these assumptions:

  • Performance Schema 配置为在 _history 表中每个线程保留 10 行,在 _history_long 表中总共保留 10,000 行。The Performance Schema is configured to retain 10 rows per thread in the _history table and 10,000 rows total in the _history_long table.

  • 线程 A 每秒生成 1 个事件。Thread A generates 1 event per second.

    线程 B 每秒生成 100 个事件。Thread B generates 100 events per second.

  • 没有其他线程在运行。No other threads are running.

执行 5 秒后:After 5 seconds of execution:

  • A 和 B 分别生成了 5 个和 500 个事件。A and B have generated 5 and 500 events, respectively.

  • _history 表中,A 有 5 行,B 有 10 行。由于每个线程的存储限制为 10 行,A 没有被丢弃的行,而 B 有 490 行被丢弃。_history contains 5 rows for A and 10 rows for B. Because storage per thread is limited to 10 rows, no rows have been discarded for A, whereas 490 rows have been discarded for B.

  • _history_long 包含 A 的 5 行和 B 的 500 行。因为该表的最大大小为 10,000 行,所以两个线程都没有丢弃任何行。_history_long contains 5 rows for A and 500 rows for B. Because the table has a maximum size of 10,000 rows, no rows have been discarded for either thread.

执行 5 分钟(300 秒)后:After 5 minutes (300 seconds) of execution:

  • A 和 B 分别生成了 300 和 30,000 个事件。A and B have generated 300 and 30,000 events, respectively.

  • _history 包含 A 的 10 行和 B 的 10 行。因为每个线程的存储限制为 10 行,A 丢弃了 290 行,而 B 丢弃了 29,990 行。A 的行包含最多 10 秒前的数据,而 B 的行仅包含最多 0.1 秒前的数据。_history contains 10 rows for A and 10 rows for B. Because storage per thread is limited to 10 rows, 290 rows have been discarded for A, whereas 29,990 rows have been discarded for B. Rows for A include data up to 10 seconds old, whereas rows for B include data up to only .1 seconds old.

  • _history_long 包含 10,000 行。因为 A 和 B 一起每秒生成 101 个事件,该表包含的数据大约有 10,000/101 = 99 秒前的数据,行的组合约为 B:A = 100:1。_history_long contains 10,000 rows. Because A and B together generate 101 events per second, the table contains data up to approximately 10,000/101 = 99 seconds old, with a mix of rows approximately 100 to 1 from B as opposed to A.