Server IP : 172.67.216.182 / Your IP : 104.23.175.161 Web Server : Apache System : Linux krdc-ubuntu-s-2vcpu-4gb-amd-blr1-01.localdomain 5.15.0-142-generic #152-Ubuntu SMP Mon May 19 10:54:31 UTC 2025 x86_64 User : www ( 1000) PHP Version : 7.4.33 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /www/server/mysql/src/install/scripts/ |
Upload File : |
/* Do not edit this file, it is automatically generated from: </www/server/mysql/src/scripts/mysql_sys_schema.sql> */ const char* mysql_sys_schema[]={ "REPLACE INTO mysql.user VALUES ('localhost','mysql.sys','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N'," "'N','N','N','N','N','N','N','N','N','N','N','N','N','','','','',0,0,0,0,'mysql_native_password','*THISISNOTAVALIDPASS" "WORDTHATCANBEUSEDHERE','N',CURRENT_TIMESTAMP,NULL,'Y');\n", "REPLACE INTO mysql.db VALUES ('localhost','sys','mysql.sys','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N'," "'N','N','N','Y');\n", "REPLACE INTO mysql.tables_priv VALUES ('localhost','sys','mysql.sys','sys_config','root@localhost', CURRENT_TIMESTAMP, '" "Select', '');\n", "FLUSH PRIVILEGES;\n", "SET NAMES utf8;\n", "SET @sql_log_bin = @@sql_log_bin;\n", "SET sql_log_bin = 0;\n", "CREATE DATABASE IF NOT EXISTS sys DEFAULT CHARACTER SET utf8;\n", "USE sys;\n", "CREATE OR REPLACE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW version ( sys_version, mysql_version ) AS" " SELECT '1.5.2' AS sys_version, version() AS mysql_version;\n", "CREATE TABLE IF NOT EXISTS sys_config ( variable VARCHAR(128) PRIMARY KEY, value VARCHAR(128), set_time TIMESTAMP DEFAUL" "T CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, set_by VARCHAR(128) ) ENGINE = InnoDB;\n", "INSERT IGNORE INTO sys.sys_config (variable, value) VALUES ('statement_truncate_len', 64), ('statement_performance_analy" "zer.limit', 100), ('statement_performance_analyzer.view', NULL), ('diagnostics.allow_i_s_tables', 'OFF'), ('diagnosti" "cs.include_raw', 'OFF'), ('ps_thread_trx_info.max_length', 65535);\n", "DROP TRIGGER IF EXISTS sys_config_insert_set_user;\n", "CREATE DEFINER='mysql.sys'@'localhost' TRIGGER sys_config_insert_set_user BEFORE INSERT on sys_config FOR EACH ROW BEGIN" " IF @sys.ignore_sys_config_triggers != true AND NEW.set_by IS NULL THEN SET NEW.set_by = USER(); END IF; END;\n", "DROP TRIGGER IF EXISTS sys_config_update_set_user;\n", "CREATE DEFINER='mysql.sys'@'localhost' TRIGGER sys_config_update_set_user BEFORE UPDATE on sys_config FOR EACH ROW BEGIN" " IF @sys.ignore_sys_config_triggers != true AND NEW.set_by IS NULL THEN SET NEW.set_by = USER(); END IF; END;\n", "DROP FUNCTION IF EXISTS extract_schema_from_file_name;\n", "CREATE DEFINER='mysql.sys'@'localhost' FUNCTION extract_schema_from_file_name ( path VARCHAR(512) ) RETURNS VARCHAR(64) " " COMMENT '\\n Description\\n \\n Takes a raw file path, and attempts to extract the schema name from it.\\n \\n Useful for" " when interacting with Performance Schema data \\n concerning IO statistics, for example.\\n \\n Currently relies on the" " fact that a table data file will be within a \\n specified database directory (will not work with partitions or table" "s\\n that specify an individual DATA_DIRECTORY).\\n \\n Parameters\\n \\n path (VARCHAR(512)):\\n The full file path to a d" "ata file to extract the schema name from.\\n \\n Returns\\n \\n VARCHAR(64)\\n \\n Example\\n \\n mysql> SELECT sys.extract_s" "chema_from_file_name(\\'/var/lib/mysql/employees/employee.ibd\\');\\n +-------------------------------------------------" "---------------------------+\\n | sys.extract_schema_from_file_name(\\'/var/lib/mysql/employees/employee.ibd\\') |\\n +--" "--------------------------------------------------------------------------+\\n | employees " " |\\n +--------------------------------------------------------------------------" "--+\\n 1 row in set (0.00 sec)\\n ' SQL SECURITY INVOKER DETERMINISTIC NO SQL BEGIN RETURN LEFT(SUBSTRING_INDEX(SUBSTRI" "NG_INDEX(REPLACE(path, '\\\\', '/'), '/', -2), '/', 1), 64); END;\n", "DROP FUNCTION IF EXISTS extract_table_from_file_name;\n", "CREATE DEFINER='mysql.sys'@'localhost' FUNCTION extract_table_from_file_name ( path VARCHAR(512) ) RETURNS VARCHAR(64) " "COMMENT '\\n Description\\n \\n Takes a raw file path, and extracts the table name from it.\\n \\n Useful for when interac" "ting with Performance Schema data \\n concerning IO statistics, for example.\\n \\n Parameters\\n \\n path (VARCHAR(512)):" "\\n The full file path to a data file to extract the table name from.\\n \\n Returns\\n \\n VARCHAR(64)\\n \\n Example\\n \\n " "mysql> SELECT sys.extract_table_from_file_name(\\'/var/lib/mysql/employees/employee.ibd\\');\\n +-----------------------" "----------------------------------------------------+\\n | sys.extract_table_from_file_name(\\'/var/lib/mysql/employees" "/employee.ibd\\') |\\n +---------------------------------------------------------------------------+\\n | employee " " |\\n +----------------------------------------------------" "-----------------------+\\n 1 row in set (0.02 sec)\\n ' SQL SECURITY INVOKER DETERMINISTIC NO SQL BEGIN RETURN LEFT(SU" "BSTRING_INDEX(REPLACE(SUBSTRING_INDEX(REPLACE(path, '\\\\', '/'), '/', -1), '@0024', '$'), '.', 1), 64); END;\n", "DROP FUNCTION IF EXISTS format_bytes;\n", "CREATE DEFINER='mysql.sys'@'localhost' FUNCTION format_bytes ( bytes TEXT ) RETURNS TEXT COMMENT '\\n Description\\n \\n Ta" "kes a raw bytes value, and converts it to a human readable format.\\n \\n Parameters\\n \\n bytes (TEXT):\\n A raw bytes v" "alue.\\n \\n Returns\\n \\n TEXT\\n \\n Example\\n \\n mysql> SELECT sys.format_bytes(2348723492723746) AS size;\\n +---------" "-+\\n | size |\\n +----------+\\n | 2.09 PiB |\\n +----------+\\n 1 row in set (0.00 sec)\\n \\n mysql> SELECT sys.forma" "t_bytes(2348723492723) AS size;\\n +----------+\\n | size |\\n +----------+\\n | 2.14 TiB |\\n +----------+\\n 1 row in" " set (0.00 sec)\\n \\n mysql> SELECT sys.format_bytes(23487234) AS size;\\n +-----------+\\n | size |\\n +-----------" "+\\n | 22.40 MiB |\\n +-----------+\\n 1 row in set (0.00 sec)\\n ' SQL SECURITY INVOKER DETERMINISTIC NO SQL BEGIN IF by" "tes IS NULL THEN RETURN NULL; ELSEIF bytes >= 1125899906842624 THEN RETURN CONCAT(ROUND(bytes / 1125899906842624, 2)," " ' PiB'); ELSEIF bytes >= 1099511627776 THEN RETURN CONCAT(ROUND(bytes / 1099511627776, 2), ' TiB'); ELSEIF bytes >= " "1073741824 THEN RETURN CONCAT(ROUND(bytes / 1073741824, 2), ' GiB'); ELSEIF bytes >= 1048576 THEN RETURN CONCAT(ROUND" "(bytes / 1048576, 2), ' MiB'); ELSEIF bytes >= 1024 THEN RETURN CONCAT(ROUND(bytes / 1024, 2), ' KiB'); ELSE RETURN C" "ONCAT(ROUND(bytes, 0), ' bytes'); END IF; END;\n", "DROP FUNCTION IF EXISTS format_path;\n", "CREATE DEFINER='mysql.sys'@'localhost' FUNCTION format_path ( in_path VARCHAR(512) ) RETURNS VARCHAR(512) CHARSET UTF8 C" "OMMENT '\\n Description\\n \\n Takes a raw path value, and strips out the datadir or tmpdir\\n replacing with @@datadir a" "nd @@tmpdir respectively.\\n \\n Also normalizes the paths across operating systems, so backslashes\\n on Windows are co" "nverted to forward slashes\\n \\n Parameters\\n \\n path (VARCHAR(512)):\\n The raw file path value to format.\\n \\n Return" "s\\n \\n VARCHAR(512) CHARSET UTF8\\n \\n Example\\n \\n mysql> select @@datadir;\\n +--------------------------------------" "---------+\\n | @@datadir |\\n +-----------------------------------------------+\\n " "| /Users/mark/sandboxes/SmallTree/AMaster/data/ |\\n +-----------------------------------------------+\\n 1 row in set " "(0.06 sec)\\n \\n mysql> select format_path(\\'/Users/mark/sandboxes/SmallTree/AMaster/data/mysql/proc.MYD\\') AS path;\\n" " +--------------------------+\\n | path |\\n +--------------------------+\\n | @@datadir/mysql/proc." "MYD |\\n +--------------------------+\\n 1 row in set (0.03 sec)\\n ' SQL SECURITY INVOKER DETERMINISTIC NO SQL BEGIN DE" "CLARE v_path VARCHAR(512); DECLARE v_undo_dir VARCHAR(1024); DECLARE path_separator CHAR(1) DEFAULT '/'; IF @@globa" "l.version_compile_os LIKE 'win%' THEN SET path_separator = '\\\\'; END IF; IF in_path LIKE '/private/%' THEN SET v_pat" "h = REPLACE(in_path, '/private', ''); ELSE SET v_path = in_path; END IF; SET v_undo_dir = IFNULL((SELECT VARIABLE_VA" "LUE FROM performance_schema.global_variables WHERE VARIABLE_NAME = 'innodb_undo_directory'), ''); IF v_path IS NULL " "THEN RETURN NULL; ELSEIF v_path LIKE CONCAT(@@global.datadir, IF(SUBSTRING(@@global.datadir, -1) = path_separator, '%" "', CONCAT(path_separator, '%'))) ESCAPE '|' THEN SET v_path = REPLACE(v_path, @@global.datadir, CONCAT('@@datadir', I" "F(SUBSTRING(@@global.datadir, -1) = path_separator, path_separator, ''))); ELSEIF v_path LIKE CONCAT(@@global.tmpdir," " IF(SUBSTRING(@@global.tmpdir, -1) = path_separator, '%', CONCAT(path_separator, '%'))) ESCAPE '|' THEN SET v_path = " "REPLACE(v_path, @@global.tmpdir, CONCAT('@@tmpdir', IF(SUBSTRING(@@global.tmpdir, -1) = path_separator, path_separato" "r, ''))); ELSEIF v_path LIKE CONCAT(@@global.slave_load_tmpdir, IF(SUBSTRING(@@global.slave_load_tmpdir, -1) = path_s" "eparator, '%', CONCAT(path_separator, '%'))) ESCAPE '|' THEN SET v_path = REPLACE(v_path, @@global.slave_load_tmpdir," " CONCAT('@@slave_load_tmpdir', IF(SUBSTRING(@@global.slave_load_tmpdir, -1) = path_separator, path_separator, ''))); " "ELSEIF v_path LIKE CONCAT(@@global.innodb_data_home_dir, IF(SUBSTRING(@@global.innodb_data_home_dir, -1) = path_separ" "ator, '%', CONCAT(path_separator, '%'))) ESCAPE '|' THEN SET v_path = REPLACE(v_path, @@global.innodb_data_home_dir, " "CONCAT('@@innodb_data_home_dir', IF(SUBSTRING(@@global.innodb_data_home_dir, -1) = path_separator, path_separator, ''" "))); ELSEIF v_path LIKE CONCAT(@@global.innodb_log_group_home_dir, IF(SUBSTRING(@@global.innodb_log_group_home_dir, -" "1) = path_separator, '%', CONCAT(path_separator, '%'))) ESCAPE '|' THEN SET v_path = REPLACE(v_path, @@global.innodb_" "log_group_home_dir, CONCAT('@@innodb_log_group_home_dir', IF(SUBSTRING(@@global.innodb_log_group_home_dir, -1) = path" "_separator, path_separator, ''))); ELSEIF v_path LIKE CONCAT(v_undo_dir, IF(SUBSTRING(v_undo_dir, -1) = path_separato" "r, '%', CONCAT(path_separator, '%'))) ESCAPE '|' THEN SET v_path = REPLACE(v_path, v_undo_dir, CONCAT('@@innodb_undo_" "directory', IF(SUBSTRING(v_undo_dir, -1) = path_separator, path_separator, ''))); ELSEIF v_path LIKE CONCAT(@@global." "basedir, IF(SUBSTRING(@@global.basedir, -1) = path_separator, '%', CONCAT(path_separator, '%'))) ESCAPE '|' THEN SET " "v_path = REPLACE(v_path, @@global.basedir, CONCAT('@@basedir', IF(SUBSTRING(@@global.basedir, -1) = path_separator, p" "ath_separator, ''))); END IF; RETURN v_path; END;\n", "DROP FUNCTION IF EXISTS format_statement;\n", "CREATE DEFINER='mysql.sys'@'localhost' FUNCTION format_statement ( statement LONGTEXT ) RETURNS LONGTEXT COMMENT '\\n Des" "cription\\n \\n Formats a normalized statement, truncating it if it is > 64 characters long by default.\\n \\n To configu" "re the length to truncate the statement to by default, update the `statement_truncate_len`\\n variable with `sys_confi" "g` table to a different value. Alternatively, to change it just for just \\n your particular session, use `SET @sys.st" "atement_truncate_len := <some new value>`.\\n \\n Useful for printing statement related data from Performance Schema fr" "om \\n the command line.\\n \\n Parameters\\n \\n statement (LONGTEXT): \\n The statement to format.\\n \\n Returns\\n \\n LONG" "TEXT\\n \\n Example\\n \\n mysql> SELECT sys.format_statement(digest_text)\\n -> FROM performance_schema.events_statemen" "ts_summary_by_digest\\n -> ORDER by sum_timer_wait DESC limit 5;\\n +-------------------------------------------------" "------------------+\\n | sys.format_statement(digest_text) |\\n +----------------------" "---------------------------------------------+\\n | CREATE SQL SECURITY INVOKER VI ... KE ? AND `variable_value` > ? " "|\\n | CREATE SQL SECURITY INVOKER VI ... ait` IS NOT NULL , `esc` . ... |\\n | CREATE SQL SECURITY INVOKER VI ... ait`" " IS NOT NULL , `sys` . ... |\\n | CREATE SQL SECURITY INVOKER VI ... , `compressed_size` ) ) DESC |\\n | CREATE SQL S" "ECURITY INVOKER VI ... LIKE ? ORDER BY `timer_start` |\\n +----------------------------------------------------------" "---------+\\n 5 rows in set (0.00 sec)\\n ' SQL SECURITY INVOKER DETERMINISTIC NO SQL BEGIN IF @sys.statement_truncate_" "len IS NULL THEN SET @sys.statement_truncate_len = sys_get_config('statement_truncate_len', 64); END IF; IF CHAR_LEN" "GTH(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;\n", "DROP FUNCTION IF EXISTS format_time;\n", "CREATE DEFINER='mysql.sys'@'localhost' FUNCTION format_time ( picoseconds TEXT ) RETURNS TEXT CHARSET UTF8 COMMENT '\\n D" "escription\\n \\n Takes a raw picoseconds value, and converts it to a human readable form.\\n \\n Picoseconds are the pre" "cision that all latency values are printed in\\n within Performance Schema, however are not user friendly when wanting" "\\n to scan output from the command line.\\n \\n Parameters\\n \\n picoseconds (TEXT):\\n The raw picoseconds value to conv" "ert.\\n \\n Returns\\n \\n TEXT\\n \\n Example\\n \\n mysql> select format_time(342342342342345);\\n +------------------------" "------+\\n | format_time(342342342342345) |\\n +------------------------------+\\n | 00:05:42 |\\n +-" "-----------------------------+\\n 1 row in set (0.00 sec)\\n \\n mysql> select format_time(342342342);\\n +--------------" "----------+\\n | format_time(342342342) |\\n +------------------------+\\n | 342.34 us |\\n +---------------" "---------+\\n 1 row in set (0.00 sec)\\n \\n mysql> select format_time(34234);\\n +--------------------+\\n | format_time(" "34234) |\\n +--------------------+\\n | 34.23 ns |\\n +--------------------+\\n 1 row in set (0.00 sec)\\n ' SQL" " SECURITY INVOKER DETERMINISTIC NO SQL BEGIN IF picoseconds IS NULL THEN RETURN NULL; ELSEIF picoseconds >= 604800000" "000000000 THEN RETURN CONCAT(ROUND(picoseconds / 604800000000000000, 2), ' w'); ELSEIF picoseconds >= 864000000000000" "00 THEN RETURN CONCAT(ROUND(picoseconds / 86400000000000000, 2), ' d'); ELSEIF picoseconds >= 3600000000000000 THEN R" "ETURN CONCAT(ROUND(picoseconds / 3600000000000000, 2), ' h'); ELSEIF picoseconds >= 60000000000000 THEN RETURN CONCAT" "(ROUND(picoseconds / 60000000000000, 2), ' m'); ELSEIF picoseconds >= 1000000000000 THEN RETURN CONCAT(ROUND(picoseco" "nds / 1000000000000, 2), ' s'); ELSEIF picoseconds >= 1000000000 THEN RETURN CONCAT(ROUND(picoseconds / 1000000000, 2" "), ' ms'); ELSEIF picoseconds >= 1000000 THEN RETURN CONCAT(ROUND(picoseconds / 1000000, 2), ' us'); ELSEIF picosecon" "ds >= 1000 THEN RETURN CONCAT(ROUND(picoseconds / 1000, 2), ' ns'); ELSE RETURN CONCAT(picoseconds, ' ps'); END IF; E" "ND;\n", "DROP FUNCTION IF EXISTS list_add;\n", "CREATE DEFINER='mysql.sys'@'localhost' FUNCTION list_add ( in_list TEXT, in_add_value TEXT ) RETURNS TEXT COMMENT '\\n De" "scription\\n \\n Takes a list, and a value to add to the list, and returns the resulting list.\\n \\n Useful for altering" " certain session variables, like sql_mode or optimizer_switch for instance.\\n \\n Parameters\\n \\n in_list (TEXT):\\n Th" "e comma separated list to add a value to\\n \\n in_add_value (TEXT):\\n The value to add to the input list\\n \\n Returns\\" "n \\n TEXT\\n \\n Example\\n \\n mysql> select @@sql_mode;\\n +------------------------------------------------------------" "-----------------------+\\n | @@sql_mode |\\n +-" "----------------------------------------------------------------------------------+\\n | ONLY_FULL_GROUP_BY,STRICT_TRA" "NS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |\\n +-----------------------------------------------------------" "------------------------+\\n 1 row in set (0.00 sec)\\n \\n mysql> set sql_mode = sys.list_add(@@sql_mode, ''ANSI_QUOTES" "'');\\n Query OK, 0 rows affected (0.06 sec)\\n \\n mysql> select @@sql_mode;\\n +---------------------------------------" "--------------------------------------------------------+\\n | @@sql_mode " " |\\n +-------------------------------------------------------------------------" "----------------------+\\n | ANSI_QUOTES,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITU" "TION |\\n +-----------------------------------------------------------------------------------------------+\\n 1 row in" " set (0.00 sec)\\n \\n ' SQL SECURITY INVOKER DETERMINISTIC CONTAINS SQL BEGIN IF (in_add_value IS NULL) THEN SIGNAL S" "QLSTATE '02200' SET MESSAGE_TEXT = 'Function sys.list_add: in_add_value input variable should not be NULL', MYSQL_ERR" "NO = 1138; END IF; IF (in_list IS NULL OR LENGTH(in_list) = 0) THEN RETURN in_add_value; END IF; RETURN (SELECT CON" "CAT(TRIM(BOTH ',' FROM TRIM(in_list)), ',', in_add_value)); END;\n", "DROP FUNCTION IF EXISTS list_drop;\n", "CREATE DEFINER='mysql.sys'@'localhost' FUNCTION list_drop ( in_list TEXT, in_drop_value TEXT ) RETURNS TEXT COMMENT '\\n " "Description\\n \\n Takes a list, and a value to attempt to remove from the list, and returns the resulting list.\\n \\n U" "seful for altering certain session variables, like sql_mode or optimizer_switch for instance.\\n \\n Parameters\\n \\n in" "_list (TEXT):\\n The comma separated list to drop a value from\\n \\n in_drop_value (TEXT):\\n The value to drop from the" " input list\\n \\n Returns\\n \\n TEXT\\n \\n Example\\n \\n mysql> select @@sql_mode;\\n +-----------------------------------" "------------------------------------------------------------+\\n | @@sql_mode " " |\\n +---------------------------------------------------------------------" "--------------------------+\\n | ANSI_QUOTES,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBS" "TITUTION |\\n +-----------------------------------------------------------------------------------------------+\\n 1 ro" "w in set (0.00 sec)\\n \\n mysql> set sql_mode = sys.list_drop(@@sql_mode, ''ONLY_FULL_GROUP_BY'');\\n Query OK, 0 rows " "affected (0.03 sec)\\n \\n mysql> select @@sql_mode;\\n +---------------------------------------------------------------" "-------------+\\n | @@sql_mode |\\n +------------------" "----------------------------------------------------------+\\n | ANSI_QUOTES,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,N" "O_ENGINE_SUBSTITUTION |\\n +----------------------------------------------------------------------------+\\n 1 row in s" "et (0.00 sec)\\n \\n ' SQL SECURITY INVOKER DETERMINISTIC CONTAINS SQL BEGIN IF (in_drop_value IS NULL) THEN SIGNAL SQ" "LSTATE '02200' SET MESSAGE_TEXT = 'Function sys.list_drop: in_drop_value input variable should not be NULL', MYSQL_ER" "RNO = 1138; END IF; IF (in_list IS NULL OR LENGTH(in_list) = 0) THEN RETURN in_list; END IF; RETURN (SELECT TRIM(BO" "TH ',' FROM REPLACE(REPLACE(CONCAT(',', in_list), CONCAT(',', in_drop_value), ''), CONCAT(', ', in_drop_value), '')))" "; END;\n", "DROP FUNCTION IF EXISTS ps_is_account_enabled;\n", "CREATE DEFINER='mysql.sys'@'localhost' FUNCTION ps_is_account_enabled ( in_host VARCHAR(60), in_user VARCHAR(32) ) RET" "URNS ENUM('YES', 'NO') COMMENT '\\n Description\\n \\n Determines whether instrumentation of an account is enabled \\n wi" "thin Performance Schema.\\n \\n Parameters\\n \\n in_host VARCHAR(60): \\n The hostname of the account to check.\\n in_user" " VARCHAR(32):\\n The username of the account to check.\\n \\n Returns\\n \\n ENUM(\\'YES\\', \\'NO\\', \\'PARTIAL\\')\\n \\n Examp" "le\\n \\n mysql> SELECT sys.ps_is_account_enabled(\\'localhost\\', \\'root\\');\\n +----------------------------------------" "--------+\\n | sys.ps_is_account_enabled(\\'localhost\\', \\'root\\') |\\n +-----------------------------------------------" "-+\\n | YES |\\n +------------------------------------------------+\\n 1 row " "in set (0.01 sec)\\n ' SQL SECURITY INVOKER DETERMINISTIC READS SQL DATA BEGIN RETURN IF(EXISTS(SELECT 1 FROM perfor" "mance_schema.setup_actors WHERE (`HOST` = '%' OR in_host LIKE `HOST`) AND (`USER` = '%' OR `USER` = in_user) AND (`EN" "ABLED` = 'YES') ), 'YES', 'NO' ); END;\n", "DROP FUNCTION IF EXISTS ps_is_consumer_enabled;\n", "CREATE DEFINER='mysql.sys'@'localhost' FUNCTION ps_is_consumer_enabled ( in_consumer varchar(64) ) RETURNS enum('YES', '" "NO') COMMENT '\\n Description\\n \\n Determines whether a consumer is enabled (taking the consumer hierarchy into consid" "eration)\\n within the Performance Schema.\\n \\n An exception with errno 3047 is thrown if an unknown consumer name is " "passed to the function.\\n A consumer name of NULL returns NULL.\\n \\n Parameters\\n \\n in_consumer VARCHAR(64): \\n The " "name of the consumer to check.\\n \\n Returns\\n \\n ENUM(\\'YES\\', \\'NO\\')\\n \\n Example\\n \\n mysql> SELECT sys.ps_is_cons" "umer_enabled(\\'events_stages_history\\');\\n +-----------------------------------------------------+\\n | sys.ps_is_cons" "umer_enabled(\\'events_stages_history\\') |\\n +-----------------------------------------------------+\\n | NO " " |\\n +-----------------------------------------------------+\\n 1 row in set (0." "00 sec)\\n ' SQL SECURITY INVOKER DETERMINISTIC READS SQL DATA BEGIN DECLARE v_is_enabled ENUM('YES', 'NO') DEFAULT " "NULL; DECLARE v_error_msg VARCHAR(128); IF (in_consumer IS NULL) THEN RETURN NULL; END IF; SET v_is_enabled = ( SEL" "ECT (CASE WHEN c.NAME = 'global_instrumentation' THEN c.ENABLED WHEN c.NAME = 'thread_instrumentation' THEN IF(cg.ENA" "BLED = 'YES' AND c.ENABLED = 'YES', 'YES', 'NO') WHEN c.NAME LIKE '%\\_digest' THEN IF(cg.ENABLED = 'YES' AN" "D 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 performanc" "e_schema.setup_consumers cg INNER JOIN performance_schema.setup_consumers ct WHERE cg.NAME = 'global_instrument" "ation' AND ct.NAME = 'thread_instrumentation' AND c.NAME = in_consumer ); IF (v_is_enabled IS NOT NULL) THEN RE" "TURN v_is_enabled; ELSE SET v_error_msg = CONCAT('Invalid argument error: ', in_consumer, ' in function sys.ps_is_con" "sumer_enabled.'); SIGNAL SQLSTATE 'HY000' SET MESSAGE_TEXT = v_error_msg, MYSQL_ERRNO = 3047; END IF; END;\n", "DROP FUNCTION IF EXISTS ps_is_instrument_default_enabled;\n", "CREATE DEFINER='mysql.sys'@'localhost' FUNCTION ps_is_instrument_default_enabled ( in_instrument VARCHAR(128) ) RETURNS" " ENUM('YES', 'NO') COMMENT '\\n Description\\n \\n Returns whether an instrument is enabled by default in this version o" "f MySQL.\\n \\n Parameters\\n \\n in_instrument VARCHAR(128): \\n The instrument to check.\\n \\n Returns\\n \\n ENUM(\\'YES\\'," " \\'NO\\')\\n \\n Example\\n \\n mysql> SELECT sys.ps_is_instrument_default_enabled(\\'statement/sql/select\\');\\n +---------" "-----------------------------------------------------+\\n | sys.ps_is_instrument_default_enabled(\\'statement/sql/selec" "t\\') |\\n +--------------------------------------------------------------+\\n | YES " " |\\n +--------------------------------------------------------------+\\n 1 row in set (0.00 sec)\\" "n ' SQL SECURITY INVOKER DETERMINISTIC READS SQL DATA BEGIN DECLARE v_enabled ENUM('YES', 'NO'); SET v_enabled = I" "F(in_instrument LIKE 'wait/io/file/%' OR in_instrument LIKE 'wait/io/table/%' OR in_instrument LIKE 'statement/%' OR " "in_instrument LIKE 'memory/performance_schema/%' OR in_instrument IN ('wait/lock/table/sql/handler', 'idle') /*!50707" " OR in_instrument LIKE 'stage/innodb/%' OR in_instrument = 'stage/sql/copy to tmp table' */ , 'YES', 'NO' ); RETURN " "v_enabled; END;\n", "DROP FUNCTION IF EXISTS ps_is_instrument_default_timed;\n", "CREATE DEFINER='mysql.sys'@'localhost' FUNCTION ps_is_instrument_default_timed ( in_instrument VARCHAR(128) ) RETURNS E" "NUM('YES', 'NO') COMMENT '\\n Description\\n \\n Returns whether an instrument is timed by default in this version of My" "SQL.\\n \\n Parameters\\n \\n in_instrument VARCHAR(128): \\n The instrument to check.\\n \\n Returns\\n \\n ENUM(\\'YES\\', \\'N" "O\\')\\n \\n Example\\n \\n mysql> SELECT sys.ps_is_instrument_default_timed(\\'statement/sql/select\\');\\n +---------------" "---------------------------------------------+\\n | sys.ps_is_instrument_default_timed(\\'statement/sql/select\\') |\\n +" "------------------------------------------------------------+\\n | YES " " |\\n +------------------------------------------------------------+\\n 1 row in set (0.00 sec)\\n ' SQL SECURITY" " INVOKER DETERMINISTIC READS SQL DATA BEGIN DECLARE v_timed ENUM('YES', 'NO'); SET v_timed = IF(in_instrument LIKE" " 'wait/io/file/%' OR in_instrument LIKE 'wait/io/table/%' OR in_instrument LIKE 'statement/%' OR in_instrument IN ('w" "ait/lock/table/sql/handler', 'idle') /*!50707 OR in_instrument LIKE 'stage/innodb/%' OR in_instrument = 'stage/sql/co" "py to tmp table' */ , 'YES', 'NO' ); RETURN v_timed; END;\n", "DROP FUNCTION IF EXISTS ps_is_thread_instrumented;\n", "CREATE DEFINER='mysql.sys'@'localhost' FUNCTION ps_is_thread_instrumented ( in_connection_id BIGINT UNSIGNED ) RETURNS E" "NUM('YES', 'NO', 'UNKNOWN') COMMENT '\\n Description\\n \\n Checks whether the provided connection id is instrumented wi" "thin Performance Schema.\\n \\n Parameters\\n \\n in_connection_id (BIGINT UNSIGNED):\\n The id of the connection to check" ".\\n \\n Returns\\n \\n ENUM(\\'YES\\', \\'NO\\', \\'UNKNOWN\\')\\n \\n Example\\n \\n mysql> SELECT sys.ps_is_thread_instrumented(" "CONNECTION_ID());\\n +------------------------------------------------+\\n | sys.ps_is_thread_instrumented(CONNECTION_I" "D()) |\\n +------------------------------------------------+\\n | YES |\\n +-" "-----------------------------------------------+\\n ' SQL SECURITY INVOKER NOT DETERMINISTIC READS SQL DATA BEGIN DEC" "LARE v_enabled ENUM('YES', 'NO', 'UNKNOWN'); IF (in_connection_id IS NULL) THEN RETURN NULL; END IF; SELECT INSTRUM" "ENTED INTO v_enabled FROM performance_schema.threads WHERE PROCESSLIST_ID = in_connection_id; IF (v_enabled IS NULL" ") THEN RETURN 'UNKNOWN'; ELSE RETURN v_enabled; END IF; END;\n", "DROP FUNCTION IF EXISTS ps_thread_id;\n", "CREATE DEFINER='mysql.sys'@'localhost' FUNCTION ps_thread_id ( in_connection_id BIGINT UNSIGNED ) RETURNS BIGINT UNSIGNE" "D COMMENT '\\n Description\\n \\n Return the Performance Schema THREAD_ID for the specified connection ID.\\n \\n Paramete" "rs\\n \\n in_connection_id (BIGINT UNSIGNED):\\n The id of the connection to return the thread id for. If NULL, the curr" "ent\\n connection thread id is returned.\\n \\n Example\\n \\n mysql> SELECT sys.ps_thread_id(79);\\n +--------------------" "--+\\n | sys.ps_thread_id(79) |\\n +----------------------+\\n | 98 |\\n +----------------------+\\n 1 r" "ow in set (0.00 sec)\\n \\n mysql> SELECT sys.ps_thread_id(CONNECTION_ID());\\n +-----------------------------------+\\n " "| sys.ps_thread_id(CONNECTION_ID()) |\\n +-----------------------------------+\\n | 98 |" "\\n +-----------------------------------+\\n 1 row in set (0.00 sec)\\n ' SQL SECURITY INVOKER NOT DETERMINISTIC READS " "SQL DATA BEGIN RETURN (SELECT THREAD_ID FROM `performance_schema`.`threads` WHERE PROCESSLIST_ID = IFNULL(in_connecti" "on_id, CONNECTION_ID()) ); END;\n", "DROP FUNCTION IF EXISTS ps_thread_account;\n", "CREATE DEFINER='mysql.sys'@'localhost' FUNCTION ps_thread_account ( in_thread_id BIGINT UNSIGNED ) RETURNS TEXT COMMENT " "'\\n Description\\n \\n Return the user@host account for the given Performance Schema thread id.\\n \\n Parameters\\n \\n in" "_thread_id (BIGINT UNSIGNED):\\n The id of the thread to return the account for.\\n \\n Example\\n \\n mysql> select threa" "d_id, processlist_user, processlist_host from performance_schema.threads where type = ''foreground'';\\n +-----------+" "------------------+------------------+\\n | thread_id | processlist_user | processlist_host |\\n +-----------+---------" "---------+------------------+\\n | 23 | NULL | NULL |\\n | 30 | root " "| localhost |\\n | 31 | msandbox | localhost |\\n | 32 | msandbox | localho" "st |\\n +-----------+------------------+------------------+\\n 4 rows in set (0.00 sec)\\n \\n mysql> select sys.p" "s_thread_account(31);\\n +---------------------------+\\n | sys.ps_thread_account(31) |\\n +---------------------------+" "\\n | msandbox@localhost |\\n +---------------------------+\\n 1 row in set (0.00 sec)\\n ' SQL SECURITY INVOKER " "NOT DETERMINISTIC READS SQL DATA BEGIN RETURN (SELECT IF( type = 'FOREGROUND', CONCAT(processlist_user, '@', processl" "ist_host), type ) AS account FROM `performance_schema`.`threads` WHERE thread_id = in_thread_id); END;\n", "DROP FUNCTION IF EXISTS ps_thread_stack;\n", "CREATE DEFINER='mysql.sys'@'localhost' FUNCTION ps_thread_stack ( thd_id BIGINT UNSIGNED, debug BOOLEAN ) RETURNS LONGTE" "XT CHARSET latin1 COMMENT '\\n Description\\n \\n Outputs a JSON formatted stack of all statements, stages and events\\n " "within Performance Schema for the specified thread.\\n \\n Parameters\\n \\n thd_id (BIGINT UNSIGNED):\\n The id of the th" "read to trace. This should match the thread_id\\n column from the performance_schema.threads table.\\n in_verbose (BOOL" "EAN):\\n Include file:lineno information in the events.\\n \\n Example\\n \\n (line separation added for output)\\n \\n mysq" "l> SELECT sys.ps_thread_stack(37, FALSE) AS thread_stack\\\\G\\n *************************** 1. row ********************" "*******\\n thread_stack: {\"rankdir\": \"LR\",\"nodesep\": \"0.10\",\"stack_created\": \"2014-02-19 13:39:03\",\\n \"my" "sql_version\": \"5.7.3-m13\",\"mysql_user\": \"root@localhost\",\"events\": \\n [{\"nesting_event_id\": \"0\", \"event" "_id\": \"10\", \"timer_wait\": 256.35, \"event_info\": \\n \"sql/select\", \"wait_info\": \"select @@version_comment l" "imit 1\\\\nerrors: 0\\\\nwarnings: 0\\\\nlock time:\\n ...\\n ' SQL SECURITY INVOKER NOT DETERMINISTIC READS SQL DATA BEGIN " "DECLARE json_objects LONGTEXT; /*!50602 UPDATE performance_schema.threads SET instrumented = 'NO' WHERE processlist_" "id = CONNECTION_ID(); */ SET SESSION group_concat_max_len=@@global.max_allowed_packet; SELECT GROUP_CONCAT(CONCAT( " "'{' , CONCAT_WS( ', ' , CONCAT('\"nesting_event_id\": \"', IF(nesting_event_id IS NULL, '0', nesting_event_id), '\"')" " , CONCAT('\"event_id\": \"', event_id, '\"') , CONCAT( '\"timer_wait\": ', ROUND(timer_wait/1000000, 2)) , CONCAT(" " '\"event_info\": \"' , CASE WHEN event_name NOT LIKE 'wait/io%' THEN REPLACE(SUBSTRING_INDEX(event_name, '/', -2), '" "\\\\', '\\\\\\\\') WHEN event_name NOT LIKE 'wait/io/file%' OR event_name NOT LIKE 'wait/io/socket%' THEN REPLACE(SUBSTRING" "_INDEX(event_name, '/', -4), '\\\\', '\\\\\\\\') ELSE event_name END , '\"' ) , CONCAT( '\"wait_info\": \"', IFNULL(wait_in" "fo, ''), '\"') , CONCAT( '\"source\": \"', IF(true AND event_name LIKE 'wait%', IFNULL(wait_info, ''), ''), '\"') , C" "ASE WHEN event_name LIKE 'wait/io/file%' THEN '\"event_type\": \"io/file\"' WHEN event_name LIKE 'wait/io/table" "%' THEN '\"event_type\": \"io/table\"' WHEN event_name LIKE 'wait/io/socket%' THEN '\"event_type\": \"io/socke" "t\"' WHEN event_name LIKE 'wait/synch/mutex%' THEN '\"event_type\": \"synch/mutex\"' WHEN event_name LIKE 'wait/sync" "h/cond%' THEN '\"event_type\": \"synch/cond\"' WHEN event_name LIKE 'wait/synch/rwlock%' THEN '\"event_type\": \"sy" "nch/rwlock\"' WHEN event_name LIKE 'wait/lock%' THEN '\"event_type\": \"lock\"' WHEN event_name LIKE 'stateme" "nt/%' THEN '\"event_type\": \"stmt\"' WHEN event_name LIKE 'stage/%' THEN '\"event_type\": \"stage\"" "' WHEN event_name LIKE '%idle%' THEN '\"event_type\": \"idle\"' ELSE '' END ) , '}' )" " ORDER BY event_id ASC SEPARATOR ',') event INTO json_objects FROM ( /*!50600 (SELECT thread_id, event_id, event_name" ", timer_wait, timer_start, nesting_event_id, CONCAT(sql_text, '\\\\n', 'errors: ', errors, '\\\\n', 'warnings: ', warnin" "gs, '\\\\n', 'lock time: ', ROUND(lock_time/1000000, 2),'us\\\\n', 'rows affected: ', rows_affected, '\\\\n', 'rows sent: '" ", rows_sent, '\\\\n', 'rows examined: ', rows_examined, '\\\\n', 'tmp tables: ', created_tmp_tables, '\\\\n', 'tmp disk tab" "les: ', created_tmp_disk_tables, '\\\\n', 'select scan: ', select_scan, '\\\\n', 'select full join: ', select_full_join, " "'\\\\n', 'select full range join: ', select_full_range_join, '\\\\n', 'select range: ', select_range, '\\\\n', 'select rang" "e check: ', select_range_check, '\\\\n', 'sort merge passes: ', sort_merge_passes, '\\\\n', 'sort rows: ', sort_rows, '\\" "\\n', 'sort range: ', sort_range, '\\\\n', 'sort scan: ', sort_scan, '\\\\n', 'no index used: ', IF(no_index_used, 'TRUE'," " 'FALSE'), '\\\\n', 'no good index used: ', IF(no_good_index_used, 'TRUE', 'FALSE'), '\\\\n' ) AS wait_info FROM performa" "nce_schema.events_statements_history_long WHERE thread_id = thd_id) UNION (SELECT thread_id, event_id, event_name, t" "imer_wait, timer_start, nesting_event_id, null AS wait_info FROM performance_schema.events_stages_history_long WHERE " "thread_id = thd_id) UNION */ (SELECT thread_id, event_id, CONCAT(event_name , IF(event_name NOT LIKE 'wait/synch/m" "utex%', IFNULL(CONCAT(' - ', operation), ''), ''), IF(number_of_bytes IS NOT NULL, CONCAT(' ', number_of_bytes, ' by" "tes'), ''), IF(event_name LIKE 'wait/io/file%', '\\\\n', ''), IF(object_schema IS NOT NULL, CONCAT('\\\\nObject: ', objec" "t_schema, '.'), ''), IF(object_name IS NOT NULL, IF (event_name LIKE 'wait/io/socket%', CONCAT(IF (object_name LIKE" " ':0%', @@socket, object_name)), object_name), ''), /*!50600 IF(index_name IS NOT NULL, CONCAT(' Index: ', index_name" "), ''),*/'\\\\n' ) AS event_name, timer_wait, timer_start, nesting_event_id, source AS wait_info FROM performance_schem" "a.events_waits_history_long WHERE thread_id = thd_id)) events ORDER BY event_id; RETURN CONCAT('{', CONCAT_WS(','," " '\"rankdir\": \"LR\"', '\"nodesep\": \"0.10\"', CONCAT('\"stack_created\": \"', NOW(), '\"'), CONCAT('\"mysql_versi" "on\": \"', VERSION(), '\"'), CONCAT('\"mysql_user\": \"', CURRENT_USER(), '\"'), CONCAT('\"events\": [', IFNULL(json_" "objects,''), ']') ), '}'); END;\n", "DROP FUNCTION IF EXISTS ps_thread_trx_info;\n", "CREATE DEFINER='mysql.sys'@'localhost' FUNCTION ps_thread_trx_info ( in_thread_id BIGINT UNSIGNED ) RETURNS LONGTEXT COM" "MENT '\\n Description\\n \\n Returns a JSON object with info on the given threads current transaction, \\n and the statem" "ents it has already executed, derived from the\\n performance_schema.events_transactions_current and\\n performance_sch" "ema.events_statements_history tables (so the consumers \\n for these also have to be enabled within Performance Schema" " to get full\\n data in the object).\\n \\n When the output exceeds the default truncation length (65535), a JSON error\\" "n object is returned, such as:\\n \\n { \"error\": \"Trx info truncated: Row 6 was cut by GROUP_CONCAT()\" }\\n \\n Simil" "ar error objects are returned for other warnings/and exceptions raised\\n when calling the function.\\n \\n The max leng" "th of the output of this function can be controlled with the\\n ps_thread_trx_info.max_length variable set via sys_con" "fig, or the\\n @sys.ps_thread_trx_info.max_length user variable, as appropriate.\\n \\n Parameters\\n \\n in_thread_id (BI" "GINT UNSIGNED):\\n The id of the thread to return the transaction info for.\\n \\n Example\\n \\n SELECT sys.ps_thread_trx" "_info(48)\\\\G\\n *************************** 1. row ***************************\\n sys.ps_thread_trx_info(48): [\\n {\\n \"" "time\": \"790.70 us\",\\n \"state\": \"COMMITTED\",\\n \"mode\": \"READ WRITE\",\\n \"autocommitted\": \"NO\",\\n \"gtid\"" ": \"AUTOMATIC\",\\n \"isolation\": \"REPEATABLE READ\",\\n \"statements_executed\": [\\n {\\n \"sql_text\": \"INSERT INTO" " info VALUES (1, \\'foo\\')\",\\n \"time\": \"471.02 us\",\\n \"schema\": \"trx\",\\n \"rows_examined\": 0,\\n \"rows_affec" "ted\": 1,\\n \"rows_sent\": 0,\\n \"tmp_tables\": 0,\\n \"tmp_disk_tables\": 0,\\n \"sort_rows\": 0,\\n \"sort_merge_passe" "s\": 0\\n },\\n {\\n \"sql_text\": \"COMMIT\",\\n \"time\": \"254.42 us\",\\n \"schema\": \"trx\",\\n \"rows_examined\": 0," "\\n \"rows_affected\": 0,\\n \"rows_sent\": 0,\\n \"tmp_tables\": 0,\\n \"tmp_disk_tables\": 0,\\n \"sort_rows\": 0,\\n \"s" "ort_merge_passes\": 0\\n }\\n ]\\n },\\n {\\n \"time\": \"426.20 us\",\\n \"state\": \"COMMITTED\",\\n \"mode\": \"READ WRIT" "E\",\\n \"autocommitted\": \"NO\",\\n \"gtid\": \"AUTOMATIC\",\\n \"isolation\": \"REPEATABLE READ\",\\n \"statements_exe" "cuted\": [\\n {\\n \"sql_text\": \"INSERT INTO info VALUES (2, \\'bar\\')\",\\n \"time\": \"107.33 us\",\\n \"schema\": \"t" "rx\",\\n \"rows_examined\": 0,\\n \"rows_affected\": 1,\\n \"rows_sent\": 0,\\n \"tmp_tables\": 0,\\n \"tmp_disk_tables\":" " 0,\\n \"sort_rows\": 0,\\n \"sort_merge_passes\": 0\\n },\\n {\\n \"sql_text\": \"COMMIT\",\\n \"time\": \"213.23 us\",\\n " "\"schema\": \"trx\",\\n \"rows_examined\": 0,\\n \"rows_affected\": 0,\\n \"rows_sent\": 0,\\n \"tmp_tables\": 0,\\n \"tmp" "_disk_tables\": 0,\\n \"sort_rows\": 0,\\n \"sort_merge_passes\": 0\\n }\\n ]\\n }\\n ]\\n 1 row in set (0.03 sec)\\n ' SQL " "SECURITY INVOKER NOT DETERMINISTIC READS SQL DATA BEGIN DECLARE v_output LONGTEXT DEFAULT '{}'; DECLARE v_msg_text TE" "XT DEFAULT ''; DECLARE v_signal_msg TEXT DEFAULT ''; DECLARE v_mysql_errno INT; DECLARE v_max_output_len BIGINT; DECL" "ARE EXIT HANDLER FOR SQLWARNING, SQLEXCEPTION BEGIN GET DIAGNOSTICS CONDITION 1 v_msg_text = MESSAGE_TEXT, v_mysql_er" "rno = MYSQL_ERRNO; IF v_mysql_errno = 1260 THEN SET v_signal_msg = CONCAT('{ \"error\": \"Trx info truncated: ', v_m" "sg_text, '\" }'); ELSE SET v_signal_msg = CONCAT('{ \"error\": \"', v_msg_text, '\" }'); END IF; RETURN v_signal_msg" "; END; IF (@sys.ps_thread_trx_info.max_length IS NULL) THEN SET @sys.ps_thread_trx_info.max_length = sys.sys_get_con" "fig('ps_thread_trx_info.max_length', 65535); END IF; IF (@sys.ps_thread_trx_info.max_length != @@session.group_conca" "t_max_len) THEN SET @old_group_concat_max_len = @@session.group_concat_max_len; SET v_max_output_len = (@sys.ps_threa" "d_trx_info.max_length - 5); SET SESSION group_concat_max_len = v_max_output_len; END IF; SET v_output = ( SELECT CON" "CAT('[', IFNULL(GROUP_CONCAT(trx_info ORDER BY event_id), ''), '\\n]') AS trx_info FROM (SELECT trxi.thread_id, trxi." "event_id, GROUP_CONCAT( IFNULL( CONCAT('\\n {\\n', ' \"time\": \"', IFNULL(sys.format_time(trxi.timer_wait), ''), '" "\",\\n', ' \"state\": \"', IFNULL(trxi.state, ''), '\",\\n', ' \"mode\": \"', IFNULL(trxi.access_mode, ''), '\",\\" "n', ' \"autocommitted\": \"', IFNULL(trxi.autocommit, ''), '\",\\n', ' \"gtid\": \"', IFNULL(trxi.gtid, ''), '\"" ",\\n', ' \"isolation\": \"', IFNULL(trxi.isolation_level, ''), '\",\\n', ' \"statements_executed\": [', IFNULL(s." "stmts, ''), IF(s.stmts IS NULL, ' ]\\n', '\\n ]\\n'), ' }' ), '') ORDER BY event_id) AS trx_info FROM ( (SELECT t" "hread_id, event_id, timer_wait, state,access_mode, autocommit, gtid, isolation_level FROM performance_schema.events_t" "ransactions_current WHERE thread_id = in_thread_id AND end_event_id IS NULL) UNION (SELECT thread_id, event_id, timer" "_wait, state,access_mode, autocommit, gtid, isolation_level FROM performance_schema.events_transactions_history WHERE" " thread_id = in_thread_id) ) AS trxi LEFT JOIN (SELECT thread_id, nesting_event_id, GROUP_CONCAT( IFNULL( CONCAT('\\n " " {\\n', ' \"sql_text\": \"', IFNULL(sys.format_statement(REPLACE(sql_text, '\\\\', '\\\\\\\\')), ''), '\",\\n', ' " " \"time\": \"', IFNULL(sys.format_time(timer_wait), ''), '\",\\n', ' \"schema\": \"', IFNULL(current_sche" "ma, ''), '\",\\n', ' \"rows_examined\": ', IFNULL(rows_examined, ''), ',\\n', ' \"rows_affected\": ', IFN" "ULL(rows_affected, ''), ',\\n', ' \"rows_sent\": ', IFNULL(rows_sent, ''), ',\\n', ' \"tmp_tables\": ', I" "FNULL(created_tmp_tables, ''), ',\\n', ' \"tmp_disk_tables\": ', IFNULL(created_tmp_disk_tables, ''), ',\\n', ' " " \"sort_rows\": ', IFNULL(sort_rows, ''), ',\\n', ' \"sort_merge_passes\": ', IFNULL(sort_merge_passes, '" "'), '\\n', ' }'), '') ORDER BY event_id) AS stmts FROM performance_schema.events_statements_history WHERE sql_tex" "t IS NOT NULL AND thread_id = in_thread_id GROUP BY thread_id, nesting_event_id ) AS s ON trxi.thread_id = s.thread_" "id AND trxi.event_id = s.nesting_event_id WHERE trxi.thread_id = in_thread_id GROUP BY trxi.thread_id, trxi.event_id" " ) trxs GROUP BY thread_id ); IF (@old_group_concat_max_len IS NOT NULL) THEN SET SESSION group_concat_max_len = @ol" "d_group_concat_max_len; END IF; RETURN v_output; END;\n", "DROP FUNCTION IF EXISTS quote_identifier;\n", "CREATE DEFINER='mysql.sys'@'localhost' FUNCTION quote_identifier(in_identifier TEXT) RETURNS TEXT CHARSET UTF8 COMMENT '" "\\n Description\\n \\n Takes an unquoted identifier (schema name, table name, etc.) and\\n returns the identifier quoted " "with backticks.\\n \\n Parameters\\n \\n in_identifier (TEXT):\\n The identifier to quote.\\n \\n Returns\\n \\n TEXT\\n \\n Exa" "mple\\n \\n mysql> SELECT sys.quote_identifier(''my_identifier'') AS Identifier;\\n +-----------------+\\n | Identifier " " |\\n +-----------------+\\n | `my_identifier` |\\n +-----------------+\\n 1 row in set (0.00 sec)\\n \\n mysql> SELECT " "sys.quote_identifier(''my`idenfier'') AS Identifier;\\n +----------------+\\n | Identifier |\\n +----------------+\\n" " | `my``idenfier` |\\n +----------------+\\n 1 row in set (0.00 sec)\\n ' SQL SECURITY INVOKER DETERMINISTIC NO SQL BEGI" "N RETURN CONCAT('`', REPLACE(in_identifier, '`', '``'), '`'); END;\n", "DROP FUNCTION IF EXISTS sys_get_config;\n", "CREATE DEFINER='mysql.sys'@'localhost' FUNCTION sys_get_config ( in_variable_name VARCHAR(128), in_default_value VARCHAR" "(128) ) RETURNS VARCHAR(128) COMMENT '\\n Description\\n \\n Returns the value for the requested variable using the foll" "owing logic:\\n \\n 1. If the option exists in sys.sys_config return the value from there.\\n 2. Else fall back on the p" "rovided default value.\\n \\n Notes for using sys_get_config():\\n \\n * If the default value argument to sys_get_config(" ") is NULL and case 2. is reached, NULL is returned.\\n It is then expected that the caller is able to handle NULL for " "the given configuration option.\\n * The convention is to name the user variables @sys.<name of variable>. It is <name" " of variable> that\\n is stored in the sys_config table and is what is expected as the argument to sys_get_config().\\n" " * If you want to check whether the configuration option has already been set and if not assign with\\n the return val" "ue of sys_get_config() you can use IFNULL(...) (see example below). However this should\\n not be done inside a loop (" "e.g. for each row in a result set) as for repeated calls where assignment\\n is only needed in the first iteration usi" "ng IFNULL(...) is expected to be significantly slower than\\n using an IF (...) THEN ... END IF; block (see example be" "low).\\n \\n Parameters\\n \\n in_variable_name (VARCHAR(128)):\\n The name of the config option to return the value for.\\" "n \\n in_default_value (VARCHAR(128)):\\n The default value to return if the variable does not exist in sys.sys_config." "\\n \\n Returns\\n \\n VARCHAR(128)\\n \\n Example\\n \\n mysql> SELECT sys.sys_get_config(''statement_truncate_len'', 128) A" "S Value;\\n +-------+\\n | Value |\\n +-------+\\n | 64 |\\n +-------+\\n 1 row in set (0.00 sec)\\n \\n mysql> SET @sys.s" "tatement_truncate_len = IFNULL(@sys.statement_truncate_len, sys.sys_get_config(''statement_truncate_len'', 64));\\n Qu" "ery OK, 0 rows affected (0.00 sec)\\n \\n IF (@sys.statement_truncate_len IS NULL) THEN\\n SET @sys.statement_truncate_l" "en = sys.sys_get_config(''statement_truncate_len'', 64);\\n END IF;\\n ' SQL SECURITY INVOKER DETERMINISTIC READS SQL D" "ATA BEGIN DECLARE v_value VARCHAR(128) DEFAULT NULL; SET v_value = (SELECT value FROM sys.sys_config WHERE variable " "= in_variable_name); IF (v_value IS NULL) THEN SET v_value = in_default_value; END IF; RETURN v_value; END ;\n", "DROP FUNCTION IF EXISTS version_major;\n", "CREATE DEFINER='mysql.sys'@'localhost' FUNCTION version_major () RETURNS TINYINT UNSIGNED COMMENT '\\n Description\\n \\n R" "eturns the major version of MySQL Server.\\n \\n Returns\\n \\n TINYINT UNSIGNED\\n \\n Example\\n \\n mysql> SELECT VERSION(" "), sys.version_major();\\n +--------------------------------------+---------------------+\\n | VERSION() " " | sys.version_major() |\\n +--------------------------------------+---------------------+\\n | 5.7.9-enter" "prise-commercial-advanced | 5 |\\n +--------------------------------------+---------------------+\\n " "1 row in set (0.00 sec)\\n ' SQL SECURITY INVOKER NOT DETERMINISTIC NO SQL BEGIN RETURN SUBSTRING_INDEX(SUBSTRING_INDE" "X(VERSION(), '-', 1), '.', 1); END;\n", "DROP FUNCTION IF EXISTS version_minor;\n", "CREATE DEFINER='mysql.sys'@'localhost' FUNCTION version_minor () RETURNS TINYINT UNSIGNED COMMENT '\\n Description\\n \\n R" "eturns the minor (release series) version of MySQL Server.\\n \\n Returns\\n \\n TINYINT UNSIGNED\\n \\n Example\\n \\n mysql" "> SELECT VERSION(), sys.server_minor();\\n +--------------------------------------+---------------------+\\n | VERSION(" ") | sys.version_minor() |\\n +--------------------------------------+---------------------+" "\\n | 5.7.9-enterprise-commercial-advanced | 7 |\\n +--------------------------------------+---------" "------------+\\n 1 row in set (0.00 sec)\\n ' SQL SECURITY INVOKER NOT DETERMINISTIC NO SQL BEGIN RETURN SUBSTRING_INDE" "X(SUBSTRING_INDEX(SUBSTRING_INDEX(VERSION(), '-', 1), '.', 2), '.', -1); END;\n", "DROP FUNCTION IF EXISTS version_patch;\n", "CREATE DEFINER='mysql.sys'@'localhost' FUNCTION version_patch () RETURNS TINYINT UNSIGNED COMMENT '\\n Description\\n \\n R" "eturns the patch release version of MySQL Server.\\n \\n Returns\\n \\n TINYINT UNSIGNED\\n \\n Example\\n \\n mysql> SELECT " "VERSION(), sys.version_patch();\\n +--------------------------------------+---------------------+\\n | VERSION() " " | sys.version_patch() |\\n +--------------------------------------+---------------------+\\n | 5.7" ".9-enterprise-commercial-advanced | 9 |\\n +--------------------------------------+-----------------" "----+\\n 1 row in set (0.00 sec)\\n ' SQL SECURITY INVOKER NOT DETERMINISTIC NO SQL BEGIN RETURN SUBSTRING_INDEX(SUBSTR" "ING_INDEX(VERSION(), '-', 1), '.', -1); END;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW innodb_buffer_stats" "_by_schema ( object_schema, allocated, data, pages, pages_hashed, pages_old, rows_cached ) AS SELECT IF(LOCATE('.', i" "bp.table_name) = 0, 'InnoDB System', REPLACE(SUBSTRING_INDEX(ibp.table_name, '.', 1), '`', '')) AS object_schema, sys" ".format_bytes(SUM(IF(ibp.compressed_size = 0, 16384, compressed_size))) AS allocated, sys.format_bytes(SUM(ibp.data_s" "ize)) AS data, COUNT(ibp.page_number) AS pages, COUNT(IF(ibp.is_hashed = 'YES', 1, NULL)) AS pages_hashed, COUNT(IF(i" "bp.is_old = 'YES', 1, NULL)) AS pages_old, ROUND(SUM(ibp.number_records)/COUNT(DISTINCT ibp.index_name)) AS rows_cach" "ed FROM information_schema.innodb_buffer_page ibp WHERE table_name IS NOT NULL GROUP BY object_schema ORDER BY SUM(" "IF(ibp.compressed_size = 0, 16384, compressed_size)) DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$innodb_buffer_sta" "ts_by_schema ( object_schema, allocated, data, pages, pages_hashed, pages_old, rows_cached ) AS SELECT IF(LOCATE('.'," " ibp.table_name) = 0, 'InnoDB System', REPLACE(SUBSTRING_INDEX(ibp.table_name, '.', 1), '`', '')) AS object_schema, S" "UM(IF(ibp.compressed_size = 0, 16384, compressed_size)) AS allocated, SUM(ibp.data_size) AS data, COUNT(ibp.page_numb" "er) AS pages, COUNT(IF(ibp.is_hashed = 'YES', 1, NULL)) AS pages_hashed, COUNT(IF(ibp.is_old = 'YES', 1, NULL)) AS pa" "ges_old, ROUND(IFNULL(SUM(ibp.number_records)/NULLIF(COUNT(DISTINCT ibp.index_name), 0), 0)) AS rows_cached FROM inf" "ormation_schema.innodb_buffer_page ibp WHERE table_name IS NOT NULL GROUP BY object_schema ORDER BY SUM(IF(ibp.compr" "essed_size = 0, 16384, compressed_size)) DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW innodb_buffer_stats" "_by_table ( object_schema, object_name, allocated, data, pages, pages_hashed, pages_old, rows_cached ) AS SELECT IF(L" "OCATE('.', ibp.table_name) = 0, 'InnoDB System', REPLACE(SUBSTRING_INDEX(ibp.table_name, '.', 1), '`', '')) AS object" "_schema, REPLACE(SUBSTRING_INDEX(ibp.table_name, '.', -1), '`', '') AS object_name, sys.format_bytes(SUM(IF(ibp.compr" "essed_size = 0, 16384, compressed_size))) AS allocated, sys.format_bytes(SUM(ibp.data_size)) AS data, COUNT(ibp.page_" "number) AS pages, COUNT(IF(ibp.is_hashed = 'YES', 1, NULL)) AS pages_hashed, COUNT(IF(ibp.is_old = 'YES', 1, NULL)) A" "S pages_old, ROUND(SUM(ibp.number_records)/COUNT(DISTINCT ibp.index_name)) AS rows_cached FROM information_schema.in" "nodb_buffer_page ibp WHERE table_name IS NOT NULL GROUP BY object_schema, object_name ORDER BY SUM(IF(ibp.compressed" "_size = 0, 16384, compressed_size)) DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$innodb_buffer_sta" "ts_by_table ( object_schema, object_name, allocated, data, pages, pages_hashed, pages_old, rows_cached ) AS SELECT IF" "(LOCATE('.', ibp.table_name) = 0, 'InnoDB System', REPLACE(SUBSTRING_INDEX(ibp.table_name, '.', 1), '`', '')) AS obje" "ct_schema, REPLACE(SUBSTRING_INDEX(ibp.table_name, '.', -1), '`', '') AS object_name, SUM(IF(ibp.compressed_size = 0," " 16384, compressed_size)) AS allocated, SUM(ibp.data_size) AS data, COUNT(ibp.page_number) AS pages, COUNT(IF(ibp.is_" "hashed = 'YES', 1, NULL)) AS pages_hashed, COUNT(IF(ibp.is_old = 'YES', 1, NULL)) AS pages_old, ROUND(IFNULL(SUM(ibp." "number_records)/NULLIF(COUNT(DISTINCT ibp.index_name), 0), 0)) AS rows_cached FROM information_schema.innodb_buffer_" "page ibp WHERE table_name IS NOT NULL GROUP BY object_schema, object_name ORDER BY SUM(IF(ibp.compressed_size = 0, 1" "6384, compressed_size)) DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW innodb_lock_waits (" " wait_started, wait_age, wait_age_secs, locked_table, locked_index, locked_type, waiting_trx_id, waiting_trx_started," " waiting_trx_age, waiting_trx_rows_locked, waiting_trx_rows_modified, waiting_pid, waiting_query, waiting_lock_id, wa" "iting_lock_mode, blocking_trx_id, blocking_pid, blocking_query, blocking_lock_id, blocking_lock_mode, blocking_trx_st" "arted, blocking_trx_age, blocking_trx_rows_locked, blocking_trx_rows_modified, sql_kill_blocking_query, sql_kill_bloc" "king_connection ) AS SELECT r.trx_wait_started AS wait_started, TIMEDIFF(NOW(), r.trx_wait_started) AS wait_age, TIME" "STAMPDIFF(SECOND, r.trx_wait_started, NOW()) AS wait_age_secs, rl.lock_table AS locked_table, rl.lock_index AS locked" "_index, rl.lock_type AS locked_type, r.trx_id AS waiting_trx_id, r.trx_started as waiting_trx_started, TIMEDIFF(NOW()" ", r.trx_started) AS waiting_trx_age, r.trx_rows_locked AS waiting_trx_rows_locked, r.trx_rows_modified AS waiting_trx" "_rows_modified, r.trx_mysql_thread_id AS waiting_pid, sys.format_statement(r.trx_query) AS waiting_query, rl.lock_id " "AS waiting_lock_id, rl.lock_mode AS waiting_lock_mode, b.trx_id AS blocking_trx_id, b.trx_mysql_thread_id AS blocking" "_pid, sys.format_statement(b.trx_query) AS blocking_query, bl.lock_id AS blocking_lock_id, bl.lock_mode AS blocking_l" "ock_mode, b.trx_started AS blocking_trx_started, TIMEDIFF(NOW(), b.trx_started) AS blocking_trx_age, b.trx_rows_locke" "d AS blocking_trx_rows_locked, b.trx_rows_modified AS blocking_trx_rows_modified, CONCAT('KILL QUERY ', b.trx_mysql_t" "hread_id) AS sql_kill_blocking_query, CONCAT('KILL ', b.trx_mysql_thread_id) AS sql_kill_blocking_connection FROM inf" "ormation_schema.innodb_lock_waits w INNER JOIN information_schema.innodb_trx b ON b.trx_id = w.blocking_trx_id INN" "ER JOIN information_schema.innodb_trx r ON r.trx_id = w.requesting_trx_id INNER JOIN information_schema.innodb_loc" "ks bl ON bl.lock_id = w.blocking_lock_id INNER JOIN information_schema.innodb_locks rl ON rl.lock_id = w.requested_lo" "ck_id ORDER BY r.trx_wait_started;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$innodb_lock_waits" " ( wait_started, wait_age, wait_age_secs, locked_table, locked_index, locked_type, waiting_trx_id, waiting_trx_starte" "d, waiting_trx_age, waiting_trx_rows_locked, waiting_trx_rows_modified, waiting_pid, waiting_query, waiting_lock_id, " "waiting_lock_mode, blocking_trx_id, blocking_pid, blocking_query, blocking_lock_id, blocking_lock_mode, blocking_trx_" "started, blocking_trx_age, blocking_trx_rows_locked, blocking_trx_rows_modified, sql_kill_blocking_query, sql_kill_bl" "ocking_connection ) AS SELECT r.trx_wait_started AS wait_started, TIMEDIFF(NOW(), r.trx_wait_started) AS wait_age, TI" "MESTAMPDIFF(SECOND, r.trx_wait_started, NOW()) AS wait_age_secs, rl.lock_table AS locked_table, rl.lock_index AS lock" "ed_index, rl.lock_type AS locked_type, r.trx_id AS waiting_trx_id, r.trx_started as waiting_trx_started, TIMEDIFF(NOW" "(), r.trx_started) AS waiting_trx_age, r.trx_rows_locked AS waiting_trx_rows_locked, r.trx_rows_modified AS waiting_t" "rx_rows_modified, r.trx_mysql_thread_id AS waiting_pid, r.trx_query AS waiting_query, rl.lock_id AS waiting_lock_id, " "rl.lock_mode AS waiting_lock_mode, b.trx_id AS blocking_trx_id, b.trx_mysql_thread_id AS blocking_pid, b.trx_query AS" " blocking_query, bl.lock_id AS blocking_lock_id, bl.lock_mode AS blocking_lock_mode, b.trx_started AS blocking_trx_st" "arted, TIMEDIFF(NOW(), b.trx_started) AS blocking_trx_age, b.trx_rows_locked AS blocking_trx_rows_locked, b.trx_rows_" "modified AS blocking_trx_rows_modified, CONCAT('KILL QUERY ', b.trx_mysql_thread_id) AS sql_kill_blocking_query, CONC" "AT('KILL ', b.trx_mysql_thread_id) AS sql_kill_blocking_connection FROM information_schema.innodb_lock_waits w INNER " "JOIN information_schema.innodb_trx b ON b.trx_id = w.blocking_trx_id INNER JOIN information_schema.innodb_trx r " " ON r.trx_id = w.requesting_trx_id INNER JOIN information_schema.innodb_locks bl ON bl.lock_id = w.blocking_lock_id I" "NNER JOIN information_schema.innodb_locks rl ON rl.lock_id = w.requested_lock_id ORDER BY r.trx_wait_started;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW schema_object_overv" "iew ( db, object_type, count ) AS SELECT ROUTINE_SCHEMA AS db, ROUTINE_TYPE AS object_type, COUNT(*) AS count FROM in" "formation_schema.routines GROUP BY ROUTINE_SCHEMA, ROUTINE_TYPE UNION SELECT TABLE_SCHEMA, TABLE_TYPE, COUNT(*) FROM" " information_schema.tables GROUP BY TABLE_SCHEMA, TABLE_TYPE UNION SELECT TABLE_SCHEMA, CONCAT('INDEX (', INDEX_TYPE," " ')'), COUNT(*) FROM information_schema.statistics GROUP BY TABLE_SCHEMA, INDEX_TYPE UNION SELECT TRIGGER_SCHEMA, 'TR" "IGGER', COUNT(*) FROM information_schema.triggers GROUP BY TRIGGER_SCHEMA UNION SELECT EVENT_SCHEMA, 'EVENT', COUNT(*" ") FROM information_schema.events GROUP BY EVENT_SCHEMA ORDER BY DB, OBJECT_TYPE;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW schema_auto_increment_co" "lumns ( table_schema, table_name, column_name, data_type, column_type, is_signed, is_unsigned, max_value, auto_increm" "ent, auto_increment_ratio ) AS SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, DATA_TYPE, COLUMN_TYPE, (LOCATE('unsigne" "d', COLUMN_TYPE) = 0) AS is_signed, (LOCATE('unsigned', COLUMN_TYPE) > 0) AS is_unsigned, ( CASE DATA_TYPE WHEN 'tiny" "int' THEN 255 WHEN 'smallint' THEN 65535 WHEN 'mediumint' THEN 16777215 WHEN 'int' THEN 4294967295 WHEN 'bigint' THEN" " 18446744073709551615 END >> IF(LOCATE('unsigned', COLUMN_TYPE) > 0, 0, 1) ) AS max_value, AUTO_INCREMENT, AUTO_INCRE" "MENT / ( CASE DATA_TYPE WHEN 'tinyint' THEN 255 WHEN 'smallint' THEN 65535 WHEN 'mediumint' THEN 16777215 WHEN 'int' " "THEN 4294967295 WHEN 'bigint' THEN 18446744073709551615 END >> IF(LOCATE('unsigned', COLUMN_TYPE) > 0, 0, 1) ) AS aut" "o_increment_ratio FROM INFORMATION_SCHEMA.COLUMNS INNER JOIN INFORMATION_SCHEMA.TABLES USING (TABLE_SCHEMA, TABLE_NAM" "E) WHERE TABLE_SCHEMA NOT IN ('mysql', 'sys', 'INFORMATION_SCHEMA', 'performance_schema') AND TABLE_TYPE='BASE TABLE'" " AND EXTRA='auto_increment' ORDER BY auto_increment_ratio DESC, max_value;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$schema_flattened_k" "eys ( table_schema, table_name, index_name, non_unique, subpart_exists, index_columns ) AS SELECT TABLE_SCHEMA, TABLE" "_NAME, INDEX_NAME, MAX(NON_UNIQUE) AS non_unique, MAX(IF(SUB_PART IS NULL, 0, 1)) AS subpart_exists, GROUP_CONCAT(COL" "UMN_NAME ORDER BY SEQ_IN_INDEX) AS index_columns FROM INFORMATION_SCHEMA.STATISTICS WHERE INDEX_TYPE='BTREE' AND TABL" "E_SCHEMA NOT IN ('mysql', 'sys', 'INFORMATION_SCHEMA', 'PERFORMANCE_SCHEMA') GROUP BY TABLE_SCHEMA, TABLE_NAME, INDEX" "_NAME;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW schema_redundant_ind" "exes ( table_schema, table_name, redundant_index_name, redundant_index_columns, redundant_index_non_unique, dominant_" "index_name, dominant_index_columns, dominant_index_non_unique, subpart_exists, sql_drop_index ) AS SELECT redundant_k" "eys.table_schema, redundant_keys.table_name, redundant_keys.index_name AS redundant_index_name, redundant_keys.index_" "columns AS redundant_index_columns, redundant_keys.non_unique AS redundant_index_non_unique, dominant_keys.index_name" " AS dominant_index_name, dominant_keys.index_columns AS dominant_index_columns, dominant_keys.non_unique AS dominant_" "index_non_unique, IF(redundant_keys.subpart_exists OR dominant_keys.subpart_exists, 1 ,0) AS subpart_exists, CONCAT( " "'ALTER TABLE `', redundant_keys.table_schema, '`.`', redundant_keys.table_name, '` DROP INDEX `', redundant_keys.inde" "x_name, '`' ) AS sql_drop_index FROM x$schema_flattened_keys AS redundant_keys INNER JOIN x$schema_flattened_keys AS " "dominant_keys USING (TABLE_SCHEMA, TABLE_NAME) WHERE redundant_keys.index_name != dominant_keys.index_name AND ( ( /" "* Identical columns */ (redundant_keys.index_columns = dominant_keys.index_columns) AND ( (redundant_keys.non_unique " "> dominant_keys.non_unique) OR (redundant_keys.non_unique = dominant_keys.non_unique AND IF(redundant_keys.index_na" "me='PRIMARY', '', redundant_keys.index_name) > IF(dominant_keys.index_name='PRIMARY', '', dominant_keys.index_name) )" " ) ) OR ( /* Non-unique prefix columns */ LOCATE(CONCAT(redundant_keys.index_columns, ','), dominant_keys.index_colu" "mns) = 1 AND redundant_keys.non_unique = 1 ) OR ( /* Unique prefix columns */ LOCATE(CONCAT(dominant_keys.index_colu" "mns, ','), redundant_keys.index_columns) = 1 AND dominant_keys.non_unique = 0 ) );\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW ps_check_lost_instrumen" "tation ( variable_name, variable_value ) AS SELECT variable_name, variable_value FROM performance_schema.global_statu" "s WHERE variable_name LIKE 'perf%lost' AND variable_value > 0;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW latest_file_io ( thread" ", file, latency, operation, requested ) AS SELECT IF(id IS NULL, CONCAT(SUBSTRING_INDEX(name, '/', -1), ':', thread_" "id), CONCAT(user, '@', host, ':', id) ) thread, sys.format_path(object_name) file, sys.format_time(timer_wait) AS " "latency, operation, sys.format_bytes(number_of_bytes) AS requested FROM performance_schema.events_waits_history_lon" "g JOIN performance_schema.threads USING (thread_id) LEFT JOIN information_schema.processlist ON processlist_id = id " "WHERE object_name IS NOT NULL AND event_name LIKE 'wait/io/file/%' ORDER BY timer_start;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$latest_file_io ( thre" "ad, file, latency, operation, requested ) AS SELECT IF(id IS NULL, CONCAT(SUBSTRING_INDEX(name, '/', -1), ':', threa" "d_id), CONCAT(user, '@', host, ':', id) ) thread, object_name file, timer_wait AS latency, operation, number_of_" "bytes AS requested FROM performance_schema.events_waits_history_long JOIN performance_schema.threads USING (thread_i" "d) LEFT JOIN information_schema.processlist ON processlist_id = id WHERE object_name IS NOT NULL AND event_name LIKE " "'wait/io/file/%' ORDER BY timer_start;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW io_by_thread_by_lat" "ency ( user, total, total_latency, min_latency, avg_latency, max_latency, thread_id, processlist_id ) AS SELECT IF(pr" "ocesslist_id IS NULL, SUBSTRING_INDEX(name, '/', -1), CONCAT(processlist_user, '@', processlist_host) ) user, SUM(" "count_star) total, sys.format_time(SUM(sum_timer_wait)) total_latency, sys.format_time(MIN(min_timer_wait)) min_laten" "cy, sys.format_time(AVG(avg_timer_wait)) avg_latency, sys.format_time(MAX(max_timer_wait)) max_latency, thread_id, pr" "ocesslist_id FROM performance_schema.events_waits_summary_by_thread_by_event_name LEFT JOIN performance_schema.threa" "ds USING (thread_id) WHERE event_name LIKE 'wait/io/file/%' AND sum_timer_wait > 0 GROUP BY thread_id, processlist_id" ", user ORDER BY SUM(sum_timer_wait) DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$io_by_thread_by_l" "atency ( user, total, total_latency, min_latency, avg_latency, max_latency, thread_id, processlist_id ) AS SELECT IF(" "processlist_id IS NULL, SUBSTRING_INDEX(name, '/', -1), CONCAT(processlist_user, '@', processlist_host) ) user, SU" "M(count_star) total, SUM(sum_timer_wait) total_latency, MIN(min_timer_wait) min_latency, AVG(avg_timer_wait) avg_late" "ncy, MAX(max_timer_wait) max_latency, thread_id, processlist_id FROM performance_schema.events_waits_summary_by_threa" "d_by_event_name LEFT JOIN performance_schema.threads USING (thread_id) WHERE event_name LIKE 'wait/io/file/%' AND su" "m_timer_wait > 0 GROUP BY thread_id, processlist_id, user ORDER BY SUM(sum_timer_wait) DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW io_global_by_file_by_by" "tes ( file, count_read, total_read, avg_read, count_write, total_written, avg_write, total, write_pct ) AS SELECT sys" ".format_path(file_name) AS file, count_read, sys.format_bytes(sum_number_of_bytes_read) AS total_read, sys.format_b" "ytes(IFNULL(sum_number_of_bytes_read / NULLIF(count_read, 0), 0)) AS avg_read, count_write, sys.format_bytes(sum_num" "ber_of_bytes_write) AS total_written, sys.format_bytes(IFNULL(sum_number_of_bytes_write / NULLIF(count_write, 0), 0.0" "0)) AS avg_write, sys.format_bytes(sum_number_of_bytes_read + sum_number_of_bytes_write) AS total, IFNULL(ROUND(100-" "((sum_number_of_bytes_read/ NULLIF((sum_number_of_bytes_read+sum_number_of_bytes_write), 0))*100), 2), 0.00) AS write" "_pct FROM performance_schema.file_summary_by_instance ORDER BY sum_number_of_bytes_read + sum_number_of_bytes_write " "DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$io_global_by_file_by_" "bytes ( file, count_read, total_read, avg_read, count_write, total_written, avg_write, total, write_pct ) AS SELECT f" "ile_name AS file, count_read, sum_number_of_bytes_read AS total_read, IFNULL(sum_number_of_bytes_read / NULLIF(coun" "t_read, 0), 0) AS avg_read, count_write, sum_number_of_bytes_write AS total_written, IFNULL(sum_number_of_bytes_writ" "e / NULLIF(count_write, 0), 0.00) AS avg_write, sum_number_of_bytes_read + sum_number_of_bytes_write AS total, IFNUL" "L(ROUND(100-((sum_number_of_bytes_read/ NULLIF((sum_number_of_bytes_read+sum_number_of_bytes_write), 0))*100), 2), 0." "00) AS write_pct FROM performance_schema.file_summary_by_instance ORDER BY sum_number_of_bytes_read + sum_number_of_" "bytes_write DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW io_global_by_file_by_la" "tency ( file, total, total_latency, count_read, read_latency, count_write, write_latency, count_misc, misc_latency ) " "AS SELECT sys.format_path(file_name) AS file, count_star AS total, sys.format_time(sum_timer_wait) AS total_latency" ", count_read, sys.format_time(sum_timer_read) AS read_latency, count_write, sys.format_time(sum_timer_write) AS write" "_latency, count_misc, sys.format_time(sum_timer_misc) AS misc_latency FROM performance_schema.file_summary_by_instanc" "e ORDER BY sum_timer_wait DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$io_global_by_file_by_" "latency ( file, total, total_latency, count_read, read_latency, count_write, write_latency, count_misc, misc_latency " ") AS SELECT file_name AS file, count_star AS total, sum_timer_wait AS total_latency, count_read, sum_timer_read AS " "read_latency, count_write, sum_timer_write AS write_latency, count_misc, sum_timer_misc AS misc_latency FROM performa" "nce_schema.file_summary_by_instance ORDER BY sum_timer_wait DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW io_global_by_wait_by_by" "tes ( event_name, total, total_latency, min_latency, avg_latency, max_latency, count_read, total_read, avg_read, coun" "t_write, total_written, avg_written, total_requested ) AS SELECT SUBSTRING_INDEX(event_name, '/', -2) event_name, cou" "nt_star AS total, sys.format_time(sum_timer_wait) AS total_latency, sys.format_time(min_timer_wait) AS min_latency, s" "ys.format_time(avg_timer_wait) AS avg_latency, sys.format_time(max_timer_wait) AS max_latency, count_read, sys.format" "_bytes(sum_number_of_bytes_read) AS total_read, sys.format_bytes(IFNULL(sum_number_of_bytes_read / NULLIF(count_read," " 0), 0)) AS avg_read, count_write, sys.format_bytes(sum_number_of_bytes_write) AS total_written, sys.format_bytes(IFN" "ULL(sum_number_of_bytes_write / NULLIF(count_write, 0), 0)) AS avg_written, sys.format_bytes(sum_number_of_bytes_writ" "e + sum_number_of_bytes_read) AS total_requested FROM performance_schema.file_summary_by_event_name WHERE event_name " "LIKE 'wait/io/file/%' AND count_star > 0 ORDER BY sum_number_of_bytes_write + sum_number_of_bytes_read DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$io_global_by_wait_by_" "bytes ( event_name, total, total_latency, min_latency, avg_latency, max_latency, count_read, total_read, avg_read, co" "unt_write, total_written, avg_written, total_requested ) AS SELECT SUBSTRING_INDEX(event_name, '/', -2) AS event_name" ", count_star AS total, sum_timer_wait AS total_latency, min_timer_wait AS min_latency, avg_timer_wait AS avg_latency," " max_timer_wait AS max_latency, count_read, sum_number_of_bytes_read AS total_read, IFNULL(sum_number_of_bytes_read /" " NULLIF(count_read, 0), 0) AS avg_read, count_write, sum_number_of_bytes_write AS total_written, IFNULL(sum_number_of" "_bytes_write / NULLIF(count_write, 0), 0) AS avg_written, sum_number_of_bytes_write + sum_number_of_bytes_read AS tot" "al_requested FROM performance_schema.file_summary_by_event_name WHERE event_name LIKE 'wait/io/file/%' AND count_sta" "r > 0 ORDER BY sum_number_of_bytes_write + sum_number_of_bytes_read DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW io_global_by_wait_by_la" "tency ( event_name, total, total_latency, avg_latency, max_latency, read_latency, write_latency, misc_latency, count_" "read, total_read, avg_read, count_write, total_written, avg_written ) AS SELECT SUBSTRING_INDEX(event_name, '/', -2) " "AS event_name, count_star AS total, sys.format_time(sum_timer_wait) AS total_latency, sys.format_time(avg_timer_wait)" " AS avg_latency, sys.format_time(max_timer_wait) AS max_latency, sys.format_time(sum_timer_read) AS read_latency, sys" ".format_time(sum_timer_write) AS write_latency, sys.format_time(sum_timer_misc) AS misc_latency, count_read, sys.form" "at_bytes(sum_number_of_bytes_read) AS total_read, sys.format_bytes(IFNULL(sum_number_of_bytes_read / NULLIF(count_rea" "d, 0), 0)) AS avg_read, count_write, sys.format_bytes(sum_number_of_bytes_write) AS total_written, sys.format_bytes(I" "FNULL(sum_number_of_bytes_write / NULLIF(count_write, 0), 0)) AS avg_written FROM performance_schema.file_summary_by_" "event_name WHERE event_name LIKE 'wait/io/file/%' AND count_star > 0 ORDER BY sum_timer_wait DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$io_global_by_wait_by_" "latency ( event_name, total, total_latency, avg_latency, max_latency, read_latency, write_latency, misc_latency, coun" "t_read, total_read, avg_read, count_write, total_written, avg_written ) AS SELECT SUBSTRING_INDEX(event_name, '/', -2" ") AS event_name, count_star AS total, sum_timer_wait AS total_latency, avg_timer_wait AS avg_latency, max_timer_wait " "AS max_latency, sum_timer_read AS read_latency, sum_timer_write AS write_latency, sum_timer_misc AS misc_latency, cou" "nt_read, sum_number_of_bytes_read AS total_read, IFNULL(sum_number_of_bytes_read / NULLIF(count_read, 0), 0) AS avg_r" "ead, count_write, sum_number_of_bytes_write AS total_written, IFNULL(sum_number_of_bytes_write / NULLIF(count_write, " "0), 0) AS avg_written FROM performance_schema.file_summary_by_event_name WHERE event_name LIKE 'wait/io/file/%' AND " "count_star > 0 ORDER BY sum_timer_wait DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW memory_by_user_by_c" "urrent_bytes ( user, current_count_used, current_allocated, current_avg_alloc, current_max_alloc, total_allocated ) A" "S SELECT IF(user IS NULL, 'background', user) AS user, SUM(current_count_used) AS current_count_used, sys.format_byte" "s(SUM(current_number_of_bytes_used)) AS current_allocated, sys.format_bytes(IFNULL(SUM(current_number_of_bytes_used) " "/ NULLIF(SUM(current_count_used), 0), 0)) AS current_avg_alloc, sys.format_bytes(MAX(current_number_of_bytes_used)) A" "S current_max_alloc, sys.format_bytes(SUM(sum_number_of_bytes_alloc)) AS total_allocated FROM performance_schema.memo" "ry_summary_by_user_by_event_name GROUP BY IF(user IS NULL, 'background', user) ORDER BY SUM(current_number_of_bytes_u" "sed) DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$memory_by_user_by" "_current_bytes ( user, current_count_used, current_allocated, current_avg_alloc, current_max_alloc, total_allocated )" " AS SELECT IF(user IS NULL, 'background', user) AS user, SUM(current_count_used) AS current_count_used, SUM(current_n" "umber_of_bytes_used) AS current_allocated, IFNULL(SUM(current_number_of_bytes_used) / NULLIF(SUM(current_count_used)," " 0), 0) AS current_avg_alloc, MAX(current_number_of_bytes_used) AS current_max_alloc, SUM(sum_number_of_bytes_alloc) " "AS total_allocated FROM performance_schema.memory_summary_by_user_by_event_name GROUP BY IF(user IS NULL, 'background" "', user) ORDER BY SUM(current_number_of_bytes_used) DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW memory_by_host_by_c" "urrent_bytes ( host, current_count_used, current_allocated, current_avg_alloc, current_max_alloc, total_allocated ) A" "S SELECT IF(host IS NULL, 'background', host) AS host, SUM(current_count_used) AS current_count_used, sys.format_byte" "s(SUM(current_number_of_bytes_used)) AS current_allocated, sys.format_bytes(IFNULL(SUM(current_number_of_bytes_used) " "/ NULLIF(SUM(current_count_used), 0), 0)) AS current_avg_alloc, sys.format_bytes(MAX(current_number_of_bytes_used)) A" "S current_max_alloc, sys.format_bytes(SUM(sum_number_of_bytes_alloc)) AS total_allocated FROM performance_schema.memo" "ry_summary_by_host_by_event_name GROUP BY IF(host IS NULL, 'background', host) ORDER BY SUM(current_number_of_bytes_u" "sed) DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$memory_by_host_by" "_current_bytes ( host, current_count_used, current_allocated, current_avg_alloc, current_max_alloc, total_allocated )" " AS SELECT IF(host IS NULL, 'background', host) AS host, SUM(current_count_used) AS current_count_used, SUM(current_n" "umber_of_bytes_used) AS current_allocated, IFNULL(SUM(current_number_of_bytes_used) / NULLIF(SUM(current_count_used)," " 0), 0) AS current_avg_alloc, MAX(current_number_of_bytes_used) AS current_max_alloc, SUM(sum_number_of_bytes_alloc) " "AS total_allocated FROM performance_schema.memory_summary_by_host_by_event_name GROUP BY IF(host IS NULL, 'background" "', host) ORDER BY SUM(current_number_of_bytes_used) DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW memory_by_thread_by" "_current_bytes ( thread_id, user, current_count_used, current_allocated, current_avg_alloc, current_max_alloc, total_" "allocated ) AS SELECT thread_id, IF(t.name = 'thread/sql/one_connection', CONCAT(t.processlist_user, '@', t.processl" "ist_host), REPLACE(t.name, 'thread/', '')) user, SUM(mt.current_count_used) AS current_count_used, sys.format_bytes(" "SUM(mt.current_number_of_bytes_used)) AS current_allocated, sys.format_bytes(IFNULL(SUM(mt.current_number_of_bytes_us" "ed) / NULLIF(SUM(current_count_used), 0), 0)) AS current_avg_alloc, sys.format_bytes(MAX(mt.current_number_of_bytes_u" "sed)) AS current_max_alloc, sys.format_bytes(SUM(mt.sum_number_of_bytes_alloc)) AS total_allocated FROM performance_s" "chema.memory_summary_by_thread_by_event_name AS mt JOIN performance_schema.threads AS t USING (thread_id) GROUP BY th" "read_id, IF(t.name = 'thread/sql/one_connection', CONCAT(t.processlist_user, '@', t.processlist_host), REPLACE(t.na" "me, 'thread/', '')) ORDER BY SUM(current_number_of_bytes_used) DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$memory_by_thread_" "by_current_bytes ( thread_id, user, current_count_used, current_allocated, current_avg_alloc, current_max_alloc, tota" "l_allocated ) AS SELECT t.thread_id, IF(t.name = 'thread/sql/one_connection', CONCAT(t.processlist_user, '@', t.proc" "esslist_host), REPLACE(t.name, 'thread/', '')) user, SUM(mt.current_count_used) AS current_count_used, SUM(mt.curren" "t_number_of_bytes_used) AS current_allocated, IFNULL(SUM(mt.current_number_of_bytes_used) / NULLIF(SUM(current_count_" "used), 0), 0) AS current_avg_alloc, MAX(mt.current_number_of_bytes_used) AS current_max_alloc, SUM(mt.sum_number_of_b" "ytes_alloc) AS total_allocated FROM performance_schema.memory_summary_by_thread_by_event_name AS mt JOIN performance_" "schema.threads AS t USING (thread_id) GROUP BY thread_id, IF(t.name = 'thread/sql/one_connection', CONCAT(t.processl" "ist_user, '@', t.processlist_host), REPLACE(t.name, 'thread/', '')) ORDER BY SUM(mt.current_number_of_bytes_used) DE" "SC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW memory_global_by_curren" "t_bytes ( event_name, current_count, current_alloc, current_avg_alloc, high_count, high_alloc, high_avg_alloc ) AS SE" "LECT event_name, current_count_used AS current_count, sys.format_bytes(current_number_of_bytes_used) AS current_alloc" ", sys.format_bytes(IFNULL(current_number_of_bytes_used / NULLIF(current_count_used, 0), 0)) AS current_avg_alloc, hig" "h_count_used AS high_count, sys.format_bytes(high_number_of_bytes_used) AS high_alloc, sys.format_bytes(IFNULL(high_n" "umber_of_bytes_used / NULLIF(high_count_used, 0), 0)) AS high_avg_alloc FROM performance_schema.memory_summary_global" "_by_event_name WHERE current_number_of_bytes_used > 0 ORDER BY current_number_of_bytes_used DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$memory_global_by_curr" "ent_bytes ( event_name, current_count, current_alloc, current_avg_alloc, high_count, high_alloc, high_avg_alloc ) AS " "SELECT event_name, current_count_used AS current_count, current_number_of_bytes_used AS current_alloc, IFNULL(current" "_number_of_bytes_used / NULLIF(current_count_used, 0), 0) AS current_avg_alloc, high_count_used AS high_count, high_n" "umber_of_bytes_used AS high_alloc, IFNULL(high_number_of_bytes_used / NULLIF(high_count_used, 0), 0) AS high_avg_allo" "c FROM performance_schema.memory_summary_global_by_event_name WHERE current_number_of_bytes_used > 0 ORDER BY current" "_number_of_bytes_used DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW memory_global_total" " ( total_allocated ) AS SELECT sys.format_bytes(SUM(CURRENT_NUMBER_OF_BYTES_USED)) total_allocated FROM performance_s" "chema.memory_summary_global_by_event_name;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$memory_global_tot" "al ( total_allocated ) AS SELECT SUM(CURRENT_NUMBER_OF_BYTES_USED) total_allocated FROM performance_schema.memory_sum" "mary_global_by_event_name;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW schema_index_statistics" " ( table_schema, table_name, index_name, rows_selected, select_latency, rows_inserted, insert_latency, rows_updated, " "update_latency, rows_deleted, delete_latency ) AS SELECT OBJECT_SCHEMA AS table_schema, OBJECT_NAME AS table_name, IN" "DEX_NAME as index_name, COUNT_FETCH AS rows_selected, sys.format_time(SUM_TIMER_FETCH) AS select_latency, COUNT_INSER" "T AS rows_inserted, sys.format_time(SUM_TIMER_INSERT) AS insert_latency, COUNT_UPDATE AS rows_updated, sys.format_tim" "e(SUM_TIMER_UPDATE) AS update_latency, COUNT_DELETE AS rows_deleted, sys.format_time(SUM_TIMER_DELETE) AS delete_late" "ncy FROM performance_schema.table_io_waits_summary_by_index_usage WHERE index_name IS NOT NULL ORDER BY sum_timer_wai" "t DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$schema_index_statisti" "cs ( table_schema, table_name, index_name, rows_selected, select_latency, rows_inserted, insert_latency, rows_updated" ", update_latency, rows_deleted, delete_latency ) AS SELECT OBJECT_SCHEMA AS table_schema, OBJECT_NAME AS table_name, " "INDEX_NAME as index_name, COUNT_FETCH AS rows_selected, SUM_TIMER_FETCH AS select_latency, COUNT_INSERT AS rows_inser" "ted, SUM_TIMER_INSERT AS insert_latency, COUNT_UPDATE AS rows_updated, SUM_TIMER_UPDATE AS update_latency, COUNT_DELE" "TE AS rows_deleted, SUM_TIMER_DELETE AS delete_latency FROM performance_schema.table_io_waits_summary_by_index_usage " "WHERE index_name IS NOT NULL ORDER BY sum_timer_wait DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$ps_schema_table_s" "tatistics_io ( table_schema, table_name, count_read, sum_number_of_bytes_read, sum_timer_read, count_write, sum_numbe" "r_of_bytes_write, sum_timer_write, count_misc, sum_timer_misc ) AS SELECT extract_schema_from_file_name(file_name) AS" " table_schema, extract_table_from_file_name(file_name) AS table_name, SUM(count_read) AS count_read, SUM(sum_number_o" "f_bytes_read) AS sum_number_of_bytes_read, SUM(sum_timer_read) AS sum_timer_read, SUM(count_write) AS count_write, SU" "M(sum_number_of_bytes_write) AS sum_number_of_bytes_write, SUM(sum_timer_write) AS sum_timer_write, SUM(count_misc) A" "S count_misc, SUM(sum_timer_misc) AS sum_timer_misc FROM performance_schema.file_summary_by_instance GROUP BY table_s" "chema, table_name;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW schema_table_statis" "tics ( table_schema, table_name, total_latency, rows_fetched, fetch_latency, rows_inserted, insert_latency, rows_upda" "ted, update_latency, rows_deleted, delete_latency, io_read_requests, io_read, io_read_latency, io_write_requests, io_" "write, io_write_latency, io_misc_requests, io_misc_latency ) AS SELECT pst.object_schema AS table_schema, pst.object_" "name AS table_name, sys.format_time(pst.sum_timer_wait) AS total_latency, pst.count_fetch AS rows_fetched, sys.format" "_time(pst.sum_timer_fetch) AS fetch_latency, pst.count_insert AS rows_inserted, sys.format_time(pst.sum_timer_insert)" " AS insert_latency, pst.count_update AS rows_updated, sys.format_time(pst.sum_timer_update) AS update_latency, pst.co" "unt_delete AS rows_deleted, sys.format_time(pst.sum_timer_delete) AS delete_latency, fsbi.count_read AS io_read_reque" "sts, sys.format_bytes(fsbi.sum_number_of_bytes_read) AS io_read, sys.format_time(fsbi.sum_timer_read) AS io_read_late" "ncy, fsbi.count_write AS io_write_requests, sys.format_bytes(fsbi.sum_number_of_bytes_write) AS io_write, sys.format_" "time(fsbi.sum_timer_write) AS io_write_latency, fsbi.count_misc AS io_misc_requests, sys.format_time(fsbi.sum_timer_m" "isc) AS io_misc_latency FROM performance_schema.table_io_waits_summary_by_table AS pst LEFT JOIN x$ps_schema_table_st" "atistics_io AS fsbi ON pst.object_schema = fsbi.table_schema AND pst.object_name = fsbi.table_name ORDER BY pst.sum_t" "imer_wait DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$schema_table_stat" "istics ( table_schema, table_name, total_latency, rows_fetched, fetch_latency, rows_inserted, insert_latency, rows_up" "dated, update_latency, rows_deleted, delete_latency, io_read_requests, io_read, io_read_latency, io_write_requests, i" "o_write, io_write_latency, io_misc_requests, io_misc_latency ) AS SELECT pst.object_schema AS table_schema, pst.objec" "t_name AS table_name, pst.sum_timer_wait AS total_latency, pst.count_fetch AS rows_fetched, pst.sum_timer_fetch AS fe" "tch_latency, pst.count_insert AS rows_inserted, pst.sum_timer_insert AS insert_latency, pst.count_update AS rows_upda" "ted, pst.sum_timer_update AS update_latency, pst.count_delete AS rows_deleted, pst.sum_timer_delete AS delete_latency" ", fsbi.count_read AS io_read_requests, fsbi.sum_number_of_bytes_read AS io_read, fsbi.sum_timer_read AS io_read_laten" "cy, fsbi.count_write AS io_write_requests, fsbi.sum_number_of_bytes_write AS io_write, fsbi.sum_timer_write AS io_wri" "te_latency, fsbi.count_misc AS io_misc_requests, fsbi.sum_timer_misc AS io_misc_latency FROM performance_schema.table" "_io_waits_summary_by_table AS pst LEFT JOIN x$ps_schema_table_statistics_io AS fsbi ON pst.object_schema = fsbi.table" "_schema AND pst.object_name = fsbi.table_name ORDER BY pst.sum_timer_wait DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW schema_table_statis" "tics_with_buffer ( table_schema, table_name, rows_fetched, fetch_latency, rows_inserted, insert_latency, rows_updated" ", update_latency, rows_deleted, delete_latency, io_read_requests, io_read, io_read_latency, io_write_requests, io_wri" "te, io_write_latency, io_misc_requests, io_misc_latency, innodb_buffer_allocated, innodb_buffer_data, innodb_buffer_f" "ree, innodb_buffer_pages, innodb_buffer_pages_hashed, innodb_buffer_pages_old, innodb_buffer_rows_cached ) AS SELECT " "pst.object_schema AS table_schema, pst.object_name AS table_name, pst.count_fetch AS rows_fetched, sys.format_time(ps" "t.sum_timer_fetch) AS fetch_latency, pst.count_insert AS rows_inserted, sys.format_time(pst.sum_timer_insert) AS inse" "rt_latency, pst.count_update AS rows_updated, sys.format_time(pst.sum_timer_update) AS update_latency, pst.count_dele" "te AS rows_deleted, sys.format_time(pst.sum_timer_delete) AS delete_latency, fsbi.count_read AS io_read_requests, sys" ".format_bytes(fsbi.sum_number_of_bytes_read) AS io_read, sys.format_time(fsbi.sum_timer_read) AS io_read_latency, fsb" "i.count_write AS io_write_requests, sys.format_bytes(fsbi.sum_number_of_bytes_write) AS io_write, sys.format_time(fsb" "i.sum_timer_write) AS io_write_latency, fsbi.count_misc AS io_misc_requests, sys.format_time(fsbi.sum_timer_misc) AS " "io_misc_latency, sys.format_bytes(ibp.allocated) AS innodb_buffer_allocated, sys.format_bytes(ibp.data) AS innodb_buf" "fer_data, sys.format_bytes(ibp.allocated - ibp.data) AS innodb_buffer_free, ibp.pages AS innodb_buffer_pages, ibp.pag" "es_hashed AS innodb_buffer_pages_hashed, ibp.pages_old AS innodb_buffer_pages_old, ibp.rows_cached AS innodb_buffer_r" "ows_cached FROM performance_schema.table_io_waits_summary_by_table AS pst LEFT JOIN x$ps_schema_table_statistics_io A" "S fsbi ON pst.object_schema = fsbi.table_schema AND pst.object_name = fsbi.table_name LEFT JOIN sys.x$innodb_buffer_s" "tats_by_table AS ibp ON pst.object_schema = ibp.object_schema AND pst.object_name = ibp.object_name ORDER BY pst.sum_" "timer_wait DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$schema_table_stat" "istics_with_buffer ( table_schema, table_name, rows_fetched, fetch_latency, rows_inserted, insert_latency, rows_updat" "ed, update_latency, rows_deleted, delete_latency, io_read_requests, io_read, io_read_latency, io_write_requests, io_w" "rite, io_write_latency, io_misc_requests, io_misc_latency, innodb_buffer_allocated, innodb_buffer_data, innodb_buffer" "_free, innodb_buffer_pages, innodb_buffer_pages_hashed, innodb_buffer_pages_old, innodb_buffer_rows_cached ) AS SELEC" "T pst.object_schema AS table_schema, pst.object_name AS table_name, pst.count_fetch AS rows_fetched, pst.sum_timer_fe" "tch AS fetch_latency, pst.count_insert AS rows_inserted, pst.sum_timer_insert AS insert_latency, pst.count_update AS " "rows_updated, pst.sum_timer_update AS update_latency, pst.count_delete AS rows_deleted, pst.sum_timer_delete AS delet" "e_latency, fsbi.count_read AS io_read_requests, fsbi.sum_number_of_bytes_read AS io_read, fsbi.sum_timer_read AS io_r" "ead_latency, fsbi.count_write AS io_write_requests, fsbi.sum_number_of_bytes_write AS io_write, fsbi.sum_timer_write " "AS io_write_latency, fsbi.count_misc AS io_misc_requests, fsbi.sum_timer_misc AS io_misc_latency, ibp.allocated AS in" "nodb_buffer_allocated, ibp.data AS innodb_buffer_data, (ibp.allocated - ibp.data) AS innodb_buffer_free, ibp.pages AS" " innodb_buffer_pages, ibp.pages_hashed AS innodb_buffer_pages_hashed, ibp.pages_old AS innodb_buffer_pages_old, ibp.r" "ows_cached AS innodb_buffer_rows_cached FROM performance_schema.table_io_waits_summary_by_table AS pst LEFT JOIN x$ps" "_schema_table_statistics_io AS fsbi ON pst.object_schema = fsbi.table_schema AND pst.object_name = fsbi.table_name LE" "FT JOIN sys.x$innodb_buffer_stats_by_table AS ibp ON pst.object_schema = ibp.object_schema AND pst.object_name = ibp." "object_name ORDER BY pst.sum_timer_wait DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW schema_tables_with_full" "_table_scans ( object_schema, object_name, rows_full_scanned, latency ) AS SELECT object_schema, object_name, count_" "read AS rows_full_scanned, sys.format_time(sum_timer_wait) AS latency FROM performance_schema.table_io_waits_summary_" "by_index_usage WHERE index_name IS NULL AND count_read > 0 ORDER BY count_read DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$schema_tables_with_fu" "ll_table_scans ( object_schema, object_name, rows_full_scanned, latency ) AS SELECT object_schema, object_name, coun" "t_read AS rows_full_scanned, sum_timer_wait AS latency FROM performance_schema.table_io_waits_summary_by_index_usage " " WHERE index_name IS NULL AND count_read > 0 ORDER BY count_read DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW schema_unused_indexes (" " object_schema, object_name, index_name ) AS SELECT t.object_schema, t.object_name, t.index_name FROM performance_sch" "ema.table_io_waits_summary_by_index_usage t INNER JOIN information_schema.statistics s ON t.object_schema = s.table_s" "chema AND t.object_name = s.table_name AND t.index_name = s.index_name WHERE t.index_name IS NOT NULL AND t.count_sta" "r = 0 AND t.object_schema != 'mysql' AND t.index_name != 'PRIMARY' AND s.NON_UNIQUE = 1 AND s.SEQ_IN_INDEX = 1 ORDER " "BY object_schema, object_name;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW schema_table_lock_w" "aits ( object_schema, object_name, waiting_thread_id, waiting_pid, waiting_account, waiting_lock_type, waiting_lock_d" "uration, waiting_query, waiting_query_secs, waiting_query_rows_affected, waiting_query_rows_examined, blocking_thread" "_id, blocking_pid, blocking_account, blocking_lock_type, blocking_lock_duration, sql_kill_blocking_query, sql_kill_bl" "ocking_connection ) AS SELECT g.object_schema AS object_schema, g.object_name AS object_name, pt.thread_id AS waiting" "_thread_id, pt.processlist_id AS waiting_pid, sys.ps_thread_account(p.owner_thread_id) AS waiting_account, p.lock_typ" "e AS waiting_lock_type, p.lock_duration AS waiting_lock_duration, sys.format_statement(pt.processlist_info) AS waitin" "g_query, pt.processlist_time AS waiting_query_secs, ps.rows_affected AS waiting_query_rows_affected, ps.rows_examined" " AS waiting_query_rows_examined, gt.thread_id AS blocking_thread_id, gt.processlist_id AS blocking_pid, sys.ps_thread" "_account(g.owner_thread_id) AS blocking_account, g.lock_type AS blocking_lock_type, g.lock_duration AS blocking_lock_" "duration, CONCAT('KILL QUERY ', gt.processlist_id) AS sql_kill_blocking_query, CONCAT('KILL ', gt.processlist_id) AS " "sql_kill_blocking_connection FROM performance_schema.metadata_locks g INNER JOIN performance_schema.metadata_locks p " " ON g.object_type = p.object_type AND g.object_schema = p.object_schema AND g.object_name = p.object_name AND g.lock_" "status = 'GRANTED' AND p.lock_status = 'PENDING' INNER JOIN performance_schema.threads gt ON g.owner_thread_id = gt.t" "hread_id INNER JOIN performance_schema.threads pt ON p.owner_thread_id = pt.thread_id LEFT JOIN performance_schema.ev" "ents_statements_current gs ON g.owner_thread_id = gs.thread_id LEFT JOIN performance_schema.events_statements_current" " ps ON p.owner_thread_id = ps.thread_id WHERE g.object_type = 'TABLE';\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$schema_table_lock" "_waits ( object_schema, object_name, waiting_thread_id, waiting_pid, waiting_account, waiting_lock_type, waiting_lock" "_duration, waiting_query, waiting_query_secs, waiting_query_rows_affected, waiting_query_rows_examined, blocking_thre" "ad_id, blocking_pid, blocking_account, blocking_lock_type, blocking_lock_duration, sql_kill_blocking_query, sql_kill_" "blocking_connection ) AS SELECT g.object_schema AS object_schema, g.object_name AS object_name, pt.thread_id AS waiti" "ng_thread_id, pt.processlist_id AS waiting_pid, sys.ps_thread_account(p.owner_thread_id) AS waiting_account, p.lock_t" "ype AS waiting_lock_type, p.lock_duration AS waiting_lock_duration, pt.processlist_info AS waiting_query, pt.processl" "ist_time AS waiting_query_secs, ps.rows_affected AS waiting_query_rows_affected, ps.rows_examined AS waiting_query_ro" "ws_examined, gt.thread_id AS blocking_thread_id, gt.processlist_id AS blocking_pid, sys.ps_thread_account(g.owner_thr" "ead_id) AS blocking_account, g.lock_type AS blocking_lock_type, g.lock_duration AS blocking_lock_duration, CONCAT('KI" "LL QUERY ', gt.processlist_id) AS sql_kill_blocking_query, CONCAT('KILL ', gt.processlist_id) AS sql_kill_blocking_co" "nnection FROM performance_schema.metadata_locks g INNER JOIN performance_schema.metadata_locks p ON g.object_type = " "p.object_type AND g.object_schema = p.object_schema AND g.object_name = p.object_name AND g.lock_status = 'GRANTED' A" "ND p.lock_status = 'PENDING' INNER JOIN performance_schema.threads gt ON g.owner_thread_id = gt.thread_id INNER JOIN " "performance_schema.threads pt ON p.owner_thread_id = pt.thread_id LEFT JOIN performance_schema.events_statements_curr" "ent gs ON g.owner_thread_id = gs.thread_id LEFT JOIN performance_schema.events_statements_current ps ON p.owner_threa" "d_id = ps.thread_id WHERE g.object_type = 'TABLE';\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW statement_analysis ( qu" "ery, db, full_scan, exec_count, err_count, warn_count, total_latency, max_latency, avg_latency, lock_latency, rows_se" "nt, rows_sent_avg, rows_examined, rows_examined_avg, rows_affected, rows_affected_avg, tmp_tables, tmp_disk_tables, r" "ows_sorted, sort_merge_passes, digest, first_seen, last_seen ) AS SELECT sys.format_statement(DIGEST_TEXT) AS query, " "SCHEMA_NAME AS db, IF(SUM_NO_GOOD_INDEX_USED > 0 OR SUM_NO_INDEX_USED > 0, '*', '') AS full_scan, COUNT_STAR AS exec_" "count, SUM_ERRORS AS err_count, SUM_WARNINGS AS warn_count, sys.format_time(SUM_TIMER_WAIT) AS total_latency, sys.for" "mat_time(MAX_TIMER_WAIT) AS max_latency, sys.format_time(AVG_TIMER_WAIT) AS avg_latency, sys.format_time(SUM_LOCK_TIM" "E) AS lock_latency, SUM_ROWS_SENT AS rows_sent, ROUND(IFNULL(SUM_ROWS_SENT / NULLIF(COUNT_STAR, 0), 0)) AS rows_sent_" "avg, SUM_ROWS_EXAMINED AS rows_examined, ROUND(IFNULL(SUM_ROWS_EXAMINED / NULLIF(COUNT_STAR, 0), 0)) AS rows_examine" "d_avg, SUM_ROWS_AFFECTED AS rows_affected, ROUND(IFNULL(SUM_ROWS_AFFECTED / NULLIF(COUNT_STAR, 0), 0)) AS rows_affec" "ted_avg, SUM_CREATED_TMP_TABLES AS tmp_tables, SUM_CREATED_TMP_DISK_TABLES AS tmp_disk_tables, SUM_SORT_ROWS AS rows_" "sorted, SUM_SORT_MERGE_PASSES AS sort_merge_passes, DIGEST AS digest, FIRST_SEEN AS first_seen, LAST_SEEN as last_see" "n FROM performance_schema.events_statements_summary_by_digest ORDER BY SUM_TIMER_WAIT DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$statement_analysis ( " "query, db, full_scan, exec_count, err_count, warn_count, total_latency, max_latency, avg_latency, lock_latency, rows_" "sent, rows_sent_avg, rows_examined, rows_examined_avg, rows_affected, rows_affected_avg, tmp_tables, tmp_disk_tables," " rows_sorted, sort_merge_passes, digest, first_seen, last_seen ) AS SELECT DIGEST_TEXT AS query, SCHEMA_NAME AS db, I" "F(SUM_NO_GOOD_INDEX_USED > 0 OR SUM_NO_INDEX_USED > 0, '*', '') AS full_scan, COUNT_STAR AS exec_count, SUM_ERRORS AS" " err_count, SUM_WARNINGS AS warn_count, SUM_TIMER_WAIT AS total_latency, MAX_TIMER_WAIT AS max_latency, AVG_TIMER_WAI" "T AS avg_latency, SUM_LOCK_TIME AS lock_latency, SUM_ROWS_SENT AS rows_sent, ROUND(IFNULL(SUM_ROWS_SENT / NULLIF(COUN" "T_STAR, 0), 0)) AS rows_sent_avg, SUM_ROWS_EXAMINED AS rows_examined, ROUND(IFNULL(SUM_ROWS_EXAMINED / NULLIF(COUNT_S" "TAR, 0), 0)) AS rows_examined_avg, SUM_ROWS_AFFECTED AS rows_affected, ROUND(IFNULL(SUM_ROWS_AFFECTED / NULLIF(COUNT" "_STAR, 0), 0)) AS rows_affected_avg, SUM_CREATED_TMP_TABLES AS tmp_tables, SUM_CREATED_TMP_DISK_TABLES AS tmp_disk_t" "ables, SUM_SORT_ROWS AS rows_sorted, SUM_SORT_MERGE_PASSES AS sort_merge_passes, DIGEST AS digest, FIRST_SEEN AS firs" "t_seen, LAST_SEEN as last_seen FROM performance_schema.events_statements_summary_by_digest ORDER BY SUM_TIMER_WAIT DE" "SC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW statements_with_errors_" "or_warnings ( query, db, exec_count, errors, error_pct, warnings, warning_pct, first_seen, last_seen, digest ) AS SEL" "ECT sys.format_statement(DIGEST_TEXT) AS query, SCHEMA_NAME as db, COUNT_STAR AS exec_count, SUM_ERRORS AS errors, IF" "NULL(SUM_ERRORS / NULLIF(COUNT_STAR, 0), 0) * 100 as error_pct, SUM_WARNINGS AS warnings, IFNULL(SUM_WARNINGS / NULLI" "F(COUNT_STAR, 0), 0) * 100 as warning_pct, FIRST_SEEN as first_seen, LAST_SEEN as last_seen, DIGEST AS digest FROM pe" "rformance_schema.events_statements_summary_by_digest WHERE SUM_ERRORS > 0 OR SUM_WARNINGS > 0 ORDER BY SUM_ERRORS DES" "C, SUM_WARNINGS DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$statements_with_error" "s_or_warnings ( query, db, exec_count, errors, error_pct, warnings, warning_pct, first_seen, last_seen, digest ) AS S" "ELECT DIGEST_TEXT AS query, SCHEMA_NAME as db, COUNT_STAR AS exec_count, SUM_ERRORS AS errors, IFNULL(SUM_ERRORS / NU" "LLIF(COUNT_STAR, 0), 0) * 100 as error_pct, SUM_WARNINGS AS warnings, IFNULL(SUM_WARNINGS / NULLIF(COUNT_STAR, 0), 0)" " * 100 as warning_pct, FIRST_SEEN as first_seen, LAST_SEEN as last_seen, DIGEST AS digest FROM performance_schema.eve" "nts_statements_summary_by_digest WHERE SUM_ERRORS > 0 OR SUM_WARNINGS > 0 ORDER BY SUM_ERRORS DESC, SUM_WARNINGS DESC" ";\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW statements_with_full_ta" "ble_scans ( query, db, exec_count, total_latency, no_index_used_count, no_good_index_used_count, no_index_used_pct, r" "ows_sent, rows_examined, rows_sent_avg, rows_examined_avg, first_seen, last_seen, digest ) AS SELECT sys.format_state" "ment(DIGEST_TEXT) AS query, SCHEMA_NAME as db, COUNT_STAR AS exec_count, sys.format_time(SUM_TIMER_WAIT) AS total_lat" "ency, SUM_NO_INDEX_USED AS no_index_used_count, SUM_NO_GOOD_INDEX_USED AS no_good_index_used_count, ROUND(IFNULL(SUM_" "NO_INDEX_USED / NULLIF(COUNT_STAR, 0), 0) * 100) AS no_index_used_pct, SUM_ROWS_SENT AS rows_sent, SUM_ROWS_EXAMINED " "AS rows_examined, ROUND(SUM_ROWS_SENT/COUNT_STAR) AS rows_sent_avg, ROUND(SUM_ROWS_EXAMINED/COUNT_STAR) AS rows_exami" "ned_avg, FIRST_SEEN as first_seen, LAST_SEEN as last_seen, DIGEST AS digest FROM performance_schema.events_statements" "_summary_by_digest WHERE (SUM_NO_INDEX_USED > 0 OR SUM_NO_GOOD_INDEX_USED > 0) AND DIGEST_TEXT NOT LIKE 'SHOW%' ORDER" " BY no_index_used_pct DESC, total_latency DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$statements_with_full_" "table_scans ( query, db, exec_count, total_latency, no_index_used_count, no_good_index_used_count, no_index_used_pct," " rows_sent, rows_examined, rows_sent_avg, rows_examined_avg, first_seen, last_seen, digest ) AS SELECT DIGEST_TEXT AS" " query, SCHEMA_NAME as db, COUNT_STAR AS exec_count, SUM_TIMER_WAIT AS total_latency, SUM_NO_INDEX_USED AS no_index_u" "sed_count, SUM_NO_GOOD_INDEX_USED AS no_good_index_used_count, ROUND(IFNULL(SUM_NO_INDEX_USED / NULLIF(COUNT_STAR, 0)" ", 0) * 100) AS no_index_used_pct, SUM_ROWS_SENT AS rows_sent, SUM_ROWS_EXAMINED AS rows_examined, ROUND(SUM_ROWS_SENT" "/COUNT_STAR) AS rows_sent_avg, ROUND(SUM_ROWS_EXAMINED/COUNT_STAR) AS rows_examined_avg, FIRST_SEEN as first_seen, LA" "ST_SEEN as last_seen, DIGEST AS digest FROM performance_schema.events_statements_summary_by_digest WHERE (SUM_NO_INDE" "X_USED > 0 OR SUM_NO_GOOD_INDEX_USED > 0) AND DIGEST_TEXT NOT LIKE 'SHOW%' ORDER BY no_index_used_pct DESC, total_lat" "ency DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$ps_digest_avg_lat" "ency_distribution ( cnt, avg_us ) AS SELECT COUNT(*) cnt, ROUND(avg_timer_wait/1000000) AS avg_us FROM performance_s" "chema.events_statements_summary_by_digest GROUP BY avg_us;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$ps_digest_95th_pe" "rcentile_by_avg_us ( avg_us, percentile ) AS SELECT s2.avg_us avg_us, IFNULL(SUM(s1.cnt)/NULLIF((SELECT COUNT(*) FROM" " performance_schema.events_statements_summary_by_digest), 0), 0) percentile FROM sys.x$ps_digest_avg_latency_distribu" "tion AS s1 JOIN sys.x$ps_digest_avg_latency_distribution AS s2 ON s1.avg_us <= s2.avg_us GROUP BY s2.avg_us HAVING IF" "NULL(SUM(s1.cnt)/NULLIF((SELECT COUNT(*) FROM performance_schema.events_statements_summary_by_digest), 0), 0) > 0.95 " "ORDER BY percentile LIMIT 1;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW statements_with_runtime" "s_in_95th_percentile ( query, db, full_scan, exec_count, err_count, warn_count, total_latency, max_latency, avg_laten" "cy, rows_sent, rows_sent_avg, rows_examined, rows_examined_avg, first_seen, last_seen, digest ) AS SELECT sys.format_" "statement(DIGEST_TEXT) AS query, SCHEMA_NAME as db, IF(SUM_NO_GOOD_INDEX_USED > 0 OR SUM_NO_INDEX_USED > 0, '*', '') " "AS full_scan, COUNT_STAR AS exec_count, SUM_ERRORS AS err_count, SUM_WARNINGS AS warn_count, sys.format_time(SUM_TIME" "R_WAIT) AS total_latency, sys.format_time(MAX_TIMER_WAIT) AS max_latency, sys.format_time(AVG_TIMER_WAIT) AS avg_late" "ncy, SUM_ROWS_SENT AS rows_sent, ROUND(IFNULL(SUM_ROWS_SENT / NULLIF(COUNT_STAR, 0), 0)) AS rows_sent_avg, SUM_ROWS_E" "XAMINED AS rows_examined, ROUND(IFNULL(SUM_ROWS_EXAMINED / NULLIF(COUNT_STAR, 0), 0)) AS rows_examined_avg, FIRST_SEE" "N AS first_seen, LAST_SEEN AS last_seen, DIGEST AS digest FROM performance_schema.events_statements_summary_by_digest" " stmts JOIN sys.x$ps_digest_95th_percentile_by_avg_us AS top_percentile ON ROUND(stmts.avg_timer_wait/1000000) >= top" "_percentile.avg_us ORDER BY AVG_TIMER_WAIT DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$statements_with_runti" "mes_in_95th_percentile ( query, db, full_scan, exec_count, err_count, warn_count, total_latency, max_latency, avg_lat" "ency, rows_sent, rows_sent_avg, rows_examined, rows_examined_avg, first_seen, last_seen, digest ) AS SELECT DIGEST_TE" "XT AS query, SCHEMA_NAME AS db, IF(SUM_NO_GOOD_INDEX_USED > 0 OR SUM_NO_INDEX_USED > 0, '*', '') AS full_scan, COUNT_" "STAR AS exec_count, SUM_ERRORS AS err_count, SUM_WARNINGS AS warn_count, SUM_TIMER_WAIT AS total_latency, MAX_TIMER_W" "AIT AS max_latency, AVG_TIMER_WAIT AS avg_latency, SUM_ROWS_SENT AS rows_sent, ROUND(IFNULL(SUM_ROWS_SENT / NULLIF(CO" "UNT_STAR, 0), 0)) AS rows_sent_avg, SUM_ROWS_EXAMINED AS rows_examined, ROUND(IFNULL(SUM_ROWS_EXAMINED / NULLIF(COUNT" "_STAR, 0), 0)) AS rows_examined_avg, FIRST_SEEN as first_seen, LAST_SEEN as last_seen, DIGEST AS digest FROM performa" "nce_schema.events_statements_summary_by_digest stmts JOIN sys.x$ps_digest_95th_percentile_by_avg_us AS top_percentile" " ON ROUND(stmts.avg_timer_wait/1000000) >= top_percentile.avg_us ORDER BY AVG_TIMER_WAIT DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW statements_with_sorting" " ( query, db, exec_count, total_latency, sort_merge_passes, avg_sort_merges, sorts_using_scans, sort_using_range, row" "s_sorted, avg_rows_sorted, first_seen, last_seen, digest ) AS SELECT sys.format_statement(DIGEST_TEXT) AS query, SCHE" "MA_NAME db, COUNT_STAR AS exec_count, sys.format_time(SUM_TIMER_WAIT) AS total_latency, SUM_SORT_MERGE_PASSES AS sort" "_merge_passes, ROUND(IFNULL(SUM_SORT_MERGE_PASSES / NULLIF(COUNT_STAR, 0), 0)) AS avg_sort_merges, SUM_SORT_SCAN AS s" "orts_using_scans, SUM_SORT_RANGE AS sort_using_range, SUM_SORT_ROWS AS rows_sorted, ROUND(IFNULL(SUM_SORT_ROWS / NULL" "IF(COUNT_STAR, 0), 0)) AS avg_rows_sorted, FIRST_SEEN as first_seen, LAST_SEEN as last_seen, DIGEST AS digest FROM pe" "rformance_schema.events_statements_summary_by_digest WHERE SUM_SORT_ROWS > 0 ORDER BY SUM_TIMER_WAIT DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$statements_with_sorti" "ng ( query, db, exec_count, total_latency, sort_merge_passes, avg_sort_merges, sorts_using_scans, sort_using_range, r" "ows_sorted, avg_rows_sorted, first_seen, last_seen, digest ) AS SELECT DIGEST_TEXT AS query, SCHEMA_NAME db, COUNT_ST" "AR AS exec_count, SUM_TIMER_WAIT AS total_latency, SUM_SORT_MERGE_PASSES AS sort_merge_passes, ROUND(IFNULL(SUM_SORT_" "MERGE_PASSES / NULLIF(COUNT_STAR, 0), 0)) AS avg_sort_merges, SUM_SORT_SCAN AS sorts_using_scans, SUM_SORT_RANGE AS s" "ort_using_range, SUM_SORT_ROWS AS rows_sorted, ROUND(IFNULL(SUM_SORT_ROWS / NULLIF(COUNT_STAR, 0), 0)) AS avg_rows_so" "rted, FIRST_SEEN as first_seen, LAST_SEEN as last_seen, DIGEST AS digest FROM performance_schema.events_statements_su" "mmary_by_digest WHERE SUM_SORT_ROWS > 0 ORDER BY SUM_TIMER_WAIT DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW statements_with_temp_ta" "bles ( query, db, exec_count, total_latency, memory_tmp_tables, disk_tmp_tables, avg_tmp_tables_per_query, tmp_tables" "_to_disk_pct, first_seen, last_seen, digest ) AS SELECT sys.format_statement(DIGEST_TEXT) AS query, SCHEMA_NAME as db" ", COUNT_STAR AS exec_count, sys.format_time(SUM_TIMER_WAIT) as total_latency, SUM_CREATED_TMP_TABLES AS memory_tmp_ta" "bles, SUM_CREATED_TMP_DISK_TABLES AS disk_tmp_tables, ROUND(IFNULL(SUM_CREATED_TMP_TABLES / NULLIF(COUNT_STAR, 0), 0)" ") AS avg_tmp_tables_per_query, ROUND(IFNULL(SUM_CREATED_TMP_DISK_TABLES / NULLIF(SUM_CREATED_TMP_TABLES, 0), 0) * 100" ") AS tmp_tables_to_disk_pct, FIRST_SEEN as first_seen, LAST_SEEN as last_seen, DIGEST AS digest FROM performance_sche" "ma.events_statements_summary_by_digest WHERE SUM_CREATED_TMP_TABLES > 0 ORDER BY SUM_CREATED_TMP_DISK_TABLES DESC, SU" "M_CREATED_TMP_TABLES DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$statements_with_temp_" "tables ( query, db, exec_count, total_latency, memory_tmp_tables, disk_tmp_tables, avg_tmp_tables_per_query, tmp_tabl" "es_to_disk_pct, first_seen, last_seen, digest ) AS SELECT DIGEST_TEXT AS query, SCHEMA_NAME as db, COUNT_STAR AS exec" "_count, SUM_TIMER_WAIT as total_latency, SUM_CREATED_TMP_TABLES AS memory_tmp_tables, SUM_CREATED_TMP_DISK_TABLES AS " "disk_tmp_tables, ROUND(IFNULL(SUM_CREATED_TMP_TABLES / NULLIF(COUNT_STAR, 0), 0)) AS avg_tmp_tables_per_query, ROUND(" "IFNULL(SUM_CREATED_TMP_DISK_TABLES / NULLIF(SUM_CREATED_TMP_TABLES, 0), 0) * 100) AS tmp_tables_to_disk_pct, FIRST_SE" "EN as first_seen, LAST_SEEN as last_seen, DIGEST AS digest FROM performance_schema.events_statements_summary_by_diges" "t WHERE SUM_CREATED_TMP_TABLES > 0 ORDER BY SUM_CREATED_TMP_DISK_TABLES DESC, SUM_CREATED_TMP_TABLES DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW user_summary_by_file_io" "_type ( user, event_name, total, latency, max_latency ) AS SELECT IF(user IS NULL, 'background', user) AS user, event" "_name, count_star AS total, sys.format_time(sum_timer_wait) AS latency, sys.format_time(max_timer_wait) AS max_latenc" "y FROM performance_schema.events_waits_summary_by_user_by_event_name WHERE event_name LIKE 'wait/io/file%' AND count_" "star > 0 ORDER BY user, sum_timer_wait DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$user_summary_by_file_" "io_type ( user, event_name, total, latency, max_latency ) AS SELECT IF(user IS NULL, 'background', user) AS user, eve" "nt_name, count_star AS total, sum_timer_wait AS latency, max_timer_wait AS max_latency FROM performance_schema.events" "_waits_summary_by_user_by_event_name WHERE event_name LIKE 'wait/io/file%' AND count_star > 0 ORDER BY user, sum_time" "r_wait DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW user_summary_by_fil" "e_io ( user, ios, io_latency ) AS SELECT IF(user IS NULL, 'background', user) AS user, SUM(count_star) AS ios, sys.fo" "rmat_time(SUM(sum_timer_wait)) AS io_latency FROM performance_schema.events_waits_summary_by_user_by_event_name WHER" "E event_name LIKE 'wait/io/file/%' GROUP BY IF(user IS NULL, 'background', user) ORDER BY SUM(sum_timer_wait) DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$user_summary_by_f" "ile_io ( user, ios, io_latency ) AS SELECT IF(user IS NULL, 'background', user) AS user, SUM(count_star) AS ios, SUM(" "sum_timer_wait) AS io_latency FROM performance_schema.events_waits_summary_by_user_by_event_name WHERE event_name LI" "KE 'wait/io/file/%' GROUP BY IF(user IS NULL, 'background', user) ORDER BY SUM(sum_timer_wait) DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW user_summary_by_stateme" "nt_type ( user, statement, total, total_latency, max_latency, lock_latency, rows_sent, rows_examined, rows_affected, " "full_scans ) AS SELECT IF(user IS NULL, 'background', user) AS user, SUBSTRING_INDEX(event_name, '/', -1) AS statemen" "t, count_star AS total, sys.format_time(sum_timer_wait) AS total_latency, sys.format_time(max_timer_wait) AS max_late" "ncy, sys.format_time(sum_lock_time) AS lock_latency, sum_rows_sent AS rows_sent, sum_rows_examined AS rows_examined, " "sum_rows_affected AS rows_affected, sum_no_index_used + sum_no_good_index_used AS full_scans FROM performance_schema." "events_statements_summary_by_user_by_event_name WHERE sum_timer_wait != 0 ORDER BY user, sum_timer_wait DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$user_summary_by_state" "ment_type ( user, statement, total, total_latency, max_latency, lock_latency, rows_sent, rows_examined, rows_affected" ", full_scans ) AS SELECT IF(user IS NULL, 'background', user) AS user, SUBSTRING_INDEX(event_name, '/', -1) AS statem" "ent, count_star AS total, sum_timer_wait AS total_latency, max_timer_wait AS max_latency, sum_lock_time AS lock_laten" "cy, sum_rows_sent AS rows_sent, sum_rows_examined AS rows_examined, sum_rows_affected AS rows_affected, sum_no_index_" "used + sum_no_good_index_used AS full_scans FROM performance_schema.events_statements_summary_by_user_by_event_name W" "HERE sum_timer_wait != 0 ORDER BY user, sum_timer_wait DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW user_summary_by_sta" "tement_latency ( user, total, total_latency, max_latency, lock_latency, rows_sent, rows_examined, rows_affected, full" "_scans ) AS SELECT IF(user IS NULL, 'background', user) AS user, SUM(count_star) AS total, sys.format_time(SUM(sum_ti" "mer_wait)) AS total_latency, sys.format_time(SUM(max_timer_wait)) AS max_latency, sys.format_time(SUM(sum_lock_time))" " AS lock_latency, SUM(sum_rows_sent) AS rows_sent, SUM(sum_rows_examined) AS rows_examined, SUM(sum_rows_affected) AS" " rows_affected, SUM(sum_no_index_used) + SUM(sum_no_good_index_used) AS full_scans FROM performance_schema.events_sta" "tements_summary_by_user_by_event_name GROUP BY IF(user IS NULL, 'background', user) ORDER BY SUM(sum_timer_wait) DESC" ";\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$user_summary_by_s" "tatement_latency ( user, total, total_latency, max_latency, lock_latency, rows_sent, rows_examined, rows_affected, fu" "ll_scans ) AS SELECT IF(user IS NULL, 'background', user) AS user, SUM(count_star) AS total, SUM(sum_timer_wait) AS t" "otal_latency, SUM(max_timer_wait) AS max_latency, SUM(sum_lock_time) AS lock_latency, SUM(sum_rows_sent) AS rows_sent" ", SUM(sum_rows_examined) AS rows_examined, SUM(sum_rows_affected) AS rows_affected, SUM(sum_no_index_used) + SUM(sum_" "no_good_index_used) AS full_scans FROM performance_schema.events_statements_summary_by_user_by_event_name GROUP BY IF" "(user IS NULL, 'background', user) ORDER BY SUM(sum_timer_wait) DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW user_summary_by_stages " "( user, event_name, total, total_latency, avg_latency ) AS SELECT IF(user IS NULL, 'background', user) AS user, event" "_name, count_star AS total, sys.format_time(sum_timer_wait) AS total_latency, sys.format_time(avg_timer_wait) AS avg" "_latency FROM performance_schema.events_stages_summary_by_user_by_event_name WHERE sum_timer_wait != 0 ORDER BY use" "r, sum_timer_wait DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$user_summary_by_stage" "s ( user, event_name, total, total_latency, avg_latency ) AS SELECT IF(user IS NULL, 'background', user) AS user, eve" "nt_name, count_star AS total, sum_timer_wait AS total_latency, avg_timer_wait AS avg_latency FROM performance_schem" "a.events_stages_summary_by_user_by_event_name WHERE sum_timer_wait != 0 ORDER BY user, sum_timer_wait DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW user_summary ( user" ", statements, statement_latency, statement_avg_latency, table_scans, file_ios, file_io_latency, current_connections, " "total_connections, unique_hosts, current_memory, total_memory_allocated ) AS SELECT IF(accounts.user IS NULL, 'backgr" "ound', accounts.user) AS user, SUM(stmt.total) AS statements, sys.format_time(SUM(stmt.total_latency)) AS statement_l" "atency, sys.format_time(IFNULL(SUM(stmt.total_latency) / NULLIF(SUM(stmt.total), 0), 0)) AS statement_avg_latency, SU" "M(stmt.full_scans) AS table_scans, SUM(io.ios) AS file_ios, sys.format_time(SUM(io.io_latency)) AS file_io_latency, S" "UM(accounts.current_connections) AS current_connections, SUM(accounts.total_connections) AS total_connections, COUNT(" "DISTINCT host) AS unique_hosts, sys.format_bytes(SUM(mem.current_allocated)) AS current_memory, sys.format_bytes(SUM(" "mem.total_allocated)) AS total_memory_allocated FROM performance_schema.accounts LEFT JOIN sys.x$user_summary_by_stat" "ement_latency AS stmt ON IF(accounts.user IS NULL, 'background', accounts.user) = stmt.user LEFT JOIN sys.x$user_summ" "ary_by_file_io AS io ON IF(accounts.user IS NULL, 'background', accounts.user) = io.user LEFT JOIN sys.x$memory_by_us" "er_by_current_bytes mem ON IF(accounts.user IS NULL, 'background', accounts.user) = mem.user GROUP BY IF(accounts.use" "r IS NULL, 'background', accounts.user) ORDER BY SUM(stmt.total_latency) DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$user_summary ( us" "er, statements, statement_latency, statement_avg_latency, table_scans, file_ios, file_io_latency, current_connections" ", total_connections, unique_hosts, current_memory, total_memory_allocated ) AS SELECT IF(accounts.user IS NULL, 'back" "ground', accounts.user) AS user, SUM(stmt.total) AS statements, SUM(stmt.total_latency) AS statement_latency, IFNULL(" "SUM(stmt.total_latency) / NULLIF(SUM(stmt.total), 0), 0) AS statement_avg_latency, SUM(stmt.full_scans) AS table_scan" "s, SUM(io.ios) AS file_ios, SUM(io.io_latency) AS file_io_latency, SUM(accounts.current_connections) AS current_conne" "ctions, SUM(accounts.total_connections) AS total_connections, COUNT(DISTINCT host) AS unique_hosts, SUM(mem.current_a" "llocated) AS current_memory, SUM(mem.total_allocated) AS total_memory_allocated FROM performance_schema.accounts LEFT" " JOIN sys.x$user_summary_by_statement_latency AS stmt ON IF(accounts.user IS NULL, 'background', accounts.user) = stm" "t.user LEFT JOIN sys.x$user_summary_by_file_io AS io ON IF(accounts.user IS NULL, 'background', accounts.user) = io.u" "ser LEFT JOIN sys.x$memory_by_user_by_current_bytes mem ON IF(accounts.user IS NULL, 'background', accounts.user) = m" "em.user GROUP BY IF(accounts.user IS NULL, 'background', accounts.user) ORDER BY SUM(stmt.total_latency) DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW host_summary_by_file_io" "_type ( host, event_name, total, total_latency, max_latency ) AS SELECT IF(host IS NULL, 'background', host) AS host," " event_name, count_star AS total, sys.format_time(sum_timer_wait) AS total_latency, sys.format_time(max_timer_wait) A" "S max_latency FROM performance_schema.events_waits_summary_by_host_by_event_name WHERE event_name LIKE 'wait/io/file%" "' AND count_star > 0 ORDER BY IF(host IS NULL, 'background', host), sum_timer_wait DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$host_summary_by_file_" "io_type ( host, event_name, total, total_latency, max_latency ) AS SELECT IF(host IS NULL, 'background', host) AS hos" "t, event_name, count_star AS total, sum_timer_wait AS total_latency, max_timer_wait AS max_latency FROM performance_s" "chema.events_waits_summary_by_host_by_event_name WHERE event_name LIKE 'wait/io/file%' AND count_star > 0 ORDER BY IF" "(host IS NULL, 'background', host), sum_timer_wait DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW host_summary_by_fil" "e_io ( host, ios, io_latency ) AS SELECT IF(host IS NULL, 'background', host) AS host, SUM(count_star) AS ios, sys.fo" "rmat_time(SUM(sum_timer_wait)) AS io_latency FROM performance_schema.events_waits_summary_by_host_by_event_name WHER" "E event_name LIKE 'wait/io/file/%' GROUP BY IF(host IS NULL, 'background', host) ORDER BY SUM(sum_timer_wait) DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$host_summary_by_f" "ile_io ( host, ios, io_latency ) AS SELECT IF(host IS NULL, 'background', host) AS host, SUM(count_star) AS ios, SUM(" "sum_timer_wait) AS io_latency FROM performance_schema.events_waits_summary_by_host_by_event_name WHERE event_name LI" "KE 'wait/io/file/%' GROUP BY IF(host IS NULL, 'background', host) ORDER BY SUM(sum_timer_wait) DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW host_summary_by_stateme" "nt_type ( host, statement, total, total_latency, max_latency, lock_latency, rows_sent, rows_examined, rows_affected, " "full_scans ) AS SELECT IF(host IS NULL, 'background', host) AS host, SUBSTRING_INDEX(event_name, '/', -1) AS statemen" "t, count_star AS total, sys.format_time(sum_timer_wait) AS total_latency, sys.format_time(max_timer_wait) AS max_late" "ncy, sys.format_time(sum_lock_time) AS lock_latency, sum_rows_sent AS rows_sent, sum_rows_examined AS rows_examined, " "sum_rows_affected AS rows_affected, sum_no_index_used + sum_no_good_index_used AS full_scans FROM performance_schema." "events_statements_summary_by_host_by_event_name WHERE sum_timer_wait != 0 ORDER BY IF(host IS NULL, 'background', hos" "t), sum_timer_wait DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$host_summary_by_state" "ment_type ( host, statement, total, total_latency, max_latency, lock_latency, rows_sent, rows_examined, rows_affected" ", full_scans ) AS SELECT IF(host IS NULL, 'background', host) AS host, SUBSTRING_INDEX(event_name, '/', -1) AS statem" "ent, count_star AS total, sum_timer_wait AS total_latency, max_timer_wait AS max_latency, sum_lock_time AS lock_laten" "cy, sum_rows_sent AS rows_sent, sum_rows_examined AS rows_examined, sum_rows_affected AS rows_affected, sum_no_index_" "used + sum_no_good_index_used AS full_scans FROM performance_schema.events_statements_summary_by_host_by_event_name W" "HERE sum_timer_wait != 0 ORDER BY IF(host IS NULL, 'background', host), sum_timer_wait DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW host_summary_by_sta" "tement_latency ( host, total, total_latency, max_latency, lock_latency, rows_sent, rows_examined, rows_affected, full" "_scans ) AS SELECT IF(host IS NULL, 'background', host) AS host, SUM(count_star) AS total, sys.format_time(SUM(sum_ti" "mer_wait)) AS total_latency, sys.format_time(MAX(max_timer_wait)) AS max_latency, sys.format_time(SUM(sum_lock_time))" " AS lock_latency, SUM(sum_rows_sent) AS rows_sent, SUM(sum_rows_examined) AS rows_examined, SUM(sum_rows_affected) AS" " rows_affected, SUM(sum_no_index_used) + SUM(sum_no_good_index_used) AS full_scans FROM performance_schema.events_sta" "tements_summary_by_host_by_event_name GROUP BY IF(host IS NULL, 'background', host) ORDER BY SUM(sum_timer_wait) DESC" ";\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$host_summary_by_s" "tatement_latency ( host, total, total_latency, max_latency, lock_latency, rows_sent, rows_examined, rows_affected, fu" "ll_scans ) AS SELECT IF(host IS NULL, 'background', host) AS host, SUM(count_star) AS total, SUM(sum_timer_wait) AS t" "otal_latency, MAX(max_timer_wait) AS max_latency, SUM(sum_lock_time) AS lock_latency, SUM(sum_rows_sent) AS rows_sent" ", SUM(sum_rows_examined) AS rows_examined, SUM(sum_rows_affected) AS rows_affected, SUM(sum_no_index_used) + SUM(sum_" "no_good_index_used) AS full_scans FROM performance_schema.events_statements_summary_by_host_by_event_name GROUP BY IF" "(host IS NULL, 'background', host) ORDER BY SUM(sum_timer_wait) DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW host_summary_by_stages " "( host, event_name, total, total_latency, avg_latency ) AS SELECT IF(host IS NULL, 'background', host) AS host, event" "_name, count_star AS total, sys.format_time(sum_timer_wait) AS total_latency, sys.format_time(avg_timer_wait) AS avg" "_latency FROM performance_schema.events_stages_summary_by_host_by_event_name WHERE sum_timer_wait != 0 ORDER BY IF(h" "ost IS NULL, 'background', host), sum_timer_wait DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$host_summary_by_stage" "s ( host, event_name, total, total_latency, avg_latency ) AS SELECT IF(host IS NULL, 'background', host) AS host, eve" "nt_name, count_star AS total, sum_timer_wait AS total_latency, avg_timer_wait AS avg_latency FROM performance_schem" "a.events_stages_summary_by_host_by_event_name WHERE sum_timer_wait != 0 ORDER BY IF(host IS NULL, 'background', host)" ", sum_timer_wait DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW host_summary ( host" ", statements, statement_latency, statement_avg_latency, table_scans, file_ios, file_io_latency, current_connections, " "total_connections, unique_users, current_memory, total_memory_allocated ) AS SELECT IF(accounts.host IS NULL, 'backgr" "ound', accounts.host) AS host, SUM(stmt.total) AS statements, sys.format_time(SUM(stmt.total_latency)) AS statement_l" "atency, sys.format_time(IFNULL(SUM(stmt.total_latency) / NULLIF(SUM(stmt.total), 0), 0)) AS statement_avg_latency, SU" "M(stmt.full_scans) AS table_scans, SUM(io.ios) AS file_ios, sys.format_time(SUM(io.io_latency)) AS file_io_latency, S" "UM(accounts.current_connections) AS current_connections, SUM(accounts.total_connections) AS total_connections, COUNT(" "DISTINCT user) AS unique_users, sys.format_bytes(SUM(mem.current_allocated)) AS current_memory, sys.format_bytes(SUM(" "mem.total_allocated)) AS total_memory_allocated FROM performance_schema.accounts JOIN sys.x$host_summary_by_statement" "_latency AS stmt ON accounts.host = stmt.host JOIN sys.x$host_summary_by_file_io AS io ON accounts.host = io.host JOI" "N sys.x$memory_by_host_by_current_bytes mem ON accounts.host = mem.host GROUP BY IF(accounts.host IS NULL, 'backgroun" "d', accounts.host);\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$host_summary ( ho" "st, statements, statement_latency, statement_avg_latency, table_scans, file_ios, file_io_latency, current_connections" ", total_connections, unique_users, current_memory, total_memory_allocated ) AS SELECT IF(accounts.host IS NULL, 'back" "ground', accounts.host) AS host, SUM(stmt.total) AS statements, SUM(stmt.total_latency) AS statement_latency, SUM(stm" "t.total_latency) / SUM(stmt.total) AS statement_avg_latency, SUM(stmt.full_scans) AS table_scans, SUM(io.ios) AS file" "_ios, SUM(io.io_latency) AS file_io_latency, SUM(accounts.current_connections) AS current_connections, SUM(accounts.t" "otal_connections) AS total_connections, COUNT(DISTINCT accounts.user) AS unique_users, SUM(mem.current_allocated) AS " "current_memory, SUM(mem.total_allocated) AS total_memory_allocated FROM performance_schema.accounts JOIN sys.x$host_s" "ummary_by_statement_latency AS stmt ON accounts.host = stmt.host JOIN sys.x$host_summary_by_file_io AS io ON accounts" ".host = io.host JOIN sys.x$memory_by_host_by_current_bytes mem ON accounts.host = mem.host GROUP BY IF(accounts.host " "IS NULL, 'background', accounts.host);\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW wait_classes_global" "_by_avg_latency ( event_class, total, total_latency, min_latency, avg_latency, max_latency ) AS SELECT SUBSTRING_INDE" "X(event_name,'/', 3) AS event_class, SUM(COUNT_STAR) AS total, sys.format_time(CAST(SUM(sum_timer_wait) AS UNSIGNED))" " AS total_latency, sys.format_time(MIN(min_timer_wait)) AS min_latency, sys.format_time(IFNULL(SUM(sum_timer_wait) / " "NULLIF(SUM(COUNT_STAR), 0), 0)) AS avg_latency, sys.format_time(CAST(MAX(max_timer_wait) AS UNSIGNED)) AS max_latency" " FROM performance_schema.events_waits_summary_global_by_event_name WHERE sum_timer_wait > 0 AND event_name != 'idle' " "GROUP BY event_class ORDER BY IFNULL(SUM(sum_timer_wait) / NULLIF(SUM(COUNT_STAR), 0), 0) DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$wait_classes_glob" "al_by_avg_latency ( event_class, total, total_latency, min_latency, avg_latency, max_latency ) AS SELECT SUBSTRING_IN" "DEX(event_name,'/', 3) AS event_class, SUM(COUNT_STAR) AS total, SUM(sum_timer_wait) AS total_latency, MIN(min_timer_" "wait) AS min_latency, IFNULL(SUM(sum_timer_wait) / NULLIF(SUM(COUNT_STAR), 0), 0) AS avg_latency, MAX(max_timer_wait)" " AS max_latency FROM performance_schema.events_waits_summary_global_by_event_name WHERE sum_timer_wait > 0 AND event_" "name != 'idle' GROUP BY event_class ORDER BY IFNULL(SUM(sum_timer_wait) / NULLIF(SUM(COUNT_STAR), 0), 0) DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW wait_classes_global" "_by_latency ( event_class, total, total_latency, min_latency, avg_latency, max_latency ) AS SELECT SUBSTRING_INDEX(ev" "ent_name,'/', 3) AS event_class, SUM(COUNT_STAR) AS total, sys.format_time(SUM(sum_timer_wait)) AS total_latency, sy" "s.format_time(MIN(min_timer_wait)) min_latency, sys.format_time(IFNULL(SUM(sum_timer_wait) / NULLIF(SUM(COUNT_STAR), " "0), 0)) AS avg_latency, sys.format_time(MAX(max_timer_wait)) AS max_latency FROM performance_schema.events_waits_summ" "ary_global_by_event_name WHERE sum_timer_wait > 0 AND event_name != 'idle' GROUP BY SUBSTRING_INDEX(event_name,'/', 3" ") ORDER BY SUM(sum_timer_wait) DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$wait_classes_glob" "al_by_latency ( event_class, total, total_latency, min_latency, avg_latency, max_latency ) AS SELECT SUBSTRING_INDEX(" "event_name,'/', 3) AS event_class, SUM(COUNT_STAR) AS total, SUM(sum_timer_wait) AS total_latency, MIN(min_timer_wai" "t) AS min_latency, IFNULL(SUM(sum_timer_wait) / NULLIF(SUM(COUNT_STAR), 0), 0) AS avg_latency, MAX(max_timer_wait) AS" " max_latency FROM performance_schema.events_waits_summary_global_by_event_name WHERE sum_timer_wait > 0 AND event_nam" "e != 'idle' GROUP BY SUBSTRING_INDEX(event_name,'/', 3) ORDER BY SUM(sum_timer_wait) DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW waits_by_user_by_latenc" "y ( user, event, total, total_latency, avg_latency, max_latency ) AS SELECT IF(user IS NULL, 'background', user) AS u" "ser, event_name AS event, count_star AS total, sys.format_time(sum_timer_wait) AS total_latency, sys.format_time(avg_" "timer_wait) AS avg_latency, sys.format_time(max_timer_wait) AS max_latency FROM performance_schema.events_waits_summa" "ry_by_user_by_event_name WHERE event_name != 'idle' AND user IS NOT NULL AND sum_timer_wait > 0 ORDER BY user, sum_ti" "mer_wait DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$waits_by_user_by_late" "ncy ( user, event, total, total_latency, avg_latency, max_latency ) AS SELECT IF(user IS NULL, 'background', user) AS" " user, event_name AS event, count_star AS total, sum_timer_wait AS total_latency, avg_timer_wait AS avg_latency, max_" "timer_wait AS max_latency FROM performance_schema.events_waits_summary_by_user_by_event_name WHERE event_name != 'idl" "e' AND user IS NOT NULL AND sum_timer_wait > 0 ORDER BY user, sum_timer_wait DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW waits_by_host_by_latenc" "y ( host, event, total, total_latency, avg_latency, max_latency ) AS SELECT IF(host IS NULL, 'background', host) AS h" "ost, event_name AS event, count_star AS total, sys.format_time(sum_timer_wait) AS total_latency, sys.format_time(avg_" "timer_wait) AS avg_latency, sys.format_time(max_timer_wait) AS max_latency FROM performance_schema.events_waits_summa" "ry_by_host_by_event_name WHERE event_name != 'idle' AND sum_timer_wait > 0 ORDER BY host, sum_timer_wait DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$waits_by_host_by_late" "ncy ( host, event, total, total_latency, avg_latency, max_latency ) AS SELECT IF(host IS NULL, 'background', host) AS" " host, event_name AS event, count_star AS total, sum_timer_wait AS total_latency, avg_timer_wait AS avg_latency, max_" "timer_wait AS max_latency FROM performance_schema.events_waits_summary_by_host_by_event_name WHERE event_name != 'idl" "e' AND sum_timer_wait > 0 ORDER BY host, sum_timer_wait DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW waits_global_by_latency" " ( events, total, total_latency, avg_latency, max_latency ) AS SELECT event_name AS event, count_star AS total, sys.f" "ormat_time(sum_timer_wait) AS total_latency, sys.format_time(avg_timer_wait) AS avg_latency, sys.format_time(max_time" "r_wait) AS max_latency FROM performance_schema.events_waits_summary_global_by_event_name WHERE event_name != 'idle' A" "ND sum_timer_wait > 0 ORDER BY sum_timer_wait DESC;\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$waits_global_by_laten" "cy ( events, total, total_latency, avg_latency, max_latency ) AS SELECT event_name AS event, count_star AS total, sum" "_timer_wait AS total_latency, avg_timer_wait AS avg_latency, max_timer_wait AS max_latency FROM performance_schema.ev" "ents_waits_summary_global_by_event_name WHERE event_name != 'idle' AND sum_timer_wait > 0 ORDER BY sum_timer_wait DES" "C;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW metrics ( Variable_" "name, Variable_value, Type, Enabled ) AS ( SELECT LOWER(VARIABLE_NAME) AS Variable_name, VARIABLE_VALUE AS Variable_v" "alue, 'Global Status' AS Type, 'YES' AS Enabled FROM performance_schema.global_status ) UNION ALL ( SELECT NAME AS Va" "riable_name, COUNT AS Variable_value, CONCAT('InnoDB Metrics - ', SUBSYSTEM) AS Type, IF(STATUS = 'enabled', 'YES', '" "NO') AS Enabled FROM information_schema.INNODB_METRICS WHERE NAME NOT IN ( 'lock_row_lock_time', 'lock_row_lock_time_" "avg', 'lock_row_lock_time_max', 'lock_row_lock_waits', 'buffer_pool_reads', 'buffer_pool_read_requests', 'buffer_pool" "_write_requests', 'buffer_pool_wait_free', 'buffer_pool_read_ahead', 'buffer_pool_read_ahead_evicted', 'buffer_pool_p" "ages_total', 'buffer_pool_pages_misc', 'buffer_pool_pages_data', 'buffer_pool_bytes_data', 'buffer_pool_pages_dirty'," " 'buffer_pool_bytes_dirty', 'buffer_pool_pages_free', 'buffer_pages_created', 'buffer_pages_written', 'buffer_pages_r" "ead', 'buffer_data_reads', 'buffer_data_written', 'file_num_open_files', 'os_log_bytes_written', 'os_log_fsyncs', 'os" "_log_pending_fsyncs', 'os_log_pending_writes', 'log_waits', 'log_write_requests', 'log_writes', 'innodb_dblwr_writes'" ", 'innodb_dblwr_pages_written', 'innodb_page_size') ) /*!50702 UNION ALL ( SELECT 'memory_current_allocated' AS Varia" "ble_name, SUM(CURRENT_NUMBER_OF_BYTES_USED) AS Variable_value, 'Performance Schema' AS Type, IF((SELECT COUNT(*) FROM" " performance_schema.setup_instruments WHERE NAME LIKE 'memory/%' AND ENABLED = 'YES') = 0, 'NO', IF((SELECT COUNT(*) " "FROM performance_schema.setup_instruments WHERE NAME LIKE 'memory/%' AND ENABLED = 'YES') = (SELECT COUNT(*) FROM per" "formance_schema.setup_instruments WHERE NAME LIKE 'memory/%'), 'YES', 'PARTIAL')) AS Enabled FROM performance_schema." "memory_summary_global_by_event_name ) UNION ALL ( SELECT 'memory_total_allocated' AS Variable_name, SUM(SUM_NUMBER_OF" "_BYTES_ALLOC) AS Variable_value, 'Performance Schema' AS Type, IF((SELECT COUNT(*) FROM performance_schema.setup_inst" "ruments WHERE NAME LIKE 'memory/%' AND ENABLED = 'YES') = 0, 'NO', IF((SELECT COUNT(*) FROM performance_schema.setup_" "instruments WHERE NAME LIKE 'memory/%' AND ENABLED = 'YES') = (SELECT COUNT(*) FROM performance_schema.setup_instrume" "nts WHERE NAME LIKE 'memory/%'), 'YES', 'PARTIAL')) AS Enabled FROM performance_schema.memory_summary_global_by_event" "_name ) */ UNION ALL ( SELECT 'NOW()' AS Variable_name, NOW(3) AS Variable_value, 'System Time' AS Type, 'YES' AS Ena" "bled ) UNION ALL ( SELECT 'UNIX_TIMESTAMP()' AS Variable_name, ROUND(UNIX_TIMESTAMP(NOW(3)), 3) AS Variable_value, 'S" "ystem Time' AS Type, 'YES' AS Enabled ) ORDER BY Type, Variable_name;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW processlist ( thd_id" ", conn_id, user, db, command, state, time, current_statement, statement_latency, progress, lock_latency, rows_examine" "d, rows_sent, rows_affected, tmp_tables, tmp_disk_tables, full_scan, last_statement, last_statement_latency, current_" "memory, last_wait, last_wait_latency, source, trx_latency, trx_state, trx_autocommit, pid, program_name ) AS SELECT p" "ps.thread_id AS thd_id, pps.processlist_id AS conn_id, IF(pps.name IN ('thread/sql/one_connection', 'thread/thread_po" "ol/tp_one_connection'), CONCAT(pps.processlist_user, '@', pps.processlist_host), REPLACE(pps.name, 'thread/', '')) us" "er, pps.processlist_db AS db, pps.processlist_command AS command, pps.processlist_state AS state, pps.processlist_tim" "e AS time, sys.format_statement(pps.processlist_info) AS current_statement, IF(esc.end_event_id IS NULL, sys.format_t" "ime(esc.timer_wait), NULL) AS statement_latency, IF(esc.end_event_id IS NULL, ROUND(100 * (estc.work_completed / estc" ".work_estimated), 2), NULL) AS progress, sys.format_time(esc.lock_time) AS lock_latency, esc.rows_examined AS rows_ex" "amined, esc.rows_sent AS rows_sent, esc.rows_affected AS rows_affected, esc.created_tmp_tables AS tmp_tables, esc.cre" "ated_tmp_disk_tables AS tmp_disk_tables, IF(esc.no_good_index_used > 0 OR esc.no_index_used > 0, 'YES', 'NO') AS full" "_scan, IF(esc.end_event_id IS NOT NULL, sys.format_statement(esc.sql_text), NULL) AS last_statement, IF(esc.end_event" "_id IS NOT NULL, sys.format_time(esc.timer_wait), NULL) AS last_statement_latency, sys.format_bytes(mem.current_alloc" "ated) AS current_memory, ewc.event_name AS last_wait, IF(ewc.end_event_id IS NULL AND ewc.event_name IS NOT NULL, 'St" "ill Waiting', sys.format_time(ewc.timer_wait)) last_wait_latency, ewc.source, sys.format_time(etc.timer_wait) AS trx_" "latency, etc.state AS trx_state, etc.autocommit AS trx_autocommit, conattr_pid.attr_value as pid, conattr_progname.at" "tr_value as program_name FROM performance_schema.threads AS pps LEFT JOIN performance_schema.events_waits_current AS " "ewc USING (thread_id) LEFT JOIN performance_schema.events_stages_current AS estc USING (thread_id) LEFT JOIN performa" "nce_schema.events_statements_current AS esc USING (thread_id) LEFT JOIN performance_schema.events_transactions_curren" "t AS etc USING (thread_id) LEFT JOIN sys.x$memory_by_thread_by_current_bytes AS mem USING (thread_id) LEFT JOIN perfo" "rmance_schema.session_connect_attrs AS conattr_pid ON conattr_pid.processlist_id=pps.processlist_id and conattr_pid.a" "ttr_name='_pid' LEFT JOIN performance_schema.session_connect_attrs AS conattr_progname ON conattr_progname.processlis" "t_id=pps.processlist_id and conattr_progname.attr_name='program_name' ORDER BY pps.processlist_time DESC, last_wait_l" "atency DESC;\n", "CREATE OR REPLACE ALGORITHM = TEMPTABLE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$processlist ( thd_" "id, conn_id, user, db, command, state, time, current_statement, statement_latency, progress, lock_latency, rows_exami" "ned, rows_sent, rows_affected, tmp_tables, tmp_disk_tables, full_scan, last_statement, last_statement_latency, curren" "t_memory, last_wait, last_wait_latency, source, trx_latency, trx_state, trx_autocommit, pid, program_name ) AS SELECT" " pps.thread_id AS thd_id, pps.processlist_id AS conn_id, IF(pps.name IN ('thread/sql/one_connection', 'thread/thread_" "pool/tp_one_connection'), CONCAT(pps.processlist_user, '@', pps.processlist_host), REPLACE(pps.name, 'thread/', '')) " "user, pps.processlist_db AS db, pps.processlist_command AS command, pps.processlist_state AS state, pps.processlist_t" "ime AS time, pps.processlist_info AS current_statement, IF(esc.end_event_id IS NULL, esc.timer_wait, NULL) AS stateme" "nt_latency, IF(esc.end_event_id IS NULL, ROUND(100 * (estc.work_completed / estc.work_estimated), 2), NULL) AS progre" "ss, esc.lock_time AS lock_latency, esc.rows_examined AS rows_examined, esc.rows_sent AS rows_sent, esc.rows_affected " "AS rows_affected, esc.created_tmp_tables AS tmp_tables, esc.created_tmp_disk_tables AS tmp_disk_tables, IF(esc.no_goo" "d_index_used > 0 OR esc.no_index_used > 0, 'YES', 'NO') AS full_scan, IF(esc.end_event_id IS NOT NULL, esc.sql_text, " "NULL) AS last_statement, IF(esc.end_event_id IS NOT NULL, esc.timer_wait, NULL) AS last_statement_latency, mem.curren" "t_allocated AS current_memory, ewc.event_name AS last_wait, IF(ewc.end_event_id IS NULL AND ewc.event_name IS NOT NUL" "L, 'Still Waiting', ewc.timer_wait) last_wait_latency, ewc.source, etc.timer_wait AS trx_latency, etc.state AS trx_s" "tate, etc.autocommit AS trx_autocommit, conattr_pid.attr_value as pid, conattr_progname.attr_value as program_name FR" "OM performance_schema.threads AS pps LEFT JOIN performance_schema.events_waits_current AS ewc USING (thread_id) LEFT " "JOIN performance_schema.events_stages_current AS estc USING (thread_id) LEFT JOIN performance_schema.events_statement" "s_current AS esc USING (thread_id) LEFT JOIN performance_schema.events_transactions_current AS etc USING (thread_id) " "LEFT JOIN sys.x$memory_by_thread_by_current_bytes AS mem USING (thread_id) LEFT JOIN performance_schema.session_conne" "ct_attrs AS conattr_pid ON conattr_pid.processlist_id=pps.processlist_id and conattr_pid.attr_name='_pid' LEFT JOIN p" "erformance_schema.session_connect_attrs AS conattr_progname ON conattr_progname.processlist_id=pps.processlist_id and" " conattr_progname.attr_name='program_name' ORDER BY pps.processlist_time DESC, last_wait_latency DESC;\n", "CREATE OR REPLACE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW session AS SELECT * FROM sys.processlist " "WHERE conn_id IS NOT NULL AND command != 'Daemon';\n", "CREATE OR REPLACE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW x$session AS SELECT * FROM sys.x$processl" "ist WHERE conn_id IS NOT NULL AND command != 'Daemon';\n", "CREATE OR REPLACE ALGORITHM = MERGE DEFINER = 'mysql.sys'@'localhost' SQL SECURITY INVOKER VIEW session_ssl_status ( thr" "ead_id, ssl_version, ssl_cipher, ssl_sessions_reused ) AS SELECT sslver.thread_id, sslver.variable_value ssl_version" ", sslcip.variable_value ssl_cipher, sslreuse.variable_value ssl_sessions_reused FROM performance_schema.status_by_th" "read sslver LEFT JOIN performance_schema.status_by_thread sslcip ON (sslcip.thread_id=sslver.thread_id and sslcip.v" "ariable_name='Ssl_cipher') LEFT JOIN performance_schema.status_by_thread sslreuse ON (sslreuse.thread_id=sslver.thre" "ad_id and sslreuse.variable_name='Ssl_sessions_reused') WHERE sslver.variable_name='Ssl_version';\n", "DROP PROCEDURE IF EXISTS create_synonym_db;\n", "CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE create_synonym_db ( IN in_db_name VARCHAR(64), IN in_synonym VARCHAR(6" "4) ) COMMENT '\\n Description\\n \\n Takes a source database name and synonym name, and then creates the \\n synonym data" "base with views that point to all of the tables within\\n the source database.\\n \\n Useful for creating a \"ps\" synon" "ym for \"performance_schema\",\\n or \"is\" instead of \"information_schema\", for example.\\n \\n Parameters\\n \\n in_db" "_name (VARCHAR(64)):\\n The database name that you would like to create a synonym for.\\n in_synonym (VARCHAR(64)):\\n T" "he database synonym name.\\n \\n Example\\n \\n mysql> SHOW DATABASES;\\n +--------------------+\\n | Database |\\" "n +--------------------+\\n | information_schema |\\n | mysql |\\n | performance_schema |\\n | sys " " |\\n | test |\\n +--------------------+\\n 5 rows in set (0.00 sec)\\n \\n mysql> CALL sys.create_syno" "nym_db(\\'performance_schema\\', \\'ps\\');\\n +---------------------------------------+\\n | summary " " |\\n +---------------------------------------+\\n | Created 74 views in the `ps` database |\\n +---------------" "------------------------+\\n 1 row in set (8.57 sec)\\n \\n Query OK, 0 rows affected (8.57 sec)\\n \\n mysql> SHOW DATABA" "SES;\\n +--------------------+\\n | Database |\\n +--------------------+\\n | information_schema |\\n | mysql " " |\\n | performance_schema |\\n | ps |\\n | sys |\\n | test |\\n +-" "-------------------+\\n 6 rows in set (0.00 sec)\\n \\n mysql> SHOW FULL TABLES FROM ps;\\n +----------------------------" "--------------------------+------------+\\n | Tables_in_ps | Table_type |\\n +-" "-----------------------------------------------------+------------+\\n | accounts " " | VIEW |\\n | cond_instances | VIEW |\\n | events_stages_curr" "ent | VIEW |\\n | events_stages_history | VIEW " " |\\n ...\\n ' SQL SECURITY INVOKER NOT DETERMINISTIC MODIFIES SQL DATA BEGIN DECLARE v_done bool DEFAULT FALSE; DECL" "ARE v_db_name_check VARCHAR(64); DECLARE v_db_err_msg TEXT; DECLARE v_table VARCHAR(64); DECLARE v_views_created INT " "DEFAULT 0; DECLARE db_doesnt_exist CONDITION FOR SQLSTATE '42000'; DECLARE db_name_exists CONDITION FOR SQLSTATE 'HY" "000'; DECLARE c_table_names CURSOR FOR SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = in_d" "b_name; DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = TRUE; SELECT SCHEMA_NAME INTO v_db_name_check FROM INFO" "RMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = in_db_name; IF v_db_name_check IS NULL THEN SET v_db_err_msg = CONCAT('U" "nknown database ', in_db_name); SIGNAL SQLSTATE 'HY000' SET MESSAGE_TEXT = v_db_err_msg; END IF; SELECT SCHEMA_NAME " "INTO v_db_name_check FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = in_synonym; IF v_db_name_check = in_synony" "m THEN SET v_db_err_msg = CONCAT('Can\\'t create database ', in_synonym, '; database exists'); SIGNAL SQLSTATE 'HY000'" " SET MESSAGE_TEXT = v_db_err_msg; END IF; SET @create_db_stmt := CONCAT('CREATE DATABASE ', sys.quote_identifier(in_" "synonym)); PREPARE create_db_stmt FROM @create_db_stmt; EXECUTE create_db_stmt; DEALLOCATE PREPARE create_db_stmt; S" "ET v_done = FALSE; OPEN c_table_names; c_table_names: LOOP FETCH c_table_names INTO v_table; IF v_done THEN LEAVE c_t" "able_names; END IF; SET @create_view_stmt = CONCAT( 'CREATE SQL SECURITY INVOKER VIEW ', sys.quote_identifier(in_syn" "onym), '.', sys.quote_identifier(v_table), ' AS SELECT * FROM ', sys.quote_identifier(in_db_name), '.', sys.quote_ide" "ntifier(v_table) ); PREPARE create_view_stmt FROM @create_view_stmt; EXECUTE create_view_stmt; DEALLOCATE PREPARE cre" "ate_view_stmt; SET v_views_created = v_views_created + 1; END LOOP; CLOSE c_table_names; SELECT CONCAT( 'Created '," " v_views_created, ' view', IF(v_views_created != 1, 's', ''), ' in the ', sys.quote_identifier(in_synonym), ' databas" "e' ) AS summary; END;\n", "DROP PROCEDURE IF EXISTS execute_prepared_stmt;\n", "CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE execute_prepared_stmt ( IN in_query longtext CHARACTER SET UTF8 ) COMME" "NT '\\n Description\\n \\n Takes the query in the argument and executes it using a prepared statement. The prepared stat" "ement is deallocated,\\n so the procedure is mainly useful for executing one off dynamically created queries.\\n \\n The" " sys_execute_prepared_stmt prepared statement name is used for the query and is required not to exist.\\n \\n \\n Parame" "ters\\n \\n in_query (longtext CHARACTER SET UTF8):\\n The query to execute.\\n \\n \\n Configuration Options\\n \\n sys.debu" "g\\n Whether to provide debugging output.\\n Default is ''OFF''. Set to ''ON'' to include.\\n \\n \\n Example\\n \\n mysql> " "CALL sys.execute_prepared_stmt(''SELECT * FROM sys.sys_config'');\\n +------------------------+-------+---------------" "------+--------+\\n | variable | value | set_time | set_by |\\n +------------------------+----" "---+---------------------+--------+\\n | statement_truncate_len | 64 | 2015-06-30 13:06:00 | NULL |\\n +----------" "--------------+-------+---------------------+--------+\\n 1 row in set (0.00 sec)\\n \\n Query OK, 0 rows affected (0.00" " sec)\\n ' SQL SECURITY INVOKER NOT DETERMINISTIC READS SQL DATA BEGIN IF (@sys.debug IS NULL) THEN SET @sys.debug = s" "ys.sys_get_config('debug', 'OFF'); END IF; IF (in_query IS NULL OR LENGTH(in_query) < 4) THEN SIGNAL SQLSTATE '45000" "' SET MESSAGE_TEXT = \"The @sys.execute_prepared_stmt.sql must contain a query\"; END IF; SET @sys.execute_prepared_" "stmt.sql = in_query; IF (@sys.debug = 'ON') THEN SELECT @sys.execute_prepared_stmt.sql AS 'Debug'; END IF; PREPARE s" "ys_execute_prepared_stmt FROM @sys.execute_prepared_stmt.sql; EXECUTE sys_execute_prepared_stmt; DEALLOCATE PREPARE s" "ys_execute_prepared_stmt; SET @sys.execute_prepared_stmt.sql = NULL; END;\n", "DROP PROCEDURE IF EXISTS diagnostics;\n", "CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE diagnostics ( IN in_max_runtime int unsigned, IN in_interval int unsign" "ed, IN in_auto_config enum ('current', 'medium', 'full') ) COMMENT '\\n Description\\n \\n Create a report of the curren" "t status of the server for diagnostics purposes. Data collected includes (some items depends on versions and settings" "):\\n \\n * The GLOBAL VARIABLES\\n * Several sys schema views including metrics or equivalent (depending on version and" " settings)\\n * Queries in the 95th percentile\\n * Several ndbinfo views for MySQL Cluster\\n * Replication (both maste" "r and slave) information.\\n \\n Some of the sys schema views are calculated as initial (optional), overall, delta:\\n \\" "n * The initial view is the content of the view at the start of this procedure.\\n This output will be the same as the" " the start values used for the delta view.\\n The initial view is included if @sys.diagnostics.include_raw = ''ON''.\\n" " * The overall view is the content of the view at the end of this procedure.\\n This output is the same as the end val" "ues used for the delta view.\\n The overall view is always included.\\n * The delta view is the difference from the beg" "inning to the end. Note that for min and max values\\n they are simply the min or max value from the end view respecti" "vely, so does not necessarily reflect\\n the minimum/maximum value in the monitored period.\\n Note: except for the met" "rics views the delta is only calculation between the first and last outputs.\\n \\n Requires the SUPER privilege for \"" "SET sql_log_bin = 0;\".\\n \\n Versions supported:\\n * MySQL 5.6: 5.6.10 and later\\n * MySQL 5.7: 5.7.9 and later\\n \\n " "Parameters\\n \\n in_max_runtime (INT UNSIGNED):\\n The maximum time to keep collecting data.\\n Use NULL to get the defa" "ult which is 60 seconds, otherwise enter a value greater than 0.\\n in_interval (INT UNSIGNED):\\n How long to sleep be" "tween data collections.\\n Use NULL to get the default which is 30 seconds, otherwise enter a value greater than 0.\\n " "in_auto_config (ENUM(''current'', ''medium'', ''full''))\\n Automatically enable Performance Schema instruments and co" "nsumers.\\n NOTE: The more that are enabled, the more impact on the performance.\\n Supported values are:\\n * current -" " use the current settings.\\n * medium - enable some settings.\\n * full - enables all settings. This will have a big i" "mpact on the\\n performance - be careful using this option.\\n If another setting the ''current'' is chosen, the curren" "t settings\\n are restored at the end of the procedure.\\n \\n \\n Configuration Options\\n \\n sys.diagnostics.allow_i_s_t" "ables\\n Specifies whether it is allowed to do table scan queries on information_schema.TABLES. This can be expensive " "if there\\n are many tables. Set to ''ON'' to allow, ''OFF'' to not allow.\\n Default is ''OFF''.\\n \\n sys.diagnostics." "include_raw\\n Set to ''ON'' to include the raw data (e.g. the original output of \"SELECT * FROM sys.metrics\").\\n Us" "e this to get the initial values of the various views.\\n Default is ''OFF''.\\n \\n sys.statement_truncate_len\\n How mu" "ch of queries in the process list output to include.\\n Default is 64.\\n \\n sys.debug\\n Whether to provide debugging o" "utput.\\n Default is ''OFF''. Set to ''ON'' to include.\\n \\n \\n Example\\n \\n To create a report and append it to the f" "ile diag.out:\\n \\n mysql> TEE diag.out;\\n mysql> CALL sys.diagnostics(120, 30, ''current'');\\n ...\\n mysql> NOTEE;\\n " "' SQL SECURITY INVOKER NOT DETERMINISTIC READS SQL DATA BEGIN DECLARE v_start, v_runtime, v_iter_start, v_sleep DECIM" "AL(20,2) DEFAULT 0.0; DECLARE v_has_innodb, v_has_ndb, v_has_ps, v_has_replication, v_has_ps_replication VARCHAR(8) C" "HARSET utf8 DEFAULT 'NO'; DECLARE v_this_thread_enabled, v_has_ps_vars, v_has_metrics ENUM('YES', 'NO'); DECLARE v_ta" "ble_name, v_banner VARCHAR(64) CHARSET utf8; DECLARE v_sql_status_summary_select, v_sql_status_summary_delta, v_sql_s" "tatus_summary_from, v_no_delta_names TEXT; DECLARE v_output_time, v_output_time_prev DECIMAL(20,3) UNSIGNED; DECLARE " "v_output_count, v_count, v_old_group_concat_max_len INT UNSIGNED DEFAULT 0; DECLARE v_status_summary_width TINYINT UN" "SIGNED DEFAULT 50; DECLARE v_done BOOLEAN DEFAULT FALSE; DECLARE c_ndbinfo CURSOR FOR SELECT TABLE_NAME FROM informat" "ion_schema.TABLES WHERE TABLE_SCHEMA = 'ndbinfo' AND TABLE_NAME NOT IN ( 'blocks', 'config_params', 'dict_obj_types'," " 'disk_write_speed_base', 'memory_per_fragment', 'memoryusage', 'operations_per_fragment', 'threadblocks' ); DECLARE " "c_sysviews_w_delta CURSOR FOR SELECT table_name FROM tmp_sys_views_delta ORDER BY table_name; DECLARE CONTINUE HANDLE" "R FOR NOT FOUND SET v_done = TRUE; SELECT INSTRUMENTED INTO v_this_thread_enabled FROM performance_schema.threads WH" "ERE PROCESSLIST_ID = CONNECTION_ID(); IF (v_this_thread_enabled = 'YES') THEN CALL sys.ps_setup_disable_thread(CONNEC" "TION_ID()); END IF; IF (in_max_runtime < in_interval) THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'in_max_runtim" "e must be greater than or equal to in_interval'; END IF; IF (in_max_runtime = 0) THEN SIGNAL SQLSTATE '45000' SET MES" "SAGE_TEXT = 'in_max_runtime must be greater than 0'; END IF; IF (in_interval = 0) THEN SIGNAL SQLSTATE '45000' SET ME" "SSAGE_TEXT = 'in_interval must be greater than 0'; END IF; IF (@sys.diagnostics.allow_i_s_tables IS NULL) THEN SET @" "sys.diagnostics.allow_i_s_tables = sys.sys_get_config('diagnostics.allow_i_s_tables', 'OFF'); END IF; IF (@sys.diagno" "stics.include_raw IS NULL) THEN SET @sys.diagnostics.include_raw = sys.sys_get_config('diagnostics.include_raw' " " , 'OFF'); END IF; IF (@sys.debug IS NULL) THEN SET @sys.debug = sys.sys_get_config('debug'" " , 'OFF'); END IF; IF (@sys.statement_truncate_len IS NULL) THEN SET @sys.statement_truncate_le" "n = sys.sys_get_config('statement_truncate_len' , '64' ); END IF; SET @log_bin := @@sql_log_bin; IF (@log" "_bin = 1) THEN SET sql_log_bin = 0; END IF; SET v_no_delta_names = CONCAT('s%{COUNT}.Variable_name NOT IN (', '''inn" "odb_buffer_pool_pages_total'', ', '''innodb_page_size'', ', '''last_query_cost'', ', '''last_query_partial_plans'', '" ", '''qcache_total_blocks'', ', '''slave_last_heartbeat'', ', '''ssl_ctx_verify_depth'', ', '''ssl_ctx_verify_mode'', " "', '''ssl_session_cache_size'', ', '''ssl_verify_depth'', ', '''ssl_verify_mode'', ', '''ssl_version'', ', '''buffer_" "flush_lsn_avg_rate'', ', '''buffer_flush_pct_for_dirty'', ', '''buffer_flush_pct_for_lsn'', ', '''buffer_pool_pages_t" "otal'', ', '''lock_row_lock_time_avg'', ', '''lock_row_lock_time_max'', ', '''innodb_page_size''', ')'); IF (in_auto" "_config <> 'current') THEN IF (@sys.debug = 'ON') THEN SELECT CONCAT('Updating Performance Schema configuration to '," " in_auto_config) AS 'Debug'; END IF; CALL sys.ps_setup_save(0); IF (in_auto_config = 'medium') THEN UPDATE performan" "ce_schema.setup_consumers SET ENABLED = 'YES' WHERE NAME NOT LIKE '%\\_history%'; UPDATE performance_schema.setup_ins" "truments SET ENABLED = 'YES', TIMED = 'YES' WHERE NAME NOT LIKE 'wait/synch/%'; ELSEIF (in_auto_config = 'full') TH" "EN UPDATE performance_schema.setup_consumers SET ENABLED = 'YES'; UPDATE performance_schema.setup_instruments SET EN" "ABLED = 'YES', TIMED = 'YES'; END IF; UPDATE performance_schema.threads SET INSTRUMENTED = 'YES' WHERE PROCESSLIST" "_ID <> CONNECTION_ID(); END IF; SET v_start = UNIX_TIMESTAMP(NOW(2)), in_interval = IFNULL(in_interval, 30" "), in_max_runtime = IFNULL(in_max_runtime, 60); SET v_banner = REPEAT( '-', LEAST( GREATEST( 36, CHAR_LENGTH(VERSION" "()), CHAR_LENGTH(@@global.version_comment), CHAR_LENGTH(@@global.version_compile_os), CHAR_LENGTH(@@global.version_co" "mpile_machine), CHAR_LENGTH(@@global.socket), CHAR_LENGTH(@@global.datadir) ), 64 ) ); SELECT 'Hostname' AS 'Name', @" "@global.hostname AS 'Value' UNION ALL SELECT 'Port' AS 'Name', @@global.port AS 'Value' UNION ALL SELECT 'Socket' AS " "'Name', @@global.socket AS 'Value' UNION ALL SELECT 'Datadir' AS 'Name', @@global.datadir AS 'Value' UNION ALL SELECT" " 'Server UUID' AS 'Name', @@global.server_uuid AS 'Value' UNION ALL SELECT REPEAT('-', 23) AS 'Name', v_banner AS 'Va" "lue' UNION ALL SELECT 'MySQL Version' AS 'Name', VERSION() AS 'Value' UNION ALL SELECT 'Sys Schema Version' AS 'Name'" ", (SELECT sys_version FROM sys.version) AS 'Value' UNION ALL SELECT 'Version Comment' AS 'Name', @@global.version_com" "ment AS 'Value' UNION ALL SELECT 'Version Compile OS' AS 'Name', @@global.version_compile_os AS 'Value' UNION ALL SEL" "ECT 'Version Compile Machine' AS 'Name', @@global.version_compile_machine AS 'Value' UNION ALL SELECT REPEAT('-', 23)" " AS 'Name', v_banner AS 'Value' UNION ALL SELECT 'UTC Time' AS 'Name', UTC_TIMESTAMP() AS 'Value' UNION ALL SELECT 'L" "ocal Time' AS 'Name', NOW() AS 'Value' UNION ALL SELECT 'Time Zone' AS 'Name', @@global.time_zone AS 'Value' UNION AL" "L SELECT 'System Time Zone' AS 'Name', @@global.system_time_zone AS 'Value' UNION ALL SELECT 'Time Zone Offset' AS 'N" "ame', TIMEDIFF(NOW(), UTC_TIMESTAMP()) AS 'Value'; SET v_has_innodb = IFNULL((SELECT SUPPORT FROM informatio" "n_schema.ENGINES WHERE ENGINE = 'InnoDB'), 'NO'), v_has_ndb = IFNULL((SELECT SUPPORT FROM information_sche" "ma.ENGINES WHERE ENGINE = 'NDBCluster'), 'NO'), v_has_ps = IFNULL((SELECT SUPPORT FROM information_schema" ".ENGINES WHERE ENGINE = 'PERFORMANCE_SCHEMA'), 'NO'), v_has_ps_replication = IF(v_has_ps = 'YES' AND EXISTS(SELECT 1 " "FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'performance_schema' AND TABLE_NAME = 'replication_applier_status" "'), 'YES', 'NO' ), v_has_replication = /*!50707 IF(v_has_ps_replication = 'YES', IF((SELECT COUNT(*) FROM performa" "nce_schema.replication_connection_status) > 0, 'YES', 'NO'),*/ IF(@@master_info_repository = 'TABLE', IF((SELECT COUN" "T(*) FROM mysql.slave_master_info) > 0, 'YES', 'NO'), IF(@@relay_log_info_repository = 'TABLE', IF((SELECT COUNT(*) F" "ROM mysql.slave_relay_log_info) > 0, 'YES', 'NO'), 'MAYBE'))/*!50707 )*/, v_has_metrics = IF(v_has_ps = 'YES' " "OR (sys.version_major() = 5 AND sys.version_minor() = 6), 'YES', 'NO'), v_has_ps_vars = 'NO'; /*!50707 SET v_" "has_ps_vars = IF(@@global.show_compatibility_56, 'NO', 'YES');*/ /*!50709 SET v_has_ps_vars = 'YES';*/ IF (@sys.debu" "g = 'ON') THEN SELECT v_has_innodb AS 'Has_InnoDB', v_has_ndb AS 'Has_NDBCluster', v_has_ps AS 'Has_Performance_Schem" "a', v_has_ps_vars AS 'Has_P_S_SHOW_Variables', v_has_metrics AS 'Has_metrics', v_has_ps_replication 'AS Has_P_S_Repli" "cation', v_has_replication AS 'Has_Replication'; END IF; IF (v_has_innodb IN ('DEFAULT', 'YES')) THEN SET @sys.diagn" "ostics.sql = 'SHOW ENGINE InnoDB STATUS'; PREPARE stmt_innodb_status FROM @sys.diagnostics.sql; END IF; IF (v_has_ps" " = 'YES') THEN SET @sys.diagnostics.sql = 'SHOW ENGINE PERFORMANCE_SCHEMA STATUS'; PREPARE stmt_ps_status FROM @sys.d" "iagnostics.sql; END IF; IF (v_has_ndb IN ('DEFAULT', 'YES')) THEN SET @sys.diagnostics.sql = 'SHOW ENGINE NDBCLUSTER" " STATUS'; PREPARE stmt_ndbcluster_status FROM @sys.diagnostics.sql; END IF; SET @sys.diagnostics.sql_gen_query_templ" "ate = 'SELECT CONCAT( ''SELECT '', GROUP_CONCAT( CASE WHEN (SUBSTRING(TABLE_NAME, 3), COLUMN_NAME) IN ( (''io_global_" "by_file_by_bytes'', ''total''), (''io_global_by_wait_by_bytes'', ''total_requested'') ) THEN CONCAT(''sys.format_byte" "s('', COLUMN_NAME, '') AS '', COLUMN_NAME) WHEN COLUMN_NAME LIKE ''%latency'' THEN CONCAT(''sys.format_time('', COLUM" "N_NAME, '') AS '', COLUMN_NAME) WHEN SUBSTRING(COLUMN_NAME, -7) = ''_memory'' OR SUBSTRING(COLUMN_NAME, -17) = ''_mem" "ory_allocated'' OR ((SUBSTRING(COLUMN_NAME, -5) = ''_read'' OR SUBSTRING(COLUMN_NAME, -8) = ''_written'' OR SUBSTRING" "(COLUMN_NAME, -6) = ''_write'') AND SUBSTRING(COLUMN_NAME, 1, 6) <> ''COUNT_'') THEN CONCAT(''sys.format_bytes('', CO" "LUMN_NAME, '') AS '', COLUMN_NAME) ELSE COLUMN_NAME END ORDER BY ORDINAL_POSITION SEPARATOR '',\\n '' ), ''\\n F" "ROM tmp_'', SUBSTRING(TABLE_NAME FROM 3), ''_%{OUTPUT}'' ) AS Query INTO @sys.diagnostics.sql_select FROM information" "_schema.COLUMNS WHERE TABLE_SCHEMA = ''sys'' AND TABLE_NAME = ? GROUP BY TABLE_NAME'; SET @sys.diagnostics.sql_gen_q" "uery_delta = 'SELECT CONCAT( ''SELECT '', GROUP_CONCAT( CASE WHEN FIND_IN_SET(COLUMN_NAME, diag.pk) THEN COLUMN_NAME " "WHEN diag.TABLE_NAME = ''io_global_by_file_by_bytes'' AND COLUMN_NAME = ''write_pct'' THEN CONCAT(''IFNULL(ROUND(100-" "(((e.total_read-IFNULL(s.total_read, 0))'', ''/NULLIF(((e.total_read-IFNULL(s.total_read, 0))+(e.total_written-IFNULL" "(s.total_written, 0))), 0))*100), 2), 0.00) AS '', COLUMN_NAME) WHEN (diag.TABLE_NAME, COLUMN_NAME) IN ( (''io_global" "_by_file_by_bytes'', ''total''), (''io_global_by_wait_by_bytes'', ''total_requested'') ) THEN CONCAT(''sys.format_byt" "es(e.'', COLUMN_NAME, ''-IFNULL(s.'', COLUMN_NAME, '', 0)) AS '', COLUMN_NAME) WHEN SUBSTRING(COLUMN_NAME, 1, 4) IN (" "''max_'', ''min_'') AND SUBSTRING(COLUMN_NAME, -8) = ''_latency'' THEN CONCAT(''sys.format_time(e.'', COLUMN_NAME, ''" ") AS '', COLUMN_NAME) WHEN COLUMN_NAME = ''avg_latency'' THEN CONCAT(''sys.format_time((e.total_latency - IFNULL(s.to" "tal_latency, 0))'', ''/NULLIF(e.total - IFNULL(s.total, 0), 0)) AS '', COLUMN_NAME) WHEN SUBSTRING(COLUMN_NAME, -12) " "= ''_avg_latency'' THEN CONCAT(''sys.format_time((e.'', SUBSTRING(COLUMN_NAME FROM 1 FOR CHAR_LENGTH(COLUMN_NAME)-12)" ", ''_latency - IFNULL(s.'', SUBSTRING(COLUMN_NAME FROM 1 FOR CHAR_LENGTH(COLUMN_NAME)-12), ''_latency, 0))'', ''/NULL" "IF(e.'', SUBSTRING(COLUMN_NAME FROM 1 FOR CHAR_LENGTH(COLUMN_NAME)-12), ''s - IFNULL(s.'', SUBSTRING(COLUMN_NAME FROM" " 1 FOR CHAR_LENGTH(COLUMN_NAME)-12), ''s, 0), 0)) AS '', COLUMN_NAME) WHEN COLUMN_NAME LIKE ''%latency'' THEN CONCAT(" "''sys.format_time(e.'', COLUMN_NAME, '' - IFNULL(s.'', COLUMN_NAME, '', 0)) AS '', COLUMN_NAME) WHEN COLUMN_NAME IN (" "''avg_read'', ''avg_write'', ''avg_written'') THEN CONCAT(''sys.format_bytes(IFNULL((e.total_'', IF(COLUMN_NAME = ''a" "vg_read'', ''read'', ''written''), ''-IFNULL(s.total_'', IF(COLUMN_NAME = ''avg_read'', ''read'', ''written''), '', 0" "))'', ''/NULLIF(e.count_'', IF(COLUMN_NAME = ''avg_read'', ''read'', ''write''), ''-IFNULL(s.count_'', IF(COLUMN_NAME" " = ''avg_read'', ''read'', ''write''), '', 0), 0), 0)) AS '', COLUMN_NAME) WHEN SUBSTRING(COLUMN_NAME, -7) = ''_memor" "y'' OR SUBSTRING(COLUMN_NAME, -17) = ''_memory_allocated'' OR ((SUBSTRING(COLUMN_NAME, -5) = ''_read'' OR SUBSTRING(C" "OLUMN_NAME, -8) = ''_written'' OR SUBSTRING(COLUMN_NAME, -6) = ''_write'') AND SUBSTRING(COLUMN_NAME, 1, 6) <> ''COUN" "T_'') THEN CONCAT(''sys.format_bytes(e.'', COLUMN_NAME, '' - IFNULL(s.'', COLUMN_NAME, '', 0)) AS '', COLUMN_NAME) EL" "SE CONCAT(''(e.'', COLUMN_NAME, '' - IFNULL(s.'', COLUMN_NAME, '', 0)) AS '', COLUMN_NAME) END ORDER BY ORDINAL_POSIT" "ION SEPARATOR '',\\n '' ), ''\\n FROM tmp_'', diag.TABLE_NAME, ''_end e LEFT OUTER JOIN tmp_'', diag.TABLE_NAME," " ''_start s USING ('', diag.pk, '')'' ) AS Query INTO @sys.diagnostics.sql_select FROM tmp_sys_views_delta diag INNER" " JOIN information_schema.COLUMNS c ON c.TABLE_NAME = CONCAT(''x$'', diag.TABLE_NAME) WHERE c.TABLE_SCHEMA = ''sys'' A" "ND diag.TABLE_NAME = ? GROUP BY diag.TABLE_NAME'; IF (v_has_ps = 'YES') THEN DROP TEMPORARY TABLE IF EXISTS tmp_sys_" "views_delta; CREATE TEMPORARY TABLE tmp_sys_views_delta ( TABLE_NAME varchar(64) NOT NULL, order_by text COMMENT 'ORD" "ER BY clause for the initial and overall views', order_by_delta text COMMENT 'ORDER BY clause for the delta views', w" "here_delta text COMMENT 'WHERE clause to use for delta views to only include rows with a \"count\" > 0', limit_rows i" "nt unsigned COMMENT 'The maximum number of rows to include for the view', pk varchar(128) COMMENT 'Used with the FIND" "_IN_SET() function so use comma separated list without whitespace', PRIMARY KEY (TABLE_NAME) ); IF (@sys.debug = 'ON" "') THEN SELECT 'Populating tmp_sys_views_delta' AS 'Debug'; END IF; INSERT INTO tmp_sys_views_delta VALUES ('host_sum" "mary' , '%{TABLE}.statement_latency DESC', '(e.statement_latency-IFNULL(s.statement_latency, 0)" ") DESC', '(e.statements - IFNULL(s.statements, 0)) > 0', NULL, 'host'), ('host_summary_by_file_io' , '%{TA" "BLE}.io_latency DESC', '(e.io_latency-IFNULL(s.io_latency, 0)) DESC', '(e.ios - IFNULL(s.ios, 0)) > 0', NULL, 'host')" ", ('host_summary_by_file_io_type' , '%{TABLE}.host, %{TABLE}.total_latency DESC', 'e.host, (e.total_latency-IFN" "ULL(s.total_latency, 0)) DESC', '(e.total - IFNULL(s.total, 0)) > 0', NULL, 'host,event_name'), ('host_summary_by_sta" "ges' , '%{TABLE}.host, %{TABLE}.total_latency DESC', 'e.host, (e.total_latency-IFNULL(s.total_latency, 0)" ") DESC', '(e.total - IFNULL(s.total, 0)) > 0', NULL, 'host,event_name'), ('host_summary_by_statement_latency' , '%{T" "ABLE}.total_latency DESC', '(e.total_latency-IFNULL(s.total_latency, 0)) DESC', '(e.total - IFNULL(s.total, 0)) > 0'," " NULL, 'host'), ('host_summary_by_statement_type' , '%{TABLE}.host, %{TABLE}.total_latency DESC', 'e.host, (e.tot" "al_latency-IFNULL(s.total_latency, 0)) DESC', '(e.total - IFNULL(s.total, 0)) > 0', NULL, 'host,statement'), ('io_by_" "thread_by_latency' , '%{TABLE}.total_latency DESC', '(e.total_latency-IFNULL(s.total_latency, 0)) DESC', '" "(e.total - IFNULL(s.total, 0)) > 0', NULL, 'user,thread_id,processlist_id'), ('io_global_by_file_by_bytes' , " "'%{TABLE}.total DESC', '(e.total-IFNULL(s.total, 0)) DESC', '(e.total - IFNULL(s.total, 0)) > 0', 100, 'file'), ('io_" "global_by_file_by_latency' , '%{TABLE}.total_latency DESC', '(e.total_latency-IFNULL(s.total_latency, 0)) DESC'" ", '(e.total - IFNULL(s.total, 0)) > 0', 100, 'file'), ('io_global_by_wait_by_bytes' , '%{TABLE}.total_request" "ed DESC', '(e.total_requested-IFNULL(s.total_requested, 0)) DESC', '(e.total - IFNULL(s.total, 0)) > 0', NULL, 'event" "_name'), ('io_global_by_wait_by_latency' , '%{TABLE}.total_latency DESC', '(e.total_latency-IFNULL(s.total_late" "ncy, 0)) DESC', '(e.total - IFNULL(s.total, 0)) > 0', NULL, 'event_name'), ('schema_index_statistics' , '(" "%{TABLE}.select_latency+%{TABLE}.insert_latency+%{TABLE}.update_latency+%{TABLE}.delete_latency) DESC', '((e.select_l" "atency+e.insert_latency+e.update_latency+e.delete_latency)-IFNULL(s.select_latency+s.insert_latency+s.update_latency+" "s.delete_latency, 0)) DESC', '((e.rows_selected+e.insert_latency+e.rows_updated+e.rows_deleted)-IFNULL(s.rows_selecte" "d+s.rows_inserted+s.rows_updated+s.rows_deleted, 0)) > 0', 100, 'table_schema,table_name,index_name'), ('schema_table" "_statistics' , '%{TABLE}.total_latency DESC', '(e.total_latency-IFNULL(s.total_latency, 0)) DESC', '(e.tot" "al_latency-IFNULL(s.total_latency, 0)) > 0', 100, 'table_schema,table_name'), ('schema_tables_with_full_table_scans'," " '%{TABLE}.rows_full_scanned DESC', '(e.rows_full_scanned-IFNULL(s.rows_full_scanned, 0)) DESC', '(e.rows_full_scanne" "d-IFNULL(s.rows_full_scanned, 0)) > 0', 100, 'object_schema,object_name'), ('user_summary' , '%" "{TABLE}.statement_latency DESC', '(e.statement_latency-IFNULL(s.statement_latency, 0)) DESC', '(e.statements - IFNULL" "(s.statements, 0)) > 0', NULL, 'user'), ('user_summary_by_file_io' , '%{TABLE}.io_latency DESC', '(e.io_la" "tency-IFNULL(s.io_latency, 0)) DESC', '(e.ios - IFNULL(s.ios, 0)) > 0', NULL, 'user'), ('user_summary_by_file_io_type" "' , '%{TABLE}.user, %{TABLE}.latency DESC', 'e.user, (e.latency-IFNULL(s.latency, 0)) DESC', '(e.total - IFNULL" "(s.total, 0)) > 0', NULL, 'user,event_name'), ('user_summary_by_stages' , '%{TABLE}.user, %{TABLE}.total_" "latency DESC', 'e.user, (e.total_latency-IFNULL(s.total_latency, 0)) DESC', '(e.total - IFNULL(s.total, 0)) > 0', NUL" "L, 'user,event_name'), ('user_summary_by_statement_latency' , '%{TABLE}.total_latency DESC', '(e.total_latency-IFNUL" "L(s.total_latency, 0)) DESC', '(e.total - IFNULL(s.total, 0)) > 0', NULL, 'user'), ('user_summary_by_statement_type' " " , '%{TABLE}.user, %{TABLE}.total_latency DESC', 'e.user, (e.total_latency-IFNULL(s.total_latency, 0)) DESC', '(e." "total - IFNULL(s.total, 0)) > 0', NULL, 'user,statement'), ('wait_classes_global_by_avg_latency' , 'IFNULL(%{TABLE}.t" "otal_latency / NULLIF(%{TABLE}.total, 0), 0) DESC', 'IFNULL((e.total_latency-IFNULL(s.total_latency, 0)) / NULLIF((e." "total - IFNULL(s.total, 0)), 0), 0) DESC', '(e.total - IFNULL(s.total, 0)) > 0', NULL, 'event_class'), ('wait_classes" "_global_by_latency' , '%{TABLE}.total_latency DESC', '(e.total_latency-IFNULL(s.total_latency, 0)) DESC', '(e.tot" "al - IFNULL(s.total, 0)) > 0', NULL, 'event_class'), ('waits_by_host_by_latency' , '%{TABLE}.host, %{TABLE}" ".total_latency DESC', 'e.host, (e.total_latency-IFNULL(s.total_latency, 0)) DESC', '(e.total - IFNULL(s.total, 0)) > " "0', NULL, 'host,event'), ('waits_by_user_by_latency' , '%{TABLE}.user, %{TABLE}.total_latency DESC', 'e.use" "r, (e.total_latency-IFNULL(s.total_latency, 0)) DESC', '(e.total - IFNULL(s.total, 0)) > 0', NULL, 'user,event'), ('w" "aits_global_by_latency' , '%{TABLE}.total_latency DESC', '(e.total_latency-IFNULL(s.total_latency, 0)) DES" "C', '(e.total - IFNULL(s.total, 0)) > 0', NULL, 'events') ; END IF; SELECT ' ======================= Configuratio" "n ======================= ' AS ''; SELECT 'GLOBAL VARIABLES' AS 'The following output is:'; IF (v_has_ps_vars = 'YE" "S') THEN SELECT LOWER(VARIABLE_NAME) AS Variable_name, VARIABLE_VALUE AS Variable_value FROM performance_schema.globa" "l_variables ORDER BY VARIABLE_NAME; ELSE SELECT LOWER(VARIABLE_NAME) AS Variable_name, VARIABLE_VALUE AS Variable_val" "ue FROM information_schema.GLOBAL_VARIABLES ORDER BY VARIABLE_NAME; END IF; IF (v_has_ps = 'YES') THEN SELECT 'Perfo" "rmance Schema Setup - Actors' AS 'The following output is:'; SELECT * FROM performance_schema.setup_actors; SELECT '" "Performance Schema Setup - Consumers' AS 'The following output is:'; SELECT NAME AS Consumer, ENABLED, sys.ps_is_cons" "umer_enabled(NAME) AS COLLECTS FROM performance_schema.setup_consumers; SELECT 'Performance Schema Setup - Instrumen" "ts' AS 'The following output is:'; SELECT SUBSTRING_INDEX(NAME, '/', 2) AS 'InstrumentClass', ROUND(100*SUM(IF(ENABLE" "D = 'YES', 1, 0))/COUNT(*), 2) AS 'EnabledPct', ROUND(100*SUM(IF(TIMED = 'YES', 1, 0))/COUNT(*), 2) AS 'TimedPct' FRO" "M performance_schema.setup_instruments GROUP BY SUBSTRING_INDEX(NAME, '/', 2) ORDER BY SUBSTRING_INDEX(NAME, '/', 2);" " SELECT 'Performance Schema Setup - Objects' AS 'The following output is:'; SELECT * FROM performance_schema.setup_o" "bjects; SELECT 'Performance Schema Setup - Threads' AS 'The following output is:'; SELECT `TYPE` AS ThreadType, COUN" "T(*) AS 'Total', ROUND(100*SUM(IF(INSTRUMENTED = 'YES', 1, 0))/COUNT(*), 2) AS 'InstrumentedPct' FROM performance_sch" "ema.threads GROUP BY TYPE; END IF; IF (v_has_replication = 'NO') THEN SELECT 'No Replication Configured' AS 'Replic" "ation Status'; ELSE SELECT CONCAT('Replication Configured: ', v_has_replication, ' - Performance Schema Replication T" "ables: ', v_has_ps_replication) AS 'Replication Status'; IF (v_has_ps_replication = 'YES') THEN SELECT 'Replication " "- Connection Configuration' AS 'The following output is:'; SELECT * FROM performance_schema.replication_connection_co" "nfiguration/*!50706 ORDER BY CHANNEL_NAME*/; END IF; IF (v_has_ps_replication = 'YES') THEN SELECT 'Replication - Ap" "plier Configuration' AS 'The following output is:'; SELECT * FROM performance_schema.replication_applier_configuratio" "n ORDER BY CHANNEL_NAME; END IF; IF (@@master_info_repository = 'TABLE') THEN SELECT 'Replication - Master Info Repo" "sitory Configuration' AS 'The following output is:'; SELECT /*!50706 Channel_name, */Host, User_name, Port, Connect_r" "etry, Enabled_ssl, Ssl_ca, Ssl_capath, Ssl_cert, Ssl_cipher, Ssl_key, Ssl_verify_server_cert, Heartbeat, Bind, Ignore" "d_server_ids, Uuid, Retry_count, Ssl_crl, Ssl_crlpath, Tls_version, Enabled_auto_position FROM mysql.slave_master_inf" "o/*!50706 ORDER BY Channel_name*/; END IF; IF (@@relay_log_info_repository = 'TABLE') THEN SELECT 'Replication - Rel" "ay Log Repository Configuration' AS 'The following output is:'; SELECT /*!50706 Channel_name, */Sql_delay, Number_of_" "workers, Id FROM mysql.slave_relay_log_info/*!50706 ORDER BY Channel_name*/; END IF; END IF; IF (v_has_ndb IN ('DEF" "AULT', 'YES')) THEN SELECT 'Cluster Thread Blocks' AS 'The following output is:'; SELECT * FROM ndbinfo.threadblocks;" " END IF; IF (v_has_ps = 'YES') THEN IF (@sys.diagnostics.include_raw = 'ON') THEN SELECT ' ========================" " Initial Status ======================== ' AS ''; END IF; DROP TEMPORARY TABLE IF EXISTS tmp_digests_start; CALL " "sys.statement_performance_analyzer('create_tmp', 'tmp_digests_start', NULL); CALL sys.statement_performance_analyzer(" "'snapshot', NULL, NULL); CALL sys.statement_performance_analyzer('save', 'tmp_digests_start', NULL); IF (@sys.diagno" "stics.include_raw = 'ON') THEN SET @sys.diagnostics.sql = REPLACE(@sys.diagnostics.sql_gen_query_template, '%{OUTPUT}" "', 'start'); IF (@sys.debug = 'ON') THEN SELECT 'The following query will be used to generate the query for each sys " "view' AS 'Debug'; SELECT @sys.diagnostics.sql AS 'Debug'; END IF; PREPARE stmt_gen_query FROM @sys.diagnostics.sql; E" "ND IF; SET v_done = FALSE; OPEN c_sysviews_w_delta; c_sysviews_w_delta_loop: LOOP FETCH c_sysviews_w_delta INTO v_tab" "le_name; IF v_done THEN LEAVE c_sysviews_w_delta_loop; END IF; IF (@sys.debug = 'ON') THEN SELECT CONCAT('The follow" "ing queries are for storing the initial content of ', v_table_name) AS 'Debug'; END IF; CALL sys.execute_prepared_st" "mt(CONCAT('DROP TEMPORARY TABLE IF EXISTS `tmp_', v_table_name, '_start`')); CALL sys.execute_prepared_stmt(CONCAT('C" "REATE TEMPORARY TABLE `tmp_', v_table_name, '_start` SELECT * FROM `sys`.`x$', v_table_name, '`')); IF (@sys.diagnos" "tics.include_raw = 'ON') THEN SET @sys.diagnostics.table_name = CONCAT('x$', v_table_name); EXECUTE stmt_gen_query US" "ING @sys.diagnostics.table_name; SELECT CONCAT(@sys.diagnostics.sql_select, IF(order_by IS NOT NULL, CONCAT('\\n ORDER" " BY ', REPLACE(order_by, '%{TABLE}', CONCAT('tmp_', v_table_name, '_start'))), ''), IF(limit_rows IS NOT NULL, CONCAT" "('\\n LIMIT ', limit_rows), '') ) INTO @sys.diagnostics.sql_select FROM tmp_sys_views_delta WHERE TABLE_NAME = v_table" "_name; SELECT CONCAT('Initial ', v_table_name) AS 'The following output is:'; CALL sys.execute_prepared_stmt(@sys.dia" "gnostics.sql_select); END IF; END LOOP; CLOSE c_sysviews_w_delta; IF (@sys.diagnostics.include_raw = 'ON') THEN DEAL" "LOCATE PREPARE stmt_gen_query; END IF; END IF; SET v_sql_status_summary_select = 'SELECT Variable_name', v_sql_statu" "s_summary_delta = '', v_sql_status_summary_from = ''; REPEAT SET v_output_count = v_output_count + 1; IF (v_outpu" "t_count > 1) THEN SET v_sleep = in_interval-(UNIX_TIMESTAMP(NOW(2))-v_iter_start); SELECT NOW() AS 'Time', CONCAT('Go" "ing to sleep for ', v_sleep, ' seconds. Please do not interrupt') AS 'The following output is:'; DO SLEEP(in_interval" "); END IF; SET v_iter_start = UNIX_TIMESTAMP(NOW(2)); SELECT NOW(), CONCAT('Iteration Number ', IFNULL(v_output_coun" "t, 'NULL')) AS 'The following output is:'; IF (@@log_bin = 1) THEN SELECT 'SHOW MASTER STATUS' AS 'The following out" "put is:'; SHOW MASTER STATUS; END IF; IF (v_has_replication <> 'NO') THEN SELECT 'SHOW SLAVE STATUS' AS 'The followi" "ng output is:'; SHOW SLAVE STATUS; IF (v_has_ps_replication = 'YES') THEN SELECT 'Replication Connection Status' AS " "'The following output is:'; SELECT * FROM performance_schema.replication_connection_status; SELECT 'Replication Appl" "ier Status' AS 'The following output is:'; SELECT * FROM performance_schema.replication_applier_status ORDER BY CHANN" "EL_NAME; SELECT 'Replication Applier Status - Coordinator' AS 'The following output is:'; SELECT * FROM performance_" "schema.replication_applier_status_by_coordinator ORDER BY CHANNEL_NAME; SELECT 'Replication Applier Status - Worker'" " AS 'The following output is:'; SELECT * FROM performance_schema.replication_applier_status_by_worker ORDER BY CHANNE" "L_NAME, WORKER_ID; END IF; IF (@@master_info_repository = 'TABLE') THEN SELECT 'Replication - Master Log Status' AS " "'The following output is:'; SELECT Master_log_name, Master_log_pos FROM mysql.slave_master_info; END IF; IF (@@relay" "_log_info_repository = 'TABLE') THEN SELECT 'Replication - Relay Log Status' AS 'The following output is:'; SELECT sy" "s.format_path(Relay_log_name) AS Relay_log_name, Relay_log_pos, Master_log_name, Master_log_pos FROM mysql.slave_rela" "y_log_info; SELECT 'Replication - Worker Status' AS 'The following output is:'; SELECT Id, sys.format_path(Relay_log" "_name) AS Relay_log_name, Relay_log_pos, Master_log_name, Master_log_pos, sys.format_path(Checkpoint_relay_log_name) " "AS Checkpoint_relay_log_name, Checkpoint_relay_log_pos, Checkpoint_master_log_name, Checkpoint_master_log_pos, Checkp" "oint_seqno, Checkpoint_group_size, HEX(Checkpoint_group_bitmap) AS Checkpoint_group_bitmap/*!50706 , Channel_name*/ F" "ROM mysql.slave_worker_info ORDER BY /*!50706 Channel_name, */Id; END IF; END IF; SET v_table_name = CONCAT('tmp_met" "rics_', v_output_count); CALL sys.execute_prepared_stmt(CONCAT('DROP TEMPORARY TABLE IF EXISTS ', v_table_name)); CA" "LL sys.execute_prepared_stmt(CONCAT('CREATE TEMPORARY TABLE ', v_table_name, ' ( Variable_name VARCHAR(193) NOT NULL," " Variable_value VARCHAR(1024), Type VARCHAR(225) NOT NULL, Enabled ENUM(''YES'', ''NO'', ''PARTIAL'') NOT NULL, PRIMA" "RY KEY (Type, Variable_name) ) ENGINE = InnoDB DEFAULT CHARSET=utf8')); IF (v_has_metrics) THEN SET @sys.diagnostics" ".sql = CONCAT( 'INSERT INTO ', v_table_name, ' SELECT Variable_name, REPLACE(Variable_value, ''\\n'', ''\\\\\\\\n'') AS Va" "riable_value, Type, Enabled FROM sys.metrics' ); ELSE SET @sys.diagnostics.sql = CONCAT( 'INSERT INTO ', v_table_name" ", '(SELECT LOWER(VARIABLE_NAME) AS Variable_name, REPLACE(VARIABLE_VALUE, ''\\n'', ''\\\\\\\\n'') AS Variable_value, ''Glo" "bal Status'' AS Type, ''YES'' AS Enabled FROM performance_schema.global_status ) UNION ALL ( SELECT NAME AS Variable_" "name, COUNT AS Variable_value, CONCAT(''InnoDB Metrics - '', SUBSYSTEM) AS Type, IF(STATUS = ''enabled'', ''YES'', ''" "NO'') AS Enabled FROM information_schema.INNODB_METRICS WHERE NAME NOT IN ( ''lock_row_lock_time'', ''lock_row_lock_t" "ime_avg'', ''lock_row_lock_time_max'', ''lock_row_lock_waits'', ''buffer_pool_reads'', ''buffer_pool_read_requests''," " ''buffer_pool_write_requests'', ''buffer_pool_wait_free'', ''buffer_pool_read_ahead'', ''buffer_pool_read_ahead_evic" "ted'', ''buffer_pool_pages_total'', ''buffer_pool_pages_misc'', ''buffer_pool_pages_data'', ''buffer_pool_bytes_data'" "', ''buffer_pool_pages_dirty'', ''buffer_pool_bytes_dirty'', ''buffer_pool_pages_free'', ''buffer_pages_created'', ''" "buffer_pages_written'', ''buffer_pages_read'', ''buffer_data_reads'', ''buffer_data_written'', ''file_num_open_files'" "', ''os_log_bytes_written'', ''os_log_fsyncs'', ''os_log_pending_fsyncs'', ''os_log_pending_writes'', ''log_waits'', " "''log_write_requests'', ''log_writes'', ''innodb_dblwr_writes'', ''innodb_dblwr_pages_written'', ''innodb_page_size''" ") ) UNION ALL ( SELECT ''NOW()'' AS Variable_name, NOW(3) AS Variable_value, ''System Time'' AS Type, ''YES'' AS Enab" "led ) UNION ALL ( SELECT ''UNIX_TIMESTAMP()'' AS Variable_name, ROUND(UNIX_TIMESTAMP(NOW(3)), 3) AS Variable_value, '" "'System Time'' AS Type, ''YES'' AS Enabled ) ORDER BY Type, Variable_name;' ); END IF; CALL sys.execute_prepared_stmt" "(@sys.diagnostics.sql); CALL sys.execute_prepared_stmt( CONCAT('(SELECT Variable_value INTO @sys.diagnostics.output_" "time FROM ', v_table_name, ' WHERE Type = ''System Time'' AND Variable_name = ''UNIX_TIMESTAMP()'')') ); SET v_output" "_time = @sys.diagnostics.output_time; SET v_sql_status_summary_select = CONCAT(v_sql_status_summary_select, ', CONCA" "T( LEFT(s', v_output_count, '.Variable_value, ', v_status_summary_width, '), IF(', REPLACE(v_no_delta_names, '%{COUNT" "}', v_output_count), ' AND s', v_output_count, '.Variable_value REGEXP ''^[0-9]+(\\\\\\\\.[0-9]+)?$'', CONCAT('' ('', ROU" "ND(s', v_output_count, '.Variable_value/', v_output_time, ', 2), ''/sec)''), '''') ) AS ''Output ', v_output_count, '" "'''), v_sql_status_summary_from = CONCAT(v_sql_status_summary_from, ' ', IF(v_output_count = 1, ' FROM ', ' " "INNER JOIN '), v_table_name, ' s', v_output_count, IF (v_output_count = 1, '', ' USING (Type, Variable_name)')); IF (" "v_output_count > 1) THEN SET v_sql_status_summary_delta = CONCAT(v_sql_status_summary_delta, ', IF(', REPLACE(v_no_d" "elta_names, '%{COUNT}', v_output_count), ' AND s', (v_output_count-1), '.Variable_value REGEXP ''^[0-9]+(\\\\\\\\.[0-9]+)" "?$'' AND s', v_output_count, '.Variable_value REGEXP ''^[0-9]+(\\\\\\\\.[0-9]+)?$'', CONCAT(IF(s', (v_output_count-1), '." "Variable_value REGEXP ''^[0-9]+\\\\\\\\.[0-9]+$'' OR s', v_output_count, '.Variable_value REGEXP ''^[0-9]+\\\\\\\\.[0-9]+$''," " ROUND((s', v_output_count, '.Variable_value-s', (v_output_count-1), '.Variable_value), 2), (s', v_output_count, '.Va" "riable_value-s', (v_output_count-1), '.Variable_value) ), '' ('', ROUND((s', v_output_count, '.Variable_value-s', (v_" "output_count-1), '.Variable_value)/(', v_output_time, '-', v_output_time_prev, '), 2), ''/sec)'' ), '''' ) AS ''Delta" " (', (v_output_count-1), ' -> ', v_output_count, ')'''); END IF; SET v_output_time_prev = v_output_time; IF (@sys.d" "iagnostics.include_raw = 'ON') THEN IF (v_has_metrics) THEN SELECT 'SELECT * FROM sys.metrics' AS 'The following outp" "ut is:'; ELSE SELECT 'sys.metrics equivalent' AS 'The following output is:'; END IF; CALL sys.execute_prepared_stmt(C" "ONCAT('SELECT Type, Variable_name, Enabled, Variable_value FROM ', v_table_name, ' ORDER BY Type, Variable_name')); E" "ND IF; IF (v_has_innodb IN ('DEFAULT', 'YES')) THEN SELECT 'SHOW ENGINE INNODB STATUS' AS 'The following output is:'" "; EXECUTE stmt_innodb_status; SELECT 'InnoDB - Transactions' AS 'The following output is:'; SELECT * FROM information" "_schema.INNODB_TRX; END IF; IF (v_has_ndb IN ('DEFAULT', 'YES')) THEN SELECT 'SHOW ENGINE NDBCLUSTER STATUS' AS 'The" " following output is:'; EXECUTE stmt_ndbcluster_status; SELECT 'ndbinfo.memoryusage' AS 'The following output is:'; " "SELECT node_id, memory_type, sys.format_bytes(used) AS used, used_pages, sys.format_bytes(total) AS total, total_page" "s, ROUND(100*(used/total), 2) AS 'Used %' FROM ndbinfo.memoryusage; SET v_done = FALSE; OPEN c_ndbinfo; c_ndbinfo_lo" "op: LOOP FETCH c_ndbinfo INTO v_table_name; IF v_done THEN LEAVE c_ndbinfo_loop; END IF; SELECT CONCAT('SELECT * FRO" "M ndbinfo.', v_table_name) AS 'The following output is:'; CALL sys.execute_prepared_stmt(CONCAT('SELECT * FROM `ndbin" "fo`.`', v_table_name, '`')); END LOOP; CLOSE c_ndbinfo; SELECT * FROM information_schema.FILES; END IF; SELECT 'SEL" "ECT * FROM sys.processlist' AS 'The following output is:'; SELECT processlist.* FROM sys.processlist; IF (v_has_ps =" " 'YES') THEN IF (sys.ps_is_consumer_enabled('events_waits_history_long') = 'YES') THEN SELECT 'SELECT * FROM sys.late" "st_file_io' AS 'The following output is:'; SELECT * FROM sys.latest_file_io; END IF; IF (EXISTS(SELECT 1 FROM perfor" "mance_schema.setup_instruments WHERE NAME LIKE 'memory/%' AND ENABLED = 'YES')) THEN SELECT 'SELECT * FROM sys.memory" "_by_host_by_current_bytes' AS 'The following output is:'; SELECT * FROM sys.memory_by_host_by_current_bytes; SELECT " "'SELECT * FROM sys.memory_by_thread_by_current_bytes' AS 'The following output is:'; SELECT * FROM sys.memory_by_thre" "ad_by_current_bytes; SELECT 'SELECT * FROM sys.memory_by_user_by_current_bytes' AS 'The following output is:'; SELEC" "T * FROM sys.memory_by_user_by_current_bytes; SELECT 'SELECT * FROM sys.memory_global_by_current_bytes' AS 'The foll" "owing output is:'; SELECT * FROM sys.memory_global_by_current_bytes; END IF; END IF; SET v_runtime = (UNIX_TIMESTAMP" "(NOW(2)) - v_start); UNTIL (v_runtime + in_interval >= in_max_runtime) END REPEAT; IF (v_has_ps = 'YES') THEN SELECT" " 'SHOW ENGINE PERFORMANCE_SCHEMA STATUS' AS 'The following output is:'; EXECUTE stmt_ps_status; END IF; IF (v_has_in" "nodb IN ('DEFAULT', 'YES')) THEN DEALLOCATE PREPARE stmt_innodb_status; END IF; IF (v_has_ps = 'YES') THEN DEALLOCATE" " PREPARE stmt_ps_status; END IF; IF (v_has_ndb IN ('DEFAULT', 'YES')) THEN DEALLOCATE PREPARE stmt_ndbcluster_status;" " END IF; SELECT ' ============================ Schema Information ============================ ' AS ''; SELECT" " COUNT(*) AS 'Total Number of Tables' FROM information_schema.TABLES; IF (@sys.diagnostics.allow_i_s_tables = 'ON') " "THEN SELECT 'Storage Engine Usage' AS 'The following output is:'; SELECT ENGINE, COUNT(*) AS NUM_TABLES, sys.format_b" "ytes(SUM(DATA_LENGTH)) AS DATA_LENGTH, sys.format_bytes(SUM(INDEX_LENGTH)) AS INDEX_LENGTH, sys.format_bytes(SUM(DATA" "_LENGTH+INDEX_LENGTH)) AS TOTAL FROM information_schema.TABLES GROUP BY ENGINE; SELECT 'Schema Object Overview' AS '" "The following output is:'; SELECT * FROM sys.schema_object_overview; SELECT 'Tables without a PRIMARY KEY' AS 'The f" "ollowing output is:'; SELECT TABLES.TABLE_SCHEMA, ENGINE, COUNT(*) AS NumTables FROM information_schema.TABLES LEFT O" "UTER JOIN information_schema.STATISTICS ON STATISTICS.TABLE_SCHEMA = TABLES.TABLE_SCHEMA AND STATISTICS.TABLE_NAME = " "TABLES.TABLE_NAME AND STATISTICS.INDEX_NAME = 'PRIMARY' WHERE STATISTICS.TABLE_NAME IS NULL AND TABLES.TABLE_SCHEMA N" "OT IN ('mysql', 'information_schema', 'performance_schema', 'sys') AND TABLES.TABLE_TYPE = 'BASE TABLE' GROUP BY TABL" "ES.TABLE_SCHEMA, ENGINE; END IF; IF (v_has_ps = 'YES') THEN SELECT 'Unused Indexes' AS 'The following output is:'; S" "ELECT object_schema, COUNT(*) AS NumUnusedIndexes FROM performance_schema.table_io_waits_summary_by_index_usage WHERE" " index_name IS NOT NULL AND count_star = 0 AND object_schema NOT IN ('mysql', 'sys') AND index_name != 'PRIMARY' GROU" "P BY object_schema; END IF; IF (v_has_ps = 'YES') THEN SELECT ' ========================= Overall Status ========" "================= ' AS ''; SELECT 'CALL sys.ps_statement_avg_latency_histogram()' AS 'The following output is:'; CA" "LL sys.ps_statement_avg_latency_histogram(); CALL sys.statement_performance_analyzer('snapshot', NULL, NULL); CALL s" "ys.statement_performance_analyzer('overall', NULL, 'with_runtimes_in_95th_percentile'); SET @sys.diagnostics.sql = R" "EPLACE(@sys.diagnostics.sql_gen_query_template, '%{OUTPUT}', 'end'); IF (@sys.debug = 'ON') THEN SELECT 'The followin" "g query will be used to generate the query for each sys view' AS 'Debug'; SELECT @sys.diagnostics.sql AS 'Debug'; END" " IF; PREPARE stmt_gen_query FROM @sys.diagnostics.sql; SET v_done = FALSE; OPEN c_sysviews_w_delta; c_sysviews_w_del" "ta_loop: LOOP FETCH c_sysviews_w_delta INTO v_table_name; IF v_done THEN LEAVE c_sysviews_w_delta_loop; END IF; IF (" "@sys.debug = 'ON') THEN SELECT CONCAT('The following queries are for storing the final content of ', v_table_name) AS" " 'Debug'; END IF; CALL sys.execute_prepared_stmt(CONCAT('DROP TEMPORARY TABLE IF EXISTS `tmp_', v_table_name, '_end`" "')); CALL sys.execute_prepared_stmt(CONCAT('CREATE TEMPORARY TABLE `tmp_', v_table_name, '_end` SELECT * FROM `sys`.`" "x$', v_table_name, '`')); SET @sys.diagnostics.table_name = CONCAT('x$', v_table_name); EXECUTE stmt_gen_query USING" " @sys.diagnostics.table_name; SELECT CONCAT(@sys.diagnostics.sql_select, IF(order_by IS NOT NULL, CONCAT('\\n ORDER BY" " ', REPLACE(order_by, '%{TABLE}', CONCAT('tmp_', v_table_name, '_end'))), ''), IF(limit_rows IS NOT NULL, CONCAT('\\n " "LIMIT ', limit_rows), '') ) INTO @sys.diagnostics.sql_select FROM tmp_sys_views_delta WHERE TABLE_NAME = v_table_name" "; SELECT CONCAT('Overall ', v_table_name) AS 'The following output is:'; CALL sys.execute_prepared_stmt(@sys.diagnost" "ics.sql_select); END LOOP; CLOSE c_sysviews_w_delta; DEALLOCATE PREPARE stmt_gen_query; SELECT ' ================" "====== Delta Status ====================== ' AS ''; CALL sys.statement_performance_analyzer('delta', 'tmp_digests" "_start', 'with_runtimes_in_95th_percentile'); CALL sys.statement_performance_analyzer('cleanup', NULL, NULL); DROP T" "EMPORARY TABLE tmp_digests_start; IF (@sys.debug = 'ON') THEN SELECT 'The following query will be used to generate t" "he query for each sys view delta' AS 'Debug'; SELECT @sys.diagnostics.sql_gen_query_delta AS 'Debug'; END IF; PREPARE" " stmt_gen_query_delta FROM @sys.diagnostics.sql_gen_query_delta; SET v_old_group_concat_max_len = @@session.group_co" "ncat_max_len; SET @@session.group_concat_max_len = 2048; SET v_done = FALSE; OPEN c_sysviews_w_delta; c_sysviews_w_de" "lta_loop: LOOP FETCH c_sysviews_w_delta INTO v_table_name; IF v_done THEN LEAVE c_sysviews_w_delta_loop; END IF; SET" " @sys.diagnostics.table_name = v_table_name; EXECUTE stmt_gen_query_delta USING @sys.diagnostics.table_name; SELECT C" "ONCAT(@sys.diagnostics.sql_select, IF(where_delta IS NOT NULL, CONCAT('\\n WHERE ', where_delta), ''), IF(order_by_del" "ta IS NOT NULL, CONCAT('\\n ORDER BY ', order_by_delta), ''), IF(limit_rows IS NOT NULL, CONCAT('\\n LIMIT ', limit_row" "s), '') ) INTO @sys.diagnostics.sql_select FROM tmp_sys_views_delta WHERE TABLE_NAME = v_table_name; SELECT CONCAT('" "Delta ', v_table_name) AS 'The following output is:'; CALL sys.execute_prepared_stmt(@sys.diagnostics.sql_select); C" "ALL sys.execute_prepared_stmt(CONCAT('DROP TEMPORARY TABLE `tmp_', v_table_name, '_end`')); CALL sys.execute_prepared" "_stmt(CONCAT('DROP TEMPORARY TABLE `tmp_', v_table_name, '_start`')); END LOOP; CLOSE c_sysviews_w_delta; SET @@sessi" "on.group_concat_max_len = v_old_group_concat_max_len; DEALLOCATE PREPARE stmt_gen_query_delta; DROP TEMPORARY TABLE " "tmp_sys_views_delta; END IF; IF (v_has_metrics) THEN SELECT 'SELECT * FROM sys.metrics' AS 'The following output is:" "'; ELSE SELECT 'sys.metrics equivalent' AS 'The following output is:'; END IF; CALL sys.execute_prepared_stmt( CONCAT" "(v_sql_status_summary_select, v_sql_status_summary_delta, ', Type, s1.Enabled', v_sql_status_summary_from, ' ORDER BY" " Type, Variable_name' ) ); SET v_count = 0; WHILE (v_count < v_output_count) DO SET v_count = v_count + 1; SET v_tab" "le_name = CONCAT('tmp_metrics_', v_count); CALL sys.execute_prepared_stmt(CONCAT('DROP TEMPORARY TABLE IF EXISTS ', v" "_table_name)); END WHILE; IF (in_auto_config <> 'current') THEN CALL sys.ps_setup_reload_saved(); SET sql_log_bin = " "@log_bin; END IF; SET @sys.diagnostics.output_time = NULL, @sys.diagnostics.sql = NULL" ", @sys.diagnostics.sql_gen_query_delta = NULL, @sys.diagnostics.sql_gen_query_template = NULL, @sys.diagnostics.sq" "l_select = NULL, @sys.diagnostics.table_name = NULL; IF (v_this_thread_enabled = 'YES') THEN" " CALL sys.ps_setup_enable_thread(CONNECTION_ID()); END IF; IF (@log_bin = 1) THEN SET sql_log_bin = @log_bin; END IF" "; END;\n", "DROP PROCEDURE IF EXISTS ps_statement_avg_latency_histogram;\n", "CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE ps_statement_avg_latency_histogram () COMMENT '\\n Description\\n \\n Outp" "uts a textual histogram graph of the average latency values\\n across all normalized queries tracked within the Perfor" "mance Schema\\n events_statements_summary_by_digest table.\\n \\n Can be used to show a very high level picture of what " "kind of \\n latency distribution statements running within this instance have.\\n \\n Parameters\\n \\n None.\\n \\n Example" "\\n \\n mysql> CALL sys.ps_statement_avg_latency_histogram()\\\\G\\n *************************** 1. row ******************" "*********\\n Performance Schema Statement Digest Average Latency Histogram:\\n \\n . = 1 unit\\n * = 2 units\\n # = 3 unit" "s\\n \\n (0 - 38ms) 240 | ################################################################################\\n (38 - " "77ms) 38 | ......................................\\n (77 - 115ms) 3 | ...\\n (115 - 154ms) 62 | *************" "******************\\n (154 - 192ms) 3 | ...\\n (192 - 231ms) 0 |\\n (231 - 269ms) 0 |\\n (269 - 307ms) 0 |\\n " "(307 - 346ms) 0 |\\n (346 - 384ms) 1 | .\\n (384 - 423ms) 1 | .\\n (423 - 461ms) 0 |\\n (461 - 499ms) 0 |\\" "n (499 - 538ms) 0 |\\n (538 - 576ms) 0 |\\n (576 - 615ms) 1 | .\\n \\n Total Statements: 350; Buckets: 16; Bucke" "t Size: 38 ms;\\n ' SQL SECURITY INVOKER NOT DETERMINISTIC READS SQL DATA BEGIN SELECT CONCAT('\\n', '\\n . = 1 unit', " "'\\n * = 2 units', '\\n # = 3 units\\n', @label := CONCAT(@label_inner := CONCAT('\\n(0 - ', ROUND((@bucket_size := (SE" "LECT ROUND((MAX(avg_us) - MIN(avg_us)) / (@buckets := 16)) AS size FROM sys.x$ps_digest_avg_latency_distribution)) / " "(@unit_div := 1000)), (@unit := 'ms'), ')'), REPEAT(' ', (@max_label_size := ((1 + LENGTH(ROUND((@bucket_size * 15) /" " @unit_div)) + 3 + LENGTH(ROUND(@bucket_size * 16) / @unit_div)) + 1)) - LENGTH(@label_inner)), @count_in_bucket := I" "FNULL((SELECT SUM(cnt) FROM sys.x$ps_digest_avg_latency_distribution AS b1 WHERE b1.avg_us <= @bucket_size), 0)), RE" "PEAT(' ', (@max_label_len := (@max_label_size + LENGTH((@total_queries := (SELECT SUM(cnt) FROM sys.x$ps_digest_avg_l" "atency_distribution)))) + 1) - LENGTH(@label)), '| ', IFNULL(REPEAT(IF(@count_in_bucket < (@one_unit := 40), '.', IF(" "@count_in_bucket < (@two_unit := 80), '*', '#')), IF(@count_in_bucket < @one_unit, @count_in_bucket, " " IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''), @label := CONCAT(" "@label_inner := CONCAT('\\n(', ROUND(@bucket_size / @unit_div), ' - ', ROUND((@bucket_size * 2) / @unit_div), @unit, '" ")'), REPEAT(' ', @max_label_size - LENGTH(@label_inner)), @count_in_bucket := IFNULL((SELECT SUM(cnt) FROM sys.x$ps_d" "igest_avg_latency_distribution AS b1 WHERE b1.avg_us > @bucket_size AND b1.avg_us <= @bucket_size * 2), 0)), REPEAT(" "' ', @max_label_len - LENGTH(@label)), '| ', IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket " "< @two_unit, '*', '#')), IF(@count_in_bucket < @one_unit, @count_in_bucket, IF(@count_i" "n_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''), @label := CONCAT(@label_inner := CONCAT('\\n" "(', ROUND((@bucket_size * 2) / @unit_div), ' - ', ROUND((@bucket_size * 3) / @unit_div), @unit, ')'), REPEAT(' ', @ma" "x_label_size - LENGTH(@label_inner)), @count_in_bucket := IFNULL((SELECT SUM(cnt) FROM sys.x$ps_digest_avg_latency_di" "stribution AS b1 WHERE b1.avg_us > @bucket_size * 2 AND b1.avg_us <= @bucket_size * 3), 0)), REPEAT(' ', @max_label_" "len - LENGTH(@label)), '| ', IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*'" ", '#')), IF(@count_in_bucket < @one_unit, @count_in_bucket, IF(@count_in_bucket < @two_" "unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''), @label := CONCAT(@label_inner := CONCAT('\\n(', ROUND((@buck" "et_size * 3) / @unit_div), ' - ', ROUND((@bucket_size * 4) / @unit_div), @unit, ')'), REPEAT(' ', @max_label_size - L" "ENGTH(@label_inner)), @count_in_bucket := IFNULL((SELECT SUM(cnt) FROM sys.x$ps_digest_avg_latency_distribution AS b1" " WHERE b1.avg_us > @bucket_size * 3 AND b1.avg_us <= @bucket_size * 4), 0)), REPEAT(' ', @max_label_len - LENGTH(@la" "bel)), '| ', IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')), " " IF(@count_in_bucket < @one_unit, @count_in_bucket, IF(@count_in_bucket < @two_unit, @count_in_" "bucket / 2, @count_in_bucket / 3))), ''), @label := CONCAT(@label_inner := CONCAT('\\n(', ROUND((@bucket_size * 4) / @" "unit_div), ' - ', ROUND((@bucket_size * 5) / @unit_div), @unit, ')'), REPEAT(' ', @max_label_size - LENGTH(@label_inn" "er)), @count_in_bucket := IFNULL((SELECT SUM(cnt) FROM sys.x$ps_digest_avg_latency_distribution AS b1 WHERE b1.avg_u" "s > @bucket_size * 4 AND b1.avg_us <= @bucket_size * 5), 0)), REPEAT(' ', @max_label_len - LENGTH(@label)), '| ', IFN" "ULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')), IF(@coun" "t_in_bucket < @one_unit, @count_in_bucket, IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @cou" "nt_in_bucket / 3))), ''), @label := CONCAT(@label_inner := CONCAT('\\n(', ROUND((@bucket_size * 5) / @unit_div), ' - '" ", ROUND((@bucket_size * 6) / @unit_div), @unit, ')'), REPEAT(' ', @max_label_size - LENGTH(@label_inner)), @count_in_" "bucket := IFNULL((SELECT SUM(cnt) FROM sys.x$ps_digest_avg_latency_distribution AS b1 WHERE b1.avg_us > @bucket_size" " * 5 AND b1.avg_us <= @bucket_size * 6), 0)), REPEAT(' ', @max_label_len - LENGTH(@label)), '| ', IFNULL(REPEAT(IF(@c" "ount_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')), IF(@count_in_bucket < @o" "ne_unit, @count_in_bucket, IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3" "))), ''), @label := CONCAT(@label_inner := CONCAT('\\n(', ROUND((@bucket_size * 6) / @unit_div), ' - ', ROUND((@bucket" "_size * 7) / @unit_div), @unit, ')'), REPEAT(' ', @max_label_size - LENGTH(@label_inner)), @count_in_bucket := IFNULL" "((SELECT SUM(cnt) FROM sys.x$ps_digest_avg_latency_distribution AS b1 WHERE b1.avg_us > @bucket_size * 6 AND b1.avg_" "us <= @bucket_size * 7), 0)), REPEAT(' ', @max_label_len - LENGTH(@label)), '| ', IFNULL(REPEAT(IF(@count_in_bucket <" " @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')), IF(@count_in_bucket < @one_unit, @count_" "in_bucket, IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''), @label" " := CONCAT(@label_inner := CONCAT('\\n(', ROUND((@bucket_size * 7) / @unit_div), ' - ', ROUND((@bucket_size * 8) / @un" "it_div), @unit, ')'), REPEAT(' ', @max_label_size - LENGTH(@label_inner)), @count_in_bucket := IFNULL((SELECT SUM(cnt" ") FROM sys.x$ps_digest_avg_latency_distribution AS b1 WHERE b1.avg_us > @bucket_size * 7 AND b1.avg_us <= @bucket_si" "ze * 8), 0)), REPEAT(' ', @max_label_len - LENGTH(@label)), '| ', IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.'," " IF(@count_in_bucket < @two_unit, '*', '#')), IF(@count_in_bucket < @one_unit, @count_in_bucket, " " IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''), @label := CONCAT(@labe" "l_inner := CONCAT('\\n(', ROUND((@bucket_size * 8) / @unit_div), ' - ', ROUND((@bucket_size * 9) / @unit_div), @unit, " "')'), REPEAT(' ', @max_label_size - LENGTH(@label_inner)), @count_in_bucket := IFNULL((SELECT SUM(cnt) FROM sys.x$ps_" "digest_avg_latency_distribution AS b1 WHERE b1.avg_us > @bucket_size * 8 AND b1.avg_us <= @bucket_size * 9), 0)), RE" "PEAT(' ', @max_label_len - LENGTH(@label)), '| ', IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bu" "cket < @two_unit, '*', '#')), IF(@count_in_bucket < @one_unit, @count_in_bucket, IF(@co" "unt_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''), @label := CONCAT(@label_inner := CONCA" "T('\\n(', ROUND((@bucket_size * 9) / @unit_div), ' - ', ROUND((@bucket_size * 10) / @unit_div), @unit, ')'), REPEAT(' " "', @max_label_size - LENGTH(@label_inner)), @count_in_bucket := IFNULL((SELECT SUM(cnt) FROM sys.x$ps_digest_avg_late" "ncy_distribution AS b1 WHERE b1.avg_us > @bucket_size * 9 AND b1.avg_us <= @bucket_size * 10), 0)), REPEAT(' ', @max" "_label_len - LENGTH(@label)), '| ', IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_un" "it, '*', '#')), IF(@count_in_bucket < @one_unit, @count_in_bucket, IF(@count_in_bucket " "< @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''), @label := CONCAT(@label_inner := CONCAT('\\n(', ROUND" "((@bucket_size * 10) / @unit_div), ' - ', ROUND((@bucket_size * 11) / @unit_div), @unit, ')'), REPEAT(' ', @max_label" "_size - LENGTH(@label_inner)), @count_in_bucket := IFNULL((SELECT SUM(cnt) FROM sys.x$ps_digest_avg_latency_distribut" "ion AS b1 WHERE b1.avg_us > @bucket_size * 10 AND b1.avg_us <= @bucket_size * 11), 0)), REPEAT(' ', @max_label_len -" " LENGTH(@label)), '| ', IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#'" ")), IF(@count_in_bucket < @one_unit, @count_in_bucket, IF(@count_in_bucket < @two_unit," " @count_in_bucket / 2, @count_in_bucket / 3))), ''), @label := CONCAT(@label_inner := CONCAT('\\n(', ROUND((@bucket_si" "ze * 11) / @unit_div), ' - ', ROUND((@bucket_size * 12) / @unit_div), @unit, ')'), REPEAT(' ', @max_label_size - LENG" "TH(@label_inner)), @count_in_bucket := IFNULL((SELECT SUM(cnt) FROM sys.x$ps_digest_avg_latency_distribution AS b1 W" "HERE b1.avg_us > @bucket_size * 11 AND b1.avg_us <= @bucket_size * 12), 0)), REPEAT(' ', @max_label_len - LENGTH(@lab" "el)), '| ', IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')), " " IF(@count_in_bucket < @one_unit, @count_in_bucket, IF(@count_in_bucket < @two_unit, @count_in_b" "ucket / 2, @count_in_bucket / 3))), ''), @label := CONCAT(@label_inner := CONCAT('\\n(', ROUND((@bucket_size * 12) / @" "unit_div), ' - ', ROUND((@bucket_size * 13) / @unit_div), @unit, ')'), REPEAT(' ', @max_label_size - LENGTH(@label_in" "ner)), @count_in_bucket := IFNULL((SELECT SUM(cnt) FROM sys.x$ps_digest_avg_latency_distribution AS b1 WHERE b1.avg_" "us > @bucket_size * 12 AND b1.avg_us <= @bucket_size * 13), 0)), REPEAT(' ', @max_label_len - LENGTH(@label)), '| ', " "IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')), IF(@c" "ount_in_bucket < @one_unit, @count_in_bucket, IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @" "count_in_bucket / 3))), ''), @label := CONCAT(@label_inner := CONCAT('\\n(', ROUND((@bucket_size * 13) / @unit_div), '" " - ', ROUND((@bucket_size * 14) / @unit_div), @unit, ')'), REPEAT(' ', @max_label_size - LENGTH(@label_inner)), @coun" "t_in_bucket := IFNULL((SELECT SUM(cnt) FROM sys.x$ps_digest_avg_latency_distribution AS b1 WHERE b1.avg_us > @bucket" "_size * 13 AND b1.avg_us <= @bucket_size * 14), 0)), REPEAT(' ', @max_label_len - LENGTH(@label)), '| ', IFNULL(REPEA" "T(IF(@count_in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')), IF(@count_in_buck" "et < @one_unit, @count_in_bucket, IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_buc" "ket / 3))), ''), @label := CONCAT(@label_inner := CONCAT('\\n(', ROUND((@bucket_size * 14) / @unit_div), ' - ', ROUND(" "(@bucket_size * 15) / @unit_div), @unit, ')'), REPEAT(' ', @max_label_size - LENGTH(@label_inner)), @count_in_bucket " ":= IFNULL((SELECT SUM(cnt) FROM sys.x$ps_digest_avg_latency_distribution AS b1 WHERE b1.avg_us > @bucket_size * 14 A" "ND b1.avg_us <= @bucket_size * 15), 0)), REPEAT(' ', @max_label_len - LENGTH(@label)), '| ', IFNULL(REPEAT(IF(@count_" "in_bucket < @one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')), IF(@count_in_bucket < @one_un" "it, @count_in_bucket, IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), " "''), @label := CONCAT(@label_inner := CONCAT('\\n(', ROUND((@bucket_size * 15) / @unit_div), ' - ', ROUND((@bucket_siz" "e * 16) / @unit_div), @unit, ')'), REPEAT(' ', @max_label_size - LENGTH(@label_inner)), @count_in_bucket := IFNULL((S" "ELECT SUM(cnt) FROM sys.x$ps_digest_avg_latency_distribution AS b1 WHERE b1.avg_us > @bucket_size * 15 AND b1.avg_us" " <= @bucket_size * 16), 0)), REPEAT(' ', @max_label_len - LENGTH(@label)), '| ', IFNULL(REPEAT(IF(@count_in_bucket < " "@one_unit, '.', IF(@count_in_bucket < @two_unit, '*', '#')), IF(@count_in_bucket < @one_unit, @count_i" "n_bucket, IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), ''), '\\n\\n " " Total Statements: ', @total_queries, '; Buckets: ', @buckets , '; Bucket Size: ', ROUND(@bucket_size / @unit_div) , " "' ', @unit, ';\\n' ) AS `Performance Schema Statement Digest Average Latency Histogram`; END ;\n", "DROP PROCEDURE IF EXISTS ps_trace_statement_digest;\n", "CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE ps_trace_statement_digest ( IN in_digest VARCHAR(32), IN in_runtime INT" ", IN in_interval DECIMAL(2,2), IN in_start_fresh BOOLEAN, IN in_auto_enable BOOLEAN ) COMMENT '\\n Description\\n \\n Tr" "aces all instrumentation within Performance Schema for a specific\\n Statement Digest.\\n \\n When finding a statement o" "f interest within the\\n performance_schema.events_statements_summary_by_digest table, feed\\n the DIGEST MD5 value in " "to this procedure, set how long to poll for,\\n and at what interval to poll, and it will generate a report of all\\n s" "tatistics tracked within Performance Schema for that digest for the\\n interval.\\n \\n It will also attempt to generate" " an EXPLAIN for the longest running\\n example of the digest during the interval. Note this may fail, as:\\n \\n * Perfo" "rmance Schema truncates long SQL_TEXT values (and hence the\\n EXPLAIN will fail due to parse errors)\\n * the default " "schema is sys (so tables that are not fully qualified\\n in the query may not be found)\\n * some queries such as SHOW " "are not supported in EXPLAIN.\\n \\n When the EXPLAIN fails, the error will be ignored and no EXPLAIN\\n output generate" "d.\\n \\n Requires the SUPER privilege for \"SET sql_log_bin = 0;\".\\n \\n Parameters\\n \\n in_digest (VARCHAR(32)):\\n Th" "e statement digest identifier you would like to analyze\\n in_runtime (INT):\\n The number of seconds to run analysis f" "or\\n in_interval (DECIMAL(2,2)):\\n The interval (in seconds, may be fractional) at which to try\\n and take snapshots\\" "n in_start_fresh (BOOLEAN):\\n Whether to TRUNCATE the events_statements_history_long and\\n events_stages_history_long" " tables before starting\\n in_auto_enable (BOOLEAN):\\n Whether to automatically turn on required consumers\\n \\n Exampl" "e\\n \\n mysql> call ps_trace_statement_digest(\\'891ec6860f98ba46d89dd20b0c03652c\\', 10, 0.1, true, true);\\n +---------" "-----------+\\n | SUMMARY STATISTICS |\\n +--------------------+\\n | SUMMARY STATISTICS |\\n +--------------------+\\n 1 " "row in set (9.11 sec)\\n \\n +------------+-----------+-----------+-----------+---------------+------------+-----------" "-+\\n | executions | exec_time | lock_time | rows_sent | rows_examined | tmp_tables | full_scans |\\n +------------+---" "--------+-----------+-----------+---------------+------------+------------+\\n | 21 | 4.11 ms | 2.00 ms | " " 0 | 21 | 0 | 0 |\\n +------------+-----------+-----------+-----------+-----------" "----+------------+------------+\\n 1 row in set (9.11 sec)\\n \\n +------------------------------------------+-------+--" "---------+\\n | event_name | count | latency |\\n +------------------------------------" "------+-------+-----------+\\n | stage/sql/checking query cache for query | 16 | 724.37 us |\\n | stage/sql/statisti" "cs | 16 | 546.92 us |\\n | stage/sql/freeing items | 18 | 520.11 us |\\n | s" "tage/sql/init | 51 | 466.80 us |\\n ...\\n | stage/sql/cleaning up | " " 18 | 11.92 us |\\n | stage/sql/executing | 16 | 6.95 us |\\n +-----------------------------" "-------------+-------+-----------+\\n 17 rows in set (9.12 sec)\\n \\n +---------------------------+\\n | LONGEST RUNNING" " STATEMENT |\\n +---------------------------+\\n | LONGEST RUNNING STATEMENT |\\n +---------------------------+\\n 1 row " "in set (9.16 sec)\\n \\n +-----------+-----------+-----------+-----------+---------------+------------+-----------+\\n |" " thread_id | exec_time | lock_time | rows_sent | rows_examined | tmp_tables | full_scan |\\n +-----------+-----------+" "-----------+-----------+---------------+------------+-----------+\\n | 166646 | 618.43 us | 1.00 ms | 0 |" " 1 | 0 | 0 |\\n +-----------+-----------+-----------+-----------+---------------+--------" "----+-----------+\\n 1 row in set (9.16 sec)\\n \\n // Truncated for clarity...\\n +-------------------------------------" "----------------------------+\\n | sql_text |\\n +--------------" "---------------------------------------------------+\\n | select hibeventhe0_.id as id1382_, hibeventhe0_.createdTime " "... |\\n +-----------------------------------------------------------------+\\n 1 row in set (9.17 sec)\\n \\n +---------" "---------------------------------+-----------+\\n | event_name | latency |\\n +--------" "----------------------------------+-----------+\\n | stage/sql/init | 8.61 us |\\n | stage/" "sql/Waiting for query cache lock | 453.23 us |\\n | stage/sql/init | 331.07 ns |\\n | stage" "/sql/checking query cache for query | 43.04 us |\\n ...\\n | stage/sql/freeing items | 30.46 us |\\n " "| stage/sql/cleaning up | 662.13 ns |\\n +------------------------------------------+-----------+\\n" " 18 rows in set (9.23 sec)\\n \\n +----+-------------+--------------+-------+---------------+-----------+---------+----" "---------+------+-------+\\n | id | select_type | table | type | possible_keys | key | key_len | ref " " | rows | Extra |\\n +----+-------------+--------------+-------+---------------+-----------+---------+------------" "-+------+-------+\\n | 1 | SIMPLE | hibeventhe0_ | const | fixedTime | fixedTime | 775 | const,const | " " 1 | NULL |\\n +----+-------------+--------------+-------+---------------+-----------+---------+-------------+------" "+-------+\\n 1 row in set (9.27 sec)\\n \\n Query OK, 0 rows affected (9.28 sec)\\n ' SQL SECURITY INVOKER NOT DETERMINIS" "TIC MODIFIES SQL DATA BEGIN DECLARE v_start_fresh BOOLEAN DEFAULT false; DECLARE v_auto_enable BOOLEAN DEFAULT false" "; DECLARE v_explain BOOLEAN DEFAULT true; DECLARE v_this_thread_enabed ENUM('YES', 'NO'); DECLARE v_runtime INT D" "EFAULT 0; DECLARE v_start INT DEFAULT 0; DECLARE v_found_stmts INT; SET @log_bin := @@sql_log_bin; SET sql_log_bin =" " 0; SELECT INSTRUMENTED INTO v_this_thread_enabed FROM performance_schema.threads WHERE PROCESSLIST_ID = CONNECTION_" "ID(); CALL sys.ps_setup_disable_thread(CONNECTION_ID()); DROP TEMPORARY TABLE IF EXISTS stmt_trace; CREATE TEMPORARY" " TABLE stmt_trace ( thread_id BIGINT UNSIGNED, timer_start BIGINT UNSIGNED, event_id BIGINT UNSIGNED, sql_text longte" "xt, timer_wait BIGINT UNSIGNED, lock_time BIGINT UNSIGNED, errors BIGINT UNSIGNED, mysql_errno INT, rows_sent BIGINT " "UNSIGNED, rows_affected BIGINT UNSIGNED, rows_examined BIGINT UNSIGNED, created_tmp_tables BIGINT UNSIGNED, created_t" "mp_disk_tables BIGINT UNSIGNED, no_index_used BIGINT UNSIGNED, PRIMARY KEY (thread_id, timer_start) ); DROP TEMPORAR" "Y TABLE IF EXISTS stmt_stages; CREATE TEMPORARY TABLE stmt_stages ( event_id BIGINT UNSIGNED, stmt_id BIGINT UNSIGNED" ", event_name VARCHAR(128), timer_wait BIGINT UNSIGNED, PRIMARY KEY (event_id) ); SET v_start_fresh = in_start_fresh;" " IF v_start_fresh THEN TRUNCATE TABLE performance_schema.events_statements_history_long; TRUNCATE TABLE performance_s" "chema.events_stages_history_long; END IF; SET v_auto_enable = in_auto_enable; IF v_auto_enable THEN CALL sys.ps_setu" "p_save(0); UPDATE performance_schema.threads SET INSTRUMENTED = IF(PROCESSLIST_ID IS NOT NULL, 'YES', 'NO'); UPDATE" " performance_schema.setup_consumers SET ENABLED = 'YES' WHERE NAME NOT LIKE '%\\_history' AND NAME NOT LIKE 'events_wa" "it%' AND NAME NOT LIKE 'events_transactions%' AND NAME <> 'statements_digest'; UPDATE performance_schema.setup_instr" "uments SET ENABLED = 'YES', TIMED = 'YES' WHERE NAME LIKE 'statement/%' OR NAME LIKE 'stage/%'; END IF; WHILE v_ru" "ntime < in_runtime DO SELECT UNIX_TIMESTAMP() INTO v_start; INSERT IGNORE INTO stmt_trace SELECT thread_id, timer_st" "art, event_id, sql_text, timer_wait, lock_time, errors, mysql_errno, rows_sent, rows_affected, rows_examined, create" "d_tmp_tables, created_tmp_disk_tables, no_index_used FROM performance_schema.events_statements_history_long WHERE dig" "est = in_digest; INSERT IGNORE INTO stmt_stages SELECT stages.event_id, stmt_trace.event_id, stages.event_name, stag" "es.timer_wait FROM performance_schema.events_stages_history_long AS stages JOIN stmt_trace ON stages.nesting_event_id" " = stmt_trace.event_id; SELECT SLEEP(in_interval) INTO @sleep; SET v_runtime = v_runtime + (UNIX_TIMESTAMP() - v_sta" "rt); END WHILE; SELECT \"SUMMARY STATISTICS\"; SELECT COUNT(*) executions, sys.format_time(SUM(timer_wait)) AS exec" "_time, sys.format_time(SUM(lock_time)) AS lock_time, SUM(rows_sent) AS rows_sent, SUM(rows_affected) AS rows_affected" ", SUM(rows_examined) AS rows_examined, SUM(created_tmp_tables) AS tmp_tables, SUM(no_index_used) AS full_scans FROM s" "tmt_trace; SELECT event_name, COUNT(*) as count, sys.format_time(SUM(timer_wait)) as latency FROM stmt_stages GROUP " "BY event_name ORDER BY SUM(timer_wait) DESC; SELECT \"LONGEST RUNNING STATEMENT\"; SELECT thread_id, sys.format_tim" "e(timer_wait) AS exec_time, sys.format_time(lock_time) AS lock_time, rows_sent, rows_affected, rows_examined, created" "_tmp_tables AS tmp_tables, no_index_used AS full_scan FROM stmt_trace ORDER BY timer_wait DESC LIMIT 1; SELECT sql_t" "ext FROM stmt_trace ORDER BY timer_wait DESC LIMIT 1; SELECT sql_text, event_id INTO @sql, @sql_id FROM stmt_trace O" "RDER BY timer_wait DESC LIMIT 1; IF (@sql_id IS NOT NULL) THEN SELECT event_name, sys.format_time(timer_wait) as lat" "ency FROM stmt_stages WHERE stmt_id = @sql_id ORDER BY event_id; END IF; DROP TEMPORARY TABLE stmt_trace; DROP TEMPO" "RARY TABLE stmt_stages; IF (@sql IS NOT NULL) THEN SET @stmt := CONCAT(\"EXPLAIN FORMAT=JSON \", @sql); BEGIN DECLAR" "E CONTINUE HANDLER FOR 1064, 1146 SET v_explain = false; PREPARE explain_stmt FROM @stmt; END; IF (v_explain) THEN " "EXECUTE explain_stmt; DEALLOCATE PREPARE explain_stmt; END IF; END IF; IF v_auto_enable THEN CALL sys.ps_setup_reloa" "d_saved(); END IF; IF (v_this_thread_enabed = 'YES') THEN CALL sys.ps_setup_enable_thread(CONNECTION_ID()); END IF; " "SET sql_log_bin = @log_bin; END;\n", "DROP PROCEDURE IF EXISTS ps_trace_thread;\n", "CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE ps_trace_thread ( IN in_thread_id BIGINT UNSIGNED, IN in_outfile VARCHA" "R(255), IN in_max_runtime DECIMAL(20,2), IN in_interval DECIMAL(20,2), IN in_start_fresh BOOLEAN, IN in_auto_setup BO" "OLEAN, IN in_debug BOOLEAN ) COMMENT '\\n Description\\n \\n Dumps all data within Performance Schema for an instrumente" "d thread,\\n to create a DOT formatted graph file. \\n \\n Each resultset returned from the procedure should be used for" " a complete graph\\n \\n Requires the SUPER privilege for \"SET sql_log_bin = 0;\".\\n \\n Parameters\\n \\n in_thread_id (" "BIGINT UNSIGNED):\\n The thread that you would like a stack trace for\\n in_outfile (VARCHAR(255)):\\n The filename the" " dot file will be written to\\n in_max_runtime (DECIMAL(20,2)):\\n The maximum time to keep collecting data.\\n Use NULL" " to get the default which is 60 seconds.\\n in_interval (DECIMAL(20,2)): \\n How long to sleep between data collections" ". \\n Use NULL to get the default which is 1 second.\\n in_start_fresh (BOOLEAN):\\n Whether to reset all Performance Sc" "hema data before tracing.\\n in_auto_setup (BOOLEAN):\\n Whether to disable all other threads and enable all consumers/" "instruments. \\n This will also reset the settings at the end of the run.\\n in_debug (BOOLEAN):\\n Whether you would li" "ke to include file:lineno in the graph\\n \\n Example\\n \\n mysql> CALL sys.ps_trace_thread(25, CONCAT(\\'/tmp/stack-\\', " "REPLACE(NOW(), \\' \\', \\'-\\'), \\'.dot\\'), NULL, NULL, TRUE, TRUE, TRUE);\\n +-------------------+\\n | summary " " |\\n +-------------------+\\n | Disabled 1 thread |\\n +-------------------+\\n 1 row in set (0.00 sec)\\n \\n +----------" "-----------------------------------+\\n | Info |\\n +---------------------------" "------------------+\\n | Data collection starting for THREAD_ID = 25 |\\n +--------------------------------------------" "-+\\n 1 row in set (0.03 sec)\\n \\n +-----------------------------------------------------------+\\n | Info " " |\\n +-----------------------------------------------------------+\\n | Stack " "trace written to /tmp/stack-2014-02-16-21:18:41.dot |\\n +-----------------------------------------------------------+" "\\n 1 row in set (60.07 sec)\\n \\n +-------------------------------------------------------------------+\\n | Convert to" " PDF |\\n +--------------------------------------------------------" "-----------+\\n | dot -Tpdf -o /tmp/stack_25.pdf /tmp/stack-2014-02-16-21:18:41.dot |\\n +-----------------------------" "--------------------------------------+\\n 1 row in set (60.07 sec)\\n \\n +--------------------------------------------" "-----------------------+\\n | Convert to PNG |\\n +-----------------" "--------------------------------------------------+\\n | dot -Tpng -o /tmp/stack_25.png /tmp/stack-2014-02-16-21:18:41" ".dot |\\n +-------------------------------------------------------------------+\\n 1 row in set (60.07 sec)\\n \\n +-----" "-------------+\\n | summary |\\n +------------------+\\n | Enabled 1 thread |\\n +------------------+\\n 1 row in" " set (60.32 sec)\\n ' SQL SECURITY INVOKER NOT DETERMINISTIC MODIFIES SQL DATA BEGIN DECLARE v_done bool DEFAULT FALSE" "; DECLARE v_start, v_runtime DECIMAL(20,2) DEFAULT 0.0; DECLARE v_min_event_id bigint unsigned DEFAULT 0; DECLARE v_t" "his_thread_enabed ENUM('YES', 'NO'); DECLARE v_event longtext; DECLARE c_stack CURSOR FOR SELECT CONCAT(IF(nesting_ev" "ent_id IS NOT NULL, CONCAT(nesting_event_id, ' -> '), ''), event_id, '; ', event_id, ' [label=\"', '(', sys.format_t" "ime(timer_wait), ') ', IF (event_name NOT LIKE 'wait/io%', SUBSTRING_INDEX(event_name, '/', -2), IF (event_name NOT" " LIKE 'wait/io/file%' OR event_name NOT LIKE 'wait/io/socket%', SUBSTRING_INDEX(event_name, '/', -4), event_name) ), " "IF (event_name LIKE 'transaction', IFNULL(CONCAT('\\\\n', wait_info), ''), ''), IF (event_name LIKE 'statement/%', IFNU" "LL(CONCAT('\\\\n', wait_info), ''), ''), IF (in_debug AND event_name LIKE 'wait%', wait_info, ''), '\", ', CASE WHEN e" "vent_name LIKE 'wait/io/file%' THEN 'shape=box, style=filled, color=red' WHEN event_name LIKE 'wait/io/table%' THEN " " 'shape=box, style=filled, color=green' WHEN event_name LIKE 'wait/io/socket%' THEN 'shape=box, style=filled, color=y" "ellow' WHEN event_name LIKE 'wait/synch/mutex%' THEN 'style=filled, color=lightskyblue' WHEN event_name LIKE 'wait/sy" "nch/cond%' THEN 'style=filled, color=darkseagreen3' WHEN event_name LIKE 'wait/synch/rwlock%' THEN 'style=filled, col" "or=orchid' WHEN event_name LIKE 'wait/synch/sxlock%' THEN 'style=filled, color=palevioletred' WHEN event_name LIKE '" "wait/lock%' THEN 'shape=box, style=filled, color=tan' WHEN event_name LIKE 'statement/%' THEN CONCAT('shape=box, styl" "e=bold', CASE WHEN event_name LIKE 'statement/com/%' THEN ' style=filled, color=darkseagreen' ELSE IF((timer_wait/100" "0000000000) > @@long_query_time, ' style=filled, color=red', ' style=filled, color=lightblue') END ) WHEN event_nam" "e LIKE 'transaction' THEN 'shape=box, style=filled, color=lightblue3' WHEN event_name LIKE 'stage/%' THEN 'style=fill" "ed, color=slategray3' WHEN event_name LIKE '%idle%' THEN 'shape=box, style=filled, color=firebrick3' ELSE '' END, '];" "\\n' ) event, event_id FROM ( (SELECT thread_id, event_id, event_name, timer_wait, timer_start, nesting_event_id, CONC" "AT('trx_id: ', IFNULL(trx_id, ''), '\\\\n', 'gtid: ', IFNULL(gtid, ''), '\\\\n', 'state: ', state, '\\\\n', 'mode: ', acce" "ss_mode, '\\\\n', 'isolation: ', isolation_level, '\\\\n', 'autocommit: ', autocommit, '\\\\n', 'savepoints: ', number_of_s" "avepoints, '\\\\n' ) AS wait_info FROM performance_schema.events_transactions_history_long WHERE thread_id = in_thread_" "id AND event_id > v_min_event_id) UNION (SELECT thread_id, event_id, event_name, timer_wait, timer_start, nesting_eve" "nt_id, CONCAT('statement: ', sql_text, '\\\\n', 'errors: ', errors, '\\\\n', 'warnings: ', warnings, '\\\\n', 'lock time: " "', sys.format_time(lock_time),'\\\\n', 'rows affected: ', rows_affected, '\\\\n', 'rows sent: ', rows_sent, '\\\\n', 'rows " "examined: ', rows_examined, '\\\\n', 'tmp tables: ', created_tmp_tables, '\\\\n', 'tmp disk tables: ', created_tmp_disk_t" "ables, '\\\\n' 'select scan: ', select_scan, '\\\\n', 'select full join: ', select_full_join, '\\\\n', 'select full range j" "oin: ', select_full_range_join, '\\\\n', 'select range: ', select_range, '\\\\n', 'select range check: ', select_range_ch" "eck, '\\\\n', 'sort merge passes: ', sort_merge_passes, '\\\\n', 'sort rows: ', sort_rows, '\\\\n', 'sort range: ', sort_r" "ange, '\\\\n', 'sort scan: ', sort_scan, '\\\\n', 'no index used: ', IF(no_index_used, 'TRUE', 'FALSE'), '\\\\n', 'no good " "index used: ', IF(no_good_index_used, 'TRUE', 'FALSE'), '\\\\n' ) AS wait_info FROM performance_schema.events_statement" "s_history_long WHERE thread_id = in_thread_id AND event_id > v_min_event_id) UNION (SELECT thread_id, event_id, event" "_name, timer_wait, timer_start, nesting_event_id, null AS wait_info FROM performance_schema.events_stages_history_lon" "g WHERE thread_id = in_thread_id AND event_id > v_min_event_id) UNION (SELECT thread_id, event_id, CONCAT(event_na" "me, IF(event_name NOT LIKE 'wait/synch/mutex%', IFNULL(CONCAT(' - ', operation), ''), ''), IF(number_of_bytes IS NO" "T NULL, CONCAT(' ', number_of_bytes, ' bytes'), ''), IF(event_name LIKE 'wait/io/file%', '\\\\n', ''), IF(object_schema" " IS NOT NULL, CONCAT('\\\\nObject: ', object_schema, '.'), ''), IF(object_name IS NOT NULL, IF (event_name LIKE 'wait" "/io/socket%', CONCAT('\\\\n', IF (object_name LIKE ':0%', @@socket, object_name)), object_name), '' ), IF(index_name IS" " NOT NULL, CONCAT(' Index: ', index_name), ''), '\\\\n' ) AS event_name, timer_wait, timer_start, nesting_event_id, sou" "rce AS wait_info FROM performance_schema.events_waits_history_long WHERE thread_id = in_thread_id AND event_id > v_mi" "n_event_id) ) events ORDER BY event_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = TRUE; SET @log_bin := @" "@sql_log_bin; SET sql_log_bin = 0; SELECT INSTRUMENTED INTO v_this_thread_enabed FROM performance_schema.threads WHE" "RE PROCESSLIST_ID = CONNECTION_ID(); CALL sys.ps_setup_disable_thread(CONNECTION_ID()); IF (in_auto_setup) THEN CALL" " sys.ps_setup_save(0); DELETE FROM performance_schema.setup_actors; UPDATE performance_schema.threads SET INSTRUMEN" "TED = IF(THREAD_ID = in_thread_id, 'YES', 'NO'); UPDATE performance_schema.setup_consumers SET ENABLED = 'YES' WHERE" " NAME NOT LIKE '%\\_history'; UPDATE performance_schema.setup_instruments SET ENABLED = 'YES', TIMED = 'YES'; END I" "F; IF (in_start_fresh) THEN TRUNCATE performance_schema.events_transactions_history_long; TRUNCATE performance_schem" "a.events_statements_history_long; TRUNCATE performance_schema.events_stages_history_long; TRUNCATE performance_schema" ".events_waits_history_long; END IF; DROP TEMPORARY TABLE IF EXISTS tmp_events; CREATE TEMPORARY TABLE tmp_events ( e" "vent_id bigint unsigned NOT NULL, event longblob, PRIMARY KEY (event_id) ); INSERT INTO tmp_events VALUES (0, CONCAT" "('digraph events { rankdir=LR; nodesep=0.10;\\n', '// Stack created .....: ', NOW(), '\\n', '// MySQL version .....: '," " VERSION(), '\\n', '// MySQL hostname ....: ', @@hostname, '\\n', '// MySQL port ........: ', @@port, '\\n', '// MySQL s" "ocket ......: ', @@socket, '\\n', '// MySQL user ........: ', CURRENT_USER(), '\\n')); SELECT CONCAT('Data collection " "starting for THREAD_ID = ', in_thread_id) AS 'Info'; SET v_min_event_id = 0, v_start = UNIX_TIMESTAMP(), in_i" "nterval = IFNULL(in_interval, 1.00), in_max_runtime = IFNULL(in_max_runtime, 60.00); WHILE (v_runtime < in_max_ru" "ntime AND (SELECT INSTRUMENTED FROM performance_schema.threads WHERE THREAD_ID = in_thread_id) = 'YES') DO SET v_done" " = FALSE; OPEN c_stack; c_stack_loop: LOOP FETCH c_stack INTO v_event, v_min_event_id; IF v_done THEN LEAVE c_stack_l" "oop; END IF; IF (LENGTH(v_event) > 0) THEN INSERT INTO tmp_events VALUES (v_min_event_id, v_event); END IF; END LOOP" "; CLOSE c_stack; SELECT SLEEP(in_interval) INTO @sleep; SET v_runtime = (UNIX_TIMESTAMP() - v_start); END WHILE; IN" "SERT INTO tmp_events VALUES (v_min_event_id+1, '}'); SET @query = CONCAT('SELECT event FROM tmp_events ORDER BY even" "t_id INTO OUTFILE ''', in_outfile, ''' FIELDS ESCAPED BY '''' LINES TERMINATED BY '''''); PREPARE stmt_output FROM @q" "uery; EXECUTE stmt_output; DEALLOCATE PREPARE stmt_output; SELECT CONCAT('Stack trace written to ', in_outfile) AS '" "Info'; SELECT CONCAT('dot -Tpdf -o /tmp/stack_', in_thread_id, '.pdf ', in_outfile) AS 'Convert to PDF'; SELECT CONCA" "T('dot -Tpng -o /tmp/stack_', in_thread_id, '.png ', in_outfile) AS 'Convert to PNG'; DROP TEMPORARY TABLE tmp_events" "; IF (in_auto_setup) THEN CALL sys.ps_setup_reload_saved(); END IF; IF (v_this_thread_enabed = 'YES') THEN CALL sys." "ps_setup_enable_thread(CONNECTION_ID()); END IF; SET sql_log_bin = @log_bin; END;\n", "DROP PROCEDURE IF EXISTS ps_setup_disable_background_threads;\n", "CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE ps_setup_disable_background_threads () COMMENT '\\n Description\\n \\n Dis" "able all background thread instrumentation within Performance Schema.\\n \\n Parameters\\n \\n None.\\n \\n Example\\n \\n my" "sql> CALL sys.ps_setup_disable_background_threads();\\n +--------------------------------+\\n | summary " " |\\n +--------------------------------+\\n | Disabled 18 background threads |\\n +------------------------------" "--+\\n 1 row in set (0.00 sec)\\n ' SQL SECURITY INVOKER NOT DETERMINISTIC MODIFIES SQL DATA BEGIN UPDATE performance_s" "chema.threads SET instrumented = 'NO' WHERE type = 'BACKGROUND'; SELECT CONCAT('Disabled ', @rows := ROW_COUNT(), ' " "background thread', IF(@rows != 1, 's', '')) AS summary; END;\n", "DROP PROCEDURE IF EXISTS ps_setup_disable_consumer;\n", "CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE ps_setup_disable_consumer ( IN consumer VARCHAR(128) ) COMMENT '\\n Desc" "ription\\n \\n Disables consumers within Performance Schema \\n matching the input pattern.\\n \\n Parameters\\n \\n consume" "r (VARCHAR(128)):\\n A LIKE pattern match (using \"%consumer%\") of consumers to disable\\n \\n Example\\n \\n To disable " "all consumers:\\n \\n mysql> CALL sys.ps_setup_disable_consumer(\\'\\');\\n +--------------------------+\\n | summary " " |\\n +--------------------------+\\n | Disabled 15 consumers |\\n +--------------------------+\\n 1 row in" " set (0.02 sec)\\n \\n To disable just the event_stage consumers:\\n \\n mysql> CALL sys.ps_setup_disable_comsumers(\\'sta" "ge\\');\\n +------------------------+\\n | summary |\\n +------------------------+\\n | Disabled 3 consumer" "s |\\n +------------------------+\\n 1 row in set (0.00 sec)\\n ' SQL SECURITY INVOKER NOT DETERMINISTIC MODIFIES SQL " "DATA BEGIN UPDATE performance_schema.setup_consumers SET enabled = 'NO' WHERE name LIKE CONCAT('%', consumer, '%'); " "SELECT CONCAT('Disabled ', @rows := ROW_COUNT(), ' consumer', IF(@rows != 1, 's', '')) AS summary; END;\n", "DROP PROCEDURE IF EXISTS ps_setup_disable_instrument;\n", "CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE ps_setup_disable_instrument ( IN in_pattern VARCHAR(128) ) COMMENT '\\n " "Description\\n \\n Disables instruments within Performance Schema \\n matching the input pattern.\\n \\n Parameters\\n \\n i" "n_pattern (VARCHAR(128)):\\n A LIKE pattern match (using \"%in_pattern%\") of events to disable\\n \\n Example\\n \\n To d" "isable all mutex instruments:\\n \\n mysql> CALL sys.ps_setup_disable_instrument(\\'wait/synch/mutex\\');\\n +------------" "--------------+\\n | summary |\\n +--------------------------+\\n | Disabled 155 instruments |\\n +-----" "---------------------+\\n 1 row in set (0.02 sec)\\n \\n To disable just a specific TCP/IP based network IO instrument:\\" "n \\n mysql> CALL sys.ps_setup_disable_instrument(\\'wait/io/socket/sql/server_tcpip_socket\\');\\n +--------------------" "----+\\n | summary |\\n +------------------------+\\n | Disabled 1 instruments |\\n +---------------------" "---+\\n 1 row in set (0.00 sec)\\n \\n To disable all instruments:\\n \\n mysql> CALL sys.ps_setup_disable_instrument(\\'\\'" ");\\n +--------------------------+\\n | summary |\\n +--------------------------+\\n | Disabled 547 inst" "ruments |\\n +--------------------------+\\n 1 row in set (0.01 sec)\\n ' SQL SECURITY INVOKER NOT DETERMINISTIC MODIFIE" "S SQL DATA BEGIN UPDATE performance_schema.setup_instruments SET enabled = 'NO', timed = 'NO' WHERE name LIKE CONCAT(" "'%', in_pattern, '%'); SELECT CONCAT('Disabled ', @rows := ROW_COUNT(), ' instrument', IF(@rows != 1, 's', '')) AS s" "ummary; END;\n", "DROP PROCEDURE IF EXISTS ps_setup_disable_thread;\n", "CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE ps_setup_disable_thread ( IN in_connection_id BIGINT ) COMMENT '\\n Desc" "ription\\n \\n Disable the given connection/thread in Performance Schema.\\n \\n Parameters\\n \\n in_connection_id (BIGINT" "):\\n The connection ID (PROCESSLIST_ID from performance_schema.threads\\n or the ID shown within SHOW PROCESSLIST)\\n \\" "n Example\\n \\n mysql> CALL sys.ps_setup_disable_thread(3);\\n +-------------------+\\n | summary |\\n +-------" "------------+\\n | Disabled 1 thread |\\n +-------------------+\\n 1 row in set (0.01 sec)\\n \\n To disable the current c" "onnection:\\n \\n mysql> CALL sys.ps_setup_disable_thread(CONNECTION_ID());\\n +-------------------+\\n | summary " " |\\n +-------------------+\\n | Disabled 1 thread |\\n +-------------------+\\n 1 row in set (0.00 sec)\\n ' SQL SECURI" "TY INVOKER NOT DETERMINISTIC MODIFIES SQL DATA BEGIN UPDATE performance_schema.threads SET instrumented = 'NO' WHERE " "processlist_id = in_connection_id; SELECT CONCAT('Disabled ', @rows := ROW_COUNT(), ' thread', IF(@rows != 1, 's', '" "')) AS summary; END;\n", "DROP PROCEDURE IF EXISTS ps_setup_enable_background_threads;\n", "CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE ps_setup_enable_background_threads () COMMENT '\\n Description\\n \\n Enab" "le all background thread instrumentation within Performance Schema.\\n \\n Parameters\\n \\n None.\\n \\n Example\\n \\n mysq" "l> CALL sys.ps_setup_enable_background_threads();\\n +-------------------------------+\\n | summary " " |\\n +-------------------------------+\\n | Enabled 18 background threads |\\n +-------------------------------+\\n 1 " "row in set (0.00 sec)\\n ' SQL SECURITY INVOKER NOT DETERMINISTIC MODIFIES SQL DATA BEGIN UPDATE performance_schema.th" "reads SET instrumented = 'YES' WHERE type = 'BACKGROUND'; SELECT CONCAT('Enabled ', @rows := ROW_COUNT(), ' backgrou" "nd thread', IF(@rows != 1, 's', '')) AS summary; END;\n", "DROP PROCEDURE IF EXISTS ps_setup_enable_consumer;\n", "CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE ps_setup_enable_consumer ( IN consumer VARCHAR(128) ) COMMENT '\\n Descr" "iption\\n \\n Enables consumers within Performance Schema \\n matching the input pattern.\\n \\n Parameters\\n \\n consumer " "(VARCHAR(128)):\\n A LIKE pattern match (using \"%consumer%\") of consumers to enable\\n \\n Example\\n \\n To enable all " "consumers:\\n \\n mysql> CALL sys.ps_setup_enable_consumer(\\'\\');\\n +-------------------------+\\n | summary " " |\\n +-------------------------+\\n | Enabled 10 consumers |\\n +-------------------------+\\n 1 row in set (0.02" " sec)\\n \\n Query OK, 0 rows affected (0.02 sec)\\n \\n To enable just \"waits\" consumers:\\n \\n mysql> CALL sys.ps_setu" "p_enable_consumer(\\'waits\\');\\n +-----------------------+\\n | summary |\\n +-----------------------+\\n |" " Enabled 3 consumers |\\n +-----------------------+\\n 1 row in set (0.00 sec)\\n \\n Query OK, 0 rows affected (0.00 s" "ec)\\n ' SQL SECURITY INVOKER NOT DETERMINISTIC MODIFIES SQL DATA BEGIN UPDATE performance_schema.setup_consumers SET " "enabled = 'YES' WHERE name LIKE CONCAT('%', consumer, '%'); SELECT CONCAT('Enabled ', @rows := ROW_COUNT(), ' consum" "er', IF(@rows != 1, 's', '')) AS summary; END;\n", "DROP PROCEDURE IF EXISTS ps_setup_enable_instrument;\n", "CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE ps_setup_enable_instrument ( IN in_pattern VARCHAR(128) ) COMMENT '\\n D" "escription\\n \\n Enables instruments within Performance Schema \\n matching the input pattern.\\n \\n Parameters\\n \\n in_" "pattern (VARCHAR(128)):\\n A LIKE pattern match (using \"%in_pattern%\") of events to enable\\n \\n Example\\n \\n To enab" "le all mutex instruments:\\n \\n mysql> CALL sys.ps_setup_enable_instrument(\\'wait/synch/mutex\\');\\n +-----------------" "--------+\\n | summary |\\n +-------------------------+\\n | Enabled 155 instruments |\\n +--------------" "-----------+\\n 1 row in set (0.02 sec)\\n \\n Query OK, 0 rows affected (0.02 sec)\\n \\n To enable just a specific TCP/I" "P based network IO instrument:\\n \\n mysql> CALL sys.ps_setup_enable_instrument(\\'wait/io/socket/sql/server_tcpip_sock" "et\\');\\n +-----------------------+\\n | summary |\\n +-----------------------+\\n | Enabled 1 instruments " "|\\n +-----------------------+\\n 1 row in set (0.00 sec)\\n \\n Query OK, 0 rows affected (0.00 sec)\\n \\n To enable all " "instruments:\\n \\n mysql> CALL sys.ps_setup_enable_instrument(\\'\\');\\n +-------------------------+\\n | summary " " |\\n +-------------------------+\\n | Enabled 547 instruments |\\n +-------------------------+\\n 1 row in set (" "0.01 sec)\\n \\n Query OK, 0 rows affected (0.01 sec)\\n ' SQL SECURITY INVOKER NOT DETERMINISTIC MODIFIES SQL DATA BEGI" "N UPDATE performance_schema.setup_instruments SET enabled = 'YES', timed = 'YES' WHERE name LIKE CONCAT('%', in_patte" "rn, '%'); SELECT CONCAT('Enabled ', @rows := ROW_COUNT(), ' instrument', IF(@rows != 1, 's', '')) AS summary; END;\n", "DROP PROCEDURE IF EXISTS ps_setup_enable_thread;\n", "CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE ps_setup_enable_thread ( IN in_connection_id BIGINT ) COMMENT '\\n Descr" "iption\\n \\n Enable the given connection/thread in Performance Schema.\\n \\n Parameters\\n \\n in_connection_id (BIGINT):" "\\n The connection ID (PROCESSLIST_ID from performance_schema.threads\\n or the ID shown within SHOW PROCESSLIST)\\n \\n " "Example\\n \\n mysql> CALL sys.ps_setup_enable_thread(3);\\n +------------------+\\n | summary |\\n +------------" "------+\\n | Enabled 1 thread |\\n +------------------+\\n 1 row in set (0.01 sec)\\n \\n To enable the current connection" ":\\n \\n mysql> CALL sys.ps_setup_enable_thread(CONNECTION_ID());\\n +------------------+\\n | summary |\\n +----" "--------------+\\n | Enabled 1 thread |\\n +------------------+\\n 1 row in set (0.00 sec)\\n ' SQL SECURITY INVOKER NOT " "DETERMINISTIC MODIFIES SQL DATA BEGIN UPDATE performance_schema.threads SET instrumented = 'YES' WHERE processlist_id" " = in_connection_id; SELECT CONCAT('Enabled ', @rows := ROW_COUNT(), ' thread', IF(@rows != 1, 's', '')) AS summary;" " END;\n", "DROP PROCEDURE IF EXISTS ps_setup_reload_saved;\n", "CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE ps_setup_reload_saved () COMMENT '\\n Description\\n \\n Reloads a saved P" "erformance Schema configuration,\\n so that you can alter the setup for debugging purposes, \\n but restore it to a pre" "vious state.\\n \\n Use the companion procedure - ps_setup_save(), to \\n save a configuration.\\n \\n Requires the SUPER " "privilege for \"SET sql_log_bin = 0;\".\\n \\n Parameters\\n \\n None.\\n \\n Example\\n \\n mysql> CALL sys.ps_setup_save();" "\\n Query OK, 0 rows affected (0.08 sec)\\n \\n mysql> UPDATE performance_schema.setup_instruments SET enabled = \\'YES\\'" ", timed = \\'YES\\';\\n Query OK, 547 rows affected (0.40 sec)\\n Rows matched: 784 Changed: 547 Warnings: 0\\n \\n /* Ru" "n some tests that need more detailed instrumentation here */\\n \\n mysql> CALL sys.ps_setup_reload_saved();\\n Query OK" ", 0 rows affected (0.32 sec)\\n ' SQL SECURITY INVOKER NOT DETERMINISTIC MODIFIES SQL DATA BEGIN DECLARE v_done bool D" "EFAULT FALSE; DECLARE v_lock_result INT; DECLARE v_lock_used_by BIGINT; DECLARE v_signal_message TEXT; DECLARE EXIT H" "ANDLER FOR SQLEXCEPTION BEGIN SIGNAL SQLSTATE VALUE '90001' SET MESSAGE_TEXT = 'An error occurred, was sys.ps_setup_s" "ave() run before this procedure?'; END; SET @log_bin := @@sql_log_bin; SET sql_log_bin = 0; SELECT IS_USED_LOCK('sy" "s.ps_setup_save') INTO v_lock_used_by; IF (v_lock_used_by != CONNECTION_ID()) THEN SET v_signal_message = CONCAT('Th" "e sys.ps_setup_save lock is currently owned by ', v_lock_used_by); SIGNAL SQLSTATE VALUE '90002' SET MESSAGE_TEXT = v" "_signal_message; END IF; DELETE FROM performance_schema.setup_actors; INSERT INTO performance_schema.setup_actors SE" "LECT * FROM tmp_setup_actors; BEGIN DECLARE v_name varchar(64); DECLARE v_enabled enum('YES', 'NO'); DECLARE c_consu" "mers CURSOR FOR SELECT NAME, ENABLED FROM tmp_setup_consumers; DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = TR" "UE; SET v_done = FALSE; OPEN c_consumers; c_consumers_loop: LOOP FETCH c_consumers INTO v_name, v_enabled; IF v_done" " THEN LEAVE c_consumers_loop; END IF; UPDATE performance_schema.setup_consumers SET ENABLED = v_enabled WHERE NAME =" " v_name; END LOOP; CLOSE c_consumers; END; UPDATE performance_schema.setup_instruments INNER JOIN tmp_setup_instrume" "nts USING (NAME) SET performance_schema.setup_instruments.ENABLED = tmp_setup_instruments.ENABLED, performance_schema" ".setup_instruments.TIMED = tmp_setup_instruments.TIMED; BEGIN DECLARE v_thread_id bigint unsigned; DECLARE v_instru" "mented enum('YES', 'NO'); DECLARE c_threads CURSOR FOR SELECT THREAD_ID, INSTRUMENTED FROM tmp_threads; DECLARE CONTI" "NUE HANDLER FOR NOT FOUND SET v_done = TRUE; SET v_done = FALSE; OPEN c_threads; c_threads_loop: LOOP FETCH c_thread" "s INTO v_thread_id, v_instrumented; IF v_done THEN LEAVE c_threads_loop; END IF; UPDATE performance_schema.threads S" "ET INSTRUMENTED = v_instrumented WHERE THREAD_ID = v_thread_id; END LOOP; CLOSE c_threads; END; UPDATE performance_s" "chema.threads SET INSTRUMENTED = IF(PROCESSLIST_USER IS NOT NULL, sys.ps_is_account_enabled(PROCESSLIST_HOST, PROCESS" "LIST_USER), 'YES') WHERE THREAD_ID NOT IN (SELECT THREAD_ID FROM tmp_threads); DROP TEMPORARY TABLE tmp_setup_actors" "; DROP TEMPORARY TABLE tmp_setup_consumers; DROP TEMPORARY TABLE tmp_setup_instruments; DROP TEMPORARY TABLE tmp_thre" "ads; SELECT RELEASE_LOCK('sys.ps_setup_save') INTO v_lock_result; SET sql_log_bin = @log_bin; END;\n", "SET @old_sql_mode = @@session.sql_mode, @@session.sql_mode = '';\n", "DROP PROCEDURE IF EXISTS ps_setup_reset_to_default;\n", "CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE ps_setup_reset_to_default ( IN in_verbose BOOLEAN ) COMMENT '\\n Descrip" "tion\\n \\n Resets the Performance Schema setup to the default settings.\\n \\n Parameters\\n \\n in_verbose (BOOLEAN):\\n W" "hether to print each setup stage (including the SQL) whilst running.\\n \\n Example\\n \\n mysql> CALL sys.ps_setup_reset" "_to_default(true)\\\\G\\n *************************** 1. row ***************************\\n status: Resetting: setup_acto" "rs\\n DELETE\\n FROM performance_schema.setup_actors\\n WHERE NOT (HOST = \\'%\\' AND USER = \\'%\\' AND `ROLE` = \\'%\\')\\n 1" " row in set (0.00 sec)\\n \\n *************************** 1. row ***************************\\n status: Resetting: setup" "_actors\\n INSERT IGNORE INTO performance_schema.setup_actors\\n VALUES (\\'%\\', \\'%\\', \\'%\\')\\n 1 row in set (0.00 sec)" "\\n ...\\n \\n mysql> CALL sys.ps_setup_reset_to_default(false)\\\\G\\n Query OK, 0 rows affected (0.00 sec)\\n ' SQL SECURI" "TY INVOKER NOT DETERMINISTIC MODIFIES SQL DATA BEGIN SET @query = 'DELETE FROM performance_schema.setup_actors WHERE " "NOT (HOST = ''%'' AND USER = ''%'' AND `ROLE` = ''%'')'; IF (in_verbose) THEN SELECT CONCAT('Resetting: setup_actors" "\\n', REPLACE(@query, ' ', '')) AS status; END IF; PREPARE reset_stmt FROM @query; EXECUTE reset_stmt; DEALLOCATE PR" "EPARE reset_stmt; SET @query = 'INSERT IGNORE INTO performance_schema.setup_actors VALUES (''%'', ''%'', ''%'', ''YE" "S'', ''YES'')'; IF (in_verbose) THEN SELECT CONCAT('Resetting: setup_actors\\n', REPLACE(@query, ' ', '')) AS status" "; END IF; PREPARE reset_stmt FROM @query; EXECUTE reset_stmt; DEALLOCATE PREPARE reset_stmt; SET @query = 'UPDATE p" "erformance_schema.setup_instruments SET ENABLED = sys.ps_is_instrument_default_enabled(NAME), TIMED = sys.ps_is_ins" "trument_default_timed(NAME)'; IF (in_verbose) THEN SELECT CONCAT('Resetting: setup_instruments\\n', REPLACE(@query, '" " ', '')) AS status; END IF; PREPARE reset_stmt FROM @query; EXECUTE reset_stmt; DEALLOCATE PREPARE reset_stmt; SET" " @query = 'UPDATE performance_schema.setup_consumers SET ENABLED = IF(NAME IN (''events_statements_current'', ''event" "s_transactions_current'', ''global_instrumentation'', ''thread_instrumentation'', ''statements_digest''), ''YES'', ''" "NO'')'; IF (in_verbose) THEN SELECT CONCAT('Resetting: setup_consumers\\n', REPLACE(@query, ' ', '')) AS status; END" " IF; PREPARE reset_stmt FROM @query; EXECUTE reset_stmt; DEALLOCATE PREPARE reset_stmt; SET @query = 'DELETE FROM p" "erformance_schema.setup_objects WHERE NOT (OBJECT_TYPE IN (''EVENT'', ''FUNCTION'', ''PROCEDURE'', ''TABLE'', ''TRIGG" "ER'') AND OBJECT_NAME = ''%'' AND (OBJECT_SCHEMA = ''mysql'' AND ENABLED = ''NO'' AND TIMED = ''NO'' )" " OR (OBJECT_SCHEMA = ''performance_schema'' AND ENABLED = ''NO'' AND TIMED = ''NO'' ) OR (OBJECT_SCHEMA = ''informat" "ion_schema'' AND ENABLED = ''NO'' AND TIMED = ''NO'' ) OR (OBJECT_SCHEMA = ''%'' AND ENABLED = ''YE" "S'' AND TIMED = ''YES''))'; IF (in_verbose) THEN SELECT CONCAT('Resetting: setup_objects\\n', REPLACE(@query, ' ', '" "')) AS status; END IF; PREPARE reset_stmt FROM @query; EXECUTE reset_stmt; DEALLOCATE PREPARE reset_stmt; SET @quer" "y = 'INSERT IGNORE INTO performance_schema.setup_objects VALUES (''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'' ), (''FUNCT" "ION'' , ''information_schema'', ''%'', ''NO'' , ''NO'' ), (''FUNCTION'' , ''%'' , ''%'', ''YES'', ''Y" "ES''), (''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'' , ''%'', ''N" "O'' , ''NO'' ), (''TRIGGER'' , ''performance_schema'', ''%'', ''NO'' , ''NO'' ), (''TRIGGER'' , ''information_schem" "a'', ''%'', ''NO'' , ''NO'' ), (''TRIGGER'' , ''%'' , ''%'', ''YES'', ''YES'')'; IF (in_verbose) TH" "EN SELECT CONCAT('Resetting: setup_objects\\n', REPLACE(@query, ' ', '')) AS status; END IF; PREPARE reset_stmt FROM" " @query; EXECUTE reset_stmt; DEALLOCATE PREPARE reset_stmt; SET @query = 'UPDATE performance_schema.threads SET INST" "RUMENTED = ''YES'''; IF (in_verbose) THEN SELECT CONCAT('Resetting: threads\\n', REPLACE(@query, ' ', '')) AS status" "; END IF; PREPARE reset_stmt FROM @query; EXECUTE reset_stmt; DEALLOCATE PREPARE reset_stmt; END;\n", "SET @@session.sql_mode = @old_sql_mode;\n", "DROP PROCEDURE IF EXISTS ps_setup_save;\n", "CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE ps_setup_save ( IN in_timeout INT ) COMMENT '\\n Description\\n \\n Saves " "the current configuration of Performance Schema, \\n so that you can alter the setup for debugging purposes, \\n but re" "store it to a previous state.\\n \\n Use the companion procedure - ps_setup_reload_saved(), to \\n restore the saved con" "fig.\\n \\n The named lock \"sys.ps_setup_save\" is taken before the\\n current configuration is saved. If the attempt t" "o get the named\\n lock times out, an error occurs.\\n \\n The lock is released after the settings have been restored by" "\\n calling ps_setup_reload_saved().\\n \\n Requires the SUPER privilege for \"SET sql_log_bin = 0;\".\\n \\n Parameters\\n" " \\n in_timeout INT\\n The timeout in seconds used when trying to obtain the lock.\\n A negative timeout means infinite " "timeout.\\n \\n Example\\n \\n mysql> CALL sys.ps_setup_save(-1);\\n Query OK, 0 rows affected (0.08 sec)\\n \\n mysql> UPDA" "TE performance_schema.setup_instruments \\n -> SET enabled = \\'YES\\', timed = \\'YES\\';\\n Query OK, 547 rows affecte" "d (0.40 sec)\\n Rows matched: 784 Changed: 547 Warnings: 0\\n \\n /* Run some tests that need more detailed instrument" "ation here */\\n \\n mysql> CALL sys.ps_setup_reload_saved();\\n Query OK, 0 rows affected (0.32 sec)\\n ' SQL SECURITY I" "NVOKER NOT DETERMINISTIC MODIFIES SQL DATA BEGIN DECLARE v_lock_result INT; SET @log_bin := @@sql_log_bin; SET sql_l" "og_bin = 0; SELECT GET_LOCK('sys.ps_setup_save', in_timeout) INTO v_lock_result; IF v_lock_result THEN DROP TEMPORA" "RY TABLE IF EXISTS tmp_setup_actors; DROP TEMPORARY TABLE IF EXISTS tmp_setup_consumers; DROP TEMPORARY TABLE IF EXIS" "TS tmp_setup_instruments; DROP TEMPORARY TABLE IF EXISTS tmp_threads; CREATE TEMPORARY TABLE tmp_setup_actors SELECT" " * FROM performance_schema.setup_actors LIMIT 0; CREATE TEMPORARY TABLE tmp_setup_consumers LIKE performance_schema.s" "etup_consumers; CREATE TEMPORARY TABLE tmp_setup_instruments LIKE performance_schema.setup_instruments; CREATE TEMPOR" "ARY TABLE tmp_threads (THREAD_ID bigint unsigned NOT NULL PRIMARY KEY, INSTRUMENTED enum('YES','NO') NOT NULL); INSE" "RT INTO tmp_setup_actors SELECT * FROM performance_schema.setup_actors; INSERT INTO tmp_setup_consumers SELECT * FROM" " performance_schema.setup_consumers; INSERT INTO tmp_setup_instruments SELECT * FROM performance_schema.setup_instrum" "ents; INSERT INTO tmp_threads SELECT THREAD_ID, INSTRUMENTED FROM performance_schema.threads; ELSE SIGNAL SQLSTATE VA" "LUE '90000' SET MESSAGE_TEXT = 'Could not lock the sys.ps_setup_save user lock, another thread has a saved configurat" "ion'; END IF; SET sql_log_bin = @log_bin; END;\n", "DROP PROCEDURE IF EXISTS ps_setup_show_disabled;\n", "CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE ps_setup_show_disabled ( IN in_show_instruments BOOLEAN, IN in_show_thr" "eads BOOLEAN ) COMMENT '\\n Description\\n \\n Shows all currently disable Performance Schema configuration.\\n \\n Disabl" "ed users is only available for MySQL 5.7.6 and later.\\n In earlier versions it was only possible to enable users.\\n \\" "n Parameters\\n \\n in_show_instruments (BOOLEAN):\\n Whether to print disabled instruments (can print many items)\\n \\n " "in_show_threads (BOOLEAN):\\n Whether to print disabled threads\\n \\n Example\\n \\n mysql> CALL sys.ps_setup_show_disabl" "ed(TRUE, TRUE);\\n +----------------------------+\\n | performance_schema_enabled |\\n +----------------------------+\\n " "| 1 |\\n +----------------------------+\\n 1 row in set (0.00 sec)\\n \\n +--------------------+" "\\n | disabled_users |\\n +--------------------+\\n | \\'mark\\'@\\'localhost\\' |\\n +--------------------+\\n 1 row in s" "et (0.00 sec)\\n \\n +-------------+----------------------+---------+-------+\\n | object_type | objects | " "enabled | timed |\\n +-------------+----------------------+---------+-------+\\n | EVENT | mysql.% |" " NO | NO |\\n | EVENT | performance_schema.% | NO | NO |\\n | EVENT | information_schema.% " "| NO | NO |\\n | FUNCTION | mysql.% | NO | NO |\\n | FUNCTION | performance_schema.%" " | NO | NO |\\n | FUNCTION | information_schema.% | NO | NO |\\n | PROCEDURE | mysql.% " " | NO | NO |\\n | PROCEDURE | performance_schema.% | NO | NO |\\n | PROCEDURE | information_schema" ".% | NO | NO |\\n | TABLE | mysql.% | NO | NO |\\n | TABLE | performance_schem" "a.% | NO | NO |\\n | TABLE | information_schema.% | NO | NO |\\n | TRIGGER | mysql.% " " | NO | NO |\\n | TRIGGER | performance_schema.% | NO | NO |\\n | TRIGGER | information_sch" "ema.% | NO | NO |\\n +-------------+----------------------+---------+-------+\\n 15 rows in set (0.00 sec)\\n \\n" " +----------------------------------+\\n | disabled_consumers |\\n +----------------------------------+\\n" " | events_stages_current |\\n | events_stages_history |\\n | events_stages_history_long |\\n" " | events_statements_history |\\n | events_statements_history_long |\\n | events_transactions_history |\\n" " | events_transactions_history_long |\\n | events_waits_current |\\n | events_waits_history |\\n" " | events_waits_history_long |\\n +----------------------------------+\\n 10 rows in set (0.00 sec)\\n \\n Empty s" "et (0.00 sec)\\n \\n +---------------------------------------------------------------------------------------+-------+\\" "n | disabled_instruments | timed |\\n +--------------" "-------------------------------------------------------------------------+-------+\\n | wait/synch/mutex/sql/TC_LOG_MM" "AP::LOCK_tc | NO |\\n | wait/synch/mutex/sql/LOCK_des_key_file " " | NO |\\n | wait/synch/mutex/sql/MYSQL_BIN_LOG::LOCK_commit " " | NO |\\n ...\\n | memory/sql/servers_cache " " | NO |\\n | memory/sql/udf_mem | NO " " |\\n | wait/lock/metadata/sql/mdl | NO |\\n +----------" "-----------------------------------------------------------------------------+-------+\\n 547 rows in set (0.00 sec)\\n" " \\n Query OK, 0 rows affected (0.01 sec)\\n ' SQL SECURITY INVOKER NOT DETERMINISTIC READS SQL DATA BEGIN SELECT @@per" "formance_schema AS performance_schema_enabled; /*!50706 SELECT CONCAT('\\'', user, '\\'@\\'', host, '\\'') AS disabled_u" "sers FROM performance_schema.setup_actors WHERE enabled = 'NO' ORDER BY disabled_users; */ SELECT object_type, CONCA" "T(object_schema, '.', object_name) AS objects, enabled, timed FROM performance_schema.setup_objects WHERE enabled = '" "NO' ORDER BY object_type, objects; SELECT name AS disabled_consumers FROM performance_schema.setup_consumers WHERE e" "nabled = 'NO' ORDER BY disabled_consumers; IF (in_show_threads) THEN SELECT IF(name = 'thread/sql/one_connection', " "CONCAT(processlist_user, '@', processlist_host), REPLACE(name, 'thread/', '')) AS disabled_threads, TYPE AS thread_t" "ype FROM performance_schema.threads WHERE INSTRUMENTED = 'NO' ORDER BY disabled_threads; END IF; IF (in_show_instrum" "ents) THEN SELECT name AS disabled_instruments, timed FROM performance_schema.setup_instruments WHERE enabled = 'NO' " "ORDER BY disabled_instruments; END IF; END;\n", "DROP PROCEDURE IF EXISTS ps_setup_show_disabled_consumers;\n", "CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE ps_setup_show_disabled_consumers () COMMENT '\\n Description\\n \\n Shows " "all currently disabled consumers.\\n \\n Parameters\\n \\n None\\n \\n Example\\n \\n mysql> CALL sys.ps_setup_show_disabled_" "consumers();\\n \\n +---------------------------+\\n | disabled_consumers |\\n +---------------------------+\\n | e" "vents_statements_current |\\n | global_instrumentation |\\n | thread_instrumentation |\\n | statements_digest " " |\\n +---------------------------+\\n 4 rows in set (0.05 sec)\\n ' SQL SECURITY INVOKER DETERMINISTIC READS SQL DAT" "A BEGIN SELECT name AS disabled_consumers FROM performance_schema.setup_consumers WHERE enabled = 'NO' ORDER BY disab" "led_consumers; END;\n", "DROP PROCEDURE IF EXISTS ps_setup_show_disabled_instruments;\n", "CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE ps_setup_show_disabled_instruments () COMMENT '\\n Description\\n \\n Show" "s all currently disabled instruments.\\n \\n Parameters\\n \\n None\\n \\n Example\\n \\n mysql> CALL sys.ps_setup_show_disab" "led_instruments();\\n ' SQL SECURITY INVOKER DETERMINISTIC READS SQL DATA BEGIN SELECT name AS disabled_instruments, t" "imed FROM performance_schema.setup_instruments WHERE enabled = 'NO' ORDER BY disabled_instruments; END;\n", "DROP PROCEDURE IF EXISTS ps_setup_show_enabled;\n", "CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE ps_setup_show_enabled ( IN in_show_instruments BOOLEAN, IN in_show_thre" "ads BOOLEAN ) COMMENT '\\n Description\\n \\n Shows all currently enabled Performance Schema configuration.\\n \\n Paramet" "ers\\n \\n in_show_instruments (BOOLEAN):\\n Whether to print enabled instruments (can print many items)\\n \\n in_show_th" "reads (BOOLEAN):\\n Whether to print enabled threads\\n \\n Example\\n \\n mysql> CALL sys.ps_setup_show_enabled(TRUE, TRU" "E);\\n +----------------------------+\\n | performance_schema_enabled |\\n +----------------------------+\\n | " " 1 |\\n +----------------------------+\\n 1 row in set (0.00 sec)\\n \\n +---------------+\\n | enabled_user" "s |\\n +---------------+\\n | \\'%\\'@\\'%\\' |\\n +---------------+\\n 1 row in set (0.01 sec)\\n \\n +-------------+---" "------+---------+-------+\\n | object_type | objects | enabled | timed |\\n +-------------+---------+---------+-------+" "\\n | EVENT | %.% | YES | YES |\\n | FUNCTION | %.% | YES | YES |\\n | PROCEDURE | %.% " " | YES | YES |\\n | TABLE | %.% | YES | YES |\\n | TRIGGER | %.% | YES | YES |\\n +" "-------------+---------+---------+-------+\\n 5 rows in set (0.01 sec)\\n \\n +---------------------------+\\n | enabled_" "consumers |\\n +---------------------------+\\n | events_statements_current |\\n | global_instrumentation |\\n" " | thread_instrumentation |\\n | statements_digest |\\n +---------------------------+\\n 4 rows in set (0.05 " "sec)\\n \\n +---------------------------------+-------------+\\n | enabled_threads | thread_type |\\n +--" "-------------------------------+-------------+\\n | sql/main | BACKGROUND |\\n | sql/thread_tim" "er_notifier | BACKGROUND |\\n | innodb/io_ibuf_thread | BACKGROUND |\\n | innodb/io_log_thread " " | BACKGROUND |\\n | innodb/io_read_thread | BACKGROUND |\\n | innodb/io_read_thread | BACKGR" "OUND |\\n | innodb/io_write_thread | BACKGROUND |\\n | innodb/io_write_thread | BACKGROUND |\\n | i" "nnodb/page_cleaner_thread | BACKGROUND |\\n | innodb/srv_lock_timeout_thread | BACKGROUND |\\n | innodb/srv_err" "or_monitor_thread | BACKGROUND |\\n | innodb/srv_monitor_thread | BACKGROUND |\\n | innodb/srv_master_thread " " | BACKGROUND |\\n | innodb/srv_purge_thread | BACKGROUND |\\n | innodb/srv_worker_thread | BACKGR" "OUND |\\n | innodb/srv_worker_thread | BACKGROUND |\\n | innodb/srv_worker_thread | BACKGROUND |\\n | i" "nnodb/buf_dump_thread | BACKGROUND |\\n | innodb/dict_stats_thread | BACKGROUND |\\n | sql/signal_han" "dler | BACKGROUND |\\n | sql/compress_gtid_table | FOREGROUND |\\n | root@localhost " " | FOREGROUND |\\n +---------------------------------+-------------+\\n 22 rows in set (0.01 sec)\\n \\n +----------" "---------------------------+-------+\\n | enabled_instruments | timed |\\n +---------------------------" "----------+-------+\\n | wait/io/file/sql/map | YES |\\n | wait/io/file/sql/binlog | YES " " |\\n ...\\n | statement/com/Error | YES |\\n | statement/com/ | YES |\\n | idle" " | YES |\\n +-------------------------------------+-------+\\n 210 rows in set (0.08 s" "ec)\\n \\n Query OK, 0 rows affected (0.89 sec)\\n ' SQL SECURITY INVOKER DETERMINISTIC READS SQL DATA BEGIN SELECT @@pe" "rformance_schema AS performance_schema_enabled; SELECT CONCAT('\\'', user, '\\'@\\'', host, '\\'') AS enabled_users FROM" " performance_schema.setup_actors /*!50706 WHERE enabled = 'YES' */ ORDER BY enabled_users; SELECT object_type, CONCA" "T(object_schema, '.', object_name) AS objects, enabled, timed FROM performance_schema.setup_objects WHERE enabled = '" "YES' ORDER BY object_type, objects; SELECT name AS enabled_consumers FROM performance_schema.setup_consumers WHERE e" "nabled = 'YES' ORDER BY enabled_consumers; IF (in_show_threads) THEN SELECT IF(name = 'thread/sql/one_connection', " "CONCAT(processlist_user, '@', processlist_host), REPLACE(name, 'thread/', '')) AS enabled_threads, TYPE AS thread_ty" "pe FROM performance_schema.threads WHERE INSTRUMENTED = 'YES' ORDER BY enabled_threads; END IF; IF (in_show_instrume" "nts) THEN SELECT name AS enabled_instruments, timed FROM performance_schema.setup_instruments WHERE enabled = 'YES' O" "RDER BY enabled_instruments; END IF; END;\n", "DROP PROCEDURE IF EXISTS ps_setup_show_enabled_consumers;\n", "CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE ps_setup_show_enabled_consumers () COMMENT '\\n Description\\n \\n Shows a" "ll currently enabled consumers.\\n \\n Parameters\\n \\n None\\n \\n Example\\n \\n mysql> CALL sys.ps_setup_show_enabled_con" "sumers();\\n \\n +---------------------------+\\n | enabled_consumers |\\n +---------------------------+\\n | even" "ts_statements_current |\\n | global_instrumentation |\\n | thread_instrumentation |\\n | statements_digest " " |\\n +---------------------------+\\n 4 rows in set (0.05 sec)\\n ' SQL SECURITY INVOKER DETERMINISTIC READS SQL DATA B" "EGIN SELECT name AS enabled_consumers FROM performance_schema.setup_consumers WHERE enabled = 'YES' ORDER BY enabled_" "consumers; END;\n", "DROP PROCEDURE IF EXISTS ps_setup_show_enabled_instruments;\n", "CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE ps_setup_show_enabled_instruments () COMMENT '\\n Description\\n \\n Shows" " all currently enabled instruments.\\n \\n Parameters\\n \\n None\\n \\n Example\\n \\n mysql> CALL sys.ps_setup_show_enabled" "_instruments();\\n ' SQL SECURITY INVOKER DETERMINISTIC READS SQL DATA BEGIN SELECT name AS enabled_instruments, timed" " FROM performance_schema.setup_instruments WHERE enabled = 'YES' ORDER BY enabled_instruments; END;\n", "DROP PROCEDURE IF EXISTS ps_truncate_all_tables;\n", "CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE ps_truncate_all_tables ( IN in_verbose BOOLEAN ) COMMENT '\\n Descriptio" "n\\n \\n Truncates all summary tables within Performance Schema, \\n resetting all aggregated instrumentation as a snaps" "hot.\\n \\n Parameters\\n \\n in_verbose (BOOLEAN):\\n Whether to print each TRUNCATE statement before running\\n \\n Exampl" "e\\n \\n mysql> CALL sys.ps_truncate_all_tables(false);\\n +---------------------+\\n | summary |\\n +--------" "-------------+\\n | Truncated 44 tables |\\n +---------------------+\\n 1 row in set (0.10 sec)\\n \\n Query OK, 0 rows af" "fected (0.10 sec)\\n ' SQL SECURITY INVOKER DETERMINISTIC MODIFIES SQL DATA BEGIN DECLARE v_done INT DEFAULT FALSE; DE" "CLARE v_total_tables INT DEFAULT 0; DECLARE v_ps_table VARCHAR(64); DECLARE ps_tables CURSOR FOR SELECT table_name F" "ROM INFORMATION_SCHEMA.TABLES WHERE table_schema = 'performance_schema' AND (table_name LIKE '%summary%' OR table_" "name LIKE '%history%'); DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = TRUE; OPEN ps_tables; ps_tables_loop: L" "OOP FETCH ps_tables INTO v_ps_table; IF v_done THEN LEAVE ps_tables_loop; END IF; SET @truncate_stmt := CONCAT('TRUN" "CATE TABLE performance_schema.', v_ps_table); IF in_verbose THEN SELECT CONCAT('Running: ', @truncate_stmt) AS status" "; END IF; PREPARE truncate_stmt FROM @truncate_stmt; EXECUTE truncate_stmt; DEALLOCATE PREPARE truncate_stmt; SET v" "_total_tables = v_total_tables + 1; END LOOP; CLOSE ps_tables; SELECT CONCAT('Truncated ', v_total_tables, ' tables" "') AS summary; END;\n", "DROP PROCEDURE IF EXISTS statement_performance_analyzer;\n", "CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE statement_performance_analyzer ( IN in_action ENUM('snapshot', 'overall" "', 'delta', 'create_table', 'create_tmp', 'save', 'cleanup'), IN in_table VARCHAR(129), IN in_views SET ('with_runtim" "es_in_95th_percentile', 'analysis', 'with_errors_or_warnings', 'with_full_table_scans', 'with_sorting', 'with_temp_ta" "bles', 'custom') ) COMMENT '\\n Description\\n \\n Create a report of the statements running on the server.\\n \\n The vie" "ws are calculated based on the overall and/or delta activity.\\n \\n Requires the SUPER privilege for \"SET sql_log_bin" " = 0;\".\\n \\n Parameters\\n \\n in_action (ENUM(''snapshot'', ''overall'', ''delta'', ''create_tmp'', ''create_table''," " ''save'', ''cleanup'')):\\n The action to take. Supported actions are:\\n * snapshot Store a snapshot. The defaul" "t is to make a snapshot of the current content of\\n performance_schema.events_statements_summary_by_digest, but by se" "tting in_table\\n this can be overwritten to copy the content of the specified table.\\n The snapshot is stored in the " "sys.tmp_digests temporary table.\\n * overall Generate analyzis based on the content specified by in_table. For " "the overall analyzis,\\n in_table can be NOW() to use a fresh snapshot. This will overwrite an existing snapshot.\\n Us" "e NULL for in_table to use the existing snapshot. If in_table IS NULL and no snapshot\\n exists, a new will be created" ".\\n See also in_views and @sys.statement_performance_analyzer.limit.\\n * delta Generate a delta analysis. The" " delta will be calculated between the reference table in\\n in_table and the snapshot. An existing snapshot must exist" ".\\n The action uses the sys.tmp_digests_delta temporary table.\\n See also in_views and @sys.statement_performance_ana" "lyzer.limit.\\n * create_table Create a regular table suitable for storing the snapshot for later use, e.g. for\\n cal" "culating deltas.\\n * create_tmp Create a temporary table suitable for storing the snapshot for later use, e.g. for" "\\n calculating deltas.\\n * save Save the snapshot in the table specified by in_table. The table must exists " "and have\\n the correct structure.\\n If no snapshot exists, a new is created.\\n * cleanup Remove the temporary t" "ables used for the snapshot and delta.\\n \\n in_table (VARCHAR(129)):\\n The table argument used for some actions. Use " "the format ''db1.t1'' or ''t1'' without using any backticks (`)\\n for quoting. Periods (.) are not supported in the d" "atabase and table names.\\n \\n The meaning of the table for each action supporting the argument is:\\n \\n * snapshot " " The snapshot is created based on the specified table. Set to NULL or NOW() to use\\n the current content of perform" "ance_schema.events_statements_summary_by_digest.\\n * overall The table with the content to create the overall a" "nalyzis for. The following values\\n can be used:\\n - A table name - use the content of that table.\\n - NOW() -" " create a fresh snapshot and overwrite the existing snapshot.\\n - NULL - use the last stored snapshot.\\n * de" "lta The table name is mandatory and specified the reference view to compare the currently\\n stored snapshot a" "gainst. If no snapshot exists, a new will be created.\\n * create_table The name of the regular table to create.\\n * " "create_tmp The name of the temporary table to create.\\n * save The name of the table to save the currentl" "y stored snapshot into.\\n \\n in_views (SET (''with_runtimes_in_95th_percentile'', ''analysis'', ''with_errors_or_warn" "ings'',\\n ''with_full_table_scans'', ''with_sorting'', ''with_temp_tables'', ''custom''))\\n Which views to include: " "* with_runtimes_in_95th_percentile Based on the sys.statements_with_runtimes_in_95th_percentile view * analysis " " Based on the sys.statement_analysis view * with_errors_or_warnings Based on the sys.st" "atements_with_errors_or_warnings view * with_full_table_scans Based on the sys.statements_with_full_table" "_scans view * with_sorting Based on the sys.statements_with_sorting view * with_temp_tables " " Based on the sys.statements_with_temp_tables view * custom Use a custom view." " This view must be specified in @sys.statement_performance_analyzer.view to an existing view or a query Default is t" "o include all except ''custom''. Configuration Options sys.statement_performance_analyzer.limit The maximum number" " of rows to include for the views that does not have a built-in limit (e.g. the 95th percentile view). If not set the" " limit is 100. sys.statement_performance_analyzer.view Used together with the ''custom'' view. If the value contains" " a space, it is considered a query, otherwise it must be an existing view querying the performance_schema.events_stat" "ements_summary_by_digest table. There cannot be any limit clause including in the query or view definition if @sys.st" "atement_performance_analyzer.limit > 0. If specifying a view, use the same format as for in_table. sys.debug Whether" " to provide debugging output. Default is ''OFF''. Set to ''ON'' to include. Example To create a report with the qu" "eries in the 95th percentile since last truncate of performance_schema.events_statements_summary_by_digest and the de" "lta for a 1 minute period: 1. Create a temporary table to store the initial snapshot. 2. Create the initial snapshot" ". 3. Save the initial snapshot in the temporary table. 4. Wait one minute. 5. Create a new snapshot. 6. Perform analy" "zis based on the new snapshot. 7. Perform analyzis based on the delta between the initial and new snapshots. mysql> " "CALL sys.statement_performance_analyzer(''create_tmp'', ''mydb.tmp_digests_ini'', NULL); Query OK, 0 rows affected (0" ".08 sec) mysql> CALL sys.statement_performance_analyzer(''snapshot'', NULL, NULL); Query OK, 0 rows affected (0.02 s" "ec) mysql> CALL sys.statement_performance_analyzer(''save'', ''mydb.tmp_digests_ini'', NULL); Query OK, 0 rows affec" "ted (0.00 sec) mysql> DO SLEEP(60); Query OK, 0 rows affected (1 min 0.00 sec) mysql> CALL sys.statement_performanc" "e_analyzer(''snapshot'', NULL, NULL); Query OK, 0 rows affected (0.02 sec) mysql> CALL sys.statement_performance_ana" "lyzer(''overall'', NULL, ''with_runtimes_in_95th_percentile''); +-----------------------------------------+ | Next Ou" "tput | +-----------------------------------------+ | Queries with Runtime in 95th Percent" "ile | +-----------------------------------------+ 1 row in set (0.05 sec) ... mysql> CALL sys.statement_performance" "_analyzer(''delta'', ''mydb.tmp_digests_ini'', ''with_runtimes_in_95th_percentile''); +------------------------------" "-----------+ | Next Output | +-----------------------------------------+ | Queries with R" "untime in 95th Percentile | +-----------------------------------------+ 1 row in set (0.03 sec) ... To create an o" "verall report of the 95th percentile queries and the top 10 queries with full table scans: mysql> CALL sys.statement" "_performance_analyzer(''snapshot'', NULL, NULL); Query OK, 0 rows affected (0.01 sec) mysql> SET @sys.statement_perf" "ormance_analyzer.limit = 10; Query OK, 0 rows affected (0.00 sec) mysql> CALL sys.statement_performance_analyzer(''o" "verall'', NULL, ''with_runtimes_in_95th_percentile,with_full_table_scans''); +---------------------------------------" "--+ | Next Output | +-----------------------------------------+ | Queries with Runtime in" " 95th Percentile | +-----------------------------------------+ 1 row in set (0.01 sec) ... +-----------------------" "--------------+ | Next Output | +-------------------------------------+ | Top 10 Queries with" " Full Table Scan | +-------------------------------------+ 1 row in set (0.09 sec) ... Use a custom view showing t" "he top 10 query sorted by total execution time refreshing the view every minute using the watch command in Linux. my" "sql> CREATE OR REPLACE VIEW mydb.my_statements AS -> SELECT sys.format_statement(DIGEST_TEXT) AS query, -> SCH" "EMA_NAME AS db, -> COUNT_STAR AS exec_count, -> sys.format_time(SUM_TIMER_WAIT) AS total_latency, -> " " sys.format_time(AVG_TIMER_WAIT) AS avg_latency, -> ROUND(IFNULL(SUM_ROWS_SENT / NULLIF(COUNT_STAR, 0), 0)" ") AS rows_sent_avg, -> ROUND(IFNULL(SUM_ROWS_EXAMINED / NULLIF(COUNT_STAR, 0), 0)) AS rows_examined_avg, -> " " ROUND(IFNULL(SUM_ROWS_AFFECTED / NULLIF(COUNT_STAR, 0), 0)) AS rows_affected_avg, -> DIGEST AS digest -> " " FROM performance_schema.events_statements_summary_by_digest -> ORDER BY SUM_TIMER_WAIT DESC; Query OK, 0 rows affec" "ted (0.01 sec) mysql> CALL sys.statement_performance_analyzer(''create_table'', ''mydb.digests_prev'', NULL); Query " "OK, 0 rows affected (0.10 sec) shell$ watch -n 60 \"mysql sys --table -e \\\" > SET @sys.statement_performance_analyz" "er.view = ''mydb.my_statements''; > SET @sys.statement_performance_analyzer.limit = 10; > CALL statement_performance_" "analyzer(''snapshot'', NULL, NULL); > CALL statement_performance_analyzer(''delta'', ''mydb.digests_prev'', ''custom'" "'); > CALL statement_performance_analyzer(''save'', ''mydb.digests_prev'', NULL); > \\\"\" Every 60.0s: mysql sys --t" "able -e \" ... Mon" " Dec 22 10:58:51 2014 +----------------------------------+ | Next Output | +-------------------" "---------------+ | Top 10 Queries Using Custom View | +----------------------------------+ +-------------------+-----" "--+------------+---------------+-------------+---------------+-------------------+-------------------+---------------" "-------------------+ | query | db | exec_count | total_latency | avg_latency | rows_sent_avg | rows_ex" "amined_avg | rows_affected_avg | digest | +-------------------+-------+------------+-------" "--------+-------------+---------------+-------------------+-------------------+----------------------------------+ .." ". ' SQL SECURITY INVOKER NOT DETERMINISTIC CONTAINS SQL BEGIN DECLARE v_table_exists, v_tmp_digests_table_exists, v_c" "ustom_view_exists ENUM('', 'BASE TABLE', 'VIEW', 'TEMPORARY') DEFAULT ''; DECLARE v_this_thread_enabled ENUM('YES', '" "NO'); DECLARE v_force_new_snapshot BOOLEAN DEFAULT FALSE; DECLARE v_digests_table VARCHAR(133); DECLARE v_quoted_tabl" "e, v_quoted_custom_view VARCHAR(133) DEFAULT ''; DECLARE v_table_db, v_table_name, v_custom_db, v_custom_name VARCHAR" "(64); DECLARE v_digest_table_template, v_checksum_ref, v_checksum_table text; DECLARE v_sql longtext; DECLARE v_error" "_msg VARCHAR(128); SELECT INSTRUMENTED INTO v_this_thread_enabled FROM performance_schema.threads WHERE PROCESSLIST" "_ID = CONNECTION_ID(); IF (v_this_thread_enabled = 'YES') THEN CALL sys.ps_setup_disable_thread(CONNECTION_ID()); END" " IF; SET @log_bin := @@sql_log_bin; IF (@log_bin = 1) THEN SET sql_log_bin = 0; END IF; IF (@sys.statement_perform" "ance_analyzer.limit IS NULL) THEN SET @sys.statement_performance_analyzer.limit = sys.sys_get_config('statement_perfo" "rmance_analyzer.limit', '100'); END IF; IF (@sys.debug IS NULL) THEN SET @sys.debug = " "sys.sys_get_config('debug' , 'OFF'); END IF; IF (in_table = 'NOW()') THEN SET v_force" "_new_snapshot = TRUE, in_table = NULL; ELSEIF (in_table IS NOT NULL) THEN IF (NOT INSTR(in_table, '.')) T" "HEN SET v_table_db = DATABASE(), v_table_name = in_table; ELSE SET v_table_db = SUBSTRING_INDEX(in_table, '.', 1)" "; SET v_table_name = SUBSTRING(in_table, CHAR_LENGTH(v_table_db)+2); END IF; SET v_quoted_table = CONCAT('`', v_tabl" "e_db, '`.`', v_table_name, '`'); IF (@sys.debug = 'ON') THEN SELECT CONCAT('in_table is: db = ''', v_table_db, ''', " "table = ''', v_table_name, '''') AS 'Debug'; END IF; IF (v_table_db = DATABASE() AND (v_table_name = 'tmp_digests' O" "R v_table_name = 'tmp_digests_delta')) THEN SET v_error_msg = CONCAT('Invalid value for in_table: ', v_quoted_table, " "' is reserved table name.'); SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = v_error_msg; END IF; CALL sys.table_exists(v" "_table_db, v_table_name, v_table_exists); IF (@sys.debug = 'ON') THEN SELECT CONCAT('v_table_exists = ', v_table_exis" "ts) AS 'Debug'; END IF; IF (v_table_exists = 'BASE TABLE') THEN SET v_checksum_ref = ( SELECT GROUP_CONCAT(CONCAT(CO" "LUMN_NAME, COLUMN_TYPE) ORDER BY ORDINAL_POSITION) AS Checksum FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '" "performance_schema' AND TABLE_NAME = 'events_statements_summary_by_digest' ), v_checksum_table = ( SELECT GROUP_CONCA" "T(CONCAT(COLUMN_NAME, COLUMN_TYPE) ORDER BY ORDINAL_POSITION) AS Checksum FROM information_schema.COLUMNS WHERE TABLE" "_SCHEMA = v_table_db AND TABLE_NAME = v_table_name ); IF (v_checksum_ref <> v_checksum_table) THEN SET v_error_msg =" " CONCAT('The table ', IF(CHAR_LENGTH(v_quoted_table) > 93, CONCAT('...', SUBSTRING(v_quoted_table, -90)), v_quoted_ta" "ble), ' has the wrong definition.'); SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = v_error_msg; END IF; END IF; END IF; " " IF (in_views IS NULL OR in_views = '') THEN SET in_views = 'with_runtimes_in_95th_percentile,analysis,with_errors_o" "r_warnings,with_full_table_scans,with_sorting,with_temp_tables'; END IF; CALL sys.table_exists(DATABASE(), 'tmp_dig" "ests', v_tmp_digests_table_exists); IF (@sys.debug = 'ON') THEN SELECT CONCAT('v_tmp_digests_table_exists = ', v_tmp_" "digests_table_exists) AS 'Debug'; END IF; CASE WHEN in_action IN ('snapshot', 'overall') THEN IF (in_table IS NOT NU" "LL) THEN IF (NOT v_table_exists IN ('TEMPORARY', 'BASE TABLE')) THEN SET v_error_msg = CONCAT('The ', in_action, ' ac" "tion requires in_table to be NULL, NOW() or specify an existing table.', ' The table ', IF(CHAR_LENGTH(v_quoted_table" ") > 16, CONCAT('...', SUBSTRING(v_quoted_table, -13)), v_quoted_table), ' does not exist.'); SIGNAL SQLSTATE '45000' " "SET MESSAGE_TEXT = v_error_msg; END IF; END IF; WHEN in_action IN ('delta', 'save') THEN IF (v_table_exists NOT IN (" "'TEMPORARY', 'BASE TABLE')) THEN SET v_error_msg = CONCAT('The ', in_action, ' action requires in_table to be an exis" "ting table.', IF(in_table IS NOT NULL, CONCAT(' The table ', IF(CHAR_LENGTH(v_quoted_table) > 39, CONCAT('...', SUBST" "RING(v_quoted_table, -36)), v_quoted_table), ' does not exist.'), '')); SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = v_" "error_msg; END IF; IF (in_action = 'delta' AND v_tmp_digests_table_exists <> 'TEMPORARY') THEN SIGNAL SQLSTATE '4500" "0' SET MESSAGE_TEXT = 'An existing snapshot generated with the statement_performance_analyzer() must exist.'; END IF;" " WHEN in_action = 'create_tmp' THEN IF (v_table_exists = 'TEMPORARY') THEN SET v_error_msg = CONCAT('Cannot create th" "e table ', IF(CHAR_LENGTH(v_quoted_table) > 72, CONCAT('...', SUBSTRING(v_quoted_table, -69)), v_quoted_table), ' as " "it already exists.'); SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = v_error_msg; END IF; WHEN in_action = 'create_table" "' THEN IF (v_table_exists <> '') THEN SET v_error_msg = CONCAT('Cannot create the table ', IF(CHAR_LENGTH(v_quoted_ta" "ble) > 52, CONCAT('...', SUBSTRING(v_quoted_table, -49)), v_quoted_table), ' as it already exists', IF(v_table_exists" " = 'TEMPORARY', ' as a temporary table.', '.')); SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = v_error_msg; END IF; WHE" "N in_action = 'cleanup' THEN DO (SELECT 1); ELSE SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Unknown action. Supporte" "d actions are: cleanup, create_table, create_tmp, delta, overall, save, snapshot'; END CASE; SET v_digest_table_temp" "late = 'CREATE %{TEMPORARY}TABLE %{TABLE_NAME} ( `SCHEMA_NAME` varchar(64) DEFAULT NULL, `DIGEST` varchar(32) DEFAULT" " NULL, `DIGEST_TEXT` longtext, `COUNT_STAR` bigint(20) unsigned NOT NULL, `SUM_TIMER_WAIT` bigint(20) unsigned NOT NU" "LL, `MIN_TIMER_WAIT` bigint(20) unsigned NOT NULL, `AVG_TIMER_WAIT` bigint(20) unsigned NOT NULL, `MAX_TIMER_WAIT` bi" "gint(20) unsigned NOT NULL, `SUM_LOCK_TIME` bigint(20) unsigned NOT NULL, `SUM_ERRORS` bigint(20) unsigned NOT NULL, " "`SUM_WARNINGS` bigint(20) unsigned NOT NULL, `SUM_ROWS_AFFECTED` bigint(20) unsigned NOT NULL, `SUM_ROWS_SENT` bigint" "(20) unsigned NOT NULL, `SUM_ROWS_EXAMINED` bigint(20) unsigned NOT NULL, `SUM_CREATED_TMP_DISK_TABLES` bigint(20) un" "signed NOT NULL, `SUM_CREATED_TMP_TABLES` bigint(20) unsigned NOT NULL, `SUM_SELECT_FULL_JOIN` bigint(20) unsigned NO" "T NULL, `SUM_SELECT_FULL_RANGE_JOIN` bigint(20) unsigned NOT NULL, `SUM_SELECT_RANGE` bigint(20) unsigned NOT NULL, `" "SUM_SELECT_RANGE_CHECK` bigint(20) unsigned NOT NULL, `SUM_SELECT_SCAN` bigint(20) unsigned NOT NULL, `SUM_SORT_MERGE" "_PASSES` bigint(20) unsigned NOT NULL, `SUM_SORT_RANGE` bigint(20) unsigned NOT NULL, `SUM_SORT_ROWS` bigint(20) unsi" "gned NOT NULL, `SUM_SORT_SCAN` bigint(20) unsigned NOT NULL, `SUM_NO_INDEX_USED` bigint(20) unsigned NOT NULL, `SUM_N" "O_GOOD_INDEX_USED` bigint(20) unsigned NOT NULL, `FIRST_SEEN` timestamp NULL DEFAULT NULL, `LAST_SEEN` timestamp NULL" " DEFAULT NULL, INDEX (SCHEMA_NAME, DIGEST) ) DEFAULT CHARSET=utf8'; IF (v_force_new_snapshot OR in_action = 'snapsho" "t' OR (in_action = 'overall' AND in_table IS NULL) OR (in_action = 'save' AND v_tmp_digests_table_exists <> 'TEMPORAR" "Y') ) THEN IF (v_tmp_digests_table_exists = 'TEMPORARY') THEN IF (@sys.debug = 'ON') THEN SELECT 'DROP TEMPORARY TABL" "E IF EXISTS tmp_digests' AS 'Debug'; END IF; DROP TEMPORARY TABLE IF EXISTS tmp_digests; END IF; CALL sys.execute_pre" "pared_stmt(REPLACE(REPLACE(v_digest_table_template, '%{TEMPORARY}', 'TEMPORARY '), '%{TABLE_NAME}', 'tmp_digests')); " " SET v_sql = CONCAT('INSERT INTO tmp_digests SELECT * FROM ', IF(in_table IS NULL OR in_action = 'save', 'performance" "_schema.events_statements_summary_by_digest', v_quoted_table)); CALL sys.execute_prepared_stmt(v_sql); END IF; IF (i" "n_action IN ('create_table', 'create_tmp')) THEN IF (in_action = 'create_table') THEN CALL sys.execute_prepared_stmt(" "REPLACE(REPLACE(v_digest_table_template, '%{TEMPORARY}', ''), '%{TABLE_NAME}', v_quoted_table)); ELSE CALL sys.execut" "e_prepared_stmt(REPLACE(REPLACE(v_digest_table_template, '%{TEMPORARY}', 'TEMPORARY '), '%{TABLE_NAME}', v_quoted_tab" "le)); END IF; ELSEIF (in_action = 'save') THEN CALL sys.execute_prepared_stmt(CONCAT('DELETE FROM ', v_quoted_table))" "; CALL sys.execute_prepared_stmt(CONCAT('INSERT INTO ', v_quoted_table, ' SELECT * FROM tmp_digests')); ELSEIF (in_ac" "tion = 'cleanup') THEN DROP TEMPORARY TABLE IF EXISTS sys.tmp_digests; DROP TEMPORARY TABLE IF EXISTS sys.tmp_digests" "_delta; ELSEIF (in_action IN ('overall', 'delta')) THEN IF (in_action = 'overall') THEN IF (in_table IS NULL) THEN SE" "T v_digests_table = 'tmp_digests'; ELSE SET v_digests_table = v_quoted_table; END IF; ELSE SET v_digests_table = 'tmp" "_digests_delta'; DROP TEMPORARY TABLE IF EXISTS tmp_digests_delta; CREATE TEMPORARY TABLE tmp_digests_delta LIKE tmp_" "digests; SET v_sql = CONCAT('INSERT INTO tmp_digests_delta SELECT `d_end`.`SCHEMA_NAME`, `d_end`.`DIGEST`, `d_end`.`D" "IGEST_TEXT`, `d_end`.`COUNT_STAR`-IFNULL(`d_start`.`COUNT_STAR`, 0) AS ''COUNT_STAR'', `d_end`.`SUM_TIMER_WAIT`-IFNUL" "L(`d_start`.`SUM_TIMER_WAIT`, 0) AS ''SUM_TIMER_WAIT'', `d_end`.`MIN_TIMER_WAIT` AS ''MIN_TIMER_WAIT'', IFNULL((`d_en" "d`.`SUM_TIMER_WAIT`-IFNULL(`d_start`.`SUM_TIMER_WAIT`, 0))/NULLIF(`d_end`.`COUNT_STAR`-IFNULL(`d_start`.`COUNT_STAR`," " 0), 0), 0) AS ''AVG_TIMER_WAIT'', `d_end`.`MAX_TIMER_WAIT` AS ''MAX_TIMER_WAIT'', `d_end`.`SUM_LOCK_TIME`-IFNULL(`d_" "start`.`SUM_LOCK_TIME`, 0) AS ''SUM_LOCK_TIME'', `d_end`.`SUM_ERRORS`-IFNULL(`d_start`.`SUM_ERRORS`, 0) AS ''SUM_ERRO" "RS'', `d_end`.`SUM_WARNINGS`-IFNULL(`d_start`.`SUM_WARNINGS`, 0) AS ''SUM_WARNINGS'', `d_end`.`SUM_ROWS_AFFECTED`-IFN" "ULL(`d_start`.`SUM_ROWS_AFFECTED`, 0) AS ''SUM_ROWS_AFFECTED'', `d_end`.`SUM_ROWS_SENT`-IFNULL(`d_start`.`SUM_ROWS_SE" "NT`, 0) AS ''SUM_ROWS_SENT'', `d_end`.`SUM_ROWS_EXAMINED`-IFNULL(`d_start`.`SUM_ROWS_EXAMINED`, 0) AS ''SUM_ROWS_EXAM" "INED'', `d_end`.`SUM_CREATED_TMP_DISK_TABLES`-IFNULL(`d_start`.`SUM_CREATED_TMP_DISK_TABLES`, 0) AS ''SUM_CREATED_TMP" "_DISK_TABLES'', `d_end`.`SUM_CREATED_TMP_TABLES`-IFNULL(`d_start`.`SUM_CREATED_TMP_TABLES`, 0) AS ''SUM_CREATED_TMP_T" "ABLES'', `d_end`.`SUM_SELECT_FULL_JOIN`-IFNULL(`d_start`.`SUM_SELECT_FULL_JOIN`, 0) AS ''SUM_SELECT_FULL_JOIN'', `d_e" "nd`.`SUM_SELECT_FULL_RANGE_JOIN`-IFNULL(`d_start`.`SUM_SELECT_FULL_RANGE_JOIN`, 0) AS ''SUM_SELECT_FULL_RANGE_JOIN''," " `d_end`.`SUM_SELECT_RANGE`-IFNULL(`d_start`.`SUM_SELECT_RANGE`, 0) AS ''SUM_SELECT_RANGE'', `d_end`.`SUM_SELECT_RANG" "E_CHECK`-IFNULL(`d_start`.`SUM_SELECT_RANGE_CHECK`, 0) AS ''SUM_SELECT_RANGE_CHECK'', `d_end`.`SUM_SELECT_SCAN`-IFNUL" "L(`d_start`.`SUM_SELECT_SCAN`, 0) AS ''SUM_SELECT_SCAN'', `d_end`.`SUM_SORT_MERGE_PASSES`-IFNULL(`d_start`.`SUM_SORT_" "MERGE_PASSES`, 0) AS ''SUM_SORT_MERGE_PASSES'', `d_end`.`SUM_SORT_RANGE`-IFNULL(`d_start`.`SUM_SORT_RANGE`, 0) AS ''S" "UM_SORT_RANGE'', `d_end`.`SUM_SORT_ROWS`-IFNULL(`d_start`.`SUM_SORT_ROWS`, 0) AS ''SUM_SORT_ROWS'', `d_end`.`SUM_SORT" "_SCAN`-IFNULL(`d_start`.`SUM_SORT_SCAN`, 0) AS ''SUM_SORT_SCAN'', `d_end`.`SUM_NO_INDEX_USED`-IFNULL(`d_start`.`SUM_N" "O_INDEX_USED`, 0) AS ''SUM_NO_INDEX_USED'', `d_end`.`SUM_NO_GOOD_INDEX_USED`-IFNULL(`d_start`.`SUM_NO_GOOD_INDEX_USED" "`, 0) AS ''SUM_NO_GOOD_INDEX_USED'', `d_end`.`FIRST_SEEN`, `d_end`.`LAST_SEEN` FROM tmp_digests d_end LEFT OUTER JOIN" " ', v_quoted_table, ' d_start ON `d_start`.`DIGEST` = `d_end`.`DIGEST` AND (`d_start`.`SCHEMA_NAME` = `d_end`.`SCHEMA" "_NAME` OR (`d_start`.`SCHEMA_NAME` IS NULL AND `d_end`.`SCHEMA_NAME` IS NULL) ) WHERE `d_end`.`COUNT_STAR`-IFNULL(`d_" "start`.`COUNT_STAR`, 0) > 0'); CALL sys.execute_prepared_stmt(v_sql); END IF; IF (FIND_IN_SET('with_runtimes_in_95th" "_percentile', in_views)) THEN SELECT 'Queries with Runtime in 95th Percentile' AS 'Next Output'; DROP TEMPORARY TABL" "E IF EXISTS tmp_digest_avg_latency_distribution1; DROP TEMPORARY TABLE IF EXISTS tmp_digest_avg_latency_distribution2" "; DROP TEMPORARY TABLE IF EXISTS tmp_digest_95th_percentile_by_avg_us; CREATE TEMPORARY TABLE tmp_digest_avg_latency" "_distribution1 ( cnt bigint unsigned NOT NULL, avg_us decimal(21,0) NOT NULL, PRIMARY KEY (avg_us) ) ENGINE=InnoDB; " "SET v_sql = CONCAT('INSERT INTO tmp_digest_avg_latency_distribution1 SELECT COUNT(*) cnt, ROUND(avg_timer_wait/100000" "0) AS avg_us FROM ', v_digests_table, ' GROUP BY avg_us'); CALL sys.execute_prepared_stmt(v_sql); CREATE TEMPORARY T" "ABLE tmp_digest_avg_latency_distribution2 LIKE tmp_digest_avg_latency_distribution1; INSERT INTO tmp_digest_avg_laten" "cy_distribution2 SELECT * FROM tmp_digest_avg_latency_distribution1; CREATE TEMPORARY TABLE tmp_digest_95th_percenti" "le_by_avg_us ( avg_us decimal(21,0) NOT NULL, percentile decimal(46,4) NOT NULL, PRIMARY KEY (avg_us) ) ENGINE=InnoDB" "; SET v_sql = CONCAT('INSERT INTO tmp_digest_95th_percentile_by_avg_us SELECT s2.avg_us avg_us, IFNULL(SUM(s1.cnt)/N" "ULLIF((SELECT COUNT(*) FROM ', v_digests_table, '), 0), 0) percentile FROM tmp_digest_avg_latency_distribution1 AS s1" " JOIN tmp_digest_avg_latency_distribution2 AS s2 ON s1.avg_us <= s2.avg_us GROUP BY s2.avg_us HAVING percentile > 0.9" "5 ORDER BY percentile LIMIT 1'); CALL sys.execute_prepared_stmt(v_sql); SET v_sql = REPLACE( REPLACE( (SELECT VIEW_D" "EFINITION FROM information_schema.VIEWS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'statements_with_runtimes_in" "_95th_percentile' ), '`performance_schema`.`events_statements_summary_by_digest`', v_digests_table ), 'sys.x$ps_diges" "t_95th_percentile_by_avg_us', '`sys`.`x$ps_digest_95th_percentile_by_avg_us`' ); CALL sys.execute_prepared_stmt(v_sql" "); DROP TEMPORARY TABLE tmp_digest_avg_latency_distribution1; DROP TEMPORARY TABLE tmp_digest_avg_latency_distributi" "on2; DROP TEMPORARY TABLE tmp_digest_95th_percentile_by_avg_us; END IF; IF (FIND_IN_SET('analysis', in_views)) THEN " "SELECT CONCAT('Top ', @sys.statement_performance_analyzer.limit, ' Queries Ordered by Total Latency') AS 'Next Output" "'; SET v_sql = REPLACE( (SELECT VIEW_DEFINITION FROM information_schema.VIEWS WHERE TABLE_SCHEMA = DATABASE() AND TAB" "LE_NAME = 'statement_analysis' ), '`performance_schema`.`events_statements_summary_by_digest`', v_digests_table ); IF" " (@sys.statement_performance_analyzer.limit > 0) THEN SET v_sql = CONCAT(v_sql, ' LIMIT ', @sys.statement_performance" "_analyzer.limit); END IF; CALL sys.execute_prepared_stmt(v_sql); END IF; IF (FIND_IN_SET('with_errors_or_warnings', " "in_views)) THEN SELECT CONCAT('Top ', @sys.statement_performance_analyzer.limit, ' Queries with Errors') AS 'Next Out" "put'; SET v_sql = REPLACE( (SELECT VIEW_DEFINITION FROM information_schema.VIEWS WHERE TABLE_SCHEMA = DATABASE() AND " "TABLE_NAME = 'statements_with_errors_or_warnings' ), '`performance_schema`.`events_statements_summary_by_digest`', v_" "digests_table ); IF (@sys.statement_performance_analyzer.limit > 0) THEN SET v_sql = CONCAT(v_sql, ' LIMIT ', @sys.st" "atement_performance_analyzer.limit); END IF; CALL sys.execute_prepared_stmt(v_sql); END IF; IF (FIND_IN_SET('with_fu" "ll_table_scans', in_views)) THEN SELECT CONCAT('Top ', @sys.statement_performance_analyzer.limit, ' Queries with Full" " Table Scan') AS 'Next Output'; SET v_sql = REPLACE( (SELECT VIEW_DEFINITION FROM information_schema.VIEWS WHERE TABL" "E_SCHEMA = DATABASE() AND TABLE_NAME = 'statements_with_full_table_scans' ), '`performance_schema`.`events_statements" "_summary_by_digest`', v_digests_table ); IF (@sys.statement_performance_analyzer.limit > 0) THEN SET v_sql = CONCAT(v" "_sql, ' LIMIT ', @sys.statement_performance_analyzer.limit); END IF; CALL sys.execute_prepared_stmt(v_sql); END IF; " "IF (FIND_IN_SET('with_sorting', in_views)) THEN SELECT CONCAT('Top ', @sys.statement_performance_analyzer.limit, ' Qu" "eries with Sorting') AS 'Next Output'; SET v_sql = REPLACE( (SELECT VIEW_DEFINITION FROM information_schema.VIEWS WHE" "RE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'statements_with_sorting' ), '`performance_schema`.`events_statements_s" "ummary_by_digest`', v_digests_table ); IF (@sys.statement_performance_analyzer.limit > 0) THEN SET v_sql = CONCAT(v_s" "ql, ' LIMIT ', @sys.statement_performance_analyzer.limit); END IF; CALL sys.execute_prepared_stmt(v_sql); END IF; IF" " (FIND_IN_SET('with_temp_tables', in_views)) THEN SELECT CONCAT('Top ', @sys.statement_performance_analyzer.limit, ' " "Queries with Internal Temporary Tables') AS 'Next Output'; SET v_sql = REPLACE( (SELECT VIEW_DEFINITION FROM informat" "ion_schema.VIEWS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'statements_with_temp_tables' ), '`performance_sche" "ma`.`events_statements_summary_by_digest`', v_digests_table ); IF (@sys.statement_performance_analyzer.limit > 0) THE" "N SET v_sql = CONCAT(v_sql, ' LIMIT ', @sys.statement_performance_analyzer.limit); END IF; CALL sys.execute_prepared_" "stmt(v_sql); END IF; IF (FIND_IN_SET('custom', in_views)) THEN SELECT CONCAT('Top ', @sys.statement_performance_anal" "yzer.limit, ' Queries Using Custom View') AS 'Next Output'; IF (@sys.statement_performance_analyzer.view IS NULL) TH" "EN SET @sys.statement_performance_analyzer.view = sys.sys_get_config('statement_performance_analyzer.view', NULL); EN" "D IF; IF (@sys.statement_performance_analyzer.view IS NULL) THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'The @sys" ".statement_performance_analyzer.view user variable must be set with the view or query to use.'; END IF; IF (NOT INST" "R(@sys.statement_performance_analyzer.view, ' ')) THEN IF (NOT INSTR(@sys.statement_performance_analyzer.view, '.')) " "THEN SET v_custom_db = DATABASE(), v_custom_name = @sys.statement_performance_analyzer.view; ELSE SET v_custom_db " " = SUBSTRING_INDEX(@sys.statement_performance_analyzer.view, '.', 1); SET v_custom_name = SUBSTRING(@sys.statement_pe" "rformance_analyzer.view, CHAR_LENGTH(v_custom_db)+2); END IF; CALL sys.table_exists(v_custom_db, v_custom_name, v_cu" "stom_view_exists); IF (v_custom_view_exists <> 'VIEW') THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'The @sys.stat" "ement_performance_analyzer.view user variable is set but specified neither an existing view nor a query.'; END IF; S" "ET v_sql = REPLACE( (SELECT VIEW_DEFINITION FROM information_schema.VIEWS WHERE TABLE_SCHEMA = v_custom_db AND TABLE_" "NAME = v_custom_name ), '`performance_schema`.`events_statements_summary_by_digest`', v_digests_table ); ELSE SET v_s" "ql = REPLACE(@sys.statement_performance_analyzer.view, '`performance_schema`.`events_statements_summary_by_digest`', " "v_digests_table); END IF; IF (@sys.statement_performance_analyzer.limit > 0) THEN SET v_sql = CONCAT(v_sql, ' LIMIT " "', @sys.statement_performance_analyzer.limit); END IF; CALL sys.execute_prepared_stmt(v_sql); END IF; END IF; IF (v" "_this_thread_enabled = 'YES') THEN CALL sys.ps_setup_enable_thread(CONNECTION_ID()); END IF; IF (@log_bin = 1) THEN " "SET sql_log_bin = @log_bin; END IF; END;\n", "DROP PROCEDURE IF EXISTS table_exists;\n", "CREATE DEFINER='mysql.sys'@'localhost' PROCEDURE table_exists ( IN in_db VARCHAR(64), IN in_table VARCHAR(64), OUT out_e" "xists ENUM('', 'BASE TABLE', 'VIEW', 'TEMPORARY') ) COMMENT '\\n Description\\n \\n Tests whether the table specified in" " in_db and in_table exists either as a regular\\n table, or as a temporary table. The returned value corresponds to th" "e table that\\n will be used, so if there''s both a temporary and a permanent table with the given\\n name, then ''TEMP" "ORARY'' will be returned.\\n \\n Parameters\\n \\n in_db (VARCHAR(64)):\\n The database name to check for the existance of" " the table in.\\n \\n in_table (VARCHAR(64)):\\n The name of the table to check the existance of.\\n \\n out_exists ENUM('" "''', ''BASE TABLE'', ''VIEW'', ''TEMPORARY''):\\n The return value: whether the table exists. The value is one of:\\n *" " '''' - the table does not exist neither as a base table, view, nor temporary table.\\n * ''BASE TABLE'' - t" "he table name exists as a permanent base table table.\\n * ''VIEW'' - the table name exists as a view.\\n * ''TEM" "PORARY'' - the table name exists as a temporary table.\\n \\n Example\\n \\n mysql> CREATE DATABASE db1;\\n Query OK, 1 r" "ow affected (0.07 sec)\\n \\n mysql> use db1;\\n Database changed\\n mysql> CREATE TABLE t1 (id INT PRIMARY KEY);\\n Query" " OK, 0 rows affected (0.08 sec)\\n \\n mysql> CREATE TABLE t2 (id INT PRIMARY KEY);\\n Query OK, 0 rows affected (0.08 s" "ec)\\n \\n mysql> CREATE view v_t1 AS SELECT * FROM t1;\\n Query OK, 0 rows affected (0.00 sec)\\n \\n mysql> CREATE TEMPO" "RARY TABLE t1 (id INT PRIMARY KEY);\\n Query OK, 0 rows affected (0.00 sec)\\n \\n mysql> CALL sys.table_exists(''db1''," " ''t1'', @exists); SELECT @exists;\\n Query OK, 0 rows affected (0.00 sec)\\n \\n +------------+\\n | @exists |\\n +---" "---------+\\n | TEMPORARY |\\n +------------+\\n 1 row in set (0.00 sec)\\n \\n mysql> CALL sys.table_exists(''db1'', ''t" "2'', @exists); SELECT @exists;\\n Query OK, 0 rows affected (0.00 sec)\\n \\n +------------+\\n | @exists |\\n +-------" "-----+\\n | BASE TABLE |\\n +------------+\\n 1 row in set (0.01 sec)\\n \\n mysql> CALL sys.table_exists(''db1'', ''v_t1'" "', @exists); SELECT @exists;\\n Query OK, 0 rows affected (0.00 sec)\\n \\n +---------+\\n | @exists |\\n +---------+\\n | " "VIEW |\\n +---------+\\n 1 row in set (0.00 sec)\\n \\n mysql> CALL sys.table_exists(''db1'', ''t3'', @exists); SELECT" " @exists;\\n Query OK, 0 rows affected (0.01 sec)\\n \\n +---------+\\n | @exists |\\n +---------+\\n | |\\n +------" "---+\\n 1 row in set (0.00 sec)\\n ' SQL SECURITY INVOKER NOT DETERMINISTIC CONTAINS SQL BEGIN DECLARE v_error BOOLEAN " "DEFAULT FALSE; DECLARE CONTINUE HANDLER FOR 1050 SET v_error = TRUE; DECLARE CONTINUE HANDLER FOR 1146 SET v_error = " "TRUE; SET out_exists = ''; IF (EXISTS(SELECT 1 FROM information_schema.TABLES WHERE TABLE_SCHEMA = in_db AND TABLE_" "NAME = in_table)) THEN SET @sys.tmp.table_exists.SQL = CONCAT('CREATE TEMPORARY TABLE `', in_db, '`.`', in_table, '` " "(id INT PRIMARY KEY)'); PREPARE stmt_create_table FROM @sys.tmp.table_exists.SQL; EXECUTE stmt_create_table; DEALLOCA" "TE PREPARE stmt_create_table; IF (v_error) THEN SET out_exists = 'TEMPORARY'; ELSE SET @sys.tmp.table_exists.SQL = CO" "NCAT('DROP TEMPORARY TABLE `', in_db, '`.`', in_table, '`'); PREPARE stmt_drop_table FROM @sys.tmp.table_exists.SQL; " "EXECUTE stmt_drop_table; DEALLOCATE PREPARE stmt_drop_table; SET out_exists = (SELECT TABLE_TYPE FROM information_sch" "ema.TABLES WHERE TABLE_SCHEMA = in_db AND TABLE_NAME = in_table); END IF; ELSE SET @sys.tmp.table_exists.SQL = CONCAT" "('SELECT COUNT(*) FROM `', in_db, '`.`', in_table, '`'); PREPARE stmt_select FROM @sys.tmp.table_exists.SQL; IF (NOT " "v_error) THEN DEALLOCATE PREPARE stmt_select; SET out_exists = 'TEMPORARY'; END IF; END IF; END;\n", "SET @@sql_log_bin = @sql_log_bin;\n", NULL };