Commit 4bac804c authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

MDEV-9077 add sys_schema from https://github.com/mysql/mysql-sys

parent 7c5c6fa6
This diff is collapsed.
Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
This diff is collapsed.
This diff is collapsed.
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
SET @@sql_log_bin = @sql_log_bin;
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
SET NAMES utf8;
SET @sql_log_bin = @@sql_log_bin;
SET sql_log_bin = 0;
CREATE DATABASE IF NOT EXISTS sys DEFAULT CHARACTER SET utf8;
USE sys;
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP FUNCTION IF EXISTS extract_schema_from_file_name;
DELIMITER $$
CREATE DEFINER='root'@'localhost' FUNCTION extract_schema_from_file_name (
path VARCHAR(512)
)
RETURNS VARCHAR(64)
COMMENT '
Description
-----------
Takes a raw file path, and attempts to extract the schema name from it.
Useful for when interacting with Performance Schema data
concerning IO statistics, for example.
Currently relies on the fact that a table data file will be within a
specified database directory (will not work with partitions or tables
that specify an individual DATA_DIRECTORY).
Parameters
-----------
path (VARCHAR(512)):
The full file path to a data file to extract the schema name from.
Returns
-----------
VARCHAR(64)
Example
-----------
mysql> SELECT sys.extract_schema_from_file_name(\'/var/lib/mysql/employees/employee.ibd\');
+----------------------------------------------------------------------------+
| sys.extract_schema_from_file_name(\'/var/lib/mysql/employees/employee.ibd\') |
+----------------------------------------------------------------------------+
| employees |
+----------------------------------------------------------------------------+
1 row in set (0.00 sec)
'
SQL SECURITY INVOKER
DETERMINISTIC
NO SQL
BEGIN
RETURN LEFT(SUBSTRING_INDEX(SUBSTRING_INDEX(REPLACE(path, '\\', '/'), '/', -2), '/', 1), 64);
END$$
DELIMITER ;
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP FUNCTION IF EXISTS extract_table_from_file_name;
DELIMITER $$
CREATE DEFINER='root'@'localhost' FUNCTION extract_table_from_file_name (
path VARCHAR(512)
)
RETURNS VARCHAR(64)
COMMENT '
Description
-----------
Takes a raw file path, and extracts the table name from it.
Useful for when interacting with Performance Schema data
concerning IO statistics, for example.
Parameters
-----------
path (VARCHAR(512)):
The full file path to a data file to extract the table name from.
Returns
-----------
VARCHAR(64)
Example
-----------
mysql> SELECT sys.extract_table_from_file_name(\'/var/lib/mysql/employees/employee.ibd\');
+---------------------------------------------------------------------------+
| sys.extract_table_from_file_name(\'/var/lib/mysql/employees/employee.ibd\') |
+---------------------------------------------------------------------------+
| employee |
+---------------------------------------------------------------------------+
1 row in set (0.02 sec)
'
SQL SECURITY INVOKER
DETERMINISTIC
NO SQL
BEGIN
RETURN LEFT(SUBSTRING_INDEX(REPLACE(SUBSTRING_INDEX(REPLACE(path, '\\', '/'), '/', -1), '@0024', '$'), '.', 1), 64);
END$$
DELIMITER ;
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP FUNCTION IF EXISTS format_bytes;
DELIMITER $$
CREATE DEFINER='root'@'localhost' FUNCTION format_bytes (
-- We feed in and return TEXT here, as aggregates of
-- bytes can return numbers larger than BIGINT UNSIGNED
bytes TEXT
)
RETURNS TEXT
COMMENT '
Description
-----------
Takes a raw bytes value, and converts it to a human readable format.
Parameters
-----------
bytes (TEXT):
A raw bytes value.
Returns
-----------
TEXT
Example
-----------
mysql> SELECT sys.format_bytes(2348723492723746) AS size;
+----------+
| size |
+----------+
| 2.09 PiB |
+----------+
1 row in set (0.00 sec)
mysql> SELECT sys.format_bytes(2348723492723) AS size;
+----------+
| size |
+----------+
| 2.14 TiB |
+----------+
1 row in set (0.00 sec)
mysql> SELECT sys.format_bytes(23487234) AS size;
+-----------+
| size |
+-----------+
| 22.40 MiB |
+-----------+
1 row in set (0.00 sec)
'
SQL SECURITY INVOKER
DETERMINISTIC
NO SQL
BEGIN
IF bytes 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 CONCAT(ROUND(bytes, 0), ' bytes');
END IF;
END$$
DELIMITER ;
-- Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP FUNCTION IF EXISTS format_path;
DELIMITER $$
CREATE DEFINER='root'@'localhost' FUNCTION format_path (
in_path VARCHAR(512)
)
RETURNS VARCHAR(512) CHARSET UTF8
COMMENT '
Description
-----------
Takes a raw path value, and strips out the datadir or tmpdir
replacing with @@datadir and @@tmpdir respectively.
Also normalizes the paths across operating systems, so backslashes
on Windows are converted to forward slashes
Parameters
-----------
path (VARCHAR(512)):
The raw file path value to format.
Returns
-----------
VARCHAR(512) CHARSET UTF8
Example
-----------
mysql> select @@datadir;
+-----------------------------------------------+
| @@datadir |
+-----------------------------------------------+
| /Users/mark/sandboxes/SmallTree/AMaster/data/ |
+-----------------------------------------------+
1 row in set (0.06 sec)
mysql> select format_path(\'/Users/mark/sandboxes/SmallTree/AMaster/data/mysql/proc.MYD\') AS path;
+--------------------------+
| path |
+--------------------------+
| @@datadir/mysql/proc.MYD |
+--------------------------+
1 row in set (0.03 sec)
'
SQL SECURITY INVOKER
DETERMINISTIC
NO SQL
BEGIN
DECLARE v_path VARCHAR(512);
DECLARE v_undo_dir VARCHAR(1024);
DECLARE path_separator CHAR(1) DEFAULT '/';
IF @@global.version_compile_os LIKE 'win%' THEN
SET path_separator = '\\';
END IF;
-- OSX hides /private/ in variables, but Performance Schema does not
IF in_path LIKE '/private/%' THEN
SET v_path = REPLACE(in_path, '/private', '');
ELSE
SET v_path = in_path;
END IF;
-- @@global.innodb_undo_directory is only set when separate undo logs are used
SET v_undo_dir = IFNULL((SELECT VARIABLE_VALUE FROM information_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', IF(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_separator, '')));
ELSEIF v_path LIKE CONCAT(@@global.slave_load_tmpdir, IF(SUBSTRING(@@global.slave_load_tmpdir, -1) = path_separator, '%', 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_separator, '%', 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_separator, '%', 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, path_separator, '')));
END IF;
RETURN v_path;
END$$
DELIMITER ;
-- Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP FUNCTION IF EXISTS format_path;
DELIMITER $$
CREATE DEFINER='root'@'localhost' FUNCTION format_path (
in_path VARCHAR(512)
)
RETURNS VARCHAR(512) CHARSET UTF8
COMMENT '
Description
-----------
Takes a raw path value, and strips out the datadir or tmpdir
replacing with @@datadir and @@tmpdir respectively.
Also normalizes the paths across operating systems, so backslashes
on Windows are converted to forward slashes
Parameters
-----------
path (VARCHAR(512)):
The raw file path value to format.
Returns
-----------
VARCHAR(512) CHARSET UTF8
Example
-----------
mysql> select @@datadir;
+-----------------------------------------------+
| @@datadir |
+-----------------------------------------------+
| /Users/mark/sandboxes/SmallTree/AMaster/data/ |
+-----------------------------------------------+
1 row in set (0.06 sec)
mysql> select format_path(\'/Users/mark/sandboxes/SmallTree/AMaster/data/mysql/proc.MYD\') AS path;
+--------------------------+
| path |
+--------------------------+
| @@datadir/mysql/proc.MYD |
+--------------------------+
1 row in set (0.03 sec)
'
SQL SECURITY INVOKER
DETERMINISTIC
NO SQL
BEGIN
DECLARE v_path VARCHAR(512);
DECLARE v_undo_dir VARCHAR(1024);
DECLARE path_separator CHAR(1) DEFAULT '/';
IF @@global.version_compile_os LIKE 'win%' THEN
SET path_separator = '\\';
END IF;
-- OSX hides /private/ in variables, but Performance Schema does not
IF in_path LIKE '/private/%' THEN
SET v_path = REPLACE(in_path, '/private', '');
ELSE
SET v_path = in_path;
END IF;
-- @@global.innodb_undo_directory is only set when separate undo logs are used
SET v_undo_dir = IFNULL((SELECT VARIABLE_VALUE 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', IF(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_separator, '')));
ELSEIF v_path LIKE CONCAT(@@global.slave_load_tmpdir, IF(SUBSTRING(@@global.slave_load_tmpdir, -1) = path_separator, '%', 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_separator, '%', 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_separator, '%', 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, path_separator, '')));
END IF;
RETURN v_path;
END$$
DELIMITER ;
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP FUNCTION IF EXISTS format_statement;
DELIMITER $$
CREATE DEFINER='root'@'localhost' FUNCTION format_statement (
statement LONGTEXT
)
RETURNS LONGTEXT
COMMENT '
Description
-----------
Formats a normalized statement, truncating it if it is > 64 characters long by default.
To configure the length to truncate the statement to by default, update the `statement_truncate_len`
variable with `sys_config` table to a different value. Alternatively, to change it just for just
your particular session, use `SET @sys.statement_truncate_len := <some new value>`.
Useful for printing statement related data from Performance Schema from
the command line.
Parameters
-----------
statement (LONGTEXT):
The statement to format.
Returns
-----------
LONGTEXT
Example
-----------
mysql> SELECT sys.format_statement(digest_text)
-> FROM performance_schema.events_statements_summary_by_digest
-> ORDER by sum_timer_wait DESC limit 5;
+-------------------------------------------------------------------+
| sys.format_statement(digest_text) |
+-------------------------------------------------------------------+
| CREATE SQL SECURITY INVOKER VI ... KE ? AND `variable_value` > ? |
| CREATE SQL SECURITY INVOKER VI ... ait` IS NOT NULL , `esc` . ... |
| CREATE SQL SECURITY INVOKER VI ... ait` IS NOT NULL , `sys` . ... |
| CREATE SQL SECURITY INVOKER VI ... , `compressed_size` ) ) DESC |
| CREATE SQL SECURITY INVOKER VI ... LIKE ? ORDER BY `timer_start` |
+-------------------------------------------------------------------+
5 rows in set (0.00 sec)
'
SQL SECURITY INVOKER
DETERMINISTIC
NO SQL
BEGIN
-- Check if we have the configured length, if not, init it
IF @sys.statement_truncate_len IS NULL THEN
SET @sys.statement_truncate_len = sys_get_config('statement_truncate_len', 64);
END IF;
IF CHAR_LENGTH(statement) > @sys.statement_truncate_len THEN
RETURN REPLACE(CONCAT(LEFT(statement, (@sys.statement_truncate_len/2)-2), ' ... ', RIGHT(statement, (@sys.statement_truncate_len/2)-2)), '\n', ' ');
ELSE
RETURN REPLACE(statement, '\n', ' ');
END IF;
END$$
DELIMITER ;
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP FUNCTION IF EXISTS format_time;
DELIMITER $$
CREATE DEFINER='root'@'localhost' FUNCTION format_time (
-- We feed in and return TEXT here, as aggregates of
-- picoseconds can return numbers larger than BIGINT UNSIGNED
picoseconds TEXT
)
RETURNS TEXT CHARSET UTF8
COMMENT '
Description
-----------
Takes a raw picoseconds value, and converts it to a human readable form.
Picoseconds are the precision that all latency values are printed in
within Performance Schema, however are not user friendly when wanting
to scan output from the command line.
Parameters
-----------
picoseconds (TEXT):
The raw picoseconds value to convert.
Returns
-----------
TEXT
Example
-----------
mysql> select format_time(342342342342345);
+------------------------------+
| format_time(342342342342345) |
+------------------------------+
| 00:05:42 |
+------------------------------+
1 row in set (0.00 sec)
mysql> select format_time(342342342);
+------------------------+
| format_time(342342342) |
+------------------------+
| 342.34 us |
+------------------------+
1 row in set (0.00 sec)
mysql> select format_time(34234);
+--------------------+
| format_time(34234) |
+--------------------+
| 34.23 ns |
+--------------------+
1 row in set (0.00 sec)
'
SQL SECURITY INVOKER
DETERMINISTIC
NO SQL
BEGIN
IF picoseconds IS NULL THEN RETURN NULL;
ELSEIF picoseconds >= 604800000000000000 THEN RETURN CONCAT(ROUND(picoseconds / 604800000000000000, 2), ' w');
ELSEIF picoseconds >= 86400000000000000 THEN RETURN CONCAT(ROUND(picoseconds / 86400000000000000, 2), ' d');
ELSEIF picoseconds >= 3600000000000000 THEN RETURN CONCAT(ROUND(picoseconds / 3600000000000000, 2), ' h');
ELSEIF picoseconds >= 60000000000000 THEN RETURN CONCAT(ROUND(picoseconds / 60000000000000, 2), ' m');
ELSEIF picoseconds >= 1000000000000 THEN RETURN CONCAT(ROUND(picoseconds / 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 picoseconds >= 1000 THEN RETURN CONCAT(ROUND(picoseconds / 1000, 2), ' ns');
ELSE RETURN CONCAT(picoseconds, ' ps');
END IF;
END$$
DELIMITER ;
-- Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP FUNCTION IF EXISTS list_add;
DELIMITER $$
CREATE DEFINER='root'@'localhost' FUNCTION list_add (
in_list TEXT,
in_add_value TEXT
)
RETURNS TEXT
COMMENT '
Description
-----------
Takes a list, and a value to add to the list, and returns the resulting list.
Useful for altering certain session variables, like sql_mode or optimizer_switch for instance.
Parameters
-----------
in_list (TEXT):
The comma separated list to add a value to
in_add_value (TEXT):
The value to add to the input list
Returns
-----------
TEXT
Example
--------
mysql> select @@sql_mode;
+-----------------------------------------------------------------------------------+
| @@sql_mode |
+-----------------------------------------------------------------------------------+
| ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+-----------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> set sql_mode = sys.list_add(@@sql_mode, ''ANSI_QUOTES'');
Query OK, 0 rows affected (0.06 sec)
mysql> select @@sql_mode;
+-----------------------------------------------------------------------------------------------+
| @@sql_mode |
+-----------------------------------------------------------------------------------------------+
| ANSI_QUOTES,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+-----------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
'
SQL SECURITY INVOKER
DETERMINISTIC
CONTAINS SQL
BEGIN
IF (in_add_value IS NULL) THEN
SIGNAL SQLSTATE '02200'
SET MESSAGE_TEXT = 'Function sys.list_add: in_add_value input variable should not be NULL',
MYSQL_ERRNO = 1138;
END IF;
IF (in_list IS NULL OR LENGTH(in_list) = 0) THEN
-- return the new value as a single value list
RETURN in_add_value;
END IF;
RETURN (SELECT CONCAT(TRIM(BOTH ',' FROM TRIM(in_list)), ',', in_add_value));
END$$
DELIMITER ;
-- Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP FUNCTION IF EXISTS list_drop;
DELIMITER $$
CREATE DEFINER='root'@'localhost' FUNCTION list_drop (
in_list TEXT,
in_drop_value TEXT
)
RETURNS TEXT
COMMENT '
Description
-----------
Takes a list, and a value to attempt to remove from the list, and returns the resulting list.
Useful for altering certain session variables, like sql_mode or optimizer_switch for instance.
Parameters
-----------
in_list (TEXT):
The comma separated list to drop a value from
in_drop_value (TEXT):
The value to drop from the input list
Returns
-----------
TEXT
Example
--------
mysql> select @@sql_mode;
+-----------------------------------------------------------------------------------------------+
| @@sql_mode |
+-----------------------------------------------------------------------------------------------+
| ANSI_QUOTES,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+-----------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> set sql_mode = sys.list_drop(@@sql_mode, ''ONLY_FULL_GROUP_BY'');
Query OK, 0 rows affected (0.03 sec)
mysql> select @@sql_mode;
+----------------------------------------------------------------------------+
| @@sql_mode |
+----------------------------------------------------------------------------+
| ANSI_QUOTES,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+----------------------------------------------------------------------------+
1 row in set (0.00 sec)
'
SQL SECURITY INVOKER
DETERMINISTIC
CONTAINS SQL
BEGIN
IF (in_drop_value IS NULL) THEN
SIGNAL SQLSTATE '02200'
SET MESSAGE_TEXT = 'Function sys.list_drop: in_drop_value input variable should not be NULL',
MYSQL_ERRNO = 1138;
END IF;
IF (in_list IS NULL OR LENGTH(in_list) = 0) THEN
-- return the list as it was passed in
RETURN in_list;
END IF;
-- ensure that leading / trailing commas are remove, support values with either spaces or not between commas
RETURN (SELECT TRIM(BOTH ',' FROM REPLACE(REPLACE(CONCAT(',', in_list), CONCAT(',', in_drop_value), ''), CONCAT(', ', in_drop_value), '')));
END$$
DELIMITER ;
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP FUNCTION IF EXISTS ps_is_account_enabled;
DELIMITER $$
CREATE DEFINER='root'@'localhost' FUNCTION ps_is_account_enabled (
in_host VARCHAR(60),
in_user VARCHAR(16)
)
RETURNS ENUM('YES', 'NO')
COMMENT '
Description
-----------
Determines whether instrumentation of an account is enabled
within Performance Schema.
Parameters
-----------
in_host VARCHAR(60):
The hostname of the account to check.
in_user (VARCHAR(16)):
The username of the account to check.
Returns
-----------
ENUM(\'YES\', \'NO\', \'PARTIAL\')
Example
-----------
mysql> SELECT sys.ps_is_account_enabled(\'localhost\', \'root\');
+------------------------------------------------+
| sys.ps_is_account_enabled(\'localhost\', \'root\') |
+------------------------------------------------+
| YES |
+------------------------------------------------+
1 row in set (0.01 sec)
'
SQL SECURITY INVOKER
DETERMINISTIC
READS SQL DATA
BEGIN
RETURN IF(EXISTS(SELECT 1
FROM performance_schema.setup_actors
WHERE (`HOST` = '%' OR in_host LIKE `HOST`)
AND (`USER` = '%' OR `USER` = in_user)
),
'YES', 'NO'
);
END$$
DELIMITER ;
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP FUNCTION IF EXISTS ps_is_account_enabled;
DELIMITER $$
CREATE DEFINER='root'@'localhost' FUNCTION ps_is_account_enabled (
in_host VARCHAR(60),
in_user VARCHAR(32)
)
RETURNS ENUM('YES', 'NO')
COMMENT '
Description
-----------
Determines whether instrumentation of an account is enabled
within Performance Schema.
Parameters
-----------
in_host VARCHAR(60):
The hostname of the account to check.
in_user VARCHAR(32):
The username of the account to check.
Returns
-----------
ENUM(\'YES\', \'NO\', \'PARTIAL\')
Example
-----------
mysql> SELECT sys.ps_is_account_enabled(\'localhost\', \'root\');
+------------------------------------------------+
| sys.ps_is_account_enabled(\'localhost\', \'root\') |
+------------------------------------------------+
| YES |
+------------------------------------------------+
1 row in set (0.01 sec)
'
SQL SECURITY INVOKER
DETERMINISTIC
READS SQL DATA
BEGIN
RETURN IF(EXISTS(SELECT 1
FROM performance_schema.setup_actors
WHERE (`HOST` = '%' OR in_host LIKE `HOST`)
AND (`USER` = '%' OR `USER` = in_user)
AND (`ENABLED` = 'YES')
),
'YES', 'NO'
);
END$$
DELIMITER ;
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP FUNCTION IF EXISTS ps_is_consumer_enabled;
DELIMITER $$
CREATE DEFINER='root'@'localhost' FUNCTION ps_is_consumer_enabled (
in_consumer varchar(64)
)
RETURNS enum('YES', 'NO')
COMMENT '
Description
-----------
Determines whether a consumer is enabled (taking the consumer hierarchy into consideration)
within the Performance Schema.
Parameters
-----------
in_consumer VARCHAR(64):
The name of the consumer to check.
Returns
-----------
ENUM(\'YES\', \'NO\')
Example
-----------
mysql> SELECT sys.ps_is_consumer_enabled(\'events_stages_history\');
+-----------------------------------------------------+
| sys.ps_is_consumer_enabled(\'events_stages_history\') |
+-----------------------------------------------------+
| NO |
+-----------------------------------------------------+
1 row in set (0.00 sec)
'
SQL SECURITY INVOKER
DETERMINISTIC
READS SQL DATA
BEGIN
RETURN (
SELECT (CASE
WHEN c.NAME = 'global_instrumentation' THEN c.ENABLED
WHEN c.NAME = 'thread_instrumentation' THEN IF(cg.ENABLED = 'YES' AND c.ENABLED = 'YES', 'YES', 'NO')
WHEN c.NAME LIKE '%\_digest' THEN IF(cg.ENABLED = 'YES' AND 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 performance_schema.setup_consumers cg
INNER JOIN performance_schema.setup_consumers ct
WHERE cg.NAME = 'global_instrumentation'
AND ct.NAME = 'thread_instrumentation'
AND c.NAME = in_consumer
);
END$$
DELIMITER ;
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP FUNCTION IF EXISTS ps_is_instrument_default_enabled;
DELIMITER $$
CREATE DEFINER='root'@'localhost' FUNCTION ps_is_instrument_default_enabled (
in_instrument VARCHAR(128)
)
RETURNS ENUM('YES', 'NO')
COMMENT '
Description
-----------
Returns whether an instrument is enabled by default in this version of MySQL.
Parameters
-----------
in_instrument VARCHAR(128):
The instrument to check.
Returns
-----------
ENUM(\'YES\', \'NO\')
Example
-----------
mysql> SELECT sys.ps_is_instrument_default_enabled(\'statement/sql/select\');
+--------------------------------------------------------------+
| sys.ps_is_instrument_default_enabled(\'statement/sql/select\') |
+--------------------------------------------------------------+
| YES |
+--------------------------------------------------------------+
1 row in set (0.00 sec)
'
SQL SECURITY INVOKER
DETERMINISTIC
READS SQL DATA
BEGIN
DECLARE v_enabled ENUM('YES', 'NO');
-- Currently the same in all versions
SET v_enabled = IF(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$$
DELIMITER ;
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP FUNCTION IF EXISTS ps_is_instrument_default_timed;
DELIMITER $$
CREATE DEFINER='root'@'localhost' FUNCTION ps_is_instrument_default_timed (
in_instrument VARCHAR(128)
)
RETURNS ENUM('YES', 'NO')
COMMENT '
Description
-----------
Returns whether an instrument is timed by default in this version of MySQL.
Parameters
-----------
in_instrument VARCHAR(128):
The instrument to check.
Returns
-----------
ENUM(\'YES\', \'NO\')
Example
-----------
mysql> SELECT sys.ps_is_instrument_default_timed(\'statement/sql/select\');
+------------------------------------------------------------+
| sys.ps_is_instrument_default_timed(\'statement/sql/select\') |
+------------------------------------------------------------+
| YES |
+------------------------------------------------------------+
1 row in set (0.00 sec)
'
SQL SECURITY INVOKER
DETERMINISTIC
READS SQL DATA
BEGIN
DECLARE v_timed ENUM('YES', 'NO');
-- Currently the same in all versions
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 ('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_timed;
END$$
DELIMITER ;
-- Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP FUNCTION IF EXISTS ps_is_thread_instrumented;
DELIMITER $$
CREATE DEFINER='root'@'localhost' FUNCTION ps_is_thread_instrumented (
in_connection_id BIGINT UNSIGNED
) RETURNS ENUM('YES', 'NO', 'UNKNOWN')
COMMENT '
Description
-----------
Checks whether the provided connection id is instrumented within Performance Schema.
Parameters
-----------
in_connection_id (BIGINT UNSIGNED):
The id of the connection to check.
Returns
-----------
ENUM(\'YES\', \'NO\', \'UNKNOWN\')
Example
-----------
mysql> SELECT sys.ps_is_thread_instrumented(CONNECTION_ID());
+------------------------------------------------+
| sys.ps_is_thread_instrumented(CONNECTION_ID()) |
+------------------------------------------------+
| YES |
+------------------------------------------------+
'
SQL SECURITY INVOKER
NOT DETERMINISTIC
READS SQL DATA
BEGIN
DECLARE v_enabled ENUM('YES', 'NO', 'UNKNOWN');
IF (in_connection_id IS NULL) THEN
RETURN NULL;
END IF;
SELECT INSTRUMENTED 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$$
DELIMITER ;
-- Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP FUNCTION IF EXISTS ps_thread_account;
DELIMITER $$
CREATE DEFINER='root'@'localhost' FUNCTION ps_thread_account (
in_thread_id BIGINT UNSIGNED
) RETURNS TEXT
COMMENT '
Description
-----------
Return the user@host account for the given Performance Schema thread id.
Parameters
-----------
in_thread_id (BIGINT UNSIGNED):
The id of the thread to return the account for.
Example
-----------
mysql> select thread_id, processlist_user, processlist_host from performance_schema.threads where type = ''foreground'';
+-----------+------------------+------------------+
| thread_id | processlist_user | processlist_host |
+-----------+------------------+------------------+
| 23 | NULL | NULL |
| 30 | root | localhost |
| 31 | msandbox | localhost |
| 32 | msandbox | localhost |
+-----------+------------------+------------------+
4 rows in set (0.00 sec)
mysql> select sys.ps_thread_account(31);
+---------------------------+
| sys.ps_thread_account(31) |
+---------------------------+
| msandbox@localhost |
+---------------------------+
1 row in set (0.00 sec)
'
SQL SECURITY INVOKER
NOT DETERMINISTIC
READS SQL DATA
BEGIN
RETURN (SELECT IF(
type = 'FOREGROUND',
CONCAT(processlist_user, '@', processlist_host),
type
) AS account
FROM `performance_schema`.`threads`
WHERE thread_id = in_thread_id);
END$$
DELIMITER ;
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP FUNCTION IF EXISTS ps_thread_id;
DELIMITER $$
CREATE DEFINER='root'@'localhost' FUNCTION ps_thread_id (
in_connection_id BIGINT UNSIGNED
) RETURNS BIGINT UNSIGNED
COMMENT '
Description
-----------
Return the Performance Schema THREAD_ID for the specified connection ID.
Parameters
-----------
in_connection_id (BIGINT UNSIGNED):
The id of the connection to return the thread id for. If NULL, the current
connection thread id is returned.
Example
-----------
mysql> SELECT sys.ps_thread_id(79);
+----------------------+
| sys.ps_thread_id(79) |
+----------------------+
| 98 |
+----------------------+
1 row in set (0.00 sec)
mysql> SELECT sys.ps_thread_id(CONNECTION_ID());
+-----------------------------------+
| sys.ps_thread_id(CONNECTION_ID()) |
+-----------------------------------+
| 98 |
+-----------------------------------+
1 row in set (0.00 sec)
'
SQL SECURITY INVOKER
NOT DETERMINISTIC
READS SQL DATA
BEGIN
RETURN (SELECT THREAD_ID
FROM `performance_schema`.`threads`
WHERE PROCESSLIST_ID = IFNULL(in_connection_id, CONNECTION_ID())
);
END$$
DELIMITER ;
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP FUNCTION IF EXISTS ps_thread_stack;
DELIMITER $$
CREATE DEFINER='root'@'localhost' FUNCTION ps_thread_stack (
thd_id BIGINT UNSIGNED,
debug BOOLEAN
)
RETURNS LONGTEXT CHARSET latin1
COMMENT '
Description
-----------
Outputs a JSON formatted stack of all statements, stages and events
within Performance Schema for the specified thread.
Parameters
-----------
thd_id (BIGINT UNSIGNED):
The id of the thread to trace. This should match the thread_id
column from the performance_schema.threads table.
in_verbose (BOOLEAN):
Include file:lineno information in the events.
Example
-----------
(line separation added for output)
mysql> SELECT sys.ps_thread_stack(37, FALSE) AS thread_stack\\G
*************************** 1. row ***************************
thread_stack: {"rankdir": "LR","nodesep": "0.10","stack_created": "2014-02-19 13:39:03",
"mysql_version": "5.7.3-m13","mysql_user": "root@localhost","events":
[{"nesting_event_id": "0", "event_id": "10", "timer_wait": 256.35, "event_info":
"sql/select", "wait_info": "select @@version_comment limit 1\\nerrors: 0\\nwarnings: 0\\nlock time:
...
'
SQL SECURITY INVOKER
NOT DETERMINISTIC
READS SQL DATA
BEGIN
DECLARE json_objects LONGTEXT;
/*!50602
-- Do not track the current thread, it will kill the stack
UPDATE performance_schema.threads
SET instrumented = 'NO'
WHERE processlist_id = CONNECTION_ID();
*/
SET SESSION group_concat_max_len=@@global.max_allowed_packet;
-- Select the entire stack of events
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, '"')
-- Convert from picoseconds to microseconds
, 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
, '"'
)
-- Always dump the extra wait information gathered for statements
, CONCAT( '"wait_info": "', IFNULL(wait_info, ''), '"')
-- If debug is enabled, add the file:lineno information for waits
, CONCAT( '"source": "', IF(true AND event_name LIKE 'wait%', IFNULL(wait_info, ''), ''), '"')
-- Depending on the type of event, name it appropriately
, CASE
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/socket"'
WHEN event_name LIKE 'wait/synch/mutex%' THEN '"event_type": "synch/mutex"'
WHEN event_name LIKE 'wait/synch/cond%' THEN '"event_type": "synch/cond"'
WHEN event_name LIKE 'wait/synch/rwlock%' THEN '"event_type": "synch/rwlock"'
WHEN event_name LIKE 'wait/lock%' THEN '"event_type": "lock"'
WHEN event_name LIKE 'statement/%' 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 all statements, with the extra tracing information available
(SELECT thread_id, event_id, event_name, timer_wait, timer_start, nesting_event_id,
CONCAT(sql_text, '\\n',
'errors: ', errors, '\\n',
'warnings: ', warnings, '\\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 tables: ', 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 range 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 performance_schema.events_statements_history_long WHERE thread_id = thd_id)
UNION
-- Select all stages
(SELECT thread_id, event_id, event_name, timer_wait, timer_start, nesting_event_id, null AS wait_info
FROM performance_schema.events_stages_history_long WHERE thread_id = thd_id)
UNION */
-- Select all events, adding information appropriate to the event
(SELECT thread_id, event_id,
CONCAT(event_name ,
IF(event_name NOT LIKE 'wait/synch/mutex%', IFNULL(CONCAT(' - ', operation), ''), ''),
IF(number_of_bytes IS NOT 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%',
-- Print the socket if used, else the IP:port as reported
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_schema.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_version": "', VERSION(), '"'),
CONCAT('"mysql_user": "', CURRENT_USER(), '"'),
CONCAT('"events": [', IFNULL(json_objects,''), ']')
),
'}');
END$$
DELIMITER ;
This diff is collapsed.
-- Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP FUNCTION IF EXISTS quote_identifier;
DELIMITER $$
-- https://dev.mysql.com/doc/refman/5.7/en/identifiers.html
-- Maximum supported length for any of the current identifiers in 5.7.5+ is 256 characters.
-- Before that, user variables could have any length.
--
-- Based on Paul Dubois' suggestion in Bug #78823/Bug #22011361.
CREATE DEFINER='root'@'localhost' FUNCTION quote_identifier(in_identifier TEXT)
RETURNS TEXT CHARSET UTF8
COMMENT '
Description
-----------
Takes an unquoted identifier (schema name, table name, etc.) and
returns the identifier quoted with backticks.
Parameters
-----------
in_identifier (TEXT):
The identifier to quote.
Returns
-----------
TEXT
Example
-----------
mysql> SELECT sys.quote_identifier(''my_identifier'') AS Identifier;
+-----------------+
| Identifier |
+-----------------+
| `my_identifier` |
+-----------------+
1 row in set (0.00 sec)
mysql> SELECT sys.quote_identifier(''my`idenfier'') AS Identifier;
+----------------+
| Identifier |
+----------------+
| `my``idenfier` |
+----------------+
1 row in set (0.00 sec)
'
SQL SECURITY INVOKER
DETERMINISTIC
NO SQL
BEGIN
RETURN CONCAT('`', REPLACE(in_identifier, '`', '``'), '`');
END$$
DELIMITER ;
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP FUNCTION IF EXISTS sys_get_config;
DELIMITER $$
CREATE DEFINER='root'@'localhost' FUNCTION sys_get_config (
in_variable_name VARCHAR(128),
in_default_value VARCHAR(128)
)
RETURNS VARCHAR(128)
COMMENT '
Description
-----------
Returns the value for the requested variable using the following logic:
1. If the option exists in sys.sys_config return the value from there.
2. Else fall back on the provided default value.
Notes for using sys_get_config():
* If the default value argument to sys_get_config() is NULL and case 2. is reached, NULL is returned.
It is then expected that the caller is able to handle NULL for the given configuration option.
* The convention is to name the user variables @sys.<name of variable>. It is <name of variable> that
is stored in the sys_config table and is what is expected as the argument to sys_get_config().
* If you want to check whether the configuration option has already been set and if not assign with
the return value of sys_get_config() you can use IFNULL(...) (see example below). However this should
not be done inside a loop (e.g. for each row in a result set) as for repeated calls where assignment
is only needed in the first iteration using IFNULL(...) is expected to be significantly slower than
using an IF (...) THEN ... END IF; block (see example below).
Parameters
-----------
in_variable_name (VARCHAR(128)):
The name of the config option to return the value for.
in_default_value (VARCHAR(128)):
The default value to return if the variable does not exist in sys.sys_config.
Returns
-----------
VARCHAR(128)
Example
-----------
-- Get the configuration value from sys.sys_config falling back on 128 if the option is not present in the table.
mysql> SELECT sys.sys_get_config(''statement_truncate_len'', 128) AS Value;
+-------+
| Value |
+-------+
| 64 |
+-------+
1 row in set (0.00 sec)
-- Check whether the option is already set, if not assign - IFNULL(...) one liner example.
mysql> SET @sys.statement_truncate_len = IFNULL(@sys.statement_truncate_len, sys.sys_get_config(''statement_truncate_len'', 64));
Query OK, 0 rows affected (0.00 sec)
-- Check whether the option is already set, if not assign - IF ... THEN ... END IF example.
IF (@sys.statement_truncate_len IS NULL) THEN
SET @sys.statement_truncate_len = sys.sys_get_config(''statement_truncate_len'', 64);
END IF;
'
SQL SECURITY INVOKER
DETERMINISTIC
READS SQL DATA
BEGIN
DECLARE v_value VARCHAR(128) DEFAULT NULL;
-- Check if we have the variable in the sys.sys_config table
SET v_value = (SELECT value FROM sys.sys_config WHERE variable = in_variable_name);
-- Protection against the variable not existing in sys_config
IF (v_value IS NULL) THEN
SET v_value = in_default_value;
END IF;
RETURN v_value;
END $$
DELIMITER ;
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP FUNCTION IF EXISTS version_major;
DELIMITER $$
CREATE DEFINER='root'@'localhost' FUNCTION version_major ()
RETURNS TINYINT UNSIGNED
COMMENT '
Description
-----------
Returns the major version of MySQL Server.
Returns
-----------
TINYINT UNSIGNED
Example
-----------
mysql> SELECT VERSION(), sys.version_major();
+--------------------------------------+---------------------+
| VERSION() | sys.version_major() |
+--------------------------------------+---------------------+
| 5.7.9-enterprise-commercial-advanced | 5 |
+--------------------------------------+---------------------+
1 row in set (0.00 sec)
'
SQL SECURITY INVOKER
NOT DETERMINISTIC
NO SQL
BEGIN
RETURN SUBSTRING_INDEX(SUBSTRING_INDEX(VERSION(), '-', 1), '.', 1);
END$$
DELIMITER ;
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP FUNCTION IF EXISTS version_minor;
DELIMITER $$
CREATE DEFINER='root'@'localhost' FUNCTION version_minor ()
RETURNS TINYINT UNSIGNED
COMMENT '
Description
-----------
Returns the minor (release series) version of MySQL Server.
Returns
-----------
TINYINT UNSIGNED
Example
-----------
mysql> SELECT VERSION(), sys.server_minor();
+--------------------------------------+---------------------+
| VERSION() | sys.version_minor() |
+--------------------------------------+---------------------+
| 5.7.9-enterprise-commercial-advanced | 7 |
+--------------------------------------+---------------------+
1 row in set (0.00 sec)
'
SQL SECURITY INVOKER
NOT DETERMINISTIC
NO SQL
BEGIN
RETURN SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(VERSION(), '-', 1), '.', 2), '.', -1);
END$$
DELIMITER ;
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP FUNCTION IF EXISTS version_patch;
DELIMITER $$
CREATE DEFINER='root'@'localhost' FUNCTION version_patch ()
RETURNS TINYINT UNSIGNED
COMMENT '
Description
-----------
Returns the patch release version of MySQL Server.
Returns
-----------
TINYINT UNSIGNED
Example
-----------
mysql> SELECT VERSION(), sys.version_patch();
+--------------------------------------+---------------------+
| VERSION() | sys.version_patch() |
+--------------------------------------+---------------------+
| 5.7.9-enterprise-commercial-advanced | 9 |
+--------------------------------------+---------------------+
1 row in set (0.00 sec)
'
SQL SECURITY INVOKER
NOT DETERMINISTIC
NO SQL
BEGIN
RETURN SUBSTRING_INDEX(SUBSTRING_INDEX(VERSION(), '-', 1), '.', -1);
END$$
DELIMITER ;
#!/bin/bash
# Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
OS=`uname`
SYSDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
GENDIR=$SYSDIR/gen
PWD=$( pwd )
# Grab the current sys version
SYSVERSIONTMP=`cat views/version.sql | grep 'AS sys_version' | awk '{print $2}'`
SYSVERSION=`echo "${SYSVERSIONTMP//\'}"`
MYSQLUSER="'root'@'localhost'"
if [ $OS == "Darwin" ] ;
then
SED_R="sed -E"
else
SED_R="sed -r"
fi
USAGE="
Options:
================
v: The version of MySQL to build the sys schema for, either '56' or '57'
b: Whether to omit any lines that deal with sql_log_bin (useful for RDS)
m: Whether to generate a mysql_install_db / mysqld --initialize formatted file
u: The user to set as the owner of the objects (useful for RDS)
Examples:
================
Generate a MySQL 5.7 SQL file that uses the 'mark'@'localhost' user:
$0 -v 57 -u \"'mark'@'localhost'\"
Generate a MySQL 5.6 SQL file for RDS:
$0 -v 56 -b -u CURRENT_USER
Generate a MySQL 5.7 initialize / bootstrap file:
$0 -v 57 -m
"
# Grab options
while getopts ":v:bhmu:" opt; do
case $opt in
b)
SKIPBINLOG=true
;;
h)
echo $"$USAGE"
exit 0
;;
m)
MYSQLCOMPAT=true
# Bundled mysql expects the mysql.sys user to be used
MYSQLUSER="'mysql.sys'@'localhost'"
;;
u)
if [ -z "$MYSQLCOMPAT" ] ;
then
MYSQLUSER="${OPTARG}"
fi
;;
v)
if [ $OPTARG == "56" ] || [ $OPTARG == "57" ] ;
then
MYSQLVERSION=$OPTARG
else
echo "Invalid -v option, please run again with either '-v 56' or '-v 57'"
exit 1
fi
;;
\?)
echo "Invalid option: -$OPTARG" >&2
echo $"$USAGE"
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
echo $"$USAGE"
exit 1
;;
esac
done
# Check required options
if [[ -z "$MYSQLVERSION" ]] ;
then
echo " -v (MySQL Version) parameter required, please run again with either '-v 56' or '-v 57'"
echo $"$USAGE"
exit 1
fi
# Create the gen directory
if [[ ! -d $GENDIR ]] ;
then
mkdir $GENDIR
fi
# Create output file name
if [[ ! -z "$MYSQLCOMPAT" ]] ;
then
OUTPUTFILE="mysql_sys_schema.sql"
else
OUTPUTFILE="sys_${SYSVERSION}_${MYSQLVERSION}_inline.sql"
fi
# Create the initial output file
if [[ ! -z "$MYSQLCOMPAT" ]] ;
then
# Pre-process all the files in a copied temp directory
if [[ ! -d $GENDIR/tmpgen ]] ;
then
mkdir $GENDIR/tmpgen
fi
cd $GENDIR/tmpgen
rm -rf *
cp -r $SYSDIR/after_setup.sql $SYSDIR/tables $SYSDIR/triggers $SYSDIR/functions $SYSDIR/views $SYSDIR/procedures .
# Switch user if requested
# Remove individual copyrights
# Replace newlines in COMMENTs with literal \n
# Drop added trailing \n <sad panda>
# Remove DELIMITER commands
# Replace $$ delimiter with ;
# Remove leading spaces
# Remove -- line comments *after removing leading spaces*
for file in `find . -name '*.sql'`; do
# The 5.6 MEM/WB integration should still use the root@localhost user
if [ ! $MYSQLVERSION == "56" ] ;
then
sed -i -e "s/'root'@'localhost'/$MYSQLUSER/g" $file
fi
sed -i -e "/Copyright/,/51 Franklin St/d" $file
sed -i -e "/^ *COMMENT/,/^ *'/{G;s/\n/\\\n/g;}" $file
sed -i -e "s/ '\\\n/ '/g" $file
sed -i -e "/^DELIMITER/d" $file
sed -i -e "s/\\$\\$/;/g" $file
sed -i -e "s/^ *//g" $file
sed -i -e "/^--/d" $file
done
# Start the output file from a non-removed copyright file
sed -e "s/^/-- /" $SYSDIR/LICENSE > $OUTPUTFILE
echo "" >> $OUTPUTFILE
echo "--" >> $OUTPUTFILE
echo "-- WARNING: THIS IS A GENERATED FILE, CHANGES NEED TO BE MADE ON THE UPSTREAM MYSQL-SYS REPOSITORY AS WELL" >> $OUTPUTFILE
echo "-- PLEASE SUBMIT A PULL REQUEST TO https://github.com/mysql/mysql-sys" >> $OUTPUTFILE
echo "--" >> $OUTPUTFILE
echo "" >> $OUTPUTFILE
# Add the expected user
# Note this currently only works with 5.7 mysql.user structure
if [ ! $MYSQLVERSION == "56" ] ;
then
echo "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','*THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE','N',CURRENT_TIMESTAMP,NULL,'Y');" >> $OUTPUTFILE
echo "" >> $OUTPUTFILE
echo "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');" >> $OUTPUTFILE
echo "" >> $OUTPUTFILE
echo "REPLACE INTO mysql.tables_priv VALUES ('localhost','sys','mysql.sys','sys_config','root@localhost', CURRENT_TIMESTAMP, 'Select', '');" >> $OUTPUTFILE
echo "" >> $OUTPUTFILE
echo "FLUSH PRIVILEGES;" >> $OUTPUTFILE
echo "" >> $OUTPUTFILE
fi
# Put in the contents of before_setup.sql, though don't collapse lines
sed -e "/sql_log_bin/d;s/'root'@'localhost'/$MYSQLUSER/g;/Copyright/,/51 Franklin St/d" $SYSDIR/before_setup.sql >> $OUTPUTFILE
# Add the rest of the files in install file order, removing new lines along the way
cat "$SYSDIR/sys_$MYSQLVERSION.sql" | tr -d '\r' | grep 'SOURCE' | grep -v before_setup | grep -v after_setup | $SED_R 's .{8} ' | sed 's/^/./' > "./sys_$MYSQLVERSION.sql"
while read file; do
# First try and get a DROP command
grep -E '(^DROP PROCEDURE|^DROP FUNCTION|^DROP TRIGGER)' $file >> $OUTPUTFILE
# And remove any that may exist (but keep DROP TEMPORARY TABLE)
sed -i -e "/^DROP PROCEDURE/d;/^DROP FUNCTION/d;/^DROP TRIGGER/d" $file
echo "" >> $OUTPUTFILE
# Then collapse the rest of the file
cat $file | tr '\n' ' ' >> $OUTPUTFILE
echo "" >> $OUTPUTFILE
echo "" >> $OUTPUTFILE
done < "./sys_$MYSQLVERSION.sql"
# Does essentially nothing right now, but may in future
sed -e "/Copyright/,/51 Franklin St/d;/sql_log_bin/d" $SYSDIR/after_setup.sql >> $OUTPUTFILE
# Remove final leading and trailing spaces
sed -i '' -e "s/^ *//g" $OUTPUTFILE
sed -i '' -e "s/[ \t]*$//g" $OUTPUTFILE
# Remove more than one empty line
sed -i '' -e "/^$/N;/^\n$/D" $OUTPUTFILE
mv $OUTPUTFILE $GENDIR/
cd $GENDIR/
rm -rf $GENDIR/tmpgen
else
sed -e "s/^/-- /" $SYSDIR/LICENSE > $GENDIR/$OUTPUTFILE
cat "$SYSDIR/sys_$MYSQLVERSION.sql" | tr -d '\r' | grep 'SOURCE' | $SED_R 's .{8} ' | sed "s/^/$(echo $SYSDIR | sed -e 's/[]\/$*.^|[]/\\&/g')/g" \
| xargs sed -e "/Copyright/,/51 Franklin St/d;s/'root'@'localhost'/$MYSQLUSER/g" >> $GENDIR/$OUTPUTFILE
fi
# Check if sql_log_bin lines should be removed
if [[ ! -z "$SKIPBINLOG" ]] ;
then
LOGWARNING="WARNING: Using a routine that could cause binary log events, but disabling of binary logging has been removed"
sed -i '' -e "s/^[ \s]*SET sql_log_bin = 0/SELECT \"$LOGWARNING\"/g" $GENDIR/$OUTPUTFILE
sed -i '' -e "s/\sSET sql_log_bin = @log_bin;/SET @log_bin = NULL;/g" $GENDIR/$OUTPUTFILE
SKIPBINLOG="disabled"
else
SKIPBINLOG="enabled"
fi
cd $PWD
# Print summary
echo $"
Wrote file: $GENDIR/$OUTPUTFILE
Object Definer: $MYSQLUSER
sql_log_bin: $SKIPBINLOG
"
-- Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP PROCEDURE IF EXISTS create_synonym_db;
DELIMITER $$
CREATE DEFINER='root'@'localhost' PROCEDURE create_synonym_db (
IN in_db_name VARCHAR(64),
IN in_synonym VARCHAR(64)
)
COMMENT '
Description
-----------
Takes a source database name and synonym name, and then creates the
synonym database with views that point to all of the tables within
the source database.
Useful for creating a "ps" synonym for "performance_schema",
or "is" instead of "information_schema", for example.
Parameters
-----------
in_db_name (VARCHAR(64)):
The database name that you would like to create a synonym for.
in_synonym (VARCHAR(64)):
The database synonym name.
Example
-----------
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test |
+--------------------+
5 rows in set (0.00 sec)
mysql> CALL sys.create_synonym_db(\'performance_schema\', \'ps\');
+---------------------------------------+
| summary |
+---------------------------------------+
| Created 74 views in the `ps` database |
+---------------------------------------+
1 row in set (8.57 sec)
Query OK, 0 rows affected (8.57 sec)
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| ps |
| sys |
| test |
+--------------------+
6 rows in set (0.00 sec)
mysql> SHOW FULL TABLES FROM ps;
+------------------------------------------------------+------------+
| Tables_in_ps | Table_type |
+------------------------------------------------------+------------+
| accounts | VIEW |
| cond_instances | VIEW |
| events_stages_current | VIEW |
| events_stages_history | VIEW |
...
'
SQL SECURITY INVOKER
NOT DETERMINISTIC
MODIFIES SQL DATA
BEGIN
DECLARE v_done bool DEFAULT FALSE;
DECLARE 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 'HY000';
DECLARE c_table_names CURSOR FOR
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = in_db_name;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = TRUE;
-- Check if the source database exists
SELECT SCHEMA_NAME INTO v_db_name_check
FROM INFORMATION_SCHEMA.SCHEMATA
WHERE SCHEMA_NAME = in_db_name;
IF v_db_name_check IS NULL THEN
SET v_db_err_msg = CONCAT('Unknown database ', in_db_name);
SIGNAL SQLSTATE 'HY000'
SET MESSAGE_TEXT = v_db_err_msg;
END IF;
-- Check if a database of the synonym name already exists
SELECT SCHEMA_NAME INTO v_db_name_check
FROM INFORMATION_SCHEMA.SCHEMATA
WHERE SCHEMA_NAME = in_synonym;
IF v_db_name_check = in_synonym 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;
-- All good, create the database and views
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;
SET v_done = FALSE;
OPEN c_table_names;
c_table_names: LOOP
FETCH c_table_names INTO v_table;
IF v_done THEN
LEAVE c_table_names;
END IF;
SET @create_view_stmt = CONCAT(
'CREATE SQL SECURITY INVOKER VIEW ',
sys.quote_identifier(in_synonym),
'.',
sys.quote_identifier(v_table),
' AS SELECT * FROM ',
sys.quote_identifier(in_db_name),
'.',
sys.quote_identifier(v_table)
);
PREPARE create_view_stmt FROM @create_view_stmt;
EXECUTE create_view_stmt;
DEALLOCATE PREPARE create_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), ' database'
) AS summary;
END$$
DELIMITER ;
This diff is collapsed.
-- Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP PROCEDURE IF EXISTS execute_prepared_stmt;
DELIMITER $$
CREATE DEFINER='root'@'localhost' PROCEDURE execute_prepared_stmt (
IN in_query longtext CHARACTER SET UTF8
)
COMMENT '
Description
-----------
Takes the query in the argument and executes it using a prepared statement. The prepared statement is deallocated,
so the procedure is mainly useful for executing one off dynamically created queries.
The sys_execute_prepared_stmt prepared statement name is used for the query and is required not to exist.
Parameters
-----------
in_query (longtext CHARACTER SET UTF8):
The query to execute.
Configuration Options
----------------------
sys.debug
Whether to provide debugging output.
Default is ''OFF''. Set to ''ON'' to include.
Example
--------
mysql> CALL sys.execute_prepared_stmt(''SELECT * FROM sys.sys_config'');
+------------------------+-------+---------------------+--------+
| variable | value | set_time | set_by |
+------------------------+-------+---------------------+--------+
| statement_truncate_len | 64 | 2015-06-30 13:06:00 | NULL |
+------------------------+-------+---------------------+--------+
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
'
SQL SECURITY INVOKER
NOT DETERMINISTIC
READS SQL DATA
BEGIN
-- Set configuration options
IF (@sys.debug IS NULL) THEN
SET @sys.debug = sys.sys_get_config('debug', 'OFF');
END IF;
-- Verify the query exists
-- The shortest possible query is "DO 1"
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 sys_execute_prepared_stmt FROM @sys.execute_prepared_stmt.sql;
EXECUTE sys_execute_prepared_stmt;
DEALLOCATE PREPARE sys_execute_prepared_stmt;
SET @sys.execute_prepared_stmt.sql = NULL;
END$$
DELIMITER ;
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP PROCEDURE IF EXISTS ps_setup_disable_background_threads;
DELIMITER $$
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_disable_background_threads ()
COMMENT '
Description
-----------
Disable all background thread instrumentation within Performance Schema.
Parameters
-----------
None.
Example
-----------
mysql> CALL sys.ps_setup_disable_background_threads();
+--------------------------------+
| summary |
+--------------------------------+
| Disabled 18 background threads |
+--------------------------------+
1 row in set (0.00 sec)
'
SQL SECURITY INVOKER
NOT DETERMINISTIC
MODIFIES SQL DATA
BEGIN
UPDATE performance_schema.threads
SET instrumented = 'NO'
WHERE type = 'BACKGROUND';
SELECT CONCAT('Disabled ', @rows := ROW_COUNT(), ' background thread', IF(@rows != 1, 's', '')) AS summary;
END$$
DELIMITER ;
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP PROCEDURE IF EXISTS ps_setup_disable_consumer;
DELIMITER $$
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_disable_consumer (
IN consumer VARCHAR(128)
)
COMMENT '
Description
-----------
Disables consumers within Performance Schema
matching the input pattern.
Parameters
-----------
consumer (VARCHAR(128)):
A LIKE pattern match (using "%consumer%") of consumers to disable
Example
-----------
To disable all consumers:
mysql> CALL sys.ps_setup_disable_consumer(\'\');
+--------------------------+
| summary |
+--------------------------+
| Disabled 15 consumers |
+--------------------------+
1 row in set (0.02 sec)
To disable just the event_stage consumers:
mysql> CALL sys.ps_setup_disable_comsumers(\'stage\');
+------------------------+
| summary |
+------------------------+
| Disabled 3 consumers |
+------------------------+
1 row in set (0.00 sec)
'
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$$
DELIMITER ;
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP PROCEDURE IF EXISTS ps_setup_disable_instrument;
DELIMITER $$
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_disable_instrument (
IN in_pattern VARCHAR(128)
)
COMMENT '
Description
-----------
Disables instruments within Performance Schema
matching the input pattern.
Parameters
-----------
in_pattern (VARCHAR(128)):
A LIKE pattern match (using "%in_pattern%") of events to disable
Example
-----------
To disable all mutex instruments:
mysql> CALL sys.ps_setup_disable_instrument(\'wait/synch/mutex\');
+--------------------------+
| summary |
+--------------------------+
| Disabled 155 instruments |
+--------------------------+
1 row in set (0.02 sec)
To disable just a specific TCP/IP based network IO instrument:
mysql> CALL sys.ps_setup_disable_instrument(\'wait/io/socket/sql/server_tcpip_socket\');
+------------------------+
| summary |
+------------------------+
| Disabled 1 instruments |
+------------------------+
1 row in set (0.00 sec)
To disable all instruments:
mysql> CALL sys.ps_setup_disable_instrument(\'\');
+--------------------------+
| summary |
+--------------------------+
| Disabled 547 instruments |
+--------------------------+
1 row in set (0.01 sec)
'
SQL SECURITY INVOKER
NOT DETERMINISTIC
MODIFIES 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 summary;
END$$
DELIMITER ;
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP PROCEDURE IF EXISTS ps_setup_disable_thread;
DELIMITER $$
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_disable_thread (
IN in_connection_id BIGINT
)
COMMENT '
Description
-----------
Disable the given connection/thread in Performance Schema.
Parameters
-----------
in_connection_id (BIGINT):
The connection ID (PROCESSLIST_ID from performance_schema.threads
or the ID shown within SHOW PROCESSLIST)
Example
-----------
mysql> CALL sys.ps_setup_disable_thread(3);
+-------------------+
| summary |
+-------------------+
| Disabled 1 thread |
+-------------------+
1 row in set (0.01 sec)
To disable the current connection:
mysql> CALL sys.ps_setup_disable_thread(CONNECTION_ID());
+-------------------+
| summary |
+-------------------+
| Disabled 1 thread |
+-------------------+
1 row in set (0.00 sec)
'
SQL SECURITY 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$$
DELIMITER ;
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP PROCEDURE IF EXISTS ps_setup_enable_background_threads;
DELIMITER $$
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_enable_background_threads ()
COMMENT '
Description
-----------
Enable all background thread instrumentation within Performance Schema.
Parameters
-----------
None.
Example
-----------
mysql> CALL sys.ps_setup_enable_background_threads();
+-------------------------------+
| summary |
+-------------------------------+
| Enabled 18 background threads |
+-------------------------------+
1 row in set (0.00 sec)
'
SQL SECURITY INVOKER
NOT DETERMINISTIC
MODIFIES SQL DATA
BEGIN
UPDATE performance_schema.threads
SET instrumented = 'YES'
WHERE type = 'BACKGROUND';
SELECT CONCAT('Enabled ', @rows := ROW_COUNT(), ' background thread', IF(@rows != 1, 's', '')) AS summary;
END$$
DELIMITER ;
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP PROCEDURE IF EXISTS ps_setup_enable_consumer;
DELIMITER $$
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_enable_consumer (
IN consumer VARCHAR(128)
)
COMMENT '
Description
-----------
Enables consumers within Performance Schema
matching the input pattern.
Parameters
-----------
consumer (VARCHAR(128)):
A LIKE pattern match (using "%consumer%") of consumers to enable
Example
-----------
To enable all consumers:
mysql> CALL sys.ps_setup_enable_consumer(\'\');
+-------------------------+
| summary |
+-------------------------+
| Enabled 10 consumers |
+-------------------------+
1 row in set (0.02 sec)
Query OK, 0 rows affected (0.02 sec)
To enable just "waits" consumers:
mysql> CALL sys.ps_setup_enable_consumer(\'waits\');
+-----------------------+
| summary |
+-----------------------+
| Enabled 3 consumers |
+-----------------------+
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
'
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(), ' consumer', IF(@rows != 1, 's', '')) AS summary;
END$$
DELIMITER ;
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP PROCEDURE IF EXISTS ps_setup_enable_instrument;
DELIMITER $$
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_enable_instrument (
IN in_pattern VARCHAR(128)
)
COMMENT '
Description
-----------
Enables instruments within Performance Schema
matching the input pattern.
Parameters
-----------
in_pattern (VARCHAR(128)):
A LIKE pattern match (using "%in_pattern%") of events to enable
Example
-----------
To enable all mutex instruments:
mysql> CALL sys.ps_setup_enable_instrument(\'wait/synch/mutex\');
+-------------------------+
| summary |
+-------------------------+
| Enabled 155 instruments |
+-------------------------+
1 row in set (0.02 sec)
Query OK, 0 rows affected (0.02 sec)
To enable just a specific TCP/IP based network IO instrument:
mysql> CALL sys.ps_setup_enable_instrument(\'wait/io/socket/sql/server_tcpip_socket\');
+-----------------------+
| summary |
+-----------------------+
| Enabled 1 instruments |
+-----------------------+
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
To enable all instruments:
mysql> CALL sys.ps_setup_enable_instrument(\'\');
+-------------------------+
| summary |
+-------------------------+
| Enabled 547 instruments |
+-------------------------+
1 row in set (0.01 sec)
Query OK, 0 rows affected (0.01 sec)
'
SQL SECURITY INVOKER
NOT DETERMINISTIC
MODIFIES SQL DATA
BEGIN
UPDATE performance_schema.setup_instruments
SET enabled = 'YES', timed = 'YES'
WHERE name LIKE CONCAT('%', in_pattern, '%');
SELECT CONCAT('Enabled ', @rows := ROW_COUNT(), ' instrument', IF(@rows != 1, 's', '')) AS summary;
END$$
DELIMITER ;
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP PROCEDURE IF EXISTS ps_setup_enable_thread;
DELIMITER $$
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_enable_thread (
IN in_connection_id BIGINT
)
COMMENT '
Description
-----------
Enable the given connection/thread in Performance Schema.
Parameters
-----------
in_connection_id (BIGINT):
The connection ID (PROCESSLIST_ID from performance_schema.threads
or the ID shown within SHOW PROCESSLIST)
Example
-----------
mysql> CALL sys.ps_setup_enable_thread(3);
+------------------+
| summary |
+------------------+
| Enabled 1 thread |
+------------------+
1 row in set (0.01 sec)
To enable the current connection:
mysql> CALL sys.ps_setup_enable_thread(CONNECTION_ID());
+------------------+
| summary |
+------------------+
| Enabled 1 thread |
+------------------+
1 row in set (0.00 sec)
'
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$$
DELIMITER ;
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
SET @@session.sql_mode = @old_sql_mode;
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-- Because of bug 11750980/bug 41686, set the sql_mode to ''
SET @old_sql_mode = @@session.sql_mode, @@session.sql_mode = '';
-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; version 2 of the License.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
DROP PROCEDURE IF EXISTS ps_setup_save;
DELIMITER $$
CREATE DEFINER='root'@'localhost' PROCEDURE ps_setup_save (
IN in_timeout INT
)
COMMENT '
Description
-----------
Saves the current configuration of Performance Schema,
so that you can alter the setup for debugging purposes,
but restore it to a previous state.
Use the companion procedure - ps_setup_reload_saved(), to
restore the saved config.
The named lock "sys.ps_setup_save" is taken before the
current configuration is saved. If the attempt to get the named
lock times out, an error occurs.
The lock is released after the settings have been restored by
calling ps_setup_reload_saved().
Requires the SUPER privilege for "SET sql_log_bin = 0;".
Parameters
-----------
in_timeout INT
The timeout in seconds used when trying to obtain the lock.
A negative timeout means infinite timeout.
Example
-----------
mysql> CALL sys.ps_setup_save(-1);
Query OK, 0 rows affected (0.08 sec)
mysql> UPDATE performance_schema.setup_instruments
-> SET enabled = \'YES\', timed = \'YES\';
Query OK, 547 rows affected (0.40 sec)
Rows matched: 784 Changed: 547 Warnings: 0
/* Run some tests that need more detailed instrumentation here */
mysql> CALL sys.ps_setup_reload_saved();
Query OK, 0 rows affected (0.32 sec)
'
SQL SECURITY INVOKER
NOT DETERMINISTIC
MODIFIES SQL DATA
BEGIN
DECLARE v_lock_result INT;
SET @log_bin := @@sql_log_bin;
SET sql_log_bin = 0;
SELECT GET_LOCK('sys.ps_setup_save', in_timeout) INTO v_lock_result;
IF v_lock_result THEN
DROP TEMPORARY TABLE IF EXISTS tmp_setup_actors;
DROP TEMPORARY TABLE IF EXISTS tmp_setup_consumers;
DROP TEMPORARY TABLE IF EXISTS tmp_setup_instruments;
DROP TEMPORARY TABLE IF EXISTS tmp_threads;
CREATE TEMPORARY TABLE tmp_setup_actors LIKE performance_schema.setup_actors;
CREATE TEMPORARY TABLE tmp_setup_consumers LIKE performance_schema.setup_consumers;
CREATE TEMPORARY TABLE tmp_setup_instruments LIKE performance_schema.setup_instruments;
CREATE TEMPORARY TABLE tmp_threads (THREAD_ID bigint unsigned NOT NULL PRIMARY KEY, INSTRUMENTED enum('YES','NO') NOT NULL);
INSERT 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_instruments;
INSERT INTO tmp_threads SELECT THREAD_ID, INSTRUMENTED FROM performance_schema.threads;
ELSE
SIGNAL SQLSTATE VALUE '90000'
SET MESSAGE_TEXT = 'Could not lock the sys.ps_setup_save user lock, another thread has a saved configuration';
END IF;
SET sql_log_bin = @log_bin;
END$$
DELIMITER ;
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment