You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
2.0 KiB
55 lines
2.0 KiB
create
|
|
definer = `mysql.sys`@localhost function sys.format_statement(statement longtext) returns longtext comment '
|
|
Description
|
|
-----------
|
|
|
|
Formats a normalized statement, truncating it if it is > 64 characters long by default.
|
|
|
|
To configure the length to truncate the statement to by default, update the `statement_truncate_len`
|
|
variable with `sys_config` table to a different value. Alternatively, to change it just for just
|
|
your particular session, use `SET @sys.statement_truncate_len := <some new value>`.
|
|
|
|
Useful for printing statement related data from Performance Schema from
|
|
the command line.
|
|
|
|
Parameters
|
|
-----------
|
|
|
|
statement (LONGTEXT):
|
|
The statement to format.
|
|
|
|
Returns
|
|
-----------
|
|
|
|
LONGTEXT
|
|
|
|
Example
|
|
-----------
|
|
|
|
mysql> SELECT sys.format_statement(digest_text)
|
|
-> FROM performance_schema.events_statements_summary_by_digest
|
|
-> ORDER by sum_timer_wait DESC limit 5;
|
|
+-------------------------------------------------------------------+
|
|
| sys.format_statement(digest_text) |
|
|
+-------------------------------------------------------------------+
|
|
| CREATE SQL SECURITY INVOKER VI ... KE ? AND `variable_value` > ? |
|
|
| CREATE SQL SECURITY INVOKER VI ... ait` IS NOT NULL , `esc` . ... |
|
|
| CREATE SQL SECURITY INVOKER VI ... ait` IS NOT NULL , `sys` . ... |
|
|
| CREATE SQL SECURITY INVOKER VI ... , `compressed_size` ) ) DESC |
|
|
| CREATE SQL SECURITY INVOKER VI ... LIKE ? ORDER BY `timer_start` |
|
|
+-------------------------------------------------------------------+
|
|
5 rows in set (0.00 sec)
|
|
' deterministic sql security invoker no sql
|
|
BEGIN
|
|
-- Check if we have the configured length, if not, init it
|
|
IF @sys.statement_truncate_len IS NULL THEN
|
|
SET @sys.statement_truncate_len = sys_get_config('statement_truncate_len', 64);
|
|
END IF;
|
|
IF CHAR_LENGTH(statement) > @sys.statement_truncate_len THEN
|
|
RETURN REPLACE(CONCAT(LEFT(statement, (@sys.statement_truncate_len/2)-2), ' ... ', RIGHT(statement, (@sys.statement_truncate_len/2)-2)), '\n', ' ');
|
|
ELSE
|
|
RETURN REPLACE(statement, '\n', ' ');
|
|
END IF;
|
|
END;
|
|
|