(725,'DROP FUNCTION',38,'Syntax\n------\n\nDROP FUNCTION [IF EXISTS] f_name\n\nDescription\n-----------\n\nThe DROP FUNCTION statement is used to drop a stored function or a\nuser-defined function (UDF). That is, the specified routine is removed from\nthe server, along with all privileges specific to the function. You must have\nthe ALTER ROUTINE privilege for the routine in order to drop it. If the\nautomatic_sp_privileges server system variable is set, both the ALTER ROUTINE\nand EXECUTE privileges are granted automatically to the routine creator - see\nStored Routine Privileges.\n\nIF EXISTS\n---------\n\nThe IF EXISTS clause is a MySQL/MariaDB extension. It prevents an error from\noccurring if the function does not exist. A NOTE is produced that can be\nviewed with SHOW WARNINGS.\n\nFor dropping a user-defined functions (UDF), see DROP FUNCTION UDF.\n\nExamples\n--------\n\nDROP FUNCTION hello;\nQuery OK, 0 rows affected (0.042 sec)\n\nDROP FUNCTION hello;\nERROR 1305 (42000): FUNCTION test.hello does not exist\n\nDROP FUNCTION IF EXISTS hello;\nQuery OK, 0 rows affected, 1 warning (0.000 sec)\n\nSHOW WARNINGS;\n+-------+------+------------------------------------+\n| Level | Code | Message                            |\n+-------+------+------------------------------------+\n| Note  | 1305 | FUNCTION test.hello does not exist |\n+-------+------+------------------------------------+\n\nURL: https://mariadb.com/kb/en/drop-function/','','https://mariadb.com/kb/en/drop-function/'),
(722,'Invisible Columns',38,'MariaDB starting with 10.3.3\n----------------------------\nInvisible columns (sometimes also called hidden columns) first appeared in\nMariaDB 10.3.3.\n\nColumns can be given an INVISIBLE attribute in a CREATE TABLE or ALTER TABLE\nstatement. These columns will then not be listed in the results of a SELECT *\nstatement, nor do they need to be assigned a value in an INSERT statement,\nunless INSERT explicitly mentions them by name.\n\nSince SELECT * does not return the invisible columns, new tables or views\ncreated in this manner will have no trace of the invisible columns. If\nspecifically referenced in the SELECT statement, the columns will be brought\ninto the view/new table, but the INVISIBLE attribute will not.\n\nInvisible columns can be declared as NOT NULL, but then require a DEFAULT\nvalue.\n\nIt is not possible for all columns in a table to be invisible.\n\nExamples\n--------\n\nCREATE TABLE t (x INT INVISIBLE);\nERROR 1113 (42000): A table must have at least 1 column\n\nCREATE TABLE t (x INT, y INT INVISIBLE, z INT INVISIBLE NOT NULL);\nERROR 4106 (HY000): Invisible column `z` must have a default value\n\nCREATE TABLE t (x INT, y INT INVISIBLE, z INT INVISIBLE NOT NULL DEFAULT 4);\n\nINSERT INTO t VALUES (1),(2);\n\nINSERT INTO t (x,y) VALUES (3,33);\n\nSELECT * FROM t;\n+------+\n| x    |\n+------+\n|    1 |\n|    2 |\n|    3 |\n+------+\n\nSELECT x,y,z FROM t;\n+------+------+---+\n| x    | y    | z |\n+------+------+---+\n|    1 | NULL | 4 |\n|    2 | NULL | 4 |\n|    3 |   33 | 4 |\n+------+------+---+\n\nDESC t;\n+-------+---------+------+-----+---------+-----------+\n| Field | Type    | Null | Key | Default | Extra     |\n+-------+---------+------+-----+---------+-----------+\n| x     | int(11) | YES  |     | NULL    |           |\n| y     | int(11) | YES  |     | NULL    | INVISIBLE |\n| z     | int(11) | NO   |     | 4       | INVISIBLE |\n+-------+---------+------+-----+---------+-----------+\n\nALTER TABLE t MODIFY x INT INVISIBLE, MODIFY y INT, MODIFY z INT NOT NULL\nDEFAULT 4;\n\nDESC t;\n+-------+---------+------+-----+---------+-----------+\n| Field | Type    | Null | Key | Default | Extra     |\n+-------+---------+------+-----+---------+-----------+\n| x     | int(11) | YES  |     | NULL    | INVISIBLE |\n| y     | int(11) | YES  |     | NULL    |           |\n| z     | int(11) | NO   |     | 4       |           |\n+-------+---------+------+-----+---------+-----------+\n\nCreating a view from a table with hidden columns:\n\nCREATE VIEW v1 AS SELECT * FROM t;\n\nDESC v1;\n+-------+---------+------+-----+---------+-------+\n| Field | Type    | Null | Key | Default | Extra |\n+-------+---------+------+-----+---------+-------+\n| y     | int(11) | YES  |     | NULL    |       |\n| z     | int(11) | NO   |     | 4       |       |\n+-------+---------+------+-----+---------+-------+\n\nCREATE VIEW v2 AS SELECT x,y,z FROM t;\n\nDESC v2;\n+-------+---------+------+-----+---------+-------+\n| Field | Type    | Null | Key | Default | Extra |\n+-------+---------+------+-----+---------+-------+\n| x     | int(11) | YES  |     | NULL    |       |\n| y     | int(11) | YES  |     | NULL    |       |\n| z     | int(11) | NO   |     | 4       |       |\n+-------+---------+------+-----+---------+-------+\n\nAdding a Surrogate Primary Key:\n\ncreate table t1 (x bigint unsigned not null, y varchar(16), z text);\n\ninsert into t1 values (123, \'qq11\', \'ipsum\');\n\ninsert into t1 values (123, \'qq22\', \'lorem\');\n\nalter table t1 add pkid serial primary key invisible first;\n\ninsert into t1 values (123, \'qq33\', \'amet\');\n\nselect * from t1;\n+-----+------+-------+\n| x   | y    | z     |\n+-----+------+-------+\n| 123 | qq11 | ipsum |\n| 123 | qq22 | lorem |\n| 123 | qq33 | amet  |\n+-----+------+-------+\n\nselect pkid, z from t1;\n+------+-------+\n| pkid | z     |\n+------+-------+\n|    1 | ipsum |\n|    2 | lorem |\n|    3 | amet  |\n+------+-------+\n\nURL: https://mariadb.com/kb/en/invisible-columns/','','https://mariadb.com/kb/en/invisible-columns/'),
(726,'DROP INDEX',38,'Syntax\n------\n\nDROP INDEX [IF EXISTS] index_name ON tbl_name \n  [WAIT n |NOWAIT]\n\nDescription\n-----------\n\nDROP INDEX drops the index named index_name from the table tbl_name. This\nstatement is mapped to an ALTER TABLE statement to drop the index.\n\nIf another connection is using the table, a metadata lock is active, and this\nstatement will wait until the lock is released. This is also true for\nnon-transactional tables.\n\nSee ALTER TABLE.\n\nAnother shortcut, CREATE INDEX, allows the creation of an index.\n\nTo remove the primary key, `PRIMARY` must be specified as index_name. Note\nthat the quotes are necessary, because PRIMARY is a keyword.\n\nPrivileges\n----------\n\nExecuting the DROP INDEX statement requires the INDEX privilege for the table\nor the database.\n\nOnline DDL\n----------\n\nOnline DDL is used by default with InnoDB, when the drop index operation\nsupports it.\n\nSee InnoDB Online DDL Overview for more information on online DDL with InnoDB.\n\nDROP INDEX IF EXISTS ...\n------------------------\n\nIf the IF EXISTS clause is used, then MariaDB will return a warning instead of\nan error if the index does not exist.\n\nWAIT/NOWAIT\n-----------\n\nSets the lock wait timeout. See WAIT and NOWAIT.\n\nProgress Reporting\n------------------\n\nMariaDB provides progress reporting for DROP INDEX statement for clients that\nsupport the new progress reporting protocol. For example, if you were using\nthe mariadb client, then the progress report might look like this::\n\nURL: https://mariadb.com/kb/en/drop-index/','','https://mariadb.com/kb/en/drop-index/'),
(729,'DROP PROCEDURE',38,'Syntax\n------\n\nDROP PROCEDURE [IF EXISTS] sp_name\n\nDescription\n-----------\n\nThis statement is used to drop a stored procedure. That is, the specified\nroutine is removed from the server along with all privileges specific to the\nprocedure. You must have the ALTER ROUTINE privilege for the routine. If the\nautomatic_sp_privileges server system variable is set, that privilege and\nEXECUTE are granted automatically to the routine creator - see Stored Routine\nPrivileges.\n\nThe IF EXISTS clause is a MySQL/MariaDB extension. It prevents an error from\noccurring if the procedure or function does not exist. A NOTE is produced that\ncan be viewed with SHOW WARNINGS.\n\nWhile this statement takes effect immediately, threads which are executing a\nprocedure can continue execution.\n\nExamples\n--------\n\nDROP PROCEDURE simpleproc;\n\nIF EXISTS:\n\nDROP PROCEDURE simpleproc;\nERROR 1305 (42000): PROCEDURE test.simpleproc does not exist\n\nDROP PROCEDURE IF EXISTS simpleproc;\nQuery OK, 0 rows affected, 1 warning (0.00 sec)\n\nSHOW WARNINGS;\n+-------+------+------------------------------------------+\n| Level | Code | Message                                  |\n+-------+------+------------------------------------------+\n| Note  | 1305 | PROCEDURE test.simpleproc does not exist |\n+-------+------+------------------------------------------+\n\nURL: https://mariadb.com/kb/en/drop-procedure/','','https://mariadb.com/kb/en/drop-procedure/'),
(730,'DROP SERVER',38,'Syntax\n------\n\nDROP SERVER [ IF EXISTS ] server_name\n\nDescription\n-----------\n\nDrops the server definition for the server named server_name. The\ncorresponding row within the mysql.servers table will be deleted. This\nstatement requires the SUPER privilege or, from MariaDB 10.5.2, the FEDERATED\nADMIN privilege.\n\nDropping a server for a table does not affect any FederatedX, FEDERATED,\nConnect or Spider tables that used this connection information when they were\ncreated.\n\nDROP SERVER is not written to the binary log, irrespective of the binary log\nformat being used. From MariaDB 10.1.13, Galera replicates the CREATE SERVER,\nALTER SERVER and DROP SERVER statements.\n\nIF EXISTS\n---------\n\nIf the IF EXISTS clause is used, MariaDB will not return an error if the\nserver does not exist. Unlike all other statements, DROP SERVER IF EXISTS does\nnot issue a note if the server does not exist. See MDEV-9400.\n\nExamples\n--------\n\nDROP SERVER s;\n\nIF EXISTS:\n\nDROP SERVER s;\nERROR 1477 (HY000): The foreign server name you are trying to reference \n does not exist. Data source error:  s\n\nDROP SERVER IF EXISTS s;\nQuery OK, 0 rows affected (0.00 sec)\n\nURL: https://mariadb.com/kb/en/drop-server/','','https://mariadb.com/kb/en/drop-server/'),
(732,'DROP TRIGGER',38,'Syntax\n------\n\nDROP TRIGGER [IF EXISTS] [schema_name.]trigger_name\n\nDescription\n-----------\n\nThis statement drops a trigger. The schema (database) name is optional. If the\nschema is omitted, the trigger is dropped from the default schema. Its use\nrequires the TRIGGER privilege for the table associated with the trigger.\n\nUse IF EXISTS to prevent an error from occurring for a trigger that does not\nexist. A NOTE is generated for a non-existent trigger when using IF EXISTS.\nSee SHOW WARNINGS.\n\nNote: Triggers for a table are also dropped if you drop the table.\n\nAtomic DDL\n----------\n\nMariaDB starting with 10.6.1\n----------------------------\nMariaDB 10.6.1 supports Atomic DDL and DROP TRIGGER is atomic.\n\nExamples\n--------\n\nDROP TRIGGER test.example_trigger;\n\nUsing the IF EXISTS clause:\n\nDROP TRIGGER IF EXISTS test.example_trigger;\nQuery OK, 0 rows affected, 1 warning (0.01 sec)\n\nSHOW WARNINGS;\n+-------+------+------------------------+\n| Level | Code | Message                |\n+-------+------+------------------------+\n| Note  | 1360 | Trigger does not exist |\n+-------+------+------------------------+\n\nURL: https://mariadb.com/kb/en/drop-trigger/','','https://mariadb.com/kb/en/drop-trigger/'),
(733,'DROP VIEW',38,'Syntax\n------\n\nDROP VIEW [IF EXISTS]\n  view_name [, view_name] ...\n  [RESTRICT | CASCADE]\n\nDescription\n-----------\n\nDROP VIEW removes one or more views. You must have the DROP privilege for each\nview. If any of the views named in the argument list do not exist, MariaDB\nreturns an error indicating by name which non-existing views it was unable to\ndrop, but it also drops all of the views in the list that do exist.\n\nThe IF EXISTS clause prevents an error from occurring for views that don\'t\nexist. When this clause is given, a NOTE is generated for each non-existent\nview. See SHOW WARNINGS.\n\nRESTRICT and CASCADE, if given, are parsed and ignored.\n\nIt is possible to specify view names as db_name.view_name. This is useful to\ndelete views from multiple databases with one statement. See Identifier\nQualifiers for details.\n\nThe DROP privilege is required to use DROP TABLE on non-temporary tables. For\ntemporary tables, no privilege is required, because such tables are only\nvisible for the current session.\n\nIf a view references another view, it will be possible to drop the referenced\nview. However, the other view will reference a view which does not exist any\nmore. Thus, querying it will produce an error similar to the following:\n\nERROR 1356 (HY000): View \'db_name.view_name\' references invalid table(s) or \ncolumn(s) or function(s) or definer/invoker of view lack rights to use them\n\nThis problem is reported in the output of CHECK TABLE.\n\nNote that it is not necessary to use DROP VIEW to replace an existing view,\nbecause CREATE VIEW has an OR REPLACE clause.\n\nAtomic DDL\n----------\n\nMariaDB starting with 10.6.1\n----------------------------\nMariaDB 10.6.1 supports Atomic DDL and DROP VIEW for a singular view is\natomic. Dropping multiple views is crash-safe.\n\nExamples\n--------\n\nDROP VIEW v,v2;\n\nGiven views v and v2, but no view v3\n\nDROP VIEW v,v2,v3;\nERROR 1051 (42S02): Unknown table \'v3\'\n\nDROP VIEW IF EXISTS v,v2,v3;\nQuery OK, 0 rows affected, 1 warning (0.01 sec)\n\nSHOW WARNINGS;\n+-------+------+-------------------------+\n| Level | Code | Message                 |\n+-------+------+-------------------------+\n| Note  | 1051 | Unknown table \'test.v3\' |\n+-------+------+-------------------------+\n\nURL: https://mariadb.com/kb/en/drop-view/','','https://mariadb.com/kb/en/drop-view/'),
(734,'CONSTRAINT',38,'MariaDB supports the implementation of constraints at the table-level using\neither CREATE TABLE or ALTER TABLE statements. A table constraint restricts\nthe data you can add to the table. If you attempt to insert invalid data on a\ncolumn, MariaDB throws an error.\n\nSyntax\n------\n\n[CONSTRAINT [symbol]] constraint_expression\n\nconstraint_expression:\n | PRIMARY KEY [index_type] (index_col_name, ...) [index_option] ...\n | FOREIGN KEY [index_name] (index_col_name, ...)\n   REFERENCES tbl_name (index_col_name, ...)\n   [ON DELETE reference_option]\n   [ON UPDATE reference_option]\n | UNIQUE [INDEX|KEY] [index_name]\n   [index_type] (index_col_name, ...) [index_option] ...\n | CHECK (check_constraints)\n\nindex_type:\n USING {BTREE | HASH | RTREE}\n\nindex_col_name:\n col_name [(length)] [ASC | DESC]\n\nindex_option:\n | KEY_BLOCK_SIZE [=] value\n | index_type\n | WITH PARSER parser_name\n | COMMENT \'string\'\n | CLUSTERING={YES|NO}\n\nreference_option:\n RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT\n\nDescription\n-----------\n\nConstraints provide restrictions on the data you can add to a table. This\nallows you to enforce data integrity from MariaDB, rather than through\napplication logic. When a statement violates a constraint, MariaDB throws an\nerror.\n\nThere are four types of table constraints:\n\n+------------------------------------+---------------------------------------+\n| Constraint                         | Description                           |\n+------------------------------------+---------------------------------------+\n| PRIMARY KEY                        | Sets the column for referencing       |\n|                                    | rows.  Values must be unique and not  |\n|                                    | null.                                 |\n+------------------------------------+---------------------------------------+\n| FOREIGN KEY                        | Sets the column to reference the      |\n|                                    | primary key on another table.         |\n+------------------------------------+---------------------------------------+\n| UNIQUE                             | Requires values in column or columns  |\n|                                    | only occur once in the table.         |\n+------------------------------------+---------------------------------------+\n| CHECK                              | Checks whether the data meets the     |\n|                                    | given condition.                      |\n+------------------------------------+---------------------------------------+\n\nThe Information Schema TABLE_CONSTRAINTS Table contains information about\ntables that have constraints.\n\nFOREIGN KEY Constraints\n-----------------------\n\nInnoDB supports foreign key constraints. The syntax for a foreign key\nconstraint definition in InnoDB looks like this:\n\n[CONSTRAINT [symbol]] FOREIGN KEY\n  [index_name] (index_col_name, ...)\n  REFERENCES tbl_name (index_col_name,...)\n  [ON DELETE reference_option]\n  [ON UPDATE reference_option]\n\nreference_option:\n  RESTRICT | CASCADE | SET NULL | NO ACTION\n\nThe Information Schema REFERENTIAL_CONSTRAINTS table has more information\nabout foreign keys.\n\nCHECK Constraints\n-----------------\n\nConstraints are enforced. Before MariaDB 10.2.1 constraint expressions were\naccepted in the syntax but ignored.\n\nYou can define constraints in 2 different ways:\n\n* CHECK(expression) given as part of a column definition.\n* CONSTRAINT [constraint_name] CHECK (expression)\n\nBefore a row is inserted or updated, all constraints are evaluated in the\norder they are defined. If any constraint expression returns false, then the\nrow will not be inserted or updated. One can use most deterministic functions\nin a constraint, including UDFs.\n\nCREATE TABLE t1 (a INT CHECK (a>2), b INT CHECK (b>2), CONSTRAINT a_greater\nCHECK (a>b));\n\nIf you use the second format and you don\'t give a name to the constraint, then\nthe constraint will get an automatically generated name. This is done so that\nyou can later delete the constraint with ALTER TABLE DROP constraint_name.\n\nOne can disable all constraint expression checks by setting the\ncheck_constraint_checks variable to OFF. This is useful for example when\nloading a table that violates some constraints that you want to later find and\nfix in SQL.\n\nReplication\n-----------\n\nIn row-based replication, only the master checks constraints, and failed\nstatements will not be replicated. In statement-based replication, the slaves\nwill also check constraints. Constraints should therefore be identical, as\nwell as deterministic, in a replication environment.\n\nAuto_increment\n--------------\n\nauto_increment columns are not permitted in check constraints. Before MariaDB\n10.2.6, they were permitted, but would not work correctly. See MDEV-11117.\n\nExamples\n--------\n\nCREATE TABLE product (category INT NOT NULL, id INT NOT NULL,\n           price DECIMAL,\n           PRIMARY KEY(category, id)) ENGINE=INNODB;\nCREATE TABLE customer (id INT NOT NULL,\n           PRIMARY KEY (id)) ENGINE=INNODB;\nCREATE TABLE product_order (no INT NOT NULL AUTO_INCREMENT,\n              product_category INT NOT NULL,\n              product_id INT NOT NULL,\n              customer_id INT NOT NULL,\n              PRIMARY KEY(no),\n              INDEX (product_category, product_id),\n              FOREIGN KEY (product_category, product_id)\n               REFERENCES product(category, id)\n               ON UPDATE CASCADE ON DELETE RESTRICT,\n              INDEX (customer_id),\n              FOREIGN KEY (customer_id)\n               REFERENCES customer(id)) ENGINE=INNODB;\n\nThe following examples will work from MariaDB 10.2.1 onwards.\n\nNumeric constraints and comparisons:\n\nCREATE TABLE t1 (a INT CHECK (a>2), b INT CHECK (b>2), CONSTRAINT a_greater\nCHECK (a>b));\n\nINSERT INTO t1(a) VALUES (1);\nERROR 4022 (23000): CONSTRAINT `a` failed for `test`.`t1`\n\nINSERT INTO t1(a,b) VALUES (3,4);\nERROR 4022 (23000): CONSTRAINT `a_greater` failed for `test`.`t1`\n\nINSERT INTO t1(a,b) VALUES (4,3);\nQuery OK, 1 row affected (0.04 sec)\n\nDropping a constraint:\n\nALTER TABLE t1 DROP CONSTRAINT a_greater;\n\nAdding a constraint:\n\nALTER TABLE t1 ADD CONSTRAINT a_greater CHECK (a>b);\n\nDate comparisons and character length:\n\nCREATE TABLE t2 (name VARCHAR(30) CHECK (CHAR_LENGTH(name)>2), start_date\nDATE, \n end_date DATE CHECK (start_date IS NULL OR end_date IS NULL OR\nstart_date<end_date));\n\nINSERT INTO t2(name, start_date, end_date) VALUES(\'Ione\', \'2003-12-15\',\n\'2014-11-09\');\nQuery OK, 1 row affected (0.04 sec)\n\nINSERT INTO t2(name, start_date, end_date) VALUES(\'Io\', \'2003-12-15\',\n\'2014-11-09\');\nERROR 4022 (23000): CONSTRAINT `name` failed for `test`.`t2`\n\nINSERT INTO t2(name, start_date, end_date) VALUES(\'Ione\', NULL, \'2014-11-09\');\nQuery OK, 1 row affected (0.04 sec)\n\nINSERT INTO t2(name, start_date, end_date) VALUES(\'Ione\', \'2015-12-15\',\n\'2014-11-09\');\nERROR 4022 (23000): CONSTRAINT `end_date` failed for `test`.`t2`\n\nA misplaced parenthesis:\n\nCREATE TABLE t3 (name VARCHAR(30) CHECK (CHAR_LENGTH(name>2)), start_date\nDATE, \n end_date DATE CHECK (start_date IS NULL OR end_date IS NULL OR\nstart_date<end_date));\nQuery OK, 0 rows affected (0.32 sec)\n\nINSERT INTO t3(name, start_date, end_date) VALUES(\'Io\', \'2003-12-15\',\n\'2014-11-09\');\nQuery OK, 1 row affected, 1 warning (0.04 sec)\n\nSHOW WARNINGS;\n+---------+------+----------------------------------------+\n| Level   | Code | Message                                |\n+---------+------+----------------------------------------+\n| Warning | 1292 | Truncated incorrect DOUBLE value: \'Io\' |\n+---------+------+----------------------------------------+\n\nCompare the definition of table t2 to table t3. CHAR_LENGTH(name)>2 is very\ndifferent to CHAR_LENGTH(name>2) as the latter mistakenly performs a numeric\ncomparison on the name field, leading to unexpected results.\n\nURL: https://mariadb.com/kb/en/constraint/','','https://mariadb.com/kb/en/constraint/'),
(736,'Dynamic Columns from MariaDB 10',38,'MariaDB starting with 10.0.1\n----------------------------\nMariaDB 10.0.1 introduced the following improvements to the dynamic columns\nfeature.\n\nColumn Name Support\n-------------------\n\nIt is possible to refer to column by names. Names can be used everywhere where\nin MariaDB 5.3 one could use only strings:\n\n* Create a dynamic column blob:\n\nCOLUMN_CREATE(\'int_col\', 123 as int, \'double_col\', 3.14 as double,\n\'string_col\', \'text-data\' as char);\n\n* Set a column value:\n\nCOLUMN_ADD(dyncol_blob, \'intcol\', 1234);\n\n* Get a column value:\n\nCOLUMN_GET(dynstr, \'column1\' as char(10));\n\n* Check whether a column exists\n\nCOLUMN_EXISTS(dyncol_blob, \'column_name\');\n\nChanges in Behavior\n-------------------\n\n* Column list output now includes quoting:\n\nselect column_list(column_create(1, 22, 2, 23));\n+------------------------------------------+\n| column_list(column_create(1, 22, 2, 23)) |\n+------------------------------------------+\n| `1`,`2`                                  |\n+------------------------------------------+\nselect column_list(column_create(\'column1\', 22, \'column2\', 23)); \n+----------------------------------------------------------+\n| column_list(column_create(\'column1\', 22, \'column2\', 23)) |\n+----------------------------------------------------------+\n| `column1`,`column2`                                      |\n+----------------------------------------------------------+\n\n* Column name interpretation has been changed so that the string now is not\nconverted to a number. So some \"magic\" tricks will not work any more, for\nexample, \"1test\" and \"1\" now become different column names:\n\nselect column_list(column_add(column_create(\'1a\', 22), \'1b\', 23));\n+------------------------------------------------------------+\n| column_list(column_add(column_create(\'1a\', 22), \'1b\', 23)) |\n+------------------------------------------------------------+\n| `1a`,`1b`                                                  |\n+------------------------------------------------------------+\n\n* Old behavior:\n\nselect column_list(column_add(column_create(\'1a\', 22), \'1b\', 23));\n+------------------------------------------------------------+\n| column_list(column_add(column_create(\'1a\', 22), \'1b\', 23)) |\n+------------------------------------------------------------+\n| 1                                                          |\n+------------------------------------------------------------+\n\nNew Functions\n-------------\n\nThe following new functions have been added to dynamic columns in MariaDB 10\n\nCOLUMN_CHECK\n------------\n\nCOLUMN_CHECK is used to check a column\'s integrity. When it encounters an\nerror it does not return illegal format errors but returns false instead. It\nalso checks integrity more thoroughly and finds errors in the dynamic column\ninternal structures which might not be found by other functions.\n\nselect column_check(column_create(\'column1\', 22));\n+--------------------------------------------+\n| column_check(column_create(\'column1\', 22)) |\n+--------------------------------------------+\n|                                          1 |\n+--------------------------------------------+\nselect column_check(\'abracadabra\');\n+-----------------------------+\n| column_check(\'abracadabra\') |\n+-----------------------------+\n|                           0 |\n+-----------------------------+\n\nCOLUMN_JSON\n-----------\n\nCOLUMN_JSON converts all dynamic column record content to a JSON object.\n\nselect column_json(column_create(\'column1\', 1, \'column2\', \"two\"));\n+------------------------------------------------------------+\n| column_json(column_create(\'column1\', 1, \'column2\', \"two\")) |\n+------------------------------------------------------------+\n| {\"column1\":1,\"column2\":\"two\"}                              |\n+------------------------------------------------------------+\n\nOther Changes\n-------------\n\n* All API functions has prefix mariadb_dyncol_ (old prefix dynamic_column_ is\ndepricated\n* API changed to be able to work with the new format (*_named functions).\n* Removed \'delete\' function because deleting could be done by adding NULL\nvalue.\n* \'Time\' and \'datetime\' in the new format are stored without microseconds if\nthey are 0.\n* New function added to API (except that two which are representing SQL level\nfunctions):\n\'Unpack\' the dynamic columns content to an arrays of values and names.\n3 functions to get any column value as string, integer (long long) or floating\npoint (double).\n\n* New type of \"dynamic column\" row added on the API level (in SQL level output\nit is a string but if you use dynamic column functions to construct object it\nwill be added as dynamic column value) which allow to add dynamic columns\ninside dynamic columns. JSON function represent such recursive constructions\ncorrectly but limit depth of representation as current implementation limit\n(internally depth of dynamic columns embedding is not limited).\n\nInterface with Cassandra\n------------------------\n\nCassandraSE is no longer actively being developed and has been removed in\nMariaDB 10.6. See MDEV-23024.\n\nSome internal changes were added to dynamic columns to allow them to serve as\nan interface to Apache Cassandra dynamic columns. The Cassandra engine may\npack all columns which were not mentioned in the MariaDB interface table\ndefinition and even bring changes in the dynamic column contents back to the\ncassandra columns family (the table analog in cassandra).\n\nURL: https://mariadb.com/kb/en/dynamic-columns-from-mariadb-10/','','https://mariadb.com/kb/en/dynamic-columns-from-mariadb-10/'),
(737,'MERGE',38,'Description\n-----------\n\nThe MERGE storage engine, also known as the MRG_MyISAM engine, is a collection\nof identical MyISAM tables that can be used as one. \"Identical\" means that all\ntables have identical column and index information. You cannot merge MyISAM\ntables in which the columns are listed in a different order, do not have\nexactly the same columns, or have the indexes in different order. However, any\nor all of the MyISAM tables can be compressed with myisampack. Columns names\nand indexes names can be different, as long as data types and NULL/NOT NULL\nclauses are the same. Differences in table options such as AVG_ROW_LENGTH,\nMAX_ROWS, or PACK_KEYS do not matter.\n\nEach index in a MERGE table must match an index in underlying MyISAM tables,\nbut the opposite is not true. Also, a MERGE table cannot have a PRIMARY KEY or\nUNIQUE indexes, because it cannot enforce uniqueness over all underlying\ntables.\n\nThe following options are meaningful for MERGE tables:\n\n* UNION. This option specifies the list of the underlying MyISAM tables. The\nlist is enclosed between parentheses and separated with commas.\n* INSERT_METHOD. This options specifies whether, and how, INSERTs are allowed\nfor the table. Allowed values are: NO (INSERTs are not allowed), FIRST (new\nrows will be written into the first table specified in the UNION list), LAST\n(new rows will be written into the last table specified in the UNION list).\nThe default value is NO.\n\nIf you define a MERGE table with a definition which is different from the\nunderlying MyISAM tables, or one of the underlying tables is not MyISAM, the\nCREATE TABLE statement will not return any error. But any statement which\ninvolves the table will produce an error like the following:\n\nERROR 1168 (HY000): Unable to open underlying table which is differently\ndefined \n or of non-MyISAM type or doesn\'t exist\n\nA CHECK TABLE will show more information about the problem.\n\nThe error is also produced if the table is properly define, but an underlying\ntable\'s definition changes at some point in time.\n\nIf you try to insert a new row into a MERGE table with INSERT_METHOD=NO, you\nwill get an error like the following:\n\nERROR 1036 (HY000): Table \'tbl_name\' is read only\n\nIt is possible to build a MERGE table on MyISAM tables which have one or more\nvirtual columns. MERGE itself does not support virtual columns, thus such\ncolumns will be seen as regular columns. The data types and sizes will still\nneed to be identical, and they cannot be NOT NULL.\n\nExamples\n--------\n\nCREATE TABLE t1 (\n  a INT NOT NULL AUTO_INCREMENT PRIMARY KEY,\n  message CHAR(20)) ENGINE=MyISAM;\n\nCREATE TABLE t2 (\n  a INT NOT NULL AUTO_INCREMENT PRIMARY KEY,\n  message CHAR(20)) ENGINE=MyISAM;\n\nINSERT INTO t1 (message) VALUES (\'Testing\'),(\'table\'),(\'t1\');\n\nINSERT INTO t2 (message) VALUES (\'Testing\'),(\'table\'),(\'t2\');\n\nCREATE TABLE total (\n  a INT NOT NULL AUTO_INCREMENT,\n  message CHAR(20), INDEX(a))\n  ENGINE=MERGE UNION=(t1,t2) INSERT_METHOD=LAST;\n\nSELECT * FROM total;\n+---+---------+\n| a | message |\n+---+---------+\n| 1 | Testing |\n| 2 | table   |\n| 3 | t1      |\n| 1 | Testing |\n| 2 | table   |\n| 3 | t2      |\n+---+---------+\n\nIn the following example, we\'ll create three MyISAM tables, and then a MERGE\ntable on them. However, one of them uses a different data type for the column\nb, so a SELECT will produce an error:\n\nCREATE TABLE t1 (\n a INT,\n b INT\n) ENGINE = MyISAM;\n\nCREATE TABLE t2 (\n a INT,\n b INT\n) ENGINE = MyISAM;\n\nCREATE TABLE t3 (\n a INT,\n b TINYINT\n) ENGINE = MyISAM;\n\nCREATE TABLE t_mrg (\n a INT,\n b INT\n) ENGINE = MERGE,UNION=(t1,t2,t3);\n\nSELECT * FROM t_mrg;\nERROR 1168 (HY000): Unable to open underlying table which is differently\ndefined\n or of non-MyISAM type or doesn\'t exist\n\nTo find out what\'s wrong, we\'ll use a CHECK TABLE:\n\nCHECK TABLE t_mrg\\G\n*************************** 1. row ***************************\n Table: test.t_mrg\n   Op: check\nMsg_type: Error\nMsg_text: Table \'test.t3\' is differently defined or of non-MyISAM type or\ndoesn\'t exist\n*************************** 2. row ***************************\n Table: test.t_mrg\n   Op: check\nMsg_type: Error\nMsg_text: Unable to open underlying table which is differently defined or of\nnon-MyISAM type or doesn\'t exist\n*************************** 3. row ***************************\n Table: test.t_mrg\n   Op: check\nMsg_type: error\nMsg_text: Corrupt\n\nNow, we know that the problem is in t3\'s definition.\n\nURL: https://mariadb.com/kb/en/merge/','','https://mariadb.com/kb/en/merge/'),
(741,'DROP SEQUENCE',39,'Syntax\n------\n\nDROP [TEMPORARY] SEQUENCE [IF EXISTS] [/*COMMENT TO SAVE*/]\n  sequence_name [, sequence_name] ...\n\nDescription\n-----------\n\nDROP SEQUENCE removes one or more sequences created with CREATE SEQUENCE. You\nmust have the DROP privilege for each sequence. MariaDB returns an error\nindicating by name which non-existing tables it was unable to drop, but it\nalso drops all of the tables in the list that do exist.\n\nImportant: When a table is dropped, user privileges on the table are not\nautomatically dropped. See GRANT.\n\nIf another connection is using the sequence, a metadata lock is active, and\nthis statement will wait until the lock is released. This is also true for\nnon-transactional tables.\n\nFor each referenced sequence, DROP SEQUENCE drops a temporary sequence with\nthat name, if it exists. If it does not exist, and the TEMPORARY keyword is\nnot used, it drops a non-temporary sequence with the same name, if it exists.\nThe TEMPORARY keyword ensures that a non-temporary sequence will not\naccidentally be dropped.\n\nUse IF EXISTS to prevent an error from occurring for sequences that do not\nexist. A NOTE is generated for each non-existent sequence when using IF\nEXISTS. See SHOW WARNINGS.\n\nDROP SEQUENCE requires the DROP privilege.\n\nNotes\n-----\n\nDROP SEQUENCE only removes sequences, not tables. However, DROP TABLE can\nremove both sequences and tables.\n\nURL: https://mariadb.com/kb/en/drop-sequence/','','https://mariadb.com/kb/en/drop-sequence/'),
(739,'CREATE SEQUENCE',39,'Syntax\n------\n\nCREATE [OR REPLACE] [TEMPORARY] SEQUENCE [IF NOT EXISTS] sequence_name\n[ INCREMENT [ BY | = ] increment ]\n[ MINVALUE [=] minvalue | NO MINVALUE | NOMINVALUE ]\n[ MAXVALUE [=] maxvalue | NO MAXVALUE | NOMAXVALUE ]\n[ START [ WITH | = ] start ] \n[ CACHE [=] cache | NOCACHE ] [ CYCLE | NOCYCLE] \n[table_options]\nThe options for CREATE SEQUENCE can be given in any order, optionally followed\nby table_options.\n\ntable_options can be any of the normal table options in CREATE TABLE but the\nmost usable ones are ENGINE=... and COMMENT=.\n\nNOMAXVALUE and NOMINVALUE are there to allow one to create SEQUENCEs using the\nOracle syntax.\n\nDescription\n-----------\n\nCREATE SEQUENCE will create a sequence that generates new values when called\nwith NEXT VALUE FOR sequence_name. It\'s an alternative to AUTO INCREMENT when\none wants to have more control of how the numbers are generated. As the\nSEQUENCE caches values (up to CACHE) it can in some cases be much faster than\nAUTO INCREMENT. Another benefit is that one can access the last value\ngenerated by all used sequences, which solves one of the limitations with\nLAST_INSERT_ID().\n\nCREATE SEQUENCE requires the CREATE privilege.\n\nDROP SEQUENCE can be used to drop a sequence, and ALTER SEQUENCE to change it.\n\nArguments to Create\n-------------------\n\nThe following options may be used:\n\n+---------------+------------------------------+----------------------------+\n| Option        | Default value                | Description                |\n+---------------+------------------------------+----------------------------+\n| INCREMENT     | 1                            | Increment to use for       |\n|               |                              | values. May be negative.   |\n|               |                              | Setting an increment of 0  |\n|               |                              | causes the sequence to     |\n|               |                              | use the value of the       |\n|               |                              | auto_increment_increment   |\n|               |                              | system variable at the     |\n|               |                              | time of creation, which    |\n|               |                              | is always a positive       |\n|               |                              | number. (see MDEV-16035).  |\n+---------------+------------------------------+----------------------------+\n| MINVALUE      | 1 if INCREMENT > 0 and       | Minimum value for the      |\n|               | -9223372036854775807 if      | sequence                   |\n|               | INCREMENT < 0                |                            |\n+---------------+------------------------------+----------------------------+\n| MAXVALUE      | 9223372036854775806 if       | Max value for sequence     |\n|               | INCREMENT > 0 and -1 if      |                            |\n|               | INCREMENT < 0                |                            |\n+---------------+------------------------------+----------------------------+\n| START         | MINVALUE if INCREMENT > 0    | First value that the       |\n|               | and MAX_VALUE if INCREMENT<  | sequence will generate     |\n|               | 0                            |                            |\n+---------------+------------------------------+----------------------------+\n| CACHE         | 1000                         | Number of values that      |\n|               |                              | should be cached. 0 if no  |\n|               |                              | CACHE.  The underlying     |\n|               |                              | table will be updated      |\n|               |                              | first time a new sequence  |\n|               |                              | number is generated and    |\n|               |                              | each time the cache runs   |\n|               |                              | out.                       |\n+---------------+------------------------------+----------------------------+\n\nIf CYCLE is used then the sequence should start again from MINVALUE after it\nhas run out of values. Default value is NOCYCLE.\n\nConstraints on Create Arguments\n-------------------------------\n\nTo be able to create a legal sequence, the following must hold:\n\n* MAXVALUE >= start\n* MAXVALUE > MINVALUE\n* START >= MINVALUE\n* MAXVALUE <= 9223372036854775806  (LONGLONG_MAX-1)\n* MINVALUE >= -9223372036854775807 (LONGLONG_MIN+1)\n\nNote that sequences can\'t generate the maximum/minimum 64 bit number because\nof the constraint of MINVALUE and MAXVALUE.\n\nAtomic DDL\n----------\n\nMariaDB starting with 10.6.1\n----------------------------\nMariaDB 10.6.1 supports Atomic DDL and CREATE SEQUENCE is atomic.\n\nExamples\n--------\n\nCREATE SEQUENCE s START WITH 100 INCREMENT BY 10;\n\nCREATE SEQUENCE s2 START WITH -100 INCREMENT BY -10;\n\nThe following statement fails, as the increment conflicts with the defaults\n\nCREATE SEQUENCE s3 START WITH -100 INCREMENT BY 10;\nERROR 4082 (HY000): Sequence \'test.s3\' values are conflicting\n\nThe sequence can be created by specifying workable minimum and maximum values:\n\nCREATE SEQUENCE s3 START WITH -100 INCREMENT BY 10 MINVALUE=-100 MAXVALUE=1000;\n\nURL: https://mariadb.com/kb/en/create-sequence/','','https://mariadb.com/kb/en/create-sequence/'),
(740,'ALTER SEQUENCE',39,'Syntax\n------\n\nALTER SEQUENCE [IF EXISTS] sequence_name\n[ INCREMENT [ BY | = ] increment ]\n[ MINVALUE [=] minvalue | NO MINVALUE | NOMINVALUE ]\n[ MAXVALUE [=] maxvalue | NO MAXVALUE | NOMAXVALUE ]\n[ START [ WITH | = ] start ] [ CACHE [=] cache ] [ [ NO ] CYCLE ]\n[ RESTART [[WITH | =] restart]\n\nALTER SEQUENCE allows one to change any values for a SEQUENCE created with\nCREATE SEQUENCE.\n\nThe options for ALTER SEQUENCE can be given in any order.\n\nDescription\n-----------\n\nALTER SEQUENCE changes the parameters of an existing sequence generator. Any\nparameters not specifically set in the ALTER SEQUENCE command retain their\nprior settings.\n\nALTER SEQUENCE requires the ALTER privilege.\n\nArguments to ALTER SEQUENCE\n---------------------------\n\nThe following options may be used:\n\n+---------------+-------------------------------+---------------------------+\n| Option        | Default value                 | Description               |\n+---------------+-------------------------------+---------------------------+\n| INCREMENT     | 1                             | Increment to use for      |\n|               |                               | values. May be negative.  |\n+---------------+-------------------------------+---------------------------+\n| MINVALUE      | 1 if INCREMENT > 0 and        | Minimum value for the     |\n|               | -9223372036854775807 if       | sequence.                 |\n|               | INCREMENT < 0                 |                           |\n+---------------+-------------------------------+---------------------------+\n| MAXVALUE      | 9223372036854775806 if        | Max value for sequence.   |\n|               | INCREMENT > 0 and -1 if       |                           |\n|               | INCREMENT < 0                 |                           |\n+---------------+-------------------------------+---------------------------+\n| START         | MINVALUE if INCREMENT > 0     | First value that the      |\n|               | and MAX_VALUE if INCREMENT< 0 | sequence will generate.   |\n+---------------+-------------------------------+---------------------------+\n| CACHE         | 1000                          | Number of values that     |\n|               |                               | should be cached. 0 if    |\n|               |                               | no CACHE.  The            |\n|               |                               | underlying table will be  |\n|               |                               | updated first time a new  |\n|               |                               | sequence number is        |\n|               |                               | generated and each time   |\n|               |                               | the cache runs out.       |\n+---------------+-------------------------------+---------------------------+\n| CYCLE         | 0 (= NO CYCLE)                | 1 if the sequence should  |\n|               |                               | start again from          |\n|               |                               | MINVALUE# after it has    |\n|               |                               | run out of values.        |\n+---------------+-------------------------------+---------------------------+\n| RESTART       | START if restart value not    | If  RESTART option is     |\n|               | is given                      | used, NEXT VALUE will     |\n|               |                               | return the restart value. |\n+---------------+-------------------------------+---------------------------+\n\nThe optional clause RESTART [ WITH restart ] sets the next value for the\nsequence. This is equivalent to calling the SETVAL() function with the is_used\nargument as 0. The specified value will be returned by the next call of\nnextval. Using RESTART with no restart value is equivalent to supplying the\nstart value that was recorded by CREATE SEQUENCE or last set by ALTER SEQUENCE\nSTART WITH.\n\nALTER SEQUENCE will not allow you to change the sequence so that it\'s\ninconsistent. For example:\n\nCREATE SEQUENCE s1;\nALTER SEQUENCE s1 MINVALUE 10;\nERROR 4061 (HY000): Sequence \'test.t1\' values are conflicting\n\nALTER SEQUENCE s1 MINVALUE 10 RESTART 10;\nERROR 4061 (HY000): Sequence \'test.t1\' values are conflicting\n\nALTER SEQUENCE s1 MINVALUE 10 START 10 RESTART 10;\n\nINSERT\n------\n\nTo allow SEQUENCE objects to be backed up by old tools, like mariadb-dump, one\ncan use SELECT to read the current state of a SEQUENCE object and use an\nINSERT to update the SEQUENCE object. INSERT is only allowed if all fields are\nspecified:\n\nCREATE SEQUENCE s1;\nINSERT INTO s1 VALUES(1000,10,2000,1005,1,1000,0,0);\nSELECT * FROM s1;\n\n+------------+-----------+-----------+-------+-----------+-------+-------+-----\n-+\n| next_value | min_value | max_value | start | increment | cache | cycle |\nround |\n+------------+-----------+-----------+-------+-----------+-------+-------+-----\n-+\n|       1000 |        10 |      2000 |  1005 |         1 |  1000 |     0 |    \n0 |\n+------------+-----------+-----------+-------+-----------+-------+-------+-----\n-+\n\nSHOW CREATE SEQUENCE s1;\n+-------+----------------------------------------------------------------------\n---------------------------------------+\n| Table | Create Table                                                        \n                    |\n+-------+----------------------------------------------------------------------\n---------------------------------------+\n| s1    | CREATE SEQUENCE `s1` start with 1005 minvalue 10 maxvalue 2000\nincrement by 1 cache 1000 nocycle ENGINE=Aria |\n+-------+----------------------------------------------------------------------\n---------------------------------------+\n\nNotes\n-----\n\nALTER SEQUENCE will instantly affect all future SEQUENCE operations. This is\nin contrast to some other databases where the changes requested by ALTER\nSEQUENCE will not be seen until the sequence cache has run out.\n\nALTER SEQUENCE will take a full table lock of the sequence object during its\n(brief) operation. This ensures that ALTER SEQUENCE is replicated correctly.\nIf you only want to set the next sequence value to a higher value than\ncurrent, then you should use SETVAL() instead, as this is not blocking.\n\nIf you want to change storage engine, sequence comment or rename the sequence,\nyou can use ALTER TABLE for this.\n\nURL: https://mariadb.com/kb/en/alter-sequence/','','https://mariadb.com/kb/en/alter-sequence/'),
(742,'NEXT VALUE for sequence_name',39,'MariaDB starting with 10.3\n--------------------------\nSEQUENCEs were introduced in MariaDB 10.3\n\nSyntax\n------\n\nNEXT VALUE FOR sequence\n\nor\n\nNEXTVAL(sequence_name)\n\nor in Oracle mode (SQL_MODE=ORACLE)\n\nsequence_name.nextval\n\nNEXT VALUE FOR is ANSI SQL syntax while NEXTVAL() is PostgreSQL syntax.\n\nDescription\n-----------\n\nGenerate next value for a SEQUENCE.\n\n* You can greatly speed up NEXT VALUE by creating the sequence with the CACHE\noption. If not, every NEXT VALUE usage will cause changes in the stored\nSEQUENCE table.\n* When using NEXT VALUE the value will be reserved at once and will not be\nreused, except if the SEQUENCE was created with CYCLE. This means that when\nyou are using SEQUENCEs you have to expect gaps in the generated sequence\nnumbers.\n* If one updates the SEQUENCE with SETVAL() or ALTER SEQUENCE ... RESTART,\nNEXT VALUE FOR will notice this and start from the next requested value.\n* FLUSH TABLES will close the sequence and the next sequence number generated\nwill be according to what\'s stored in the SEQUENCE object. In effect, this\nwill discard the cached values.\n* A server restart (or closing the current connection) also causes a drop of\nall cached values. The cached sequence numbers are reserved only for the\ncurrent connection.\n* NEXT VALUE requires the INSERT privilege.\n\nMariaDB starting with 10.3.3\n----------------------------\n* You can also use NEXT VALUE FOR sequence for column DEFAULT.\n\nURL: https://mariadb.com/kb/en/next-value-for-sequence_name/','','https://mariadb.com/kb/en/next-value-for-sequence_name/'),
(743,'PREVIOUS VALUE FOR sequence_name',39,'MariaDB starting with 10.3\n--------------------------\nSEQUENCEs were introduced in MariaDB 10.3.\n\nSyntax\n------\n\nPREVIOUS VALUE FOR sequence_name\n\nor\n\nLASTVAL(sequence_name)\n\nor in Oracle mode (SQL_MODE=ORACLE)\n\nsequence_name.currval\n\nPREVIOUS VALUE FOR is IBM DB2 syntax while LASTVAL() is PostgreSQL syntax.\n\nDescription\n-----------\n\nGet last value in the current connection generated from a sequence.\n\n* If the sequence has not yet been used by the connection, PREVIOUS VALUE FOR\nreturns NULL (the same thing applies with a new connection which doesn\'t see a\nlast value for an existing sequence).\n* If a SEQUENCE has been dropped and re-created then it\'s treated as a new\nSEQUENCE and PREVIOUS VALUE FOR will return NULL.\n* FLUSH TABLES has no effect on PREVIOUS VALUE FOR.\n* Previous values for all used sequences are stored per connection until\nconnection ends.\n* PREVIOUS VALUE FOR requires the SELECT privilege.\n\nExample\n-------\n\nCREATE SEQUENCE s START WITH 100 INCREMENT BY 10;\n\nSELECT PREVIOUS VALUE FOR s;\n+----------------------+\n| PREVIOUS VALUE FOR s |\n+----------------------+\n|                 NULL |\n+----------------------+\n\n# The function works for sequences only, if the table is used an error is\ngenerated\nSELECT PREVIOUS VALUE FOR t;\nERROR 4089 (42S02): \'test.t\' is not a SEQUENCE\n\n# Call the NEXT VALUE FOR s:\nSELECT NEXT VALUE FOR s;\n+------------------+\n| NEXT VALUE FOR s |\n+------------------+\n|              100 |\n+------------------+\n\nSELECT PREVIOUS VALUE FOR s;\n+----------------------+\n| PREVIOUS VALUE FOR s |\n+----------------------+\n|                  100 |\n+----------------------+\n\nNow try to start the new connection and check that the last value is still\nNULL, before updating the value in the new connection after the output of the\nnew connection gets current value (110 in the example below). Note that first\nconnection cannot see this change and the result of last value still remains\nthe same (100 in the example above).\n\n$ .mysql -uroot test -e\"SELECT PREVIOUS VALUE FOR s; SELECT NEXT VALUE FOR s;\nSELECT PREVIOUS VALUE FOR s;\"\n+----------------------+\n| PREVIOUS VALUE FOR s |\n+----------------------+\n|                 NULL |\n+----------------------+\n+------------------+\n| NEXT VALUE FOR s |\n+------------------+\n|              110 |\n+------------------+\n+----------------------+\n| PREVIOUS VALUE FOR s |\n+----------------------+\n|                  110 |\n+----------------------+\n\nURL: https://mariadb.com/kb/en/previous-value-for-sequence_name/','','https://mariadb.com/kb/en/previous-value-for-sequence_name/'),
(745,'JSON_ARRAYAGG',40,'MariaDB starting with 10.5.0\n----------------------------\nJSON_ARRAYAGG was added in MariaDB 10.5.0.\n\nSyntax\n------\n\nJSON_ARRAYAGG(column_or_expression)\n\nDescription\n-----------\n\nJSON_ARRAYAGG returns a JSON array containing an element for each value in a\ngiven set of JSON or SQL values. It acts on a column or an expression that\nevaluates to a single value.\n\nReturns NULL in the case of an error, or if the result contains no rows.\n\nJSON_ARRAYAGG cannot currently be used as a window function.\n\nThe full syntax is as follows:\n\nJSON_ARRAYAGG([DISTINCT] expr [,expr ...]\n      [ORDER BY {unsigned_integer | col_name | expr}\n        [ASC | DESC] [,col_name ...]]\n      [LIMIT {[offset,] row_count | row_count OFFSET offset}])\n\nExamples\n--------\n\nCREATE TABLE t1 (a INT, b INT);\n\nINSERT INTO t1 VALUES (1, 1),(2, 1), (1, 1),(2, 1), (3, 2),(2, 2),(2, 2),(2,\n2);\n\nSELECT JSON_ARRAYAGG(a), JSON_ARRAYAGG(b) FROM t1;\n+-------------------+-------------------+\n| JSON_ARRAYAGG(a)  | JSON_ARRAYAGG(b)  |\n+-------------------+-------------------+\n| [1,2,1,2,3,2,2,2] | [1,1,1,1,2,2,2,2] |\n+-------------------+-------------------+\n\nSELECT JSON_ARRAYAGG(a), JSON_ARRAYAGG(b) FROM t1 GROUP BY b;\n+------------------+------------------+\n| JSON_ARRAYAGG(a) | JSON_ARRAYAGG(b) |\n+------------------+------------------+\n| [1,2,1,2]        | [1,1,1,1]        |\n| [3,2,2,2]        | [2,2,2,2]        |\n+------------------+------------------+\n\nURL: https://mariadb.com/kb/en/json_arrayagg/','','https://mariadb.com/kb/en/json_arrayagg/'),
(744,'SETVAL',39,'MariaDB starting with 10.3.1\n----------------------------\nSEQUENCEs were introduced in MariaDB 10.3.\n\nSyntax\n------\n\nSETVAL(sequence_name, next_value, [is_used, [round]])\n\nDescription\n-----------\n\nSet the next value to be returned for a SEQUENCE.\n\nThis function is compatible with PostgreSQL syntax, extended with the round\nargument.\n\nIf the is_used argument is not given or is 1 or true, then the next used value\nwill one after the given value. If is_used is 0 or false then the next\ngenerated value will be the given value.\n\nIf round is used then it will set the round value (or the internal cycle\ncount, starting at zero) for the sequence. If round is not used, it\'s assumed\nto be 0.\n\nnext_value must be an integer literal.\n\nFor SEQUENCE tables defined with CYCLE (see CREATE SEQUENCE) one should use\nboth next_value and round to define the next value. In this case the current\nsequence value is defined to be round, next_value.\n\nThe result returned by SETVAL() is next_value or NULL if the given next_value\nand round is smaller than the current value.\n\nSETVAL() will not set the SEQUENCE value to a something that is less than its\ncurrent value. This is needed to ensure that SETVAL() is replication safe. If\nyou want to set the SEQUENCE to a smaller number use ALTER SEQUENCE.\n\nIf CYCLE is used, first round and then next_value are compared to see if the\nvalue is bigger than the current value.\n\nInternally, in the MariaDB server, SETVAL() is used to inform slaves that a\nSEQUENCE has changed value. The slave may get SETVAL() statements out of\norder, but this is ok as only the biggest one will have an effect.\n\nSETVAL requires the INSERT privilege.\n\nExamples\n--------\n\nSELECT setval(foo, 42);           -- Next nextval will return 43\nSELECT setval(foo, 42, true);     -- Same as above\nSELECT setval(foo, 42, false);    -- Next nextval will return 42\n\nSETVAL setting higher and lower values on a sequence with an increment of 10:\n\nSELECT NEXTVAL(s);\n+------------+\n| NEXTVAL(s) |\n+------------+\n|         50 |\n+------------+\n\nSELECT SETVAL(s, 100);\n+----------------+\n| SETVAL(s, 100) |\n+----------------+\n|            100 |\n+----------------+\n\nSELECT NEXTVAL(s);\n+------------+\n| NEXTVAL(s) |\n+------------+\n|        110 |\n+------------+\n\nSELECT SETVAL(s, 50);\n+---------------+\n| SETVAL(s, 50) |\n+---------------+\n|          NULL |\n+---------------+\n\nSELECT NEXTVAL(s);\n+------------+\n| NEXTVAL(s) |\n+------------+\n|        120 |\n+------------+\n\nExample demonstrating round:\n\nCREATE OR REPLACE SEQUENCE s1\n START WITH 1\n MINVALUE 1\n MAXVALUE 99\n INCREMENT BY 1\n CACHE 20\n CYCLE;\n\nSELECT SETVAL(s1, 99, 1, 0);\n+----------------------+\n| SETVAL(s1, 99, 1, 0) |\n+----------------------+\n|                   99 |\n+----------------------+\n\nSELECT NEXTVAL(s1);\n+-------------+\n| NEXTVAL(s1) |\n+-------------+\n|           1 |\n+-------------+\n\nThe following statement returns NULL, as the given next_value and round is\nsmaller than the current value.\n\nSELECT SETVAL(s1, 99, 1, 0);\n+----------------------+\n| SETVAL(s1, 99, 1, 0) |\n+----------------------+\n|                 NULL |\n+----------------------+\n\nSELECT NEXTVAL(s1);\n+-------------+\n| NEXTVAL(s1) |\n+-------------+\n|           2 |\n+-------------+\n\nIncreasing the round from zero to 1 will allow next_value to be returned.\n\nSELECT SETVAL(s1, 99, 1, 1);\n+----------------------+\n| SETVAL(s1, 99, 1, 1) |\n+----------------------+\n|                   99 |\n+----------------------+\n\nSELECT NEXTVAL(s1);\n+-------------+\n| NEXTVAL(s1) |\n+-------------+\n|           1 |\n+-------------+\n\nURL: https://mariadb.com/kb/en/setval/','','https://mariadb.com/kb/en/setval/'),
(746,'JSON_OBJECTAGG',40,'MariaDB starting with 10.5.0\n----------------------------\nJSON_OBJECTAGG was added in MariaDB 10.5.0.\n\nSyntax\n------\n\nJSON_OBJECTAGG(key, value)\n\nDescription\n-----------\n\nJSON_OBJECTAGG returns a JSON object containing key-value pairs. It takes two\nexpressions that evaluate to a single value, or two column names, as\narguments, the first used as a key, and the second as a value.\n\nReturns NULL in the case of an error, or if the result contains no rows.\n\nJSON_OBJECTAGG cannot currently be used as a window function.\n\nExamples\n--------\n\nselect * from t1;\n+------+-------+\n| a    | b     |\n+------+-------+\n|    1 | Hello |\n|    1 | World |\n|    2 | This  |\n+------+-------+\n\nSELECT JSON_OBJECTAGG(a, b) FROM t1;\n+----------------------------------------+\n| JSON_OBJECTAGG(a, b)                   |\n+----------------------------------------+\n| {\"1\":\"Hello\", \"1\":\"World\", \"2\":\"This\"} |\n+----------------------------------------+\n\nURL: https://mariadb.com/kb/en/json_objectagg/','','https://mariadb.com/kb/en/json_objectagg/'),
(749,'JSON_ARRAY_APPEND',40,'Syntax\n------\n\nJSON_ARRAY_APPEND(json_doc, path, value[, path, value] ...)\n\nDescription\n-----------\n\nAppends values to the end of the specified arrays within a JSON document,\nreturning the result, or NULL if any of the arguments are NULL.\n\nEvaluation is performed from left to right, with the resulting document from\nthe previous pair becoming the new value against which the next pair is\nevaluated.\n\nIf the json_doc is not a valid JSON document, or if any of the paths are not\nvalid, or contain a * or ** wildcard, an error is returned.\n\nExamples\n--------\n\nSET @json = \'[1, 2, [3, 4]]\';\n\nSELECT JSON_ARRAY_APPEND(@json, \'$[0]\', 5)\n+-------------------------------------+\n| JSON_ARRAY_APPEND(@json, \'$[0]\', 5) |\n+-------------------------------------+\n| [[1, 5], 2, [3, 4]]                 |\n+-------------------------------------+\n\nSELECT JSON_ARRAY_APPEND(@json, \'$[1]\', 6);\n+-------------------------------------+\n| JSON_ARRAY_APPEND(@json, \'$[1]\', 6) |\n+-------------------------------------+\n| [1, [2, 6], [3, 4]]                 |\n+-------------------------------------+\n\nSELECT JSON_ARRAY_APPEND(@json, \'$[1]\', 6, \'$[2]\', 7);\n+------------------------------------------------+\n| JSON_ARRAY_APPEND(@json, \'$[1]\', 6, \'$[2]\', 7) |\n+------------------------------------------------+\n| [1, [2, 6], [3, 4, 7]]                         |\n+------------------------------------------------+\n\nSELECT JSON_ARRAY_APPEND(@json, \'$\', 5);\n+----------------------------------+\n| JSON_ARRAY_APPEND(@json, \'$\', 5) |\n+----------------------------------+\n| [1, 2, [3, 4], 5]                |\n+----------------------------------+\n\nSET @json = \'{\"A\": 1, \"B\": [2], \"C\": [3, 4]}\';\n\nSELECT JSON_ARRAY_APPEND(@json, \'$.B\', 5);\n+------------------------------------+\n| JSON_ARRAY_APPEND(@json, \'$.B\', 5) |\n+------------------------------------+\n| {\"A\": 1, \"B\": [2, 5], \"C\": [3, 4]} |\n+------------------------------------+\n\nURL: https://mariadb.com/kb/en/json_array_append/','','https://mariadb.com/kb/en/json_array_append/'),
(747,'JSONPath Expressions',40,'A number of JSON functions accept JSON Path expressions. MariaDB defines this\npath as follows:\n\nJSON Path Syntax\n----------------\n\npath : [\'lax\'] \'$\' [step]*\n\nThe path starts with an optional path mode. At the moment, MariaDB supports\nonly the \"lax\" mode, which is also the mode that is used when it is not\nexplicitly specified.\n\nThe $ symbol represents the context item. The search always starts from the\ncontext item; because of that, the path always starts with $.\n\nThen, it is followed by zero or more steps, which select element(s) in the\nJSON document. A step may be one of the following:\n\n* Object member selector\n* Array element selector\n* Wildcard selector\n\nObject Member Selector\n----------------------\n\nTo select member(s) in a JSON object, one can use one of the following:\n\n* .memberName selects the value of the member with name memberName.\n* .\"memberName\" - the same as above but allows one to select a member with a\nname that\'s not a valid identifier (that is, has space, dot, and/or other\ncharacters)\n* .* - selects the values of all members of the object.\n\nIf the current item is an array (instead of an object), nothing will be\nselected.\n\nArray Element Selector\n----------------------\n\nTo select elements of an array, one can use one of the following:\n\n* [N] selects element number N in the array. The elements are counted from\nzero.\n* [*] selects all elements in the array.\n\nIf the current item is an object (instead of an array), nothing will be\nselected.\n\nStarting from MariaDB server 10.9, JSON path also supports negative index in\narray, \'last\' keyword and range notation (\'to\' keyword) for accessing array\nelements. Negative index starts from -1.\n\n* [-N] selects n th element from end.\n* [last-N] selects n th element from the last element.\n* [M to N] selects range of elements starting from index M to N.\n\nExample:\n\nSET @json=\'{\n      \"A\": [0,\n         [1, 2, 3],\n         [4, 5, 6],\n         \"seven\",\n         0.8,\n         true,\n         false,\n         \"eleven\",\n         [12, [13, 14], {\"key1\":\"value1\"},[15]],\n         true],\n      \"B\": {\"C\": 1},\n      \"D\": 2\n     }\';\nSELECT JSON_EXTRACT(@json, \'$.A[-8][1]\');\n+--------------------------------------------------+\n| JSON_EXTRACT(@json, \'$.A[-8][1]\')                |\n+--------------------------------------------------+\n| 5                                                |\n+--------------------------------------------------+\n\nSELECT JSON_EXTRACT(@json, \'$.A[last-7][1]\');\n+-----------------------------------------------+\n| SELECT JSON_EXTRACT(@json, \'$.A[last-7][1]\'); |\n+-----------------------------------------------+\n| 5                                             |\n+-----------------------------------------------+\n\nSET @json= \'[\n      [1, {\"key1\": \"value1\"}, 3],\n      [false, 5, 6],\n      [7, 8, [9, {\"key2\": 2}, 11]],\n      [15, 1.34, [14], [\"string1\", [16, {\"key1\":[1,2,3,[4,5,6]]}, 18]]],\n      [19, 20],\n      21, 22\n      ]\';\n\nSELECT JSON_EXTRACT(@json, \'$[0 to 3][2]\');\n+-----------------------------------------------+\n| JSON_EXTRACT(@json, \'$[0 to 3][2]\')           |\n+-----------------------------------------------+\n| [3, 6, [9, {\"key2\": 2}, 11], [14]]            |\n+-----------------------------------------------+\n\nThis will produce output for first index of eighth from last element of a two\ndimensional array.\n\nNote: In range notation, when M > N ( when M,N are greater than or equal to 0)\nor (size of array - M or size of array - N when M, N are less than 0), then it\nis treated as an impossible range and NULL is returned.\n\nSET @json= \'[1, 2, 3, 4, 5]\';\nSELECT JSON_EXTRACT(@json, \'$[4 to 2]\');\n+-----------------------------------+\n| JSON_EXTRACT(@json, \'$[4 to 2]\')  |\n+-----------------------------------+\n| NULL                              |\n+-----------------------------------+\n\nWildcard\n--------\n\nThe wildcard step, **, recursively selects all child elements of the current\nelement. Both array elements and object members are selected.\n\nThe wildcard step must not be the last step in the JSONPath expression. It\nmust be followed by an array or object member selector step.\n\nFor example:\n\nselect json_extract(@json_doc, \'$**.price\');\n\nwill select all object members in the document that are named price, while\n\nselect json_extract(@json_doc, \'$**[2]\');\n\nwill select the second element in each of the arrays present in the document.\n\nCompatibility\n-------------\n\nMariaDB\'s JSONPath syntax supports a subset of JSON Path\'s definition in the\nSQL Standard. The most notable things not supported are the strict mode and\nfilters.\n\nMariaDB\'s JSONPath is close to MySQL\'s JSONPath. The wildcard step ( ** ) is a\nnon-standard extension that has the same meaning as in MySQL. The difference\nbetween MariaDB and MySQL\'s JSONPath is: MySQL doesn\'t allow one to specify\nthe mode explicitly (but uses lax mode implicitly).\n\nURL: https://mariadb.com/kb/en/jsonpath-expressions/','','https://mariadb.com/kb/en/jsonpath-expressions/'),
(750,'JSON_ARRAY_INSERT',40,'Syntax\n------\n\nJSON_ARRAY_INSERT(json_doc, path, value[, path, value] ...)\n\nDescription\n-----------\n\nInserts a value into a JSON document, returning the modified document, or NULL\nif any of the arguments are NULL.\n\nEvaluation is performed from left to right, with the resulting document from\nthe previous pair becoming the new value against which the next pair is\nevaluated.\n\nIf the json_doc is not a valid JSON document, or if any of the paths are not\nvalid, or contain a * or ** wildcard, an error is returned.\n\nExamples\n--------\n\nSET @json = \'[1, 2, [3, 4]]\';\n\nSELECT JSON_ARRAY_INSERT(@json, \'$[0]\', 5);\n+-------------------------------------+\n| JSON_ARRAY_INSERT(@json, \'$[0]\', 5) |\n+-------------------------------------+\n| [5, 1, 2, [3, 4]]                   |\n+-------------------------------------+\n\nSELECT JSON_ARRAY_INSERT(@json, \'$[1]\', 6);\n+-------------------------------------+\n| JSON_ARRAY_INSERT(@json, \'$[1]\', 6) |\n+-------------------------------------+\n| [1, 6, 2, [3, 4]]                   |\n+-------------------------------------+\n\nSELECT JSON_ARRAY_INSERT(@json, \'$[1]\', 6, \'$[2]\', 7);\n+------------------------------------------------+\n| JSON_ARRAY_INSERT(@json, \'$[1]\', 6, \'$[2]\', 7) |\n+------------------------------------------------+\n| [1, 6, 7, 2, [3, 4]]                           |\n+------------------------------------------------+\n\nURL: https://mariadb.com/kb/en/json_array_insert/','','https://mariadb.com/kb/en/json_array_insert/'),
(752,'JSON_CONTAINS',40,'Syntax\n------\n\nJSON_CONTAINS(json_doc, val[, path])\n\nDescription\n-----------\n\nReturns whether or not the specified value is found in the given JSON document\nor, optionally, at the specified path within the document. Returns 1 if it\ndoes, 0 if not and NULL if any of the arguments are null. An error occurs if\nthe document or path is not valid, or contains the * or ** wildcards.\n\nExamples\n--------\n\nSET @json = \'{\"A\": 0, \"B\": {\"C\": 1}, \"D\": 2}\';\n\nSELECT JSON_CONTAINS(@json, \'2\', \'$.A\');\n+----------------------------------+\n| JSON_CONTAINS(@json, \'2\', \'$.A\') |\n+----------------------------------+\n|                                0 |\n+----------------------------------+\n\nSELECT JSON_CONTAINS(@json, \'2\', \'$.D\');\n+----------------------------------+\n| JSON_CONTAINS(@json, \'2\', \'$.D\') |\n+----------------------------------+\n|                                1 |\n+----------------------------------+\n\nSELECT JSON_CONTAINS(@json, \'{\"C\": 1}\', \'$.A\');\n+-----------------------------------------+\n| JSON_CONTAINS(@json, \'{\"C\": 1}\', \'$.A\') |\n+-----------------------------------------+\n|                                       0 |\n+-----------------------------------------+\n\nSELECT JSON_CONTAINS(@json, \'{\"C\": 1}\', \'$.B\');\n+-----------------------------------------+\n| JSON_CONTAINS(@json, \'{\"C\": 1}\', \'$.B\') |\n+-----------------------------------------+\n|                                       1 |\n+-----------------------------------------+\n\nURL: https://mariadb.com/kb/en/json_contains/','','https://mariadb.com/kb/en/json_contains/'),
(753,'JSON_CONTAINS_PATH',40,'Syntax\n------\n\nJSON_CONTAINS_PATH(json_doc, return_arg, path[, path] ...)\n\nDescription\n-----------\n\nIndicates whether the given JSON document contains data at the specified path\nor paths. Returns 1 if it does, 0 if not and NULL if any of the arguments are\nnull.\n\nThe return_arg can be one or all:\n\n* one - Returns 1 if at least one path exists within the JSON document. \n* all - Returns 1 only if all paths exist within the JSON document.\n\nExamples\n--------\n\nSET @json = \'{\"A\": 1, \"B\": [2], \"C\": [3, 4]}\';\n\nSELECT JSON_CONTAINS_PATH(@json, \'one\', \'$.A\', \'$.D\');\n+------------------------------------------------+\n| JSON_CONTAINS_PATH(@json, \'one\', \'$.A\', \'$.D\') |\n+------------------------------------------------+\n|                                              1 |\n+------------------------------------------------+\n1 row in set (0.00 sec)\n\nSELECT JSON_CONTAINS_PATH(@json, \'all\', \'$.A\', \'$.D\');\n+------------------------------------------------+\n| JSON_CONTAINS_PATH(@json, \'all\', \'$.A\', \'$.D\') |\n+------------------------------------------------+\n|                                              0 |\n+------------------------------------------------+\n\nURL: https://mariadb.com/kb/en/json_contains_path/','','https://mariadb.com/kb/en/json_contains_path/'),
(754,'JSON_DEPTH',40,'Syntax\n------\n\nJSON_DEPTH(json_doc)\n\nDescription\n-----------\n\nReturns the maximum depth of the given JSON document, or NULL if the argument\nis null. An error will occur if the argument is an invalid JSON document.\n\n* Scalar values or empty arrays or objects have a depth of 1.\n* Arrays or objects that are not empty but contain only elements or member\nvalues of depth 1 will have a depth of 2.\n* In other cases, the depth will be greater than 2.\n\nExamples\n--------\n\nSELECT JSON_DEPTH(\'[]\'), JSON_DEPTH(\'true\'), JSON_DEPTH(\'{}\');\n+------------------+--------------------+------------------+\n| JSON_DEPTH(\'[]\') | JSON_DEPTH(\'true\') | JSON_DEPTH(\'{}\') |\n+------------------+--------------------+------------------+\n|                1 |                  1 |                1 |\n+------------------+--------------------+------------------+\n\nSELECT JSON_DEPTH(\'[1, 2, 3]\'), JSON_DEPTH(\'[[], {}, []]\');\n+-------------------------+----------------------------+\n| JSON_DEPTH(\'[1, 2, 3]\') | JSON_DEPTH(\'[[], {}, []]\') |\n+-------------------------+----------------------------+\n|                       2 |                          2 |\n+-------------------------+----------------------------+\n\nSELECT JSON_DEPTH(\'[1, 2, [3, 4, 5, 6], 7]\');\n+---------------------------------------+\n| JSON_DEPTH(\'[1, 2, [3, 4, 5, 6], 7]\') |\n+---------------------------------------+\n|                                     3 |\n+---------------------------------------+\n\nURL: https://mariadb.com/kb/en/json_depth/','','https://mariadb.com/kb/en/json_depth/'),
(755,'JSON_DETAILED',40,'Syntax\n------\n\nJSON_DETAILED(json_doc[, tab_size])\nJSON_PRETTY(json_doc[, tab_size])\n\nDescription\n-----------\n\nRepresents JSON in the most understandable way emphasizing nested structures.\n\nJSON_PRETTY was added as an alias for JSON_DETAILED in MariaDB 10.10.3,\nMariaDB 10.9.5, MariaDB 10.8.7, MariaDB 10.7.8, MariaDB 10.6.12, MariaDB\n10.5.19 and MariaDB 10.4.28.\n\nExample\n-------\n\nSET @j = \'{ \"A\":1,\"B\":[2,3]}\';\n\nSELECT @j;\n+--------------------+\n| @j                 |\n+--------------------+\n| { \"A\":1,\"B\":[2,3]} |\n+--------------------+\n\nSELECT JSON_DETAILED(@j);\n+------------------------------------------------------------+\n| JSON_DETAILED(@j)                                          |\n+------------------------------------------------------------+\n| {\n  \"A\": 1,\n  \"B\":\n  [\n    2,\n    3\n  ]\n} |\n+------------------------------------------------------------+\n\nURL: https://mariadb.com/kb/en/json_detailed/','','https://mariadb.com/kb/en/json_detailed/'),
(756,'JSON_EQUALS',40,'MariaDB starting with 10.7.0\n----------------------------\nJSON_EQUALS was added in MariaDB 10.7.0\n\nSyntax\n------\n\nJSON_EQUALS(json1, json2)\n\nDescription\n-----------\n\nChecks if there is equality between two json objects. Returns 1 if it there\nis, 0 if not, or NULL if any of the arguments are null.\n\nExamples\n--------\n\nSELECT JSON_EQUALS(\'{\"a\"   :[1, 2, 3],\"b\":[4]}\', \'{\"b\":[4],\"a\":[1, 2, 3.0]}\');\n+------------------------------------------------------------------------+\n| JSON_EQUALS(\'{\"a\"   :[1, 2, 3],\"b\":[4]}\', \'{\"b\":[4],\"a\":[1, 2, 3.0]}\') |\n+------------------------------------------------------------------------+\n|                                                                      1 |\n+------------------------------------------------------------------------+\n\nSELECT JSON_EQUALS(\'{\"a\":[1, 2, 3]}\', \'{\"a\":[1, 2, 3.01]}\');\n+------------------------------------------------------+\n| JSON_EQUALS(\'{\"a\":[1, 2, 3]}\', \'{\"a\":[1, 2, 3.01]}\') |\n+------------------------------------------------------+\n|                                                    0 |\n+------------------------------------------------------+\n\nURL: https://mariadb.com/kb/en/json_equals/','','https://mariadb.com/kb/en/json_equals/'),
(757,'JSON_EXISTS',40,'Syntax\n------\n\nDescription\n-----------\n\nDetermines whether a specified JSON value exists in the given data. Returns 1\nif found, 0 if not, or NULL if any of the inputs were NULL.\n\nExamples\n--------\n\nSELECT JSON_EXISTS(\'{\"key1\":\"xxxx\", \"key2\":[1, 2, 3]}\', \"$.key2\");\n+------------------------------------------------------------+\n| JSON_EXISTS(\'{\"key1\":\"xxxx\", \"key2\":[1, 2, 3]}\', \"$.key2\") |\n+------------------------------------------------------------+\n|                                                          1 |\n+------------------------------------------------------------+\n\nSELECT JSON_EXISTS(\'{\"key1\":\"xxxx\", \"key2\":[1, 2, 3]}\', \"$.key3\");\n+------------------------------------------------------------+\n| JSON_EXISTS(\'{\"key1\":\"xxxx\", \"key2\":[1, 2, 3]}\', \"$.key3\") |\n+------------------------------------------------------------+\n|                                                          0 |\n+------------------------------------------------------------+\n\nSELECT JSON_EXISTS(\'{\"key1\":\"xxxx\", \"key2\":[1, 2, 3]}\', \"$.key2[1]\");\n+---------------------------------------------------------------+\n| JSON_EXISTS(\'{\"key1\":\"xxxx\", \"key2\":[1, 2, 3]}\', \"$.key2[1]\") |\n+---------------------------------------------------------------+\n|                                                             1 |\n+---------------------------------------------------------------+\n\nSELECT JSON_EXISTS(\'{\"key1\":\"xxxx\", \"key2\":[1, 2, 3]}\', \"$.key2[10]\");\n+----------------------------------------------------------------+\n| JSON_EXISTS(\'{\"key1\":\"xxxx\", \"key2\":[1, 2, 3]}\', \"$.key2[10]\") |\n+----------------------------------------------------------------+\n|                                                              0 |\n+----------------------------------------------------------------+\n\nURL: https://mariadb.com/kb/en/json_exists/','','https://mariadb.com/kb/en/json_exists/'),
(758,'JSON_EXTRACT',40,'Syntax\n------\n\nJSON_EXTRACT(json_doc, path[, path] ...)\n\nDescription\n-----------\n\nExtracts data from a JSON document. The extracted data is selected from the\nparts matching the path arguments. Returns all matched values; either as a\nsingle matched value, or, if the arguments could return multiple values, a\nresult autowrapped as an array in the matching order.\n\nReturns NULL if no paths match or if any of the arguments are NULL.\n\nAn error will occur if any path argument is not a valid path, or if the\njson_doc argument is not a valid JSON document.\n\nThe path expression be a JSONPath expression as supported by MariaDB\n\nExamples\n--------\n\nSET @json = \'[1, 2, [3, 4]]\';\n\nSELECT JSON_EXTRACT(@json, \'$[1]\');\n+-----------------------------+\n| JSON_EXTRACT(@json, \'$[1]\') |\n+-----------------------------+\n| 2                           |\n+-----------------------------+\n\nSELECT JSON_EXTRACT(@json, \'$[2]\');\n+-----------------------------+\n| JSON_EXTRACT(@json, \'$[2]\') |\n+-----------------------------+\n| [3, 4]                      |\n+-----------------------------+\n\nSELECT JSON_EXTRACT(@json, \'$[2][1]\');\n+--------------------------------+\n| JSON_EXTRACT(@json, \'$[2][1]\') |\n+--------------------------------+\n| 4                              |\n+--------------------------------+\n\nURL: https://mariadb.com/kb/en/json_extract/','','https://mariadb.com/kb/en/json_extract/'),
(759,'JSON_INSERT',40,'Syntax\n------\n\nJSON_INSERT(json_doc, path, val[, path, val] ...)\n\nDescription\n-----------\n\nInserts data into a JSON document, returning the resulting document or NULL if\neither of the json_doc or path arguments are null.\n\nAn error will occur if the JSON document is invalid, or if any of the paths\nare invalid or contain a * or ** wildcard.\n\nJSON_INSERT can only insert data while JSON_REPLACE can only update. JSON_SET\ncan update or insert data.\n\nExamples\n--------\n\nSET @json = \'{ \"A\": 0, \"B\": [1, 2]}\';\n\nSELECT JSON_INSERT(@json, \'$.C\', \'[3, 4]\');\n+--------------------------------------+\n| JSON_INSERT(@json, \'$.C\', \'[3, 4]\')  |\n+--------------------------------------+\n| { \"A\": 0, \"B\": [1, 2], \"C\":\"[3, 4]\"} |\n+--------------------------------------+\n\nURL: https://mariadb.com/kb/en/json_insert/','','https://mariadb.com/kb/en/json_insert/'),
(760,'JSON_KEYS',40,'Syntax\n------\n\nJSON_KEYS(json_doc[, path])\n\nDescription\n-----------\n\nReturns the keys as a JSON array from the top-level value of a JSON object or,\nif the optional path argument is provided, the top-level keys from the path.\n\nExcludes keys from nested sub-objects in the top level value. The resulting\narray will be empty if the selected object is empty.\n\nReturns NULL if any of the arguments are null, a given path does not locate an\nobject, or if the json_doc argument is not an object.\n\nAn error will occur if JSON document is invalid, the path is invalid or if the\npath contains a * or ** wildcard.\n\nExamples\n--------\n\nSELECT JSON_KEYS(\'{\"A\": 1, \"B\": {\"C\": 2}}\');\n+--------------------------------------+\n| JSON_KEYS(\'{\"A\": 1, \"B\": {\"C\": 2}}\') |\n+--------------------------------------+\n| [\"A\", \"B\"]                           |\n+--------------------------------------+\n\nSELECT JSON_KEYS(\'{\"A\": 1, \"B\": 2, \"C\": {\"D\": 3}}\', \'$.C\');\n+-----------------------------------------------------+\n| JSON_KEYS(\'{\"A\": 1, \"B\": 2, \"C\": {\"D\": 3}}\', \'$.C\') |\n+-----------------------------------------------------+\n| [\"D\"]                                               |\n+-----------------------------------------------------+\n\nURL: https://mariadb.com/kb/en/json_keys/','','https://mariadb.com/kb/en/json_keys/'),
(761,'JSON_LENGTH',40,'Syntax\n------\n\nJSON_LENGTH(json_doc[, path])\n\nDescription\n-----------\n\nReturns the length of a JSON document, or, if the optional path argument is\ngiven, the length of the value within the document specified by the path.\n\nReturns NULL if any of the arguments argument are null or the path argument\ndoes not identify a value in the document.\n\nAn error will occur if the JSON document is invalid, the path is invalid or if\nthe path contains a * or ** wildcard.\n\nLength will be determined as follow:\n\n* A scalar\'s length is always 1.\n* If an array, the number of elements in the array.\n* If an object, the number of members in the object.\n\nThe length of nested arrays or objects are not counted.\n\nExamples\n--------\n\nURL: https://mariadb.com/kb/en/json_length/','','https://mariadb.com/kb/en/json_length/'),
(764,'JSON_MERGE_PATCH',40,'MariaDB starting with 10.3.16\n-----------------------------\nJSON_MERGE_PATCH was introduced in MariaDB 10.3.16 and MariaDB 10.4.5.\n\nSyntax\n------\n\nJSON_MERGE_PATCH(json_doc, json_doc[, json_doc] ...)\n\nDescription\n-----------\n\nMerges the given JSON documents, returning the merged result, or NULL if any\nargument is NULL.\n\nJSON_MERGE_PATCH is an RFC 7396-compliant replacement for JSON_MERGE, which\nhas been deprecated.\n\nExample\n-------\n\nSET @json1 = \'[1, 2]\';\nSET @json2 = \'[2, 3]\';\nSELECT JSON_MERGE_PATCH(@json1,@json2),JSON_MERGE_PRESERVE(@json1,@json2);\n+---------------------------------+------------------------------------+\n| JSON_MERGE_PATCH(@json1,@json2) | JSON_MERGE_PRESERVE(@json1,@json2) |\n+---------------------------------+------------------------------------+\n| [2, 3]                          | [1, 2, 2, 3]                       |\n+---------------------------------+------------------------------------+\n\nURL: https://mariadb.com/kb/en/json_merge_patch/','','https://mariadb.com/kb/en/json_merge_patch/'),
(765,'JSON_MERGE_PRESERVE',40,'MariaDB starting with 10.3.16\n-----------------------------\nJSON_MERGE_PRESERVE was introduced in MariaDB 10.3.16 and MariaDB 10.4.5.\n\nSyntax\n------\n\nJSON_MERGE_PRESERVE(json_doc, json_doc[, json_doc] ...)\n\nDescription\n-----------\n\nMerges the given JSON documents, returning the merged result, or NULL if any\nargument is NULL.\n\nJSON_MERGE_PRESERVE was introduced in MariaDB 10.2.25, MariaDB 10.3.16 and\nMariaDB 10.4.5 as a synonym for JSON_MERGE, which has been deprecated.\n\nExample\n-------\n\nSET @json1 = \'[1, 2]\';\nSET @json2 = \'[2, 3]\';\nSELECT JSON_MERGE_PATCH(@json1,@json2),JSON_MERGE_PRESERVE(@json1,@json2);\n+---------------------------------+------------------------------------+\n| JSON_MERGE_PATCH(@json1,@json2) | JSON_MERGE_PRESERVE(@json1,@json2) |\n+---------------------------------+------------------------------------+\n| [2, 3]                          | [1, 2, 2, 3]                       |\n+---------------------------------+------------------------------------+\n\nURL: https://mariadb.com/kb/en/json_merge_preserve/','','https://mariadb.com/kb/en/json_merge_preserve/'),
(766,'JSON_NORMALIZE',40,'MariaDB starting with 10.7.0\n----------------------------\nJSON_NORMALIZE was added in MariaDB 10.7.0.\n\nSyntax\n------\n\nJSON_NORMALIZE(json)\n\nDescription\n-----------\n\nRecursively sorts keys and removes spaces, allowing comparison of json\ndocuments for equality.\n\nExamples\n--------\n\nWe may wish our application to use the database to enforce a unique constraint\non the JSON contents, and we can do so using the JSON_NORMALIZE function in\ncombination with a unique key.\n\nFor example, if we have a table with a JSON column:\n\nCREATE TABLE t1 (\n id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,\n val JSON,\n /* other columns here */\n PRIMARY KEY (id)\n);\n\nAdd a unique constraint using JSON_NORMALIZE like this:\n\nALTER TABLE t1\n ADD COLUMN jnorm JSON AS (JSON_NORMALIZE(val)) VIRTUAL,\n ADD UNIQUE KEY (jnorm);\n\nWe can test this by first inserting a row as normal:\n\nINSERT INTO t1 (val) VALUES (\'{\"name\":\"alice\",\"color\":\"blue\"}\');\n\nAnd then seeing what happens with a different string which would produce the\nsame JSON object:\n\nINSERT INTO t1 (val) VALUES (\'{ \"color\": \"blue\", \"name\": \"alice\" }\');\nERROR 1062 (23000): Duplicate entry \'{\"color\":\"blue\",\"name\":\"alice\"}\' for key\n\'jnorm\'\n\nURL: https://mariadb.com/kb/en/json_normalize/','','https://mariadb.com/kb/en/json_normalize/'),
(768,'JSON_OVERLAPS',40,'MariaDB starting with 10.9\n--------------------------\nJSON_OVERLAPS was added in MariaDB 10.9.\n\nSyntax\n------\n\nJSON_OVERLAPS(json_doc1, json_doc2)\n\nDescription\n-----------\n\nJSON_OVERLAPS() compares two json documents and returns true if they have at\nleast one common key-value pair between two objects, array element common\nbetween two arrays, or array element common with scalar if one of the\narguments is a scalar and other is an array. If two json documents are\nscalars, it returns true if they have same type and value.\n\nIf none of the above conditions are satisfied then it returns false.\n\nExamples\n--------\n\nSELECT JSON_OVERLAPS(\'false\', \'false\');\n+---------------------------------+\n| JSON_OVERLAPS(\'false\', \'false\') |\n+---------------------------------+\n| 1                               |\n+---------------------------------+\n\nSELECT JSON_OVERLAPS(\'true\', \'[\"abc\", 1, 2, true, false]\');\n+----------------------------------------------------+\n| JSON_OVERLAPS(\'true\',\'[\"abc\", 1, 2, true, false]\') |\n+----------------------------------------------------+\n| 1                                                  |\n+----------------------------------------------------+\n\nSELECT JSON_OVERLAPS(\'{\"A\": 1, \"B\": {\"C\":2}}\', \'{\"A\": 2, \"B\": {\"C\":2}}\') AS\nis_overlap;\n+---------------------+\n| is_overlap          |\n+---------------------+\n| 1                   |\n+---------------------+\n\nPartial match is considered as no-match.\n\nExamples\n--------\n\nSELECT JSON_OVERLAPS(\'[1, 2, true, false, null]\', \'[3, 4, [1]]\') AS is_overlap;\n+--------------------- +\n| is_overlap           |\n+----------------------+\n| 0                    |\n+----------------------+\n\nURL: https://mariadb.com/kb/en/json_overlaps/','','https://mariadb.com/kb/en/json_overlaps/'),
(770,'JSON_QUERY',40,'Syntax\n------\n\nJSON_QUERY(json_doc, path)\n\nDescription\n-----------\n\nGiven a JSON document, returns an object or array specified by the path.\nReturns NULL if not given a valid JSON document, or if there is no match.\n\nExamples\n--------\n\nselect json_query(\'{\"key1\":{\"a\":1, \"b\":[1,2]}}\', \'$.key1\');\n+-----------------------------------------------------+\n| json_query(\'{\"key1\":{\"a\":1, \"b\":[1,2]}}\', \'$.key1\') |\n+-----------------------------------------------------+\n| {\"a\":1, \"b\":[1,2]}                                  |\n+-----------------------------------------------------+\n\nselect json_query(\'{\"key1\":123, \"key1\": [1,2,3]}\', \'$.key1\');\n+-------------------------------------------------------+\n| json_query(\'{\"key1\":123, \"key1\": [1,2,3]}\', \'$.key1\') |\n+-------------------------------------------------------+\n| [1,2,3]                                               |\n+-------------------------------------------------------+\n\nURL: https://mariadb.com/kb/en/json_query/','','https://mariadb.com/kb/en/json_query/'),
(771,'JSON_QUOTE',40,'Syntax\n------\n\nJSON_QUOTE(json_value)\n\nDescription\n-----------\n\nQuotes a string as a JSON value, usually for producing valid JSON string\nliterals for inclusion in JSON documents. Wraps the string with double quote\ncharacters and escapes interior quotes and other special characters, returning\na utf8mb4 string.\n\nReturns NULL if the argument is NULL.\n\nExamples\n--------\n\nSELECT JSON_QUOTE(\'A\'), JSON_QUOTE(\"B\"), JSON_QUOTE(\'\"C\"\');\n+-----------------+-----------------+-------------------+\n| JSON_QUOTE(\'A\') | JSON_QUOTE(\"B\") | JSON_QUOTE(\'\"C\"\') |\n+-----------------+-----------------+-------------------+\n| \"A\"             | \"B\"             | \"\\\"C\\\"\"           |\n+-----------------+-----------------+-------------------+\n\nURL: https://mariadb.com/kb/en/json_quote/','','https://mariadb.com/kb/en/json_quote/'),
(772,'JSON_REMOVE',40,'Syntax\n------\n\nJSON_REMOVE(json_doc, path[, path] ...)\n\nDescription\n-----------\n\nRemoves data from a JSON document returning the result, or NULL if any of the\narguments are null. If the element does not exist in the document, no changes\nare made.\n\nThe function returns NULL and throws a warning if the JSON document is\ninvalid, the path is invalid, contains a range, or contains a * or ** wildcard.\n\nPath arguments are evaluated from left to right, with the result from the\nearlier evaluation being used as the value for the next.\n\nExamples\n--------\n\nSELECT JSON_REMOVE(\'{\"A\": 1, \"B\": 2, \"C\": {\"D\": 3}}\', \'$.C\');\n+-------------------------------------------------------+\n| JSON_REMOVE(\'{\"A\": 1, \"B\": 2, \"C\": {\"D\": 3}}\', \'$.C\') |\n+-------------------------------------------------------+\n| {\"A\": 1, \"B\": 2}                                      |\n+-------------------------------------------------------+\n\nSELECT JSON_REMOVE(\'[\"A\", \"B\", [\"C\", \"D\"], \"E\"]\', \'$[1]\');\n+----------------------------------------------------+\n| JSON_REMOVE(\'[\"A\", \"B\", [\"C\", \"D\"], \"E\"]\', \'$[1]\') |\n+----------------------------------------------------+\n| [\"A\", [\"C\", \"D\"], \"E\"]                             |\n+----------------------------------------------------+\n\nURL: https://mariadb.com/kb/en/json_remove/','','https://mariadb.com/kb/en/json_remove/'),
(773,'JSON_REPLACE',40,'Syntax\n------\n\nJSON_REPLACE(json_doc, path, val[, path, val] ...)\n\nDescription\n-----------\n\nReplaces existing values in a JSON document, returning the result, or NULL if\nany of the arguments are NULL.\n\nAn error will occur if the JSON document is invalid, the path is invalid or if\nthe path contains a * or ** wildcard.\n\nPaths and values are evaluated from left to right, with the result from the\nearlier evaluation being used as the value for the next.\n\nJSON_REPLACE can only update data, while JSON_INSERT can only insert. JSON_SET\ncan update or insert data.\n\nExamples\n--------\n\nSELECT JSON_REPLACE(\'{ \"A\": 1, \"B\": [2, 3]}\', \'$.B[1]\', 4);\n+-----------------------------------------------------+\n| JSON_REPLACE(\'{ \"A\": 1, \"B\": [2, 3]}\', \'$.B[1]\', 4) |\n+-----------------------------------------------------+\n| { \"A\": 1, \"B\": [2, 4]}                              |\n+-----------------------------------------------------+\n\nURL: https://mariadb.com/kb/en/json_replace/','','https://mariadb.com/kb/en/json_replace/'),
(774,'JSON_SCHEMA_VALID',40,'MariaDB starting with 11.1\n--------------------------\nJSON_SCHEMA_VALID was introduced in MariaDB 11.1.\n\nSyntax\n------\n\nJSON_SCHEMA_VALID(schema, json);\n\nDescription\n-----------\n\nJSON_SCHEMA_VALID allows MariaDB to support JSON schema validation. If a given\njson is valid against a schema it returns true. When JSON does not validate\nagainst the schema, it does not return a message about which keyword it failed\nagainst and only returns false.\n\nThe function supports JSON Schema Draft 2020 with a few exceptions:\n\n* External resources are not supported\n* Hyper schema keywords are not supported\n* Formats like date, email etc are treated as annotations.\n\nExamples\n--------\n\nTo create validation rules for json field\n\nCREATE TABLE obj_table(val_obj JSON CHECK(JSON_SCHEMA_VALID(\'{\n \"type\":\"object\",\n  \"properties\": {\n   \"number1\":{\n    \"type\":\"number\",\n    \"maximum\":5,\n    \"const\":4\n   },\n   \"string1\":{\n    \"type\":\"string\",\n    \"maxLength\":5,\n    \"minLength\":3\n   },\n  \"object1\":{\n   \"type\":\"object\",\n   \"properties\":{\n    \"key1\": {\"type\":\"string\"},\n    \"key2\":{\"type\":\"array\"},\n    \"key3\":{\"type\":\"number\", \"minimum\":3}\n   },\n   \"dependentRequired\": { \"key1\":[\"key3\"] }\n  }\n },\n \"required\":[\"number1\",\"object1\"]\n }\', val_obj)));\n\nINSERT INTO obj_table VALUES(\n \'{\"number1\":4, \"string1\":\"abcd\",\n \"object1\":{\"key1\":\"val1\", \"key2\":[1,2,3, \"string1\"], \"key3\":4}}\'\n);\n\nINSERT INTO obj_table VALUES(\n \'{\"number1\":3, \"string1\":\"abcd\",\n \"object1\":{\"key1\":\"val1\", \"key2\":[1,2,3, \"string1\"], \"key3\":4}}\'\n);\nERROR 4025 (23000): CONSTRAINT `obj_table.val_obj` failed for\n`test`.`obj_table`\n\nSELECT * FROM obj_table;\n+------------------------------------------------------------------------------\n-------------------+\n| val_obj                                                                     \n          |\n+------------------------------------------------------------------------------\n-------------------+\n| {\"number1\":4, \"string1\":\"abcd\", \"object1\":{\"key1\":\"val1\", \"key2\":[1,2,3,\n\"string1\"], \"key3\":4}} |\n+------------------------------------------------------------------------------\n-------------------+\n\nSET @schema= \'{\n \"properties\" : {\n  \"number1\":{ \"maximum\":10 },\n  \"string1\" : { \"maxLength\": 3}\n }\n}\';\n\nSELECT JSON_SCHEMA_VALID(@schema, \'{ \"number1\":25, \"string1\":\"ab\" }\');\n+----------------------------------------------------------------+\n| JSON_SCHEMA_VALID(@schema, \'{ \"number1\":25, \"string1\":\"ab\" }\') |\n+----------------------------------------------------------------+\n|                                                              0 |\n+----------------------------------------------------------------+\n\nSELECT JSON_SCHEMA_VALID(@schema, \'{ \"number1\":10, \"string1\":\"ab\" }\');\n+----------------------------------------------------------------+\n| JSON_SCHEMA_VALID(@schema, \'{ \"number1\":10, \"string1\":\"ab\" }\') |\n+----------------------------------------------------------------+\n|                                                              1 |\n+----------------------------------------------------------------+\n\nURL: https://mariadb.com/kb/en/json_schema_valid/','','https://mariadb.com/kb/en/json_schema_valid/'),
(775,'JSON_SEARCH',40,'Syntax\n------\n\nJSON_SEARCH(json_doc, return_arg, search_str[, escape_char[, path] ...])\n\nDescription\n-----------\n\nReturns the path to the given string within a JSON document, or NULL if any of\njson_doc, search_str or a path argument is NULL; if the search string is not\nfound, or if no path exists within the document.\n\nA warning will occur if the JSON document is not valid, any of the path\narguments are not valid, if return_arg is neither one nor all, or if the\nescape character is not a constant. NULL will be returned.\n\nreturn_arg can be one of two values:\n\n* \'one: Terminates after finding the first match, so will return one path\nstring. If there is more than one match, it is undefined which is considered\nfirst.\n* all: Returns all matching path strings, without duplicates. Multiple strings\nare autowrapped as an array. The order is undefined.\n\nExamples\n--------\n\nSET @json = \'[\"A\", [{\"B\": \"1\"}], {\"C\":\"AB\"}, {\"D\":\"BC\"}]\';\n\nSELECT JSON_SEARCH(@json, \'one\', \'AB\');\n+---------------------------------+\n| JSON_SEARCH(@json, \'one\', \'AB\') |\n+---------------------------------+\n| \"$[2].C\"                        |\n+---------------------------------+\n\nURL: https://mariadb.com/kb/en/json_search/','','https://mariadb.com/kb/en/json_search/'),
(778,'JSON_TYPE',40,'Syntax\n------\n\nJSON_TYPE(json_val)\n\nDescription\n-----------\n\nReturns the type of a JSON value (as a string), or NULL if the argument is\nnull.\n\nAn error will occur if the argument is an invalid JSON value.\n\nThe following is a complete list of the possible return types:\n\n+-----------------------------------+-----------------+-----------------------+\n| Return type                       | Value           | Example               |\n+-----------------------------------+-----------------+-----------------------+\n| ARRAY                             | JSON array      | [1, 2, {\"key\":        |\n|                                   |                 | \"value\"}]             |\n+-----------------------------------+-----------------+-----------------------+\n| OBJECT                            | JSON object     | {\"key\":\"value\"}       |\n+-----------------------------------+-----------------+-----------------------+\n| BOOLEAN                           | JSON            | true, false           |\n|                                   | true/false      |                       |\n|                                   | literals        |                       |\n+-----------------------------------+-----------------+-----------------------+\n| DOUBLE                            | A number with   | 1.2                   |\n|                                   | at least one    |                       |\n|                                   | floating point  |                       |\n|                                   | decimal.        |                       |\n+-----------------------------------+-----------------+-----------------------+\n| INTEGER                           | A number        | 1                     |\n|                                   | without a       |                       |\n|                                   | floating point  |                       |\n|                                   | decimal.        |                       |\n+-----------------------------------+-----------------+-----------------------+\n| NULL                              | JSON null       | null                  |\n|                                   | literal (this   |                       |\n|                                   | is returned as  |                       |\n|                                   | a string, not   |                       |\n|                                   | to be confused  |                       |\n|                                   | with the SQL    |                       |\n|                                   | NULL value!)    |                       |\n+-----------------------------------+-----------------+-----------------------+\n| STRING                            | JSON String     | \"a sample string\"     |\n+-----------------------------------+-----------------+-----------------------+\n\nExamples\n--------\n\nSELECT JSON_TYPE(\'{\"A\": 1, \"B\": 2, \"C\": 3}\');\n+---------------------------------------+\n| JSON_TYPE(\'{\"A\": 1, \"B\": 2, \"C\": 3}\') |\n+---------------------------------------+\n| OBJECT                                |\n+---------------------------------------+\n\nURL: https://mariadb.com/kb/en/json_type/','','https://mariadb.com/kb/en/json_type/'),
(779,'JSON_UNQUOTE',40,'Syntax\n------\n\nJSON_UNQUOTE(val)\n\nDescription\n-----------\n\nUnquotes a JSON value, returning a string, or NULL if the argument is null.\n\nAn error will occur if the given value begins and ends with double quotes and\nis an invalid JSON string literal.\n\nIf the given value is not a JSON string, value is passed through unmodified.\n\nCertain character sequences have special meanings within a string. Usually, a\nbackslash is ignored, but the escape sequences in the table below are\nrecognised by MariaDB, unless the SQL Mode is set to NO_BACKSLASH_ESCAPES SQL.\n\n+-----------------------------------------------+-----------------------------+\n| Escape sequence                               | Character                   |\n+-----------------------------------------------+-----------------------------+\n| \\\"                                            | Double quote (\")            |\n+-----------------------------------------------+-----------------------------+\n| \\b                                            | Backslash                   |\n+-----------------------------------------------+-----------------------------+\n| \\f                                            | Formfeed                    |\n+-----------------------------------------------+-----------------------------+\n| \\n                                            | Newline (linefeed)          |\n+-----------------------------------------------+-----------------------------+\n| \\r                                            | Carriage return             |\n+-----------------------------------------------+-----------------------------+\n| \\t                                            | Tab                         |\n+-----------------------------------------------+-----------------------------+\n| \\\\                                            | Backslash (\\)               |\n+-----------------------------------------------+-----------------------------+\n| \\uXXXX                                        | UTF-8 bytes for Unicode     |\n|                                               | value XXXX                  |\n+-----------------------------------------------+-----------------------------+\n\nExamples\n--------\n\nSELECT JSON_UNQUOTE(\'\"Monty\"\');\n+-------------------------+\n| JSON_UNQUOTE(\'\"Monty\"\') |\n+-------------------------+\n| Monty                   |\n+-------------------------+\n\nWith the default SQL Mode:\n\nSELECT JSON_UNQUOTE(\'Si\\bng\\ting\');\n+-----------------------------+\n| JSON_UNQUOTE(\'Si\\bng\\ting\') |\n+-----------------------------+\n| Sng	ing                   |\n+-----------------------------+\n\nSetting NO_BACKSLASH_ESCAPES:\n\nSET @@sql_mode = \'NO_BACKSLASH_ESCAPES\';\n\nSELECT JSON_UNQUOTE(\'Si\\bng\\ting\');\n+-----------------------------+\n| JSON_UNQUOTE(\'Si\\bng\\ting\') |\n+-----------------------------+\n| Si\\bng\\ting                 |\n+-----------------------------+\n\nURL: https://mariadb.com/kb/en/json_unquote/','','https://mariadb.com/kb/en/json_unquote/'),
(777,'JSON_TABLE',40,'MariaDB starting with 10.6.0\n----------------------------\nJSON_TABLE was added in MariaDB 10.6.0.\n\nJSON_TABLE is a table function that converts JSON data into a relational form.\n\nSyntax\n------\n\nJSON_TABLE(json_doc, \n     context_path COLUMNS (column_list)\n) [AS] alias\n\ncolumn_list:\n  column[, column][, ...]\n\ncolumn:\n  name FOR ORDINALITY\n  |  name type PATH path_str [on_empty] [on_error]\n  |  name type EXISTS PATH path_str\n  |  NESTED PATH path_str COLUMNS (column_list)\n\non_empty:\n  {NULL | DEFAULT string | ERROR} ON EMPTY\n\non_error:\n  {NULL | DEFAULT string | ERROR} ON ERROR\n\nDescription\n-----------\n\nJSON_TABLE can be used in contexts where a table reference can be used; in the\nFROM clause of a SELECT statement, and in multi-table UPDATE/DELETE statements.\n\njson_doc is the JSON document to extract data from. In the simplest case, it\nis a string literal containing JSON. In more complex cases it can be an\narbitrary expression returning JSON. The expression may have references to\ncolumns of other tables. However, one can only refer to tables that precede\nthis JSON_TABLE invocation. For RIGHT JOIN, it is assumed that its outer side\nprecedes the inner. All tables in outer selects are also considered preceding.\n\ncontext_path is a JSON Path expression pointing to a collection of nodes in\njson_doc that will be used as the source of rows.\n\nThe COLUMNS clause declares the names and types of the columns that JSON_TABLE\nreturns, as well as how the values of the columns are produced.\n\nColumn Definitions\n------------------\n\nThe following types of columns are supported:\n\nPath Columns\n------------\n\nname type PATH path_str [on_empty] [on_error]\n\nLocates the JSON node pointed to by path_str and returns its value. The\npath_str is evaluated using the current row source node as the context node.\n\nset @json=\'\n[\n {\"name\":\"Laptop\", \"color\":\"black\", \"price\":\"1000\"},\n {\"name\":\"Jeans\",  \"color\":\"blue\"}\n]\';\n\nselect * from json_table(@json, \'$[*]\' \n columns(\n name  varchar(10) path \'$.name\',\n color varchar(10) path \'$.color\',\n price decimal(8,2) path \'$.price\' )\n) as jt;\n+--------+-------+---------+\n| name   | color | price   |\n+--------+-------+---------+\n| Laptop | black | 1000.00 |\n| Jeans  | blue  |    NULL |\n+--------+-------+---------+\n\nThe on_empty and on_error clauses specify the actions to be performed when the\nvalue was not found or there was an error condition. See the ON EMPTY and ON\nERROR clauses section for details.\n\nORDINALITY Columns\n------------------\n\nname FOR ORDINALITY\n\nCounts the rows, starting from 1.\n\nExample:\n\nset @json=\'\n[\n {\"name\":\"Laptop\", \"color\":\"black\"},\n {\"name\":\"Jeans\",  \"color\":\"blue\"}\n]\';\n\nselect * from json_table(@json, \'$[*]\' \n columns(\n id for ordinality,\n name  varchar(10) path \'$.name\')\n) as jt;\n+------+--------+\n| id   | name   |\n+------+--------+\n|    1 | Laptop |\n|    2 | Jeans  |\n+------+--------+\n\nEXISTS PATH Columns\n-------------------\n\nname type EXISTS PATH path_str\n\nChecks whether the node pointed to by value_path exists. The value_path is\nevaluated using the current row source node as the context node.\n\nset @json=\'\n[\n {\"name\":\"Laptop\", \"color\":\"black\", \"price\":1000},\n {\"name\":\"Jeans\",  \"color\":\"blue\"}\n]\';\n\nselect * from json_table(@json, \'$[*]\' \n columns(\n name  varchar(10) path \'$.name\',\n has_price integer exists path \'$.price\')\n) as jt;\n+--------+-----------+\n| name   | has_price |\n+--------+-----------+\n| Laptop |         1 |\n| Jeans  |         0 |\n+--------+-----------+\n\nNESTED PATHs\n------------\n\nNESTED PATH converts nested JSON structures into multiple rows.\n\nNESTED PATH path COLUMNS (column_list)\n\nIt finds the sequence of JSON nodes pointed to by path and uses it to produce\nrows. For each found node, a row is generated with column values as specified\nby the NESTED PATH\'s COLUMNS clause. If path finds no nodes, only one row is\ngenerated with all columns having NULL values.\n\nFor example, consider a JSON document that contains an array of items, and\neach item, in turn, is expected to have an array of its available sizes:\n\nset @json=\'\n[\n {\"name\":\"Jeans\",  \"sizes\": [32, 34, 36]},\n {\"name\":\"T-Shirt\", \"sizes\":[\"Medium\", \"Large\"]},\n {\"name\":\"Cellphone\"}\n]\';\n\nNESTED PATH allows one to produce a separate row for each size each item has:\n\nselect * from json_table(@json, \'$[*]\' \n columns(\n  name  varchar(10) path \'$.name\',\n  nested path \'$.sizes[*]\' columns (\n   size varchar(32) path \'$\'\n  )\n )\n) as jt;\n+-----------+--------+\n| name      | size   |\n+-----------+--------+\n| Jeans     | 32     |\n| Jeans     | 34     |\n| Jeans     | 36     |\n| T-Shirt   | Medium |\n| T-Shirt   | Large  |\n| Cellphone | NULL   |\n+-----------+--------+\n\nNESTED PATH clauses can be nested within one another. They can also be located\nnext to each other. In that case, the nested path clauses will produce records\none at a time. The ones that are not producing records will have all columns\nset to NULL.\n\nExample:\n\nset @json=\'\n[\n {\"name\":\"Jeans\",  \"sizes\": [32, 34, 36], \"colors\":[\"black\", \"blue\"]}\n]\';\n\nselect * from json_table(@json, \'$[*]\' \n columns(\n  name  varchar(10) path \'$.name\',\n  nested path \'$.sizes[*]\' columns (\n   size varchar(32) path \'$\'\n  ),\n  nested path \'$.colors[*]\' columns (\n   color varchar(32) path \'$\'\n  )\n )\n) as jt;\n\n+-------+------+-------+\n| name  | size | color |\n+-------+------+-------+\n| Jeans | 32   | NULL  |\n| Jeans | 34   | NULL  |\n| Jeans | 36   | NULL  |\n| Jeans | NULL | black |\n| Jeans | NULL | blue  |\n+-------+------+-------+\n\nON EMPTY and ON ERROR Clauses\n-----------------------------\n\nThe ON EMPTY clause specifies what will be done when the element specified by\nthe search path is missing in the JSON document.\n\non_empty:\n  {NULL | DEFAULT string | ERROR} ON EMPTY\n\nWhen ON EMPTY clause is not present, NULL ON EMPTY is implied.\n\non_error:\n  {NULL | DEFAULT string | ERROR} ON ERROR\n\nThe ON ERROR clause specifies what should be done if a JSON structure error\noccurs when trying to extract the value pointed to by the path expression. A\nJSON structure error here occurs only when one attempts to convert a JSON\nnon-scalar (array or object) into a scalar value. When the ON ERROR clause is\nnot present, NULL ON ERROR is implied.\n\nNote: A datatype conversion error (e.g. attempt to store a non-integer value\ninto an integer field, or a varchar column being truncated) is not considered\na JSON error and so will not trigger the ON ERROR behavior. It will produce\nwarnings, in the same way as CAST(value AS datatype) would.\n\nReplication\n-----------\n\nIn the current code, evaluation of JSON_TABLE is deterministic, that is, for a\ngiven input string JSON_TABLE will always produce the same set of rows in the\nsame order. However, one can think of JSON documents that one can consider\nidentical which will produce different output. In order to be future-proof and\nwithstand changes like:\n\n* sorting JSON object members by name (like MySQL does)\n* changing the way duplicate object members are handled\nthe function is marked as unsafe for statement-based replication.\n\nExtracting a Subdocument into a Column\n--------------------------------------\n\nMariaDB starting with 10.6.9\n----------------------------\nPrior to MariaDB 10.6.9, JSON_TABLE did not allow one to extract a JSON\n\"subdocument\" into a JSON column.\n\nSELECT * FROM JSON_TABLE(\'{\"foo\": [1,2,3,4]}\',\'$\' columns( jscol json path\n\'$.foo\') ) AS T;\n+-------+\n| jscol |\n+-------+\n| NULL  |\n+-------+\n\nThis is supported from MariaDB 10.6.9:\n\nSELECT * FROM JSON_TABLE(\'{\"foo\": [1,2,3,4]}\',\'$\' columns( jscol json path\n\'$.foo\') ) AS T;\n+-----------+\n| jscol     |\n+-----------+\n| [1,2,3,4] |\n+-----------+\n\nURL: https://mariadb.com/kb/en/json_table/','','https://mariadb.com/kb/en/json_table/'),
(780,'JSON_VALID',40,'Syntax\n------\n\nJSON_VALID(value)\n\nDescription\n-----------\n\nIndicates whether the given value is a valid JSON document or not. Returns 1\nif valid, 0 if not, and NULL if the argument is NULL.\n\nFrom MariaDB 10.4.3, the JSON_VALID function is automatically used as a CHECK\nconstraint for the JSON data type alias in order to ensure that a valid json\ndocument is inserted.\n\nExamples\n--------\n\nSELECT JSON_VALID(\'{\"id\": 1, \"name\": \"Monty\"}\');\n+------------------------------------------+\n| JSON_VALID(\'{\"id\": 1, \"name\": \"Monty\"}\') |\n+------------------------------------------+\n|                                        1 |\n+------------------------------------------+\n\nSELECT JSON_VALID(\'{\"id\": 1, \"name\": \"Monty\", \"oddfield\"}\');\n+------------------------------------------------------+\n| JSON_VALID(\'{\"id\": 1, \"name\": \"Monty\", \"oddfield\"}\') |\n+------------------------------------------------------+\n|                                                    0 |\n+------------------------------------------------------+\n\nURL: https://mariadb.com/kb/en/json_valid/','','https://mariadb.com/kb/en/json_valid/'),
(781,'JSON_VALUE',40,'Syntax\n------\n\nJSON_VALUE(json_doc, path)\n\nDescription\n-----------\n\nGiven a JSON document, returns the scalar specified by the path. Returns NULL\nif not given a valid JSON document, or if there is no match.\n\nExamples\n--------\n\nselect json_value(\'{\"key1\":123}\', \'$.key1\');\n+--------------------------------------+\n| json_value(\'{\"key1\":123}\', \'$.key1\') |\n+--------------------------------------+\n| 123                                  |\n+--------------------------------------+\n\nselect json_value(\'{\"key1\": [1,2,3], \"key1\":123}\', \'$.key1\');\n+-------------------------------------------------------+\n| json_value(\'{\"key1\": [1,2,3], \"key1\":123}\', \'$.key1\') |\n+-------------------------------------------------------+\n| 123                                                   |\n+-------------------------------------------------------+\n\nIn the SET statement below, two escape characters are needed, as a single\nescape character would be applied by the SQL parser in the SET statement, and\nthe escaped character would not form part of the saved value.\n\nSET @json = \'{\"key1\":\"60\\\\\" Table\", \"key2\":\"1\"}\';\n\nSELECT JSON_VALUE(@json,\'$.key1\') AS Name , json_value(@json,\'$.key2\') as ID;\n+-----------+------+\n| Name      | ID   |\n+-----------+------+\n| 60\" Table | 1    |\n+-----------+------+\n\nURL: https://mariadb.com/kb/en/json_value/','','https://mariadb.com/kb/en/json_value/'),
(784,'DENSE_RANK',41,'Syntax\n------\n\nDENSE_RANK() OVER (\n [ PARTITION BY partition_expression ]\n [ ORDER BY order_list ]\n)\n\nDescription\n-----------\n\nDENSE_RANK() is a window function that displays the number of a given row,\nstarting at one and following the ORDER BY sequence of the window function,\nwith identical values receiving the same result. Unlike the RANK() function,\nthere are no skipped values if the preceding results are identical. It is also\nsimilar to the ROW_NUMBER() function except that in that function, identical\nvalues will receive a different row number for each result.\n\nExamples\n--------\n\nThe distinction between DENSE_RANK(), RANK() and ROW_NUMBER():\n\nCREATE TABLE student(course VARCHAR(10), mark int, name varchar(10));\n\nINSERT INTO student VALUES \n (\'Maths\', 60, \'Thulile\'),\n (\'Maths\', 60, \'Pritha\'),\n (\'Maths\', 70, \'Voitto\'),\n (\'Maths\', 55, \'Chun\'),\n (\'Biology\', 60, \'Bilal\'),\n (\'Biology\', 70, \'Roger\');\n\nSELECT \n RANK() OVER (PARTITION BY course ORDER BY mark DESC) AS rank,\n DENSE_RANK() OVER (PARTITION BY course ORDER BY mark DESC) AS dense_rank,\n ROW_NUMBER() OVER (PARTITION BY course ORDER BY mark DESC) AS row_num,\n course, mark, name\nFROM student ORDER BY course, mark DESC;\n+------+------------+---------+---------+------+---------+\n| rank | dense_rank | row_num | course  | mark | name    |\n+------+------------+---------+---------+------+---------+\n|    1 |          1 |       1 | Biology |   70 | Roger   |\n|    2 |          2 |       2 | Biology |   60 | Bilal   |\n|    1 |          1 |       1 | Maths   |   70 | Voitto  |\n|    2 |          2 |       2 | Maths   |   60 | Thulile |\n|    2 |          2 |       3 | Maths   |   60 | Pritha  |\n|    4 |          3 |       4 | Maths   |   55 | Chun    |\n+------+------------+---------+---------+------+---------+\n\nURL: https://mariadb.com/kb/en/dense_rank/','','https://mariadb.com/kb/en/dense_rank/'),
(786,'LAG',41,'Syntax\n------\n\nLAG (expr[, offset]) OVER ( \n [ PARTITION BY partition_expression ]\n < ORDER BY order_list >\n)\n\nDescription\n-----------\n\nThe LAG function accesses data from a previous row according to the ORDER BY\nclause without the need for a self-join. The specific row is determined by the\noffset (default 1), which specifies the number of rows behind the current row\nto use. An offset of 0 is the current row.\n\nExamples\n--------\n\nCREATE TABLE t1 (pk int primary key, a int, b int, c char(10), d decimal(10,\n3), e real);\n\nINSERT INTO t1 VALUES\n ( 1, 0, 1,    \'one\',    0.1,  0.001),\n ( 2, 0, 2,    \'two\',    0.2,  0.002),\n ( 3, 0, 3,    \'three\',  0.3,  0.003),\n ( 4, 1, 2,    \'three\',  0.4,  0.004),\n ( 5, 1, 1,    \'two\',    0.5,  0.005),\n ( 6, 1, 1,    \'one\',    0.6,  0.006),\n ( 7, 2, NULL, \'n_one\',  0.5,  0.007),\n ( 8, 2, 1,    \'n_two\',  NULL, 0.008),\n ( 9, 2, 2,    NULL,     0.7,  0.009),\n (10, 2, 0,    \'n_four\', 0.8,  0.010),\n (11, 2, 10,   NULL,     0.9,  NULL);\n\nSELECT pk, LAG(pk) OVER (ORDER BY pk) AS l,\n LAG(pk,1) OVER (ORDER BY pk) AS l1,\n LAG(pk,2) OVER (ORDER BY pk) AS l2,\n LAG(pk,0) OVER (ORDER BY pk) AS l0,\n LAG(pk,-1) OVER (ORDER BY pk) AS lm1,\n LAG(pk,-2) OVER (ORDER BY pk) AS lm2\nFROM t1;\n+----+------+------+------+------+------+------+\n| pk | l    | l1   | l2   | l0   | lm1  | lm2  |\n+----+------+------+------+------+------+------+\n|  1 | NULL | NULL | NULL |    1 |    2 |    3 |\n|  2 |    1 |    1 | NULL |    2 |    3 |    4 |\n|  3 |    2 |    2 |    1 |    3 |    4 |    5 |\n|  4 |    3 |    3 |    2 |    4 |    5 |    6 |\n|  5 |    4 |    4 |    3 |    5 |    6 |    7 |\n|  6 |    5 |    5 |    4 |    6 |    7 |    8 |\n|  7 |    6 |    6 |    5 |    7 |    8 |    9 |\n|  8 |    7 |    7 |    6 |    8 |    9 |   10 |\n|  9 |    8 |    8 |    7 |    9 |   10 |   11 |\n| 10 |    9 |    9 |    8 |   10 |   11 | NULL |\n| 11 |   10 |   10 |    9 |   11 | NULL | NULL |\n+----+------+------+------+------+------+------+\n\nURL: https://mariadb.com/kb/en/lag/','','https://mariadb.com/kb/en/lag/'),
(783,'CUME_DIST',41,'Syntax\n------\n\nCUME_DIST() OVER ( \n [ PARTITION BY partition_expression ]\n [ ORDER BY order_list ]\n)\n\nDescription\n-----------\n\nCUME_DIST() is a window function that returns the cumulative distribution of a\ngiven row. The following formula is used to calculate the value:\n\n(number of rows <= current row) / (total rows)\n\nExamples\n--------\n\ncreate table t1 (\n pk int primary key,\n a int,\n b int\n);\n\ninsert into t1 values\n( 1 , 0, 10),\n( 2 , 0, 10),\n( 3 , 1, 10),\n( 4 , 1, 10),\n( 8 , 2, 10),\n( 5 , 2, 20),\n( 6 , 2, 20),\n( 7 , 2, 20),\n( 9 , 4, 20),\n(10 , 4, 20);\n\nselect pk, a, b,\n  rank() over (order by a) as rank,\n  percent_rank() over (order by a) as pct_rank,\n  cume_dist() over (order by a) as cume_dist\nfrom t1;\n+----+------+------+------+--------------+--------------+\n| pk | a    | b    | rank | pct_rank     | cume_dist    |\n+----+------+------+------+--------------+--------------+\n|  1 |    0 |   10 |    1 | 0.0000000000 | 0.2000000000 |\n|  2 |    0 |   10 |    1 | 0.0000000000 | 0.2000000000 |\n|  3 |    1 |   10 |    3 | 0.2222222222 | 0.4000000000 |\n|  4 |    1 |   10 |    3 | 0.2222222222 | 0.4000000000 |\n|  5 |    2 |   20 |    5 | 0.4444444444 | 0.8000000000 |\n|  6 |    2 |   20 |    5 | 0.4444444444 | 0.8000000000 |\n|  7 |    2 |   20 |    5 | 0.4444444444 | 0.8000000000 |\n|  8 |    2 |   10 |    5 | 0.4444444444 | 0.8000000000 |\n|  9 |    4 |   20 |    9 | 0.8888888889 | 1.0000000000 |\n| 10 |    4 |   20 |    9 | 0.8888888889 | 1.0000000000 |\n+----+------+------+------+--------------+--------------+\n\nselect pk, a, b,\n   percent_rank() over (order by pk) as pct_rank,\n   cume_dist() over (order by pk) as cume_dist\nfrom t1 order by pk;\n+----+------+------+--------------+--------------+\n| pk | a    | b    | pct_rank     | cume_dist    |\n+----+------+------+--------------+--------------+\n|  1 |    0 |   10 | 0.0000000000 | 0.1000000000 |\n|  2 |    0 |   10 | 0.1111111111 | 0.2000000000 |\n|  3 |    1 |   10 | 0.2222222222 | 0.3000000000 |\n|  4 |    1 |   10 | 0.3333333333 | 0.4000000000 |\n|  5 |    2 |   20 | 0.4444444444 | 0.5000000000 |\n|  6 |    2 |   20 | 0.5555555556 | 0.6000000000 |\n|  7 |    2 |   20 | 0.6666666667 | 0.7000000000 |\n|  8 |    2 |   10 | 0.7777777778 | 0.8000000000 |\n|  9 |    4 |   20 | 0.8888888889 | 0.9000000000 |\n| 10 |    4 |   20 | 1.0000000000 | 1.0000000000 |\n+----+------+------+--------------+--------------+\n\nselect pk, a, b,\n    percent_rank() over (partition by a order by a) as pct_rank,\n    cume_dist() over (partition by a order by a) as cume_dist\nfrom t1;\n+----+------+------+--------------+--------------+\n| pk | a    | b    | pct_rank     | cume_dist    |\n+----+------+------+--------------+--------------+\n|  1 |    0 |   10 | 0.0000000000 | 1.0000000000 |\n|  2 |    0 |   10 | 0.0000000000 | 1.0000000000 |\n|  3 |    1 |   10 | 0.0000000000 | 1.0000000000 |\n|  4 |    1 |   10 | 0.0000000000 | 1.0000000000 |\n|  5 |    2 |   20 | 0.0000000000 | 1.0000000000 |\n|  6 |    2 |   20 | 0.0000000000 | 1.0000000000 |\n|  7 |    2 |   20 | 0.0000000000 | 1.0000000000 |\n|  8 |    2 |   10 | 0.0000000000 | 1.0000000000 |\n|  9 |    4 |   20 | 0.0000000000 | 1.0000000000 |\n| 10 |    4 |   20 | 0.0000000000 | 1.0000000000 |\n+----+------+------+--------------+--------------+\n\nURL: https://mariadb.com/kb/en/cume_dist/','','https://mariadb.com/kb/en/cume_dist/'),
(787,'LEAD',41,'Syntax\n------\n\nLEAD (expr[, offset]) OVER ( \n [ PARTITION BY partition_expression ]\n [ ORDER BY order_list ]\n)\n\nDescription\n-----------\n\nThe LEAD function accesses data from a following row in the same result set\nwithout the need for a self-join. The specific row is determined by the offset\n(default 1), which specifies the number of rows ahead the current row to use.\nAn offset of 0 is the current row.\n\nExample\n-------\n\nCREATE TABLE t1 (pk int primary key, a int, b int, c char(10), d decimal(10,\n3), e real);\n\nINSERT INTO t1 VALUES\n ( 1, 0, 1,    \'one\',    0.1,  0.001),\n ( 2, 0, 2,    \'two\',    0.2,  0.002),\n ( 3, 0, 3,    \'three\',  0.3,  0.003),\n ( 4, 1, 2,    \'three\',  0.4,  0.004),\n ( 5, 1, 1,    \'two\',    0.5,  0.005),\n ( 6, 1, 1,    \'one\',    0.6,  0.006),\n ( 7, 2, NULL, \'n_one\',  0.5,  0.007),\n ( 8, 2, 1,    \'n_two\',  NULL, 0.008),\n ( 9, 2, 2,    NULL,     0.7,  0.009),\n (10, 2, 0,    \'n_four\', 0.8,  0.010),\n (11, 2, 10,   NULL,     0.9,  NULL);\n\nSELECT pk, LEAD(pk) OVER (ORDER BY pk) AS l,\n LEAD(pk,1) OVER (ORDER BY pk) AS l1,\n LEAD(pk,2) OVER (ORDER BY pk) AS l2,\n LEAD(pk,0) OVER (ORDER BY pk) AS l0,\n LEAD(pk,-1) OVER (ORDER BY pk) AS lm1,\n LEAD(pk,-2) OVER (ORDER BY pk) AS lm2\nFROM t1;\n+----+------+------+------+------+------+------+\n| pk | l    | l1   | l2   | l0   | lm1  | lm2  |\n+----+------+------+------+------+------+------+\n|  1 |    2 |    2 |    3 |    1 | NULL | NULL |\n|  2 |    3 |    3 |    4 |    2 |    1 | NULL |\n|  3 |    4 |    4 |    5 |    3 |    2 |    1 |\n|  4 |    5 |    5 |    6 |    4 |    3 |    2 |\n|  5 |    6 |    6 |    7 |    5 |    4 |    3 |\n|  6 |    7 |    7 |    8 |    6 |    5 |    4 |\n|  7 |    8 |    8 |    9 |    7 |    6 |    5 |\n|  8 |    9 |    9 |   10 |    8 |    7 |    6 |\n|  9 |   10 |   10 |   11 |    9 |    8 |    7 |\n| 10 |   11 |   11 | NULL |   10 |    9 |    8 |\n| 11 | NULL | NULL | NULL |   11 |   10 |    9 |\n+----+------+------+------+------+------+------+\n\nURL: https://mariadb.com/kb/en/lead/','','https://mariadb.com/kb/en/lead/'),
(785,'FIRST_VALUE',41,'Syntax\n------\n\nFIRST_VALUE(expr) OVER (\n [ PARTITION BY partition_expression ]\n [ ORDER BY order_list ]\n)\n\nDescription\n-----------\n\nFIRST_VALUE returns the first result from an ordered set, or NULL if no such\nresult exists.\n\nExamples\n--------\n\nCREATE TABLE t1 (\n pk int primary key,\n a int,\n b int,\n c char(10),\n d decimal(10, 3),\n e real\n);\n\nINSERT INTO t1 VALUES\n( 1, 0, 1,    \'one\',    0.1,  0.001),\n( 2, 0, 2,    \'two\',    0.2,  0.002),\n( 3, 0, 3,    \'three\',  0.3,  0.003),\n( 4, 1, 2,    \'three\',  0.4,  0.004),\n( 5, 1, 1,    \'two\',    0.5,  0.005),\n( 6, 1, 1,    \'one\',    0.6,  0.006),\n( 7, 2, NULL, \'n_one\',  0.5,  0.007),\n( 8, 2, 1,    \'n_two\',  NULL, 0.008),\n( 9, 2, 2,    NULL,     0.7,  0.009),\n(10, 2, 0,    \'n_four\', 0.8,  0.010),\n(11, 2, 10,   NULL,     0.9,  NULL);\n\nSELECT pk, FIRST_VALUE(pk) OVER (ORDER BY pk) AS first_asc,\n     LAST_VALUE(pk) OVER (ORDER BY pk) AS last_asc,\n     FIRST_VALUE(pk) OVER (ORDER BY pk DESC) AS first_desc,\n     LAST_VALUE(pk) OVER (ORDER BY pk DESC) AS last_desc\nFROM t1\nORDER BY pk DESC;\n\n+----+-----------+----------+------------+-----------+\n| pk | first_asc | last_asc | first_desc | last_desc |\n+----+-----------+----------+------------+-----------+\n| 11 |         1 |       11 |         11 |        11 |\n| 10 |         1 |       10 |         11 |        10 |\n|  9 |         1 |        9 |         11 |         9 |\n|  8 |         1 |        8 |         11 |         8 |\n|  7 |         1 |        7 |         11 |         7 |\n|  6 |         1 |        6 |         11 |         6 |\n|  5 |         1 |        5 |         11 |         5 |\n|  4 |         1 |        4 |         11 |         4 |\n|  3 |         1 |        3 |         11 |         3 |\n|  2 |         1 |        2 |         11 |         2 |\n|  1 |         1 |        1 |         11 |         1 |\n+----+-----------+----------+------------+-----------+\n\nCREATE OR REPLACE TABLE t1 (i int);\nINSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);\n\nSELECT i,\n FIRST_VALUE(i) OVER (ORDER BY i ROWS BETWEEN CURRENT ROW and 1 FOLLOWING) AS\nf_1f,\n LAST_VALUE(i) OVER (ORDER BY i ROWS BETWEEN CURRENT ROW and 1 FOLLOWING) AS\nl_1f,\n FIRST_VALUE(i) OVER (ORDER BY i ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) AS\nf_1p1f,\n LAST_VALUE(i) OVER (ORDER BY i ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) AS\nl_1p1f,\n FIRST_VALUE(i) OVER (ORDER BY i ROWS BETWEEN 2 PRECEDING AND 1 PRECEDING) AS\nf_2p1p,\n LAST_VALUE(i) OVER (ORDER BY i ROWS BETWEEN 2 PRECEDING AND 1 PRECEDING) AS\nl_2p1p,\n FIRST_VALUE(i) OVER (ORDER BY i ROWS BETWEEN 1 FOLLOWING AND 2 FOLLOWING) AS\nf_1f2f,\n LAST_VALUE(i) OVER (ORDER BY i ROWS BETWEEN 1 FOLLOWING AND 2 FOLLOWING) AS\nl_1f2f\nFROM t1;\n\n+------+------+------+--------+--------+--------+--------+--------+--------+\n| i    | f_1f | l_1f | f_1p1f | l_1p1f | f_2p1p | l_2p1p | f_1f2f | l_1f2f |\n+------+------+------+--------+--------+--------+--------+--------+--------+\n|    1 |    1 |    2 |      1 |      2 |   NULL |   NULL |      2 |      3 |\n|    2 |    2 |    3 |      1 |      3 |      1 |      1 |      3 |      4 |\n|    3 |    3 |    4 |      2 |      4 |      1 |      2 |      4 |      5 |\n|    4 |    4 |    5 |      3 |      5 |      2 |      3 |      5 |      6 |\n|    5 |    5 |    6 |      4 |      6 |      3 |      4 |      6 |      7 |\n|    6 |    6 |    7 |      5 |      7 |      4 |      5 |      7 |      8 |\n|    7 |    7 |    8 |      6 |      8 |      5 |      6 |      8 |      9 |\n|    8 |    8 |    9 |      7 |      9 |      6 |      7 |      9 |     10 |\n|    9 |    9 |   10 |      8 |     10 |      7 |      8 |     10 |     10 |\n|   10 |   10 |   10 |      9 |     10 |      8 |      9 |   NULL |   NULL |\n+------+------+------+--------+--------+--------+--------+--------+--------+\n\nURL: https://mariadb.com/kb/en/first_value/','','https://mariadb.com/kb/en/first_value/'),
(788,'Median Window Function',41,'MariaDB starting with 10.3.3\n----------------------------\nThe MEDIAN() window function was first introduced with in MariaDB 10.3.3.\n\nSyntax\n------\n\nMEDIAN(median expression) OVER (\n [ PARTITION BY partition_expression ]\n)\n\nDescription\n-----------\n\nMEDIAN() is a window function that returns the median value of a range of\nvalues.\n\nIt is a specific case of PERCENTILE_CONT, with an argument of 0.5 and the\nORDER BY column the one in MEDIAN\'s argument.\n\nMEDIAN(<median-arg>) OVER ( [ PARTITION BY partition_expression] )\n\nIs equivalent to:\n\nPERCENTILE_CONT(0.5) WITHIN \n GROUP (ORDER BY <median-arg>) OVER ( [ PARTITION BY partition_expression ])\n\nExamples\n--------\n\nCREATE TABLE book_rating (name CHAR(30), star_rating TINYINT);\n\nINSERT INTO book_rating VALUES (\'Lord of the Ladybirds\', 5);\nINSERT INTO book_rating VALUES (\'Lord of the Ladybirds\', 3);\nINSERT INTO book_rating VALUES (\'Lady of the Flies\', 1);\nINSERT INTO book_rating VALUES (\'Lady of the Flies\', 2);\nINSERT INTO book_rating VALUES (\'Lady of the Flies\', 5);\n\nSELECT name, median(star_rating) OVER (PARTITION BY name) FROM book_rating;\n+-----------------------+----------------------------------------------+\n| name                  | median(star_rating) OVER (PARTITION BY name) |\n+-----------------------+----------------------------------------------+\n| Lord of the Ladybirds |                                 4.0000000000 |\n| Lord of the Ladybirds |                                 4.0000000000 |\n| Lady of the Flies     |                                 2.0000000000 |\n| Lady of the Flies     |                                 2.0000000000 |\n| Lady of the Flies     |                                 2.0000000000 |\n+-----------------------+----------------------------------------------+\n\nURL: https://mariadb.com/kb/en/median/','','https://mariadb.com/kb/en/median/'),
(790,'NTILE',41,'Syntax\n------\n\nNTILE (expr) OVER ( \n [ PARTITION BY partition_expression ]\n [ ORDER BY order_list ]\n)\n\nDescription\n-----------\n\nNTILE() is a window function that returns an integer indicating which group a\ngiven row falls into. The number of groups is specified in the argument\n(expr), starting at one. Ordered rows in the partition are divided into the\nspecified number of groups with as equal a size as possible.\n\nExamples\n--------\n\ncreate table t1 (\n  pk int primary key,\n  a int,\n  b int\n );\n\ninsert into t1 values\n  (11 , 0, 10),\n  (12 , 0, 10),\n  (13 , 1, 10),\n  (14 , 1, 10),\n  (18 , 2, 10),\n  (15 , 2, 20),\n  (16 , 2, 20),\n  (17 , 2, 20),\n  (19 , 4, 20),\n  (20 , 4, 20);\n\nselect pk, a, b,\n  ntile(1) over (order by pk)\n from t1;\n+----+------+------+-----------------------------+\n| pk | a    | b    | ntile(1) over (order by pk) |\n+----+------+------+-----------------------------+\n| 11 |    0 |   10 |                           1 |\n| 12 |    0 |   10 |                           1 |\n| 13 |    1 |   10 |                           1 |\n| 14 |    1 |   10 |                           1 |\n| 15 |    2 |   20 |                           1 |\n| 16 |    2 |   20 |                           1 |\n| 17 |    2 |   20 |                           1 |\n| 18 |    2 |   10 |                           1 |\n| 19 |    4 |   20 |                           1 |\n| 20 |    4 |   20 |                           1 |\n+----+------+------+-----------------------------+\n\nselect pk, a, b,\n  ntile(4) over (order by pk)\n from t1;\n+----+------+------+-----------------------------+\n| pk | a    | b    | ntile(4) over (order by pk) |\n+----+------+------+-----------------------------+\n| 11 |    0 |   10 |                           1 |\n| 12 |    0 |   10 |                           1 |\n| 13 |    1 |   10 |                           1 |\n| 14 |    1 |   10 |                           2 |\n| 15 |    2 |   20 |                           2 |\n| 16 |    2 |   20 |                           2 |\n| 17 |    2 |   20 |                           3 |\n| 18 |    2 |   10 |                           3 |\n| 19 |    4 |   20 |                           4 |\n| 20 |    4 |   20 |                           4 |\n+----+------+------+-----------------------------+\n\nURL: https://mariadb.com/kb/en/ntile/','','https://mariadb.com/kb/en/ntile/'),
(791,'PERCENT_RANK',41,'Syntax\n------\n\nPERCENT_RANK() OVER (\n [ PARTITION BY partition_expression ]\n [ ORDER BY order_list ]\n)\n\nDescription\n-----------\n\nPERCENT_RANK() is a window function that returns the relative percent rank of\na given row. The following formula is used to calculate the percent rank:\n\n(rank - 1) / (number of rows in the window or partition - 1)\n\nExamples\n--------\n\ncreate table t1 (\n pk int primary key,\n a int,\n b int\n);\n\ninsert into t1 values\n( 1 , 0, 10),\n( 2 , 0, 10),\n( 3 , 1, 10),\n( 4 , 1, 10),\n( 8 , 2, 10),\n( 5 , 2, 20),\n( 6 , 2, 20),\n( 7 , 2, 20),\n( 9 , 4, 20),\n(10 , 4, 20);\n\nselect pk, a, b,\n  rank() over (order by a) as rank,\n  percent_rank() over (order by a) as pct_rank,\n  cume_dist() over (order by a) as cume_dist\nfrom t1;\n+----+------+------+------+--------------+--------------+\n| pk | a    | b    | rank | pct_rank     | cume_dist    |\n+----+------+------+------+--------------+--------------+\n|  1 |    0 |   10 |    1 | 0.0000000000 | 0.2000000000 |\n|  2 |    0 |   10 |    1 | 0.0000000000 | 0.2000000000 |\n|  3 |    1 |   10 |    3 | 0.2222222222 | 0.4000000000 |\n|  4 |    1 |   10 |    3 | 0.2222222222 | 0.4000000000 |\n|  5 |    2 |   20 |    5 | 0.4444444444 | 0.8000000000 |\n|  6 |    2 |   20 |    5 | 0.4444444444 | 0.8000000000 |\n|  7 |    2 |   20 |    5 | 0.4444444444 | 0.8000000000 |\n|  8 |    2 |   10 |    5 | 0.4444444444 | 0.8000000000 |\n|  9 |    4 |   20 |    9 | 0.8888888889 | 1.0000000000 |\n| 10 |    4 |   20 |    9 | 0.8888888889 | 1.0000000000 |\n+----+------+------+------+--------------+--------------+\n\nselect pk, a, b,\n   percent_rank() over (order by pk) as pct_rank,\n   cume_dist() over (order by pk) as cume_dist\nfrom t1 order by pk;\n+----+------+------+--------------+--------------+\n| pk | a    | b    | pct_rank     | cume_dist    |\n+----+------+------+--------------+--------------+\n|  1 |    0 |   10 | 0.0000000000 | 0.1000000000 |\n|  2 |    0 |   10 | 0.1111111111 | 0.2000000000 |\n|  3 |    1 |   10 | 0.2222222222 | 0.3000000000 |\n|  4 |    1 |   10 | 0.3333333333 | 0.4000000000 |\n|  5 |    2 |   20 | 0.4444444444 | 0.5000000000 |\n|  6 |    2 |   20 | 0.5555555556 | 0.6000000000 |\n|  7 |    2 |   20 | 0.6666666667 | 0.7000000000 |\n|  8 |    2 |   10 | 0.7777777778 | 0.8000000000 |\n|  9 |    4 |   20 | 0.8888888889 | 0.9000000000 |\n| 10 |    4 |   20 | 1.0000000000 | 1.0000000000 |\n+----+------+------+--------------+--------------+\n\nselect pk, a, b,\n    percent_rank() over (partition by a order by a) as pct_rank,\n    cume_dist() over (partition by a order by a) as cume_dist\nfrom t1;\n+----+------+------+--------------+--------------+\n| pk | a    | b    | pct_rank     | cume_dist    |\n+----+------+------+--------------+--------------+\n|  1 |    0 |   10 | 0.0000000000 | 1.0000000000 |\n|  2 |    0 |   10 | 0.0000000000 | 1.0000000000 |\n|  3 |    1 |   10 | 0.0000000000 | 1.0000000000 |\n|  4 |    1 |   10 | 0.0000000000 | 1.0000000000 |\n|  5 |    2 |   20 | 0.0000000000 | 1.0000000000 |\n|  6 |    2 |   20 | 0.0000000000 | 1.0000000000 |\n|  7 |    2 |   20 | 0.0000000000 | 1.0000000000 |\n|  8 |    2 |   10 | 0.0000000000 | 1.0000000000 |\n|  9 |    4 |   20 | 0.0000000000 | 1.0000000000 |\n| 10 |    4 |   20 | 0.0000000000 | 1.0000000000 |\n+----+------+------+--------------+--------------+\n\nURL: https://mariadb.com/kb/en/percent_rank/','','https://mariadb.com/kb/en/percent_rank/'),
(792,'PERCENTILE_CONT',41,'MariaDB starting with 10.3.3\n----------------------------\nThe PERCENTILE_CONT() window function was first introduced with in MariaDB\n10.3.3.\n\nSyntax\n------\n\nDescription\n-----------\n\nPERCENTILE_CONT() (standing for continuous percentile) is a window function\nwhich returns a value which corresponds to the given fraction in the sort\norder. If required, it will interpolate between adjacent input items.\n\nEssentially, the following process is followed to find the value to return:\n\n* Get the number of rows in the partition, denoted by N\n* RN = p*(N-1), where p denotes the argument to the PERCENTILE_CONT function\n* calculate the FRN(floor row number) and CRN(column row number for the group(\nFRN= floor(RN) and CRN = ceil(RN))\n* look up rows FRN and CRN\n* If (CRN = FRN = RN) then the result is (value of expression from row at RN)\n* Otherwise the result is\n* (CRN - RN) * (value of expression for row at FRN) +\n* (RN - FRN) * (value of expression for row at CRN)\n\nThe MEDIAN function is a specific case of PERCENTILE_CONT, equivalent to\nPERCENTILE_CONT(0.5).\n\nExamples\n--------\n\nCREATE TABLE book_rating (name CHAR(30), star_rating TINYINT);\n\nINSERT INTO book_rating VALUES (\'Lord of the Ladybirds\', 5);\nINSERT INTO book_rating VALUES (\'Lord of the Ladybirds\', 3);\nINSERT INTO book_rating VALUES (\'Lady of the Flies\', 1);\nINSERT INTO book_rating VALUES (\'Lady of the Flies\', 2);\nINSERT INTO book_rating VALUES (\'Lady of the Flies\', 5);\n\nSELECT name, PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY star_rating) \n OVER (PARTITION BY name) AS pc\n FROM book_rating;\n+-----------------------+--------------+\n| name                  | pc           |\n+-----------------------+--------------+\n| Lord of the Ladybirds | 4.0000000000 |\n| Lord of the Ladybirds | 4.0000000000 |\n| Lady of the Flies     | 2.0000000000 |\n| Lady of the Flies     | 2.0000000000 |\n| Lady of the Flies     | 2.0000000000 |\n+-----------------------+--------------+\n\nSELECT name, PERCENTILE_CONT(1) WITHIN GROUP (ORDER BY star_rating) \n OVER (PARTITION BY name) AS pc\n FROM book_rating;\n+-----------------------+--------------+\n| name                  | pc           |\n+-----------------------+--------------+\n| Lord of the Ladybirds | 5.0000000000 |\n| Lord of the Ladybirds | 5.0000000000 |\n| Lady of the Flies     | 5.0000000000 |\n| Lady of the Flies     | 5.0000000000 |\n| Lady of the Flies     | 5.0000000000 |\n+-----------------------+--------------+\n\nSELECT name, PERCENTILE_CONT(0) WITHIN GROUP (ORDER BY star_rating) \n OVER (PARTITION BY name) AS pc\n FROM book_rating;\n+-----------------------+--------------+\n| name                  | pc           |\n+-----------------------+--------------+\n| Lord of the Ladybirds | 3.0000000000 |\n| Lord of the Ladybirds | 3.0000000000 |\n| Lady of the Flies     | 1.0000000000 |\n| Lady of the Flies     | 1.0000000000 |\n| Lady of the Flies     | 1.0000000000 |\n+-----------------------+--------------+\n\nSELECT name, PERCENTILE_CONT(0.6) WITHIN GROUP (ORDER BY star_rating) \n OVER (PARTITION BY name) AS pc\n FROM book_rating;\n+-----------------------+--------------+\n| name                  | pc           |\n+-----------------------+--------------+\n| Lord of the Ladybirds | 4.2000000000 |\n| Lord of the Ladybirds | 4.2000000000 |\n| Lady of the Flies     | 2.6000000000 |\n| Lady of the Flies     | 2.6000000000 |\n| Lady of the Flies     | 2.6000000000 |\n+-----------------------+--------------+\n\nURL: https://mariadb.com/kb/en/percentile_cont/','','https://mariadb.com/kb/en/percentile_cont/'),
(793,'PERCENTILE_DISC',41,'MariaDB starting with 10.3.3\n----------------------------\nThe PERCENTILE_DISC() window function was first introduced with in MariaDB\n10.3.3.\n\nSyntax\n------\n\nDescription\n-----------\n\nPERCENTILE_DISC() (standing for discrete percentile) is a window function\nwhich returns the first value in the set whose ordered position is the same or\nmore than the specified fraction.\n\nEssentially, the following process is followed to find the value to return:\n\n* Get the number of rows in the partition.\n* Walk through the partition, in order, until finding the the first row with\nCUME_DIST() >= function_argument.\n\nExamples\n--------\n\nCREATE TABLE book_rating (name CHAR(30), star_rating TINYINT);\n\nINSERT INTO book_rating VALUES (\'Lord of the Ladybirds\', 5);\nINSERT INTO book_rating VALUES (\'Lord of the Ladybirds\', 3);\nINSERT INTO book_rating VALUES (\'Lady of the Flies\', 1);\nINSERT INTO book_rating VALUES (\'Lady of the Flies\', 2);\nINSERT INTO book_rating VALUES (\'Lady of the Flies\', 5);\n\nSELECT name, PERCENTILE_DISC(0.5) WITHIN GROUP (ORDER BY star_rating)\n OVER (PARTITION BY name) AS pc FROM book_rating;\n+-----------------------+------+\n| name                  | pc   |\n+-----------------------+------+\n| Lord of the Ladybirds |    3 |\n| Lord of the Ladybirds |    3 |\n| Lady of the Flies     |    2 |\n| Lady of the Flies     |    2 |\n| Lady of the Flies     |    2 |\n+-----------------------+------+\n5 rows in set (0.000 sec)\n\nSELECT name, PERCENTILE_DISC(0) WITHIN GROUP (ORDER BY star_rating) \n OVER (PARTITION BY name) AS pc FROM book_rating;\n+-----------------------+------+\n| name                  | pc   |\n+-----------------------+------+\n| Lord of the Ladybirds |    3 |\n| Lord of the Ladybirds |    3 |\n| Lady of the Flies     |    1 |\n| Lady of the Flies     |    1 |\n| Lady of the Flies     |    1 |\n+-----------------------+------+\n5 rows in set (0.000 sec)\n\nSELECT name, PERCENTILE_DISC(1) WITHIN GROUP (ORDER BY star_rating) \n OVER (PARTITION BY name) AS pc FROM book_rating;\n+-----------------------+------+\n| name                  | pc   |\n+-----------------------+------+\n| Lord of the Ladybirds |    5 |\n| Lord of the Ladybirds |    5 |\n| Lady of the Flies     |    5 |\n| Lady of the Flies     |    5 |\n| Lady of the Flies     |    5 |\n+-----------------------+------+\n5 rows in set (0.000 sec)\n\nSELECT name, PERCENTILE_DISC(0.6) WITHIN GROUP (ORDER BY star_rating) \n OVER (PARTITION BY name) AS pc FROM book_rating;\n+-----------------------+------+\n| name                  | pc   |\n+-----------------------+------+\n| Lord of the Ladybirds |    5 |\n| Lord of the Ladybirds |    5 |\n| Lady of the Flies     |    2 |\n| Lady of the Flies     |    2 |\n| Lady of the Flies     |    2 |\n+-----------------------+------\n\nURL: https://mariadb.com/kb/en/percentile_disc/','','https://mariadb.com/kb/en/percentile_disc/'),
(794,'RANK',41,'Syntax\n------\n\nRANK() OVER (\n [ PARTITION BY partition_expression ]\n [ ORDER BY order_list ]\n)\n\nDescription\n-----------\n\nRANK() is a window function that displays the number of a given row, starting\nat one and following the ORDER BY sequence of the window function, with\nidentical values receiving the same result. It is similar to the ROW_NUMBER()\nfunction except that in that function, identical values will receive a\ndifferent row number for each result.\n\nExamples\n--------\n\nThe distinction between DENSE_RANK(), RANK() and ROW_NUMBER():\n\nCREATE TABLE student(course VARCHAR(10), mark int, name varchar(10));\n\nINSERT INTO student VALUES \n (\'Maths\', 60, \'Thulile\'),\n (\'Maths\', 60, \'Pritha\'),\n (\'Maths\', 70, \'Voitto\'),\n (\'Maths\', 55, \'Chun\'),\n (\'Biology\', 60, \'Bilal\'),\n (\'Biology\', 70, \'Roger\');\n\nSELECT \n RANK() OVER (PARTITION BY course ORDER BY mark DESC) AS rank,\n DENSE_RANK() OVER (PARTITION BY course ORDER BY mark DESC) AS dense_rank,\n ROW_NUMBER() OVER (PARTITION BY course ORDER BY mark DESC) AS row_num,\n course, mark, name\nFROM student ORDER BY course, mark DESC;\n+------+------------+---------+---------+------+---------+\n| rank | dense_rank | row_num | course  | mark | name    |\n+------+------------+---------+---------+------+---------+\n|    1 |          1 |       1 | Biology |   70 | Roger   |\n|    2 |          2 |       2 | Biology |   60 | Bilal   |\n|    1 |          1 |       1 | Maths   |   70 | Voitto  |\n|    2 |          2 |       2 | Maths   |   60 | Thulile |\n|    2 |          2 |       3 | Maths   |   60 | Pritha  |\n|    4 |          3 |       4 | Maths   |   55 | Chun    |\n+------+------------+---------+---------+------+---------+\n\nURL: https://mariadb.com/kb/en/rank/','','https://mariadb.com/kb/en/rank/'),
(795,'ROW_NUMBER',41,'Syntax\n------\n\nROW_NUMBER() OVER (\n [ PARTITION BY partition_expression ]\n [ ORDER BY order_list ]\n)\n\nDescription\n-----------\n\nROW_NUMBER() is a window function that displays the number of a given row,\nstarting at one and following the ORDER BY sequence of the window function,\nwith identical values receiving different row numbers. It is similar to the\nRANK() and DENSE_RANK() functions except that in that function, identical\nvalues will receive the same rank for each result.\n\nExamples\n--------\n\nThe distinction between DENSE_RANK(), RANK() and ROW_NUMBER():\n\nCREATE TABLE student(course VARCHAR(10), mark int, name varchar(10));\n\nINSERT INTO student VALUES \n (\'Maths\', 60, \'Thulile\'),\n (\'Maths\', 60, \'Pritha\'),\n (\'Maths\', 70, \'Voitto\'),\n (\'Maths\', 55, \'Chun\'),\n (\'Biology\', 60, \'Bilal\'),\n (\'Biology\', 70, \'Roger\');\n\nSELECT \n RANK() OVER (PARTITION BY course ORDER BY mark DESC) AS rank,\n DENSE_RANK() OVER (PARTITION BY course ORDER BY mark DESC) AS dense_rank,\n ROW_NUMBER() OVER (PARTITION BY course ORDER BY mark DESC) AS row_num,\n course, mark, name\nFROM student ORDER BY course, mark DESC;\n+------+------------+---------+---------+------+---------+\n| rank | dense_rank | row_num | course  | mark | name    |\n+------+------------+---------+---------+------+---------+\n|    1 |          1 |       1 | Biology |   70 | Roger   |\n|    2 |          2 |       2 | Biology |   60 | Bilal   |\n|    1 |          1 |       1 | Maths   |   70 | Voitto  |\n|    2 |          2 |       2 | Maths   |   60 | Thulile |\n|    2 |          2 |       3 | Maths   |   60 | Pritha  |\n|    4 |          3 |       4 | Maths   |   55 | Chun    |\n+------+------------+---------+---------+------+---------+\n\nURL: https://mariadb.com/kb/en/row_number/','','https://mariadb.com/kb/en/row_number/'),
(799,'SPIDER_BG_DIRECT_SQL',42,'Syntax\n------\n\nSPIDER_BG_DIRECT_SQL(\'sql\', \'tmp_table_list\', \'parameters\')\n\nDescription\n-----------\n\nExecutes the given SQL statement in the background on the remote server, as\ndefined in the parameters listing. If the query returns a result-set, it\nsttores the results in the given temporary table. When the given SQL statement\nexecutes successfully, this function returns the number of called UDF\'s. It\nreturns 0 when the given SQL statement fails.\n\nThis function is a UDF installed with the Spider storage engine.\n\nExamples\n--------\n\nSELECT SPIDER_BG_DIRECT_SQL(\'SELECT * FROM example_table\',  \'\', \n \'srv \"node1\", port \"8607\"\') AS \"Direct Query\";\n+--------------+\n| Direct Query | \n+--------------+\n|            1 |\n+--------------+\n\nParameters\n----------\n\nerror_rw_mode\n-------------\n\n* Description: Returns empty results on network error.\n0 : Return error on getting network error.\n1: Return 0 records on getting network error.\n\n* Default Table Value: 0\n* DSN Parameter Name: erwm\n\nURL: https://mariadb.com/kb/en/spider_bg_direct_sql/','','https://mariadb.com/kb/en/spider_bg_direct_sql/'),
(800,'SPIDER_COPY_TABLES',42,'Syntax\n------\n\nSPIDER_COPY_TABLES(spider_table_name, \n source_link_id, destination_link_id_list [,parameters])\n\nDescription\n-----------\n\nA UDF installed with the Spider Storage Engine, this function copies table\ndata from source_link_id to destination_link_id_list. The service does not\nneed to be stopped in order to copy.\n\nIf the Spider table is partitioned, the name must be of the format\ntable_name#P#partition_name. The partition name can be viewed in the\nmysql.spider_tables table, for example:\n\nSELECT table_name FROM mysql.spider_tables;\n+-------------+\n| table_name  |\n+-------------+\n| spt_a#P#pt1 |\n| spt_a#P#pt2 |\n| spt_a#P#pt3 |\n+-------------+\n\nReturns 1 if the data was copied successfully, or 0 if copying the data failed.\n\nURL: https://mariadb.com/kb/en/spider_copy_tables/','','https://mariadb.com/kb/en/spider_copy_tables/'),
(798,'Window Frames',41,'Syntax\n------\n\nframe_clause:\n {ROWS | RANGE} {frame_border | BETWEEN frame_border AND frame_border}\n\nframe_border:\n | UNBOUNDED PRECEDING\n | UNBOUNDED FOLLOWING\n | CURRENT ROW\n | expr PRECEDING\n | expr FOLLOWING\n\nDescription\n-----------\n\nA basic overview of window functions is described in Window Functions\nOverview. Window frames expand this functionality by allowing the function to\ninclude a specified a number of rows around the current row.\n\nThese include:\n\n* All rows before the current row (UNBOUNDED PRECEDING), for example RANGE\nBETWEEN UNBOUNDED PRECEDING AND CURRENT ROW\n* All rows after the current row (UNBOUNDED FOLLOWING), for example RANGE\nBETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING\n* A set number of rows before the current row (expr PRECEDING) for example\nRANGE BETWEEN 6 PRECEDING AND CURRENT ROW\n* A set number of rows after the current row (expr PRECEDING AND expr\nFOLLOWING)  for example RANGE BETWEEN CURRENT ROW AND 2 FOLLOWING\n* A specified number of rows both before and after the current row, for\nexample RANGE BETWEEN 6 PRECEDING AND 3 FOLLOWING\n\nThe following functions operate on window frames:\n\n* AVG\n* BIT_AND\n* BIT_OR\n* BIT_XOR\n* COUNT\n* LEAD\n* MAX\n* MIN\n* NTILE\n* STD\n* STDDEV\n* STDDEV_POP\n* STDDEV_SAMP\n* SUM\n* VAR_POP\n* VAR_SAMP\n* VARIANCE\n\nWindow frames are determined by the frame_clause in the window function\nrequest.\n\nTake the following example:\n\nCREATE TABLE `student_test` (\n name char(10),\n test char(10),\n score tinyint(4)\n);\n\nINSERT INTO student_test VALUES \n  (\'Chun\', \'SQL\', 75), (\'Chun\', \'Tuning\', 73),\n  (\'Esben\', \'SQL\', 43), (\'Esben\', \'Tuning\', 31),\n  (\'Kaolin\', \'SQL\', 56), (\'Kaolin\', \'Tuning\', 88),\n  (\'Tatiana\', \'SQL\', 87);\n\nSELECT name, test, score, SUM(score) \n OVER () AS total_score\n FROM student_test;\n+---------+--------+-------+-------------+\n| name    | test   | score | total_score |\n+---------+--------+-------+-------------+\n| Chun    | SQL    |    75 |         453 |\n| Chun    | Tuning |    73 |         453 |\n| Esben   | SQL    |    43 |         453 |\n| Esben   | Tuning |    31 |         453 |\n| Kaolin  | SQL    |    56 |         453 |\n| Kaolin  | Tuning |    88 |         453 |\n| Tatiana | SQL    |    87 |         453 |\n+---------+--------+-------+-------------+\n\nBy not specifying an OVER clause, the SUM function is run over the entire\ndataset. However, if we specify an ORDER BY condition based on score (and\norder the entire result in the same way for clarity), the following result is\nreturned:\n\nSELECT name, test, score, SUM(score) \n OVER (ORDER BY score) AS total_score\n FROM student_test ORDER BY score;\n+---------+--------+-------+-------------+\n| name    | test   | score | total_score |\n+---------+--------+-------+-------------+\n| Esben   | Tuning |    31 |          31 |\n| Esben   | SQL    |    43 |          74 |\n| Kaolin  | SQL    |    56 |         130 |\n| Chun    | Tuning |    73 |         203 |\n| Chun    | SQL    |    75 |         278 |\n| Tatiana | SQL    |    87 |         365 |\n| Kaolin  | Tuning |    88 |         453 |\n+---------+--------+-------+-------------+\n\nThe total_score column represents a running total of the current row, and all\nprevious rows. The window frame in this example expands as the function\nproceeds.\n\nThe above query makes use of the default to define the window frame. It could\nbe written explicitly as follows:\n\nSELECT name, test, score, SUM(score) \n OVER (ORDER BY score RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS\ntotal_score \n FROM student_test ORDER BY score;\n+---------+--------+-------+-------------+\n| name    | test   | score | total_score |\n+---------+--------+-------+-------------+\n| Esben   | Tuning |    31 |          31 |\n| Esben   | SQL    |    43 |          74 |\n| Kaolin  | SQL    |    56 |         130 |\n| Chun    | Tuning |    73 |         203 |\n| Chun    | SQL    |    75 |         278 |\n| Tatiana | SQL    |    87 |         365 |\n| Kaolin  | Tuning |    88 |         453 |\n+---------+--------+-------+-------------+\n\nLet\'s look at some alternatives:\n\nFirstly, applying the window function to the current row and all following\nrows can be done with the use of UNBOUNDED FOLLOWING:\n\nSELECT name, test, score, SUM(score) \n OVER (ORDER BY score RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) AS\ntotal_score \n FROM student_test ORDER BY score;\n+---------+--------+-------+-------------+\n| name    | test   | score | total_score |\n+---------+--------+-------+-------------+\n| Esben   | Tuning |    31 |         453 |\n| Esben   | SQL    |    43 |         422 |\n| Kaolin  | SQL    |    56 |         379 |\n| Chun    | Tuning |    73 |         323 |\n| Chun    | SQL    |    75 |         250 |\n| Tatiana | SQL    |    87 |         175 |\n| Kaolin  | Tuning |    88 |          88 |\n+---------+--------+-------+-------------+\n\nIt\'s possible to specify a number of rows, rather than the entire unbounded\nfollowing or preceding set. The following example takes the current row, as\nwell as the previous row:\n\nSELECT name, test, score, SUM(score) \n OVER (ORDER BY score ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) AS\ntotal_score \n FROM student_test ORDER BY score;\n+---------+--------+-------+-------------+\n| name    | test   | score | total_score |\n+---------+--------+-------+-------------+\n| Esben   | Tuning |    31 |          31 |\n| Esben   | SQL    |    43 |          74 |\n| Kaolin  | SQL    |    56 |          99 |\n| Chun    | Tuning |    73 |         129 |\n| Chun    | SQL    |    75 |         148 |\n| Tatiana | SQL    |    87 |         162 |\n| Kaolin  | Tuning |    88 |         175 |\n+---------+--------+-------+-------------+\n\nThe current row and the following row:\n\nSELECT name, test, score, SUM(score) \n OVER (ORDER BY score ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) AS\ntotal_score \n FROM student_test ORDER BY score;\n+---------+--------+-------+-------------+\n| name    | test   | score | total_score |\n+---------+--------+-------+-------------+\n| Esben   | Tuning |    31 |          74 |\n| Esben   | SQL    |    43 |         130 |\n| Kaolin  | SQL    |    56 |         172 |\n| Chun    | Tuning |    73 |         204 |\n| Chun    | SQL    |    75 |         235 |\n| Tatiana | SQL    |    87 |         250 |\n| Kaolin  | Tuning |    88 |         175 |\n+---------+--------+-------+-------------+\n\nURL: https://mariadb.com/kb/en/window-frames/','','https://mariadb.com/kb/en/window-frames/'),
(801,'SPIDER_DIRECT_SQL',42,'Syntax\n------\n\nSPIDER_DIRECT_SQL(\'sql\', \'tmp_table_list\', \'parameters\')\n\nDescription\n-----------\n\nA UDF installed with the Spider Storage Engine, this function is used to\nexecute the SQL string sql on the remote server, as defined in parameters. If\nany resultsets are returned, they are stored in the tmp_table_list.\n\nThe function returns 1 if the SQL executes successfully, or 0 if it fails.\n\nExamples\n--------\n\nSELECT SPIDER_DIRECT_SQL(\'SELECT * FROM s\', \'\', \'srv \"node1\", port \"8607\"\');\n+----------------------------------------------------------------------+\n| SPIDER_DIRECT_SQL(\'SELECT * FROM s\', \'\', \'srv \"node1\", port \"8607\"\') |\n+----------------------------------------------------------------------+\n|                                                                    1 |\n+----------------------------------------------------------------------+\n\nURL: https://mariadb.com/kb/en/spider_direct_sql/','','https://mariadb.com/kb/en/spider_direct_sql/'),
(803,'COLUMN_ADD',43,'Syntax\n------\n\nCOLUMN_ADD(dyncol_blob, column_nr, value [as type], [column_nr, value [as\ntype]]...);\nCOLUMN_ADD(dyncol_blob, column_name, value [as type], [column_name, value [as\ntype]]...);\n\nDescription\n-----------\n\nAdds or updates dynamic columns.\n\n* dyncol_blob must be either a valid dynamic columns blob (for example,\nCOLUMN_CREATE returns such blob), or an empty string.\n* column_name specifies the name of the column to be added. If dyncol_blob\nalready has a column with this name, it will be overwritten.\n* value specifies the new value for the column.  Passing a NULL value will\ncause the column to be deleted.\n* as type is optional. See #datatypes section for a discussion about types.\n\nThe return value is a dynamic column blob after the modifications.\n\nExamples\n--------\n\nUPDATE t1 SET dyncol_blob=COLUMN_ADD(dyncol_blob, \"column_name\", \"value\")\nWHERE id=1;\n\nNote: COLUMN_ADD() is a regular function (just like CONCAT()), hence, in order\nto update the value in the table you have to use the UPDATE ... SET\ndynamic_col=COLUMN_ADD(dynamic_col, ....) pattern.\n\nURL: https://mariadb.com/kb/en/column_add/','','https://mariadb.com/kb/en/column_add/'),
(805,'COLUMN_CREATE',43,'Syntax\n------\n\nCOLUMN_CREATE(column_nr, value [as type], [column_nr, value [as type]]...);\nCOLUMN_CREATE(column_name, value [as type], [column_name, value [as type]]...);\n\nDescription\n-----------\n\nReturns a dynamic columns blob that stores the specified columns with values.\n\nThe return value is suitable for\n\n* storing in a table\n* further modification with other dynamic columns functions\n\nThe as type part allows one to specify the value type. In most cases, this is\nredundant because MariaDB will be able to deduce the type of the value.\nExplicit type specification may be needed when the type of the value is not\napparent. For example, a literal \'2012-12-01\' has a CHAR type by default, one\nwill need to specify \'2012-12-01\' AS DATE to have it stored as a date. See\nDynamic Columns:Datatypes for further details.\n\nExamples\n--------\n\nINSERT INTO tbl SET dyncol_blob=COLUMN_CREATE(\"column_name\", \"value\");\n\nURL: https://mariadb.com/kb/en/column_create/','','https://mariadb.com/kb/en/column_create/'),
(808,'COLUMN_GET',43,'Syntax\n------\n\nCOLUMN_GET(dyncol_blob, column_nr as type);\nCOLUMN_GET(dyncol_blob, column_name as type);\n\nDescription\n-----------\n\nGets the value of a dynamic column by its name. If no column with the given\nname exists, NULL will be returned.\n\ncolumn_name as type requires that one specify the datatype of the dynamic\ncolumn they are reading.\n\nThis may seem counter-intuitive: why would one need to specify which datatype\nthey\'re retrieving? Can\'t the dynamic columns system figure the datatype from\nthe data being stored?\n\nThe answer is: SQL is a statically-typed language. The SQL interpreter needs\nto know the datatypes of all expressions before the query is run (for example,\nwhen one is using prepared statements and runs \"select COLUMN_GET(...)\", the\nprepared statement API requires the server to inform the client about the\ndatatype of the column being read before the query is executed and the server\ncan see what datatype the column actually has).\n\nLengths\n-------\n\nIf you\'re running queries like:\n\nSELECT COLUMN_GET(blob, \'colname\' as CHAR) ...\n\nwithout specifying a maximum length (i.e. using as CHAR, not as CHAR(n)),\nMariaDB will report the maximum length of the resultset column to be\n16,777,216. This may cause excessive memory usage in some client libraries,\nbecause they try to pre-allocate a buffer of maximum resultset width. To avoid\nthis problem, use CHAR(n) whenever you\'re using COLUMN_GET in the select list.\n\nSee Dynamic Columns:Datatypes for more information about datatypes.\n\nURL: https://mariadb.com/kb/en/column_get/','','https://mariadb.com/kb/en/column_get/'),
(809,'COLUMN_JSON',43,'Syntax\n------\n\nCOLUMN_JSON(dyncol_blob)\n\nDescription\n-----------\n\nReturns a JSON representation of data in dyncol_blob. Can also be used to\ndisplay nested columns. See dynamic columns for more information.\n\nExample\n-------\n\nselect item_name, COLUMN_JSON(dynamic_cols) from assets;\n+-----------------+----------------------------------------+\n| item_name       | COLUMN_JSON(dynamic_cols)              |\n+-----------------+----------------------------------------+\n| MariaDB T-shirt | {\"size\":\"XL\",\"color\":\"blue\"}           |\n| Thinkpad Laptop | {\"color\":\"black\",\"warranty\":\"3 years\"} |\n+-----------------+----------------------------------------+\n\nLimitation: COLUMN_JSON will decode nested dynamic columns at a nesting level\nof not more than 10 levels deep. Dynamic columns that are nested deeper than\n10 levels will be shown as BINARY string, without encoding.\n\nURL: https://mariadb.com/kb/en/column_json/','','https://mariadb.com/kb/en/column_json/'),
(813,'WSREP_SYNC_WAIT_UPTO_GTID',44,'MariaDB starting with 10.4.2\n----------------------------\nWSREP_SYNC_WAIT_UPTO_GTID was added as part of Galera 4 in MariaDB 10.4.2.\n\nSyntax\n------\n\nWSREP_SYNC_WAIT_UPTO_GTID(gtid[,timeout])\n\nDescription\n-----------\n\nBlocks the client until the transaction specified by the given Global\nTransaction ID is applied and committed by the node.\n\nThe optional timeout argument can be used to specify a block timeout in\nseconds. If not provided, the timeout will be indefinite.\n\nReturns the node that applied and committed the Global Transaction ID,\nER_LOCAL_WAIT_TIMEOUT if the function is timed out before this, or\nER_WRONG_ARGUMENTS if the function is given an invalid GTID.\n\nThe result from WSREP_LAST_SEEN_GTID can be useful to determine the\ntransaction to provide to WSREP_SYNC_WAIT_UPTO_GTID for waiting and unblocking\npurposes.\n\nURL: https://mariadb.com/kb/en/wsrep_sync_wait_upto_gtid/','','https://mariadb.com/kb/en/wsrep_sync_wait_upto_gtid/'),
(816,'Bitemporal Tables',45,'MariaDB starting with 10.4.3\n----------------------------\nBitemporal tables are tables that use versioning both at the system and\napplication-time period levels.\n\nUsing Bitemporal Tables\n-----------------------\n\nTo create a bitemporal table, use:\n\nCREATE TABLE test.t3 (\n date_1 DATE,\n date_2 DATE,\n row_start TIMESTAMP(6) AS ROW START INVISIBLE,\n row_end TIMESTAMP(6) AS ROW END INVISIBLE,\n PERIOD FOR application_time(date_1, date_2),\n PERIOD FOR system_time(row_start, row_end))\nWITH SYSTEM VERSIONING;\n\nNote that, while system_time here is also a time period, it cannot be used in\nDELETE FOR PORTION or UPDATE FOR PORTION statements.\n\nDELETE FROM test.t3 \nFOR PORTION OF system_time \n  FROM \'2000-01-01\' TO \'2018-01-01\';\nERROR 42000: You have an error in your SQL syntax; check the manual that\ncorresponds \n to your MariaDB server version for the right syntax to use near\n \'of system_time from \'2000-01-01\' to \'2018-01-01\'\' at line 1\n\nURL: https://mariadb.com/kb/en/bitemporal-tables/','','https://mariadb.com/kb/en/bitemporal-tables/'),
(818,'ST_GeomFromGeoJSON',46,'MariaDB starting with 10.2.4\n----------------------------\nST_GeomFromGeoJSON was added in MariaDB 10.2.4\n\nSyntax\n------\n\nST_GeomFromGeoJSON(g[, option])\n\nDescription\n-----------\n\nGiven a GeoJSON input g, returns a geometry object. The option specifies what\nto do if g contains geometries with coordinate dimensions higher than 2.\n\n+---------------------------+------------------------------------------------+\n| Option                    | Description                                    |\n+---------------------------+------------------------------------------------+\n| 1                         | Return an error (the default)                  |\n+---------------------------+------------------------------------------------+\n| 2 - 4                     | The document is accepted, but the coordinates  |\n|                           | for higher coordinate dimensions are stripped  |\n|                           | off.                                           |\n+---------------------------+------------------------------------------------+\n\nNote that this function did not work correctly before MariaDB 10.2.8 - see\nMDEV-12180.\n\nExamples\n--------\n\nSET @j = \'{ \"type\": \"Point\", \"coordinates\": [5.3, 15.0]}\';\n\nSELECT ST_AsText(ST_GeomFromGeoJSON(@j));\n+-----------------------------------+\n| ST_AsText(ST_GeomFromGeoJSON(@j)) |\n+-----------------------------------+\n| POINT(5.3 15)                     |\n+-----------------------------------+\n\nURL: https://mariadb.com/kb/en/st_geomfromgeojson/','','https://mariadb.com/kb/en/st_geomfromgeojson/'),
(819,'Operator Precedence',47,'The precedence is the order in which the SQL operators are evaluated.\n\nThe following list shows the SQL operator precedence. Operators that appear\nfirst in the list have a higher precedence. Operators which are listed\ntogether have the same precedence.\n\n* INTERVAL\n* BINARY, COLLATE\n* !\n* - (unary minus), [[bitwise-not|]] (unary bit inversion)\n* || (string concatenation)\n* ^\n* *, /, DIV, %, MOD\n* -, +\n* <<, >>\n* &\n* |\n* = (comparison), <=>, >=, >, <=, <, <>, !=, IS, LIKE, REGEXP, IN\n* BETWEEN, CASE, WHEN, THEN, ELSE, END\n* NOT\n* &&, AND\n* XOR\n* || (logical or), OR\n* = (assignment), :=\n\nFunctions precedence is always higher than operators precedence.\n\nIn this page CASE refers to the CASE operator, not to the CASE statement.\n\nIf the HIGH_NOT_PRECEDENCE SQL_MODE is set, NOT has the same precedence as !.\n\nThe || operator\'s precedence, as well as its meaning, depends on the\nPIPES_AS_CONCAT SQL_MODE flag: if it is on, || can be used to concatenate\nstrings (like the CONCAT() function) and has a higher precedence.\n\nThe = operator\'s precedence depends on the context - it is higher when = is\nused as a comparison operator.\n\nParenthesis can be used to modify the operators precedence in an expression.\n\nShort-circuit evaluation\n------------------------\n\nThe AND, OR, && and || operators support short-circuit evaluation. This means\nthat, in some cases, the expression on the right of those operators is not\nevaluated, because its result cannot affect the result. In the following\ncases, short-circuit evaluation is used and x() is not evaluated:\n\n* FALSE AND x()\n* FALSE && x()\n* TRUE OR x()\n* TRUE || x()\n* NULL BETWEEN x() AND x()\n\nNote however that the short-circuit evaluation does not apply to NULL AND x().\nAlso, BETWEEN\'s right operands are not evaluated if the left operand is NULL,\nbut in all other cases all the operands are evaluated.\n\nThis is a speed optimization. Also, since functions can have side-effects,\nthis behavior can be used to choose whether execute them or not using a\nconcise syntax:\n\nSELECT some_function() OR log_error();\n\nURL: https://mariadb.com/kb/en/operator-precedence/','','https://mariadb.com/kb/en/operator-precedence/'),
(821,'Division Operator (/)',48,'Syntax\n------\n\n/\n\nDescription\n-----------\n\nDivision operator. Dividing by zero will return NULL. By default, returns four\ndigits after the decimal. This is determined by the server system variable\ndiv_precision_increment which by default is four. It can be set from 0 to 30.\n\nDividing by zero returns NULL. If the ERROR_ON_DIVISION_BY_ZERO SQL_MODE is\nused (the default since MariaDB 10.2.4), a division by zero also produces a\nwarning.\n\nExamples\n--------\n\nSELECT 4/5;\n+--------+\n| 4/5    |\n+--------+\n| 0.8000 |\n+--------+\n\nSELECT 300/(2-2);\n+-----------+\n| 300/(2-2) |\n+-----------+\n|      NULL |\n+-----------+\n\nSELECT 300/7;\n+---------+\n| 300/7   |\n+---------+\n| 42.8571 |\n+---------+\n\nChanging div_precision_increment for the session from the default of four to\nsix:\n\nSET div_precision_increment = 6;\n\nSELECT 300/7;\n+-----------+\n| 300/7     |\n+-----------+\n| 42.857143 |\n+-----------+\n\nSELECT 300/7;\n+-----------+\n| 300/7     |\n+-----------+\n| 42.857143 |\n+-----------+\n\nURL: https://mariadb.com/kb/en/division-operator/','','https://mariadb.com/kb/en/division-operator/'),
(823,'Multiplication Operator (*)',48,'Syntax\n------\n\n*\n\nDescription\n-----------\n\nMultiplication operator.\n\nExamples\n--------\n\nSELECT 7*6;\n+-----+\n| 7*6 |\n+-----+\n|  42 |\n+-----+\n\nSELECT 1234567890*9876543210;\n+-----------------------+\n| 1234567890*9876543210 |\n+-----------------------+\n|  -6253480962446024716 |\n+-----------------------+\n\nSELECT 18014398509481984*18014398509481984.0;\n+---------------------------------------+\n| 18014398509481984*18014398509481984.0 |\n+---------------------------------------+\n|   324518553658426726783156020576256.0 |\n+---------------------------------------+\n\nSELECT 18014398509481984*18014398509481984;\n+-------------------------------------+\n| 18014398509481984*18014398509481984 |\n+-------------------------------------+\n|                                   0 |\n+-------------------------------------+\n\nURL: https://mariadb.com/kb/en/multiplication-operator/','','https://mariadb.com/kb/en/multiplication-operator/'),
(824,'Subtraction Operator (-)',48,'Syntax\n------\n\n-\n\nDescription\n-----------\n\nSubtraction. The operator is also used as the unary minus for changing sign.\n\nIf both operands are integers, the result is calculated with BIGINT precision.\nIf either integer is unsigned, the result is also an unsigned integer, unless\nthe NO_UNSIGNED_SUBTRACTION SQL_MODE is enabled, in which case the result is\nalways signed.\n\nFor real or string operands, the operand with the highest precision determines\nthe result precision.\n\nExamples\n--------\n\nSELECT 96-9;\n+------+\n| 96-9 |\n+------+\n|   87 |\n+------+\n\nSELECT 15-17;\n+-------+\n| 15-17 |\n+-------+\n|    -2 |\n+-------+\n\nSELECT 3.66 + 1.333;\n+--------------+\n| 3.66 + 1.333 |\n+--------------+\n|        4.993 |\n+--------------+\n\nUnary minus:\n\nSELECT - (3+5);\n+---------+\n| - (3+5) |\n+---------+\n|      -8 |\n+---------+\n\nURL: https://mariadb.com/kb/en/subtraction-operator-/','','https://mariadb.com/kb/en/subtraction-operator-/'),
(827,'STOP SLAVE',49,'The terms master and slave have historically been used in replication, but the\nterms terms primary and replica are now preferred. The old terms are used\nstill used in parts of the documentation, and in MariaDB commands, although\nMariaDB 10.5 has begun the process of renaming. The documentation process is\nongoing. See MDEV-18777 to follow progress on this effort.\n\nSyntax\n------\n\nSTOP SLAVE [\"connection_name\"] [thread_type [, thread_type] ... ] [FOR CHANNEL\n\"connection_name\"]\n\nSTOP ALL SLAVES [thread_type [, thread_type]]\n\nSTOP REPLICA [\"connection_name\"] [thread_type [, thread_type] ... ] -- from\n10.5.1\n\nSTOP ALL REPLICAS [thread_type [, thread_type]] -- from 10.5.1\n\nthread_type: IO_THREAD | SQL_THREAD\n\nDescription\n-----------\n\nStops the replica threads. STOP SLAVE requires the SUPER privilege, or, from\nMariaDB 10.5.2, the REPLICATION SLAVE ADMIN privilege.\n\nLike START SLAVE, this statement may be used with the IO_THREAD and SQL_THREAD\noptions to name the thread or threads to be stopped. In almost all cases, one\nnever need to use the thread_type options.\n\nSTOP SLAVE waits until any current replication event group affecting one or\nmore non-transactional tables has finished executing (if there is any such\nreplication group), or until the user issues a KILL QUERY or KILL CONNECTION\nstatement.\n\nNote that STOP SLAVE doesn\'t delete the connection permanently. Next time you\nexecute START SLAVE or the MariaDB server restarts, the replica connection is\nrestored with it\'s original arguments. If you want to delete a connection, you\nshould execute RESET SLAVE.\n\nSTOP ALL SLAVES\n---------------\n\nSTOP ALL SLAVES stops all your running replicas. It will give you a note for\nevery stopped connection. You can check the notes with SHOW WARNINGS.\n\nconnection_name\n---------------\n\nThe connection_name option is used for multi-source replication.\n\nIf there is only one nameless master, or the default master (as specified by\nthe default_master_connection system variable) is intended, connection_name\ncan be omitted. If provided, the STOP SLAVE statement will apply to the\nspecified master. connection_name is case-insensitive.\n\nMariaDB starting with 10.7.0\n----------------------------\nThe FOR CHANNEL keyword was added for MySQL compatibility. This is identical\nas using the channel_name directly after STOP SLAVE.\n\nSTOP REPLICA\n------------\n\nMariaDB starting with 10.5.1\n----------------------------\nSTOP REPLICA is an alias for STOP SLAVE from MariaDB 10.5.1.\n\nURL: https://mariadb.com/kb/en/stop-replica/','','https://mariadb.com/kb/en/stop-replica/'),
(826,'START SLAVE',49,'The terms master and slave have historically been used in replication, but the\nterms terms primary and replica are now preferred. The old terms are used\nstill used in parts of the documentation, and in MariaDB commands, although\nMariaDB 10.5 has begun the process of renaming. The documentation process is\nongoing. See MDEV-18777 to follow progress on this effort.\n\nSyntax\n------\n\nSTART SLAVE [\"connection_name\"] [thread_type [, thread_type] ... ] [FOR\nCHANNEL \"connection_name\"]\nSTART SLAVE [\"connection_name\"] [SQL_THREAD] UNTIL                \n  MASTER_LOG_FILE = \'log_name\', MASTER_LOG_POS = log_pos [FOR CHANNEL\n\"connection_name\"]\nSTART SLAVE [\"connection_name\"] [SQL_THREAD] UNTIL\n  RELAY_LOG_FILE = \'log_name\', RELAY_LOG_POS = log_pos [FOR CHANNEL\n\"connection_name\"]\nSTART SLAVE [\"connection_name\"] [SQL_THREAD] UNTIL\n  MASTER_GTID_POS = <GTID position> [FOR CHANNEL \"connection_name\"]\nSTART ALL SLAVES [thread_type [, thread_type]]\n\nSTART REPLICA [\"connection_name\"] [thread_type [, thread_type] ... ] -- from\n10.5.1\nSTART REPLICA [\"connection_name\"] [SQL_THREAD] UNTIL                \n  MASTER_LOG_FILE = \'log_name\', MASTER_LOG_POS = log_pos -- from 10.5.1\nSTART REPLICA [\"connection_name\"] [SQL_THREAD] UNTIL\n  RELAY_LOG_FILE = \'log_name\', RELAY_LOG_POS = log_pos -- from 10.5.1\nSTART REPLICA [\"connection_name\"] [SQL_THREAD] UNTIL\n  MASTER_GTID_POS = <GTID position> -- from 10.5.1\nSTART ALL REPLICAS [thread_type [, thread_type]] -- from 10.5.1\n\nthread_type: IO_THREAD | SQL_THREAD\n\nDescription\n-----------\n\nSTART SLAVE (START REPLICA from MariaDB 10.5.1) with no thread_type options\nstarts both of the replica threads (see replication). The I/O thread reads\nevents from the primary server and stores them in the relay log. The SQL\nthread reads events from the relay log and executes them. START SLAVE requires\nthe SUPER privilege, or, from MariaDB 10.5.2, the REPLICATION SLAVE ADMIN\nprivilege.\n\nIf START SLAVE succeeds in starting the replica threads, it returns without\nany error. However, even in that case, it might be that the replica threads\nstart and then later stop (for example, because they do not manage to connect\nto the primary or read its binary log, or some other problem). START SLAVE\ndoes not warn you about this. You must check the replica\'s error log for error\nmessages generated by the replica threads, or check that they are running\nsatisfactorily with SHOW SLAVE STATUS (SHOW REPLICA STATUS from MariaDB\n10.5.1).\n\nSTART SLAVE UNTIL\n-----------------\n\nSTART SLAVE UNTIL refers to the SQL_THREAD replica position at which the\nSQL_THREAD replication will halt. If SQL_THREAD isn\'t specified both threads\nare started.\n\nSTART SLAVE UNTIL master_gtid_pos=xxx is also supported. See Global\nTransaction ID/START SLAVE UNTIL master_gtid_pos=xxx for more details.\n\nconnection_name\n---------------\n\nIf there is only one nameless primary, or the default primary (as specified by\nthe default_master_connection system variable) is intended, connection_name\ncan be omitted. If provided, the START SLAVE statement will apply to the\nspecified primary. connection_name is case-insensitive.\n\nMariaDB starting with 10.7.0\n----------------------------\nThe FOR CHANNEL keyword was added for MySQL compatibility. This is identical\nas using the channel_name directly after START SLAVE.\n\nSTART ALL SLAVES\n----------------\n\nSTART ALL SLAVES starts all configured replicas (replicas with master_host not\nempty) that were not started before. It will give a note for all started\nconnections. You can check the notes with SHOW WARNINGS.\n\nSTART REPLICA\n-------------\n\nMariaDB starting with 10.5.1\n----------------------------\nSTART REPLICA is an alias for START SLAVE from MariaDB 10.5.1.\n\nURL: https://mariadb.com/kb/en/start-replica/','','https://mariadb.com/kb/en/start-replica/'),
(828,'RESET REPLICA/SLAVE',49,'The terms master and slave have historically been used in replication, but the\nterms terms primary and replica are now preferred. The old terms are used\nstill used in parts of the documentation, and in MariaDB commands, although\nMariaDB 10.5 has begun the process of renaming. The documentation process is\nongoing. See MDEV-18777 to follow progress on this effort.\n\nSyntax\n------\n\nRESET REPLICA [\"connection_name\"] [ALL]  [FOR CHANNEL \"connection_name\"] --\nfrom MariaDB 10.5.1         \nRESET SLAVE [\"connection_name\"] [ALL]  [FOR CHANNEL \"connection_name\"]\n\nDescription\n-----------\n\nRESET REPLICA/SLAVE makes the replica forget its replication position in the\nmaster\'s binary log. This statement is meant to be used for a clean start. It\ndeletes the master.info and relay-log.info files, all the relay log files, and\nstarts a new relay log file. To use RESET REPLICA/SLAVE, the replica threads\nmust be stopped (use STOP REPLICA/SLAVE if necessary).\n\nNote: All relay log files are deleted, even if they have not been completely\nexecuted by the slave SQL thread. (This is a condition likely to exist on a\nreplication slave if you have issued a STOP REPLICA/SLAVE statement or if the\nslave is highly loaded.)\n\nNote: RESET REPLICA does not reset the global gtid_slave_pos variable. This\nmeans that a replica server configured with CHANGE MASTER TO\nMASTER_USE_GTID=slave_pos will not receive events with GTIDs occurring before\nthe state saved in gtid_slave_pos. If the intent is to reprocess these events,\ngtid_slave_pos must be manually reset, e.g. by executing set global\ngtid_slave_pos=\"\".\n\nConnection information stored in the master.info file is immediately reset\nusing any values specified in the corresponding startup options. This\ninformation includes values such as master host, master port, master user, and\nmaster password. If the replica SQL thread was in the middle of replicating\ntemporary tables when it was stopped, and RESET REPLICA/SLAVE is issued, these\nreplicated temporary tables are deleted on the slave.\n\nThe ALL also resets the PORT, HOST, USER and PASSWORD parameters for the\nslave. If you are using a connection name, it will permanently delete it and\nit will not show up anymore in SHOW ALL REPLICAS/SLAVE STATUS.\n\nconnection_name\n---------------\n\nThe connection_name option is used for multi-source replication.\n\nIf there is only one nameless primary, or the default primary (as specified by\nthe default_master_connection system variable) is intended, connection_name\ncan be omitted. If provided, the RESET REPLICA/SLAVE statement will apply to\nthe specified primary. connection_name is case-insensitive.\n\nMariaDB starting with 10.7.0\n----------------------------\nThe FOR CHANNEL keyword was added for MySQL compatibility. This is identical\nas using the channel_name directly after RESET REPLICA.\n\nRESET REPLICA\n-------------\n\nMariaDB starting with 10.5.1\n----------------------------\nRESET REPLICA is an alias for RESET SLAVE from MariaDB 10.5.1.\n\nURL: https://mariadb.com/kb/en/reset-replica/','','https://mariadb.com/kb/en/reset-replica/'),
(830,'EXECUTE Statement',50,'Syntax\n------\n\nEXECUTE stmt_name\n  [USING expression[, expression] ...]\n\nMariaDB starting with 10.2.3\n----------------------------\nEXECUTE with expression as parameters was introduced in MariaDB 10.2.3. Before\nthat one could only use variables (@var_name) as parameters.\n\nDescription\n-----------\n\nAfter preparing a statement with PREPARE, you execute it with an EXECUTE\nstatement that refers to the prepared statement name. If the prepared\nstatement contains any parameter markers, you must supply a USING clause that\nlists user variables containing the values to be bound to the parameters.\nParameter values can be supplied only by user variables, and the USING clause\nmust name exactly as many variables as the number of parameter markers in the\nstatement.\n\nYou can execute a given prepared statement multiple times, passing different\nvariables to it or setting the variables to different values before each\nexecution.\n\nIf the specified statement has not been PREPAREd, an error similar to the\nfollowing is produced:\n\nERROR 1243 (HY000): Unknown prepared statement handler (stmt_name) given to\nEXECUTE\n\nExample\n-------\n\nSee example in PREPARE.\n\nURL: https://mariadb.com/kb/en/execute-statement/','','https://mariadb.com/kb/en/execute-statement/'),
(832,'DEALLOCATE / DROP PREPARE',50,'Syntax\n------\n\n{DEALLOCATE | DROP} PREPARE stmt_name\n\nDescription\n-----------\n\nTo deallocate a prepared statement produced with PREPARE, use a DEALLOCATE\nPREPARE statement that refers to the prepared statement name.\n\nA prepared statement is implicitly deallocated when a new PREPARE command is\nissued. In that case, there is no need to use DEALLOCATE.\n\nAttempting to execute a prepared statement after deallocating it results in an\nerror, as if it was not prepared at all:\n\nERROR 1243 (HY000): Unknown prepared statement handler (stmt_name) given to\nEXECUTE\n\nIf the specified statement has not been PREPAREd, an error similar to the\nfollowing will be produced:\n\nERROR 1243 (HY000): Unknown prepared statement handler (stmt_name) given to\nDEALLOCATE PREPARE\n\nExample\n-------\n\nSee example in PREPARE.\n\nURL: https://mariadb.com/kb/en/deallocate-drop-prepare/','','https://mariadb.com/kb/en/deallocate-drop-prepare/'),
(833,'EXECUTE IMMEDIATE',50,'MariaDB starting with 10.2.3\n----------------------------\nEXECUTE IMMEDIATE was introduced in MariaDB 10.2.3.\n\nSyntax\n------\n\nEXECUTE IMMEDIATE statement\n\nDescription\n-----------\n\nEXECUTE IMMEDIATE executes a dynamic SQL statement created on the fly, which\ncan reduce performance overhead.\n\nFor example:\n\nEXECUTE IMMEDIATE \'SELECT 1\'\n\nwhich is shorthand for:\n\nprepare stmt from \"select 1\";\nexecute stmt;\ndeallocate prepare stmt;\n\nEXECUTE IMMEDIATE supports complex expressions as prepare source and\nparameters:\n\nEXECUTE IMMEDIATE CONCAT(\'SELECT COUNT(*) FROM \', \'t1\', \' WHERE a=?\') USING\n5+5;\n\nLimitations: subselects and stored function calls are not supported as a\nprepare source.\n\nThe following examples return an error:\n\nCREATE OR REPLACE FUNCTION f1() RETURNS VARCHAR(64) RETURN \'SELECT * FROM t1\';\nEXECUTE IMMEDIATE f1();\nERROR 1970 (42000): EXECUTE IMMEDIATE does not support subqueries or stored\nfunctions\n\nEXECUTE IMMEDIATE (SELECT \'SELECT * FROM t1\');\nERROR 1064 (42000): You have an error in your SQL syntax; check the manual\nthat \n corresponds to your MariaDB server version for the right syntax to use near\n \'SELECT \'SELECT * FROM t1\')\' at line 1\n\nCREATE OR REPLACE FUNCTION f1() RETURNS INT RETURN 10;\nEXECUTE IMMEDIATE \'SELECT * FROM t1 WHERE a=?\' USING f1();\nERROR 1970 (42000): EXECUTE..USING does not support subqueries or stored\nfunctions\n\nEXECUTE IMMEDIATE \'SELECT * FROM t1 WHERE a=?\' USING (SELECT 10);\nERROR 1064 (42000): You have an error in your SQL syntax; check the manual\nthat \n corresponds to your MariaDB server version for the right syntax to use near\n \'SELECT 10)\' at line 1\n\nOne can use a user or an SP variable as a workaround:\n\nCREATE OR REPLACE FUNCTION f1() RETURNS VARCHAR(64) RETURN \'SELECT * FROM t1\';\nSET @stmt=f1();\nEXECUTE IMMEDIATE @stmt;\n\nSET @stmt=(SELECT \'SELECT 1\');\nEXECUTE IMMEDIATE @stmt;\n\nCREATE OR REPLACE FUNCTION f1() RETURNS INT RETURN 10;\nSET @param=f1();\nEXECUTE IMMEDIATE \'SELECT * FROM t1 WHERE a=?\' USING @param;\n\nSET @param=(SELECT 10);\nEXECUTE IMMEDIATE \'SELECT * FROM t1 WHERE a=?\' USING @param;\n\nEXECUTE IMMEDIATE supports user variables and SP variables as OUT parameters\n\nDELIMITER $$\nCREATE OR REPLACE PROCEDURE p1(OUT a INT)\nBEGIN\n SET a:= 10;\nEND;\n$$\nDELIMITER ;\nSET @a=2;\nEXECUTE IMMEDIATE \'CALL p1(?)\' USING @a;\nSELECT @a;\n+------+\n| @a   |\n+------+\n|   10 |\n+------+\n\nSimilar to PREPARE, EXECUTE IMMEDIATE is allowed in stored procedures but is\nnot allowed in stored functions.\n\nThis example uses EXECUTE IMMEDIATE inside a stored procedure:\n\nDELIMITER $$\nCREATE OR REPLACE PROCEDURE p1()\nBEGIN\n EXECUTE IMMEDIATE \'SELECT 1\';\nEND;\n$$\nDELIMITER ;\nCALL p1;\n+---+\n| 1 |\n+---+\n| 1 |\n+---+\n\nThis script returns an error:\n\nDELIMITER $$\nCREATE FUNCTION f1() RETURNS INT\nBEGIN\n EXECUTE IMMEDIATE \'DO 1\';\n RETURN 1;\nEND;\n$$\nERROR 1336 (0A000): Dynamic SQL is not allowed in stored function or trigger\n\nEXECUTE IMMEDIATE can use DEFAULT and IGNORE indicators as bind parameters:\n\nCREATE OR REPLACE TABLE t1 (a INT DEFAULT 10);\nEXECUTE IMMEDIATE \'INSERT INTO t1 VALUES (?)\' USING DEFAULT;\nSELECT * FROM t1;\n+------+\n| a    |\n+------+\n|   10 |\n+------+\n\nEXECUTE IMMEDIATE increments the Com_execute_immediate status variable, as\nwell as the Com_stmt_prepare, Com_stmt_execute and Com_stmt_close status\nvariables.\n\nNote, EXECUTE IMMEDIATE does not increment the Com_execute_sql status\nvariable. Com_execute_sql is used only for PREPARE..EXECUTE.\n\nThis session screenshot demonstrates how EXECUTE IMMEDIATE affects status\nvariables:\n\nSELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME RLIKE \n (\'COM_(EXECUTE|STMT_PREPARE|STMT_EXECUTE|STMT_CLOSE)\');\n\n+-----------------------+----------------+\n| VARIABLE_NAME         | VARIABLE_VALUE |\n+-----------------------+----------------+\n| COM_EXECUTE_IMMEDIATE | 0              |\n| COM_EXECUTE_SQL       | 0              |\n| COM_STMT_CLOSE        | 0              |\n| COM_STMT_EXECUTE      | 0              |\n| COM_STMT_PREPARE      | 0              |\n+-----------------------+----------------+\n\nEXECUTE IMMEDIATE \'SELECT 1\';\n+---+\n| 1 |\n+---+\n| 1 |\n+---+\n\nSELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME RLIKE \n (\'COM_(EXECUTE|STMT_PREPARE|STMT_EXECUTE|STMT_CLOSE)\');\n+-----------------------+----------------+\n| VARIABLE_NAME         | VARIABLE_VALUE |\n+-----------------------+----------------+\n| COM_EXECUTE_IMMEDIATE | 1              |\n| COM_EXECUTE_SQL       | 0              |\n| COM_STMT_CLOSE        | 1              |\n| COM_STMT_EXECUTE      | 1              |\n| COM_STMT_PREPARE      | 1              |\n+-----------------------+----------------+\n\nURL: https://mariadb.com/kb/en/execute-immediate/','','https://mariadb.com/kb/en/execute-immediate/'),
(831,'PREPARE Statement',50,'Syntax\n------\n\nPREPARE stmt_name FROM preparable_stmt\n\nDescription\n-----------\n\nThe PREPARE statement prepares a statement and assigns it a name, stmt_name,\nby which to refer to the statement later. Statement names are not case\nsensitive. preparable_stmt is either a string literal or a user variable (not\na local variable, an SQL expression or a subquery) that contains the text of\nthe statement. The text must represent a single SQL statement, not multiple\nstatements. Within the statement, \"?\" characters can be used as parameter\nmarkers to indicate where data values are to be bound to the query later when\nyou execute it. The \"?\" characters should not be enclosed within quotes, even\nif you intend to bind them to string values. Parameter markers can be used\nonly where expressions should appear, not for SQL keywords, identifiers, and\nso forth.\n\nThe scope of a prepared statement is the session within which it is created.\nOther sessions cannot see it.\n\nIf a prepared statement with the given name already exists, it is deallocated\nimplicitly before the new statement is prepared. This means that if the new\nstatement contains an error and cannot be prepared, an error is returned and\nno statement with the given name exists.\n\nPrepared statements can be PREPAREd and EXECUTEd in a stored procedure, but\nnot in a stored function or trigger. Also, even if the statement is PREPAREd\nin a procedure, it will not be deallocated when the procedure execution ends.\n\nA prepared statement can access user-defined variables, but not local\nvariables or procedure\'s parameters.\n\nIf the prepared statement contains a syntax error, PREPARE will fail. As a\nside effect, stored procedures can use it to check if a statement is valid.\nFor example:\n\nCREATE PROCEDURE `test_stmt`(IN sql_text TEXT)\nBEGIN\n    DECLARE EXIT HANDLER FOR SQLEXCEPTION\n    BEGIN\n        SELECT CONCAT(sql_text, \' is not valid\');\n    END;\n    SET @SQL := sql_text;\n    PREPARE stmt FROM @SQL;\n    DEALLOCATE PREPARE stmt;\nEND;\n\nThe FOUND_ROWS() and ROW_COUNT() functions, if called immediatly after\nEXECUTE, return the number of rows read or affected by the prepared\nstatements; however, if they are called after DEALLOCATE PREPARE, they provide\ninformation about this statement. If the prepared statement produces errors or\nwarnings, GET DIAGNOSTICS return information about them. DEALLOCATE PREPARE\nshouldn\'t clear the diagnostics area, unless it produces an error.\n\nA prepared statement is executed with EXECUTE and released with DEALLOCATE\nPREPARE.\n\nThe max_prepared_stmt_count server system variable determines the number of\nallowed prepared statements that can be prepared on the server. If it is set\nto 0, prepared statements are not allowed. If the limit is reached, an error\nsimilar to the following will be produced:\n\nERROR 1461 (42000): Can\'t create more than max_prepared_stmt_count statements \n (current value: 0)\n\nOracle Mode\n-----------\n\nMariaDB starting with 10.3\n--------------------------\nIn Oracle mode from MariaDB 10.3, PREPARE stmt FROM \'SELECT :1, :2\' is used,\ninstead of ?.\n\nPermitted Statements\n--------------------\n\nMariaDB starting with 10.6.2\n----------------------------\nAll statements can be prepared, except PREPARE, EXECUTE, and DEALLOCATE / DROP\nPREPARE.\n\nPrior to this, not all statements can be prepared. Only the following SQL\ncommands are permitted:\n\n* ALTER TABLE\n* ANALYZE TABLE\n* BINLOG\n* CACHE INDEX\n* CALL\n* CHANGE MASTER\n* CHECKSUM {TABLE | TABLES}\n* COMMIT\n* {CREATE | DROP} DATABASE\n* {CREATE | DROP} INDEX\n* {CREATE | RENAME | DROP} TABLE\n* {CREATE | RENAME | DROP} USER\n* {CREATE | DROP} VIEW\n* DELETE\n* DESCRIBE\n* DO\n* EXPLAIN\n* FLUSH {TABLE | TABLES | TABLES WITH READ LOCK | HOSTS | PRIVILEGES | LOGS |\nSTATUS | \n MASTER | SLAVE | DES_KEY_FILE | USER_RESOURCES | QUERY CACHE |\nTABLE_STATISTICS | \n INDEX_STATISTICS | USER_STATISTICS | CLIENT_STATISTICS}\n* GRANT\n* INSERT\n* INSTALL {PLUGIN | SONAME}\n* HANDLER READ\n* KILL\n* LOAD INDEX INTO CACHE\n* OPTIMIZE TABLE\n* REPAIR TABLE\n* REPLACE\n* RESET {MASTER | SLAVE | QUERY CACHE}\n* REVOKE\n* ROLLBACK\n* SELECT\n* SET\n* SET GLOBAL SQL_SLAVE_SKIP_COUNTER\n* SET ROLE\n* SET SQL_LOG_BIN\n* SET TRANSACTION ISOLATION LEVEL\n* SHOW EXPLAIN\n* SHOW {DATABASES | TABLES | OPEN TABLES | TABLE STATUS | COLUMNS | INDEX |\nTRIGGERS | \n EVENTS | GRANTS | CHARACTER SET | COLLATION | ENGINES | PLUGINS [SONAME] |\nPRIVILEGES | \n PROCESSLIST | PROFILE | PROFILES | VARIABLES | STATUS | WARNINGS | ERRORS |\n TABLE_STATISTICS | INDEX_STATISTICS | USER_STATISTICS | CLIENT_STATISTICS |\nAUTHORS | \n CONTRIBUTORS}\n* SHOW CREATE {DATABASE | TABLE | VIEW | PROCEDURE | FUNCTION | TRIGGER |\nEVENT}\n* SHOW {FUNCTION | PROCEDURE} CODE\n* SHOW BINLOG EVENTS\n* SHOW SLAVE HOSTS\n* SHOW {MASTER | BINARY} LOGS\n* SHOW {MASTER | SLAVE | TABLES | INNODB | FUNCTION | PROCEDURE} STATUS\n* SLAVE {START | STOP}\n* TRUNCATE TABLE\n* SHUTDOWN\n* UNINSTALL {PLUGIN | SONAME}\n* UPDATE\n\nSynonyms are not listed here, but can be used. For example, DESC can be used\ninstead of DESCRIBE.\n\nCompound statements can be prepared too.\n\nNote that if a statement can be run in a stored routine, it will work even if\nit is called by a prepared statement. For example, SIGNAL can\'t be directly\nprepared. However, it is allowed in stored routines. If the x() procedure\ncontains SIGNAL, you can still prepare and execute the \'CALL x();\' prepared\nstatement.\n\nPREPARE supports most kinds of expressions as well, for example:\n\nPREPARE stmt FROM CONCAT(\'SELECT * FROM \', table_name);\n\nWhen PREPARE is used with a statement which is not supported, the following\nerror is produced:\n\nERROR 1295 (HY000): This command is not supported in the prepared statement\nprotocol yet\n\nExample\n-------\n\ncreate table t1 (a int,b char(10));\ninsert into t1 values (1,\"one\"),(2, \"two\"),(3,\"three\");\nprepare test from \"select * from t1 where a=?\";\nset @param=2;\nexecute test using @param;\n+------+------+\n| a    | b    |\n+------+------+\n|    2 | two  |\n+------+------+\nset @param=3;\nexecute test using @param;\n+------+-------+\n| a    | b     |\n+------+-------+\n|    3 | three |\n+------+-------+\ndeallocate prepare test;\n\nSince identifiers are not permitted as prepared statements parameters,\nsometimes it is necessary to dynamically compose an SQL statement. This\ntechnique is called dynamic SQL). The following example shows how to use\ndynamic SQL:\n\nCREATE PROCEDURE test.stmt_test(IN tab_name VARCHAR(64))\nBEGIN\n	SET @sql = CONCAT(\'SELECT COUNT(*) FROM \', tab_name);\n	PREPARE stmt FROM @sql;\n	EXECUTE stmt;\n	DEALLOCATE PREPARE stmt;\nEND;\n\nCALL test.stmt_test(\'mysql.user\');\n+----------+\n| COUNT(*) |\n+----------+\n|        4 |\n+----------+\n\nUse of variables in prepared statements:\n\nPREPARE stmt FROM \'SELECT @x;\';\n\nSET @x = 1;\n\nEXECUTE stmt;\n+------+\n| @x   |\n+------+\n|    1 |\n+------+\n\nSET @x = 0;\n\nEXECUTE stmt;\n+------+\n| @x   |\n+------+\n|    0 |\n+------+\n\nDEALLOCATE PREPARE stmt;\n\nURL: https://mariadb.com/kb/en/prepare-statement/','','https://mariadb.com/kb/en/prepare-statement/');

--
-- Table structure for table `index_stats`
--

CREATE TABLE `index_stats` (
  `db_name` varchar(64) NOT NULL,
  `table_name` varchar(64) NOT NULL,
  `index_name` varchar(64) NOT NULL,
  `prefix_arity` int(11) unsigned NOT NULL,
  `avg_frequency` decimal(12,4) DEFAULT NULL,
  PRIMARY KEY (`db_name`,`table_name`,`index_name`,`prefix_arity`)
) ENGINE=Aria DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin PAGE_CHECKSUM=1 TRANSACTIONAL=0 COMMENT='Statistics on Indexes';

--
-- Dumping data for table `index_stats`
--


--
-- Table structure for table `innodb_index_stats`
--

CREATE TABLE `innodb_index_stats` (
  `database_name` varchar(64) NOT NULL,
  `table_name` varchar(199) NOT NULL,
  `index_name` varchar(64) NOT NULL,
  `last_update` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `stat_name` varchar(64) NOT NULL,
  `stat_value` bigint(20) unsigned NOT NULL,
  `sample_size` bigint(20) unsigned DEFAULT NULL,
  `stat_description` varchar(1024) NOT NULL,
  PRIMARY KEY (`database_name`,`table_name`,`index_name`,`stat_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin STATS_PERSISTENT=0;

--
-- Table structure for table `innodb_table_stats`
--

CREATE TABLE `innodb_table_stats` (
  `database_name` varchar(64) NOT NULL,
  `table_name` varchar(199) NOT NULL,
  `last_update` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `n_rows` bigint(20) unsigned NOT NULL,
  `clustered_index_size` bigint(20) unsigned NOT NULL,
  `sum_of_other_index_sizes` bigint(20) unsigned NOT NULL,
  PRIMARY KEY (`database_name`,`table_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_bin STATS_PERSISTENT=0;

--
-- Table structure for table `plugin`
--

CREATE TABLE `plugin` (
  `name` varchar(64) NOT NULL DEFAULT '',
  `dl` varchar(128) NOT NULL DEFAULT '',
  PRIMARY KEY (`name`)
) ENGINE=Aria DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci PAGE_CHECKSUM=1 TRANSACTIONAL=1 COMMENT='MySQL plugins';

--
-- Dumping data for table `plugin`
--


--
-- Table structure for table `proc`
--

CREATE TABLE `proc` (
  `db` char(64) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin NOT NULL DEFAULT '',
  `name` char(64) NOT NULL DEFAULT '',
  `type` enum('FUNCTION','PROCEDURE','PACKAGE','PACKAGE BODY') NOT NULL,
  `specific_name` char(64) NOT NULL DEFAULT '',
  `language` enum('SQL') NOT NULL DEFAULT 'SQL',
  `sql_data_access` enum('CONTAINS_SQL','NO_SQL','READS_SQL_DATA','MODIFIES_SQL_DATA') NOT NULL DEFAULT 'CONTAINS_SQL',
  `is_deterministic` enum('YES','NO') NOT NULL DEFAULT 'NO',
  `security_type` enum('INVOKER','DEFINER') NOT NULL DEFAULT 'DEFINER',
  `param_list` blob NOT NULL,
  `returns` longblob NOT NULL,
  `body` longblob NOT NULL,
  `definer` varchar(384) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin NOT NULL DEFAULT '',
  `created` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  `modified` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `sql_mode` set('REAL_AS_FLOAT','PIPES_AS_CONCAT','ANSI_QUOTES','IGNORE_SPACE','IGNORE_BAD_TABLE_OPTIONS','ONLY_FULL_GROUP_BY','NO_UNSIGNED_SUBTRACTION','NO_DIR_IN_CREATE','POSTGRESQL','ORACLE','MSSQL','DB2','MAXDB','NO_KEY_OPTIONS','NO_TABLE_OPTIONS','NO_FIELD_OPTIONS','MYSQL323','MYSQL40','ANSI','NO_AUTO_VALUE_ON_ZERO','NO_BACKSLASH_ESCAPES','STRICT_TRANS_TABLES','STRICT_ALL_TABLES','NO_ZERO_IN_DATE','NO_ZERO_DATE','INVALID_DATES','ERROR_FOR_DIVISION_BY_ZERO','TRADITIONAL','NO_AUTO_CREATE_USER','HIGH_NOT_PRECEDENCE','NO_ENGINE_SUBSTITUTION','PAD_CHAR_TO_FULL_LENGTH','EMPTY_STRING_IS_NULL','SIMULTANEOUS_ASSIGNMENT','TIME_ROUND_FRACTIONAL') NOT NULL DEFAULT '',
  `comment` text CHARACTER SET utf8mb3 COLLATE utf8mb3_bin NOT NULL,
  `character_set_client` char(32) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin DEFAULT NULL,
  `collation_connection` char(64) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin DEFAULT NULL,
  `db_collation` char(64) CHARACTER SET utf8mb3 COLLATE utf8mb3_bin DEFAULT NULL,
  `body_utf8` longblob DEFAULT NULL,
  `aggregate` enum('NONE','GROUP') NOT NULL DEFAULT 'NONE',
  PRIMARY KEY (`db`,`name`,`type`)
) ENGINE=Aria DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci PAGE_CHECKSUM=1 TRANSACTIONAL=1 COMMENT='Stored Procedures';

--
-- Dumping data for table `proc`
--

INSERT INTO `proc` VALUES
('mysql','AddGeometryColumn','PROCEDURE','AddGeometryColumn','SQL','CONTAINS_SQL','NO','INVOKER','catalog varchar(64), t_schema varchar(64),\n   t_name varchar(64), geometry_column varchar(64), t_srid int','','begin\n  set @qwe= concat(\'ALTER TABLE \', t_schema, \'.\', t_name, \' ADD \', geometry_column,\' GEOMETRY REF_SYSTEM_ID=\', t_srid); PREPARE ls from @qwe; execute ls; deallocate prepare ls; end','mariadb.sys@localhost','2024-02-11 05:51:12','2024-02-11 05:51:12','','','utf8mb3','utf8mb3_general_ci','utf8mb4_general_ci','begin\n  set @qwe= concat(\'ALTER TABLE \', t_schema, \'.\', t_name, \' ADD \', geometry_column,\' GEOMETRY REF_SYSTEM_ID=\', t_srid); PREPARE ls from @qwe; execute ls; deallocate prepare ls; end','NONE'),
('mysql','DropGeometryColumn','PROCEDURE','DropGeometryColumn','SQL','CONTAINS_SQL','NO','INVOKER','catalog varchar(64), t_schema varchar(64),\n   t_name varchar(64), geometry_column varchar(64)','','begin\n  set @qwe= concat(\'ALTER TABLE \', t_schema, \'.\', t_name, \' DROP \', geometry_column); PREPARE ls from @qwe; execute ls; deallocate prepare ls; end','mariadb.sys@localhost','2024-02-11 05:51:12','2024-02-11 05:51:12','','','utf8mb3','utf8mb3_general_ci','utf8mb4_general_ci','begin\n  set @qwe= concat(\'ALTER TABLE \', t_schema, \'.\', t_name, \' DROP \', geometry_column); PREPARE ls from @qwe; execute ls; deallocate prepare ls; end','NONE'),
('sys','extract_schema_from_file_name','FUNCTION','extract_schema_from_file_name','SQL','NO_SQL','YES','INVOKER','path VARCHAR(512)\n    ','varchar(64) CHARSET utf8mb3 COLLATE utf8mb3_general_ci','BEGIN\n    RETURN LEFT(SUBSTRING_INDEX(SUBSTRING_INDEX(REPLACE(path, \'\\\\\', \'/\'), \'/\', -2), \'/\', 1), 64);\nEND','mariadb.sys@localhost','2024-02-11 05:51:12','2024-02-11 05:51:12','','\n             Description\n             Takes a raw file path, and attempts to extract the schema name from it.\n             Useful for when interacting with Performance Schema data\n             concerning IO statistics, for example.\n             Currently relies on the fact that a table data file will be within a\n             specified database directory (will not work with partitions or tables\n             that specify an individual DATA_DIRECTORY).\n             Parameters\n             path (VARCHAR(512)):\n               The full file path to a data file to extract the schema name from.\n             Returns\n             VARCHAR(64)\n             Example\n             mysql> SELECT sys.extract_schema_from_file_name(\'/var/lib/mysql/employees/employee.ibd\');\n             +----------------------------------------------------------------------------+\n             | sys.extract_schema_from_file_name(\'/var/lib/mysql/employees/employee.ibd\') |\n             +----------------------------------------------------------------------------+\n             | employees                                                                  |\n             +----------------------------------------------------------------------------+\n             1 row in set (0.00 sec)\n            ','utf8mb3','utf8mb3_general_ci','utf8mb3_general_ci','BEGIN\n    RETURN LEFT(SUBSTRING_INDEX(SUBSTRING_INDEX(REPLACE(path, \'\\\', \'/\'), \'/\', -2), \'/\', 1), 64);\nEND','NONE'),
('sys','extract_table_from_file_name','FUNCTION','extract_table_from_file_name','SQL','NO_SQL','YES','INVOKER','path VARCHAR(512)\n    ','varchar(64) CHARSET utf8mb3 COLLATE utf8mb3_general_ci','BEGIN\n    RETURN LEFT(SUBSTRING_INDEX(REPLACE(SUBSTRING_INDEX(REPLACE(path, \'\\\\\', \'/\'), \'/\', -1), \'@0024\', \'$\'), \'.\', 1), 64);\nEND','mariadb.sys@localhost','2024-02-11 05:51:12','2024-02-11 05:51:12','','\n             Description\n             Takes a raw file path, and extracts the table name from it.\n             Useful for when interacting with Performance Schema data\n             concerning IO statistics, for example.\n             Parameters\n             path (VARCHAR(512)):\n               The full file path to a data file to extract the table name from.\n             Returns\n             VARCHAR(64)\n             Example\n             mysql> SELECT sys.extract_table_from_file_name(\'/var/lib/mysql/employees/employee.ibd\');\n             +---------------------------------------------------------------------------+\n             | sys.extract_table_from_file_name(\'/var/lib/mysql/employees/employee.ibd\') |\n             +---------------------------------------------------------------------------+\n             | employee                                                                  |\n             +---------------------------------------------------------------------------+\n             1 row in set (0.02 sec)\n            ','utf8mb3','utf8mb3_general_ci','utf8mb3_general_ci','BEGIN\n    RETURN LEFT(SUBSTRING_INDEX(REPLACE(SUBSTRING_INDEX(REPLACE(path, \'\\\', \'/\'), \'/\', -1), \'@0024\', \'$\'), \'.\', 1), 64);\nEND','NONE'),
('sys','format_bytes','FUNCTION','format_bytes','SQL','NO_SQL','YES','INVOKER','bytes TEXT\n    ','text CHARSET utf8mb3 COLLATE utf8mb3_general_ci','BEGIN\n  IF bytes IS NULL THEN RETURN NULL;\n  ELSEIF bytes >= 1125899906842624 THEN RETURN CONCAT(ROUND(bytes / 1125899906842624, 2), \' PiB\');\n  ELSEIF bytes >= 1099511627776 THEN RETURN CONCAT(ROUND(bytes / 1099511627776, 2), \' TiB\');\n  ELSEIF bytes >= 1073741824 THEN RETURN CONCAT(ROUND(bytes / 1073741824, 2), \' GiB\');\n  ELSEIF bytes >= 1048576 THEN RETURN CONCAT(ROUND(bytes / 1048576, 2), \' MiB\');\n  ELSEIF bytes >= 1024 THEN RETURN CONCAT(ROUND(bytes / 1024, 2), \' KiB\');\n  ELSE RETURN CONCAT(ROUND(bytes, 0), \' bytes\');\n  END IF;\nEND','mariadb.sys@localhost','2024-02-11 05:51:12','2024-02-11 05:51:12','','\n             Description\n             Takes a raw bytes value, and converts it to a human readable format.\n             Parameters\n             bytes (TEXT):\n               A raw bytes value.\n             Returns\n             TEXT\n             Example\n             mysql> SELECT sys.format_bytes(2348723492723746) AS size;\n             +----------+\n             | size     |\n             +----------+\n             | 2.09 PiB |\n             +----------+\n             1 row in set (0.00 sec)\n             mysql> SELECT sys.format_bytes(2348723492723) AS size;\n             +----------+\n             | size     |\n             +----------+\n             | 2.14 TiB |\n             +----------+\n             1 row in set (0.00 sec)\n             mysql> SELECT sys.format_bytes(23487234) AS size;\n             +-----------+\n             | size      |\n             +-----------+\n             | 22.40 MiB |\n             +-----------+\n             1 row in set (0.00 sec)\n            ','utf8mb3','utf8mb3_general_ci','utf8mb3_general_ci','BEGIN\n  IF bytes IS NULL THEN RETURN NULL;\n  ELSEIF bytes >= 1125899906842624 THEN RETURN CONCAT(ROUND(bytes / 1125899906842624, 2), \' PiB\');\n  ELSEIF bytes >= 1099511627776 THEN RETURN CONCAT(ROUND(bytes / 1099511627776, 2), \' TiB\');\n  ELSEIF bytes >= 1073741824 THEN RETURN CONCAT(ROUND(bytes / 1073741824, 2), \' GiB\');\n  ELSEIF bytes >= 1048576 THEN RETURN CONCAT(ROUND(bytes / 1048576, 2), \' MiB\');\n  ELSEIF bytes >= 1024 THEN RETURN CONCAT(ROUND(bytes / 1024, 2), \' KiB\');\n  ELSE RETURN CONCAT(ROUND(bytes, 0), \' bytes\');\n  END IF;\nEND','NONE'),
('sys','ps_thread_stack','FUNCTION','ps_thread_stack','SQL','READS_SQL_DATA','NO','INVOKER','thd_id BIGINT UNSIGNED,\n        debug BOOLEAN\n    ','longtext CHARSET latin1 COLLATE latin1_swedish_ci','BEGIN\n    DECLARE json_objects LONGTEXT;\n    \n    UPDATE performance_schema.threads\n       SET instrumented = \'NO\'\n     WHERE processlist_id = CONNECTION_ID();\n    \n    SET SESSION group_concat_max_len=@@global.max_allowed_packet;\n    SELECT GROUP_CONCAT(CONCAT( \'{\'\n              , CONCAT_WS( \', \'\n              , CONCAT(\'\"nesting_event_id\": \"\', IF(nesting_event_id IS NULL, \'0\', nesting_event_id), \'\"\')\n              , CONCAT(\'\"event_id\": \"\', event_id, \'\"\')\n              , CONCAT( \'\"timer_wait\": \', ROUND(timer_wait/1000000, 2))\n              , CONCAT( \'\"event_info\": \"\'\n                  , CASE\n                        WHEN event_name NOT LIKE \'wait/io%\' THEN REPLACE(SUBSTRING_INDEX(event_name, \'/\', -2), \'\\\\\', \'\\\\\\\\\')\n                        WHEN event_name NOT LIKE \'wait/io/file%\' OR event_name NOT LIKE \'wait/io/socket%\' THEN REPLACE(SUBSTRING_INDEX(event_name, \'/\', -4), \'\\\\\', \'\\\\\\\\\')\n                        ELSE event_name\n                    END\n                  , \'\"\'\n              )\n              , CONCAT( \'\"wait_info\": \"\', IFNULL(wait_info, \'\'), \'\"\')\n              , CONCAT( \'\"source\": \"\', IF(true AND event_name LIKE \'wait%\', IFNULL(wait_info, \'\'), \'\'), \'\"\')\n              , CASE\n                     WHEN event_name LIKE \'wait/io/file%\'      THEN \'\"event_type\": \"io/file\"\'\n                     WHEN event_name LIKE \'wait/io/table%\'     THEN \'\"event_type\": \"io/table\"\'\n                     WHEN event_name LIKE \'wait/io/socket%\'    THEN \'\"event_type\": \"io/socket\"\'\n                     WHEN event_name LIKE \'wait/synch/mutex%\'  THEN \'\"event_type\": \"synch/mutex\"\'\n                     WHEN event_name LIKE \'wait/synch/cond%\'   THEN \'\"event_type\": \"synch/cond\"\'\n                     WHEN event_name LIKE \'wait/synch/rwlock%\' THEN \'\"event_type\": \"synch/rwlock\"\'\n                     WHEN event_name LIKE \'wait/lock%\'         THEN \'\"event_type\": \"lock\"\'\n                     WHEN event_name LIKE \'statement/%\'        THEN \'\"event_type\": \"stmt\"\'\n                     WHEN event_name LIKE \'stage/%\'            THEN \'\"event_type\": \"stage\"\'\n                     WHEN event_name LIKE \'%idle%\'             THEN \'\"event_type\": \"idle\"\'\n                     ELSE \'\'\n                END\n            )\n            , \'}\'\n          )\n          ORDER BY event_id ASC SEPARATOR \',\') event\n    INTO json_objects\n    FROM (\n          \n          (SELECT thread_id, event_id, event_name, timer_wait, timer_start, nesting_event_id,\n                  CONCAT(sql_text, \'\\\\n\',\n                         \'errors: \', errors, \'\\\\n\',\n                         \'warnings: \', warnings, \'\\\\n\',\n                         \'lock time: \', ROUND(lock_time/1000000, 2),\'us\\\\n\',\n                         \'rows affected: \', rows_affected, \'\\\\n\',\n                         \'rows sent: \', rows_sent, \'\\\\n\',\n                         \'rows examined: \', rows_examined, \'\\\\n\',\n                         \'tmp tables: \', created_tmp_tables, \'\\\\n\',\n                         \'tmp disk tables: \', created_tmp_disk_tables, \'\\\\n\',\n                         \'select scan: \', select_scan, \'\\\\n\',\n                         \'select full join: \', select_full_join, \'\\\\n\',\n                         \'select full range join: \', select_full_range_join, \'\\\\n\',\n                         \'select range: \', select_range, \'\\\\n\',\n                         \'select range check: \', select_range_check, \'\\\\n\',\n                         \'sort merge passes: \', sort_merge_passes, \'\\\\n\',\n                         \'sort rows: \', sort_rows, \'\\\\n\',\n                         \'sort range: \', sort_range, \'\\\\n\',\n                         \'sort scan: \', sort_scan, \'\\\\n\',\n                         \'no index used: \', IF(no_index_used, \'TRUE\', \'FALSE\'), \'\\\\n\',\n                         \'no good index used: \', IF(no_good_index_used, \'TRUE\', \'FALSE\'), \'\\\\n\'\n                         ) AS wait_info\n             FROM performance_schema.events_statements_history_long WHERE thread_id = thd_id)\n          UNION\n          (SELECT thread_id, event_id, event_name, timer_wait, timer_start, nesting_event_id, null AS wait_info\n             FROM performance_schema.events_stages_history_long WHERE thread_id = thd_id)\n          UNION \n          (SELECT thread_id, event_id,\n                  CONCAT(event_name ,\n                         IF(event_name NOT LIKE \'wait/synch/mutex%\', IFNULL(CONCAT(\' - \', operation), \'\'), \'\'),\n                         IF(number_of_bytes IS NOT NULL, CONCAT(\' \', number_of_bytes, \' bytes\'), \'\'),\n                         IF(event_name LIKE \'wait/io/file%\', \'\\\\n\', \'\'),\n                         IF(object_schema IS NOT NULL, CONCAT(\'\\\\nObject: \', object_schema, \'.\'), \'\'),\n                         IF(object_name IS NOT NULL,\n                            IF (event_name LIKE \'wait/io/socket%\',\n                                CONCAT(IF (object_name LIKE \':0%\', @@socket, object_name)),\n                                object_name),\n                            \'\'),\n                          IF(index_name IS NOT NULL, CONCAT(\' Index: \', index_name), \'\'),\'\\\\n\'\n                         ) AS event_name,\n                  timer_wait, timer_start, nesting_event_id, source AS wait_info\n             FROM performance_schema.events_waits_history_long WHERE thread_id = thd_id)) events\n    ORDER BY event_id;\n    RETURN CONCAT(\'{\',\n                  CONCAT_WS(\',\',\n                            \'\"rankdir\": \"LR\"\',\n                            \'\"nodesep\": \"0.10\"\',\n                            CONCAT(\'\"stack_created\": \"\', NOW(), \'\"\'),\n                            CONCAT(\'\"mysql_version\": \"\', VERSION(), \'\"\'),\n                            CONCAT(\'\"mysql_user\": \"\', CURRENT_USER(), \'\"\'),\n                            CONCAT(\'\"events\": [\', IFNULL(json_objects,\'\'), \']\')\n                           ),\n                  \'}\');\nEND','mariadb.sys@localhost','2024-02-11 05:51:12','2024-02-11 05:51:12','','\n             Description\n             Outputs a JSON formatted stack of all statements, stages and events\n             within Performance Schema for the specified thread.\n             Parameters\n             thd_id (BIGINT UNSIGNED):\n               The id of the thread to trace. This should match the thread_id\n               column from the performance_schema.threads table.\n             in_verbose (BOOLEAN):\n               Include file:lineno information in the events.\n             Example\n             (line separation added for output)\n             mysql> SELECT sys.ps_thread_stack(37, FALSE) AS thread_stack\\G\n             *************************** 1. row ***************************\n             thread_stack: {\"rankdir\": \"LR\",\"nodesep\": \"0.10\",\"stack_created\": \"2014-02-19 13:39:03\",\n             \"mysql_version\": \"5.7.3-m13\",\"mysql_user\": \"root@localhost\",\"events\":\n             [{\"nesting_event_id\": \"0\", \"event_id\": \"10\", \"timer_wait\": 256.35, \"event_info\":\n             \"sql/select\", \"wait_info\": \"select @@version_comment limit 1\\nerrors: 0\\nwarnings: 0\\nlock time:\n             ...\n            ','utf8mb3','utf8mb3_general_ci','utf8mb3_general_ci','BEGIN\n    DECLARE json_objects LONGTEXT;\n    \n    UPDATE performance_schema.threads\n       SET instrumented = \'NO\'\n     WHERE processlist_id = CONNECTION_ID();\n    \n    SET SESSION group_concat_max_len=@@global.max_allowed_packet;\n    SELECT GROUP_CONCAT(CONCAT( \'{\'\n              , CONCAT_WS( \', \'\n              , CONCAT(\'\"nesting_event_id\": \"\', IF(nesting_event_id IS NULL, \'0\', nesting_event_id), \'\"\')\n              , CONCAT(\'\"event_id\": \"\', event_id, \'\"\')\n              , CONCAT( \'\"timer_wait\": \', ROUND(timer_wait/1000000, 2))\n              , CONCAT( \'\"event_info\": \"\'\n                  , CASE\n                        WHEN event_name NOT LIKE \'wait/io%\' THEN REPLACE(SUBSTRING_INDEX(event_name, \'/\', -2), \'\\\', \'\\\\\')\n                        WHEN event_name NOT LIKE \'wait/io/file%\' OR event_name NOT LIKE \'wait/io/socket%\' THEN REPLACE(SUBSTRING_INDEX(event_name, \'/\', -4), \'\\\', \'\\\\\')\n                        ELSE event_name\n                    END\n                  , \'\"\'\n              )\n              , CONCAT( \'\"wait_info\": \"\', IFNULL(wait_info, \'\'), \'\"\')\n              , CONCAT( \'\"source\": \"\', IF(true AND event_name LIKE \'wait%\', IFNULL(wait_info, \'\'), \'\'), \'\"\')\n              , CASE\n                     WHEN event_name LIKE \'wait/io/file%\'      THEN \'\"event_type\": \"io/file\"\'\n                     WHEN event_name LIKE \'wait/io/table%\'     THEN \'\"event_type\": \"io/table\"\'\n                     WHEN event_name LIKE \'wait/io/socket%\'    THEN \'\"event_type\": \"io/socket\"\'\n                     WHEN event_name LIKE \'wait/synch/mutex%\'  THEN \'\"event_type\": \"synch/mutex\"\'\n                     WHEN event_name LIKE \'wait/synch/cond%\'   THEN \'\"event_type\": \"synch/cond\"\'\n                     WHEN event_name LIKE \'wait/synch/rwlock%\' THEN \'\"event_type\": \"synch/rwlock\"\'\n                     WHEN event_name LIKE \'wait/lock%\'         THEN \'\"event_type\": \"lock\"\'\n                     WHEN event_name LIKE \'statement/%\'        THEN \'\"event_type\": \"stmt\"\'\n                     WHEN event_name LIKE \'stage/%\'            THEN \'\"event_type\": \"stage\"\'\n                     WHEN event_name LIKE \'%idle%\'             THEN \'\"event_type\": \"idle\"\'\n                     ELSE \'\'\n                END\n            )\n            , \'}\'\n          )\n          ORDER BY event_id ASC SEPARATOR \',\') event\n    INTO json_objects\n    FROM (\n          \n          (SELECT thread_id, event_id, event_name, timer_wait, timer_start, nesting_event_id,\n                  CONCAT(sql_text, \'\\n\',\n                         \'errors: \', errors, \'\\n\',\n                         \'warnings: \', warnings, \'\\n\',\n                         \'lock time: \', ROUND(lock_time/1000000, 2),\'us\\n\',\n                         \'rows affected: \', rows_affected, \'\\n\',\n                         \'rows sent: \', rows_sent, \'\\n\',\n                         \'rows examined: \', rows_examined, \'\\n\',\n                         \'tmp tables: \', created_tmp_tables, \'\\n\',\n                         \'tmp disk tables: \', created_tmp_disk_tables, \'\\n\',\n                         \'select scan: \', select_scan, \'\\n\',\n                         \'select full join: \', select_full_join, \'\\n\',\n                         \'select full range join: \', select_full_range_join, \'\\n\',\n                         \'select range: \', select_range, \'\\n\',\n                         \'select range check: \', select_range_check, \'\\n\',\n                         \'sort merge passes: \', sort_merge_passes, \'\\n\',\n                         \'sort rows: \', sort_rows, \'\\n\',\n                         \'sort range: \', sort_range, \'\\n\',\n                         \'sort scan: \', sort_scan, \'\\n\',\n                         \'no index used: \', IF(no_index_used, \'TRUE\', \'FALSE\'), \'\\n\',\n                         \'no good index used: \', IF(no_good_index_used, \'TRUE\', \'FALSE\'), \'\\n\'\n                         ) AS wait_info\n             FROM performance_schema.events_statements_history_long WHERE thread_id = thd_id)\n          UNION\n          (SELECT thread_id, event_id, event_name, timer_wait, timer_start, nesting_event_id, null AS wait_info\n             FROM performance_schema.events_stages_history_long WHERE thread_id = thd_id)\n          UNION \n          (SELECT thread_id, event_id,\n                  CONCAT(event_name ,\n                         IF(event_name NOT LIKE \'wait/synch/mutex%\', IFNULL(CONCAT(\' - \', operation), \'\'), \'\'),\n                         IF(number_of_bytes IS NOT NULL, CONCAT(\' \', number_of_bytes, \' bytes\'), \'\'),\n                         IF(event_name LIKE \'wait/io/file%\', \'\\n\', \'\'),\n                         IF(object_schema IS NOT NULL, CONCAT(\'\\nObject: \', object_schema, \'.\'), \'\'),\n                         IF(object_name IS NOT NULL,\n                            IF (event_name LIKE \'wait/io/socket%\',\n                                CONCAT(IF (object_name LIKE \':0%\', @@socket, object_name)),\n                                object_name),\n                            \'\'),\n                          IF(index_name IS NOT NULL, CONCAT(\' Index: \', index_name), \'\'),\'\\n\'\n                         ) AS event_name,\n                  timer_wait, timer_start, nesting_event_id, source AS wait_info\n             FROM performance_schema.events_waits_history_long WHERE thread_id = thd_id)) events\n    ORDER BY event_id;\n    RETURN CONCAT(\'{\',\n                  CONCAT_WS(\',\',\n                            \'\"rankdir\": \"LR\"\',\n                            \'\"nodesep\": \"0.10\"\',\n                            CONCAT(\'\"stack_created\": \"\', NOW(), \'\"\'),\n                            CONCAT(\'\"mysql_version\": \"\', VERSION(), \'\"\'),\n                            CONCAT(\'\"mysql_user\": \"\', CURRENT_USER(), \'\"\'),\n                            CONCAT(\'\"events\": [\', IFNULL(json_objects,\'\'), \']\')\n                           ),\n                  \'}\');\nEND','NONE'),
('sys','ps_thread_trx_info','FUNCTION','ps_thread_trx_info','SQL','READS_SQL_DATA','NO','INVOKER','in_thread_id BIGINT UNSIGNED\n    ','longtext CHARSET utf8mb3 COLLATE utf8mb3_general_ci','BEGIN\n    DECLARE v_output LONGTEXT DEFAULT \'{}\';\n    DECLARE v_msg_text TEXT DEFAULT \'\';\n    DECLARE v_signal_msg TEXT DEFAULT \'\';\n    DECLARE v_mysql_errno INT;\n    DECLARE v_max_output_len BIGINT;\n    DECLARE EXIT HANDLER FOR SQLWARNING, SQLEXCEPTION\n    BEGIN\n        GET DIAGNOSTICS CONDITION 1\n            v_msg_text = MESSAGE_TEXT,\n            v_mysql_errno = MYSQL_ERRNO;\n        IF v_mysql_errno = 1260 THEN\n            SET v_signal_msg = CONCAT(\'{ \"error\": \"Trx info truncated: \', v_msg_text, \'\" }\');\n        ELSE\n            SET v_signal_msg = CONCAT(\'{ \"error\": \"\', v_msg_text, \'\" }\');\n        END IF;\n        RETURN v_signal_msg;\n    END;\n    IF (@sys.ps_thread_trx_info.max_length IS NULL) THEN\n        SET @sys.ps_thread_trx_info.max_length = sys.sys_get_config(\'ps_thread_trx_info.max_length\', 65535);\n    END IF;\n    IF (@sys.ps_thread_trx_info.max_length != @@session.group_concat_max_len) THEN\n        SET @old_group_concat_max_len = @@session.group_concat_max_len;\n        SET v_max_output_len = (@sys.ps_thread_trx_info.max_length - 5);\n        SET SESSION group_concat_max_len = v_max_output_len;\n    END IF;\n    SET v_output = (\n        SELECT CONCAT(\'[\', IFNULL(GROUP_CONCAT(trx_info ORDER BY event_id), \'\'), \'\\n]\') AS trx_info\n          FROM (SELECT trxi.thread_id,\n                       trxi.event_id,\n                       GROUP_CONCAT(\n                         IFNULL(\n                           CONCAT(\'\\n  {\\n\',\n                                  \'    \"time\": \"\', IFNULL(sys.format_time(trxi.timer_wait), \'\'), \'\",\\n\',\n                                  \'    \"state\": \"\', IFNULL(trxi.state, \'\'), \'\",\\n\',\n                                  \'    \"mode\": \"\', IFNULL(trxi.access_mode, \'\'), \'\",\\n\',\n                                  \'    \"autocommitted\": \"\', IFNULL(trxi.autocommit, \'\'), \'\",\\n\',\n                                  \'    \"gtid\": \"\', IFNULL(trxi.gtid, \'\'), \'\",\\n\',\n                                  \'    \"isolation\": \"\', IFNULL(trxi.isolation_level, \'\'), \'\",\\n\',\n                                  \'    \"statements_executed\": [\', IFNULL(s.stmts, \'\'), IF(s.stmts IS NULL, \' ]\\n\', \'\\n    ]\\n\'),\n                                  \'  }\'\n                           ),\n                           \'\')\n                         ORDER BY event_id) AS trx_info\n                  FROM (\n                        (SELECT thread_id, event_id, timer_wait, state,access_mode, autocommit, gtid, isolation_level\n                           FROM performance_schema.events_transactions_current\n                          WHERE thread_id = in_thread_id\n                            AND end_event_id IS NULL)\n                        UNION\n                        (SELECT thread_id, event_id, timer_wait, state,access_mode, autocommit, gtid, isolation_level\n                           FROM performance_schema.events_transactions_history\n                          WHERE thread_id = in_thread_id)\n                       ) AS trxi\n                  LEFT JOIN (SELECT thread_id,\n                                    nesting_event_id,\n                                    GROUP_CONCAT(\n                                      IFNULL(\n                                        CONCAT(\'\\n      {\\n\',\n                                               \'        \"sql_text\": \"\', IFNULL(sys.format_statement(REPLACE(sql_text, \'\\\\\', \'\\\\\\\\\')), \'\'), \'\",\\n\',\n                                               \'        \"time\": \"\', IFNULL(sys.format_time(timer_wait), \'\'), \'\",\\n\',\n                                               \'        \"schema\": \"\', IFNULL(current_schema, \'\'), \'\",\\n\',\n                                               \'        \"rows_examined\": \', IFNULL(rows_examined, \'\'), \',\\n\',\n                                               \'        \"rows_affected\": \', IFNULL(rows_affected, \'\'), \',\\n\',\n                                               \'        \"rows_sent\": \', IFNULL(rows_sent, \'\'), \',\\n\',\n                                               \'        \"tmp_tables\": \', IFNULL(created_tmp_tables, \'\'), \',\\n\',\n                                               \'        \"tmp_disk_tables\": \', IFNULL(created_tmp_disk_tables, \'\'), \',\\n\',\n                                               \'        \"sort_rows\": \', IFNULL(sort_rows, \'\'), \',\\n\',\n                                               \'        \"sort_merge_passes\": \', IFNULL(sort_merge_passes, \'\'), \'\\n\',\n                                               \'      }\'), \'\') ORDER BY event_id) AS stmts\n                               FROM performance_schema.events_statements_history\n                              WHERE sql_text IS NOT NULL\n                                AND thread_id = in_thread_id\n                              GROUP BY thread_id, nesting_event_id\n                            ) AS s\n                    ON trxi.thread_id = s.thread_id\n                   AND trxi.event_id = s.nesting_event_id\n                 WHERE trxi.thread_id = in_thread_id\n                 GROUP BY trxi.thread_id, trxi.event_id\n                ) trxs\n          GROUP BY thread_id\n    );\n    IF (@old_group_concat_max_len IS NOT NULL) THEN\n        SET SESSION group_concat_max_len = @old_group_concat_max_len;\n    END IF;\n    RETURN v_output;\nEND','mariadb.sys@localhost','2024-02-11 05:51:12','2024-02-11 05:51:12','','\n             Description\n             Returns a JSON object with info on the given threads current transaction,\n             and the statements it has already executed, derived from the\n             performance_schema.events_transactions_current and\n             performance_schema.events_statements_history tables (so the consumers\n             for these also have to be enabled within Performance Schema to get full\n             data in the object).\n             When the output exceeds the default truncation length (65535), a JSON error\n             object is returned, such as:\n             { \"error\": \"Trx info truncated: Row 6 was cut by GROUP_CONCAT()\" }\n             Similar error objects are returned for other warnings/and exceptions raised\n             when calling the function.\n             The max length of the output of this function can be controlled with the\n             ps_thread_trx_info.max_length variable set via sys_config, or the\n             @sys.ps_thread_trx_info.max_length user variable, as appropriate.\n             Parameters\n             in_thread_id (BIGINT UNSIGNED):\n               The id of the thread to return the transaction info for.\n             Example\n             SELECT sys.ps_thread_trx_info(48)\\G\n             *************************** 1. row ***************************\n             sys.ps_thread_trx_info(48): [\n               {\n                 \"time\": \"790.70 us\",\n                 \"state\": \"COMMITTED\",\n                 \"mode\": \"READ WRITE\",\n                 \"autocommitted\": \"NO\",\n                 \"gtid\": \"AUTOMATIC\",\n                 \"isolation\": \"REPEATABLE READ\",\n                 \"statements_executed\": [\n                   {\n                     \"sql_text\": \"INSERT INTO info VALUES (1, \'foo\')\",\n                     \"time\": \"471.02 us\",\n                     \"schema\": \"trx\",\n                     \"rows_examined\": 0,\n                     \"rows_affected\": 1,\n                     \"rows_sent\": 0,\n                     \"tmp_tables\": 0,\n                     \"tmp_disk_tables\": 0,\n                     \"sort_rows\": 0,\n                     \"sort_merge_passes\": 0\n                   },\n                   {\n                     \"sql_text\": \"COMMIT\",\n                     \"time\": \"254.42 us\",\n                     \"schema\": \"trx\",\n                     \"rows_examined\": 0,\n                     \"rows_affected\": 0,\n                     \"rows_sent\": 0,\n                     \"tmp_tables\": 0,\n                     \"tmp_disk_tables\": 0,\n                     \"sort_rows\": 0,\n                     \"sort_merge_passes\": 0\n                   }\n                 ]\n               },\n               {\n                 \"time\": \"426.20 us\",\n                 \"state\": \"COMMITTED\",\n                 \"mode\": \"READ WRITE\",\n                 \"autocommitted\": \"NO\",\n                 \"gtid\": \"AUTOMATIC\",\n                 \"isolation\": \"REPEATABLE READ\",\n                 \"statements_executed\": [\n                   {\n                     \"sql_text\": \"INSERT INTO info VALUES (2, \'bar\')\",\n                     \"time\": \"107.33 us\",\n                     \"schema\": \"trx\",\n                     \"rows_examined\": 0,\n                     \"rows_affected\": 1,\n                     \"rows_sent\": 0,\n                     \"tmp_tables\": 0,\n                     \"tmp_disk_tables\": 0,\n                     \"sort_rows\": 0,\n                     \"sort_merge_passes\": 0\n                   },\n                   {\n                     \"sql_text\": \"COMMIT\",\n                     \"time\": \"213.23 us\",\n                     \"schema\": \"trx\",\n                     \"rows_examined\": 0,\n                     \"rows_affected\": 0,\n                     \"rows_sent\": 0,\n                     \"tmp_tables\": 0,\n                     \"tmp_disk_tables\": 0,\n                     \"sort_rows\": 0,\n                     \"sort_merge_passes\": 0\n                   }\n                 ]\n               }\n             ]\n             1 row in set (0.03 sec)\n            ','utf8mb3','utf8mb3_general_ci','utf8mb3_general_ci','BEGIN\n    DECLARE v_output LONGTEXT DEFAULT \'{}\';\n    DECLARE v_msg_text TEXT DEFAULT \'\';\n    DECLARE v_signal_msg TEXT DEFAULT \'\';\n    DECLARE v_mysql_errno INT;\n    DECLARE v_max_output_len BIGINT;\n    DECLARE EXIT HANDLER FOR SQLWARNING, SQLEXCEPTION\n    BEGIN\n        GET DIAGNOSTICS CONDITION 1\n            v_msg_text = MESSAGE_TEXT,\n            v_mysql_errno = MYSQL_ERRNO;\n        IF v_mysql_errno = 1260 THEN\n            SET v_signal_msg = CONCAT(\'{ \"error\": \"Trx info truncated: \', v_msg_text, \'\" }\');\n        ELSE\n            SET v_signal_msg = CONCAT(\'{ \"error\": \"\', v_msg_text, \'\" }\');\n        END IF;\n        RETURN v_signal_msg;\n    END;\n    IF (@sys.ps_thread_trx_info.max_length IS NULL) THEN\n        SET @sys.ps_thread_trx_info.max_length = sys.sys_get_config(\'ps_thread_trx_info.max_length\', 65535);\n    END IF;\n    IF (@sys.ps_thread_trx_info.max_length != @@session.group_concat_max_len) THEN\n        SET @old_group_concat_max_len = @@session.group_concat_max_len;\n        SET v_max_output_len = (@sys.ps_thread_trx_info.max_length - 5);\n        SET SESSION group_concat_max_len = v_max_output_len;\n    END IF;\n    SET v_output = (\n        SELECT CONCAT(\'[\', IFNULL(GROUP_CONCAT(trx_info ORDER BY event_id), \'\'), \'\\n]\') AS trx_info\n          FROM (SELECT trxi.thread_id,\n                       trxi.event_id,\n                       GROUP_CONCAT(\n                         IFNULL(\n                           CONCAT(\'\\n  {\\n\',\n                                  \'    \"time\": \"\', IFNULL(sys.format_time(trxi.timer_wait), \'\'), \'\",\\n\',\n                                  \'    \"state\": \"\', IFNULL(trxi.state, \'\'), \'\",\\n\',\n                                  \'    \"mode\": \"\', IFNULL(trxi.access_mode, \'\'), \'\",\\n\',\n                                  \'    \"autocommitted\": \"\', IFNULL(trxi.autocommit, \'\'), \'\",\\n\',\n                                  \'    \"gtid\": \"\', IFNULL(trxi.gtid, \'\'), \'\",\\n\',\n                                  \'    \"isolation\": \"\', IFNULL(trxi.isolation_level, \'\'), \'\",\\n\',\n                                  \'    \"statements_executed\": [\', IFNULL(s.stmts, \'\'), IF(s.stmts IS NULL, \' ]\\n\', \'\\n    ]\\n\'),\n                                  \'  }\'\n                           ),\n                           \'\')\n                         ORDER BY event_id) AS trx_info\n                  FROM (\n                        (SELECT thread_id, event_id, timer_wait, state,access_mode, autocommit, gtid, isolation_level\n                           FROM performance_schema.events_transactions_current\n                          WHERE thread_id = in_thread_id\n                            AND end_event_id IS NULL)\n                        UNION\n                        (SELECT thread_id, event_id, timer_wait, state,access_mode, autocommit, gtid, isolation_level\n                           FROM performance_schema.events_transactions_history\n                          WHERE thread_id = in_thread_id)\n                       ) AS trxi\n                  LEFT JOIN (SELECT thread_id,\n                                    nesting_event_id,\n                                    GROUP_CONCAT(\n                                      IFNULL(\n                                        CONCAT(\'\\n      {\\n\',\n                                               \'        \"sql_text\": \"\', IFNULL(sys.format_statement(REPLACE(sql_text, \'\\\', \'\\\\\')), \'\'), \'\",\\n\',\n                                               \'        \"time\": \"\', IFNULL(sys.format_time(timer_wait), \'\'), \'\",\\n\',\n                                               \'        \"schema\": \"\', IFNULL(current_schema, \'\'), \'\",\\n\',\n                                               \'        \"rows_examined\": \', IFNULL(rows_examined, \'\'), \',\\n\',\n                                               \'        \"rows_affected\": \', IFNULL(rows_affected, \'\'), \',\\n\',\n                                               \'        \"rows_sent\": \', IFNULL(rows_sent, \'\'), \',\\n\',\n                                               \'        \"tmp_tables\": \', IFNULL(created_tmp_tables, \'\'), \',\\n\',\n                                               \'        \"tmp_disk_tables\": \', IFNULL(created_tmp_disk_tables, \'\'), \',\\n\',\n                                               \'        \"sort_rows\": \', IFNULL(sort_rows, \'\'), \',\\n\',\n                                               \'        \"sort_merge_passes\": \', IFNULL(sort_merge_passes, \'\'), \'\\n\',\n                                               \'      }\'), \'\') ORDER BY event_id) AS stmts\n                               FROM performance_schema.events_statements_history\n                              WHERE sql_text IS NOT NULL\n                                AND thread_id = in_thread_id\n                              GROUP BY thread_id, nesting_event_id\n                            ) AS s\n                    ON trxi.thread_id = s.thread_id\n                   AND trxi.event_id = s.nesting_event_id\n                 WHERE trxi.thread_id = in_thread_id\n                 GROUP BY trxi.thread_id, trxi.event_id\n                ) trxs\n          GROUP BY thread_id\n    );\n    IF (@old_group_concat_max_len IS NOT NULL) THEN\n        SET SESSION group_concat_max_len = @old_group_concat_max_len;\n    END IF;\n    RETURN v_output;\nEND','NONE'),
('sys','create_synonym_db','PROCEDURE','create_synonym_db','SQL','MODIFIES_SQL_DATA','NO','INVOKER','\n        IN in_db_name VARCHAR(64),\n        IN in_synonym VARCHAR(64)\n    ','','BEGIN\n    DECLARE v_done bool DEFAULT FALSE;\n    DECLARE v_db_name_check VARCHAR(64);\n    DECLARE v_db_err_msg TEXT;\n    DECLARE v_table VARCHAR(64);\n    DECLARE v_views_created INT DEFAULT 0;\n    DECLARE v_table_exists ENUM(\'\', \'BASE TABLE\', \'VIEW\', \'TEMPORARY\') DEFAULT \'\';\n    DECLARE v_temp_table TEXT;\n    DECLARE c_table_names CURSOR FOR\n        SELECT TABLE_NAME\n          FROM INFORMATION_SCHEMA.TABLES\n         WHERE TABLE_SCHEMA = in_db_name;\n    DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = TRUE;\n    SELECT SCHEMA_NAME INTO v_db_name_check\n      FROM INFORMATION_SCHEMA.SCHEMATA\n     WHERE SCHEMA_NAME = in_db_name;\n    IF v_db_name_check IS NULL THEN\n        SET v_db_err_msg = CONCAT(\'Unknown database \', in_db_name);\n        SIGNAL SQLSTATE \'HY000\'\n            SET MESSAGE_TEXT = v_db_err_msg;\n    END IF;\n    SELECT SCHEMA_NAME INTO v_db_name_check\n      FROM INFORMATION_SCHEMA.SCHEMATA\n     WHERE SCHEMA_NAME = in_synonym;\n    IF v_db_name_check = in_synonym THEN\n        SET v_db_err_msg = CONCAT(\'Can\\\'t create database \', in_synonym, \'; database exists\');\n        SIGNAL SQLSTATE \'HY000\'\n            SET MESSAGE_TEXT = v_db_err_msg;\n    END IF;\n    SET @create_db_stmt := CONCAT(\'CREATE DATABASE \', sys.quote_identifier(in_synonym));\n    PREPARE create_db_stmt FROM @create_db_stmt;\n    EXECUTE create_db_stmt;\n    DEALLOCATE PREPARE create_db_stmt;\n    SET v_done = FALSE;\n    OPEN c_table_names;\n    c_table_names: LOOP\n        FETCH c_table_names INTO v_table;\n        IF v_done THEN\n            LEAVE c_table_names;\n        END IF;\n        CALL sys.table_exists(in_db_name, v_table, v_table_exists);\n        IF (v_table_exists = \'TEMPORARY\') THEN\n            SET v_temp_table =\n            CONCAT(\n                \'Table\',\n                 sys.quote_identifier(in_db_name),\n                 \'.\',\n                 sys.quote_identifier(v_table),\n                 \'shadows base table. View cannot be created! Terminating!\');\n             SIGNAL SQLSTATE \'HY000\'\n                 SET MESSAGE_TEXT = v_temp_table;\n             LEAVE c_table_names;\n        END IF;\n        SET @create_view_stmt = CONCAT(\n            \'CREATE SQL SECURITY INVOKER VIEW \',\n            sys.quote_identifier(in_synonym),\n            \'.\',\n            sys.quote_identifier(v_table),\n            \' AS SELECT * FROM \',\n            sys.quote_identifier(in_db_name),\n            \'.\',\n            sys.quote_identifier(v_table)\n        );\n        PREPARE create_view_stmt FROM @create_view_stmt;\n        EXECUTE create_view_stmt;\n        DEALLOCATE PREPARE create_view_stmt;\n        SET v_views_created = v_views_created + 1;\n    END LOOP;\n    CLOSE c_table_names;\n    SELECT CONCAT(\n        \'Created \', v_views_created, \' view\',\n        IF(v_views_created != 1, \'s\', \'\'), \' in the \',\n        sys.quote_identifier(in_synonym), \' database\'\n    ) AS summary;\nEND','mariadb.sys@localhost','2024-02-11 05:51:13','2024-02-11 05:51:13','','\n             Description\n             Takes a source database name and synonym name, and then creates the\n             synonym database with views that point to all of the tables within\n             the source database.\n             Useful for creating a \"ps\" synonym for \"performance_schema\",\n             or \"is\" instead of \"information_schema\", for example.\n             Parameters\n             in_db_name (VARCHAR(64)):\n               The database name that you would like to create a synonym for.\n             in_synonym (VARCHAR(64)):\n               The database synonym name.\n             Example\n             mysql> SHOW DATABASES;\n             +--------------------+\n             | Database           |\n             +--------------------+\n             | information_schema |\n             | mysql              |\n             | performance_schema |\n             | sys                |\n             | test               |\n             +--------------------+\n             5 rows in set (0.00 sec)\n             mysql> CALL sys.create_synonym_db(\'performance_schema\', \'ps\');\n             +---------------------------------------+\n             | summary                               |\n             +---------------------------------------+\n             | Created 74 views in the `ps` database |\n             +---------------------------------------+\n             1 row in set (8.57 sec)\n             Query OK, 0 rows affected (8.57 sec)\n             mysql> SHOW DATABASES;\n             +--------------------+\n             | Database           |\n             +--------------------+\n             | information_schema |\n             | mysql              |\n             | performance_schema |\n             | ps                 |\n             | sys                |\n             | test               |\n             +--------------------+\n             6 rows in set (0.00 sec)\n             mysql> SHOW FULL TABLES FROM ps;\n             +------------------------------------------------------+------------+\n             | Tables_in_ps                                         | Table_type |\n             +------------------------------------------------------+------------+\n             | accounts                                             | VIEW       |\n             | cond_instances                                       | VIEW       |\n             | events_stages_current                                | VIEW       |\n             | events_stages_history                                | VIEW       |\n             ...\n            ','utf8mb3','utf8mb3_general_ci','utf8mb3_general_ci','BEGIN\n    DECLARE v_done bool DEFAULT FALSE;\n    DECLARE v_db_name_check VARCHAR(64);\n    DECLARE v_db_err_msg TEXT;\n    DECLARE v_table VARCHAR(64);\n    DECLARE v_views_created INT DEFAULT 0;\n    DECLARE v_table_exists ENUM(\'\', \'BASE TABLE\', \'VIEW\', \'TEMPORARY\') DEFAULT \'\';\n    DECLARE v_temp_table TEXT;\n    DECLARE c_table_names CURSOR FOR\n        SELECT TABLE_NAME\n          FROM INFORMATION_SCHEMA.TABLES\n         WHERE TABLE_SCHEMA = in_db_name;\n    DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = TRUE;\n    SELECT SCHEMA_NAME INTO v_db_name_check\n      FROM INFORMATION_SCHEMA.SCHEMATA\n     WHERE SCHEMA_NAME = in_db_name;\n    IF v_db_name_check IS NULL THEN\n        SET v_db_err_msg = CONCAT(\'Unknown database \', in_db_name);\n        SIGNAL SQLSTATE \'HY000\'\n            SET MESSAGE_TEXT = v_db_err_msg;\n    END IF;\n    SELECT SCHEMA_NAME INTO v_db_name_check\n      FROM INFORMATION_SCHEMA.SCHEMATA\n     WHERE SCHEMA_NAME = in_synonym;\n    IF v_db_name_check = in_synonym THEN\n        SET v_db_err_msg = CONCAT(\'Can\'\'t create database \', in_synonym, \'; database exists\');\n        SIGNAL SQLSTATE \'HY000\'\n            SET MESSAGE_TEXT = v_db_err_msg;\n    END IF;\n    SET @create_db_stmt := CONCAT(\'CREATE DATABASE \', sys.quote_identifier(in_synonym));\n    PREPARE create_db_stmt FROM @create_db_stmt;\n    EXECUTE create_db_stmt;\n    DEALLOCATE PREPARE create_db_stmt;\n    SET v_done = FALSE;\n    OPEN c_table_names;\n    c_table_names: LOOP\n        FETCH c_table_names INTO v_table;\n        IF v_done THEN\n            LEAVE c_table_names;\n        END IF;\n        CALL sys.table_exists(in_db_name, v_table, v_table_exists);\n        IF (v_table_exists = \'TEMPORARY\') THEN\n            SET v_temp_table =\n            CONCAT(\n                \'Table\',\n                 sys.quote_identifier(in_db_name),\n                 \'.\',\n                 sys.quote_identifier(v_table),\n                 \'shadows base table. View cannot be created! Terminating!\');\n             SIGNAL SQLSTATE \'HY000\'\n                 SET MESSAGE_TEXT = v_temp_table;\n             LEAVE c_table_names;\n        END IF;\n        SET @create_view_stmt = CONCAT(\n            \'CREATE SQL SECURITY INVOKER VIEW \',\n            sys.quote_identifier(in_synonym),\n            \'.\',\n            sys.quote_identifier(v_table),\n            \' AS SELECT * FROM \',\n            sys.quote_identifier(in_db_name),\n            \'.\',\n            sys.quote_identifier(v_table)\n        );\n        PREPARE create_view_stmt FROM @create_view_stmt;\n        EXECUTE create_view_stmt;\n        DEALLOCATE PREPARE create_view_stmt;\n        SET v_views_created = v_views_created + 1;\n    END LOOP;\n    CLOSE c_table_names;\n    SELECT CONCAT(\n        \'Created \', v_views_created, \' view\',\n        IF(v_views_created != 1, \'s\', \'\'), \' in the \',\n        sys.quote_identifier(in_synonym), \' database\'\n    ) AS summary;\nEND','NONE'),
('sys','format_path','FUNCTION','format_path','SQL','NO_SQL','YES','INVOKER','in_path VARCHAR(512)\n    ','varchar(512) CHARSET utf8mb3 COLLATE utf8mb3_general_ci','BEGIN\n  DECLARE v_dir VARCHAR(1024);\n  DECLARE v_path VARCHAR(512);\n  DECLARE path_separator CHAR(1) DEFAULT \'/\';\n  IF @@global.version_compile_os LIKE \'win%\' THEN\n    SET path_separator = \'\\\\\';\n  END IF;\n  IF in_path LIKE \'/private/%\' THEN\n    SET v_path = REPLACE(in_path, \'/private\', \'\');\n  ELSE\n    SET v_path = in_path;\n  END IF;\n  SET v_dir= IFNULL((SELECT VARIABLE_VALUE FROM information_schema.global_variables WHERE VARIABLE_NAME = \'innodb_data_home_dir\'), \'\');\n  IF v_path IS NULL THEN\n    RETURN NULL;\n  END IF;\n  IF v_path LIKE CONCAT(@@global.datadir, IF(SUBSTRING(@@global.datadir, -1) = path_separator, \'%\', CONCAT(path_separator, \'%\'))) ESCAPE \'|\' THEN\n    SET v_path = REPLACE(v_path, @@global.datadir, CONCAT(\'@@datadir\', IF(SUBSTRING(@@global.datadir, -1) = path_separator, path_separator, \'\')));\n    RETURN v_path;\n  END IF;\n  IF v_path LIKE CONCAT(@@global.tmpdir, IF(SUBSTRING(@@global.tmpdir, -1) = path_separator, \'%\', CONCAT(path_separator, \'%\'))) ESCAPE \'|\' THEN\n    SET v_path = REPLACE(v_path, @@global.tmpdir, CONCAT(\'@@tmpdir\', IF(SUBSTRING(@@global.tmpdir, -1) = path_separator, path_separator, \'\')));\n    RETURN v_path;\n  END IF;\n  SET v_dir= IFNULL((SELECT VARIABLE_VALUE FROM information_schema.global_variables WHERE VARIABLE_NAME = \'innodb_data_home_dir\'), \'\');\n  IF v_path LIKE CONCAT(v_dir, IF(SUBSTRING(v_dir, -1) = path_separator, \'%\', CONCAT(path_separator, \'%\'))) ESCAPE \'|\' THEN\n    SET v_path = REPLACE(v_path, v_dir, CONCAT(\'@@innodb_data_home_dir\', IF(SUBSTRING(v_dir, -1) = path_separator, path_separator, \'\')));\n    RETURN v_path;\n  END IF;\n  SET v_dir= IFNULL((SELECT VARIABLE_VALUE FROM information_schema.global_variables WHERE VARIABLE_NAME = \'innodb_log_group_home_dir\'), \'\');\n  IF v_path LIKE CONCAT(v_dir, IF(SUBSTRING(v_dir, -1) = path_separator, \'%\', CONCAT(path_separator, \'%\'))) ESCAPE \'|\' THEN\n    SET v_path = REPLACE(v_path, v_dir, CONCAT(\'@@innodb_log_group_home_dir\', IF(SUBSTRING(v_dir, -1) = path_separator, path_separator, \'\')));\n    RETURN v_path;\n  END IF;\n  SET v_dir= IFNULL((SELECT VARIABLE_VALUE FROM information_schema.global_variables WHERE VARIABLE_NAME = \'slave_load_tmpdir\'), \'\');\n  IF v_path LIKE CONCAT(v_dir, IF(SUBSTRING(v_dir, -1) = path_separator, \'%\', CONCAT(path_separator, \'%\'))) ESCAPE \'|\' THEN\n    SET v_path = REPLACE(v_path, v_dir, CONCAT(\'@@slave_load_tmpdir\', IF(SUBSTRING(v_dir, -1) = path_separator, path_separator, \'\')));\n    RETURN v_path;\n  END IF;\n  SET v_dir = IFNULL((SELECT VARIABLE_VALUE FROM information_schema.global_variables WHERE VARIABLE_NAME = \'innodb_undo_directory\'), \'\');\n  IF v_path LIKE CONCAT(v_dir, IF(SUBSTRING(v_dir, -1) = path_separator, \'%\', CONCAT(path_separator, \'%\'))) ESCAPE \'|\' THEN\n    SET v_path = REPLACE(v_path, v_dir, CONCAT(\'@@innodb_undo_directory\', IF(SUBSTRING(v_dir, -1) = path_separator, path_separator, \'\')));\n    RETURN v_path;\n  END IF;\n  IF v_path LIKE CONCAT(@@global.basedir, IF(SUBSTRING(@@global.basedir, -1) = path_separator, \'%\', CONCAT(path_separator, \'%\'))) ESCAPE \'|\' THEN\n    SET v_path = REPLACE(v_path, @@global.basedir, CONCAT(\'@@basedir\', IF(SUBSTRING(@@global.basedir, -1) = path_separator, path_separator, \'\')));\n    RETURN v_path;\n  END IF;\n  RETURN v_path;\nEND','mariadb.sys@localhost','2024-02-11 05:51:12','2024-02-11 05:51:12','','\n             Description\n             Takes a raw path value, and strips out the datadir or tmpdir\n             replacing with @@datadir and @@tmpdir respectively.\n             Also normalizes the paths across operating systems, so backslashes\n             on Windows are converted to forward slashes\n             Parameters\n             path (VARCHAR(512)):\n               The raw file path value to format.\n             Returns\n             VARCHAR(512) CHARSET UTF8\n             Example\n             mysql> select @@datadir;\n             +-----------------------------------------------+\n             | @@datadir                                     |\n             +-----------------------------------------------+\n             | /Users/mark/sandboxes/SmallTree/AMaster/data/ |\n             +-----------------------------------------------+\n             1 row in set (0.06 sec)\n             mysql> select format_path(\'/Users/mark/sandboxes/SmallTree/AMaster/data/mysql/proc.MYD\') AS path;\n             +--------------------------+\n             | path                     |\n             +--------------------------+\n             | @@datadir/mysql/proc.MYD |\n             +--------------------------+\n             1 row in set (0.03 sec)\n            ','utf8mb3','utf8mb3_general_ci','utf8mb3_general_ci','BEGIN\n  DECLARE v_dir VARCHAR(1024);\n  DECLARE v_path VARCHAR(512);\n  DECLARE path_separator CHAR(1) DEFAULT \'/\';\n  IF @@global.version_compile_os LIKE \'win%\' THEN\n    SET path_separator = \'\\\';\n  END IF;\n  IF in_path LIKE \'/private/%\' THEN\n    SET v_path = REPLACE(in_path, \'/private\', \'\');\n  ELSE\n    SET v_path = in_path;\n  END IF;\n  SET v_dir= IFNULL((SELECT VARIABLE_VALUE FROM information_schema.global_variables WHERE VARIABLE_NAME = \'innodb_data_home_dir\'), \'\');\n  IF v_path IS NULL THEN\n    RETURN NULL;\n  END IF;\n  IF v_path LIKE CONCAT(@@global.datadir, IF(SUBSTRING(@@global.datadir, -1) = path_separator, \'%\', CONCAT(path_separator, \'%\'))) ESCAPE \'|\' THEN\n    SET v_path = REPLACE(v_path, @@global.datadir, CONCAT(\'@@datadir\', IF(SUBSTRING(@@global.datadir, -1) = path_separator, path_separator, \'\')));\n    RETURN v_path;\n  END IF;\n  IF v_path LIKE CONCAT(@@global.tmpdir, IF(SUBSTRING(@@global.tmpdir, -1) = path_separator, \'%\', CONCAT(path_separator, \'%\'))) ESCAPE \'|\' THEN\n    SET v_path = REPLACE(v_path, @@global.tmpdir, CONCAT(\'@@tmpdir\', IF(SUBSTRING(@@global.tmpdir, -1) = path_separator, path_separator, \'\')));\n    RETURN v_path;\n  END IF;\n  SET v_dir= IFNULL((SELECT VARIABLE_VALUE FROM information_schema.global_variables WHERE VARIABLE_NAME = \'innodb_data_home_dir\'), \'\');\n  IF v_path LIKE CONCAT(v_dir, IF(SUBSTRING(v_dir, -1) = path_separator, \'%\', CONCAT(path_separator, \'%\'))) ESCAPE \'|\' THEN\n    SET v_path = REPLACE(v_path, v_dir, CONCAT(\'@@innodb_data_home_dir\', IF(SUBSTRING(v_dir, -1) = path_separator, path_separator, \'\')));\n    RETURN v_path;\n  END IF;\n  SET v_dir= IFNULL((SELECT VARIABLE_VALUE FROM information_schema.global_variables WHERE VARIABLE_NAME = \'innodb_log_group_home_dir\'), \'\');\n  IF v_path LIKE CONCAT(v_dir, IF(SUBSTRING(v_dir, -1) = path_separator, \'%\', CONCAT(path_separator, \'%\'))) ESCAPE \'|\' THEN\n    SET v_path = REPLACE(v_path, v_dir, CONCAT(\'@@innodb_log_group_home_dir\', IF(SUBSTRING(v_dir, -1) = path_separator, path_separator, \'\')));\n    RETURN v_path;\n  END IF;\n  SET v_dir= IFNULL((SELECT VARIABLE_VALUE FROM information_schema.global_variables WHERE VARIABLE_NAME = \'slave_load_tmpdir\'), \'\');\n  IF v_path LIKE CONCAT(v_dir, IF(SUBSTRING(v_dir, -1) = path_separator, \'%\', CONCAT(path_separator, \'%\'))) ESCAPE \'|\' THEN\n    SET v_path = REPLACE(v_path, v_dir, CONCAT(\'@@slave_load_tmpdir\', IF(SUBSTRING(v_dir, -1) = path_separator, path_separator, \'\')));\n    RETURN v_path;\n  END IF;\n  SET v_dir = IFNULL((SELECT VARIABLE_VALUE FROM information_schema.global_variables WHERE VARIABLE_NAME = \'innodb_undo_directory\'), \'\');\n  IF v_path LIKE CONCAT(v_dir, IF(SUBSTRING(v_dir, -1) = path_separator, \'%\', CONCAT(path_separator, \'%\'))) ESCAPE \'|\' THEN\n    SET v_path = REPLACE(v_path, v_dir, CONCAT(\'@@innodb_undo_directory\', IF(SUBSTRING(v_dir, -1) = path_separator, path_separator, \'\')));\n    RETURN v_path;\n  END IF;\n  IF v_path LIKE CONCAT(@@global.basedir, IF(SUBSTRING(@@global.basedir, -1) = path_separator, \'%\', CONCAT(path_separator, \'%\'))) ESCAPE \'|\' THEN\n    SET v_path = REPLACE(v_path, @@global.basedir, CONCAT(\'@@basedir\', IF(SUBSTRING(@@global.basedir, -1) = path_separator, path_separator, \'\')));\n    RETURN v_path;\n  END IF;\n  RETURN v_path;\nEND','NONE'),
('sys','format_statement','FUNCTION','format_statement','SQL','NO_SQL','YES','INVOKER','statement LONGTEXT\n    ','longtext CHARSET utf8mb3 COLLATE utf8mb3_general_ci','BEGIN\n  IF @sys.statement_truncate_len IS NULL THEN\n      SET @sys.statement_truncate_len = sys_get_config(\'statement_truncate_len\', 64);\n  END IF;\n  IF CHAR_LENGTH(statement) > @sys.statement_truncate_len THEN\n      RETURN REPLACE(CONCAT(LEFT(statement, (@sys.statement_truncate_len/2)-2), \' ... \', RIGHT(statement, (@sys.statement_truncate_len/2)-2)), \'\\n\', \' \');\n  ELSE\n      RETURN REPLACE(statement, \'\\n\', \' \');\n  END IF;\nEND','mariadb.sys@localhost','2024-02-11 05:51:12','2024-02-11 05:51:12','','\n             Description\n             Formats a normalized statement, truncating it if it is > 64 characters long by default.\n             To configure the length to truncate the statement to by default, update the `statement_truncate_len`\n             variable with `sys_config` table to a different value. Alternatively, to change it just for just\n             your particular session, use `SET @sys.statement_truncate_len := <some new value>`.\n             Useful for printing statement related data from Performance Schema from\n             the command line.\n             Parameters\n             statement (LONGTEXT):\n               The statement to format.\n             Returns\n             LONGTEXT\n             Example\n             mysql> SELECT sys.format_statement(digest_text)\n                 ->   FROM performance_schema.events_statements_summary_by_digest\n                 ->  ORDER by sum_timer_wait DESC limit 5;\n             +-------------------------------------------------------------------+\n             | sys.format_statement(digest_text)                                 |\n             +-------------------------------------------------------------------+\n             | CREATE SQL SECURITY INVOKER VI ... KE ? AND `variable_value` > ?  |\n             | CREATE SQL SECURITY INVOKER VI ... ait` IS NOT NULL , `esc` . ... |\n             | CREATE SQL SECURITY INVOKER VI ... ait` IS NOT NULL , `sys` . ... |\n             | CREATE SQL SECURITY INVOKER VI ...  , `compressed_size` ) ) DESC  |\n             | CREATE SQL SECURITY INVOKER VI ... LIKE ? ORDER BY `timer_start`  |\n             +-------------------------------------------------------------------+\n             5 rows in set (0.00 sec)\n            ','utf8mb3','utf8mb3_general_ci','utf8mb3_general_ci','BEGIN\n  IF @sys.statement_truncate_len IS NULL THEN\n      SET @sys.statement_truncate_len = sys_get_config(\'statement_truncate_len\', 64);\n  END IF;\n  IF CHAR_LENGTH(statement) > @sys.statement_truncate_len THEN\n      RETURN REPLACE(CONCAT(LEFT(statement, (@sys.statement_truncate_len/2)-2), \' ... \', RIGHT(statement, (@sys.statement_truncate_len/2)-2)), \'\\n\', \' \');\n  ELSE\n      RETURN REPLACE(statement, \'\\n\', \' \');\n  END IF;\nEND','NONE'),
('sys','list_add','FUNCTION','list_add','SQL','CONTAINS_SQL','YES','INVOKER','in_list TEXT,\n        in_add_value TEXT\n    ','text CHARSET utf8mb3 COLLATE utf8mb3_general_ci','BEGIN\n    IF (in_add_value IS NULL) THEN\n        SIGNAL SQLSTATE \'02200\'\n           SET MESSAGE_TEXT = \'Function sys.list_add: in_add_value input variable should not be NULL\',\n               MYSQL_ERRNO = 1138;\n    END IF;\n    IF (in_list IS NULL OR LENGTH(in_list) = 0) THEN\n        RETURN in_add_value;\n    END IF;\n    RETURN (SELECT CONCAT(TRIM(BOTH \',\' FROM TRIM(in_list)), \',\', in_add_value));\nEND','mariadb.sys@localhost','2024-02-11 05:51:12','2024-02-11 05:51:12','','\n             Description\n             Takes a list, and a value to add to the list, and returns the resulting list.\n             Useful for altering certain session variables, like sql_mode or optimizer_switch for instance.\n             Parameters\n             in_list (TEXT):\n               The comma separated list to add a value to\n             in_add_value (TEXT):\n               The value to add to the input list\n             Returns\n             TEXT\n             Example\n             mysql> select @@sql_mode;\n             +-----------------------------------------------------------------------------------+\n             | @@sql_mode                                                                        |\n             +-----------------------------------------------------------------------------------+\n             | ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |\n             +-----------------------------------------------------------------------------------+\n             1 row in set (0.00 sec)\n             mysql> set sql_mode = sys.list_add(@@sql_mode, \'ANSI_QUOTES\');\n             Query OK, 0 rows affected (0.06 sec)\n             mysql> select @@sql_mode;\n             +-----------------------------------------------------------------------------------------------+\n             | @@sql_mode                                                                                    |\n             +-----------------------------------------------------------------------------------------------+\n             | ANSI_QUOTES,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |\n             +-----------------------------------------------------------------------------------------------+\n             1 row in set (0.00 sec)\n            ','utf8mb3','utf8mb3_general_ci','utf8mb3_general_ci','BEGIN\n    IF (in_add_value IS NULL) THEN\n        SIGNAL SQLSTATE \'02200\'\n           SET MESSAGE_TEXT = \'Function sys.list_add: in_add_value input variable should not be NULL\',\n               MYSQL_ERRNO = 1138;\n    END IF;\n    IF (in_list IS NULL OR LENGTH(in_list) = 0) THEN\n        RETURN in_add_value;\n    END IF;\n    RETURN (SELECT CONCAT(TRIM(BOTH \',\' FROM TRIM(in_list)), \',\', in_add_value));\nEND','NONE'),
('sys','diagnostics','PROCEDURE','diagnostics','SQL','READS_SQL_DATA','NO','INVOKER','\n        IN in_max_runtime int unsigned, IN in_interval int unsigned,\n        IN in_auto_config enum (\'current\', \'medium\', \'full\')\n    ','','BEGIN\n    DECLARE v_start, v_runtime, v_iter_start, v_sleep DECIMAL(20,2) DEFAULT 0.0;\n    DECLARE v_has_innodb, v_has_ndb, v_has_ps, v_has_replication, v_has_ps_replication VARCHAR(8) CHARSET utf8 DEFAULT \'NO\';\n    DECLARE v_this_thread_enabled, v_has_ps_vars, v_has_metrics ENUM(\'YES\', \'NO\');\n    DECLARE v_table_name, v_banner VARCHAR(64) CHARSET utf8;\n    DECLARE v_sql_status_summary_select, v_sql_status_summary_delta, v_sql_status_summary_from, v_no_delta_names TEXT;\n    DECLARE v_output_time, v_output_time_prev DECIMAL(20,3) UNSIGNED;\n    DECLARE v_output_count, v_count, v_old_group_concat_max_len INT UNSIGNED DEFAULT 0;\n    DECLARE v_status_summary_width TINYINT UNSIGNED DEFAULT 50;\n    DECLARE v_done BOOLEAN DEFAULT FALSE;\n    DECLARE c_ndbinfo CURSOR FOR\n        SELECT TABLE_NAME\n          FROM information_schema.TABLES\n         WHERE TABLE_SCHEMA = \'ndbinfo\'\n               AND TABLE_NAME NOT IN (\n                  \'blocks\',\n                  \'config_params\',\n                  \'dict_obj_types\',\n                  \'disk_write_speed_base\',\n                  \'memory_per_fragment\',\n                  \'memoryusage\',\n                  \'operations_per_fragment\',\n                  \'threadblocks\'\n               );\n    DECLARE c_sysviews_w_delta CURSOR FOR\n        SELECT table_name\n          FROM tmp_sys_views_delta\n         ORDER BY table_name;\n    DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = TRUE;\n    SELECT INSTRUMENTED INTO v_this_thread_enabled FROM performance_schema.threads WHERE PROCESSLIST_ID = CONNECTION_ID();\n    IF (v_this_thread_enabled = \'YES\') THEN\n        CALL sys.ps_setup_disable_thread(CONNECTION_ID());\n    END IF;\n    IF (in_max_runtime < in_interval) THEN\n        SIGNAL SQLSTATE \'45000\'\n           SET MESSAGE_TEXT = \'in_max_runtime must be greater than or equal to in_interval\';\n    END IF;\n    IF (in_max_runtime = 0) THEN\n        SIGNAL SQLSTATE \'45000\'\n           SET MESSAGE_TEXT = \'in_max_runtime must be greater than 0\';\n    END IF;\n    IF (in_interval = 0) THEN\n        SIGNAL SQLSTATE \'45000\'\n           SET MESSAGE_TEXT = \'in_interval must be greater than 0\';\n    END IF;\n    IF (@sys.diagnostics.allow_i_s_tables IS NULL) THEN\n        SET @sys.diagnostics.allow_i_s_tables = sys.sys_get_config(\'diagnostics.allow_i_s_tables\', \'OFF\');\n    END IF;\n    IF (@sys.diagnostics.include_raw IS NULL) THEN\n        SET @sys.diagnostics.include_raw      = sys.sys_get_config(\'diagnostics.include_raw\'     , \'OFF\');\n    END IF;\n    IF (@sys.debug IS NULL) THEN\n        SET @sys.debug                        = sys.sys_get_config(\'debug\'                       , \'OFF\');\n    END IF;\n    IF (@sys.statement_truncate_len IS NULL) THEN\n        SET @sys.statement_truncate_len       = sys.sys_get_config(\'statement_truncate_len\'      , \'64\' );\n    END IF;\n    SET @log_bin := @@sql_log_bin;\n    IF (@log_bin = 1) THEN\n        SET sql_log_bin = 0;\n    END IF;\n    SET v_no_delta_names = CONCAT(\'s%{COUNT}.Variable_name NOT IN (\',\n        \'\'\'innodb_buffer_pool_pages_total\'\', \',\n        \'\'\'innodb_page_size\'\', \',\n        \'\'\'last_query_cost\'\', \',\n        \'\'\'last_query_partial_plans\'\', \',\n        \'\'\'qcache_total_blocks\'\', \',\n        \'\'\'slave_last_heartbeat\'\', \',\n        \'\'\'ssl_ctx_verify_depth\'\', \',\n        \'\'\'ssl_ctx_verify_mode\'\', \',\n        \'\'\'ssl_session_cache_size\'\', \',\n        \'\'\'ssl_verify_depth\'\', \',\n        \'\'\'ssl_verify_mode\'\', \',\n        \'\'\'ssl_version\'\', \',\n        \'\'\'buffer_flush_lsn_avg_rate\'\', \',\n        \'\'\'buffer_flush_pct_for_dirty\'\', \',\n        \'\'\'buffer_flush_pct_for_lsn\'\', \',\n        \'\'\'buffer_pool_pages_total\'\', \',\n        \'\'\'lock_row_lock_time_avg\'\', \',\n        \'\'\'lock_row_lock_time_max\'\', \',\n        \'\'\'innodb_page_size\'\'\',\n    \')\');\n    IF (in_auto_config <> \'current\') THEN\n        IF (@sys.debug = \'ON\') THEN\n            SELECT CONCAT(\'Updating Performance Schema configuration to \', in_auto_config) AS \'Debug\';\n        END IF;\n        CALL sys.ps_setup_save(0);\n        IF (in_auto_config = \'medium\') THEN\n            UPDATE performance_schema.setup_consumers\n                SET ENABLED = \'YES\'\n            WHERE NAME NOT LIKE \'%\\_history%\';\n            UPDATE performance_schema.setup_instruments\n                SET ENABLED = \'YES\',\n                    TIMED   = \'YES\'\n            WHERE NAME NOT LIKE \'wait/synch/%\';\n        ELSEIF (in_auto_config = \'full\') THEN\n            UPDATE performance_schema.setup_consumers\n                SET ENABLED = \'YES\';\n            UPDATE performance_schema.setup_instruments\n                SET ENABLED = \'YES\',\n                    TIMED   = \'YES\';\n        END IF;\n        UPDATE performance_schema.threads\n           SET INSTRUMENTED = \'YES\'\n         WHERE PROCESSLIST_ID <> CONNECTION_ID();\n    END IF;\n    SET v_start        = UNIX_TIMESTAMP(NOW(2)),\n        in_interval    = IFNULL(in_interval, 30),\n        in_max_runtime = IFNULL(in_max_runtime, 60);\n    SET v_banner = REPEAT(\n                      \'-\',\n                      LEAST(\n                         GREATEST(\n                            36,\n                            CHAR_LENGTH(VERSION()),\n                            CHAR_LENGTH(@@global.version_comment),\n                            CHAR_LENGTH(@@global.version_compile_os),\n                            CHAR_LENGTH(@@global.version_compile_machine),\n                            CHAR_LENGTH(@@global.socket),\n                            CHAR_LENGTH(@@global.datadir)\n                         ),\n                         64\n                      )\n                   );\n    SELECT \'Hostname\' AS \'Name\', @@global.hostname AS \'Value\'\n    UNION ALL\n    SELECT \'Port\' AS \'Name\', @@global.port AS \'Value\'\n    UNION ALL\n    SELECT \'Socket\' AS \'Name\', @@global.socket AS \'Value\'\n    UNION ALL\n    SELECT \'Datadir\' AS \'Name\', @@global.datadir AS \'Value\'\n    UNION ALL\n    SELECT REPEAT(\'-\', 23) AS \'Name\', v_banner AS \'Value\'\n    UNION ALL\n    SELECT \'MySQL Version\' AS \'Name\', VERSION() AS \'Value\'\n    UNION ALL\n    SELECT \'Sys Schema Version\' AS \'Name\', (SELECT sys_version FROM sys.version) AS \'Value\'\n    UNION ALL\n    SELECT \'Version Comment\' AS \'Name\', @@global.version_comment AS \'Value\'\n    UNION ALL\n    SELECT \'Version Compile OS\' AS \'Name\', @@global.version_compile_os AS \'Value\'\n    UNION ALL\n    SELECT \'Version Compile Machine\' AS \'Name\', @@global.version_compile_machine AS \'Value\'\n    UNION ALL\n    SELECT REPEAT(\'-\', 23) AS \'Name\', v_banner AS \'Value\'\n    UNION ALL\n    SELECT \'UTC Time\' AS \'Name\', UTC_TIMESTAMP() AS \'Value\'\n    UNION ALL\n    SELECT \'Local Time\' AS \'Name\', NOW() AS \'Value\'\n    UNION ALL\n    SELECT \'Time Zone\' AS \'Name\', @@global.time_zone AS \'Value\'\n    UNION ALL\n    SELECT \'System Time Zone\' AS \'Name\', @@global.system_time_zone AS \'Value\'\n    UNION ALL\n    SELECT \'Time Zone Offset\' AS \'Name\', TIMEDIFF(NOW(), UTC_TIMESTAMP()) AS \'Value\';\n    SET v_has_innodb         = IFNULL((SELECT SUPPORT FROM information_schema.ENGINES WHERE ENGINE = \'InnoDB\'), \'NO\'),\n        v_has_ndb            = IFNULL((SELECT SUPPORT FROM information_schema.ENGINES WHERE ENGINE = \'NDBCluster\'), \'NO\'),\n        v_has_ps             = IFNULL((SELECT SUPPORT FROM information_schema.ENGINES WHERE ENGINE = \'PERFORMANCE_SCHEMA\'), \'NO\'),\n        v_has_ps_replication = IF(v_has_ps = \'YES\'\n                                   AND EXISTS(SELECT 1 FROM information_schema.TABLES WHERE TABLE_SCHEMA = \'performance_schema\' AND TABLE_NAME = \'replication_applier_status\'),\n                                   \'YES\',\n                                   \'NO\'\n                               ),\n        v_has_replication    = \'MAYBE\',\n        v_has_metrics        = IF(v_has_ps = \'YES\' OR (sys.version_major() = 5 AND sys.version_minor() = 6), \'YES\', \'NO\'),\n        v_has_ps_vars        = \'NO\';\n    \n    \n    IF (@sys.debug = \'ON\') THEN\n       SELECT v_has_innodb AS \'Has_InnoDB\', v_has_ndb AS \'Has_NDBCluster\',\n              v_has_ps AS \'Has_Performance_Schema\', v_has_ps_vars AS \'Has_P_S_SHOW_Variables\',\n              v_has_metrics AS \'Has_metrics\',\n              v_has_ps_replication \'AS Has_P_S_Replication\', v_has_replication AS \'Has_Replication\';\n    END IF;\n    IF (v_has_innodb IN (\'DEFAULT\', \'YES\')) THEN\n        SET @sys.diagnostics.sql = \'SHOW ENGINE InnoDB STATUS\';\n        PREPARE stmt_innodb_status FROM @sys.diagnostics.sql;\n    END IF;\n    IF (v_has_ps = \'YES\') THEN\n        SET @sys.diagnostics.sql = \'SHOW ENGINE PERFORMANCE_SCHEMA STATUS\';\n        PREPARE stmt_ps_status FROM @sys.diagnostics.sql;\n    END IF;\n    IF (v_has_ndb IN (\'DEFAULT\', \'YES\')) THEN\n        SET @sys.diagnostics.sql = \'SHOW ENGINE NDBCLUSTER STATUS\';\n        PREPARE stmt_ndbcluster_status FROM @sys.diagnostics.sql;\n    END IF;\n    SET @sys.diagnostics.sql_gen_query_template = \'SELECT CONCAT(\n           \'\'SELECT \'\',\n           GROUP_CONCAT(\n               CASE WHEN (SUBSTRING(TABLE_NAME, 3), COLUMN_NAME) IN (\n                                (\'\'io_global_by_file_by_bytes\'\', \'\'total\'\'),\n                                (\'\'io_global_by_wait_by_bytes\'\', \'\'total_requested\'\')\n                         )\n                         THEN CONCAT(\'\'sys.format_bytes(\'\', COLUMN_NAME, \'\') AS \'\', COLUMN_NAME)\n                    WHEN SUBSTRING(COLUMN_NAME, -8) = \'\'_latency\'\'\n                         THEN CONCAT(\'\'sys.format_time(\'\', COLUMN_NAME, \'\') AS \'\', COLUMN_NAME)\n                    WHEN SUBSTRING(COLUMN_NAME, -7) = \'\'_memory\'\' OR SUBSTRING(COLUMN_NAME, -17) = \'\'_memory_allocated\'\'\n                         OR ((SUBSTRING(COLUMN_NAME, -5) = \'\'_read\'\' OR SUBSTRING(COLUMN_NAME, -8) = \'\'_written\'\' OR SUBSTRING(COLUMN_NAME, -6) = \'\'_write\'\') AND SUBSTRING(COLUMN_NAME, 1, 6) <> \'\'COUNT_\'\')\n                         THEN CONCAT(\'\'sys.format_bytes(\'\', COLUMN_NAME, \'\') AS \'\', COLUMN_NAME)\n                    ELSE COLUMN_NAME\n               END\n               ORDER BY ORDINAL_POSITION\n               SEPARATOR \'\',\\n       \'\'\n           ),\n           \'\'\\n  FROM tmp_\'\', SUBSTRING(TABLE_NAME FROM 3), \'\'_%{OUTPUT}\'\'\n       ) AS Query INTO @sys.diagnostics.sql_select\n  FROM information_schema.COLUMNS\n WHERE TABLE_SCHEMA = \'\'sys\'\' AND TABLE_NAME = ?\n GROUP BY TABLE_NAME\';\n    SET @sys.diagnostics.sql_gen_query_delta = \'SELECT CONCAT(\n           \'\'SELECT \'\',\n           GROUP_CONCAT(\n               CASE WHEN FIND_IN_SET(COLUMN_NAME, diag.pk)\n                         THEN COLUMN_NAME\n                    WHEN diag.TABLE_NAME = \'\'io_global_by_file_by_bytes\'\' AND COLUMN_NAME = \'\'write_pct\'\'\n                         THEN CONCAT(\'\'IFNULL(ROUND(100-(((e.total_read-IFNULL(s.total_read, 0))\'\',\n                                     \'\'/NULLIF(((e.total_read-IFNULL(s.total_read, 0))+(e.total_written-IFNULL(s.total_written, 0))), 0))*100), 2), 0.00) AS \'\',\n                                     COLUMN_NAME)\n                    WHEN (diag.TABLE_NAME, COLUMN_NAME) IN (\n                                (\'\'io_global_by_file_by_bytes\'\', \'\'total\'\'),\n                                (\'\'io_global_by_wait_by_bytes\'\', \'\'total_requested\'\')\n                         )\n                         THEN CONCAT(\'\'sys.format_bytes(e.\'\', COLUMN_NAME, \'\'-IFNULL(s.\'\', COLUMN_NAME, \'\', 0)) AS \'\', COLUMN_NAME)\n                    WHEN SUBSTRING(COLUMN_NAME, 1, 4) IN (\'\'max_\'\', \'\'min_\'\') AND SUBSTRING(COLUMN_NAME, -8) = \'\'_latency\'\'\n                         THEN CONCAT(\'\'sys.format_time(e.\'\', COLUMN_NAME, \'\') AS \'\', COLUMN_NAME)\n                    WHEN COLUMN_NAME = \'\'avg_latency\'\'\n                         THEN CONCAT(\'\'sys.format_time((e.total_latency - IFNULL(s.total_latency, 0))\'\',\n                                     \'\'/NULLIF(e.total - IFNULL(s.total, 0), 0)) AS \'\', COLUMN_NAME)\n                    WHEN SUBSTRING(COLUMN_NAME, -12) = \'\'_avg_latency\'\'\n                         THEN CONCAT(\'\'sys.format_time((e.\'\', SUBSTRING(COLUMN_NAME FROM 1 FOR CHAR_LENGTH(COLUMN_NAME)-12), \'\'_latency - IFNULL(s.\'\', SUBSTRING(COLUMN_NAME FROM 1 FOR CHAR_LENGTH(COLUMN_NAME)-12), \'\'_latency, 0))\'\',\n                                     \'\'/NULLIF(e.\'\', SUBSTRING(COLUMN_NAME FROM 1 FOR CHAR_LENGTH(COLUMN_NAME)-12), \'\'s - IFNULL(s.\'\', SUBSTRING(COLUMN_NAME FROM 1 FOR CHAR_LENGTH(COLUMN_NAME)-12), \'\'s, 0), 0)) AS \'\', COLUMN_NAME)\n                    WHEN SUBSTRING(COLUMN_NAME, -8) = \'\'_latency\'\'\n                         THEN CONCAT(\'\'sys.format_time(e.\'\', COLUMN_NAME, \'\' - IFNULL(s.\'\', COLUMN_NAME, \'\', 0)) AS \'\', COLUMN_NAME)\n                    WHEN COLUMN_NAME IN (\'\'avg_read\'\', \'\'avg_write\'\', \'\'avg_written\'\')\n                         THEN CONCAT(\'\'sys.format_bytes(IFNULL((e.total_\'\', IF(COLUMN_NAME = \'\'avg_read\'\', \'\'read\'\', \'\'written\'\'), \'\'-IFNULL(s.total_\'\', IF(COLUMN_NAME = \'\'avg_read\'\', \'\'read\'\', \'\'written\'\'), \'\', 0))\'\',\n                                     \'\'/NULLIF(e.count_\'\', IF(COLUMN_NAME = \'\'avg_read\'\', \'\'read\'\', \'\'write\'\'), \'\'-IFNULL(s.count_\'\', IF(COLUMN_NAME = \'\'avg_read\'\', \'\'read\'\', \'\'write\'\'), \'\', 0), 0), 0)) AS \'\',\n                                     COLUMN_NAME)\n                    WHEN SUBSTRING(COLUMN_NAME, -7) = \'\'_memory\'\' OR SUBSTRING(COLUMN_NAME, -17) = \'\'_memory_allocated\'\'\n                         OR ((SUBSTRING(COLUMN_NAME, -5) = \'\'_read\'\' OR SUBSTRING(COLUMN_NAME, -8) = \'\'_written\'\' OR SUBSTRING(COLUMN_NAME, -6) = \'\'_write\'\') AND SUBSTRING(COLUMN_NAME, 1, 6) <> \'\'COUNT_\'\')\n                         THEN CONCAT(\'\'sys.format_bytes(e.\'\', COLUMN_NAME, \'\' - IFNULL(s.\'\', COLUMN_NAME, \'\', 0)) AS \'\', COLUMN_NAME)\n                    ELSE CONCAT(\'\'(e.\'\', COLUMN_NAME, \'\' - IFNULL(s.\'\', COLUMN_NAME, \'\', 0)) AS \'\', COLUMN_NAME)\n               END\n               ORDER BY ORDINAL_POSITION\n               SEPARATOR \'\',\\n       \'\'\n           ),\n           \'\'\\n  FROM tmp_\'\', diag.TABLE_NAME, \'\'_end e\n       LEFT OUTER JOIN tmp_\'\', diag.TABLE_NAME, \'\'_start s USING (\'\', diag.pk, \'\')\'\'\n       ) AS Query INTO @sys.diagnostics.sql_select\n  FROM tmp_sys_views_delta diag\n       INNER JOIN information_schema.COLUMNS c ON c.TABLE_NAME = CONCAT(\'\'x$\'\', diag.TABLE_NAME)\n WHERE c.TABLE_SCHEMA = \'\'sys\'\' AND diag.TABLE_NAME = ?\n GROUP BY diag.TABLE_NAME\';\n    IF (v_has_ps = \'YES\') THEN\n        DROP TEMPORARY TABLE IF EXISTS tmp_sys_views_delta;\n        CREATE TEMPORARY TABLE tmp_sys_views_delta (\n            TABLE_NAME varchar(64) NOT NULL,\n            order_by text COMMENT \'ORDER BY clause for the initial and overall views\',\n            order_by_delta text COMMENT \'ORDER BY clause for the delta views\',\n            where_delta text COMMENT \'WHERE clause to use for delta views to only include rows with a \"count\" > 0\',\n            limit_rows int unsigned COMMENT \'The maximum number of rows to include for the view\',\n            pk varchar(128) COMMENT \'Used with the FIND_IN_SET() function so use comma separated list without whitespace\',\n            PRIMARY KEY (TABLE_NAME)\n        );\n        IF (@sys.debug = \'ON\') THEN\n            SELECT \'Populating tmp_sys_views_delta\' AS \'Debug\';\n        END IF;\n        INSERT INTO tmp_sys_views_delta\n        VALUES (\'host_summary\'                       , \'%{TABLE}.statement_latency DESC\',\n                                                       \'(e.statement_latency-IFNULL(s.statement_latency, 0)) DESC\',\n                                                       \'(e.statements - IFNULL(s.statements, 0)) > 0\', NULL, \'host\'),\n               (\'host_summary_by_file_io\'            , \'%{TABLE}.io_latency DESC\',\n                                                       \'(e.io_latency-IFNULL(s.io_latency, 0)) DESC\',\n                                                       \'(e.ios - IFNULL(s.ios, 0)) > 0\', NULL, \'host\'),\n               (\'host_summary_by_file_io_type\'       , \'%{TABLE}.host, %{TABLE}.total_latency DESC\',\n                                                       \'e.host, (e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'host,event_name\'),\n               (\'host_summary_by_stages\'             , \'%{TABLE}.host, %{TABLE}.total_latency DESC\',\n                                                       \'e.host, (e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'host,event_name\'),\n               (\'host_summary_by_statement_latency\'  , \'%{TABLE}.total_latency DESC\',\n                                                       \'(e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'host\'),\n               (\'host_summary_by_statement_type\'     , \'%{TABLE}.host, %{TABLE}.total_latency DESC\',\n                                                       \'e.host, (e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'host,statement\'),\n               (\'io_by_thread_by_latency\'            , \'%{TABLE}.total_latency DESC\',\n                                                       \'(e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'user,thread_id,processlist_id\'),\n               (\'io_global_by_file_by_bytes\'         , \'%{TABLE}.total DESC\',\n                                                       \'(e.total-IFNULL(s.total, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', 100, \'file\'),\n               (\'io_global_by_file_by_latency\'       , \'%{TABLE}.total_latency DESC\',\n                                                       \'(e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', 100, \'file\'),\n               (\'io_global_by_wait_by_bytes\'         , \'%{TABLE}.total_requested DESC\',\n                                                       \'(e.total_requested-IFNULL(s.total_requested, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'event_name\'),\n               (\'io_global_by_wait_by_latency\'       , \'%{TABLE}.total_latency DESC\',\n                                                       \'(e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'event_name\'),\n               (\'schema_index_statistics\'            , \'(%{TABLE}.select_latency+%{TABLE}.insert_latency+%{TABLE}.update_latency+%{TABLE}.delete_latency) DESC\',\n                                                       \'((e.select_latency+e.insert_latency+e.update_latency+e.delete_latency)-IFNULL(s.select_latency+s.insert_latency+s.update_latency+s.delete_latency, 0)) DESC\',\n                                                       \'((e.rows_selected+e.insert_latency+e.rows_updated+e.rows_deleted)-IFNULL(s.rows_selected+s.rows_inserted+s.rows_updated+s.rows_deleted, 0)) > 0\',\n                                                       100, \'table_schema,table_name,index_name\'),\n               (\'schema_table_statistics\'            , \'%{TABLE}.total_latency DESC\',\n                                                       \'(e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total_latency-IFNULL(s.total_latency, 0)) > 0\', 100, \'table_schema,table_name\'),\n               (\'schema_tables_with_full_table_scans\', \'%{TABLE}.rows_full_scanned DESC\',\n                                                       \'(e.rows_full_scanned-IFNULL(s.rows_full_scanned, 0)) DESC\',\n                                                       \'(e.rows_full_scanned-IFNULL(s.rows_full_scanned, 0)) > 0\', 100, \'object_schema,object_name\'),\n               (\'user_summary\'                       , \'%{TABLE}.statement_latency DESC\',\n                                                       \'(e.statement_latency-IFNULL(s.statement_latency, 0)) DESC\',\n                                                       \'(e.statements - IFNULL(s.statements, 0)) > 0\', NULL, \'user\'),\n               (\'user_summary_by_file_io\'            , \'%{TABLE}.io_latency DESC\',\n                                                       \'(e.io_latency-IFNULL(s.io_latency, 0)) DESC\',\n                                                       \'(e.ios - IFNULL(s.ios, 0)) > 0\', NULL, \'user\'),\n               (\'user_summary_by_file_io_type\'       , \'%{TABLE}.user, %{TABLE}.latency DESC\',\n                                                       \'e.user, (e.latency-IFNULL(s.latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'user,event_name\'),\n               (\'user_summary_by_stages\'             , \'%{TABLE}.user, %{TABLE}.total_latency DESC\',\n                                                       \'e.user, (e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'user,event_name\'),\n               (\'user_summary_by_statement_latency\'  , \'%{TABLE}.total_latency DESC\',\n                                                       \'(e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'user\'),\n               (\'user_summary_by_statement_type\'     , \'%{TABLE}.user, %{TABLE}.total_latency DESC\',\n                                                       \'e.user, (e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'user,statement\'),\n               (\'wait_classes_global_by_avg_latency\' , \'IFNULL(%{TABLE}.total_latency / NULLIF(%{TABLE}.total, 0), 0) DESC\',\n                                                       \'IFNULL((e.total_latency-IFNULL(s.total_latency, 0)) / NULLIF((e.total - IFNULL(s.total, 0)), 0), 0) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'event_class\'),\n               (\'wait_classes_global_by_latency\'     , \'%{TABLE}.total_latency DESC\',\n                                                       \'(e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'event_class\'),\n               (\'waits_by_host_by_latency\'           , \'%{TABLE}.host, %{TABLE}.total_latency DESC\',\n                                                       \'e.host, (e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'host,event\'),\n               (\'waits_by_user_by_latency\'           , \'%{TABLE}.user, %{TABLE}.total_latency DESC\',\n                                                       \'e.user, (e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'user,event\'),\n               (\'waits_global_by_latency\'            , \'%{TABLE}.total_latency DESC\',\n                                                       \'(e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'events\')\n        ;\n    END IF;\n    SELECT \'\n=======================\n     Configuration\n=======================\n\' AS \'\';\n    SELECT \'GLOBAL VARIABLES\' AS \'The following output is:\';\n    IF (v_has_ps_vars = \'YES\') THEN\n        SELECT LOWER(VARIABLE_NAME) AS Variable_name, VARIABLE_VALUE AS Variable_value FROM performance_schema.global_variables ORDER BY VARIABLE_NAME;\n    ELSE\n        SELECT LOWER(VARIABLE_NAME) AS Variable_name, VARIABLE_VALUE AS Variable_value FROM information_schema.GLOBAL_VARIABLES ORDER BY VARIABLE_NAME;\n    END IF;\n    IF (v_has_ps = \'YES\') THEN\n        SELECT \'Performance Schema Setup - Actors\' AS \'The following output is:\';\n        SELECT * FROM performance_schema.setup_actors;\n        SELECT \'Performance Schema Setup - Consumers\' AS \'The following output is:\';\n        SELECT NAME AS Consumer, ENABLED, sys.ps_is_consumer_enabled(NAME) AS COLLECTS\n          FROM performance_schema.setup_consumers;\n        SELECT \'Performance Schema Setup - Instruments\' AS \'The following output is:\';\n        SELECT SUBSTRING_INDEX(NAME, \'/\', 2) AS \'InstrumentClass\',\n               ROUND(100*SUM(IF(ENABLED = \'YES\', 1, 0))/COUNT(*), 2) AS \'EnabledPct\',\n               ROUND(100*SUM(IF(TIMED = \'YES\', 1, 0))/COUNT(*), 2) AS \'TimedPct\'\n          FROM performance_schema.setup_instruments\n         GROUP BY SUBSTRING_INDEX(NAME, \'/\', 2)\n         ORDER BY SUBSTRING_INDEX(NAME, \'/\', 2);\n        SELECT \'Performance Schema Setup - Objects\' AS \'The following output is:\';\n        SELECT * FROM performance_schema.setup_objects;\n        SELECT \'Performance Schema Setup - Threads\' AS \'The following output is:\';\n        SELECT `TYPE` AS ThreadType, COUNT(*) AS \'Total\', ROUND(100*SUM(IF(INSTRUMENTED = \'YES\', 1, 0))/COUNT(*), 2) AS \'InstrumentedPct\'\n          FROM performance_schema.threads\n        GROUP BY TYPE;\n    END IF;\n    IF (v_has_replication = \'NO\') THEN\n        SELECT \'No Replication Configured\' AS \'Replication Status\';\n    ELSE\n        SELECT CONCAT(\'Replication Configured: \', v_has_replication, \' - Performance Schema Replication Tables: \', v_has_ps_replication) AS \'Replication Status\';\n        IF (v_has_ps_replication = \'YES\') THEN\n            SELECT \'Replication - Connection Configuration\' AS \'The following output is:\';\n            SELECT * FROM performance_schema.replication_connection_configuration;\n        END IF;\n        IF (v_has_ps_replication = \'YES\') THEN\n            SELECT \'Replication - Applier Configuration\' AS \'The following output is:\';\n            SELECT * FROM performance_schema.replication_applier_configuration ORDER BY CHANNEL_NAME;\n        END IF;\n    END IF;\n    IF (v_has_ndb IN (\'DEFAULT\', \'YES\')) THEN\n       SELECT \'Cluster Thread Blocks\' AS \'The following output is:\';\n       SELECT * FROM ndbinfo.threadblocks;\n    END IF;\n    IF (v_has_ps = \'YES\') THEN\n        IF (@sys.diagnostics.include_raw = \'ON\') THEN\n            SELECT \'\n========================\n     Initial Status\n========================\n\' AS \'\';\n        END IF;\n        DROP TEMPORARY TABLE IF EXISTS tmp_digests_start;\n        CALL sys.statement_performance_analyzer(\'create_tmp\', \'tmp_digests_start\', NULL);\n        CALL sys.statement_performance_analyzer(\'snapshot\', NULL, NULL);\n        CALL sys.statement_performance_analyzer(\'save\', \'tmp_digests_start\', NULL);\n        IF (@sys.diagnostics.include_raw = \'ON\') THEN\n            SET @sys.diagnostics.sql = REPLACE(@sys.diagnostics.sql_gen_query_template, \'%{OUTPUT}\', \'start\');\n            IF (@sys.debug = \'ON\') THEN\n                SELECT \'The following query will be used to generate the query for each sys view\' AS \'Debug\';\n                SELECT @sys.diagnostics.sql AS \'Debug\';\n            END IF;\n            PREPARE stmt_gen_query FROM @sys.diagnostics.sql;\n        END IF;\n        SET v_done = FALSE;\n        OPEN c_sysviews_w_delta;\n        c_sysviews_w_delta_loop: LOOP\n            FETCH c_sysviews_w_delta INTO v_table_name;\n            IF v_done THEN\n                LEAVE c_sysviews_w_delta_loop;\n            END IF;\n            IF (@sys.debug = \'ON\') THEN\n                SELECT CONCAT(\'The following queries are for storing the initial content of \', v_table_name) AS \'Debug\';\n            END IF;\n            CALL sys.execute_prepared_stmt(CONCAT(\'DROP TEMPORARY TABLE IF EXISTS `tmp_\', v_table_name, \'_start`\'));\n            CALL sys.execute_prepared_stmt(CONCAT(\'CREATE TEMPORARY TABLE `tmp_\', v_table_name, \'_start` SELECT * FROM `sys`.`x$\', v_table_name, \'`\'));\n            IF (@sys.diagnostics.include_raw = \'ON\') THEN\n                SET @sys.diagnostics.table_name = CONCAT(\'x$\', v_table_name);\n                EXECUTE stmt_gen_query USING @sys.diagnostics.table_name;\n                SELECT CONCAT(@sys.diagnostics.sql_select,\n                              IF(order_by IS NOT NULL, CONCAT(\'\\n ORDER BY \', REPLACE(order_by, \'%{TABLE}\', CONCAT(\'tmp_\', v_table_name, \'_start\'))), \'\'),\n                              IF(limit_rows IS NOT NULL, CONCAT(\'\\n LIMIT \', limit_rows), \'\')\n                       )\n                  INTO @sys.diagnostics.sql_select\n                  FROM tmp_sys_views_delta\n                 WHERE TABLE_NAME = v_table_name;\n                SELECT CONCAT(\'Initial \', v_table_name) AS \'The following output is:\';\n                CALL sys.execute_prepared_stmt(@sys.diagnostics.sql_select);\n            END IF;\n        END LOOP;\n        CLOSE c_sysviews_w_delta;\n        IF (@sys.diagnostics.include_raw = \'ON\') THEN\n            DEALLOCATE PREPARE stmt_gen_query;\n        END IF;\n    END IF;\n    SET v_sql_status_summary_select = \'SELECT Variable_name\',\n        v_sql_status_summary_delta  = \'\',\n        v_sql_status_summary_from   = \'\';\n    REPEAT\n        SET v_output_count = v_output_count + 1;\n        IF (v_output_count > 1) THEN\n            SET v_sleep = in_interval-(UNIX_TIMESTAMP(NOW(2))-v_iter_start);\n            SELECT NOW() AS \'Time\', CONCAT(\'Going to sleep for \', v_sleep, \' seconds. Please do not interrupt\') AS \'The following output is:\';\n            DO SLEEP(in_interval);\n        END IF;\n        SET v_iter_start = UNIX_TIMESTAMP(NOW(2));\n        SELECT NOW(), CONCAT(\'Iteration Number \', IFNULL(v_output_count, \'NULL\')) AS \'The following output is:\';\n        IF (@@log_bin = 1) THEN\n            SELECT \'SHOW MASTER STATUS\' AS \'The following output is:\';\n            SHOW MASTER STATUS;\n        END IF;\n        IF (v_has_replication <> \'NO\') THEN\n            SELECT \'SHOW SLAVE STATUS\' AS \'The following output is:\';\n            SHOW SLAVE STATUS;\n        END IF;\n        SET v_table_name = CONCAT(\'tmp_metrics_\', v_output_count);\n        CALL sys.execute_prepared_stmt(CONCAT(\'DROP TEMPORARY TABLE IF EXISTS \', v_table_name));\n        CALL sys.execute_prepared_stmt(CONCAT(\'CREATE TEMPORARY TABLE \', v_table_name, \' (\n  Variable_name VARCHAR(193) NOT NULL,\n  Variable_value VARCHAR(1024),\n  Type VARCHAR(100) NOT NULL,\n  Enabled ENUM(\'\'YES\'\', \'\'NO\'\', \'\'PARTIAL\'\') NOT NULL,\n  PRIMARY KEY (Type, Variable_name)\n) ENGINE = InnoDB DEFAULT CHARSET=utf8\'));\n        IF (v_has_metrics) THEN\n            SET @sys.diagnostics.sql = CONCAT(\n                \'INSERT INTO \', v_table_name,\n                \' SELECT Variable_name, REPLACE(Variable_value, \'\'\\n\'\', \'\'\\\\\\\\n\'\') AS Variable_value, Type, Enabled FROM sys.metrics\'\n            );\n        ELSE\n            SET @sys.diagnostics.sql = CONCAT(\n                \'INSERT INTO \', v_table_name,\n                \'(SELECT LOWER(VARIABLE_NAME) AS Variable_name, REPLACE(VARIABLE_VALUE, \'\'\\n\'\', \'\'\\\\\\\\n\'\') AS Variable_value,\n                         \'\'Global Status\'\' AS Type, \'\'YES\'\' AS Enabled\n  FROM performance_schema.global_status\n) UNION ALL (\nSELECT NAME AS Variable_name, COUNT AS Variable_value,\n       CONCAT(\'\'InnoDB Metrics - \'\', SUBSYSTEM) AS Type,\n       IF(STATUS = \'\'enabled\'\', \'\'YES\'\', \'\'NO\'\') AS Enabled\n  FROM information_schema.INNODB_METRICS\n WHERE NAME NOT IN (\n     \'\'lock_row_lock_time\'\', \'\'lock_row_lock_time_avg\'\', \'\'lock_row_lock_time_max\'\', \'\'lock_row_lock_waits\'\',\n     \'\'buffer_pool_reads\'\', \'\'buffer_pool_read_requests\'\', \'\'buffer_pool_write_requests\'\', \'\'buffer_pool_wait_free\'\',\n     \'\'buffer_pool_read_ahead\'\', \'\'buffer_pool_read_ahead_evicted\'\', \'\'buffer_pool_pages_total\'\', \'\'buffer_pool_pages_misc\'\',\n     \'\'buffer_pool_pages_data\'\', \'\'buffer_pool_bytes_data\'\', \'\'buffer_pool_pages_dirty\'\', \'\'buffer_pool_bytes_dirty\'\',\n     \'\'buffer_pool_pages_free\'\', \'\'buffer_pages_created\'\', \'\'buffer_pages_written\'\', \'\'buffer_pages_read\'\',\n     \'\'buffer_data_reads\'\', \'\'buffer_data_written\'\', \'\'file_num_open_files\'\',\n     \'\'os_log_bytes_written\'\', \'\'os_log_fsyncs\'\', \'\'os_log_pending_fsyncs\'\', \'\'os_log_pending_writes\'\',\n     \'\'log_waits\'\', \'\'log_write_requests\'\', \'\'log_writes\'\', \'\'innodb_dblwr_writes\'\', \'\'innodb_dblwr_pages_written\'\', \'\'innodb_page_size\'\')\n) UNION ALL (\nSELECT \'\'NOW()\'\' AS Variable_name, NOW(3) AS Variable_value, \'\'System Time\'\' AS Type, \'\'YES\'\' AS Enabled\n) UNION ALL (\nSELECT \'\'UNIX_TIMESTAMP()\'\' AS Variable_name, ROUND(UNIX_TIMESTAMP(NOW(3)), 3) AS Variable_value, \'\'System Time\'\' AS Type, \'\'YES\'\' AS Enabled\n)\n ORDER BY Type, Variable_name;\'\n            );\n        END IF;\n        CALL sys.execute_prepared_stmt(@sys.diagnostics.sql);\n        CALL sys.execute_prepared_stmt(\n            CONCAT(\'SELECT Variable_value INTO @sys.diagnostics.output_time FROM \', v_table_name, \' WHERE Type = \'\'System Time\'\' AND Variable_name = \'\'UNIX_TIMESTAMP()\'\'\')\n        );\n        SET v_output_time = @sys.diagnostics.output_time;\n        SET v_sql_status_summary_select = CONCAT(v_sql_status_summary_select, \',\n       CONCAT(\n           LEFT(s\', v_output_count, \'.Variable_value, \', v_status_summary_width, \'),\n           IF(\', REPLACE(v_no_delta_names, \'%{COUNT}\', v_output_count), \' AND s\', v_output_count, \'.Variable_value REGEXP \'\'^[0-9]+(\\\\\\\\.[0-9]+)?$\'\', CONCAT(\'\' (\'\', ROUND(s\', v_output_count, \'.Variable_value/\', v_output_time, \', 2), \'\'/sec)\'\'), \'\'\'\')\n       ) AS \'\'Output \', v_output_count, \'\'\'\'),\n            v_sql_status_summary_from   = CONCAT(v_sql_status_summary_from, \'\n\',\n                                                    IF(v_output_count = 1, \'  FROM \', \'       INNER JOIN \'),\n                                                    v_table_name, \' s\', v_output_count,\n                                                    IF (v_output_count = 1, \'\', \' USING (Type, Variable_name)\'));\n        IF (v_output_count > 1) THEN\n            SET v_sql_status_summary_delta  = CONCAT(v_sql_status_summary_delta, \',\n       IF(\', REPLACE(v_no_delta_names, \'%{COUNT}\', v_output_count), \' AND s\', (v_output_count-1), \'.Variable_value REGEXP \'\'^[0-9]+(\\\\\\\\.[0-9]+)?$\'\' AND s\', v_output_count, \'.Variable_value REGEXP \'\'^[0-9]+(\\\\\\\\.[0-9]+)?$\'\',\n          CONCAT(IF(s\', (v_output_count-1), \'.Variable_value REGEXP \'\'^[0-9]+\\\\\\\\.[0-9]+$\'\' OR s\', v_output_count, \'.Variable_value REGEXP \'\'^[0-9]+\\\\\\\\.[0-9]+$\'\',\n                    ROUND((s\', v_output_count, \'.Variable_value-s\', (v_output_count-1), \'.Variable_value), 2),\n                    (s\', v_output_count, \'.Variable_value-s\', (v_output_count-1), \'.Variable_value)\n                   ),\n                 \'\' (\'\', ROUND((s\', v_output_count, \'.Variable_value-s\', (v_output_count-1), \'.Variable_value)/(\', v_output_time, \'-\', v_output_time_prev, \'), 2), \'\'/sec)\'\'\n          ),\n          \'\'\'\'\n       ) AS \'\'Delta (\', (v_output_count-1), \' -> \', v_output_count, \')\'\'\');\n        END IF;\n        SET v_output_time_prev = v_output_time;\n        IF (@sys.diagnostics.include_raw = \'ON\') THEN\n            IF (v_has_metrics) THEN\n                SELECT \'SELECT * FROM sys.metrics\' AS \'The following output is:\';\n            ELSE\n                SELECT \'sys.metrics equivalent\' AS \'The following output is:\';\n            END IF;\n            CALL sys.execute_prepared_stmt(CONCAT(\'SELECT Type, Variable_name, Enabled, Variable_value FROM \', v_table_name, \' ORDER BY Type, Variable_name\'));\n        END IF;\n        IF (v_has_innodb IN (\'DEFAULT\', \'YES\')) THEN\n            SELECT \'SHOW ENGINE INNODB STATUS\' AS \'The following output is:\';\n            EXECUTE stmt_innodb_status;\n            SELECT \'InnoDB - Transactions\' AS \'The following output is:\';\n            SELECT * FROM information_schema.INNODB_TRX;\n        END IF;\n        IF (v_has_ndb IN (\'DEFAULT\', \'YES\')) THEN\n            SELECT \'SHOW ENGINE NDBCLUSTER STATUS\' AS \'The following output is:\';\n            EXECUTE stmt_ndbcluster_status;\n            SELECT \'ndbinfo.memoryusage\' AS \'The following output is:\';\n            SELECT node_id, memory_type, sys.format_bytes(used) AS used, used_pages, sys.format_bytes(total) AS total, total_pages,\n                   ROUND(100*(used/total), 2) AS \'Used %\'\n            FROM ndbinfo.memoryusage;\n            SET v_done = FALSE;\n            OPEN c_ndbinfo;\n            c_ndbinfo_loop: LOOP\n                FETCH c_ndbinfo INTO v_table_name;\n                IF v_done THEN\n                LEAVE c_ndbinfo_loop;\n                END IF;\n                SELECT CONCAT(\'SELECT * FROM ndbinfo.\', v_table_name) AS \'The following output is:\';\n                CALL sys.execute_prepared_stmt(CONCAT(\'SELECT * FROM `ndbinfo`.`\', v_table_name, \'`\'));\n            END LOOP;\n            CLOSE c_ndbinfo;\n            SELECT * FROM information_schema.FILES;\n        END IF;\n        SELECT \'SELECT * FROM sys.processlist\' AS \'The following output is:\';\n        SELECT processlist.* FROM sys.processlist;\n        IF (v_has_ps = \'YES\') THEN\n            IF (sys.ps_is_consumer_enabled(\'events_waits_history_long\') = \'YES\') THEN\n                SELECT \'SELECT * FROM sys.latest_file_io\' AS \'The following output is:\';\n                SELECT * FROM sys.latest_file_io;\n            END IF;\n            IF (EXISTS(SELECT 1 FROM performance_schema.setup_instruments WHERE NAME LIKE \'memory/%\' AND ENABLED = \'YES\')) THEN\n                SELECT \'SELECT * FROM sys.memory_by_host_by_current_bytes\' AS \'The following output is:\';\n                SELECT * FROM sys.memory_by_host_by_current_bytes;\n                SELECT \'SELECT * FROM sys.memory_by_thread_by_current_bytes\' AS \'The following output is:\';\n                SELECT * FROM sys.memory_by_thread_by_current_bytes;\n                SELECT \'SELECT * FROM sys.memory_by_user_by_current_bytes\' AS \'The following output is:\';\n                SELECT * FROM sys.memory_by_user_by_current_bytes;\n                SELECT \'SELECT * FROM sys.memory_global_by_current_bytes\' AS \'The following output is:\';\n                SELECT * FROM sys.memory_global_by_current_bytes;\n            END IF;\n        END IF;\n        SET v_runtime = (UNIX_TIMESTAMP(NOW(2)) - v_start);\n    UNTIL (v_runtime + in_interval >= in_max_runtime) END REPEAT;\n    IF (v_has_ps = \'YES\') THEN\n        SELECT \'SHOW ENGINE PERFORMANCE_SCHEMA STATUS\' AS \'The following output is:\';\n        EXECUTE stmt_ps_status;\n    END IF;\n    IF (v_has_innodb IN (\'DEFAULT\', \'YES\')) THEN\n        DEALLOCATE PREPARE stmt_innodb_status;\n    END IF;\n    IF (v_has_ps = \'YES\') THEN\n        DEALLOCATE PREPARE stmt_ps_status;\n    END IF;\n    IF (v_has_ndb IN (\'DEFAULT\', \'YES\')) THEN\n        DEALLOCATE PREPARE stmt_ndbcluster_status;\n    END IF;\n    SELECT \'\n============================\n     Schema Information\n============================\n\' AS \'\';\n    SELECT COUNT(*) AS \'Total Number of Tables\' FROM information_schema.TABLES;\n    IF (@sys.diagnostics.allow_i_s_tables = \'ON\') THEN\n        SELECT \'Storage Engine Usage\' AS \'The following output is:\';\n        SELECT ENGINE, COUNT(*) AS NUM_TABLES,\n                sys.format_bytes(SUM(DATA_LENGTH)) AS DATA_LENGTH,\n                sys.format_bytes(SUM(INDEX_LENGTH)) AS INDEX_LENGTH,\n                sys.format_bytes(SUM(DATA_LENGTH+INDEX_LENGTH)) AS TOTAL\n            FROM information_schema.TABLES\n            GROUP BY ENGINE;\n        SELECT \'Schema Object Overview\' AS \'The following output is:\';\n        SELECT * FROM sys.schema_object_overview;\n        SELECT \'Tables without a PRIMARY KEY\' AS \'The following output is:\';\n        SELECT TABLES.TABLE_SCHEMA, ENGINE, COUNT(*) AS NumTables\n          FROM information_schema.TABLES\n               LEFT OUTER JOIN information_schema.STATISTICS ON STATISTICS.TABLE_SCHEMA = TABLES.TABLE_SCHEMA\n                                                                AND STATISTICS.TABLE_NAME = TABLES.TABLE_NAME\n                                                                AND STATISTICS.INDEX_NAME = \'PRIMARY\'\n         WHERE STATISTICS.TABLE_NAME IS NULL\n               AND TABLES.TABLE_SCHEMA NOT IN (\'mysql\', \'information_schema\', \'performance_schema\', \'sys\')\n               AND TABLES.TABLE_TYPE = \'BASE TABLE\'\n         GROUP BY TABLES.TABLE_SCHEMA, ENGINE;\n    END IF;\n    IF (v_has_ps = \'YES\') THEN\n        SELECT \'Unused Indexes\' AS \'The following output is:\';\n        SELECT object_schema, COUNT(*) AS NumUnusedIndexes\n          FROM performance_schema.table_io_waits_summary_by_index_usage\n         WHERE index_name IS NOT NULL\n               AND count_star = 0\n               AND object_schema NOT IN (\'mysql\', \'sys\')\n               AND index_name != \'PRIMARY\'\n         GROUP BY object_schema;\n    END IF;\n    IF (v_has_ps = \'YES\') THEN\n        SELECT \'\n=========================\n     Overall Status\n=========================\n\' AS \'\';\n        SELECT \'CALL sys.ps_statement_avg_latency_histogram()\' AS \'The following output is:\';\n        CALL sys.ps_statement_avg_latency_histogram();\n        CALL sys.statement_performance_analyzer(\'snapshot\', NULL, NULL);\n        CALL sys.statement_performance_analyzer(\'overall\', NULL, \'with_runtimes_in_95th_percentile\');\n        SET @sys.diagnostics.sql = REPLACE(@sys.diagnostics.sql_gen_query_template, \'%{OUTPUT}\', \'end\');\n        IF (@sys.debug = \'ON\') THEN\n            SELECT \'The following query will be used to generate the query for each sys view\' AS \'Debug\';\n            SELECT @sys.diagnostics.sql AS \'Debug\';\n        END IF;\n        PREPARE stmt_gen_query FROM @sys.diagnostics.sql;\n        SET v_done = FALSE;\n        OPEN c_sysviews_w_delta;\n        c_sysviews_w_delta_loop: LOOP\n            FETCH c_sysviews_w_delta INTO v_table_name;\n            IF v_done THEN\n                LEAVE c_sysviews_w_delta_loop;\n            END IF;\n            IF (@sys.debug = \'ON\') THEN\n                SELECT CONCAT(\'The following queries are for storing the final content of \', v_table_name) AS \'Debug\';\n            END IF;\n            CALL sys.execute_prepared_stmt(CONCAT(\'DROP TEMPORARY TABLE IF EXISTS `tmp_\', v_table_name, \'_end`\'));\n            CALL sys.execute_prepared_stmt(CONCAT(\'CREATE TEMPORARY TABLE `tmp_\', v_table_name, \'_end` SELECT * FROM `sys`.`x$\', v_table_name, \'`\'));\n            IF (@sys.diagnostics.include_raw = \'ON\') THEN\n                SET @sys.diagnostics.table_name = CONCAT(\'x$\', v_table_name);\n                EXECUTE stmt_gen_query USING @sys.diagnostics.table_name;\n                SELECT CONCAT(@sys.diagnostics.sql_select,\n                                IF(order_by IS NOT NULL, CONCAT(\'\\n ORDER BY \', REPLACE(order_by, \'%{TABLE}\', CONCAT(\'tmp_\', v_table_name, \'_end\'))), \'\'),\n                                IF(limit_rows IS NOT NULL, CONCAT(\'\\n LIMIT \', limit_rows), \'\')\n                        )\n                    INTO @sys.diagnostics.sql_select\n                    FROM tmp_sys_views_delta\n                    WHERE TABLE_NAME = v_table_name;\n                SELECT CONCAT(\'Overall \', v_table_name) AS \'The following output is:\';\n                CALL sys.execute_prepared_stmt(@sys.diagnostics.sql_select);\n            END IF;\n        END LOOP;\n        CLOSE c_sysviews_w_delta;\n        DEALLOCATE PREPARE stmt_gen_query;\n        SELECT \'\n======================\n     Delta Status\n======================\n\' AS \'\';\n        CALL sys.statement_performance_analyzer(\'delta\', \'tmp_digests_start\', \'with_runtimes_in_95th_percentile\');\n        CALL sys.statement_performance_analyzer(\'cleanup\', NULL, NULL);\n        DROP TEMPORARY TABLE tmp_digests_start;\n        IF (@sys.debug = \'ON\') THEN\n            SELECT \'The following query will be used to generate the query for each sys view delta\' AS \'Debug\';\n            SELECT @sys.diagnostics.sql_gen_query_delta AS \'Debug\';\n        END IF;\n        PREPARE stmt_gen_query_delta FROM @sys.diagnostics.sql_gen_query_delta;\n        SET v_old_group_concat_max_len = @@session.group_concat_max_len;\n        SET @@session.group_concat_max_len = 2048;\n        SET v_done = FALSE;\n        OPEN c_sysviews_w_delta;\n        c_sysviews_w_delta_loop: LOOP\n            FETCH c_sysviews_w_delta INTO v_table_name;\n            IF v_done THEN\n                LEAVE c_sysviews_w_delta_loop;\n            END IF;\n            SET @sys.diagnostics.table_name = v_table_name;\n            EXECUTE stmt_gen_query_delta USING @sys.diagnostics.table_name;\n            SELECT CONCAT(@sys.diagnostics.sql_select,\n                            IF(where_delta IS NOT NULL, CONCAT(\'\\n WHERE \', where_delta), \'\'),\n                            IF(order_by_delta IS NOT NULL, CONCAT(\'\\n ORDER BY \', order_by_delta), \'\'),\n                            IF(limit_rows IS NOT NULL, CONCAT(\'\\n LIMIT \', limit_rows), \'\')\n                    )\n                INTO @sys.diagnostics.sql_select\n                FROM tmp_sys_views_delta\n                WHERE TABLE_NAME = v_table_name;\n            SELECT CONCAT(\'Delta \', v_table_name) AS \'The following output is:\';\n            CALL sys.execute_prepared_stmt(@sys.diagnostics.sql_select);\n            CALL sys.execute_prepared_stmt(CONCAT(\'DROP TEMPORARY TABLE `tmp_\', v_table_name, \'_end`\'));\n            CALL sys.execute_prepared_stmt(CONCAT(\'DROP TEMPORARY TABLE `tmp_\', v_table_name, \'_start`\'));\n        END LOOP;\n        CLOSE c_sysviews_w_delta;\n        SET @@session.group_concat_max_len = v_old_group_concat_max_len;\n        DEALLOCATE PREPARE stmt_gen_query_delta;\n        DROP TEMPORARY TABLE tmp_sys_views_delta;\n    END IF;\n    IF (v_has_metrics) THEN\n        SELECT \'SELECT * FROM sys.metrics\' AS \'The following output is:\';\n    ELSE\n        SELECT \'sys.metrics equivalent\' AS \'The following output is:\';\n    END IF;\n    CALL sys.execute_prepared_stmt(\n        CONCAT(v_sql_status_summary_select, v_sql_status_summary_delta, \', Type, s1.Enabled\', v_sql_status_summary_from,\n               \'\n ORDER BY Type, Variable_name\'\n        )\n    );\n    SET v_count = 0;\n    WHILE (v_count < v_output_count) DO\n        SET v_count = v_count + 1;\n        SET v_table_name = CONCAT(\'tmp_metrics_\', v_count);\n        CALL sys.execute_prepared_stmt(CONCAT(\'DROP TEMPORARY TABLE IF EXISTS \', v_table_name));\n    END WHILE;\n    IF (in_auto_config <> \'current\') THEN\n        CALL sys.ps_setup_reload_saved();\n        SET sql_log_bin = @log_bin;\n    END IF;\n    SET @sys.diagnostics.output_time            = NULL,\n        @sys.diagnostics.sql                    = NULL,\n        @sys.diagnostics.sql_gen_query_delta    = NULL,\n        @sys.diagnostics.sql_gen_query_template = NULL,\n        @sys.diagnostics.sql_select             = NULL,\n        @sys.diagnostics.table_name             = NULL;\n    IF (v_this_thread_enabled = \'YES\') THEN\n        CALL sys.ps_setup_enable_thread(CONNECTION_ID());\n    END IF;\n    IF (@log_bin = 1) THEN\n        SET sql_log_bin = @log_bin;\n    END IF;\nEND','mariadb.sys@localhost','2024-02-11 05:51:13','2024-02-11 05:51:13','','\n             Description\n             Create a report of the current status of the server for diagnostics purposes. Data collected includes (some items depends on versions and settings):\n                * The GLOBAL VARIABLES\n                * Several sys schema views including metrics or equivalent (depending on version and settings)\n                * Queries in the 95th percentile\n                * Several ndbinfo views for MySQL Cluster\n                * Replication (both master and slave) information.\n             Some of the sys schema views are calculated as initial (optional), overall, delta:\n                * The initial view is the content of the view at the start of this procedure.\n                  This output will be the same as the the start values used for the delta view.\n                  The initial view is included if @sys.diagnostics.include_raw = \'ON\'.\n                * The overall view is the content of the view at the end of this procedure.\n                  This output is the same as the end values used for the delta view.\n                  The overall view is always included.\n                * The delta view is the difference from the beginning to the end. Note that for min and max values\n                  they are simply the min or max value from the end view respectively, so does not necessarily reflect\n                  the minimum/maximum value in the monitored period.\n                  Note: except for the metrics views the delta is only calculation between the first and last outputs.\n             Requires the SUPER privilege for \"SET sql_log_bin = 0;\".\n             Versions supported:\n                * MySQL 5.6: 5.6.10 and later\n                * MySQL 5.7: 5.7.9 and later\n             Parameters\n             in_max_runtime (INT UNSIGNED):\n               The maximum time to keep collecting data.\n               Use NULL to get the default which is 60 seconds, otherwise enter a value greater than 0.\n             in_interval (INT UNSIGNED):\n               How long to sleep between data collections.\n               Use NULL to get the default which is 30 seconds, otherwise enter a value greater than 0.\n             in_auto_config (ENUM(\'current\', \'medium\', \'full\'))\n               Automatically enable Performance Schema instruments and consumers.\n               NOTE: The more that are enabled, the more impact on the performance.\n               Supported values are:\n                  * current - use the current settings.\n                  * medium - enable some settings.\n                  * full - enables all settings. This will have a big impact on the\n                           performance - be careful using this option.\n               If another setting the \'current\' is chosen, the current settings\n               are restored at the end of the procedure.\n             Configuration Options\n             sys.diagnostics.allow_i_s_tables\n               Specifies whether it is allowed to do table scan queries on information_schema.TABLES. This can be expensive if there\n               are many tables. Set to \'ON\' to allow, \'OFF\' to not allow.\n               Default is \'OFF\'.\n             sys.diagnostics.include_raw\n               Set to \'ON\' to include the raw data (e.g. the original output of \"SELECT * FROM sys.metrics\").\n               Use this to get the initial values of the various views.\n               Default is \'OFF\'.\n             sys.statement_truncate_len\n               How much of queries in the process list output to include.\n               Default is 64.\n             sys.debug\n               Whether to provide debugging output.\n               Default is \'OFF\'. Set to \'ON\' to include.\n             Example\n             To create a report and append it to the file diag.out:\n             mysql> TEE diag.out;\n             mysql> CALL sys.diagnostics(120, 30, \'current\');\n             ...\n             mysql> NOTEE;\n            ','utf8mb3','utf8mb3_general_ci','utf8mb3_general_ci','BEGIN\n    DECLARE v_start, v_runtime, v_iter_start, v_sleep DECIMAL(20,2) DEFAULT 0.0;\n    DECLARE v_has_innodb, v_has_ndb, v_has_ps, v_has_replication, v_has_ps_replication VARCHAR(8) CHARSET utf8 DEFAULT \'NO\';\n    DECLARE v_this_thread_enabled, v_has_ps_vars, v_has_metrics ENUM(\'YES\', \'NO\');\n    DECLARE v_table_name, v_banner VARCHAR(64) CHARSET utf8;\n    DECLARE v_sql_status_summary_select, v_sql_status_summary_delta, v_sql_status_summary_from, v_no_delta_names TEXT;\n    DECLARE v_output_time, v_output_time_prev DECIMAL(20,3) UNSIGNED;\n    DECLARE v_output_count, v_count, v_old_group_concat_max_len INT UNSIGNED DEFAULT 0;\n    DECLARE v_status_summary_width TINYINT UNSIGNED DEFAULT 50;\n    DECLARE v_done BOOLEAN DEFAULT FALSE;\n    DECLARE c_ndbinfo CURSOR FOR\n        SELECT TABLE_NAME\n          FROM information_schema.TABLES\n         WHERE TABLE_SCHEMA = \'ndbinfo\'\n               AND TABLE_NAME NOT IN (\n                  \'blocks\',\n                  \'config_params\',\n                  \'dict_obj_types\',\n                  \'disk_write_speed_base\',\n                  \'memory_per_fragment\',\n                  \'memoryusage\',\n                  \'operations_per_fragment\',\n                  \'threadblocks\'\n               );\n    DECLARE c_sysviews_w_delta CURSOR FOR\n        SELECT table_name\n          FROM tmp_sys_views_delta\n         ORDER BY table_name;\n    DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = TRUE;\n    SELECT INSTRUMENTED INTO v_this_thread_enabled FROM performance_schema.threads WHERE PROCESSLIST_ID = CONNECTION_ID();\n    IF (v_this_thread_enabled = \'YES\') THEN\n        CALL sys.ps_setup_disable_thread(CONNECTION_ID());\n    END IF;\n    IF (in_max_runtime < in_interval) THEN\n        SIGNAL SQLSTATE \'45000\'\n           SET MESSAGE_TEXT = \'in_max_runtime must be greater than or equal to in_interval\';\n    END IF;\n    IF (in_max_runtime = 0) THEN\n        SIGNAL SQLSTATE \'45000\'\n           SET MESSAGE_TEXT = \'in_max_runtime must be greater than 0\';\n    END IF;\n    IF (in_interval = 0) THEN\n        SIGNAL SQLSTATE \'45000\'\n           SET MESSAGE_TEXT = \'in_interval must be greater than 0\';\n    END IF;\n    IF (@sys.diagnostics.allow_i_s_tables IS NULL) THEN\n        SET @sys.diagnostics.allow_i_s_tables = sys.sys_get_config(\'diagnostics.allow_i_s_tables\', \'OFF\');\n    END IF;\n    IF (@sys.diagnostics.include_raw IS NULL) THEN\n        SET @sys.diagnostics.include_raw      = sys.sys_get_config(\'diagnostics.include_raw\'     , \'OFF\');\n    END IF;\n    IF (@sys.debug IS NULL) THEN\n        SET @sys.debug                        = sys.sys_get_config(\'debug\'                       , \'OFF\');\n    END IF;\n    IF (@sys.statement_truncate_len IS NULL) THEN\n        SET @sys.statement_truncate_len       = sys.sys_get_config(\'statement_truncate_len\'      , \'64\' );\n    END IF;\n    SET @log_bin := @@sql_log_bin;\n    IF (@log_bin = 1) THEN\n        SET sql_log_bin = 0;\n    END IF;\n    SET v_no_delta_names = CONCAT(\'s%{COUNT}.Variable_name NOT IN (\',\n        \'\'\'innodb_buffer_pool_pages_total\'\', \',\n        \'\'\'innodb_page_size\'\', \',\n        \'\'\'last_query_cost\'\', \',\n        \'\'\'last_query_partial_plans\'\', \',\n        \'\'\'qcache_total_blocks\'\', \',\n        \'\'\'slave_last_heartbeat\'\', \',\n        \'\'\'ssl_ctx_verify_depth\'\', \',\n        \'\'\'ssl_ctx_verify_mode\'\', \',\n        \'\'\'ssl_session_cache_size\'\', \',\n        \'\'\'ssl_verify_depth\'\', \',\n        \'\'\'ssl_verify_mode\'\', \',\n        \'\'\'ssl_version\'\', \',\n        \'\'\'buffer_flush_lsn_avg_rate\'\', \',\n        \'\'\'buffer_flush_pct_for_dirty\'\', \',\n        \'\'\'buffer_flush_pct_for_lsn\'\', \',\n        \'\'\'buffer_pool_pages_total\'\', \',\n        \'\'\'lock_row_lock_time_avg\'\', \',\n        \'\'\'lock_row_lock_time_max\'\', \',\n        \'\'\'innodb_page_size\'\'\',\n    \')\');\n    IF (in_auto_config <> \'current\') THEN\n        IF (@sys.debug = \'ON\') THEN\n            SELECT CONCAT(\'Updating Performance Schema configuration to \', in_auto_config) AS \'Debug\';\n        END IF;\n        CALL sys.ps_setup_save(0);\n        IF (in_auto_config = \'medium\') THEN\n            UPDATE performance_schema.setup_consumers\n                SET ENABLED = \'YES\'\n            WHERE NAME NOT LIKE \'%\\_history%\';\n            UPDATE performance_schema.setup_instruments\n                SET ENABLED = \'YES\',\n                    TIMED   = \'YES\'\n            WHERE NAME NOT LIKE \'wait/synch/%\';\n        ELSEIF (in_auto_config = \'full\') THEN\n            UPDATE performance_schema.setup_consumers\n                SET ENABLED = \'YES\';\n            UPDATE performance_schema.setup_instruments\n                SET ENABLED = \'YES\',\n                    TIMED   = \'YES\';\n        END IF;\n        UPDATE performance_schema.threads\n           SET INSTRUMENTED = \'YES\'\n         WHERE PROCESSLIST_ID <> CONNECTION_ID();\n    END IF;\n    SET v_start        = UNIX_TIMESTAMP(NOW(2)),\n        in_interval    = IFNULL(in_interval, 30),\n        in_max_runtime = IFNULL(in_max_runtime, 60);\n    SET v_banner = REPEAT(\n                      \'-\',\n                      LEAST(\n                         GREATEST(\n                            36,\n                            CHAR_LENGTH(VERSION()),\n                            CHAR_LENGTH(@@global.version_comment),\n                            CHAR_LENGTH(@@global.version_compile_os),\n                            CHAR_LENGTH(@@global.version_compile_machine),\n                            CHAR_LENGTH(@@global.socket),\n                            CHAR_LENGTH(@@global.datadir)\n                         ),\n                         64\n                      )\n                   );\n    SELECT \'Hostname\' AS \'Name\', @@global.hostname AS \'Value\'\n    UNION ALL\n    SELECT \'Port\' AS \'Name\', @@global.port AS \'Value\'\n    UNION ALL\n    SELECT \'Socket\' AS \'Name\', @@global.socket AS \'Value\'\n    UNION ALL\n    SELECT \'Datadir\' AS \'Name\', @@global.datadir AS \'Value\'\n    UNION ALL\n    SELECT REPEAT(\'-\', 23) AS \'Name\', v_banner AS \'Value\'\n    UNION ALL\n    SELECT \'MySQL Version\' AS \'Name\', VERSION() AS \'Value\'\n    UNION ALL\n    SELECT \'Sys Schema Version\' AS \'Name\', (SELECT sys_version FROM sys.version) AS \'Value\'\n    UNION ALL\n    SELECT \'Version Comment\' AS \'Name\', @@global.version_comment AS \'Value\'\n    UNION ALL\n    SELECT \'Version Compile OS\' AS \'Name\', @@global.version_compile_os AS \'Value\'\n    UNION ALL\n    SELECT \'Version Compile Machine\' AS \'Name\', @@global.version_compile_machine AS \'Value\'\n    UNION ALL\n    SELECT REPEAT(\'-\', 23) AS \'Name\', v_banner AS \'Value\'\n    UNION ALL\n    SELECT \'UTC Time\' AS \'Name\', UTC_TIMESTAMP() AS \'Value\'\n    UNION ALL\n    SELECT \'Local Time\' AS \'Name\', NOW() AS \'Value\'\n    UNION ALL\n    SELECT \'Time Zone\' AS \'Name\', @@global.time_zone AS \'Value\'\n    UNION ALL\n    SELECT \'System Time Zone\' AS \'Name\', @@global.system_time_zone AS \'Value\'\n    UNION ALL\n    SELECT \'Time Zone Offset\' AS \'Name\', TIMEDIFF(NOW(), UTC_TIMESTAMP()) AS \'Value\';\n    SET v_has_innodb         = IFNULL((SELECT SUPPORT FROM information_schema.ENGINES WHERE ENGINE = \'InnoDB\'), \'NO\'),\n        v_has_ndb            = IFNULL((SELECT SUPPORT FROM information_schema.ENGINES WHERE ENGINE = \'NDBCluster\'), \'NO\'),\n        v_has_ps             = IFNULL((SELECT SUPPORT FROM information_schema.ENGINES WHERE ENGINE = \'PERFORMANCE_SCHEMA\'), \'NO\'),\n        v_has_ps_replication = IF(v_has_ps = \'YES\'\n                                   AND EXISTS(SELECT 1 FROM information_schema.TABLES WHERE TABLE_SCHEMA = \'performance_schema\' AND TABLE_NAME = \'replication_applier_status\'),\n                                   \'YES\',\n                                   \'NO\'\n                               ),\n        v_has_replication    = \'MAYBE\',\n        v_has_metrics        = IF(v_has_ps = \'YES\' OR (sys.version_major() = 5 AND sys.version_minor() = 6), \'YES\', \'NO\'),\n        v_has_ps_vars        = \'NO\';\n    \n    \n    IF (@sys.debug = \'ON\') THEN\n       SELECT v_has_innodb AS \'Has_InnoDB\', v_has_ndb AS \'Has_NDBCluster\',\n              v_has_ps AS \'Has_Performance_Schema\', v_has_ps_vars AS \'Has_P_S_SHOW_Variables\',\n              v_has_metrics AS \'Has_metrics\',\n              v_has_ps_replication \'AS Has_P_S_Replication\', v_has_replication AS \'Has_Replication\';\n    END IF;\n    IF (v_has_innodb IN (\'DEFAULT\', \'YES\')) THEN\n        SET @sys.diagnostics.sql = \'SHOW ENGINE InnoDB STATUS\';\n        PREPARE stmt_innodb_status FROM @sys.diagnostics.sql;\n    END IF;\n    IF (v_has_ps = \'YES\') THEN\n        SET @sys.diagnostics.sql = \'SHOW ENGINE PERFORMANCE_SCHEMA STATUS\';\n        PREPARE stmt_ps_status FROM @sys.diagnostics.sql;\n    END IF;\n    IF (v_has_ndb IN (\'DEFAULT\', \'YES\')) THEN\n        SET @sys.diagnostics.sql = \'SHOW ENGINE NDBCLUSTER STATUS\';\n        PREPARE stmt_ndbcluster_status FROM @sys.diagnostics.sql;\n    END IF;\n    SET @sys.diagnostics.sql_gen_query_template = \'SELECT CONCAT(\\n           \'\'SELECT \'\',\\n           GROUP_CONCAT(\\n               CASE WHEN (SUBSTRING(TABLE_NAME, 3), COLUMN_NAME) IN (\\n                                (\'\'io_global_by_file_by_bytes\'\', \'\'total\'\'),\\n                                (\'\'io_global_by_wait_by_bytes\'\', \'\'total_requested\'\')\\n                         )\\n                         THEN CONCAT(\'\'sys.format_bytes(\'\', COLUMN_NAME, \'\') AS \'\', COLUMN_NAME)\\n                    WHEN SUBSTRING(COLUMN_NAME, -8) = \'\'_latency\'\'\\n                         THEN CONCAT(\'\'sys.format_time(\'\', COLUMN_NAME, \'\') AS \'\', COLUMN_NAME)\\n                    WHEN SUBSTRING(COLUMN_NAME, -7) = \'\'_memory\'\' OR SUBSTRING(COLUMN_NAME, -17) = \'\'_memory_allocated\'\'\\n                         OR ((SUBSTRING(COLUMN_NAME, -5) = \'\'_read\'\' OR SUBSTRING(COLUMN_NAME, -8) = \'\'_written\'\' OR SUBSTRING(COLUMN_NAME, -6) = \'\'_write\'\') AND SUBSTRING(COLUMN_NAME, 1, 6) <> \'\'COUNT_\'\')\\n                         THEN CONCAT(\'\'sys.format_bytes(\'\', COLUMN_NAME, \'\') AS \'\', COLUMN_NAME)\\n                    ELSE COLUMN_NAME\\n               END\\n               ORDER BY ORDINAL_POSITION\\n               SEPARATOR \'\',\\n       \'\'\\n           ),\\n           \'\'\\n  FROM tmp_\'\', SUBSTRING(TABLE_NAME FROM 3), \'\'_%{OUTPUT}\'\'\\n       ) AS Query INTO @sys.diagnostics.sql_select\\n  FROM information_schema.COLUMNS\\n WHERE TABLE_SCHEMA = \'\'sys\'\' AND TABLE_NAME = ?\\n GROUP BY TABLE_NAME\';\n    SET @sys.diagnostics.sql_gen_query_delta = \'SELECT CONCAT(\\n           \'\'SELECT \'\',\\n           GROUP_CONCAT(\\n               CASE WHEN FIND_IN_SET(COLUMN_NAME, diag.pk)\\n                         THEN COLUMN_NAME\\n                    WHEN diag.TABLE_NAME = \'\'io_global_by_file_by_bytes\'\' AND COLUMN_NAME = \'\'write_pct\'\'\\n                         THEN CONCAT(\'\'IFNULL(ROUND(100-(((e.total_read-IFNULL(s.total_read, 0))\'\',\\n                                     \'\'/NULLIF(((e.total_read-IFNULL(s.total_read, 0))+(e.total_written-IFNULL(s.total_written, 0))), 0))*100), 2), 0.00) AS \'\',\\n                                     COLUMN_NAME)\\n                    WHEN (diag.TABLE_NAME, COLUMN_NAME) IN (\\n                                (\'\'io_global_by_file_by_bytes\'\', \'\'total\'\'),\\n                                (\'\'io_global_by_wait_by_bytes\'\', \'\'total_requested\'\')\\n                         )\\n                         THEN CONCAT(\'\'sys.format_bytes(e.\'\', COLUMN_NAME, \'\'-IFNULL(s.\'\', COLUMN_NAME, \'\', 0)) AS \'\', COLUMN_NAME)\\n                    WHEN SUBSTRING(COLUMN_NAME, 1, 4) IN (\'\'max_\'\', \'\'min_\'\') AND SUBSTRING(COLUMN_NAME, -8) = \'\'_latency\'\'\\n                         THEN CONCAT(\'\'sys.format_time(e.\'\', COLUMN_NAME, \'\') AS \'\', COLUMN_NAME)\\n                    WHEN COLUMN_NAME = \'\'avg_latency\'\'\\n                         THEN CONCAT(\'\'sys.format_time((e.total_latency - IFNULL(s.total_latency, 0))\'\',\\n                                     \'\'/NULLIF(e.total - IFNULL(s.total, 0), 0)) AS \'\', COLUMN_NAME)\\n                    WHEN SUBSTRING(COLUMN_NAME, -12) = \'\'_avg_latency\'\'\\n                         THEN CONCAT(\'\'sys.format_time((e.\'\', SUBSTRING(COLUMN_NAME FROM 1 FOR CHAR_LENGTH(COLUMN_NAME)-12), \'\'_latency - IFNULL(s.\'\', SUBSTRING(COLUMN_NAME FROM 1 FOR CHAR_LENGTH(COLUMN_NAME)-12), \'\'_latency, 0))\'\',\\n                                     \'\'/NULLIF(e.\'\', SUBSTRING(COLUMN_NAME FROM 1 FOR CHAR_LENGTH(COLUMN_NAME)-12), \'\'s - IFNULL(s.\'\', SUBSTRING(COLUMN_NAME FROM 1 FOR CHAR_LENGTH(COLUMN_NAME)-12), \'\'s, 0), 0)) AS \'\', COLUMN_NAME)\\n                    WHEN SUBSTRING(COLUMN_NAME, -8) = \'\'_latency\'\'\\n                         THEN CONCAT(\'\'sys.format_time(e.\'\', COLUMN_NAME, \'\' - IFNULL(s.\'\', COLUMN_NAME, \'\', 0)) AS \'\', COLUMN_NAME)\\n                    WHEN COLUMN_NAME IN (\'\'avg_read\'\', \'\'avg_write\'\', \'\'avg_written\'\')\\n                         THEN CONCAT(\'\'sys.format_bytes(IFNULL((e.total_\'\', IF(COLUMN_NAME = \'\'avg_read\'\', \'\'read\'\', \'\'written\'\'), \'\'-IFNULL(s.total_\'\', IF(COLUMN_NAME = \'\'avg_read\'\', \'\'read\'\', \'\'written\'\'), \'\', 0))\'\',\\n                                     \'\'/NULLIF(e.count_\'\', IF(COLUMN_NAME = \'\'avg_read\'\', \'\'read\'\', \'\'write\'\'), \'\'-IFNULL(s.count_\'\', IF(COLUMN_NAME = \'\'avg_read\'\', \'\'read\'\', \'\'write\'\'), \'\', 0), 0), 0)) AS \'\',\\n                                     COLUMN_NAME)\\n                    WHEN SUBSTRING(COLUMN_NAME, -7) = \'\'_memory\'\' OR SUBSTRING(COLUMN_NAME, -17) = \'\'_memory_allocated\'\'\\n                         OR ((SUBSTRING(COLUMN_NAME, -5) = \'\'_read\'\' OR SUBSTRING(COLUMN_NAME, -8) = \'\'_written\'\' OR SUBSTRING(COLUMN_NAME, -6) = \'\'_write\'\') AND SUBSTRING(COLUMN_NAME, 1, 6) <> \'\'COUNT_\'\')\\n                         THEN CONCAT(\'\'sys.format_bytes(e.\'\', COLUMN_NAME, \'\' - IFNULL(s.\'\', COLUMN_NAME, \'\', 0)) AS \'\', COLUMN_NAME)\\n                    ELSE CONCAT(\'\'(e.\'\', COLUMN_NAME, \'\' - IFNULL(s.\'\', COLUMN_NAME, \'\', 0)) AS \'\', COLUMN_NAME)\\n               END\\n               ORDER BY ORDINAL_POSITION\\n               SEPARATOR \'\',\\n       \'\'\\n           ),\\n           \'\'\\n  FROM tmp_\'\', diag.TABLE_NAME, \'\'_end e\\n       LEFT OUTER JOIN tmp_\'\', diag.TABLE_NAME, \'\'_start s USING (\'\', diag.pk, \'\')\'\'\\n       ) AS Query INTO @sys.diagnostics.sql_select\\n  FROM tmp_sys_views_delta diag\\n       INNER JOIN information_schema.COLUMNS c ON c.TABLE_NAME = CONCAT(\'\'x$\'\', diag.TABLE_NAME)\\n WHERE c.TABLE_SCHEMA = \'\'sys\'\' AND diag.TABLE_NAME = ?\\n GROUP BY diag.TABLE_NAME\';\n    IF (v_has_ps = \'YES\') THEN\n        DROP TEMPORARY TABLE IF EXISTS tmp_sys_views_delta;\n        CREATE TEMPORARY TABLE tmp_sys_views_delta (\n            TABLE_NAME varchar(64) NOT NULL,\n            order_by text COMMENT \'ORDER BY clause for the initial and overall views\',\n            order_by_delta text COMMENT \'ORDER BY clause for the delta views\',\n            where_delta text COMMENT \'WHERE clause to use for delta views to only include rows with a \"count\" > 0\',\n            limit_rows int unsigned COMMENT \'The maximum number of rows to include for the view\',\n            pk varchar(128) COMMENT \'Used with the FIND_IN_SET() function so use comma separated list without whitespace\',\n            PRIMARY KEY (TABLE_NAME)\n        );\n        IF (@sys.debug = \'ON\') THEN\n            SELECT \'Populating tmp_sys_views_delta\' AS \'Debug\';\n        END IF;\n        INSERT INTO tmp_sys_views_delta\n        VALUES (\'host_summary\'                       , \'%{TABLE}.statement_latency DESC\',\n                                                       \'(e.statement_latency-IFNULL(s.statement_latency, 0)) DESC\',\n                                                       \'(e.statements - IFNULL(s.statements, 0)) > 0\', NULL, \'host\'),\n               (\'host_summary_by_file_io\'            , \'%{TABLE}.io_latency DESC\',\n                                                       \'(e.io_latency-IFNULL(s.io_latency, 0)) DESC\',\n                                                       \'(e.ios - IFNULL(s.ios, 0)) > 0\', NULL, \'host\'),\n               (\'host_summary_by_file_io_type\'       , \'%{TABLE}.host, %{TABLE}.total_latency DESC\',\n                                                       \'e.host, (e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'host,event_name\'),\n               (\'host_summary_by_stages\'             , \'%{TABLE}.host, %{TABLE}.total_latency DESC\',\n                                                       \'e.host, (e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'host,event_name\'),\n               (\'host_summary_by_statement_latency\'  , \'%{TABLE}.total_latency DESC\',\n                                                       \'(e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'host\'),\n               (\'host_summary_by_statement_type\'     , \'%{TABLE}.host, %{TABLE}.total_latency DESC\',\n                                                       \'e.host, (e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'host,statement\'),\n               (\'io_by_thread_by_latency\'            , \'%{TABLE}.total_latency DESC\',\n                                                       \'(e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'user,thread_id,processlist_id\'),\n               (\'io_global_by_file_by_bytes\'         , \'%{TABLE}.total DESC\',\n                                                       \'(e.total-IFNULL(s.total, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', 100, \'file\'),\n               (\'io_global_by_file_by_latency\'       , \'%{TABLE}.total_latency DESC\',\n                                                       \'(e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', 100, \'file\'),\n               (\'io_global_by_wait_by_bytes\'         , \'%{TABLE}.total_requested DESC\',\n                                                       \'(e.total_requested-IFNULL(s.total_requested, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'event_name\'),\n               (\'io_global_by_wait_by_latency\'       , \'%{TABLE}.total_latency DESC\',\n                                                       \'(e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'event_name\'),\n               (\'schema_index_statistics\'            , \'(%{TABLE}.select_latency+%{TABLE}.insert_latency+%{TABLE}.update_latency+%{TABLE}.delete_latency) DESC\',\n                                                       \'((e.select_latency+e.insert_latency+e.update_latency+e.delete_latency)-IFNULL(s.select_latency+s.insert_latency+s.update_latency+s.delete_latency, 0)) DESC\',\n                                                       \'((e.rows_selected+e.insert_latency+e.rows_updated+e.rows_deleted)-IFNULL(s.rows_selected+s.rows_inserted+s.rows_updated+s.rows_deleted, 0)) > 0\',\n                                                       100, \'table_schema,table_name,index_name\'),\n               (\'schema_table_statistics\'            , \'%{TABLE}.total_latency DESC\',\n                                                       \'(e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total_latency-IFNULL(s.total_latency, 0)) > 0\', 100, \'table_schema,table_name\'),\n               (\'schema_tables_with_full_table_scans\', \'%{TABLE}.rows_full_scanned DESC\',\n                                                       \'(e.rows_full_scanned-IFNULL(s.rows_full_scanned, 0)) DESC\',\n                                                       \'(e.rows_full_scanned-IFNULL(s.rows_full_scanned, 0)) > 0\', 100, \'object_schema,object_name\'),\n               (\'user_summary\'                       , \'%{TABLE}.statement_latency DESC\',\n                                                       \'(e.statement_latency-IFNULL(s.statement_latency, 0)) DESC\',\n                                                       \'(e.statements - IFNULL(s.statements, 0)) > 0\', NULL, \'user\'),\n               (\'user_summary_by_file_io\'            , \'%{TABLE}.io_latency DESC\',\n                                                       \'(e.io_latency-IFNULL(s.io_latency, 0)) DESC\',\n                                                       \'(e.ios - IFNULL(s.ios, 0)) > 0\', NULL, \'user\'),\n               (\'user_summary_by_file_io_type\'       , \'%{TABLE}.user, %{TABLE}.latency DESC\',\n                                                       \'e.user, (e.latency-IFNULL(s.latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'user,event_name\'),\n               (\'user_summary_by_stages\'             , \'%{TABLE}.user, %{TABLE}.total_latency DESC\',\n                                                       \'e.user, (e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'user,event_name\'),\n               (\'user_summary_by_statement_latency\'  , \'%{TABLE}.total_latency DESC\',\n                                                       \'(e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'user\'),\n               (\'user_summary_by_statement_type\'     , \'%{TABLE}.user, %{TABLE}.total_latency DESC\',\n                                                       \'e.user, (e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'user,statement\'),\n               (\'wait_classes_global_by_avg_latency\' , \'IFNULL(%{TABLE}.total_latency / NULLIF(%{TABLE}.total, 0), 0) DESC\',\n                                                       \'IFNULL((e.total_latency-IFNULL(s.total_latency, 0)) / NULLIF((e.total - IFNULL(s.total, 0)), 0), 0) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'event_class\'),\n               (\'wait_classes_global_by_latency\'     , \'%{TABLE}.total_latency DESC\',\n                                                       \'(e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'event_class\'),\n               (\'waits_by_host_by_latency\'           , \'%{TABLE}.host, %{TABLE}.total_latency DESC\',\n                                                       \'e.host, (e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'host,event\'),\n               (\'waits_by_user_by_latency\'           , \'%{TABLE}.user, %{TABLE}.total_latency DESC\',\n                                                       \'e.user, (e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'user,event\'),\n               (\'waits_global_by_latency\'            , \'%{TABLE}.total_latency DESC\',\n                                                       \'(e.total_latency-IFNULL(s.total_latency, 0)) DESC\',\n                                                       \'(e.total - IFNULL(s.total, 0)) > 0\', NULL, \'events\')\n        ;\n    END IF;\n    SELECT \'\\n=======================\\n     Configuration\\n=======================\\n\' AS \'\';\n    SELECT \'GLOBAL VARIABLES\' AS \'The following output is:\';\n    IF (v_has_ps_vars = \'YES\') THEN\n        SELECT LOWER(VARIABLE_NAME) AS Variable_name, VARIABLE_VALUE AS Variable_value FROM performance_schema.global_variables ORDER BY VARIABLE_NAME;\n    ELSE\n        SELECT LOWER(VARIABLE_NAME) AS Variable_name, VARIABLE_VALUE AS Variable_value FROM information_schema.GLOBAL_VARIABLES ORDER BY VARIABLE_NAME;\n    END IF;\n    IF (v_has_ps = \'YES\') THEN\n        SELECT \'Performance Schema Setup - Actors\' AS \'The following output is:\';\n        SELECT * FROM performance_schema.setup_actors;\n        SELECT \'Performance Schema Setup - Consumers\' AS \'The following output is:\';\n        SELECT NAME AS Consumer, ENABLED, sys.ps_is_consumer_enabled(NAME) AS COLLECTS\n          FROM performance_schema.setup_consumers;\n        SELECT \'Performance Schema Setup - Instruments\' AS \'The following output is:\';\n        SELECT SUBSTRING_INDEX(NAME, \'/\', 2) AS \'InstrumentClass\',\n               ROUND(100*SUM(IF(ENABLED = \'YES\', 1, 0))/COUNT(*), 2) AS \'EnabledPct\',\n               ROUND(100*SUM(IF(TIMED = \'YES\', 1, 0))/COUNT(*), 2) AS \'TimedPct\'\n          FROM performance_schema.setup_instruments\n         GROUP BY SUBSTRING_INDEX(NAME, \'/\', 2)\n         ORDER BY SUBSTRING_INDEX(NAME, \'/\', 2);\n        SELECT \'Performance Schema Setup - Objects\' AS \'The following output is:\';\n        SELECT * FROM performance_schema.setup_objects;\n        SELECT \'Performance Schema Setup - Threads\' AS \'The following output is:\';\n        SELECT `TYPE` AS ThreadType, COUNT(*) AS \'Total\', ROUND(100*SUM(IF(INSTRUMENTED = \'YES\', 1, 0))/COUNT(*), 2) AS \'InstrumentedPct\'\n          FROM performance_schema.threads\n        GROUP BY TYPE;\n    END IF;\n    IF (v_has_replication = \'NO\') THEN\n        SELECT \'No Replication Configured\' AS \'Replication Status\';\n    ELSE\n        SELECT CONCAT(\'Replication Configured: \', v_has_replication, \' - Performance Schema Replication Tables: \', v_has_ps_replication) AS \'Replication Status\';\n        IF (v_has_ps_replication = \'YES\') THEN\n            SELECT \'Replication - Connection Configuration\' AS \'The following output is:\';\n            SELECT * FROM performance_schema.replication_connection_configuration;\n        END IF;\n        IF (v_has_ps_replication = \'YES\') THEN\n            SELECT \'Replication - Applier Configuration\' AS \'The following output is:\';\n            SELECT * FROM performance_schema.replication_applier_configuration ORDER BY CHANNEL_NAME;\n        END IF;\n    END IF;\n    IF (v_has_ndb IN (\'DEFAULT\', \'YES\')) THEN\n       SELECT \'Cluster Thread Blocks\' AS \'The following output is:\';\n       SELECT * FROM ndbinfo.threadblocks;\n    END IF;\n    IF (v_has_ps = \'YES\') THEN\n        IF (@sys.diagnostics.include_raw = \'ON\') THEN\n            SELECT \'\\n========================\\n     Initial Status\\n========================\\n\' AS \'\';\n        END IF;\n        DROP TEMPORARY TABLE IF EXISTS tmp_digests_start;\n        CALL sys.statement_performance_analyzer(\'create_tmp\', \'tmp_digests_start\', NULL);\n        CALL sys.statement_performance_analyzer(\'snapshot\', NULL, NULL);\n        CALL sys.statement_performance_analyzer(\'save\', \'tmp_digests_start\', NULL);\n        IF (@sys.diagnostics.include_raw = \'ON\') THEN\n            SET @sys.diagnostics.sql = REPLACE(@sys.diagnostics.sql_gen_query_template, \'%{OUTPUT}\', \'start\');\n            IF (@sys.debug = \'ON\') THEN\n                SELECT \'The following query will be used to generate the query for each sys view\' AS \'Debug\';\n                SELECT @sys.diagnostics.sql AS \'Debug\';\n            END IF;\n            PREPARE stmt_gen_query FROM @sys.diagnostics.sql;\n        END IF;\n        SET v_done = FALSE;\n        OPEN c_sysviews_w_delta;\n        c_sysviews_w_delta_loop: LOOP\n            FETCH c_sysviews_w_delta INTO v_table_name;\n            IF v_done THEN\n                LEAVE c_sysviews_w_delta_loop;\n            END IF;\n            IF (@sys.debug = \'ON\') THEN\n                SELECT CONCAT(\'The following queries are for storing the initial content of \', v_table_name) AS \'Debug\';\n            END IF;\n            CALL sys.execute_prepared_stmt(CONCAT(\'DROP TEMPORARY TABLE IF EXISTS `tmp_\', v_table_name, \'_start`\'));\n            CALL sys.execute_prepared_stmt(CONCAT(\'CREATE TEMPORARY TABLE `tmp_\', v_table_name, \'_start` SELECT * FROM `sys`.`x$\', v_table_name, \'`\'));\n            IF (@sys.diagnostics.include_raw = \'ON\') THEN\n                SET @sys.diagnostics.table_name = CONCAT(\'x$\', v_table_name);\n                EXECUTE stmt_gen_query USING @sys.diagnostics.table_name;\n                SELECT CONCAT(@sys.diagnostics.sql_select,\n                              IF(order_by IS NOT NULL, CONCAT(\'\\n ORDER BY \', REPLACE(order_by, \'%{TABLE}\', CONCAT(\'tmp_\', v_table_name, \'_start\'))), \'\'),\n                              IF(limit_rows IS NOT NULL, CONCAT(\'\\n LIMIT \', limit_rows), \'\')\n                       )\n                  INTO @sys.diagnostics.sql_select\n                  FROM tmp_sys_views_delta\n                 WHERE TABLE_NAME = v_table_name;\n                SELECT CONCAT(\'Initial \', v_table_name) AS \'The following output is:\';\n                CALL sys.execute_prepared_stmt(@sys.diagnostics.sql_select);\n            END IF;\n        END LOOP;\n        CLOSE c_sysviews_w_delta;\n        IF (@sys.diagnostics.include_raw = \'ON\') THEN\n            DEALLOCATE PREPARE stmt_gen_query;\n        END IF;\n    END IF;\n    SET v_sql_status_summary_select = \'SELECT Variable_name\',\n        v_sql_status_summary_delta  = \'\',\n        v_sql_status_summary_from   = \'\';\n    REPEAT\n        SET v_output_count = v_output_count + 1;\n        IF (v_output_count > 1) THEN\n            SET v_sleep = in_interval-(UNIX_TIMESTAMP(NOW(2))-v_iter_start);\n            SELECT NOW() AS \'Time\', CONCAT(\'Going to sleep for \', v_sleep, \' seconds. Please do not interrupt\') AS \'The following output is:\';\n            DO SLEEP(in_interval);\n        END IF;\n        SET v_iter_start = UNIX_TIMESTAMP(NOW(2));\n        SELECT NOW(), CONCAT(\'Iteration Number \', IFNULL(v_output_count, \'NULL\')) AS \'The following output is:\';\n        IF (@@log_bin = 1) THEN\n            SELECT \'SHOW MASTER STATUS\' AS \'The following output is:\';\n            SHOW MASTER STATUS;\n        END IF;\n        IF (v_has_replication <> \'NO\') THEN\n            SELECT \'SHOW SLAVE STATUS\' AS \'The following output is:\';\n            SHOW SLAVE STATUS;\n        END IF;\n        SET v_table_name = CONCAT(\'tmp_metrics_\', v_output_count);\n        CALL sys.execute_prepared_stmt(CONCAT(\'DROP TEMPORARY TABLE IF EXISTS \', v_table_name));\n        CALL sys.execute_prepared_stmt(CONCAT(\'CREATE TEMPORARY TABLE \', v_table_name, \' (\\n  Variable_name VARCHAR(193) NOT NULL,\\n  Variable_value VARCHAR(1024),\\n  Type VARCHAR(100) NOT NULL,\\n  Enabled ENUM(\'\'YES\'\', \'\'NO\'\', \'\'PARTIAL\'\') NOT NULL,\\n  PRIMARY KEY (Type, Variable_name)\\n) ENGINE = InnoDB DEFAULT CHARSET=utf8\'));\n        IF (v_has_metrics) THEN\n            SET @sys.diagnostics.sql = CONCAT(\n                \'INSERT INTO \', v_table_name,\n                \' SELECT Variable_name, REPLACE(Variable_value, \'\'\\n\'\', \'\'\\\\n\'\') AS Variable_value, Type, Enabled FROM sys.metrics\'\n            );\n        ELSE\n            SET @sys.diagnostics.sql = CONCAT(\n                \'INSERT INTO \', v_table_name,\n                \'(SELECT LOWER(VARIABLE_NAME) AS Variable_name, REPLACE(VARIABLE_VALUE, \'\'\\n\'\', \'\'\\\\n\'\') AS Variable_value,\\n                         \'\'Global Status\'\' AS Type, \'\'YES\'\' AS Enabled\\n  FROM performance_schema.global_status\\n) UNION ALL (\\nSELECT NAME AS Variable_name, COUNT AS Variable_value,\\n       CONCAT(\'\'InnoDB Metrics - \'\', SUBSYSTEM) AS Type,\\n       IF(STATUS = \'\'enabled\'\', \'\'YES\'\', \'\'NO\'\') AS Enabled\\n  FROM information_schema.INNODB_METRICS\\n WHERE NAME NOT IN (\\n     \'\'lock_row_lock_time\'\', \'\'lock_row_lock_time_avg\'\', \'\'lock_row_lock_time_max\'\', \'\'lock_row_lock_waits\'\',\\n     \'\'buffer_pool_reads\'\', \'\'buffer_pool_read_requests\'\', \'\'buffer_pool_write_requests\'\', \'\'buffer_pool_wait_free\'\',\\n     \'\'buffer_pool_read_ahead\'\', \'\'buffer_pool_read_ahead_evicted\'\', \'\'buffer_pool_pages_total\'\', \'\'buffer_pool_pages_misc\'\',\\n     \'\'buffer_pool_pages_data\'\', \'\'buffer_pool_bytes_data\'\', \'\'buffer_pool_pages_dirty\'\', \'\'buffer_pool_bytes_dirty\'\',\\n     \'\'buffer_pool_pages_free\'\', \'\'buffer_pages_created\'\', \'\'buffer_pages_written\'\', \'\'buffer_pages_read\'\',\\n     \'\'buffer_data_reads\'\', \'\'buffer_data_written\'\', \'\'file_num_open_files\'\',\\n     \'\'os_log_bytes_written\'\', \'\'os_log_fsyncs\'\', \'\'os_log_pending_fsyncs\'\', \'\'os_log_pending_writes\'\',\\n     \'\'log_waits\'\', \'\'log_write_requests\'\', \'\'log_writes\'\', \'\'innodb_dblwr_writes\'\', \'\'innodb_dblwr_pages_written\'\', \'\'innodb_page_size\'\')\\n) UNION ALL (\\nSELECT \'\'NOW()\'\' AS Variable_name, NOW(3) AS Variable_value, \'\'System Time\'\' AS Type, \'\'YES\'\' AS Enabled\\n) UNION ALL (\\nSELECT \'\'UNIX_TIMESTAMP()\'\' AS Variable_name, ROUND(UNIX_TIMESTAMP(NOW(3)), 3) AS Variable_value, \'\'System Time\'\' AS Type, \'\'YES\'\' AS Enabled\\n)\\n ORDER BY Type, Variable_name;\'\n            );\n        END IF;\n        CALL sys.execute_prepared_stmt(@sys.diagnostics.sql);\n        CALL sys.execute_prepared_stmt(\n            CONCAT(\'SELECT Variable_value INTO @sys.diagnostics.output_time FROM \', v_table_name, \' WHERE Type = \'\'System Time\'\' AND Variable_name = \'\'UNIX_TIMESTAMP()\'\'\')\n        );\n        SET v_output_time = @sys.diagnostics.output_time;\n        SET v_sql_status_summary_select = CONCAT(v_sql_status_summary_select, \',\\n       CONCAT(\\n           LEFT(s\', v_output_count, \'.Variable_value, \', v_status_summary_width, \'),\\n           IF(\', REPLACE(v_no_delta_names, \'%{COUNT}\', v_output_count), \' AND s\', v_output_count, \'.Variable_value REGEXP \'\'^[0-9]+(\\\\.[0-9]+)?$\'\', CONCAT(\'\' (\'\', ROUND(s\', v_output_count, \'.Variable_value/\', v_output_time, \', 2), \'\'/sec)\'\'), \'\'\'\')\\n       ) AS \'\'Output \', v_output_count, \'\'\'\'),\n            v_sql_status_summary_from   = CONCAT(v_sql_status_summary_from, \'\\n\',\n                                                    IF(v_output_count = 1, \'  FROM \', \'       INNER JOIN \'),\n                                                    v_table_name, \' s\', v_output_count,\n                                                    IF (v_output_count = 1, \'\', \' USING (Type, Variable_name)\'));\n        IF (v_output_count > 1) THEN\n            SET v_sql_status_summary_delta  = CONCAT(v_sql_status_summary_delta, \',\\n       IF(\', REPLACE(v_no_delta_names, \'%{COUNT}\', v_output_count), \' AND s\', (v_output_count-1), \'.Variable_value REGEXP \'\'^[0-9]+(\\\\.[0-9]+)?$\'\' AND s\', v_output_count, \'.Variable_value REGEXP \'\'^[0-9]+(\\\\.[0-9]+)?$\'\',\\n          CONCAT(IF(s\', (v_output_count-1), \'.Variable_value REGEXP \'\'^[0-9]+\\\\.[0-9]+$\'\' OR s\', v_output_count, \'.Variable_value REGEXP \'\'^[0-9]+\\\\.[0-9]+$\'\',\\n                    ROUND((s\', v_output_count, \'.Variable_value-s\', (v_output_count-1), \'.Variable_value), 2),\\n                    (s\', v_output_count, \'.Variable_value-s\', (v_output_count-1), \'.Variable_value)\\n                   ),\\n                 \'\' (\'\', ROUND((s\', v_output_count, \'.Variable_value-s\', (v_output_count-1), \'.Variable_value)/(\', v_output_time, \'-\', v_output_time_prev, \'), 2), \'\'/sec)\'\'\\n          ),\\n          \'\'\'\'\\n       ) AS \'\'Delta (\', (v_output_count-1), \' -> \', v_output_count, \')\'\'\');\n        END IF;\n        SET v_output_time_prev = v_output_time;\n        IF (@sys.diagnostics.include_raw = \'ON\') THEN\n            IF (v_has_metrics) THEN\n                SELECT \'SELECT * FROM sys.metrics\' AS \'The following output is:\';\n            ELSE\n                SELECT \'sys.metrics equivalent\' AS \'The following output is:\';\n            END IF;\n            CALL sys.execute_prepared_stmt(CONCAT(\'SELECT Type, Variable_name, Enabled, Variable_value FROM \', v_table_name, \' ORDER BY Type, Variable_name\'));\n        END IF;\n        IF (v_has_innodb IN (\'DEFAULT\', \'YES\')) THEN\n            SELECT \'SHOW ENGINE INNODB STATUS\' AS \'The following output is:\';\n            EXECUTE stmt_innodb_status;\n            SELECT \'InnoDB - Transactions\' AS \'The following output is:\';\n            SELECT * FROM information_schema.INNODB_TRX;\n        END IF;\n        IF (v_has_ndb IN (\'DEFAULT\', \'YES\')) THEN\n            SELECT \'SHOW ENGINE NDBCLUSTER STATUS\' AS \'The following output is:\';\n            EXECUTE stmt_ndbcluster_status;\n            SELECT \'ndbinfo.memoryusage\' AS \'The following output is:\';\n            SELECT node_id, memory_type, sys.format_bytes(used) AS used, used_pages, sys.format_bytes(total) AS total, total_pages,\n                   ROUND(100*(used/total), 2) AS \'Used %\'\n            FROM ndbinfo.memoryusage;\n            SET v_done = FALSE;\n            OPEN c_ndbinfo;\n            c_ndbinfo_loop: LOOP\n                FETCH c_ndbinfo INTO v_table_name;\n                IF v_done THEN\n                LEAVE c_ndbinfo_loop;\n                END IF;\n                SELECT CONCAT(\'SELECT * FROM ndbinfo.\', v_table_name) AS \'The following output is:\';\n                CALL sys.execute_prepared_stmt(CONCAT(\'SELECT * FROM `ndbinfo`.`\', v_table_name, \'`\'));\n            END LOOP;\n            CLOSE c_ndbinfo;\n            SELECT * FROM information_schema.FILES;\n        END IF;\n        SELECT \'SELECT * FROM sys.processlist\' AS \'The following output is:\';\n        SELECT processlist.* FROM sys.processlist;\n        IF (v_has_ps = \'YES\') THEN\n            IF (sys.ps_is_consumer_enabled(\'events_waits_history_long\') = \'YES\') THEN\n                SELECT \'SELECT * FROM sys.latest_file_io\' AS \'The following output is:\';\n                SELECT * FROM sys.latest_file_io;\n            END IF;\n            IF (EXISTS(SELECT 1 FROM performance_schema.setup_instruments WHERE NAME LIKE \'memory/%\' AND ENABLED = \'YES\')) THEN\n                SELECT \'SELECT * FROM sys.memory_by_host_by_current_bytes\' AS \'The following output is:\';\n                SELECT * FROM sys.memory_by_host_by_current_bytes;\n                SELECT \'SELECT * FROM sys.memory_by_thread_by_current_bytes\' AS \'The following output is:\';\n                SELECT * FROM sys.memory_by_thread_by_current_bytes;\n                SELECT \'SELECT * FROM sys.memory_by_user_by_current_bytes\' AS \'The following output is:\';\n                SELECT * FROM sys.memory_by_user_by_current_bytes;\n                SELECT \'SELECT * FROM sys.memory_global_by_current_bytes\' AS \'The following output is:\';\n                SELECT * FROM sys.memory_global_by_current_bytes;\n            END IF;\n        END IF;\n        SET v_runtime = (UNIX_TIMESTAMP(NOW(2)) - v_start);\n    UNTIL (v_runtime + in_interval >= in_max_runtime) END REPEAT;\n    IF (v_has_ps = \'YES\') THEN\n        SELECT \'SHOW ENGINE PERFORMANCE_SCHEMA STATUS\' AS \'The following output is:\';\n        EXECUTE stmt_ps_status;\n    END IF;\n    IF (v_has_innodb IN (\'DEFAULT\', \'YES\')) THEN\n        DEALLOCATE PREPARE stmt_innodb_status;\n    END IF;\n    IF (v_has_ps = \'YES\') THEN\n        DEALLOCATE PREPARE stmt_ps_status;\n    END IF;\n    IF (v_has_ndb IN (\'DEFAULT\', \'YES\')) THEN\n        DEALLOCATE PREPARE stmt_ndbcluster_status;\n    END IF;\n    SELECT \'\\n============================\\n     Schema Information\\n============================\\n\' AS \'\';\n    SELECT COUNT(*) AS \'Total Number of Tables\' FROM information_schema.TABLES;\n    IF (@sys.diagnostics.allow_i_s_tables = \'ON\') THEN\n        SELECT \'Storage Engine Usage\' AS \'The following output is:\';\n        SELECT ENGINE, COUNT(*) AS NUM_TABLES,\n                sys.format_bytes(SUM(DATA_LENGTH)) AS DATA_LENGTH,\n                sys.format_bytes(SUM(INDEX_LENGTH)) AS INDEX_LENGTH,\n                sys.format_bytes(SUM(DATA_LENGTH+INDEX_LENGTH)) AS TOTAL\n            FROM information_schema.TABLES\n            GROUP BY ENGINE;\n        SELECT \'Schema Object Overview\' AS \'The following output is:\';\n        SELECT * FROM sys.schema_object_overview;\n        SELECT \'Tables without a PRIMARY KEY\' AS \'The following output is:\';\n        SELECT TABLES.TABLE_SCHEMA, ENGINE, COUNT(*) AS NumTables\n          FROM information_schema.TABLES\n               LEFT OUTER JOIN information_schema.STATISTICS ON STATISTICS.TABLE_SCHEMA = TABLES.TABLE_SCHEMA\n                                                                AND STATISTICS.TABLE_NAME = TABLES.TABLE_NAME\n                                                                AND STATISTICS.INDEX_NAME = \'PRIMARY\'\n         WHERE STATISTICS.TABLE_NAME IS NULL\n               AND TABLES.TABLE_SCHEMA NOT IN (\'mysql\', \'information_schema\', \'performance_schema\', \'sys\')\n               AND TABLES.TABLE_TYPE = \'BASE TABLE\'\n         GROUP BY TABLES.TABLE_SCHEMA, ENGINE;\n    END IF;\n    IF (v_has_ps = \'YES\') THEN\n        SELECT \'Unused Indexes\' AS \'The following output is:\';\n        SELECT object_schema, COUNT(*) AS NumUnusedIndexes\n          FROM performance_schema.table_io_waits_summary_by_index_usage\n         WHERE index_name IS NOT NULL\n               AND count_star = 0\n               AND object_schema NOT IN (\'mysql\', \'sys\')\n               AND index_name != \'PRIMARY\'\n         GROUP BY object_schema;\n    END IF;\n    IF (v_has_ps = \'YES\') THEN\n        SELECT \'\\n=========================\\n     Overall Status\\n=========================\\n\' AS \'\';\n        SELECT \'CALL sys.ps_statement_avg_latency_histogram()\' AS \'The following output is:\';\n        CALL sys.ps_statement_avg_latency_histogram();\n        CALL sys.statement_performance_analyzer(\'snapshot\', NULL, NULL);\n        CALL sys.statement_performance_analyzer(\'overall\', NULL, \'with_runtimes_in_95th_percentile\');\n        SET @sys.diagnostics.sql = REPLACE(@sys.diagnostics.sql_gen_query_template, \'%{OUTPUT}\', \'end\');\n        IF (@sys.debug = \'ON\') THEN\n            SELECT \'The following query will be used to generate the query for each sys view\' AS \'Debug\';\n            SELECT @sys.diagnostics.sql AS \'Debug\';\n        END IF;\n        PREPARE stmt_gen_query FROM @sys.diagnostics.sql;\n        SET v_done = FALSE;\n        OPEN c_sysviews_w_delta;\n        c_sysviews_w_delta_loop: LOOP\n            FETCH c_sysviews_w_delta INTO v_table_name;\n            IF v_done THEN\n                LEAVE c_sysviews_w_delta_loop;\n            END IF;\n            IF (@sys.debug = \'ON\') THEN\n                SELECT CONCAT(\'The following queries are for storing the final content of \', v_table_name) AS \'Debug\';\n            END IF;\n            CALL sys.execute_prepared_stmt(CONCAT(\'DROP TEMPORARY TABLE IF EXISTS `tmp_\', v_table_name, \'_end`\'));\n            CALL sys.execute_prepared_stmt(CONCAT(\'CREATE TEMPORARY TABLE `tmp_\', v_table_name, \'_end` SELECT * FROM `sys`.`x$\', v_table_name, \'`\'));\n            IF (@sys.diagnostics.include_raw = \'ON\') THEN\n                SET @sys.diagnostics.table_name = CONCAT(\'x$\', v_table_name);\n                EXECUTE stmt_gen_query USING @sys.diagnostics.table_name;\n                SELECT CONCAT(@sys.diagnostics.sql_select,\n                                IF(order_by IS NOT NULL, CONCAT(\'\\n ORDER BY \', REPLACE(order_by, \'%{TABLE}\', CONCAT(\'tmp_\', v_table_name, \'_end\'))), \'\'),\n                                IF(limit_rows IS NOT NULL, CONCAT(\'\\n LIMIT \', limit_rows), \'\')\n                        )\n                    INTO @sys.diagnostics.sql_select\n                    FROM tmp_sys_views_delta\n                    WHERE TABLE_NAME = v_table_name;\n                SELECT CONCAT(\'Overall \', v_table_name) AS \'The following output is:\';\n                CALL sys.execute_prepared_stmt(@sys.diagnostics.sql_select);\n            END IF;\n        END LOOP;\n        CLOSE c_sysviews_w_delta;\n        DEALLOCATE PREPARE stmt_gen_query;\n        SELECT \'\\n======================\\n     Delta Status\\n======================\\n\' AS \'\';\n        CALL sys.statement_performance_analyzer(\'delta\', \'tmp_digests_start\', \'with_runtimes_in_95th_percentile\');\n        CALL sys.statement_performance_analyzer(\'cleanup\', NULL, NULL);\n        DROP TEMPORARY TABLE tmp_digests_start;\n        IF (@sys.debug = \'ON\') THEN\n            SELECT \'The following query will be used to generate the query for each sys view delta\' AS \'Debug\';\n            SELECT @sys.diagnostics.sql_gen_query_delta AS \'Debug\';\n        END IF;\n        PREPARE stmt_gen_query_delta FROM @sys.diagnostics.sql_gen_query_delta;\n        SET v_old_group_concat_max_len = @@session.group_concat_max_len;\n        SET @@session.group_concat_max_len = 2048;\n        SET v_done = FALSE;\n        OPEN c_sysviews_w_delta;\n        c_sysviews_w_delta_loop: LOOP\n            FETCH c_sysviews_w_delta INTO v_table_name;\n            IF v_done THEN\n                LEAVE c_sysviews_w_delta_loop;\n            END IF;\n            SET @sys.diagnostics.table_name = v_table_name;\n            EXECUTE stmt_gen_query_delta USING @sys.diagnostics.table_name;\n            SELECT CONCAT(@sys.diagnostics.sql_select,\n                            IF(where_delta IS NOT NULL, CONCAT(\'\\n WHERE \', where_delta), \'\'),\n                            IF(order_by_delta IS NOT NULL, CONCAT(\'\\n ORDER BY \', order_by_delta), \'\'),\n                            IF(limit_rows IS NOT NULL, CONCAT(\'\\n LIMIT \', limit_rows), \'\')\n                    )\n                INTO @sys.diagnostics.sql_select\n                FROM tmp_sys_views_delta\n                WHERE TABLE_NAME = v_table_name;\n            SELECT CONCAT(\'Delta \', v_table_name) AS \'The following output is:\';\n            CALL sys.execute_prepared_stmt(@sys.diagnostics.sql_select);\n            CALL sys.execute_prepared_stmt(CONCAT(\'DROP TEMPORARY TABLE `tmp_\', v_table_name, \'_end`\'));\n            CALL sys.execute_prepared_stmt(CONCAT(\'DROP TEMPORARY TABLE `tmp_\', v_table_name, \'_start`\'));\n        END LOOP;\n        CLOSE c_sysviews_w_delta;\n        SET @@session.group_concat_max_len = v_old_group_concat_max_len;\n        DEALLOCATE PREPARE stmt_gen_query_delta;\n        DROP TEMPORARY TABLE tmp_sys_views_delta;\n    END IF;\n    IF (v_has_metrics) THEN\n        SELECT \'SELECT * FROM sys.metrics\' AS \'The following output is:\';\n    ELSE\n        SELECT \'sys.metrics equivalent\' AS \'The following output is:\';\n    END IF;\n    CALL sys.execute_prepared_stmt(\n        CONCAT(v_sql_status_summary_select, v_sql_status_summary_delta, \', Type, s1.Enabled\', v_sql_status_summary_from,\n               \'\\n ORDER BY Type, Variable_name\'\n        )\n    );\n    SET v_count = 0;\n    WHILE (v_count < v_output_count) DO\n        SET v_count = v_count + 1;\n        SET v_table_name = CONCAT(\'tmp_metrics_\', v_count);\n        CALL sys.execute_prepared_stmt(CONCAT(\'DROP TEMPORARY TABLE IF EXISTS \', v_table_name));\n    END WHILE;\n    IF (in_auto_config <> \'current\') THEN\n        CALL sys.ps_setup_reload_saved();\n        SET sql_log_bin = @log_bin;\n    END IF;\n    SET @sys.diagnostics.output_time            = NULL,\n        @sys.diagnostics.sql                    = NULL,\n        @sys.diagnostics.sql_gen_query_delta    = NULL,\n        @sys.diagnostics.sql_gen_query_template = NULL,\n        @sys.diagnostics.sql_select             = NULL,\n        @sys.diagnostics.table_name             = NULL;\n    IF (v_this_thread_enabled = \'YES\') THEN\n        CALL sys.ps_setup_enable_thread(CONNECTION_ID());\n    END IF;\n    IF (@log_bin = 1) THEN\n        SET sql_log_bin = @log_bin;\n    END IF;\nEND','NONE'),
('sys','ps_statement_avg_latency_histogram','PROCEDURE','ps_statement_avg_latency_histogram','SQL','READS_SQL_DATA','NO','INVOKER','','','BEGIN\nSELECT CONCAT(\'\\n\',\n       \'\\n  . = 1 unit\',\n       \'\\n  * = 2 units\',\n       \'\\n  # = 3 units\\n\',\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(0 - \',\n                                               ROUND((@bucket_size := (SELECT ROUND((MAX(avg_us) - MIN(avg_us)) / (@buckets := 16)) AS size\n                                                                         FROM sys.x$ps_digest_avg_latency_distribution)) / (@unit_div := 1000)),\n                                                (@unit := \'ms\'), \')\'),\n                        REPEAT(\' \', (@max_label_size := ((1 + LENGTH(ROUND((@bucket_size * 15) / @unit_div)) + 3 + LENGTH(ROUND(@bucket_size * 16) / @unit_div)) + 1)) - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us <= @bucket_size), 0)),\n       REPEAT(\' \', (@max_label_len := (@max_label_size + LENGTH((@total_queries := (SELECT SUM(cnt) FROM sys.x$ps_digest_avg_latency_distribution)))) + 1) - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < (@one_unit := 40), \'.\', IF(@count_in_bucket < (@two_unit := 80), \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND(@bucket_size / @unit_div), \' - \', ROUND((@bucket_size * 2) / @unit_div), @unit, \')\'),\n                        REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us > @bucket_size AND b1.avg_us <= @bucket_size * 2), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND((@bucket_size * 2) / @unit_div), \' - \', ROUND((@bucket_size * 3) / @unit_div), @unit, \')\'),\n                        REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us > @bucket_size * 2 AND b1.avg_us <= @bucket_size * 3), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND((@bucket_size * 3) / @unit_div), \' - \', ROUND((@bucket_size * 4) / @unit_div), @unit, \')\'),\n                        REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us > @bucket_size * 3 AND b1.avg_us <= @bucket_size * 4), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND((@bucket_size * 4) / @unit_div), \' - \', ROUND((@bucket_size * 5) / @unit_div), @unit, \')\'),\n                        REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us > @bucket_size * 4 AND b1.avg_us <= @bucket_size * 5), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND((@bucket_size * 5) / @unit_div), \' - \', ROUND((@bucket_size * 6) / @unit_div), @unit, \')\'),\n                        REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us > @bucket_size * 5 AND b1.avg_us <= @bucket_size * 6), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND((@bucket_size * 6) / @unit_div), \' - \', ROUND((@bucket_size * 7) / @unit_div), @unit, \')\'),\n                        REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us > @bucket_size * 6 AND b1.avg_us <= @bucket_size * 7), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND((@bucket_size * 7) / @unit_div), \' - \', ROUND((@bucket_size * 8) / @unit_div), @unit, \')\'),\n                        REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us > @bucket_size * 7 AND b1.avg_us <= @bucket_size * 8), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND((@bucket_size * 8) / @unit_div), \' - \', ROUND((@bucket_size * 9) / @unit_div), @unit, \')\'),\n                        REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us > @bucket_size * 8 AND b1.avg_us <= @bucket_size * 9), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND((@bucket_size * 9) / @unit_div), \' - \', ROUND((@bucket_size * 10) / @unit_div), @unit, \')\'),\n                         REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                         @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                       FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                      WHERE b1.avg_us > @bucket_size * 9 AND b1.avg_us <= @bucket_size * 10), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND((@bucket_size * 10) / @unit_div), \' - \', ROUND((@bucket_size * 11) / @unit_div), @unit, \')\'),\n                        REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us > @bucket_size * 10 AND b1.avg_us <= @bucket_size * 11), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND((@bucket_size * 11) / @unit_div), \' - \', ROUND((@bucket_size * 12) / @unit_div), @unit, \')\'),\n                        REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us > @bucket_size * 11 AND b1.avg_us <= @bucket_size * 12), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND((@bucket_size * 12) / @unit_div), \' - \', ROUND((@bucket_size * 13) / @unit_div), @unit, \')\'),\n                        REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us > @bucket_size * 12 AND b1.avg_us <= @bucket_size * 13), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND((@bucket_size * 13) / @unit_div), \' - \', ROUND((@bucket_size * 14) / @unit_div), @unit, \')\'),\n                        REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us > @bucket_size * 13 AND b1.avg_us <= @bucket_size * 14), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND((@bucket_size * 14) / @unit_div), \' - \', ROUND((@bucket_size * 15) / @unit_div), @unit, \')\'),\n                        REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us > @bucket_size * 14 AND b1.avg_us <= @bucket_size * 15), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND((@bucket_size * 15) / @unit_div), \' - \', ROUND((@bucket_size * 16) / @unit_div), @unit, \')\'),\n                        REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us > @bucket_size * 15 AND b1.avg_us <= @bucket_size * 16), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       \'\\n\\n  Total Statements: \', @total_queries, \'; Buckets: \', @buckets , \'; Bucket Size: \', ROUND(@bucket_size / @unit_div) , \' \', @unit, \';\\n\'\n      ) AS `Performance Schema Statement Digest Average Latency Histogram`;\nEND','mariadb.sys@localhost','2024-02-11 05:51:13','2024-02-11 05:51:13','','\n             Description\n             Outputs a textual histogram graph of the average latency values\n             across all normalized queries tracked within the Performance Schema\n             events_statements_summary_by_digest table.\n             Can be used to show a very high level picture of what kind of\n             latency distribution statements running within this instance have.\n             Parameters\n             None.\n             Example\n             mysql> CALL sys.ps_statement_avg_latency_histogram()\\G\n             *************************** 1. row ***************************\n             Performance Schema Statement Digest Average Latency Histogram:\n               . = 1 unit\n               * = 2 units\n               # = 3 units\n             (0 - 38ms)     240 | ################################################################################\n             (38 - 77ms)    38  | ......................................\n             (77 - 115ms)   3   | ...\n             (115 - 154ms)  62  | *******************************\n             (154 - 192ms)  3   | ...\n             (192 - 231ms)  0   |\n             (231 - 269ms)  0   |\n             (269 - 307ms)  0   |\n             (307 - 346ms)  0   |\n             (346 - 384ms)  1   | .\n             (384 - 423ms)  1   | .\n             (423 - 461ms)  0   |\n             (461 - 499ms)  0   |\n             (499 - 538ms)  0   |\n             (538 - 576ms)  0   |\n             (576 - 615ms)  1   | .\n               Total Statements: 350; Buckets: 16; Bucket Size: 38 ms;\n            ','utf8mb3','utf8mb3_general_ci','utf8mb3_general_ci','BEGIN\nSELECT CONCAT(\'\\n\',\n       \'\\n  . = 1 unit\',\n       \'\\n  * = 2 units\',\n       \'\\n  # = 3 units\\n\',\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(0 - \',\n                                               ROUND((@bucket_size := (SELECT ROUND((MAX(avg_us) - MIN(avg_us)) / (@buckets := 16)) AS size\n                                                                         FROM sys.x$ps_digest_avg_latency_distribution)) / (@unit_div := 1000)),\n                                                (@unit := \'ms\'), \')\'),\n                        REPEAT(\' \', (@max_label_size := ((1 + LENGTH(ROUND((@bucket_size * 15) / @unit_div)) + 3 + LENGTH(ROUND(@bucket_size * 16) / @unit_div)) + 1)) - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us <= @bucket_size), 0)),\n       REPEAT(\' \', (@max_label_len := (@max_label_size + LENGTH((@total_queries := (SELECT SUM(cnt) FROM sys.x$ps_digest_avg_latency_distribution)))) + 1) - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < (@one_unit := 40), \'.\', IF(@count_in_bucket < (@two_unit := 80), \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND(@bucket_size / @unit_div), \' - \', ROUND((@bucket_size * 2) / @unit_div), @unit, \')\'),\n                        REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us > @bucket_size AND b1.avg_us <= @bucket_size * 2), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND((@bucket_size * 2) / @unit_div), \' - \', ROUND((@bucket_size * 3) / @unit_div), @unit, \')\'),\n                        REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us > @bucket_size * 2 AND b1.avg_us <= @bucket_size * 3), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND((@bucket_size * 3) / @unit_div), \' - \', ROUND((@bucket_size * 4) / @unit_div), @unit, \')\'),\n                        REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us > @bucket_size * 3 AND b1.avg_us <= @bucket_size * 4), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND((@bucket_size * 4) / @unit_div), \' - \', ROUND((@bucket_size * 5) / @unit_div), @unit, \')\'),\n                        REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us > @bucket_size * 4 AND b1.avg_us <= @bucket_size * 5), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND((@bucket_size * 5) / @unit_div), \' - \', ROUND((@bucket_size * 6) / @unit_div), @unit, \')\'),\n                        REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us > @bucket_size * 5 AND b1.avg_us <= @bucket_size * 6), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND((@bucket_size * 6) / @unit_div), \' - \', ROUND((@bucket_size * 7) / @unit_div), @unit, \')\'),\n                        REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us > @bucket_size * 6 AND b1.avg_us <= @bucket_size * 7), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND((@bucket_size * 7) / @unit_div), \' - \', ROUND((@bucket_size * 8) / @unit_div), @unit, \')\'),\n                        REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us > @bucket_size * 7 AND b1.avg_us <= @bucket_size * 8), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND((@bucket_size * 8) / @unit_div), \' - \', ROUND((@bucket_size * 9) / @unit_div), @unit, \')\'),\n                        REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us > @bucket_size * 8 AND b1.avg_us <= @bucket_size * 9), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND((@bucket_size * 9) / @unit_div), \' - \', ROUND((@bucket_size * 10) / @unit_div), @unit, \')\'),\n                         REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                         @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                       FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                      WHERE b1.avg_us > @bucket_size * 9 AND b1.avg_us <= @bucket_size * 10), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND((@bucket_size * 10) / @unit_div), \' - \', ROUND((@bucket_size * 11) / @unit_div), @unit, \')\'),\n                        REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us > @bucket_size * 10 AND b1.avg_us <= @bucket_size * 11), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND((@bucket_size * 11) / @unit_div), \' - \', ROUND((@bucket_size * 12) / @unit_div), @unit, \')\'),\n                        REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us > @bucket_size * 11 AND b1.avg_us <= @bucket_size * 12), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND((@bucket_size * 12) / @unit_div), \' - \', ROUND((@bucket_size * 13) / @unit_div), @unit, \')\'),\n                        REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us > @bucket_size * 12 AND b1.avg_us <= @bucket_size * 13), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND((@bucket_size * 13) / @unit_div), \' - \', ROUND((@bucket_size * 14) / @unit_div), @unit, \')\'),\n                        REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us > @bucket_size * 13 AND b1.avg_us <= @bucket_size * 14), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND((@bucket_size * 14) / @unit_div), \' - \', ROUND((@bucket_size * 15) / @unit_div), @unit, \')\'),\n                        REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us > @bucket_size * 14 AND b1.avg_us <= @bucket_size * 15), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       @label := CONCAT(@label_inner := CONCAT(\'\\n(\', ROUND((@bucket_size * 15) / @unit_div), \' - \', ROUND((@bucket_size * 16) / @unit_div), @unit, \')\'),\n                        REPEAT(\' \', @max_label_size - LENGTH(@label_inner)),\n                        @count_in_bucket := IFNULL((SELECT SUM(cnt)\n                                                      FROM sys.x$ps_digest_avg_latency_distribution AS b1\n                                                     WHERE b1.avg_us > @bucket_size * 15 AND b1.avg_us <= @bucket_size * 16), 0)),\n       REPEAT(\' \', @max_label_len - LENGTH(@label)), \'| \',\n       IFNULL(REPEAT(IF(@count_in_bucket < @one_unit, \'.\', IF(@count_in_bucket < @two_unit, \'*\', \'#\')),\n       	             IF(@count_in_bucket < @one_unit, @count_in_bucket,\n       	             	IF(@count_in_bucket < @two_unit, @count_in_bucket / 2, @count_in_bucket / 3))), \'\'),\n       \'\\n\\n  Total Statements: \', @total_queries, \'; Buckets: \', @buckets , \'; Bucket Size: \', ROUND(@bucket_size / @unit_div) , \' \', @unit, \';\\n\'\n      ) AS `Performance Schema Statement Digest Average Latency Histogram`;\nEND','NONE'),
('sys','ps_trace_statement_digest','PROCEDURE','ps_trace_statement_digest','SQL','MODIFIES_SQL_DATA','NO','INVOKER','\n        IN in_digest VARCHAR(32),\n        IN in_runtime INT,\n        IN in_interval DECIMAL(2,2),\n        IN in_start_fresh BOOLEAN,\n        IN in_auto_enable BOOLEAN\n    ','','BEGIN\n    DECLARE v_start_fresh BOOLEAN DEFAULT false;\n    DECLARE v_auto_enable BOOLEAN DEFAULT false;\n    DECLARE v_explain     BOOLEAN DEFAULT true;\n    DECLARE v_this_thread_enabed ENUM(\'YES\', \'NO\');\n    DECLARE v_runtime INT DEFAULT 0;\n    DECLARE v_start INT DEFAULT 0;\n    DECLARE v_found_stmts INT;\n    SET @log_bin := @@sql_log_bin;\n    SET sql_log_bin = 0;\n    SELECT INSTRUMENTED INTO v_this_thread_enabed FROM performance_schema.threads WHERE PROCESSLIST_ID = CONNECTION_ID();\n    CALL sys.ps_setup_disable_thread(CONNECTION_ID());\n    DROP TEMPORARY TABLE IF EXISTS stmt_trace;\n    CREATE TEMPORARY TABLE stmt_trace (\n        thread_id BIGINT UNSIGNED,\n        timer_start BIGINT UNSIGNED,\n        event_id BIGINT UNSIGNED,\n        sql_text longtext,\n        timer_wait BIGINT UNSIGNED,\n        lock_time BIGINT UNSIGNED,\n        errors BIGINT UNSIGNED,\n        mysql_errno INT,\n        rows_sent BIGINT UNSIGNED,\n        rows_affected BIGINT UNSIGNED,\n        rows_examined BIGINT UNSIGNED,\n        created_tmp_tables BIGINT UNSIGNED,\n        created_tmp_disk_tables BIGINT UNSIGNED,\n        no_index_used BIGINT UNSIGNED,\n        PRIMARY KEY (thread_id, timer_start)\n    );\n    DROP TEMPORARY TABLE IF EXISTS stmt_stages;\n    CREATE TEMPORARY TABLE stmt_stages (\n       event_id BIGINT UNSIGNED,\n       stmt_id BIGINT UNSIGNED,\n       event_name VARCHAR(128),\n       timer_wait BIGINT UNSIGNED,\n       PRIMARY KEY (event_id)\n    );\n    SET v_start_fresh = in_start_fresh;\n    IF v_start_fresh THEN\n        TRUNCATE TABLE performance_schema.events_statements_history_long;\n        TRUNCATE TABLE performance_schema.events_stages_history_long;\n    END IF;\n    SET v_auto_enable = in_auto_enable;\n    IF v_auto_enable THEN\n        CALL sys.ps_setup_save(0);\n        UPDATE performance_schema.threads\n           SET INSTRUMENTED = IF(PROCESSLIST_ID IS NOT NULL, \'YES\', \'NO\');\n        UPDATE performance_schema.setup_consumers\n           SET ENABLED = \'YES\'\n         WHERE NAME NOT LIKE \'%\\_history\'\n               AND NAME NOT LIKE \'events_wait%\'\n               AND NAME NOT LIKE \'events_transactions%\'\n               AND NAME <> \'statements_digest\';\n        UPDATE performance_schema.setup_instruments\n           SET ENABLED = \'YES\',\n               TIMED   = \'YES\'\n         WHERE NAME LIKE \'statement/%\' OR NAME LIKE \'stage/%\';\n    END IF;\n    WHILE v_runtime < in_runtime DO\n        SELECT UNIX_TIMESTAMP() INTO v_start;\n        INSERT IGNORE INTO stmt_trace\n        SELECT thread_id, timer_start, event_id, sql_text, timer_wait, lock_time, errors, mysql_errno,\n               rows_sent, rows_affected, rows_examined, created_tmp_tables, created_tmp_disk_tables, no_index_used\n          FROM performance_schema.events_statements_history_long\n        WHERE digest = in_digest;\n        INSERT IGNORE INTO stmt_stages\n        SELECT stages.event_id, stmt_trace.event_id,\n               stages.event_name, stages.timer_wait\n          FROM performance_schema.events_stages_history_long AS stages\n          JOIN stmt_trace ON stages.nesting_event_id = stmt_trace.event_id;\n        SELECT SLEEP(in_interval) INTO @sleep;\n        SET v_runtime = v_runtime + (UNIX_TIMESTAMP() - v_start);\n    END WHILE;\n    SELECT \"SUMMARY STATISTICS\";\n    SELECT COUNT(*) executions,\n           sys.format_time(SUM(timer_wait)) AS exec_time,\n           sys.format_time(SUM(lock_time)) AS lock_time,\n           SUM(rows_sent) AS rows_sent,\n           SUM(rows_affected) AS rows_affected,\n           SUM(rows_examined) AS rows_examined,\n           SUM(created_tmp_tables) AS tmp_tables,\n           SUM(no_index_used) AS full_scans\n      FROM stmt_trace;\n    SELECT event_name,\n           COUNT(*) as count,\n           sys.format_time(SUM(timer_wait)) as latency\n      FROM stmt_stages\n     GROUP BY event_name\n     ORDER BY SUM(timer_wait) DESC;\n    SELECT \"LONGEST RUNNING STATEMENT\";\n    SELECT thread_id,\n           sys.format_time(timer_wait) AS exec_time,\n           sys.format_time(lock_time) AS lock_time,\n           rows_sent,\n           rows_affected,\n           rows_examined,\n           created_tmp_tables AS tmp_tables,\n           no_index_used AS full_scan\n      FROM stmt_trace\n     ORDER BY timer_wait DESC LIMIT 1;\n    SELECT sql_text\n      FROM stmt_trace\n     ORDER BY timer_wait DESC LIMIT 1;\n    SELECT sql_text, event_id INTO @sql, @sql_id\n      FROM stmt_trace\n    ORDER BY timer_wait DESC LIMIT 1;\n    IF (@sql_id IS NOT NULL) THEN\n        SELECT event_name,\n               sys.format_time(timer_wait) as latency\n          FROM stmt_stages\n         WHERE stmt_id = @sql_id\n         ORDER BY event_id;\n    END IF;\n    DROP TEMPORARY TABLE stmt_trace;\n    DROP TEMPORARY TABLE stmt_stages;\n    IF (@sql IS NOT NULL) THEN\n        SET @stmt := CONCAT(\"EXPLAIN FORMAT=JSON \", @sql);\n        BEGIN\n            DECLARE CONTINUE HANDLER FOR 1064, 1146 SET v_explain = false;\n            PREPARE explain_stmt FROM @stmt;\n        END;\n        IF (v_explain) THEN\n            EXECUTE explain_stmt;\n            DEALLOCATE PREPARE explain_stmt;\n        END IF;\n    END IF;\n    IF v_auto_enable THEN\n        CALL sys.ps_setup_reload_saved();\n    END IF;\n    IF (v_this_thread_enabed = \'YES\') THEN\n        CALL sys.ps_setup_enable_thread(CONNECTION_ID());\n    END IF;\n    SET sql_log_bin = @log_bin;\nEND','mariadb.sys@localhost','2024-02-11 05:51:13','2024-02-11 05:51:13','','\n             Description\n             Traces all instrumentation within Performance Schema for a specific\n             Statement Digest.\n             When finding a statement of interest within the\n             performance_schema.events_statements_summary_by_digest table, feed\n             the DIGEST MD5 value in to this procedure, set how long to poll for,\n             and at what interval to poll, and it will generate a report of all\n             statistics tracked within Performance Schema for that digest for the\n             interval.\n             It will also attempt to generate an EXPLAIN for the longest running\n             example of the digest during the interval. Note this may fail, as:\n                * Performance Schema truncates long SQL_TEXT values (and hence the\n                  EXPLAIN will fail due to parse errors)\n                * the default schema is sys (so tables that are not fully qualified\n                  in the query may not be found)\n                * some queries such as SHOW are not supported in EXPLAIN.\n             When the EXPLAIN fails, the error will be ignored and no EXPLAIN\n             output generated.\n             Requires the SUPER privilege for \"SET sql_log_bin = 0;\".\n             Parameters\n             in_digest (VARCHAR(32)):\n               The statement digest identifier you would like to analyze\n             in_runtime (INT):\n               The number of seconds to run analysis for\n             in_interval (DECIMAL(2,2)):\n               The interval (in seconds, may be fractional) at which to try\n               and take snapshots\n             in_start_fresh (BOOLEAN):\n               Whether to TRUNCATE the events_statements_history_long and\n               events_stages_history_long tables before starting\n             in_auto_enable (BOOLEAN):\n               Whether to automatically turn on required consumers\n             Example\n             mysql> call ps_trace_statement_digest(\'891ec6860f98ba46d89dd20b0c03652c\', 10, 0.1, true, true);\n             +--------------------+\n             | SUMMARY STATISTICS |\n             +--------------------+\n             | SUMMARY STATISTICS |\n             +--------------------+\n             1 row in set (9.11 sec)\n             +------------+-----------+-----------+-----------+---------------+------------+------------+\n             | executions | exec_time | lock_time | rows_sent | rows_examined | tmp_tables | full_scans |\n             +------------+-----------+-----------+-----------+---------------+------------+------------+\n             |         21 | 4.11 ms   | 2.00 ms   |         0 |            21 |          0 |          0 |\n             +------------+-----------+-----------+-----------+---------------+------------+------------+\n             1 row in set (9.11 sec)\n             +------------------------------------------+-------+-----------+\n             | event_name                               | count | latency   |\n             +------------------------------------------+-------+-----------+\n             | stage/sql/checking query cache for query |    16 | 724.37 us |\n             | stage/sql/statistics                     |    16 | 546.92 us |\n             | stage/sql/freeing items                  |    18 | 520.11 us |\n             | stage/sql/init                           |    51 | 466.80 us |\n             ...\n             | stage/sql/cleaning up                    |    18 | 11.92 us  |\n             | stage/sql/executing                      |    16 | 6.95 us   |\n             +------------------------------------------+-------+-----------+\n             17 rows in set (9.12 sec)\n             +---------------------------+\n             | LONGEST RUNNING STATEMENT |\n             +---------------------------+\n             | LONGEST RUNNING STATEMENT |\n             +---------------------------+\n             1 row in set (9.16 sec)\n             +-----------+-----------+-----------+-----------+---------------+------------+-----------+\n             | thread_id | exec_time | lock_time | rows_sent | rows_examined | tmp_tables | full_scan |\n             +-----------+-----------+-----------+-----------+---------------+------------+-----------+\n             |    166646 | 618.43 us | 1.00 ms   |         0 |             1 |          0 |         0 |\n             +-----------+-----------+-----------+-----------+---------------+------------+-----------+\n             1 row in set (9.16 sec)\n             // Truncated for clarity...\n             +-----------------------------------------------------------------+\n             | sql_text                                                        |\n             +-----------------------------------------------------------------+\n             | select hibeventhe0_.id as id1382_, hibeventhe0_.createdTime ... |\n             +-----------------------------------------------------------------+\n             1 row in set (9.17 sec)\n             +------------------------------------------+-----------+\n             | event_name                               | latency   |\n             +------------------------------------------+-----------+\n             | stage/sql/init                           | 8.61 us   |\n             | stage/sql/Waiting for query cache lock   | 453.23 us |\n             | stage/sql/init                           | 331.07 ns |\n             | stage/sql/checking query cache for query | 43.04 us  |\n             ...\n             | stage/sql/freeing items                  | 30.46 us  |\n             | stage/sql/cleaning up                    | 662.13 ns |\n             +------------------------------------------+-----------+\n             18 rows in set (9.23 sec)\n             +----+-------------+--------------+-------+---------------+-----------+---------+-------------+------+-------+\n             | id | select_type | table        | type  | possible_keys | key       | key_len | ref         | rows | Extra |\n             +----+-------------+--------------+-------+---------------+-----------+---------+-------------+------+-------+\n             |  1 | SIMPLE      | hibeventhe0_ | const | fixedTime     | fixedTime | 775     | const,const |    1 | NULL  |\n             +----+-------------+--------------+-------+---------------+-----------+---------+-------------+------+-------+\n             1 row in set (9.27 sec)\n             Query OK, 0 rows affected (9.28 sec)\n            ','utf8mb3','utf8mb3_general_ci','utf8mb3_general_ci','BEGIN\n    DECLARE v_start_fresh BOOLEAN DEFAULT false;\n    DECLARE v_auto_enable BOOLEAN DEFAULT false;\n    DECLARE v_explain     BOOLEAN DEFAULT true;\n    DECLARE v_this_thread_enabed ENUM(\'YES\', \'NO\');\n    DECLARE v_runtime INT DEFAULT 0;\n    DECLARE v_start INT DEFAULT 0;\n    DECLARE v_found_stmts INT;\n    SET @log_bin := @@sql_log_bin;\n    SET sql_log_bin = 0;\n    SELECT INSTRUMENTED INTO v_this_thread_enabed FROM performance_schema.threads WHERE PROCESSLIST_ID = CONNECTION_ID();\n    CALL sys.ps_setup_disable_thread(CONNECTION_ID());\n    DROP TEMPORARY TABLE IF EXISTS stmt_trace;\n    CREATE TEMPORARY TABLE stmt_trace (\n        thread_id BIGINT UNSIGNED,\n        timer_start BIGINT UNSIGNED,\n        event_id BIGINT UNSIGNED,\n        sql_text longtext,\n        timer_wait BIGINT UNSIGNED,\n        lock_time BIGINT UNSIGNED,\n        errors BIGINT UNSIGNED,\n        mysql_errno INT,\n        rows_sent BIGINT UNSIGNED,\n        rows_affected BIGINT UNSIGNED,\n        rows_examined BIGINT UNSIGNED,\n        created_tmp_tables BIGINT UNSIGNED,\n        created_tmp_disk_tables BIGINT UNSIGNED,\n        no_index_used BIGINT UNSIGNED,\n        PRIMARY KEY (thread_id, timer_start)\n    );\n    DROP TEMPORARY TABLE IF EXISTS stmt_stages;\n    CREATE TEMPORARY TABLE stmt_stages (\n       event_id BIGINT UNSIGNED,\n       stmt_id BIGINT UNSIGNED,\n       event_name VARCHAR(128),\n       timer_wait BIGINT UNSIGNED,\n       PRIMARY KEY (event_id)\n    );\n    SET v_start_fresh = in_start_fresh;\n    IF v_start_fresh THEN\n        TRUNCATE TABLE performance_schema.events_statements_history_long;\n        TRUNCATE TABLE performance_schema.events_stages_history_long;\n    END IF;\n    SET v_auto_enable = in_auto_enable;\n    IF v_auto_enable THEN\n        CALL sys.ps_setup_save(0);\n        UPDATE performance_schema.threads\n           SET INSTRUMENTED = IF(PROCESSLIST_ID IS NOT NULL, \'YES\', \'NO\');\n        UPDATE performance_schema.setup_consumers\n           SET ENABLED = \'YES\'\n         WHERE NAME NOT LIKE \'%\\_history\'\n               AND NAME NOT LIKE \'events_wait%\'\n               AND NAME NOT LIKE \'events_transactions%\'\n               AND NAME <> \'statements_digest\';\n        UPDATE performance_schema.setup_instruments\n           SET ENABLED = \'YES\',\n               TIMED   = \'YES\'\n         WHERE NAME LIKE \'statement/%\' OR NAME LIKE \'stage/%\';\n    END IF;\n    WHILE v_runtime < in_runtime DO\n        SELECT UNIX_TIMESTAMP() INTO v_start;\n        INSERT IGNORE INTO stmt_trace\n        SELECT thread_id, timer_start, event_id, sql_text, timer_wait, lock_time, errors, mysql_errno,\n               rows_sent, rows_affected, rows_examined, created_tmp_tables, created_tmp_disk_tables, no_index_used\n          FROM performance_schema.events_statements_history_long\n        WHERE digest = in_digest;\n        INSERT IGNORE INTO stmt_stages\n        SELECT stages.event_id, stmt_trace.event_id,\n               stages.event_name, stages.timer_wait\n          FROM performance_schema.events_stages_history_long AS stages\n          JOIN stmt_trace ON stages.nesting_event_id = stmt_trace.event_id;\n        SELECT SLEEP(in_interval) INTO @sleep;\n        SET v_runtime = v_runtime + (UNIX_TIMESTAMP() - v_start);\n    END WHILE;\n    SELECT \"SUMMARY STATISTICS\";\n    SELECT COUNT(*) executions,\n           sys.format_time(SUM(timer_wait)) AS exec_time,\n           sys.format_time(SUM(lock_time)) AS lock_time,\n           SUM(rows_sent) AS rows_sent,\n           SUM(rows_affected) AS rows_affected,\n           SUM(rows_examined) AS rows_examined,\n           SUM(created_tmp_tables) AS tmp_tables,\n           SUM(no_index_used) AS full_scans\n      FROM stmt_trace;\n    SELECT event_name,\n           COUNT(*) as count,\n           sys.format_time(SUM(timer_wait)) as latency\n      FROM stmt_stages\n     GROUP BY event_name\n     ORDER BY SUM(timer_wait) DESC;\n    SELECT \"LONGEST RUNNING STATEMENT\";\n    SELECT thread_id,\n           sys.format_time(timer_wait) AS exec_time,\n           sys.format_time(lock_time) AS lock_time,\n           rows_sent,\n           rows_affected,\n           rows_examined,\n           created_tmp_tables AS tmp_tables,\n           no_index_used AS full_scan\n      FROM stmt_trace\n     ORDER BY timer_wait DESC LIMIT 1;\n    SELECT sql_text\n      FROM stmt_trace\n     ORDER BY timer_wait DESC LIMIT 1;\n    SELECT sql_text, event_id INTO @sql, @sql_id\n      FROM stmt_trace\n    ORDER BY timer_wait DESC LIMIT 1;\n    IF (@sql_id IS NOT NULL) THEN\n        SELECT event_name,\n               sys.format_time(timer_wait) as latency\n          FROM stmt_stages\n         WHERE stmt_id = @sql_id\n         ORDER BY event_id;\n    END IF;\n    DROP TEMPORARY TABLE stmt_trace;\n    DROP TEMPORARY TABLE stmt_stages;\n    IF (@sql IS NOT NULL) THEN\n        SET @stmt := CONCAT(\"EXPLAIN FORMAT=JSON \", @sql);\n        BEGIN\n            DECLARE CONTINUE HANDLER FOR 1064, 1146 SET v_explain = false;\n            PREPARE explain_stmt FROM @stmt;\n        END;\n        IF (v_explain) THEN\n            EXECUTE explain_stmt;\n            DEALLOCATE PREPARE explain_stmt;\n        END IF;\n    END IF;\n    IF v_auto_enable THEN\n        CALL sys.ps_setup_reload_saved();\n    END IF;\n    IF (v_this_thread_enabed = \'YES\') THEN\n        CALL sys.ps_setup_enable_thread(CONNECTION_ID());\n    END IF;\n    SET sql_log_bin = @log_bin;\nEND','NONE'),
('sys','ps_trace_thread','PROCEDURE','ps_trace_thread','SQL','MODIFIES_SQL_DATA','NO','INVOKER','\n        IN in_thread_id BIGINT UNSIGNED,\n        IN in_outfile VARCHAR(255),\n        IN in_max_runtime DECIMAL(20,2),\n        IN in_interval DECIMAL(20,2),\n        IN in_start_fresh BOOLEAN,\n        IN in_auto_setup BOOLEAN,\n        IN in_debug BOOLEAN\n    ','','BEGIN\n    DECLARE v_done bool DEFAULT FALSE;\n    DECLARE v_start, v_runtime DECIMAL(20,2) DEFAULT 0.0;\n    DECLARE v_min_event_id bigint unsigned DEFAULT 0;\n    DECLARE v_this_thread_enabed ENUM(\'YES\', \'NO\');\n    DECLARE v_event longtext;\n    DECLARE c_stack CURSOR FOR\n        SELECT CONCAT(IF(nesting_event_id IS NOT NULL, CONCAT(nesting_event_id, \' -> \'), \'\'),\n                    event_id, \'; \', event_id, \' [label=\"\',\n                    \'(\', sys.format_time(timer_wait), \') \',\n                    IF (event_name NOT LIKE \'wait/io%\',\n                        SUBSTRING_INDEX(event_name, \'/\', -2),\n                        IF (event_name NOT LIKE \'wait/io/file%\' OR event_name NOT LIKE \'wait/io/socket%\',\n                            SUBSTRING_INDEX(event_name, \'/\', -4),\n                            event_name)\n                        ),\n                    IF (event_name LIKE \'statement/%\', IFNULL(CONCAT(\'\\\\n\', wait_info), \'\'), \'\'),\n                    IF (in_debug AND event_name LIKE \'wait%\', wait_info, \'\'),\n                    \'\", \',\n                    CASE WHEN event_name LIKE \'wait/io/file%\' THEN\n                           \'shape=box, style=filled, color=red\'\n                         WHEN event_name LIKE \'wait/io/table%\' THEN\n                           \'shape=box, style=filled, color=green\'\n                         WHEN event_name LIKE \'wait/io/socket%\' THEN\n                           \'shape=box, style=filled, color=yellow\'\n                         WHEN event_name LIKE \'wait/synch/mutex%\' THEN\n                           \'style=filled, color=lightskyblue\'\n                         WHEN event_name LIKE \'wait/synch/cond%\' THEN\n                           \'style=filled, color=darkseagreen3\'\n                         WHEN event_name LIKE \'wait/synch/rwlock%\' THEN\n                           \'style=filled, color=orchid\'\n                         WHEN event_name LIKE \'wait/lock%\' THEN\n                           \'shape=box, style=filled, color=tan\'\n                         WHEN event_name LIKE \'statement/%\' THEN\n                           CONCAT(\'shape=box, style=bold\',\n                                  CASE WHEN event_name LIKE \'statement/com/%\' THEN\n                                         \' style=filled, color=darkseagreen\'\n                                       ELSE\n                                         IF((timer_wait/1000000000000) > @@log_slow_query_time,\n                                            \' style=filled, color=red\',\n                                            \' style=filled, color=lightblue\')\n                                  END\n                           )\n                         WHEN event_name LIKE \'stage/%\' THEN\n                           \'style=filled, color=slategray3\'\n                         WHEN event_name LIKE \'%idle%\' THEN\n                           \'shape=box, style=filled, color=firebrick3\'\n                         ELSE \'\' END,\n                     \'];\\n\'\n                   ) event, event_id\n        FROM (\n             (SELECT thread_id, event_id, event_name, timer_wait, timer_start, nesting_event_id,\n                     CONCAT(sql_text, \'\\\\n\',\n                            \'errors: \', errors, \'\\\\n\',\n                            \'warnings: \', warnings, \'\\\\n\',\n                            \'lock time: \', sys.format_time(lock_time),\'\\\\n\',\n                            \'rows affected: \', rows_affected, \'\\\\n\',\n                            \'rows sent: \', rows_sent, \'\\\\n\',\n                            \'rows examined: \', rows_examined, \'\\\\n\',\n                            \'tmp tables: \', created_tmp_tables, \'\\\\n\',\n                            \'tmp disk tables: \', created_tmp_disk_tables, \'\\\\n\'\n                            \'select scan: \', select_scan, \'\\\\n\',\n                            \'select full join: \', select_full_join, \'\\\\n\',\n                            \'select full range join: \', select_full_range_join, \'\\\\n\',\n                            \'select range: \', select_range, \'\\\\n\',\n                            \'select range check: \', select_range_check, \'\\\\n\',\n                            \'sort merge passes: \', sort_merge_passes, \'\\\\n\',\n                            \'sort rows: \', sort_rows, \'\\\\n\',\n                            \'sort range: \', sort_range, \'\\\\n\',\n                            \'sort scan: \', sort_scan, \'\\\\n\',\n                            \'no index used: \', IF(no_index_used, \'TRUE\', \'FALSE\'), \'\\\\n\',\n                            \'no good index used: \', IF(no_good_index_used, \'TRUE\', \'FALSE\'), \'\\\\n\'\n                     ) AS wait_info\n                FROM performance_schema.events_statements_history_long\n               WHERE thread_id = in_thread_id AND event_id > v_min_event_id)\n             UNION\n             (SELECT thread_id, event_id, event_name, timer_wait, timer_start, nesting_event_id, null AS wait_info\n                FROM performance_schema.events_stages_history_long\n               WHERE thread_id = in_thread_id AND event_id > v_min_event_id)\n             UNION\n             (SELECT thread_id, event_id,\n                     CONCAT(event_name,\n                            IF(event_name NOT LIKE \'wait/synch/mutex%\', IFNULL(CONCAT(\' - \', operation), \'\'), \'\'),\n                            IF(number_of_bytes IS NOT NULL, CONCAT(\' \', number_of_bytes, \' bytes\'), \'\'),\n                            IF(event_name LIKE \'wait/io/file%\', \'\\\\n\', \'\'),\n                            IF(object_schema IS NOT NULL, CONCAT(\'\\\\nObject: \', object_schema, \'.\'), \'\'),\n                            IF(object_name IS NOT NULL,\n                               IF (event_name LIKE \'wait/io/socket%\',\n                                   CONCAT(\'\\\\n\', IF (object_name LIKE \':0%\', @@socket, object_name)),\n                                   object_name),\n                               \'\'\n                            ),\n                            IF(index_name IS NOT NULL, CONCAT(\' Index: \', index_name), \'\'), \'\\\\n\'\n                     ) AS event_name,\n                     timer_wait, timer_start, nesting_event_id, source AS wait_info\n                FROM performance_schema.events_waits_history_long\n               WHERE thread_id = in_thread_id AND event_id > v_min_event_id)\n           ) events\n       ORDER BY event_id;\n    DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = TRUE;\n    SET @log_bin := @@sql_log_bin;\n    SET sql_log_bin = 0;\n    SELECT INSTRUMENTED INTO v_this_thread_enabed FROM performance_schema.threads WHERE PROCESSLIST_ID = CONNECTION_ID();\n    CALL sys.ps_setup_disable_thread(CONNECTION_ID());\n    IF (in_auto_setup) THEN\n        CALL sys.ps_setup_save(0);\n        DELETE FROM performance_schema.setup_actors;\n        UPDATE performance_schema.threads\n           SET INSTRUMENTED = IF(THREAD_ID = in_thread_id, \'YES\', \'NO\');\n        UPDATE performance_schema.setup_consumers\n           SET ENABLED = \'YES\'\n         WHERE NAME NOT LIKE \'%\\_history\';\n        UPDATE performance_schema.setup_instruments\n           SET ENABLED = \'YES\',\n               TIMED   = \'YES\';\n    END IF;\n    IF (in_start_fresh) THEN\n        TRUNCATE performance_schema.events_statements_history_long;\n        TRUNCATE performance_schema.events_stages_history_long;\n        TRUNCATE performance_schema.events_waits_history_long;\n    END IF;\n    DROP TEMPORARY TABLE IF EXISTS tmp_events;\n    CREATE TEMPORARY TABLE tmp_events (\n      event_id bigint unsigned NOT NULL,\n      event longblob,\n      PRIMARY KEY (event_id)\n    );\n    INSERT INTO tmp_events VALUES (0, CONCAT(\'digraph events { rankdir=LR; nodesep=0.10;\\n\',\n                                             \'// Stack created .....: \', NOW(), \'\\n\',\n                                             \'// MySQL version .....: \', VERSION(), \'\\n\',\n                                             \'// MySQL hostname ....: \', @@hostname, \'\\n\',\n                                             \'// MySQL port ........: \', @@port, \'\\n\',\n                                             \'// MySQL socket ......: \', @@socket, \'\\n\',\n                                             \'// MySQL user ........: \', CURRENT_USER(), \'\\n\'));\n    SELECT CONCAT(\'Data collection starting for THREAD_ID = \', in_thread_id) AS \'Info\';\n    SET v_min_event_id = 0,\n        v_start        = UNIX_TIMESTAMP(),\n        in_interval    = IFNULL(in_interval, 1.00),\n        in_max_runtime = IFNULL(in_max_runtime, 60.00);\n    WHILE (v_runtime < in_max_runtime\n           AND (SELECT INSTRUMENTED FROM performance_schema.threads WHERE THREAD_ID = in_thread_id) = \'YES\') DO\n        SET v_done = FALSE;\n        OPEN c_stack;\n        c_stack_loop: LOOP\n            FETCH c_stack INTO v_event, v_min_event_id;\n            IF v_done THEN\n                LEAVE c_stack_loop;\n            END IF;\n            IF (LENGTH(v_event) > 0) THEN\n                INSERT INTO tmp_events VALUES (v_min_event_id, v_event);\n            END IF;\n        END LOOP;\n        CLOSE c_stack;\n        SELECT SLEEP(in_interval) INTO @sleep;\n        SET v_runtime = (UNIX_TIMESTAMP() - v_start);\n    END WHILE;\n    INSERT INTO tmp_events VALUES (v_min_event_id+1, \'}\');\n    SET @query = CONCAT(\'SELECT event FROM tmp_events ORDER BY event_id INTO OUTFILE \'\'\', in_outfile, \'\'\' FIELDS ESCAPED BY \'\'\'\' LINES TERMINATED BY \'\'\'\'\');\n    PREPARE stmt_output FROM @query;\n    EXECUTE stmt_output;\n    DEALLOCATE PREPARE stmt_output;\n    SELECT CONCAT(\'Stack trace written to \', in_outfile) AS \'Info\';\n    SELECT CONCAT(\'dot -Tpdf -o /tmp/stack_\', in_thread_id, \'.pdf \', in_outfile) AS \'Convert to PDF\';\n    SELECT CONCAT(\'dot -Tpng -o /tmp/stack_\', in_thread_id, \'.png \', in_outfile) AS \'Convert to PNG\';\n    DROP TEMPORARY TABLE tmp_events;\n    IF (in_auto_setup) THEN\n        CALL sys.ps_setup_reload_saved();\n    END IF;\n    IF (v_this_thread_enabed = \'YES\') THEN\n        CALL sys.ps_setup_enable_thread(CONNECTION_ID());\n    END IF;\n    SET sql_log_bin = @log_bin;\nEND','mariadb.sys@localhost','2024-02-11 05:51:13','2024-02-11 05:51:13','','\n             Description\n             Dumps all data within Performance Schema for an instrumented thread,\n             to create a DOT formatted graph file.\n             Each resultset returned from the procedure should be used for a complete graph\n             Requires the SUPER privilege for \"SET sql_log_bin = 0;\".\n             Parameters\n             in_thread_id (BIGINT UNSIGNED):\n               The thread that you would like a stack trace for\n             in_outfile  (VARCHAR(255)):\n               The filename the dot file will be written to\n             in_max_runtime (DECIMAL(20,2)):\n               The maximum time to keep collecting data.\n               Use NULL to get the default which is 60 seconds.\n             in_interval (DECIMAL(20,2)):\n               How long to sleep between data collections.\n               Use NULL to get the default which is 1 second.\n             in_start_fresh (BOOLEAN):\n               Whether to reset all Performance Schema data before tracing.\n             in_auto_setup (BOOLEAN):\n               Whether to disable all other threads and enable all consumers/instruments.\n               This will also reset the settings at the end of the run.\n             in_debug (BOOLEAN):\n               Whether you would like to include file:lineno in the graph\n             Example\n             mysql> CALL sys.ps_trace_thread(25, CONCAT(\'/tmp/stack-\', REPLACE(NOW(), \' \', \'-\'), \'.dot\'), NULL, NULL, TRUE, TRUE, TRUE);\n             +-------------------+\n             | summary           |\n             +-------------------+\n             | Disabled 1 thread |\n             +-------------------+\n             1 row in set (0.00 sec)\n             +---------------------------------------------+\n             | Info                                        |\n             +---------------------------------------------+\n             | Data collection starting for THREAD_ID = 25 |\n             +---------------------------------------------+\n             1 row in set (0.03 sec)\n             +-----------------------------------------------------------+\n             | Info                                                      |\n             +-----------------------------------------------------------+\n             | Stack trace written to /tmp/stack-2014-02-16-21:18:41.dot |\n             +-----------------------------------------------------------+\n             1 row in set (60.07 sec)\n             +-------------------------------------------------------------------+\n             | Convert to PDF                                                    |\n             +-------------------------------------------------------------------+\n             | dot -Tpdf -o /tmp/stack_25.pdf /tmp/stack-2014-02-16-21:18:41.dot |\n             +-------------------------------------------------------------------+\n             1 row in set (60.07 sec)\n             +-------------------------------------------------------------------+\n             | Convert to PNG                                                    |\n             +-------------------------------------------------------------------+\n             | dot -Tpng -o /tmp/stack_25.png /tmp/stack-2014-02-16-21:18:41.dot |\n             +-------------------------------------------------------------------+\n             1 row in set (60.07 sec)\n             +------------------+\n             | summary          |\n             +------------------+\n             | Enabled 1 thread |\n             +------------------+\n             1 row in set (60.32 sec)\n            ','utf8mb3','utf8mb3_general_ci','utf8mb3_general_ci','BEGIN\n    DECLARE v_done bool DEFAULT FALSE;\n    DECLARE v_start, v_runtime DECIMAL(20,2) DEFAULT 0.0;\n    DECLARE v_min_event_id bigint unsigned DEFAULT 0;\n    DECLARE v_this_thread_enabed ENUM(\'YES\', \'NO\');\n    DECLARE v_event longtext;\n    DECLARE c_stack CURSOR FOR\n        SELECT CONCAT(IF(nesting_event_id IS NOT NULL, CONCAT(nesting_event_id, \' -> \'), \'\'),\n                    event_id, \'; \', event_id, \' [label=\"\',\n                    \'(\', sys.format_time(timer_wait), \') \',\n                    IF (event_name NOT LIKE \'wait/io%\',\n                        SUBSTRING_INDEX(event_name, \'/\', -2),\n                        IF (event_name NOT LIKE \'wait/io/file%\' OR event_name NOT LIKE \'wait/io/socket%\',\n                            SUBSTRING_INDEX(event_name, \'/\', -4),\n                            event_name)\n                        ),\n                    IF (event_name LIKE \'statement/%\', IFNULL(CONCAT(\'\\n\', wait_info), \'\'), \'\'),\n                    IF (in_debug AND event_name LIKE \'wait%\', wait_info, \'\'),\n                    \'\", \',\n                    CASE WHEN event_name LIKE \'wait/io/file%\' THEN\n                           \'shape=box, style=filled, color=red\'\n                         WHEN event_name LIKE \'wait/io/table%\' THEN\n                           \'shape=box, style=filled, color=green\'\n                         WHEN event_name LIKE \'wait/io/socket%\' THEN\n                           \'shape=box, style=filled, color=yellow\'\n                         WHEN event_name LIKE \'wait/synch/mutex%\' THEN\n                           \'style=filled, color=lightskyblue\'\n                         WHEN event_name LIKE \'wait/synch/cond%\' THEN\n                           \'style=filled, color=darkseagreen3\'\n                         WHEN event_name LIKE \'wait/synch/rwlock%\' THEN\n                           \'style=filled, color=orchid\'\n                         WHEN event_name LIKE \'wait/lock%\' THEN\n                           \'shape=box, style=filled, color=tan\'\n                         WHEN event_name LIKE \'statement/%\' THEN\n                           CONCAT(\'shape=box, style=bold\',\n                                  CASE WHEN event_name LIKE \'statement/com/%\' THEN\n                                         \' style=filled, color=darkseagreen\'\n                                       ELSE\n                                         IF((timer_wait/1000000000000) > @@log_slow_query_time,\n                                            \' style=filled, color=red\',\n                                            \' style=filled, color=lightblue\')\n                                  END\n                           )\n                         WHEN event_name LIKE \'stage/%\' THEN\n                           \'style=filled, color=slategray3\'\n                         WHEN event_name LIKE \'%idle%\' THEN\n                           \'shape=box, style=filled, color=firebrick3\'\n                         ELSE \'\' END,\n                     \'];\\n\'\n                   ) event, event_id\n        FROM (\n             (SELECT thread_id, event_id, event_name, timer_wait, timer_start, nesting_event_id,\n                     CONCAT(sql_text, \'\\n\',\n                            \'errors: \', errors, \'\\n\',\n                            \'warnings: \', warnings, \'\\n\',\n                            \'lock time: \', sys.format_time(lock_time),\'\\n\',\n                            \'rows affected: \', rows_affected, \'\\n\',\n                            \'rows sent: \', rows_sent, \'\\n\',\n                            \'rows examined: \', rows_examined, \'\\n\',\n                            \'tmp tables: \', created_tmp_tables, \'\\n\',\n                            \'tmp disk tables: \', created_tmp_disk_tables, \'\\n\'\n                            \'select scan: \', select_scan, \'\\n\',\n                            \'select full join: \', select_full_join, \'\\n\',\n                            \'select full range join: \', select_full_range_join, \'\\n\',\n                            \'select range: \', select_range, \'\\n\',\n                            \'select range check: \', select_range_check, \'\\n\',\n                            \'sort merge passes: \', sort_merge_passes, \'\\n\',\n                            \'sort rows: \', sort_rows, \'\\n\',\n                            \'sort range: \', sort_range, \'\\n\',\n                            \'sort scan: \', sort_scan, \'\\n\',\n                            \'no index used: \', IF(no_index_used, \'TRUE\', \'FALSE\'), \'\\n\',\n                            \'no good index used: \', IF(no_good_index_used, \'TRUE\', \'FALSE\'), \'\\n\'\n                     ) AS wait_info\n                FROM performance_schema.events_statements_history_long\n               WHERE thread_id = in_thread_id AND event_id > v_min_event_id)\n             UNION\n             (SELECT thread_id, event_id, event_name, timer_wait, timer_start, nesting_event_id, null AS wait_info\n                FROM performance_schema.events_stages_history_long\n               WHERE thread_id = in_thread_id AND event_id > v_min_event_id)\n             UNION\n             (SELECT thread_id, event_id,\n                     CONCAT(event_name,\n                            IF(event_name NOT LIKE \'wait/synch/mutex%\', IFNULL(CONCAT(\' - \', operation), \'\'), \'\'),\n                            IF(number_of_bytes IS NOT NULL, CONCAT(\' \', number_of_bytes, \' bytes\'), \'\'),\n                            IF(event_name LIKE \'wait/io/file%\', \'\\n\', \'\'),\n                            IF(object_schema IS NOT NULL, CONCAT(\'\\nObject: \', object_schema, \'.\'), \'\'),\n                            IF(object_name IS NOT NULL,\n                               IF (event_name LIKE \'wait/io/socket%\',\n                                   CONCAT(\'\\n\', IF (object_name LIKE \':0%\', @@socket, object_name)),\n                                   object_name),\n                               \'\'\n                            ),\n                            IF(index_name IS NOT NULL, CONCAT(\' Index: \', index_name), \'\'), \'\\n\'\n                     ) AS event_name,\n                     timer_wait, timer_start, nesting_event_id, source AS wait_info\n                FROM performance_schema.events_waits_history_long\n               WHERE thread_id = in_thread_id AND event_id > v_min_event_id)\n           ) events\n       ORDER BY event_id;\n    DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = TRUE;\n    SET @log_bin := @@sql_log_bin;\n    SET sql_log_bin = 0;\n    SELECT INSTRUMENTED INTO v_this_thread_enabed FROM performance_schema.threads WHERE PROCESSLIST_ID = CONNECTION_ID();\n    CALL sys.ps_setup_disable_thread(CONNECTION_ID());\n    IF (in_auto_setup) THEN\n        CALL sys.ps_setup_save(0);\n        DELETE FROM performance_schema.setup_actors;\n        UPDATE performance_schema.threads\n           SET INSTRUMENTED = IF(THREAD_ID = in_thread_id, \'YES\', \'NO\');\n        UPDATE performance_schema.setup_consumers\n           SET ENABLED = \'YES\'\n         WHERE NAME NOT LIKE \'%\\_history\';\n        UPDATE performance_schema.setup_instruments\n           SET ENABLED = \'YES\',\n               TIMED   = \'YES\';\n    END IF;\n    IF (in_start_fresh) THEN\n        TRUNCATE performance_schema.events_statements_history_long;\n        TRUNCATE performance_schema.events_stages_history_long;\n        TRUNCATE performance_schema.events_waits_history_long;\n    END IF;\n    DROP TEMPORARY TABLE IF EXISTS tmp_events;\n    CREATE TEMPORARY TABLE tmp_events (\n      event_id bigint unsigned NOT NULL,\n      event longblob,\n      PRIMARY KEY (event_id)\n    );\n    INSERT INTO tmp_events VALUES (0, CONCAT(\'digraph events { rankdir=LR; nodesep=0.10;\\n\',\n                                             \'// Stack created .....: \', NOW(), \'\\n\',\n                                             \'// MySQL version .....: \', VERSION(), \'\\n\',\n                                             \'// MySQL hostname ....: \', @@hostname, \'\\n\',\n                                             \'// MySQL port ........: \', @@port, \'\\n\',\n                                             \'// MySQL socket ......: \', @@socket, \'\\n\',\n                                             \'// MySQL user ........: \', CURRENT_USER(), \'\\n\'));\n    SELECT CONCAT(\'Data collection starting for THREAD_ID = \', in_thread_id) AS \'Info\';\n    SET v_min_event_id = 0,\n        v_start        = UNIX_TIMESTAMP(),\n        in_interval    = IFNULL(in_interval, 1.00),\n        in_max_runtime = IFNULL(in_max_runtime, 60.00);\n    WHILE (v_runtime < in_max_runtime\n           AND (SELECT INSTRUMENTED FROM performance_schema.threads WHERE THREAD_ID = in_thread_id) = \'YES\') DO\n        SET v_done = FALSE;\n        OPEN c_stack;\n        c_stack_loop: LOOP\n            FETCH c_stack INTO v_event, v_min_event_id;\n            IF v_done THEN\n                LEAVE c_stack_loop;\n            END IF;\n            IF (LENGTH(v_event) > 0) THEN\n                INSERT INTO tmp_events VALUES (v_min_event_id, v_event);\n            END IF;\n        END LOOP;\n        CLOSE c_stack;\n        SELECT SLEEP(in_interval) INTO @sleep;\n        SET v_runtime = (UNIX_TIMESTAMP() - v_start);\n    END WHILE;\n    INSERT INTO tmp_events VALUES (v_min_event_id+1, \'}\');\n    SET @query = CONCAT(\'SELECT event FROM tmp_events ORDER BY event_id INTO OUTFILE \'\'\', in_outfile, \'\'\' FIELDS ESCAPED BY \'\'\'\' LINES TERMINATED BY \'\'\'\'\');\n    PREPARE stmt_output FROM @query;\n    EXECUTE stmt_output;\n    DEALLOCATE PREPARE stmt_output;\n    SELECT CONCAT(\'Stack trace written to \', in_outfile) AS \'Info\';\n    SELECT CONCAT(\'dot -Tpdf -o /tmp/stack_\', in_thread_id, \'.pdf \', in_outfile) AS \'Convert to PDF\';\n    SELECT CONCAT(\'dot -Tpng -o /tmp/stack_\', in_thread_id, \'.png \', in_outfile) AS \'Convert to PNG\';\n    DROP TEMPORARY TABLE tmp_events;\n    IF (in_auto_setup) THEN\n        CALL sys.ps_setup_reload_saved();\n    END IF;\n    IF (v_this_thread_enabed = \'YES\') THEN\n        CALL sys.ps_setup_enable_thread(CONNECTION_ID());\n    END IF;\n    SET sql_log_bin = @log_bin;\nEND','NONE'),
('sys','ps_setup_reset_to_default','PROCEDURE','ps_setup_reset_to_default','SQL','MODIFIES_SQL_DATA','NO','INVOKER','\n       IN in_verbose BOOLEAN\n    ','','BEGIN\n    SET @query = \'DELETE\n                    FROM performance_schema.setup_actors\n                   WHERE NOT (HOST = \'\'%\'\' AND USER = \'\'%\'\' AND ROLE = \'\'%\'\')\';\n    IF (in_verbose) THEN\n        SELECT CONCAT(\'Resetting: setup_actors\\n\', REPLACE(@query, \'  \', \'\')) AS status;\n    END IF;\n    PREPARE reset_stmt FROM @query;\n    EXECUTE reset_stmt;\n    DEALLOCATE PREPARE reset_stmt;\n    SET @query = \'INSERT IGNORE INTO performance_schema.setup_actors\n                  VALUES (\'\'%\'\', \'\'%\'\', \'\'%\'\', \'\'YES\'\', \'\'YES\'\')\';\n    IF (in_verbose) THEN\n        SELECT CONCAT(\'Resetting: setup_actors\\n\', REPLACE(@query, \'  \', \'\')) AS status;\n    END IF;\n    PREPARE reset_stmt FROM @query;\n    EXECUTE reset_stmt;\n    DEALLOCATE PREPARE reset_stmt;\n    SET @query = \'UPDATE performance_schema.setup_instruments\n                     SET ENABLED = sys.ps_is_instrument_default_enabled(NAME),\n                         TIMED   = sys.ps_is_instrument_default_timed(NAME)\';\n    IF (in_verbose) THEN\n        SELECT CONCAT(\'Resetting: setup_instruments\\n\', REPLACE(@query, \'  \', \'\')) AS status;\n    END IF;\n    PREPARE reset_stmt FROM @query;\n    EXECUTE reset_stmt;\n    DEALLOCATE PREPARE reset_stmt;\n    SET @query = \'UPDATE performance_schema.setup_consumers\n                     SET ENABLED = IF(NAME IN (\'\'events_statements_current\'\', \'\'events_transactions_current\'\', \'\'global_instrumentation\'\', \'\'thread_instrumentation\'\', \'\'statements_digest\'\'), \'\'YES\'\', \'\'NO\'\')\';\n    IF (in_verbose) THEN\n        SELECT CONCAT(\'Resetting: setup_consumers\\n\', REPLACE(@query, \'  \', \'\')) AS status;\n    END IF;\n    PREPARE reset_stmt FROM @query;\n    EXECUTE reset_stmt;\n    DEALLOCATE PREPARE reset_stmt;\n    SET @query = \'DELETE\n                    FROM performance_schema.setup_objects\n                   WHERE NOT (OBJECT_TYPE IN (\'\'EVENT\'\', \'\'FUNCTION\'\', \'\'PROCEDURE\'\', \'\'TABLE\'\', \'\'TRIGGER\'\') AND OBJECT_NAME = \'\'%\'\'\n                     AND (OBJECT_SCHEMA = \'\'mysql\'\'              AND ENABLED = \'\'NO\'\'  AND TIMED = \'\'NO\'\' )\n                      OR (OBJECT_SCHEMA = \'\'performance_schema\'\' AND ENABLED = \'\'NO\'\'  AND TIMED = \'\'NO\'\' )\n                      OR (OBJECT_SCHEMA = \'\'information_schema\'\' AND ENABLED = \'\'NO\'\'  AND TIMED = \'\'NO\'\' )\n                      OR (OBJECT_SCHEMA = \'\'%\'\'                  AND ENABLED = \'\'YES\'\' AND TIMED = \'\'YES\'\'))\';\n    IF (in_verbose) THEN\n        SELECT CONCAT(\'Resetting: setup_objects\\n\', REPLACE(@query, \'  \', \'\')) AS status;\n    END IF;\n    PREPARE reset_stmt FROM @query;\n    EXECUTE reset_stmt;\n    DEALLOCATE PREPARE reset_stmt;\n    SET @query = \'INSERT IGNORE INTO performance_schema.setup_objects\n                  VALUES (\'\'EVENT\'\'    , \'\'mysql\'\'             , \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\n                         (\'\'EVENT\'\'    , \'\'performance_schema\'\', \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\n                         (\'\'EVENT\'\'    , \'\'information_schema\'\', \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\n                         (\'\'EVENT\'\'    , \'\'%\'\'                 , \'\'%\'\', \'\'YES\'\', \'\'YES\'\'),\n                         (\'\'FUNCTION\'\' , \'\'mysql\'\'             , \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\n                         (\'\'FUNCTION\'\' , \'\'performance_schema\'\', \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\n                         (\'\'FUNCTION\'\' , \'\'information_schema\'\', \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\n                         (\'\'FUNCTION\'\' , \'\'%\'\'                 , \'\'%\'\', \'\'YES\'\', \'\'YES\'\'),\n                         (\'\'PROCEDURE\'\', \'\'mysql\'\'             , \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\n                         (\'\'PROCEDURE\'\', \'\'performance_schema\'\', \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\n                         (\'\'PROCEDURE\'\', \'\'information_schema\'\', \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\n                         (\'\'PROCEDURE\'\', \'\'%\'\'                 , \'\'%\'\', \'\'YES\'\', \'\'YES\'\'),\n                         (\'\'TABLE\'\'    , \'\'mysql\'\'             , \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\n                         (\'\'TABLE\'\'    , \'\'performance_schema\'\', \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\n                         (\'\'TABLE\'\'    , \'\'information_schema\'\', \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\n                         (\'\'TABLE\'\'    , \'\'%\'\'                 , \'\'%\'\', \'\'YES\'\', \'\'YES\'\'),\n                         (\'\'TRIGGER\'\'  , \'\'mysql\'\'             , \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\n                         (\'\'TRIGGER\'\'  , \'\'performance_schema\'\', \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\n                         (\'\'TRIGGER\'\'  , \'\'information_schema\'\', \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\n                         (\'\'TRIGGER\'\'  , \'\'%\'\'                 , \'\'%\'\', \'\'YES\'\', \'\'YES\'\')\';\n    IF (in_verbose) THEN\n        SELECT CONCAT(\'Resetting: setup_objects\\n\', REPLACE(@query, \'  \', \'\')) AS status;\n    END IF;\n    PREPARE reset_stmt FROM @query;\n    EXECUTE reset_stmt;\n    DEALLOCATE PREPARE reset_stmt;\n    SET @query = \'UPDATE performance_schema.threads\n                     SET INSTRUMENTED = \'\'YES\'\'\';\n    IF (in_verbose) THEN\n        SELECT CONCAT(\'Resetting: threads\\n\', REPLACE(@query, \'  \', \'\')) AS status;\n    END IF;\n    PREPARE reset_stmt FROM @query;\n    EXECUTE reset_stmt;\n    DEALLOCATE PREPARE reset_stmt;\nEND','mariadb.sys@localhost','2024-02-11 05:51:13','2024-02-11 05:51:13','','\n             Description\n             Resets the Performance Schema setup to the default settings.\n             Parameters\n             in_verbose (BOOLEAN):\n               Whether to print each setup stage (including the SQL) whilst running.\n             Example\n             mysql> CALL sys.ps_setup_reset_to_default(true)\\G\n             *************************** 1. row ***************************\n             status: Resetting: setup_actors\n             DELETE\n             FROM performance_schema.setup_actors\n              WHERE NOT (HOST = \'%\' AND USER = \'%\' AND ROLE = \'%\')\n             1 row in set (0.00 sec)\n             *************************** 1. row ***************************\n             status: Resetting: setup_actors\n             INSERT IGNORE INTO performance_schema.setup_actors\n             VALUES (\'%\', \'%\', \'%\')\n             1 row in set (0.00 sec)\n             ...\n             mysql> CALL sys.ps_setup_reset_to_default(false)\\G\n             Query OK, 0 rows affected (0.00 sec)\n            ','utf8mb3','utf8mb3_general_ci','utf8mb3_general_ci','BEGIN\n    SET @query = \'DELETE\\n                    FROM performance_schema.setup_actors\\n                   WHERE NOT (HOST = \'\'%\'\' AND USER = \'\'%\'\' AND ROLE = \'\'%\'\')\';\n    IF (in_verbose) THEN\n        SELECT CONCAT(\'Resetting: setup_actors\\n\', REPLACE(@query, \'  \', \'\')) AS status;\n    END IF;\n    PREPARE reset_stmt FROM @query;\n    EXECUTE reset_stmt;\n    DEALLOCATE PREPARE reset_stmt;\n    SET @query = \'INSERT IGNORE INTO performance_schema.setup_actors\\n                  VALUES (\'\'%\'\', \'\'%\'\', \'\'%\'\', \'\'YES\'\', \'\'YES\'\')\';\n    IF (in_verbose) THEN\n        SELECT CONCAT(\'Resetting: setup_actors\\n\', REPLACE(@query, \'  \', \'\')) AS status;\n    END IF;\n    PREPARE reset_stmt FROM @query;\n    EXECUTE reset_stmt;\n    DEALLOCATE PREPARE reset_stmt;\n    SET @query = \'UPDATE performance_schema.setup_instruments\\n                     SET ENABLED = sys.ps_is_instrument_default_enabled(NAME),\\n                         TIMED   = sys.ps_is_instrument_default_timed(NAME)\';\n    IF (in_verbose) THEN\n        SELECT CONCAT(\'Resetting: setup_instruments\\n\', REPLACE(@query, \'  \', \'\')) AS status;\n    END IF;\n    PREPARE reset_stmt FROM @query;\n    EXECUTE reset_stmt;\n    DEALLOCATE PREPARE reset_stmt;\n    SET @query = \'UPDATE performance_schema.setup_consumers\\n                     SET ENABLED = IF(NAME IN (\'\'events_statements_current\'\', \'\'events_transactions_current\'\', \'\'global_instrumentation\'\', \'\'thread_instrumentation\'\', \'\'statements_digest\'\'), \'\'YES\'\', \'\'NO\'\')\';\n    IF (in_verbose) THEN\n        SELECT CONCAT(\'Resetting: setup_consumers\\n\', REPLACE(@query, \'  \', \'\')) AS status;\n    END IF;\n    PREPARE reset_stmt FROM @query;\n    EXECUTE reset_stmt;\n    DEALLOCATE PREPARE reset_stmt;\n    SET @query = \'DELETE\\n                    FROM performance_schema.setup_objects\\n                   WHERE NOT (OBJECT_TYPE IN (\'\'EVENT\'\', \'\'FUNCTION\'\', \'\'PROCEDURE\'\', \'\'TABLE\'\', \'\'TRIGGER\'\') AND OBJECT_NAME = \'\'%\'\'\\n                     AND (OBJECT_SCHEMA = \'\'mysql\'\'              AND ENABLED = \'\'NO\'\'  AND TIMED = \'\'NO\'\' )\\n                      OR (OBJECT_SCHEMA = \'\'performance_schema\'\' AND ENABLED = \'\'NO\'\'  AND TIMED = \'\'NO\'\' )\\n                      OR (OBJECT_SCHEMA = \'\'information_schema\'\' AND ENABLED = \'\'NO\'\'  AND TIMED = \'\'NO\'\' )\\n                      OR (OBJECT_SCHEMA = \'\'%\'\'                  AND ENABLED = \'\'YES\'\' AND TIMED = \'\'YES\'\'))\';\n    IF (in_verbose) THEN\n        SELECT CONCAT(\'Resetting: setup_objects\\n\', REPLACE(@query, \'  \', \'\')) AS status;\n    END IF;\n    PREPARE reset_stmt FROM @query;\n    EXECUTE reset_stmt;\n    DEALLOCATE PREPARE reset_stmt;\n    SET @query = \'INSERT IGNORE INTO performance_schema.setup_objects\\n                  VALUES (\'\'EVENT\'\'    , \'\'mysql\'\'             , \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\\n                         (\'\'EVENT\'\'    , \'\'performance_schema\'\', \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\\n                         (\'\'EVENT\'\'    , \'\'information_schema\'\', \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\\n                         (\'\'EVENT\'\'    , \'\'%\'\'                 , \'\'%\'\', \'\'YES\'\', \'\'YES\'\'),\\n                         (\'\'FUNCTION\'\' , \'\'mysql\'\'             , \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\\n                         (\'\'FUNCTION\'\' , \'\'performance_schema\'\', \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\\n                         (\'\'FUNCTION\'\' , \'\'information_schema\'\', \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\\n                         (\'\'FUNCTION\'\' , \'\'%\'\'                 , \'\'%\'\', \'\'YES\'\', \'\'YES\'\'),\\n                         (\'\'PROCEDURE\'\', \'\'mysql\'\'             , \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\\n                         (\'\'PROCEDURE\'\', \'\'performance_schema\'\', \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\\n                         (\'\'PROCEDURE\'\', \'\'information_schema\'\', \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\\n                         (\'\'PROCEDURE\'\', \'\'%\'\'                 , \'\'%\'\', \'\'YES\'\', \'\'YES\'\'),\\n                         (\'\'TABLE\'\'    , \'\'mysql\'\'             , \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\\n                         (\'\'TABLE\'\'    , \'\'performance_schema\'\', \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\\n                         (\'\'TABLE\'\'    , \'\'information_schema\'\', \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\\n                         (\'\'TABLE\'\'    , \'\'%\'\'                 , \'\'%\'\', \'\'YES\'\', \'\'YES\'\'),\\n                         (\'\'TRIGGER\'\'  , \'\'mysql\'\'             , \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\\n                         (\'\'TRIGGER\'\'  , \'\'performance_schema\'\', \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\\n                         (\'\'TRIGGER\'\'  , \'\'information_schema\'\', \'\'%\'\', \'\'NO\'\' , \'\'NO\'\' ),\\n                         (\'\'TRIGGER\'\'  , \'\'%\'\'                 , \'\'%\'\', \'\'YES\'\', \'\'YES\'\')\';\n    IF (in_verbose) THEN\n        SELECT CONCAT(\'Resetting: setup_objects\\n\', REPLACE(@query, \'  \', \'\')) AS status;\n    END IF;\n    PREPARE reset_stmt FROM @query;\n    EXECUTE reset_stmt;\n    DEALLOCATE PREPARE reset_stmt;\n    SET @query = \'UPDATE performance_schema.threads\\n                     SET INSTRUMENTED = \'\'YES\'\'\';\n    IF (in_verbose) THEN\n        SELECT CONCAT(\'Resetting: threads\\n\', REPLACE(@query, \'  \', \'\')) AS status;\n    END IF;\n    PREPARE reset_stmt FROM @query;\n    EXECUTE reset_stmt;\n    DEALLOCATE PREPARE reset_stmt;\nEND','NONE'),
('sys','ps_setup_show_disabled_instruments','PROCEDURE','ps_setup_show_disabled_instruments','SQL','READS_SQL_DATA','YES','INVOKER','','','BEGIN\n    SELECT name AS disabled_instruments, timed\n      FROM performance_schema.setup_instruments\n     WHERE enabled = \'NO\'\n     ORDER BY disabled_instruments;\nEND','mariadb.sys@localhost','2024-02-11 05:51:13','2024-02-11 05:51:13','','\n             Description\n             Shows all currently disabled instruments.\n             Parameters\n             None\n             Example\n             mysql> CALL sys.ps_setup_show_disabled_instruments();\n            ','utf8mb3','utf8mb3_general_ci','utf8mb3_general_ci','BEGIN\n    SELECT name AS disabled_instruments, timed\n      FROM performance_schema.setup_instruments\n     WHERE enabled = \'NO\'\n     ORDER BY disabled_instruments;\nEND','NONE'),
('sys','format_time','FUNCTION','format_time','SQL','NO_SQL','YES','INVOKER','picoseconds TEXT\n    ','text CHARSET utf8mb3 COLLATE utf8mb3_general_ci','BEGIN\n  IF picoseconds IS NULL THEN RETURN NULL;\n  ELSEIF picoseconds >= 604800000000000000 THEN RETURN CONCAT(ROUND(picoseconds / 604800000000000000, 2), \' w\');\n  ELSEIF picoseconds >= 86400000000000000 THEN RETURN CONCAT(ROUND(picoseconds / 86400000000000000, 2), \' d\');\n  ELSEIF picoseconds >= 3600000000000000 THEN RETURN CONCAT(ROUND(picoseconds / 3600000000000000, 2), \' h\');\n  ELSEIF picoseconds >= 60000000000000 THEN RETURN CONCAT(ROUND(picoseconds / 60000000000000, 2), \' m\');\n  ELSEIF picoseconds >= 1000000000000 THEN RETURN CONCAT(ROUND(picoseconds / 1000000000000, 2), \' s\');\n  ELSEIF picoseconds >= 1000000000 THEN RETURN CONCAT(ROUND(picoseconds / 1000000000, 2), \' ms\');\n  ELSEIF picoseconds >= 1000000 THEN RETURN CONCAT(ROUND(picoseconds / 1000000, 2), \' us\');\n  ELSEIF picoseconds >= 1000 THEN RETURN CONCAT(ROUND(picoseconds / 1000, 2), \' ns\');\n  ELSE RETURN CONCAT(picoseconds, \' ps\');\n  END IF;\nEND','mariadb.sys@localhost','2024-02-11 05:51:12','2024-02-11 05:51:12','','\n             Description\n             Takes a raw picoseconds value, and converts it to a human readable form.\n             Picoseconds are the precision that all latency values are printed in\n             within Performance Schema, however are not user friendly when wanting\n             to scan output from the command line.\n             Parameters\n             picoseconds (TEXT):\n               The raw picoseconds value to convert.\n             Returns\n             TEXT\n             Example\n             mysql> select format_time(342342342342345);\n             +------------------------------+\n             | format_time(342342342342345) |\n             +------------------------------+\n             | 00:05:42                     |\n             +------------------------------+\n             1 row in set (0.00 sec)\n             mysql> select format_time(342342342);\n             +------------------------+\n             | format_time(342342342) |\n             +------------------------+\n             | 342.34 us              |\n             +------------------------+\n             1 row in set (0.00 sec)\n             mysql> select format_time(34234);\n              +--------------------+\n             | format_time(34234) |\n             +--------------------+\n             | 34.23 ns           |\n             +--------------------+\n             1 row in set (0.00 sec)\n            ','utf8mb3','utf8mb3_general_ci','utf8mb3_general_ci','BEGIN\n  IF picoseconds IS NULL THEN RETURN NULL;\n  ELSEIF picoseconds >= 604800000000000000 THEN RETURN CONCAT(ROUND(picoseconds / 604800000000000000, 2), \' w\');\n  ELSEIF picoseconds >= 86400000000000000 THEN RETURN CONCAT(ROUND(picoseconds / 86400000000000000, 2), \' d\');\n  ELSEIF picoseconds >= 3600000000000000 THEN RETURN CONCAT(ROUND(picoseconds / 3600000000000000, 2), \' h\');\n  ELSEIF picoseconds >= 60000000000000 THEN RETURN CONCAT(ROUND(picoseconds / 60000000000000, 2), \' m\');\n  ELSEIF picoseconds >= 1000000000000 THEN RETURN CONCAT(ROUND(picoseconds / 1000000000000, 2), \' s\');\n  ELSEIF picoseconds >= 1000000000 THEN RETURN CONCAT(ROUND(picoseconds / 1000000000, 2), \' ms\');\n  ELSEIF picoseconds >= 1000000 THEN RETURN CONCAT(ROUND(picoseconds / 1000000, 2), \' us\');\n  ELSEIF picoseconds >= 1000 THEN RETURN CONCAT(ROUND(picoseconds / 1000, 2), \' ns\');\n  ELSE RETURN CONCAT(picoseconds, \' ps\');\n  END IF;\nEND','NONE'),
('sys','list_drop','FUNCTION','list_drop','SQL','CONTAINS_SQL','YES','INVOKER','in_list TEXT,\n        in_drop_value TEXT\n    ','text CHARSET utf8mb3 COLLATE utf8mb3_general_ci','BEGIN\n    IF (in_drop_value IS NULL) THEN\n        SIGNAL SQLSTATE \'02200\'\n           SET MESSAGE_TEXT = \'Function sys.list_drop: in_drop_value input variable should not be NULL\',\n               MYSQL_ERRNO = 1138;\n    END IF;\n    IF (in_list IS NULL OR LENGTH(in_list) = 0) THEN\n        RETURN in_list;\n    END IF;\n    RETURN (SELECT TRIM(BOTH \',\' FROM REPLACE(REPLACE(CONCAT(\',\', in_list), CONCAT(\',\', in_drop_value), \'\'), CONCAT(\', \', in_drop_value), \'\')));\nEND','mariadb.sys@localhost','2024-02-11 05:51:12','2024-02-11 05:51:12','','\n             Description\n             Takes a list, and a value to attempt to remove from the list, and returns the resulting list.\n             Useful for altering certain session variables, like sql_mode or optimizer_switch for instance.\n             Parameters\n             in_list (TEXT):\n               The comma separated list to drop a value from\n             in_drop_value (TEXT):\n               The value to drop from the input list\n             Returns\n             TEXT\n             Example\n             mysql> select @@sql_mode;\n             +-----------------------------------------------------------------------------------------------+\n             | @@sql_mode                                                                                    |\n             +-----------------------------------------------------------------------------------------------+\n             | ANSI_QUOTES,ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |\n             +-----------------------------------------------------------------------------------------------+\n             1 row in set (0.00 sec)\n             mysql> set sql_mode = sys.list_drop(@@sql_mode, \'ONLY_FULL_GROUP_BY\');\n             Query OK, 0 rows affected (0.03 sec)\n             mysql> select @@sql_mode;\n             +----------------------------------------------------------------------------+\n             | @@sql_mode                                                                 |\n             +----------------------------------------------------------------------------+\n             | ANSI_QUOTES,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |\n             +----------------------------------------------------------------------------+\n             1 row in set (0.00 sec)\n            ','utf8mb3','utf8mb3_general_ci','utf8mb3_general_ci','BEGIN\n    IF (in_drop_value IS NULL) THEN\n        SIGNAL SQLSTATE \'02200\'\n           SET MESSAGE_TEXT = \'Function sys.list_drop: in_drop_value input variable should not be NULL\',\n               MYSQL_ERRNO = 1138;\n    END IF;\n    IF (in_list IS NULL OR LENGTH(in_list) = 0) THEN\n        RETURN in_list;\n    END IF;\n    RETURN (SELECT TRIM(BOTH \',\' FROM REPLACE(REPLACE(CONCAT(\',\', in_list), CONCAT(\',\', in_drop_value), \'\'), CONCAT(\', \', in_drop_value), \'\')));\nEND','NONE'),
('sys','ps_setup_show_enabled_instruments','PROCEDURE','ps_setup_show_enabled_instruments','SQL','READS_SQL_DATA','YES','INVOKER','','','BEGIN\n    SELECT name AS enabled_instruments, timed\n      FROM performance_schema.setup_instruments\n     WHERE enabled = \'YES\'\n     ORDER BY enabled_instruments;\nEND','mariadb.sys@localhost','2024-02-11 05:51:13','2024-02-11 05:51:13','','\n             Description\n             Shows all currently enabled instruments.\n             Parameters\n             None\n             Example\n             mysql> CALL sys.ps_setup_show_enabled_instruments();\n            ','utf8mb3','utf8mb3_general_ci','utf8mb3_general_ci','BEGIN\n    SELECT name AS enabled_instruments, timed\n      FROM performance_schema.setup_instruments\n     WHERE enabled = \'YES\'\n     ORDER BY enabled_instruments;\nEND','NONE'),
('sys','statement_performance_analyzer','PROCEDURE','statement_performance_analyzer','SQL','CONTAINS_SQL','NO','INVOKER','\n        IN in_action ENUM(\'snapshot\', \'overall\', \'delta\', \'create_table\', \'create_tmp\', \'save\', \'cleanup\'),\n        IN in_table VARCHAR(129),\n        IN in_views SET (\'with_runtimes_in_95th_percentile\', \'analysis\', \'with_errors_or_warnings\', \'with_full_table_scans\', \'with_sorting\', \'with_temp_tables\', \'custom\')\n    ','','BEGIN\n    DECLARE v_table_exists, v_tmp_digests_table_exists, v_custom_view_exists ENUM(\'\', \'BASE TABLE\', \'VIEW\', \'TEMPORARY\') DEFAULT \'\';\n    DECLARE v_this_thread_enabled ENUM(\'YES\', \'NO\');\n    DECLARE v_force_new_snapshot BOOLEAN DEFAULT FALSE;\n    DECLARE v_digests_table VARCHAR(133);\n    DECLARE v_quoted_table, v_quoted_custom_view VARCHAR(133) DEFAULT \'\';\n    DECLARE v_table_db, v_table_name, v_custom_db, v_custom_name VARCHAR(64);\n    DECLARE v_digest_table_template, v_checksum_ref, v_checksum_table text;\n    DECLARE v_sql longtext;\n    DECLARE v_error_msg VARCHAR(128);\n    SELECT INSTRUMENTED INTO v_this_thread_enabled FROM performance_schema.threads WHERE PROCESSLIST_ID = CONNECTION_ID();\n    IF (v_this_thread_enabled = \'YES\') THEN\n        CALL sys.ps_setup_disable_thread(CONNECTION_ID());\n    END IF;\n    SET @log_bin := @@sql_log_bin;\n    IF (@log_bin = 1) THEN\n        SET sql_log_bin = 0;\n    END IF;\n    IF (@sys.statement_performance_analyzer.limit IS NULL) THEN\n        SET @sys.statement_performance_analyzer.limit = sys.sys_get_config(\'statement_performance_analyzer.limit\', \'100\');\n    END IF;\n    IF (@sys.debug IS NULL) THEN\n        SET @sys.debug                                = sys.sys_get_config(\'debug\'                               , \'OFF\');\n    END IF;\n    IF (in_table = \'NOW()\') THEN\n        SET v_force_new_snapshot = TRUE,\n            in_table             = NULL;\n    ELSEIF (in_table IS NOT NULL) THEN\n        IF (NOT INSTR(in_table, \'.\')) THEN\n            SET v_table_db   = DATABASE(),\n                v_table_name = in_table;\n        ELSE\n            SET v_table_db   = SUBSTRING_INDEX(in_table, \'.\', 1);\n            SET v_table_name = SUBSTRING(in_table, CHAR_LENGTH(v_table_db)+2);\n        END IF;\n        SET v_quoted_table = CONCAT(\'`\', v_table_db, \'`.`\', v_table_name, \'`\');\n        IF (@sys.debug = \'ON\') THEN\n            SELECT CONCAT(\'in_table is: db = \'\'\', v_table_db, \'\'\', table = \'\'\', v_table_name, \'\'\'\') AS \'Debug\';\n        END IF;\n        IF (v_table_db = DATABASE() AND (v_table_name = \'tmp_digests\' OR v_table_name = \'tmp_digests_delta\')) THEN\n            SET v_error_msg = CONCAT(\'Invalid value for in_table: \', v_quoted_table, \' is reserved table name.\');\n            SIGNAL SQLSTATE \'45000\'\n               SET MESSAGE_TEXT = v_error_msg;\n        END IF;\n        CALL sys.table_exists(v_table_db, v_table_name, v_table_exists);\n        IF (@sys.debug = \'ON\') THEN\n            SELECT CONCAT(\'v_table_exists = \', v_table_exists) AS \'Debug\';\n        END IF;\n        IF (v_table_exists = \'BASE TABLE\') THEN\n            SET v_checksum_ref = (\n                 SELECT GROUP_CONCAT(CONCAT(COLUMN_NAME, COLUMN_TYPE) ORDER BY ORDINAL_POSITION) AS Checksum\n                   FROM information_schema.COLUMNS\n                  WHERE TABLE_SCHEMA = \'performance_schema\' AND TABLE_NAME = \'events_statements_summary_by_digest\'\n                ),\n                v_checksum_table = (\n                 SELECT GROUP_CONCAT(CONCAT(COLUMN_NAME, COLUMN_TYPE) ORDER BY ORDINAL_POSITION) AS Checksum\n                   FROM information_schema.COLUMNS\n                  WHERE TABLE_SCHEMA = v_table_db AND TABLE_NAME = v_table_name\n                );\n            IF (v_checksum_ref <> v_checksum_table) THEN\n                SET v_error_msg = CONCAT(\'The table \',\n                                         IF(CHAR_LENGTH(v_quoted_table) > 93, CONCAT(\'...\', SUBSTRING(v_quoted_table, -90)), v_quoted_table),\n                                         \' has the wrong definition.\');\n                SIGNAL SQLSTATE \'45000\'\n                   SET MESSAGE_TEXT = v_error_msg;\n            END IF;\n        END IF;\n    END IF;\n    IF (in_views IS NULL OR in_views = \'\') THEN\n        SET in_views = \'with_runtimes_in_95th_percentile,analysis,with_errors_or_warnings,with_full_table_scans,with_sorting,with_temp_tables\';\n    END IF;\n    CALL sys.table_exists(DATABASE(), \'tmp_digests\', v_tmp_digests_table_exists);\n    IF (@sys.debug = \'ON\') THEN\n        SELECT CONCAT(\'v_tmp_digests_table_exists = \', v_tmp_digests_table_exists) AS \'Debug\';\n    END IF;\n    CASE\n        WHEN in_action IN (\'snapshot\', \'overall\') THEN\n            IF (in_table IS NOT NULL) THEN\n                IF (NOT v_table_exists IN (\'TEMPORARY\', \'BASE TABLE\')) THEN\n                    SET v_error_msg = CONCAT(\'The \', in_action, \' action requires in_table to be NULL, NOW() or specify an existing table.\',\n                                             \' The table \',\n                                             IF(CHAR_LENGTH(v_quoted_table) > 16, CONCAT(\'...\', SUBSTRING(v_quoted_table, -13)), v_quoted_table),\n                                             \' does not exist.\');\n                    SIGNAL SQLSTATE \'45000\'\n                       SET MESSAGE_TEXT = v_error_msg;\n                END IF;\n            END IF;\n        WHEN in_action IN (\'delta\', \'save\') THEN\n            IF (v_table_exists NOT IN (\'TEMPORARY\', \'BASE TABLE\')) THEN\n                SET v_error_msg = CONCAT(\'The \', in_action, \' action requires in_table to be an existing table.\',\n                                         IF(in_table IS NOT NULL, CONCAT(\' The table \',\n                                             IF(CHAR_LENGTH(v_quoted_table) > 39, CONCAT(\'...\', SUBSTRING(v_quoted_table, -36)), v_quoted_table),\n                                             \' does not exist.\'), \'\'));\n                SIGNAL SQLSTATE \'45000\'\n                   SET MESSAGE_TEXT = v_error_msg;\n            END IF;\n            IF (in_action = \'delta\' AND v_tmp_digests_table_exists <> \'TEMPORARY\') THEN\n                SIGNAL SQLSTATE \'45000\'\n                   SET MESSAGE_TEXT = \'An existing snapshot generated with the statement_performance_analyzer() must exist.\';\n            END IF;\n        WHEN in_action = \'create_tmp\' THEN\n            IF (v_table_exists = \'TEMPORARY\') THEN\n                SET v_error_msg = CONCAT(\'Cannot create the table \',\n                                         IF(CHAR_LENGTH(v_quoted_table) > 72, CONCAT(\'...\', SUBSTRING(v_quoted_table, -69)), v_quoted_table),\n                                         \' as it already exists.\');\n                SIGNAL SQLSTATE \'45000\'\n                   SET MESSAGE_TEXT = v_error_msg;\n            END IF;\n        WHEN in_action = \'create_table\' THEN\n            IF (v_table_exists <> \'\') THEN\n                SET v_error_msg = CONCAT(\'Cannot create the table \',\n                                         IF(CHAR_LENGTH(v_quoted_table) > 52, CONCAT(\'...\', SUBSTRING(v_quoted_table, -49)), v_quoted_table),\n                                         \' as it already exists\',\n                                         IF(v_table_exists = \'TEMPORARY\', \' as a temporary table.\', \'.\'));\n                SIGNAL SQLSTATE \'45000\'\n                   SET MESSAGE_TEXT = v_error_msg;\n            END IF;\n        WHEN in_action = \'cleanup\' THEN\n            DO (SELECT 1);\n        ELSE\n            SIGNAL SQLSTATE \'45000\'\n               SET MESSAGE_TEXT = \'Unknown action. Supported actions are: cleanup, create_table, create_tmp, delta, overall, save, snapshot\';\n    END CASE;\n    SET v_digest_table_template = \'CREATE %{TEMPORARY}TABLE %{TABLE_NAME} (\n  `SCHEMA_NAME` varchar(64) DEFAULT NULL,\n  `DIGEST` varchar(32) DEFAULT NULL,\n  `DIGEST_TEXT` longtext,\n  `COUNT_STAR` bigint(20) unsigned NOT NULL,\n  `SUM_TIMER_WAIT` bigint(20) unsigned NOT NULL,\n  `MIN_TIMER_WAIT` bigint(20) unsigned NOT NULL,\n  `AVG_TIMER_WAIT` bigint(20) unsigned NOT NULL,\n  `MAX_TIMER_WAIT` bigint(20) unsigned NOT NULL,\n  `SUM_LOCK_TIME` bigint(20) unsigned NOT NULL,\n  `SUM_ERRORS` bigint(20) unsigned NOT NULL,\n  `SUM_WARNINGS` bigint(20) unsigned NOT NULL,\n  `SUM_ROWS_AFFECTED` bigint(20) unsigned NOT NULL,\n  `SUM_ROWS_SENT` bigint(20) unsigned NOT NULL,\n  `SUM_ROWS_EXAMINED` bigint(20) unsigned NOT NULL,\n  `SUM_CREATED_TMP_DISK_TABLES` bigint(20) unsigned NOT NULL,\n  `SUM_CREATED_TMP_TABLES` bigint(20) unsigned NOT NULL,\n  `SUM_SELECT_FULL_JOIN` bigint(20) unsigned NOT NULL,\n  `SUM_SELECT_FULL_RANGE_JOIN` bigint(20) unsigned NOT NULL,\n  `SUM_SELECT_RANGE` bigint(20) unsigned NOT NULL,\n  `SUM_SELECT_RANGE_CHECK` bigint(20) unsigned NOT NULL,\n  `SUM_SELECT_SCAN` bigint(20) unsigned NOT NULL,\n  `SUM_SORT_MERGE_PASSES` bigint(20) unsigned NOT NULL,\n  `SUM_SORT_RANGE` bigint(20) unsigned NOT NULL,\n  `SUM_SORT_ROWS` bigint(20) unsigned NOT NULL,\n  `SUM_SORT_SCAN` bigint(20) unsigned NOT NULL,\n  `SUM_NO_INDEX_USED` bigint(20) unsigned NOT NULL,\n  `SUM_NO_GOOD_INDEX_USED` bigint(20) unsigned NOT NULL,\n  `FIRST_SEEN` timestamp NULL DEFAULT NULL,\n  `LAST_SEEN` timestamp NULL DEFAULT NULL,\n  INDEX (SCHEMA_NAME, DIGEST)\n) DEFAULT CHARSET=utf8\';\n    IF (v_force_new_snapshot\n           OR in_action = \'snapshot\'\n           OR (in_action = \'overall\' AND in_table IS NULL)\n           OR (in_action = \'save\' AND v_tmp_digests_table_exists <> \'TEMPORARY\')\n       ) THEN\n        IF (v_tmp_digests_table_exists = \'TEMPORARY\') THEN\n            IF (@sys.debug = \'ON\') THEN\n                SELECT \'DROP TEMPORARY TABLE IF EXISTS tmp_digests\' AS \'Debug\';\n            END IF;\n            DROP TEMPORARY TABLE IF EXISTS tmp_digests;\n        END IF;\n        CALL sys.execute_prepared_stmt(REPLACE(REPLACE(v_digest_table_template, \'%{TEMPORARY}\', \'TEMPORARY \'), \'%{TABLE_NAME}\', \'tmp_digests\'));\n        SET v_sql = CONCAT(\'INSERT INTO tmp_digests SELECT * FROM \',\n                           IF(in_table IS NULL OR in_action = \'save\', \'performance_schema.events_statements_summary_by_digest\', v_quoted_table));\n        CALL sys.execute_prepared_stmt(v_sql);\n    END IF;\n    IF (in_action IN (\'create_table\', \'create_tmp\')) THEN\n        IF (in_action = \'create_table\') THEN\n            CALL sys.execute_prepared_stmt(REPLACE(REPLACE(v_digest_table_template, \'%{TEMPORARY}\', \'\'), \'%{TABLE_NAME}\', v_quoted_table));\n        ELSE\n            CALL sys.execute_prepared_stmt(REPLACE(REPLACE(v_digest_table_template, \'%{TEMPORARY}\', \'TEMPORARY \'), \'%{TABLE_NAME}\', v_quoted_table));\n        END IF;\n    ELSEIF (in_action = \'save\') THEN\n        CALL sys.execute_prepared_stmt(CONCAT(\'DELETE FROM \', v_quoted_table));\n        CALL sys.execute_prepared_stmt(CONCAT(\'INSERT INTO \', v_quoted_table, \' SELECT * FROM tmp_digests\'));\n    ELSEIF (in_action = \'cleanup\') THEN\n        DROP TEMPORARY TABLE IF EXISTS sys.tmp_digests;\n        DROP TEMPORARY TABLE IF EXISTS sys.tmp_digests_delta;\n    ELSEIF (in_action IN (\'overall\', \'delta\')) THEN\n        IF (in_action = \'overall\') THEN\n            IF (in_table IS NULL) THEN\n                SET v_digests_table = \'tmp_digests\';\n            ELSE\n                SET v_digests_table = v_quoted_table;\n            END IF;\n        ELSE\n            SET v_digests_table = \'tmp_digests_delta\';\n            DROP TEMPORARY TABLE IF EXISTS tmp_digests_delta;\n            CREATE TEMPORARY TABLE tmp_digests_delta LIKE tmp_digests;\n            SET v_sql = CONCAT(\'INSERT INTO tmp_digests_delta\nSELECT `d_end`.`SCHEMA_NAME`,\n       `d_end`.`DIGEST`,\n       `d_end`.`DIGEST_TEXT`,\n       `d_end`.`COUNT_STAR`-IFNULL(`d_start`.`COUNT_STAR`, 0) AS \'\'COUNT_STAR\'\',\n       `d_end`.`SUM_TIMER_WAIT`-IFNULL(`d_start`.`SUM_TIMER_WAIT`, 0) AS \'\'SUM_TIMER_WAIT\'\',\n       `d_end`.`MIN_TIMER_WAIT` AS \'\'MIN_TIMER_WAIT\'\',\n       IFNULL((`d_end`.`SUM_TIMER_WAIT`-IFNULL(`d_start`.`SUM_TIMER_WAIT`, 0))/NULLIF(`d_end`.`COUNT_STAR`-IFNULL(`d_start`.`COUNT_STAR`, 0), 0), 0) AS \'\'AVG_TIMER_WAIT\'\',\n       `d_end`.`MAX_TIMER_WAIT` AS \'\'MAX_TIMER_WAIT\'\',\n       `d_end`.`SUM_LOCK_TIME`-IFNULL(`d_start`.`SUM_LOCK_TIME`, 0) AS \'\'SUM_LOCK_TIME\'\',\n       `d_end`.`SUM_ERRORS`-IFNULL(`d_start`.`SUM_ERRORS`, 0) AS \'\'SUM_ERRORS\'\',\n       `d_end`.`SUM_WARNINGS`-IFNULL(`d_start`.`SUM_WARNINGS`, 0) AS \'\'SUM_WARNINGS\'\',\n       `d_end`.`SUM_ROWS_AFFECTED`-IFNULL(`d_start`.`SUM_ROWS_AFFECTED`, 0) AS \'\'SUM_ROWS_AFFECTED\'\',\n       `d_end`.`SUM_ROWS_SENT`-IFNULL(`d_start`.`SUM_ROWS_SENT`, 0) AS \'\'SUM_ROWS_SENT\'\',\n       `d_end`.`SUM_ROWS_EXAMINED`-IFNULL(`d_start`.`SUM_ROWS_EXAMINED`, 0) AS \'\'SUM_ROWS_EXAMINED\'\',\n       `d_end`.`SUM_CREATED_TMP_DISK_TABLES`-IFNULL(`d_start`.`SUM_CREATED_TMP_DISK_TABLES`, 0) AS \'\'SUM_CREATED_TMP_DISK_TABLES\'\',\n       `d_end`.`SUM_CREATED_TMP_TABLES`-IFNULL(`d_start`.`SUM_CREATED_TMP_TABLES`, 0) AS \'\'SUM_CREATED_TMP_TABLES\'\',\n       `d_end`.`SUM_SELECT_FULL_JOIN`-IFNULL(`d_start`.`SUM_SELECT_FULL_JOIN`, 0) AS \'\'SUM_SELECT_FULL_JOIN\'\',\n       `d_end`.`SUM_SELECT_FULL_RANGE_JOIN`-IFNULL(`d_start`.`SUM_SELECT_FULL_RANGE_JOIN`, 0) AS \'\'SUM_SELECT_FULL_RANGE_JOIN\'\',\n       `d_end`.`SUM_SELECT_RANGE`-IFNULL(`d_start`.`SUM_SELECT_RANGE`, 0) AS \'\'SUM_SELECT_RANGE\'\',\n       `d_end`.`SUM_SELECT_RANGE_CHECK`-IFNULL(`d_start`.`SUM_SELECT_RANGE_CHECK`, 0) AS \'\'SUM_SELECT_RANGE_CHECK\'\',\n       `d_end`.`SUM_SELECT_SCAN`-IFNULL(`d_start`.`SUM_SELECT_SCAN`, 0) AS \'\'SUM_SELECT_SCAN\'\',\n       `d_end`.`SUM_SORT_MERGE_PASSES`-IFNULL(`d_start`.`SUM_SORT_MERGE_PASSES`, 0) AS \'\'SUM_SORT_MERGE_PASSES\'\',\n       `d_end`.`SUM_SORT_RANGE`-IFNULL(`d_start`.`SUM_SORT_RANGE`, 0) AS \'\'SUM_SORT_RANGE\'\',\n       `d_end`.`SUM_SORT_ROWS`-IFNULL(`d_start`.`SUM_SORT_ROWS`, 0) AS \'\'SUM_SORT_ROWS\'\',\n       `d_end`.`SUM_SORT_SCAN`-IFNULL(`d_start`.`SUM_SORT_SCAN`, 0) AS \'\'SUM_SORT_SCAN\'\',\n       `d_end`.`SUM_NO_INDEX_USED`-IFNULL(`d_start`.`SUM_NO_INDEX_USED`, 0) AS \'\'SUM_NO_INDEX_USED\'\',\n       `d_end`.`SUM_NO_GOOD_INDEX_USED`-IFNULL(`d_start`.`SUM_NO_GOOD_INDEX_USED`, 0) AS \'\'SUM_NO_GOOD_INDEX_USED\'\',\n       `d_end`.`FIRST_SEEN`,\n       `d_end`.`LAST_SEEN`\n  FROM tmp_digests d_end\n       LEFT OUTER JOIN \', v_quoted_table, \' d_start ON `d_start`.`DIGEST` = `d_end`.`DIGEST`\n                                                    AND (`d_start`.`SCHEMA_NAME` = `d_end`.`SCHEMA_NAME`\n                                                          OR (`d_start`.`SCHEMA_NAME` IS NULL AND `d_end`.`SCHEMA_NAME` IS NULL)\n                                                        )\n WHERE `d_end`.`COUNT_STAR`-IFNULL(`d_start`.`COUNT_STAR`, 0) > 0\');\n            CALL sys.execute_prepared_stmt(v_sql);\n        END IF;\n        IF (FIND_IN_SET(\'with_runtimes_in_95th_percentile\', in_views)) THEN\n            SELECT \'Queries with Runtime in 95th Percentile\' AS \'Next Output\';\n            DROP TEMPORARY TABLE IF EXISTS tmp_digest_avg_latency_distribution1;\n            DROP TEMPORARY TABLE IF EXISTS tmp_digest_avg_latency_distribution2;\n            DROP TEMPORARY TABLE IF EXISTS tmp_digest_95th_percentile_by_avg_us;\n            CREATE TEMPORARY TABLE tmp_digest_avg_latency_distribution1 (\n              cnt bigint unsigned NOT NULL,\n              avg_us decimal(21,0) NOT NULL,\n              PRIMARY KEY (avg_us)\n            ) ENGINE=InnoDB;\n            SET v_sql = CONCAT(\'INSERT INTO tmp_digest_avg_latency_distribution1\nSELECT COUNT(*) cnt,\n       ROUND(avg_timer_wait/1000000) AS avg_us\n  FROM \', v_digests_table, \'\n GROUP BY avg_us\');\n            CALL sys.execute_prepared_stmt(v_sql);\n            CREATE TEMPORARY TABLE tmp_digest_avg_latency_distribution2 LIKE tmp_digest_avg_latency_distribution1;\n            INSERT INTO tmp_digest_avg_latency_distribution2 SELECT * FROM tmp_digest_avg_latency_distribution1;\n            CREATE TEMPORARY TABLE tmp_digest_95th_percentile_by_avg_us (\n              avg_us decimal(21,0) NOT NULL,\n              percentile decimal(46,4) NOT NULL,\n              PRIMARY KEY (avg_us)\n            ) ENGINE=InnoDB;\n            SET v_sql = CONCAT(\'INSERT INTO tmp_digest_95th_percentile_by_avg_us\nSELECT s2.avg_us avg_us,\n       IFNULL(SUM(s1.cnt)/NULLIF((SELECT COUNT(*) FROM \', v_digests_table, \'), 0), 0) percentile\n  FROM tmp_digest_avg_latency_distribution1 AS s1\n       JOIN tmp_digest_avg_latency_distribution2 AS s2 ON s1.avg_us <= s2.avg_us\n GROUP BY s2.avg_us\nHAVING percentile > 0.95\n ORDER BY percentile\n LIMIT 1\');\n            CALL sys.execute_prepared_stmt(v_sql);\n            SET v_sql =\n                REPLACE(\n                    REPLACE(\n                        (SELECT VIEW_DEFINITION\n                           FROM information_schema.VIEWS\n                          WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = \'statements_with_runtimes_in_95th_percentile\'\n                        ),\n                        \'`performance_schema`.`events_statements_summary_by_digest`\',\n                        v_digests_table\n                    ),\n                    \'sys.x$ps_digest_95th_percentile_by_avg_us\',\n                    \'`sys`.`x$ps_digest_95th_percentile_by_avg_us`\'\n              );\n            CALL sys.execute_prepared_stmt(v_sql);\n            DROP TEMPORARY TABLE tmp_digest_avg_latency_distribution1;\n            DROP TEMPORARY TABLE tmp_digest_avg_latency_distribution2;\n            DROP TEMPORARY TABLE tmp_digest_95th_percentile_by_avg_us;\n        END IF;\n        IF (FIND_IN_SET(\'analysis\', in_views)) THEN\n            SELECT CONCAT(\'Top \', @sys.statement_performance_analyzer.limit, \' Queries Ordered by Total Latency\') AS \'Next Output\';\n            SET v_sql =\n                REPLACE(\n                    (SELECT VIEW_DEFINITION\n                       FROM information_schema.VIEWS\n                      WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = \'statement_analysis\'\n                    ),\n                    \'`performance_schema`.`events_statements_summary_by_digest`\',\n                    v_digests_table\n                );\n            IF (@sys.statement_performance_analyzer.limit > 0) THEN\n                SET v_sql = CONCAT(v_sql, \' LIMIT \', @sys.statement_performance_analyzer.limit);\n            END IF;\n            CALL sys.execute_prepared_stmt(v_sql);\n        END IF;\n        IF (FIND_IN_SET(\'with_errors_or_warnings\', in_views)) THEN\n            SELECT CONCAT(\'Top \', @sys.statement_performance_analyzer.limit, \' Queries with Errors\') AS \'Next Output\';\n            SET v_sql =\n                REPLACE(\n                    (SELECT VIEW_DEFINITION\n                       FROM information_schema.VIEWS\n                      WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = \'statements_with_errors_or_warnings\'\n                    ),\n                    \'`performance_schema`.`events_statements_summary_by_digest`\',\n                    v_digests_table\n                );\n            IF (@sys.statement_performance_analyzer.limit > 0) THEN\n                SET v_sql = CONCAT(v_sql, \' LIMIT \', @sys.statement_performance_analyzer.limit);\n            END IF;\n            CALL sys.execute_prepared_stmt(v_sql);\n        END IF;\n        IF (FIND_IN_SET(\'with_full_table_scans\', in_views)) THEN\n            SELECT CONCAT(\'Top \', @sys.statement_performance_analyzer.limit, \' Queries with Full Table Scan\') AS \'Next Output\';\n            SET v_sql =\n                REPLACE(\n                    (SELECT VIEW_DEFINITION\n                       FROM information_schema.VIEWS\n                      WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = \'statements_with_full_table_scans\'\n                    ),\n                    \'`performance_schema`.`events_statements_summary_by_digest`\',\n                    v_digests_table\n                );\n            IF (@sys.statement_performance_analyzer.limit > 0) THEN\n                SET v_sql = CONCAT(v_sql, \' LIMIT \', @sys.statement_performance_analyzer.limit);\n            END IF;\n            CALL sys.execute_prepared_stmt(v_sql);\n        END IF;\n        IF (FIND_IN_SET(\'with_sorting\', in_views)) THEN\n            SELECT CONCAT(\'Top \', @sys.statement_performance_analyzer.limit, \' Queries with Sorting\') AS \'Next Output\';\n            SET v_sql =\n                REPLACE(\n                    (SELECT VIEW_DEFINITION\n                       FROM information_schema.VIEWS\n                      WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = \'statements_with_sorting\'\n                    ),\n                    \'`performance_schema`.`events_statements_summary_by_digest`\',\n                    v_digests_table\n                );\n            IF (@sys.statement_performance_analyzer.limit > 0) THEN\n                SET v_sql = CONCAT(v_sql, \' LIMIT \', @sys.statement_performance_analyzer.limit);\n            END IF;\n            CALL sys.execute_prepared_stmt(v_sql);\n        END IF;\n        IF (FIND_IN_SET(\'with_temp_tables\', in_views)) THEN\n            SELECT CONCAT(\'Top \', @sys.statement_performance_analyzer.limit, \' Queries with Internal Temporary Tables\') AS \'Next Output\';\n            SET v_sql =\n                REPLACE(\n                    (SELECT VIEW_DEFINITION\n                       FROM information_schema.VIEWS\n                      WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = \'statements_with_temp_tables\'\n                    ),\n                    \'`performance_schema`.`events_statements_summary_by_digest`\',\n                    v_digests_table\n                );\n            IF (@sys.statement_performance_analyzer.limit > 0) THEN\n                SET v_sql = CONCAT(v_sql, \' LIMIT \', @sys.statement_performance_analyzer.limit);\n            END IF;\n            CALL sys.execute_prepared_stmt(v_sql);\n        END IF;\n        IF (FIND_IN_SET(\'custom\', in_views)) THEN\n            SELECT CONCAT(\'Top \', @sys.statement_performance_analyzer.limit, \' Queries Using Custom View\') AS \'Next Output\';\n            IF (@sys.statement_performance_analyzer.view IS NULL) THEN\n                SET @sys.statement_performance_analyzer.view = sys.sys_get_config(\'statement_performance_analyzer.view\', NULL);\n            END IF;\n            IF (@sys.statement_performance_analyzer.view IS NULL) THEN\n                SIGNAL SQLSTATE \'45000\'\n                   SET MESSAGE_TEXT = \'The @sys.statement_performance_analyzer.view user variable must be set with the view or query to use.\';\n            END IF;\n            IF (NOT INSTR(@sys.statement_performance_analyzer.view, \' \')) THEN\n                IF (NOT INSTR(@sys.statement_performance_analyzer.view, \'.\')) THEN\n                    SET v_custom_db   = DATABASE(),\n                        v_custom_name = @sys.statement_performance_analyzer.view;\n                ELSE\n                    SET v_custom_db   = SUBSTRING_INDEX(@sys.statement_performance_analyzer.view, \'.\', 1);\n                    SET v_custom_name = SUBSTRING(@sys.statement_performance_analyzer.view, CHAR_LENGTH(v_custom_db)+2);\n                END IF;\n                CALL sys.table_exists(v_custom_db, v_custom_name, v_custom_view_exists);\n                IF (v_custom_view_exists <> \'VIEW\') THEN\n                    SIGNAL SQLSTATE \'45000\'\n                       SET MESSAGE_TEXT = \'The @sys.statement_performance_analyzer.view user variable is set but specified neither an existing view nor a query.\';\n                END IF;\n                SET v_sql =\n                    REPLACE(\n                        (SELECT VIEW_DEFINITION\n                           FROM information_schema.VIEWS\n                          WHERE TABLE_SCHEMA = v_custom_db AND TABLE_NAME = v_custom_name\n                        ),\n                        \'`performance_schema`.`events_statements_summary_by_digest`\',\n                        v_digests_table\n                    );\n            ELSE\n                SET v_sql = REPLACE(@sys.statement_performance_analyzer.view, \'`performance_schema`.`events_statements_summary_by_digest`\', v_digests_table);\n            END IF;\n            IF (@sys.statement_performance_analyzer.limit > 0) THEN\n                SET v_sql = CONCAT(v_sql, \' LIMIT \', @sys.statement_performance_analyzer.limit);\n            END IF;\n            CALL sys.execute_prepared_stmt(v_sql);\n        END IF;\n    END IF;\n    IF (v_this_thread_enabled = \'YES\') THEN\n        CALL sys.ps_setup_enable_thread(CONNECTION_ID());\n    END IF;\n    IF (@log_bin = 1) THEN\n        SET sql_log_bin = @log_bin;\n    END IF;\nEND','mariadb.sys@localhost','2024-02-11 05:51:13','2024-02-11 05:51:13','','\n             Description\n             Create a report of the statements running on the server.\n             The views are calculated based on the overall and/or delta activity.\n             Requires the SUPER privilege for \"SET sql_log_bin = 0;\".\n             Parameters\n             in_action (ENUM(\'snapshot\', \'overall\', \'delta\', \'create_tmp\', \'create_table\', \'save\', \'cleanup\')):\n               The action to take. Supported actions are:\n                 * snapshot      Store a snapshot. The default is to make a snapshot of the current content of\n                                 performance_schema.events_statements_summary_by_digest, but by setting in_table\n                                 this can be overwritten to copy the content of the specified table.\n                                 The snapshot is stored in the sys.tmp_digests temporary table.\n                 * overall       Generate analyzis based on the content specified by in_table. For the overall analyzis,\n                                 in_table can be NOW() to use a fresh snapshot. This will overwrite an existing snapshot.\n                                 Use NULL for in_table to use the existing snapshot. If in_table IS NULL and no snapshot\n                                 exists, a new will be created.\n                                 See also in_views and @sys.statement_performance_analyzer.limit.\n                 * delta         Generate a delta analysis. The delta will be calculated between the reference table in\n                                 in_table and the snapshot. An existing snapshot must exist.\n                                 The action uses the sys.tmp_digests_delta temporary table.\n                                 See also in_views and @sys.statement_performance_analyzer.limit.\n                 * create_table  Create a regular table suitable for storing the snapshot for later use, e.g. for\n                                 calculating deltas.\n                 * create_tmp    Create a temporary table suitable for storing the snapshot for later use, e.g. for\n                                 calculating deltas.\n                 * save          Save the snapshot in the table specified by in_table. The table must exists and have\n                                 the correct structure.\n                                 If no snapshot exists, a new is created.\n                 * cleanup       Remove the temporary tables used for the snapshot and delta.\n             in_table (VARCHAR(129)):\n               The table argument used for some actions. Use the format \'db1.t1\' or \'t1\' without using any backticks (`)\n               for quoting. Periods (.) are not supported in the database and table names.\n               The meaning of the table for each action supporting the argument is:\n                 * snapshot      The snapshot is created based on the specified table. Set to NULL or NOW() to use\n                                 the current content of performance_schema.events_statements_summary_by_digest.\n                 * overall       The table with the content to create the overall analyzis for. The following values\n                                 can be used:\n                                   - A table name - use the content of that table.\n                                   - NOW()        - create a fresh snapshot and overwrite the existing snapshot.\n                                   - NULL         - use the last stored snapshot.\n                 * delta         The table name is mandatory and specified the reference view to compare the currently\n                                 stored snapshot against. If no snapshot exists, a new will be created.\n                 * create_table  The name of the regular table to create.\n                 * create_tmp    The name of the temporary table to create.\n                 * save          The name of the table to save the currently stored snapshot into.\n             in_views (SET (\'with_runtimes_in_95th_percentile\', \'analysis\', \'with_errors_or_warnings\',\n                            \'with_full_table_scans\', \'with_sorting\', \'with_temp_tables\', \'custom\'))\n               Which views to include:\n                 * with_runtimes_in_95th_percentile  Based on the sys.statements_with_runtimes_in_95th_percentile view\n                 * analysis                          Based on the sys.statement_analysis view\n                 * with_errors_or_warnings           Based on the sys.statements_with_errors_or_warnings view\n                 * with_full_table_scans             Based on the sys.statements_with_full_table_scans view\n                 * with_sorting                      Based on the sys.statements_with_sorting view\n                 * with_temp_tables                  Based on the sys.statements_with_temp_tables view\n                 * custom                            Use a custom view. This view must be specified in @sys.statement_performance_analyzer.view to an existing view or a query\n             Default is to include all except \'custom\'.\n             Configuration Options\n             sys.statement_performance_analyzer.limit\n               The maximum number of rows to include for the views that does not have a built-in limit (e.g. the 95th percentile view).\n               If not set the limit is 100.\n             sys.statement_performance_analyzer.view\n               Used together with the \'custom\' view. If the value contains a space, it is considered a query, otherwise it must be\n               an existing view querying the performance_schema.events_statements_summary_by_digest table. There cannot be any limit\n               clause including in the query or view definition if @sys.statement_performance_analyzer.limit > 0.\n               If specifying a view, use the same format as for in_table.\n             sys.debug\n               Whether to provide debugging output.\n               Default is \'OFF\'. Set to \'ON\' to include.\n             Example\n             To create a report with the queries in the 95th percentile since last truncate of performance_schema.events_statements_summary_by_digest\n             and the delta for a 1 minute period:\n                1. Create a temporary table to store the initial snapshot.\n                2. Create the initial snapshot.\n                3. Save the initial snapshot in the temporary table.\n                4. Wait one minute.\n                5. Create a new snapshot.\n                6. Perform analyzis based on the new snapshot.\n                7. Perform analyzis based on the delta between the initial and new snapshots.\n             mysql> CALL sys.statement_performance_analyzer(\'create_tmp\', \'mydb.tmp_digests_ini\', NULL);\n             Query OK, 0 rows affected (0.08 sec)\n             mysql> CALL sys.statement_performance_analyzer(\'snapshot\', NULL, NULL);\n             Query OK, 0 rows affected (0.02 sec)\n             mysql> CALL sys.statement_performance_analyzer(\'save\', \'mydb.tmp_digests_ini\', NULL);\n             Query OK, 0 rows affected (0.00 sec)\n             mysql> DO SLEEP(60);\n             Query OK, 0 rows affected (1 min 0.00 sec)\n             mysql> CALL sys.statement_performance_analyzer(\'snapshot\', NULL, NULL);\n             Query OK, 0 rows affected (0.02 sec)\n             mysql> CALL sys.statement_performance_analyzer(\'overall\', NULL, \'with_runtimes_in_95th_percentile\');\n             +-----------------------------------------+\n             | Next Output                             |\n             +-----------------------------------------+\n             | Queries with Runtime in 95th Percentile |\n             +-----------------------------------------+\n             1 row in set (0.05 sec)\n             ...\n             mysql> CALL sys.statement_performance_analyzer(\'delta\', \'mydb.tmp_digests_ini\', \'with_runtimes_in_95th_percentile\');\n             +-----------------------------------------+\n             | Next Output                             |\n             +-----------------------------------------+\n             | Queries with Runtime in 95th Percentile |\n             +-----------------------------------------+\n             1 row in set (0.03 sec)\n             ...\n             To create an overall report of the 95th percentile queries and the top 10 queries with full table scans:\n             mysql> CALL sys.statement_performance_analyzer(\'snapshot\', NULL, NULL);\n             Query OK, 0 rows affected (0.01 sec)\n             mysql> SET @sys.statement_performance_analyzer.limit = 10;\n             Query OK, 0 rows affected (0.00 sec)\n             mysql> CALL sys.statement_performance_analyzer(\'overall\', NULL, \'with_runtimes_in_95th_percentile,with_full_table_scans\');\n             +-----------------------------------------+\n             | Next Output                             |\n             +-----------------------------------------+\n             | Queries with Runtime in 95th Percentile |\n             +-----------------------------------------+\n             1 row in set (0.01 sec)\n             ...\n             +-------------------------------------+\n             | Next Output                         |\n             +-------------------------------------+\n             | Top 10 Queries with Full Table Scan |\n             +-------------------------------------+\n             1 row in set (0.09 sec)\n             ...\n             Use a custom view showing the top 10 query sorted by total execution time refreshing the view every minute using\n             the watch command in Linux.\n             mysql> CREATE OR REPLACE VIEW mydb.my_statements AS\n                 -> SELECT sys.format_statement(DIGEST_TEXT) AS query,\n                 ->        SCHEMA_NAME AS db,\n                 ->        COUNT_STAR AS exec_count,\n                 ->        sys.format_time(SUM_TIMER_WAIT) AS total_latency,\n                 ->        sys.format_time(AVG_TIMER_WAIT) AS avg_latency,\n                 ->        ROUND(IFNULL(SUM_ROWS_SENT / NULLIF(COUNT_STAR, 0), 0)) AS rows_sent_avg,\n                 ->        ROUND(IFNULL(SUM_ROWS_EXAMINED / NULLIF(COUNT_STAR, 0), 0)) AS rows_examined_avg,\n                 ->        ROUND(IFNULL(SUM_ROWS_AFFECTED / NULLIF(COUNT_STAR, 0), 0)) AS rows_affected_avg,\n                 ->        DIGEST AS digest\n                 ->   FROM performance_schema.events_statements_summary_by_digest\n                 -> ORDER BY SUM_TIMER_WAIT DESC;\n             Query OK, 0 rows affected (0.01 sec)\n             mysql> CALL sys.statement_performance_analyzer(\'create_table\', \'mydb.digests_prev\', NULL);\n             Query OK, 0 rows affected (0.10 sec)\n             shell$ watch -n 60 \"mysql sys --table -e \"\n             > SET @sys.statement_performance_analyzer.view = \'mydb.my_statements\';\n             > SET @sys.statement_performance_analyzer.limit = 10;\n             > CALL statement_performance_analyzer(\'snapshot\', NULL, NULL);\n             > CALL statement_performance_analyzer(\'delta\', \'mydb.digests_prev\', \'custom\');\n             > CALL statement_performance_analyzer(\'save\', \'mydb.digests_prev\', NULL);\n             > \"\"\n             Every 60.0s: mysql sys --table -e \"                                                                                                   ...  Mon Dec 22 10:58:51 2014\n             +----------------------------------+\n             | Next Output                      |\n             +----------------------------------+\n             | Top 10 Queries Using Custom View |\n             +----------------------------------+\n             +-------------------+-------+------------+---------------+-------------+---------------+-------------------+-------------------+----------------------------------+\n             | query             | db    | exec_count | total_latency | avg_latency | rows_sent_avg | rows_examined_avg | rows_affected_avg | digest                           |\n             +-------------------+-------+------------+---------------+-------------+---------------+-------------------+-------------------+----------------------------------+\n             ...\n            ','utf8mb3','utf8mb3_general_ci','utf8mb3_general_ci','BEGIN\n    DECLARE v_table_exists, v_tmp_digests_table_exists, v_custom_view_exists ENUM(\'\', \'BASE TABLE\', \'VIEW\', \'TEMPORARY\') DEFAULT \'\';\n    DECLARE v_this_thread_enabled ENUM(\'YES\', \'NO\');\n    DECLARE v_force_new_snapshot BOOLEAN DEFAULT FALSE;\n    DECLARE v_digests_table VARCHAR(133);\n    DECLARE v_quoted_table, v_quoted_custom_view VARCHAR(133) DEFAULT \'\';\n    DECLARE v_table_db, v_table_name, v_custom_db, v_custom_name VARCHAR(64);\n    DECLARE v_digest_table_template, v_checksum_ref, v_checksum_table text;\n    DECLARE v_sql longtext;\n    DECLARE v_error_msg VARCHAR(128);\n    SELECT INSTRUMENTED INTO v_this_thread_enabled FROM performance_schema.threads WHERE PROCESSLIST_ID = CONNECTION_ID();\n    IF (v_this_thread_enabled = \'YES\') THEN\n        CALL sys.ps_setup_disable_thread(CONNECTION_ID());\n    END IF;\n    SET @log_bin := @@sql_log_bin;\n    IF (@log_bin = 1) THEN\n        SET sql_log_bin = 0;\n    END IF;\n    IF (@sys.statement_performance_analyzer.limit IS NULL) THEN\n        SET @sys.statement_performance_analyzer.limit = sys.sys_get_config(\'statement_performance_analyzer.limit\', \'100\');\n    END IF;\n    IF (@sys.debug IS NULL) THEN\n        SET @sys.debug                                = sys.sys_get_config(\'debug\'                               , \'OFF\');\n    END IF;\n    IF (in_table = \'NOW()\') THEN\n        SET v_force_new_snapshot = TRUE,\n            in_table             = NULL;\n    ELSEIF (in_table IS NOT NULL) THEN\n        IF (NOT INSTR(in_table, \'.\')) THEN\n            SET v_table_db   = DATABASE(),\n                v_table_name = in_table;\n        ELSE\n            SET v_table_db   = SUBSTRING_INDEX(in_table, \'.\', 1);\n            SET v_table_name = SUBSTRING(in_table, CHAR_LENGTH(v_table_db)+2);\n        END IF;\n        SET v_quoted_table = CONCAT(\'`\', v_table_db, \'`.`\', v_table_name, \'`\');\n        IF (@sys.debug = \'ON\') THEN\n            SELECT CONCAT(\'in_table is: db = \'\'\', v_table_db, \'\'\', table = \'\'\', v_table_name, \'\'\'\') AS \'Debug\';\n        END IF;\n        IF (v_table_db = DATABASE() AND (v_table_name = \'tmp_digests\' OR v_table_name = \'tmp_digests_delta\')) THEN\n            SET v_error_msg = CONCAT(\'Invalid value for in_table: \', v_quoted_table, \' is reserved table name.\');\n            SIGNAL SQLSTATE \'45000\'\n               SET MESSAGE_TEXT = v_error_msg;\n        END IF;\n        CALL sys.table_exists(v_table_db, v_table_name, v_table_exists);\n        IF (@sys.debug = \'ON\') THEN\n            SELECT CONCAT(\'v_table_exists = \', v_table_exists) AS \'Debug\';\n        END IF;\n        IF (v_table_exists = \'BASE TABLE\') THEN\n            SET v_checksum_ref = (\n                 SELECT GROUP_CONCAT(CONCAT(COLUMN_NAME, COLUMN_TYPE) ORDER BY ORDINAL_POSITION) AS Checksum\n                   FROM information_schema.COLUMNS\n                  WHERE TABLE_SCHEMA = \'performance_schema\' AND TABLE_NAME = \'events_statements_summary_by_digest\'\n                ),\n                v_checksum_table = (\n                 SELECT GROUP_CONCAT(CONCAT(COLUMN_NAME, COLUMN_TYPE) ORDER BY ORDINAL_POSITION) AS Checksum\n                   FROM information_schema.COLUMNS\n                  WHERE TABLE_SCHEMA = v_table_db AND TABLE_NAME = v_table_name\n                );\n            IF (v_checksum_ref <> v_checksum_table) THEN\n                SET v_error_msg = CONCAT(\'The table \',\n                                         IF(CHAR_LENGTH(v_quoted_table) > 93, CONCAT(\'...\', SUBSTRING(v_quoted_table, -90)), v_quoted_table),\n                                         \' has the wrong definition.\');\n                SIGNAL SQLSTATE \'45000\'\n                   SET MESSAGE_TEXT = v_error_msg;\n            END IF;\n        END IF;\n    END IF;\n    IF (in_views IS NULL OR in_views = \'\') THEN\n        SET in_views = \'with_runtimes_in_95th_percentile,analysis,with_errors_or_warnings,with_full_table_scans,with_sorting,with_temp_tables\';\n    END IF;\n    CALL sys.table_exists(DATABASE(), \'tmp_digests\', v_tmp_digests_table_exists);\n    IF (@sys.debug = \'ON\') THEN\n        SELECT CONCAT(\'v_tmp_digests_table_exists = \', v_tmp_digests_table_exists) AS \'Debug\';\n    END IF;\n    CASE\n        WHEN in_action IN (\'snapshot\', \'overall\') THEN\n            IF (in_table IS NOT NULL) THEN\n                IF (NOT v_table_exists IN (\'TEMPORARY\', \'BASE TABLE\')) THEN\n                    SET v_error_msg = CONCAT(\'The \', in_action, \' action requires in_table to be NULL, NOW() or specify an existing table.\',\n                                             \' The table \',\n                                             IF(CHAR_LENGTH(v_quoted_table) > 16, CONCAT(\'...\', SUBSTRING(v_quoted_table, -13)), v_quoted_table),\n                                             \' does not exist.\');\n                    SIGNAL SQLSTATE \'45000\'\n                       SET MESSAGE_TEXT = v_error_msg;\n                END IF;\n            END IF;\n        WHEN in_action IN (\'delta\', \'save\') THEN\n            IF (v_table_exists NOT IN (\'TEMPORARY\', \'BASE TABLE\')) THEN\n                SET v_error_msg = CONCAT(\'The \', in_action, \' action requires in_table to be an existing table.\',\n                                         IF(in_table IS NOT NULL, CONCAT(\' The table \',\n                                             IF(CHAR_LENGTH(v_quoted_table) > 39, CONCAT(\'...\', SUBSTRING(v_quoted_table, -36)), v_quoted_table),\n                                             \' does not exist.\'), \'\'));\n                SIGNAL SQLSTATE \'45000\'\n                   SET MESSAGE_TEXT = v_error_msg;\n            END IF;\n            IF (in_action = \'delta\' AND v_tmp_digests_table_exists <> \'TEMPORARY\') THEN\n                SIGNAL SQLSTATE \'45000\'\n                   SET MESSAGE_TEXT = \'An existing snapshot generated with the statement_performance_analyzer() must exist.\';\n            END IF;\n        WHEN in_action = \'create_tmp\' THEN\n            IF (v_table_exists = \'TEMPORARY\') THEN\n                SET v_error_msg = CONCAT(\'Cannot create the table \',\n                                         IF(CHAR_LENGTH(v_quoted_table) > 72, CONCAT(\'...\', SUBSTRING(v_quoted_table, -69)), v_quoted_table),\n                                         \' as it already exists.\');\n                SIGNAL SQLSTATE \'45000\'\n                   SET MESSAGE_TEXT = v_error_msg;\n            END IF;\n        WHEN in_action = \'create_table\' THEN\n            IF (v_table_exists <> \'\') THEN\n                SET v_error_msg = CONCAT(\'Cannot create the table \',\n                                         IF(CHAR_LENGTH(v_quoted_table) > 52, CONCAT(\'...\', SUBSTRING(v_quoted_table, -49)), v_quoted_table),\n                                         \' as it already exists\',\n                                         IF(v_table_exists = \'TEMPORARY\', \' as a temporary table.\', \'.\'));\n                SIGNAL SQLSTATE \'45000\'\n                   SET MESSAGE_TEXT = v_error_msg;\n            END IF;\n        WHEN in_action = \'cleanup\' THEN\n            DO (SELECT 1);\n        ELSE\n            SIGNAL SQLSTATE \'45000\'\n               SET MESSAGE_TEXT = \'Unknown action. Supported actions are: cleanup, create_table, create_tmp, delta, overall, save, snapshot\';\n    END CASE;\n    SET v_digest_table_template = \'CREATE %{TEMPORARY}TABLE %{TABLE_NAME} (\\n  `SCHEMA_NAME` varchar(64) DEFAULT NULL,\\n  `DIGEST` varchar(32) DEFAULT NULL,\\n  `DIGEST_TEXT` longtext,\\n  `COUNT_STAR` bigint(20) unsigned NOT NULL,\\n  `SUM_TIMER_WAIT` bigint(20) unsigned NOT NULL,\\n  `MIN_TIMER_WAIT` bigint(20) unsigned NOT NULL,\\n  `AVG_TIMER_WAIT` bigint(20) unsigned NOT NULL,\\n  `MAX_TIMER_WAIT` bigint(20) unsigned NOT NULL,\\n  `SUM_LOCK_TIME` bigint(20) unsigned NOT NULL,\\n  `SUM_ERRORS` bigint(20) unsigned NOT NULL,\\n  `SUM_WARNINGS` bigint(20) unsigned NOT NULL,\\n  `SUM_ROWS_AFFECTED` bigint(20) unsigned NOT NULL,\\n  `SUM_ROWS_SENT` bigint(20) unsigned NOT NULL,\\n  `SUM_ROWS_EXAMINED` bigint(20) unsigned NOT NULL,\\n  `SUM_CREATED_TMP_DISK_TABLES` bigint(20) unsigned NOT NULL,\\n  `SUM_CREATED_TMP_TABLES` bigint(20) unsigned NOT NULL,\\n  `SUM_SELECT_FULL_JOIN` bigint(20) unsigned NOT NULL,\\n  `SUM_SELECT_FULL_RANGE_JOIN` bigint(20) unsigned NOT NULL,\\n  `SUM_SELECT_RANGE` bigint(20) unsigned NOT NULL,\\n  `SUM_SELECT_RANGE_CHECK` bigint(20) unsigned NOT NULL,\\n  `SUM_SELECT_SCAN` bigint(20) unsigned NOT NULL,\\n  `SUM_SORT_MERGE_PASSES` bigint(20) unsigned NOT NULL,\\n  `SUM_SORT_RANGE` bigint(20) unsigned NOT NULL,\\n  `SUM_SORT_ROWS` bigint(20) unsigned NOT NULL,\\n  `SUM_SORT_SCAN` bigint(20) unsigned NOT NULL,\\n  `SUM_NO_INDEX_USED` bigint(20) unsigned NOT NULL,\\n  `SUM_NO_GOOD_INDEX_USED` bigint(20) unsigned NOT NULL,\\n  `FIRST_SEEN` timestamp NULL DEFAULT NULL,\\n  `LAST_SEEN` timestamp NULL DEFAULT NULL,\\n  INDEX (SCHEMA_NAME, DIGEST)\\n) DEFAULT CHARSET=utf8\';\n    IF (v_force_new_snapshot\n           OR in_action = \'snapshot\'\n           OR (in_action = \'overall\' AND in_table IS NULL)\n           OR (in_action = \'save\' AND v_tmp_digests_table_exists <> \'TEMPORARY\')\n       ) THEN\n        IF (v_tmp_digests_table_exists = \'TEMPORARY\') THEN\n            IF (@sys.debug = \'ON\') THEN\n                SELECT \'DROP TEMPORARY TABLE IF EXISTS tmp_digests\' AS \'Debug\';\n            END IF;\n            DROP TEMPORARY TABLE IF EXISTS tmp_digests;\n        END IF;\n        CALL sys.execute_prepared_stmt(REPLACE(REPLACE(v_digest_table_template, \'%{TEMPORARY}\', \'TEMPORARY \'), \'%{TABLE_NAME}\', \'tmp_digests\'));\n        SET v_sql = CONCAT(\'INSERT INTO tmp_digests SELECT * FROM \',\n                           IF(in_table IS NULL OR in_action = \'save\', \'performance_schema.events_statements_summary_by_digest\', v_quoted_table));\n        CALL sys.execute_prepared_stmt(v_sql);\n    END IF;\n    IF (in_action IN (\'create_table\', \'create_tmp\')) THEN\n        IF (in_action = \'create_table\') THEN\n            CALL sys.execute_prepared_stmt(REPLACE(REPLACE(v_digest_table_template, \'%{TEMPORARY}\', \'\'), \'%{TABLE_NAME}\', v_quoted_table));\n        ELSE\n            CALL sys.execute_prepared_stmt(REPLACE(REPLACE(v_digest_table_template, \'%{TEMPORARY}\', \'TEMPORARY \'), \'%{TABLE_NAME}\', v_quoted_table));\n        END IF;\n    ELSEIF (in_action = \'save\') THEN\n        CALL sys.execute_prepared_stmt(CONCAT(\'DELETE FROM \', v_quoted_table));\n        CALL sys.execute_prepared_stmt(CONCAT(\'INSERT INTO \', v_quoted_table, \' SELECT * FROM tmp_digests\'));\n    ELSEIF (in_action = \'cleanup\') THEN\n        DROP TEMPORARY TABLE IF EXISTS sys.tmp_digests;\n        DROP TEMPORARY TABLE IF EXISTS sys.tmp_digests_delta;\n    ELSEIF (in_action IN (\'overall\', \'delta\')) THEN\n        IF (in_action = \'overall\') THEN\n            IF (in_table IS NULL) THEN\n                SET v_digests_table = \'tmp_digests\';\n            ELSE\n                SET v_digests_table = v_quoted_table;\n            END IF;\n        ELSE\n            SET v_digests_table = \'tmp_digests_delta\';\n            DROP TEMPORARY TABLE IF EXISTS tmp_digests_delta;\n            CREATE TEMPORARY TABLE tmp_digests_delta LIKE tmp_digests;\n            SET v_sql = CONCAT(\'INSERT INTO tmp_digests_delta\\nSELECT `d_end`.`SCHEMA_NAME`,\\n       `d_end`.`DIGEST`,\\n       `d_end`.`DIGEST_TEXT`,\\n       `d_end`.`COUNT_STAR`-IFNULL(`d_start`.`COUNT_STAR`, 0) AS \'\'COUNT_STAR\'\',\\n       `d_end`.`SUM_TIMER_WAIT`-IFNULL(`d_start`.`SUM_TIMER_WAIT`, 0) AS \'\'SUM_TIMER_WAIT\'\',\\n       `d_end`.`MIN_TIMER_WAIT` AS \'\'MIN_TIMER_WAIT\'\',\\n       IFNULL((`d_end`.`SUM_TIMER_WAIT`-IFNULL(`d_start`.`SUM_TIMER_WAIT`, 0))/NULLIF(`d_end`.`COUNT_STAR`-IFNULL(`d_start`.`COUNT_STAR`, 0), 0), 0) AS \'\'AVG_TIMER_WAIT\'\',\\n       `d_end`.`MAX_TIMER_WAIT` AS \'\'MAX_TIMER_WAIT\'\',\\n       `d_end`.`SUM_LOCK_TIME`-IFNULL(`d_start`.`SUM_LOCK_TIME`, 0) AS \'\'SUM_LOCK_TIME\'\',\\n       `d_end`.`SUM_ERRORS`-IFNULL(`d_start`.`SUM_ERRORS`, 0) AS \'\'SUM_ERRORS\'\',\\n       `d_end`.`SUM_WARNINGS`-IFNULL(`d_start`.`SUM_WARNINGS`, 0) AS \'\'SUM_WARNINGS\'\',\\n       `d_end`.`SUM_ROWS_AFFECTED`-IFNULL(`d_start`.`SUM_ROWS_AFFECTED`, 0) AS \'\'SUM_ROWS_AFFECTED\'\',\\n       `d_end`.`SUM_ROWS_SENT`-IFNULL(`d_start`.`SUM_ROWS_SENT`, 0) AS \'\'SUM_ROWS_SENT\'\',\\n       `d_end`.`SUM_ROWS_EXAMINED`-IFNULL(`d_start`.`SUM_ROWS_EXAMINED`, 0) AS \'\'SUM_ROWS_EXAMINED\'\',\\n       `d_end`.`SUM_CREATED_TMP_DISK_TABLES`-IFNULL(`d_start`.`SUM_CREATED_TMP_DISK_TABLES`, 0) AS \'\'SUM_CREATED_TMP_DISK_TABLES\'\',\\n       `d_end`.`SUM_CREATED_TMP_TABLES`-IFNULL(`d_start`.`SUM_CREATED_TMP_TABLES`, 0) AS \'\'SUM_CREATED_TMP_TABLES\'\',\\n       `d_end`.`SUM_SELECT_FULL_JOIN`-IFNULL(`d_start`.`SUM_SELECT_FULL_JOIN`, 0) AS \'\'SUM_SELECT_FULL_JOIN\'\',\\n       `d_end`.`SUM_SELECT_FULL_RANGE_JOIN`-IFNULL(`d_start`.`SUM_SELECT_FULL_RANGE_JOIN`, 0) AS \'\'SUM_SELECT_FULL_RANGE_JOIN\'\',\\n       `d_end`.`SUM_SELECT_RANGE`-IFNULL(`d_start`.`SUM_SELECT_RANGE`, 0) AS \'\'SUM_SELECT_RANGE\'\',\\n       `d_end`.`SUM_SELECT_RANGE_CHECK`-IFNULL(`d_start`.`SUM_SELECT_RANGE_CHECK`, 0) AS \'\'SUM_SELECT_RANGE_CHECK\'\',\\n       `d_end`.`SUM_SELECT_SCAN`-IFNULL(`d_start`.`SUM_SELECT_SCAN`, 0) AS \'\'SUM_SELECT_SCAN\'\',\\n       `d_end`.`SUM_SORT_MERGE_PASSES`-IFNULL(`d_start`.`SUM_SORT_MERGE_PASSES`, 0) AS \'\'SUM_SORT_MERGE_PASSES\'\',\\n       `d_end`.`SUM_SORT_RANGE`-IFNULL(`d_start`.`SUM_SORT_RANGE`, 0) AS \'\'SUM_SORT_RANGE\'\',\\n       `d_end`.`SUM_SORT_ROWS`-IFNULL(`d_start`.`SUM_SORT_ROWS`, 0) AS \'\'SUM_SORT_ROWS\'\',\\n       `d_end`.`SUM_SORT_SCAN`-IFNULL(`d_start`.`SUM_SORT_SCAN`, 0) AS \'\'SUM_SORT_SCAN\'\',\\n       `d_end`.`SUM_NO_INDEX_USED`-IFNULL(`d_start`.`SUM_NO_INDEX_USED`, 0) AS \'\'SUM_NO_INDEX_USED\'\',\\n       `d_end`.`SUM_NO_GOOD_INDEX_USED`-IFNULL(`d_start`.`SUM_NO_GOOD_INDEX_USED`, 0) AS \'\'SUM_NO_GOOD_INDEX_USED\'\',\\n       `d_end`.`FIRST_SEEN`,\\n       `d_end`.`LAST_SEEN`\\n  FROM tmp_digests d_end\\n       LEFT OUTER JOIN \', v_quoted_table, \' d_start ON `d_start`.`DIGEST` = `d_end`.`DIGEST`\\n                                                    AND (`d_start`.`SCHEMA_NAME` = `d_end`.`SCHEMA_NAME`\\n                                                          OR (`d_start`.`SCHEMA_NAME` IS NULL AND `d_end`.`SCHEMA_NAME` IS NULL)\\n                                                        )\\n WHERE `d_end`.`COUNT_STAR`-IFNULL(`d_start`.`COUNT_STAR`, 0) > 0\');\n            CALL sys.execute_prepared_stmt(v_sql);\n        END IF;\n        IF (FIND_IN_SET(\'with_runtimes_in_95th_percentile\', in_views)) THEN\n            SELECT \'Queries with Runtime in 95th Percentile\' AS \'Next Output\';\n            DROP TEMPORARY TABLE IF EXISTS tmp_digest_avg_latency_distribution1;\n            DROP TEMPORARY TABLE IF EXISTS tmp_digest_avg_latency_distribution2;\n            DROP TEMPORARY TABLE IF EXISTS tmp_digest_95th_percentile_by_avg_us;\n            CREATE TEMPORARY TABLE tmp_digest_avg_latency_distribution1 (\n              cnt bigint unsigned NOT NULL,\n              avg_us decimal(21,0) NOT NULL,\n              PRIMARY KEY (avg_us)\n            ) ENGINE=InnoDB;\n            SET v_sql = CONCAT(\'INSERT INTO tmp_digest_avg_latency_distribution1\\nSELECT COUNT(*) cnt,\\n       ROUND(avg_timer_wait/1000000) AS avg_us\\n  FROM \', v_digests_table, \'\\n GROUP BY avg_us\');\n            CALL sys.execute_prepared_stmt(v_sql);\n            CREATE TEMPORARY TABLE tmp_digest_avg_latency_distribution2 LIKE tmp_digest_avg_latency_distribution1;\n            INSERT INTO tmp_digest_avg_latency_distribution2 SELECT * FROM tmp_digest_avg_latency_distribution1;\n            CREATE TEMPORARY TABLE tmp_digest_95th_percentile_by_avg_us (\n              avg_us decimal(21,0) NOT NULL,\n              percentile decimal(46,4) NOT NULL,\n              PRIMARY KEY (avg_us)\n            ) ENGINE=InnoDB;\n            SET v_sql = CONCAT(\'INSERT INTO tmp_digest_95th_percentile_by_avg_us\\nSELECT s2.avg_us avg_us,\\n       IFNULL(SUM(s1.cnt)/NULLIF((SELECT COUNT(*) FROM \', v_digests_table, \'), 0), 0) percentile\\n  FROM tmp_digest_avg_latency_distribution1 AS s1\\n       JOIN tmp_digest_avg_latency_distribution2 AS s2 ON s1.avg_us <= s2.avg_us\\n GROUP BY s2.avg_us\\nHAVING percentile > 0.95\\n ORDER BY percentile\\n LIMIT 1\');\n            CALL sys.execute_prepared_stmt(v_sql);\n            SET v_sql =\n                REPLACE(\n                    REPLACE(\n                        (SELECT VIEW_DEFINITION\n                           FROM information_schema.VIEWS\n                          WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = \'statements_with_runtimes_in_95th_percentile\'\n                        ),\n                        \'`performance_schema`.`events_statements_summary_by_digest`\',\n                        v_digests_table\n                    ),\n                    \'sys.x$ps_digest_95th_percentile_by_avg_us\',\n                    \'`sys`.`x$ps_digest_95th_percentile_by_avg_us`\'\n              );\n            CALL sys.execute_prepared_stmt(v_sql);\n            DROP TEMPORARY TABLE tmp_digest_avg_latency_distribution1;\n            DROP TEMPORARY TABLE tmp_digest_avg_latency_distribution2;\n            DROP TEMPORARY TABLE tmp_digest_95th_percentile_by_avg_us;\n        END IF;\n        IF (FIND_IN_SET(\'analysis\', in_views)) THEN\n            SELECT CONCAT(\'Top \', @sys.statement_performance_analyzer.limit, \' Queries Ordered by Total Latency\') AS \'Next Output\';\n            SET v_sql =\n                REPLACE(\n                    (SELECT VIEW_DEFINITION\n                       FROM information_schema.VIEWS\n                      WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = \'statement_analysis\'\n                    ),\n                    \'`performance_schema`.`events_statements_summary_by_digest`\',\n                    v_digests_table\n                );\n            IF (@sys.statement_performance_analyzer.limit > 0) THEN\n                SET v_sql = CONCAT(v_sql, \' LIMIT \', @sys.statement_performance_analyzer.limit);\n            END IF;\n            CALL sys.execute_prepared_stmt(v_sql);\n        END IF;\n        IF (FIND_IN_SET(\'with_errors_or_warnings\', in_views)) THEN\n            SELECT CONCAT(\'Top \', @sys.statement_performance_analyzer.limit, \' Queries with Errors\') AS \'Next Output\';\n            SET v_sql =\n                REPLACE(\n                    (SELECT VIEW_DEFINITION\n                       FROM information_schema.VIEWS\n                      WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = \'statements_with_errors_or_warnings\'\n                    ),\n                    \'`performance_schema`.`events_statements_summary_by_digest`\',\n                    v_digests_table\n                );\n            IF (@sys.statement_performance_analyzer.limit > 0) THEN\n                SET v_sql = CONCAT(v_sql, \' LIMIT \', @sys.statement_performance_analyzer.limit);\n            END IF;\n            CALL sys.execute_prepared_stmt(v_sql);\n        END IF;\n        IF (FIND_IN_SET(\'with_full_table_scans\', in_views)) THEN\n            SELECT CONCAT(\'Top \', @sys.statement_performance_analyzer.limit, \' Queries with Full Table Scan\') AS \'Next Output\';\n            SET v_sql =\n                REPLACE(\n                    (SELECT VIEW_DEFINITION\n                       FROM information_schema.VIEWS\n                      WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = \'statements_with_full_table_scans\'\n                    ),\n                    \'`performance_schema`.`events_statements_summary_by_digest`\',\n                    v_digests_table\n                );\n            IF (@sys.statement_performance_analyzer.limit > 0) THEN\n                SET v_sql = CONCAT(v_sql, \' LIMIT \', @sys.statement_performance_analyzer.limit);\n            END IF;\n            CALL sys.execute_prepared_stmt(v_sql);\n        END IF;\n        IF (FIND_IN_SET(\'with_sorting\', in_views)) THEN\n            SELECT CONCAT(\'Top \', @sys.statement_performance_analyzer.limit, \' Queries with Sorting\') AS \'Next Output\';\n            SET v_sql =\n                REPLACE(\n                    (SELECT VIEW_DEFINITION\n                       FROM information_schema.VIEWS\n                      WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = \'statements_with_sorting\'\n                    ),\n                    \'`performance_schema`.`events_statements_summary_by_digest`\',\n                    v_digests_table\n                );\n            IF (@sys.statement_performance_analyzer.limit > 0) THEN\n                SET v_sql = CONCAT(v_sql, \' LIMIT \', @sys.statement_performance_analyzer.limit);\n            END IF;\n            CALL sys.execute_prepared_stmt(v_sql);\n        END IF;\n        IF (FIND_IN_SET(\'with_temp_tables\', in_views)) THEN\n            SELECT CONCAT(\'Top \', @sys.statement_performance_analyzer.limit, \' Queries with Internal Temporary Tables\') AS \'Next Output\';\n            SET v_sql =\n                REPLACE(\n                    (SELECT VIEW_DEFINITION\n                       FROM information_schema.VIEWS\n                      WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = \'statements_with_temp_tables\'\n                    ),\n                    \'`performance_schema`.`events_statements_summary_by_digest`\',\n                    v_digests_table\n                );\n            IF (@sys.statement_performance_analyzer.limit > 0) THEN\n                SET v_sql = CONCAT(v_sql, \' LIMIT \', @sys.statement_performance_analyzer.limit);\n            END IF;\n            CALL sys.execute_prepared_stmt(v_sql);\n        END IF;\n        IF (FIND_IN_SET(\'custom\', in_views)) THEN\n            SELECT CONCAT(\'Top \', @sys.statement_performance_analyzer.limit, \' Queries Using Custom View\') AS \'Next Output\';\n            IF (@sys.statement_performance_analyzer.view IS NULL) THEN\n                SET @sys.statement_performance_analyzer.view = sys.sys_get_config(\'statement_performance_analyzer.view\', NULL);\n            END IF;\n            IF (@sys.statement_performance_analyzer.view IS NULL) THEN\n                SIGNAL SQLSTATE \'45000\'\n                   SET MESSAGE_TEXT = \'The @sys.statement_performance_analyzer.view user variable must be set with the view or query to use.\';\n            END IF;\n            IF (NOT INSTR(@sys.statement_performance_analyzer.view, \' \')) THEN\n                IF (NOT INSTR(@sys.statement_performance_analyzer.view, \'.\')) THEN\n                    SET v_custom_db   = DATABASE(),\n                        v_custom_name = @sys.statement_performance_analyzer.view;\n                ELSE\n                    SET v_custom_db   = SUBSTRING_INDEX(@sys.statement_performance_analyzer.view, \'.\', 1);\n                    SET v_custom_name = SUBSTRING(@sys.statement_performance_analyzer.view, CHAR_LENGTH(v_custom_db)+2);\n                END IF;\n                CALL sys.table_exists(v_custom_db, v_custom_name, v_custom_view_exists);\n                IF (v_custom_view_exists <> \'VIEW\') THEN\n                    SIGNAL SQLSTATE \'45000\'\n                       SET MESSAGE_TEXT = \'The @sys.statement_performance_analyzer.view user variable is set but specified neither an existing view nor a query.\';\n                END IF;\n                SET v_sql =\n                    REPLACE(\n                        (SELECT VIEW_DEFINITION\n                           FROM information_schema.VIEWS\n                          WHERE TABLE_SCHEMA = v_custom_db AND TABLE_NAME = v_custom_name\n                        ),\n                        \'`performance_schema`.`events_statements_summary_by_digest`\',\n                        v_digests_table\n                    );\n            ELSE\n                SET v_sql = REPLACE(@sys.statement_performance_analyzer.view, \'`performance_schema`.`events_statements_summary_by_digest`\', v_digests_table);\n            END IF;\n            IF (@sys.statement_performance_analyzer.limit > 0) THEN\n                SET v_sql = CONCAT(v_sql, \' LIMIT \', @sys.statement_performance_analyzer.limit);\n            END IF;\n            CALL sys.execute_prepared_stmt(v_sql);\n        END IF;\n    END IF;\n    IF (v_this_thread_enabled = \'YES\') THEN\n        CALL sys.ps_setup_enable_thread(CONNECTION_ID());\n    END IF;\n    IF (@log_bin = 1) THEN\n        SET sql_log_bin = @log_bin;\n    END IF;\nEND','NONE'),
