Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit bebf88c

Browse files
committed
Move all function documentation in to COMMENT characteristics clauses and the README
1 parent 6a01944 commit bebf88c

File tree

8 files changed

+558
-184
lines changed

8 files changed

+558
-184
lines changed

README.md

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,241 @@ Alternatively, you could just choose to load individual files based on your need
2323

2424
## Overview of objects
2525

26+
### Functions
27+
28+
#### extract_schema_from_file_name
29+
30+
##### Description
31+
32+
Takes a raw file path, and attempts to extract the schema name from it.
33+
34+
Useful for when interacting with Performance Schema data concerning IO statistics, for example.
35+
36+
Currently relies on the fact that a table data file will be within a specified database directory (will not work with partitions or tables that specify an individual DATA_DIRECTORY).
37+
38+
##### Parameters
39+
40+
* path (VARCHAR(512)): The full file path to a data file to extract the schema name from.
41+
42+
##### Returns
43+
44+
VARCHAR(512)
45+
46+
##### Example
47+
48+
mysql> SELECT sys.extract_schema_from_file_name('/var/lib/mysql/employees/employee.ibd');
49+
+----------------------------------------------------------------------------+
50+
| sys.extract_schema_from_file_name('/var/lib/mysql/employees/employee.ibd') |
51+
+----------------------------------------------------------------------------+
52+
| employees |
53+
+----------------------------------------------------------------------------+
54+
1 row in set (0.00 sec)
55+
56+
57+
#### extract_table_from_file_name
58+
59+
##### Description
60+
61+
Takes a raw file path, and extracts the table name from it.
62+
63+
Useful for when interacting with Performance Schema data concerning IO statistics, for example.
64+
65+
##### Parameters
66+
67+
* path (VARCHAR(512)): The full file path to a data file to extract the table name from.
68+
69+
##### Returns
70+
71+
VARCHAR(512)
72+
73+
##### Example
74+
75+
mysql> SELECT sys.extract_table_from_file_name('/var/lib/mysql/employees/employee.ibd');
76+
+---------------------------------------------------------------------------+
77+
| sys.extract_table_from_file_name('/var/lib/mysql/employees/employee.ibd') |
78+
+---------------------------------------------------------------------------+
79+
| employee |
80+
+---------------------------------------------------------------------------+
81+
1 row in set (0.02 sec)
82+
83+
84+
#### format_bytes
85+
86+
##### Description
87+
88+
Takes a raw bytes value, and converts it to a human readable format.
89+
90+
##### Parameters
91+
92+
* bytes (BIGINT): A raw bytes value.
93+
94+
##### Returns
95+
96+
VARCHAR(16)
97+
98+
##### Example
99+
100+
mysql> SELECT sys.format_bytes(2348723492723746) AS size;
101+
+----------+
102+
| size |
103+
+----------+
104+
| 2.09 PiB |
105+
+----------+
106+
1 row in set (0.00 sec)
107+
108+
mysql> SELECT sys.format_bytes(2348723492723) AS size;
109+
+----------+
110+
| size |
111+
+----------+
112+
| 2.14 TiB |
113+
+----------+
114+
1 row in set (0.00 sec)
115+
116+
mysql> SELECT sys.format_bytes(23487234) AS size;
117+
+-----------+
118+
| size |
119+
+-----------+
120+
| 22.40 MiB |
121+
+-----------+
122+
1 row in set (0.00 sec)
123+
124+
125+
#### format_path
126+
127+
##### Description
128+
129+
Takes a raw path value, and strips out the datadir or tmpdir replacing with @@datadir and @@tmpdir respectively.
130+
131+
Also normalizes the paths across operating systems, so backslashes on Windows are converted to forward slashes.
132+
133+
##### Parameters
134+
135+
* path (VARCHAR(260)): The raw file path value to format.
136+
137+
##### Returns
138+
139+
VARCHAR(260) CHARSET UTF8
140+
141+
##### Example
142+
143+
mysql> select @@datadir;
144+
+-----------------------------------------------+
145+
| @@datadir |
146+
+-----------------------------------------------+
147+
| /Users/mark/sandboxes/SmallTree/AMaster/data/ |
148+
+-----------------------------------------------+
149+
1 row in set (0.06 sec)
150+
151+
mysql> select format_path('/Users/mark/sandboxes/SmallTree/AMaster/data/mysql/proc.MYD') AS path;
152+
+--------------------------+
153+
| path |
154+
+--------------------------+
155+
| @@datadir/mysql/proc.MYD |
156+
+--------------------------+
157+
1 row in set (0.03 sec)
158+
159+
160+
#### format_statement
161+
162+
##### Description
163+
164+
Formats a normalized statement, truncating it if it's > 64 characters long.
165+
166+
Useful for printing statement related data from Performance Schema from the command line.
167+
168+
##### Parameters
169+
170+
* statement (LONGTEXT): The statement to format.
171+
172+
##### Returns
173+
174+
VARCHAR(65)
175+
176+
##### Example
177+
178+
mysql> SELECT sys.format_statement(digest_text)
179+
-> FROM performance_schema.events_statements_summary_by_digest
180+
-> ORDER by sum_timer_wait DESC limit 5;
181+
+-------------------------------------------------------------------+
182+
| sys.format_statement(digest_text) |
183+
+-------------------------------------------------------------------+
184+
| CREATE SQL SECURITY INVOKER VI ... KE ? AND `variable_value` > ? |
185+
| CREATE SQL SECURITY INVOKER VI ... ait` IS NOT NULL , `esc` . ... |
186+
| CREATE SQL SECURITY INVOKER VI ... ait` IS NOT NULL , `sys` . ... |
187+
| CREATE SQL SECURITY INVOKER VI ... , `compressed_size` ) ) DESC |
188+
| CREATE SQL SECURITY INVOKER VI ... LIKE ? ORDER BY `timer_start` |
189+
+-------------------------------------------------------------------+
190+
5 rows in set (0.00 sec)
191+
192+
193+
#### format_time
194+
195+
##### Description
196+
197+
Takes a raw picoseconds value, and converts it to a human readable form.
198+
199+
Picoseconds are the precision that all latency values are printed in within Performance Schema, however are not user friendly when wanting to scan output from the command line.
200+
201+
##### Parameters
202+
203+
* picoseconds (BIGINT UNSIGNED): The raw picoseconds value to convert.
204+
205+
##### Returns
206+
207+
VARCHAR(16) CHARSET UTF8
208+
209+
##### Example
210+
211+
mysql> select format_time(342342342342345);
212+
+------------------------------+
213+
| format_time(342342342342345) |
214+
+------------------------------+
215+
| 00:05:42 |
216+
+------------------------------+
217+
1 row in set (0.00 sec)
218+
219+
mysql> select format_time(342342342);
220+
+------------------------+
221+
| format_time(342342342) |
222+
+------------------------+
223+
| 342.34 µs |
224+
+------------------------+
225+
1 row in set (0.00 sec)
226+
227+
mysql> select format_time(34234);
228+
+--------------------+
229+
| format_time(34234) |
230+
+--------------------+
231+
| 34.23 ns |
232+
+--------------------+
233+
1 row in set (0.00 sec)
234+
235+
236+
#### ps_is_account_enabled
237+
238+
##### Description
239+
240+
Determines whether instrumentation of an account is enabled within Performance Schema.
241+
242+
##### Parameters
243+
244+
* in_host VARCHAR(60): The hostname of the account to check.
245+
* in_user (VARCHAR(16)): The username of the account to check.
246+
247+
##### Returns
248+
249+
ENUM('YES', 'NO', 'PARTIAL')
250+
251+
##### Example
252+
253+
mysql> SELECT sys.ps_is_account_enabled('localhost', 'root');
254+
+------------------------------------------------+
255+
| sys.ps_is_account_enabled('localhost', 'root') |
256+
+------------------------------------------------+
257+
| YES |
258+
+------------------------------------------------+
259+
1 row in set (0.01 sec)
260+
26261
### Procedures
27262

28263
#### create_synonym_db

functions/extract_schema_from_file_name.sql

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,55 @@
1111
1212
You should have received a copy of the GNU General Public License
1313
along with this program; if not, write to the Free Software
14-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15-
16-
/*
17-
* Function: extract_schema_from_file_name()
18-
*
19-
* Takes a raw file path, and attempts to extract the schema name from it
20-
*
21-
* Parameters
22-
* path: The raw file name value to extract the schema name from
23-
*/
14+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
2415

2516
DROP FUNCTION IF EXISTS extract_schema_from_file_name;
2617

2718
DELIMITER $$
2819

29-
CREATE FUNCTION extract_schema_from_file_name(path VARCHAR(512))
30-
RETURNS VARCHAR(512) DETERMINISTIC
31-
RETURN SUBSTRING_INDEX(SUBSTRING_INDEX(REPLACE(path, '\\', '/'), '/', -2), '/', 1)
20+
CREATE DEFINER='root'@'localhost' FUNCTION extract_schema_from_file_name (
21+
path VARCHAR(512)
22+
)
23+
RETURNS VARCHAR(512)
24+
COMMENT '
25+
Description
26+
-----------
27+
28+
Takes a raw file path, and attempts to extract the schema name from it.
29+
30+
Useful for when interacting with Performance Schema data
31+
concerning IO statistics, for example.
32+
33+
Currently relies on the fact that a table data file will be within a
34+
specified database directory (will not work with partitions or tables
35+
that specify an individual DATA_DIRECTORY).
36+
37+
Parameters
38+
-----------
39+
40+
path (VARCHAR(512)):
41+
The full file path to a data file to extract the schema name from.
42+
43+
Returns
44+
-----------
45+
46+
VARCHAR(512)
47+
48+
Example
49+
-----------
50+
51+
mysql> SELECT sys.extract_schema_from_file_name(\'/var/lib/mysql/employees/employee.ibd\');
52+
+----------------------------------------------------------------------------+
53+
| sys.extract_schema_from_file_name(\'/var/lib/mysql/employees/employee.ibd\') |
54+
+----------------------------------------------------------------------------+
55+
| employees |
56+
+----------------------------------------------------------------------------+
57+
1 row in set (0.00 sec)
58+
'
59+
SQL SECURITY INVOKER
60+
DETERMINISTIC
61+
NO SQL
62+
RETURN SUBSTRING_INDEX(SUBSTRING_INDEX(REPLACE(path, '\\', '/'), '/', -2), '/', 1)
3263
$$
3364

3465
DELIMITER ;

functions/extract_table_from_file_name.sql

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,51 @@
1111
1212
You should have received a copy of the GNU General Public License
1313
along with this program; if not, write to the Free Software
14-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15-
16-
/*
17-
* Function: extract_table_from_file_name()
18-
*
19-
* Takes a raw file path, and attempts to extract the table name from it
20-
*
21-
* Parameters
22-
* path: The raw file name value to extract the table name from
23-
*/
14+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
2415

2516
DROP FUNCTION IF EXISTS extract_table_from_file_name;
2617

2718
DELIMITER $$
2819

29-
CREATE FUNCTION extract_table_from_file_name(path VARCHAR(512))
30-
RETURNS VARCHAR(512) DETERMINISTIC
31-
RETURN SUBSTRING_INDEX(REPLACE(SUBSTRING_INDEX(REPLACE(path, '\\', '/'), '/', -1), '@0024', '$'), '.', 1);
20+
CREATE DEFINER='root'@'localhost' FUNCTION extract_table_from_file_name (
21+
path VARCHAR(512)
22+
)
23+
RETURNS VARCHAR(512)
24+
COMMENT '
25+
Description
26+
-----------
27+
28+
Takes a raw file path, and extracts the table name from it.
29+
30+
Useful for when interacting with Performance Schema data
31+
concerning IO statistics, for example.
32+
33+
Parameters
34+
-----------
35+
36+
path (VARCHAR(512)):
37+
The full file path to a data file to extract the table name from.
38+
39+
Returns
40+
-----------
41+
42+
VARCHAR(512)
43+
44+
Example
45+
-----------
46+
47+
mysql> SELECT sys.extract_table_from_file_name(\'/var/lib/mysql/employees/employee.ibd\');
48+
+---------------------------------------------------------------------------+
49+
| sys.extract_table_from_file_name(\'/var/lib/mysql/employees/employee.ibd\') |
50+
+---------------------------------------------------------------------------+
51+
| employee |
52+
+---------------------------------------------------------------------------+
53+
1 row in set (0.02 sec)
54+
'
55+
SQL SECURITY INVOKER
56+
DETERMINISTIC
57+
NO SQL
58+
RETURN SUBSTRING_INDEX(REPLACE(SUBSTRING_INDEX(REPLACE(path, '\\', '/'), '/', -1), '@0024', '$'), '.', 1);
3259
$$
3360

3461
DELIMITER ;

0 commit comments

Comments
 (0)