As of MySQL 8.0.16, MySQL includes built-in SQL functions that format or retrieve Performance Schema data, and that may be used as equivalents for the corresponding 从MySQL 8.0.16开始,MySQL包含了内置的SQL函数,这些函数格式化或检索性能架构数据,并且可以用作对应sys schema stored functions. sys架构存储函数的等价物。The built-in functions can be invoked in any schema and require no qualifier, unlike the 内置函数可以在任何架构中调用,并且不需要限定符,不像sys functions, which require either a sys. schema qualifier or that sys be the current schema.sys函数需要sys.架构限定符或sys必须是当前架构。
Table 12.27 Performance Schema Functions性能架构函数
FORMAT_BYTES() | 8.0.16 | |
|---|---|---|
FORMAT_PICO_TIME() | 8.0.16 | |
PS_CURRENT_THREAD_ID() | 8.0.16 | |
PS_THREAD_ID() | 8.0.16 | 
The built-in functions supersede the corresponding 内置函数取代相应的sys functions, which are deprecated; expect them to be removed in a future version of MySQL. sys函数,后者已被弃用;希望在MySQL的未来版本中删除它们。Applications that use the 使用sys functions should be adjusted to use the built-in functions instead, keeping in mind some minor differences between the sys functions and the built-in functions. sys函数的应用程序应该调整为使用内置函数,记住sys函数和内置函数之间的一些细微差别。For details about these differences, see the function descriptions in this section.有关这些差异的详细信息,请参阅本节中的函数说明。
Given a numeric byte count, converts it to human-readable format and returns a string consisting of a value and a units indicator. 给定一个数字字节计数,将其转换为可读格式,并返回一个由值和单位指示符组成的字符串。The string contains the number of bytes rounded to 2 decimal places and a minimum of 3 significant digits. 字符串包含四舍五入到2位小数位的字节数和至少3位有效数字。Numbers less than 1024 bytes are represented as whole numbers and are not rounded.小于1024字节的数字表示为整数,不舍入。
The units indicator depends on the size of the byte-count argument as shown in the following table.单位指示符取决于byte-count参数的大小,如下表所示。
| Argument Value | ||
|---|---|---|
| Up to 1023 | bytes | bytes | 
| Up to 10242 − 1 | kibibytes | KiB | 
| Up to 10243 − 1 | mebibytes | MiB | 
| Up to 10244 − 1 | gibibytes | GiB | 
| Up to 10245 − 1 | tebibytes | TiB | 
| Up to 10246 − 1 | pebibytes | PiB | 
| 10246 and up | exbibytes | EiB | 
mysql> SELECT FORMAT_BYTES(512), FORMAT_BYTES(18446644073709551615);
+-------------------+------------------------------------+
| FORMAT_BYTES(512) | FORMAT_BYTES(18446644073709551615) |
+-------------------+------------------------------------+
|  512 bytes        | 16.00 EiB                          |
+-------------------+------------------------------------+
MySQL 8.0.16增加了FORMAT_BYTES() was added in MySQL 8.0.16. FORMAT_BYTES()。It may be used instead of the 可以使用它来代替sys schema format_bytes() function, keeping in mind this difference:sys架构format_bytes()函数,请记住以下区别:
FORMAT_BYTES() uses the EiB units indicator. FORMAT_BYTES()使用EiB单位指示符。sys.format_bytes() does not.sys.format_bytes()不使用。
Given a numeric Performance Schema latency or wait time in picoseconds, converts it to human-readable format and returns a string consisting of a value and a units indicator. 给定以皮秒为单位的数字性能架构延迟或等待时间,将其转换为可读格式,并返回由值和单位指示符组成的字符串。The string contains the decimal time rounded to 2 decimal places and a minimum of 3 significant digits. 字符串包含四舍五入到2个小数位的小数时间和至少3个有效数字。Times under 1 nanosecond are represented as whole numbers and are not rounded.小于1纳秒的时间表示为整数,不四舍五入。
The units indicator depends on the size of the time-value argument as shown in the following table.单位指示器取决于时间值参数的大小,如下表所示。
| Up to 103 − 1 | picoseconds | ps | 
|---|---|---|
| Up to 106 − 1 | nanoseconds | ns | 
| Up to 109 − 1 | microseconds | us | 
| Up to 1012 − 1 | milliseconds | ms | 
| Up to 60×1012 − 1 | seconds | s | 
| Up to 3.6×1015 − 1 | minutes | min | 
| Up to 8.64×1016 − 1 | hours | h | 
| 8.64×1016 and up | days | d | 
mysql> SELECT FORMAT_PICO_TIME(3501), FORMAT_PICO_TIME(188732396662000);
+------------------------+-----------------------------------+
| FORMAT_PICO_TIME(3501) | FORMAT_PICO_TIME(188732396662000) |
+------------------------+-----------------------------------+
| 3.50 ns                | 3.15 min                          |
+------------------------+-----------------------------------+
MySQL 8.0.16中增加了FORMAT_PICO_TIME() was added in MySQL 8.0.16. FORMAT_PICO_TIME()。It may be used instead of the 可以使用它来代替sys schema format_time() function, keeping in mind these differences:sys架构format_time()函数,请记住以下区别:
To indicate minutes, 为了表示分钟,sys.format_time() uses the m units indicator, whereas FORMAT_PICO_TIME() uses min.sys.format_time()使用m单位指示符,而format_PICO_TIME()使用min。
sys.format_time() uses the w (weeks) units indicator. sys.format_time()使用w(周)单位指示符。FORMAT_PICO_TIME() does not.FORMAT_PICO_TIME()不使用它。
Returns a 返回一个BIGINT UNSIGNED value representing the Performance Schema thread ID assigned to the current connection.BIGINT UNSIGNED值,该值表示分配给当前连接的性能架构线程ID。
The thread ID return value is a value of the type given in the 线程ID返回值是性能架构表的THREAD_ID column of Performance Schema tables.THREAD_ID列中给定类型的值。
Performance Schema configuration affects 性能架构配置影响PS_CURRENT_THREAD_ID() the same way as for PS_THREAD_ID(). PS_CURRENT_THREAD_ID()的方式与影响PS_THREAD_ID()的方式相同。For details, see the description of that function.有关详细信息,请参见该函数的描述。
mysql>SELECT PS_CURRENT_THREAD_ID();+------------------------+ | PS_CURRENT_THREAD_ID() | +------------------------+ | 52 | +------------------------+ mysql>SELECT PS_THREAD_ID(CONNECTION_ID());+-------------------------------+ | PS_THREAD_ID(CONNECTION_ID()) | +-------------------------------+ | 52 | +-------------------------------+
在MySQL 8.0.16中添加了PS_CURRENT_THREAD_ID() was added in MySQL 8.0.16. PS_CURRENT_THREAD_ID()。It may be used as a shortcut for invoking the 它可用作调用参数为sys schema ps_thread_id() function with an argument of NULL or CONNECTION_ID().NULL或CONNECTION_id()的sys架构ps_thread_id()函数的快捷方式。
Given a connection ID, returns a 给定一个连接ID,返回一个BIGINT UNSIGNED value representing the Performance Schema thread ID assigned to the connection ID, or NULL if no thread ID exists for the connection ID. BIGINT UNSIGNED值,该值表示分配给该连接ID的性能架构线程ID,如果不存在该连接ID的线程ID,则返回NULL。The latter can occur for threads that are not instrumented.后者可能发生在未检测的线程上。
The connection ID argument is a value of the type given in the 连接ID参数是在性能架构PROCESSLIST_ID column of the Performance Schema threads table or the Id column of SHOW PROCESSLIST output.threads表的PROCESSLIST_ID列或SHOW PROCESSLIST输出的Id列中给定的类型值。
The thread ID return value is a value of the type given in the 线程ID返回值是性能模式表的THREAD_ID column of Performance Schema tables.THREAD_ID列中给定类型的值。
Performance Schema configuration affects 性能架构配置影响PS_THREAD_ID() operation as follows. PS_THREAD_ID()操作,如下所示。(These remarks also apply to (这些备注也适用于PS_CURRENT_THREAD_ID().)PS_CURRENT_THREAD_ID()。)
Disabling the 禁用thread_instrumentation consumer disables statistics from being collected and aggregated at the thread level, but has no effect on PS_THREAD_ID().thread_instrumentation消费者将禁止在线程级别收集和聚合统计信息,但对PS_thread_ID()没有影响。
If 如果performance_schema_max_thread_instances is not 0, the Performance Schema allocates memory for thread statistics and assigns an internal ID to each thread for which instance memory is available. performance_schema_max_thread_instances不为0,则性能架构会为线程统计信息分配内存,并为实例内存可用的每个线程分配一个内部ID。If there are threads for which instance memory is not available, 如果有实例内存不可用的线程,PS_THREAD_ID() returns NULL; in this case, Performance_schema_thread_instances_lost is nonzero.PS_THREAD_ID()返回NULL;在这种情况下,Performance_schema_thread_instances_lost为非零。
If 如果performance_schema_max_thread_instances is 0, the Performance Schema allocates no thread memory and PS_THREAD_ID() returns NULL.performance_schema_max_thread_instances为0,则性能架构不分配线程内存,PS_thread_ID()返回NULL。
If the Performance Schema itself is disabled, 如果性能模式本身被禁用,PS_THREAD_ID() produces an error.PS_THREAD_ID()将生成一个错误。
mysql> SELECT PS_THREAD_ID(6);
+-----------------+
| PS_THREAD_ID(6) |
+-----------------+
|              45 |
+-----------------+
在MySQL 8.0.16中添加了PS_THREAD_ID() was added in MySQL 8.0.16. PS_THREAD_ID()。It may be used instead of the 可以使用它来代替sys schema ps_thread_id() function, keeping in mind this difference:sys架构ps_thread_id()函数,请记住以下区别:
With an argument of 当参数为NULL, sys.ps_thread_id() returns the thread ID for the current connection, whereas PS_THREAD_ID() returns NULL. NULL时,sys.ps_thread_id()返回当前连接的线程id,而PS_THREAD_ID()返回NULL。To obtain the current connection thread ID, use 要获取当前连接线程ID,请改用PS_CURRENT_THREAD_ID() instead.PS_current_thread_ID()。