Skip to content

Commit 45d4c57

Browse files
author
Christopher Powers
committed
WL#13439 Sys Schema, Replace Stored Functions With Native Functions - restore SYS functions
For compatibility, keep rather than remove the the original SYS schema functions. RB: 23175
1 parent 3d69f96 commit 45d4c57

File tree

12 files changed

+335
-30
lines changed

12 files changed

+335
-30
lines changed

mysql-test/r/mysqldump.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5162,7 +5162,7 @@ DROP DATABASE dump_generated;
51625162
#
51635163
SELECT COUNT(*) FROM INFORMATION_SCHEMA.routines WHERE routine_schema = 'sys';
51645164
COUNT(*)
5165-
45
5165+
48
51665166
DROP DATABASE sys;
51675167
SELECT COUNT(*) FROM INFORMATION_SCHEMA.routines WHERE routine_schema = 'sys';
51685168
COUNT(*)
@@ -5172,7 +5172,7 @@ COUNT(*)
51725172
0
51735173
SELECT COUNT(*) FROM INFORMATION_SCHEMA.routines WHERE routine_schema = 'sys';
51745174
COUNT(*)
5175-
45
5175+
48
51765176
#
51775177
# WL#8697: Invisible Indexes
51785178
# Test of mysqldump.

mysql-test/suite/perfschema/r/native_func_format_bytes.result

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,41 @@ SELECT format_bytes((pow(2, 63) - 1) * 2 + 1);
122122
format_bytes((pow(2, 63) - 1) * 2 + 1)
123123
16.00 EiB
124124

125-
## Bad input
125+
## Text input
126126
SELECT format_bytes("foo");
127-
ERROR 22003: Input value is out of range in 'format_bytes'
127+
format_bytes("foo")
128+
0 bytes
129+
Warnings:
130+
Warning 1292 Truncated incorrect DOUBLE value: 'foo'
131+
132+
SELECT format_bytes("");
133+
format_bytes("")
134+
0 bytes
135+
136+
SELECT format_bytes("118059162071741143500099");
137+
format_bytes("118059162071741143500099")
138+
1.02e+05 EiB
128139

140+
SELECT format_bytes("-118059162071741143500099");
141+
format_bytes("-118059162071741143500099")
142+
-1.02e+05 EiB
143+
144+
## Recognizes up to first non-numeric
145+
SELECT format_bytes("40000 * 2000");
146+
format_bytes("40000 * 2000")
147+
39.06 KiB
148+
Warnings:
149+
Warning 1292 Truncated incorrect DOUBLE value: '40000 * 2000'
150+
151+
SELECT format_bytes("40000 foo 2000");
152+
format_bytes("40000 foo 2000")
153+
39.06 KiB
154+
Warnings:
155+
Warning 1292 Truncated incorrect DOUBLE value: '40000 foo 2000'
129156
## Aggregate functions
130157
USE test;
131158

132-
CREATE TABLE memory_counts (id VARCHAR(10), bytes BIGINT(20) UNSIGNED DEFAULT NULL) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
133-
Warnings:
134-
Warning 1681 Integer display width is deprecated and will be removed in a future release.
159+
CREATE TABLE memory_counts (id VARCHAR(10), bytes BIGINT UNSIGNED DEFAULT NULL) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
135160

136161
INSERT INTO memory_counts VALUES ('Bytes', 512);
137162
INSERT INTO memory_counts VALUES ('10 KiB', 10 * 1024);

mysql-test/suite/perfschema/r/native_func_format_time.result

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,41 @@ format_pico_time(8640000000000000000099 * 2)
125125
2.00e+05 d
126126

127127

128-
## Bad input
128+
## Text input
129129
SELECT format_pico_time("foo");
130-
ERROR 22003: Input value is out of range in 'format_pico_time'
130+
format_pico_time("foo")
131+
0 ps
132+
Warnings:
133+
Warning 1292 Truncated incorrect DOUBLE value: 'foo'
134+
135+
SELECT format_pico_time("");
136+
format_pico_time("")
137+
0 ps
138+
139+
SELECT format_pico_time("118059162071741143500099");
140+
format_pico_time("118059162071741143500099")
141+
1.37e+06 d
131142

143+
SELECT format_pico_time("-118059162071741143500099");
144+
format_pico_time("-118059162071741143500099")
145+
-1.37e+06 d
146+
147+
## Recognizes up to first non-numeric
148+
SELECT format_pico_time("40000 * 2000");
149+
format_pico_time("40000 * 2000")
150+
40.00 ns
151+
Warnings:
152+
Warning 1292 Truncated incorrect DOUBLE value: '40000 * 2000'
153+
154+
SELECT format_pico_time("40000 foo 2000");
155+
format_pico_time("40000 foo 2000")
156+
40.00 ns
157+
Warnings:
158+
Warning 1292 Truncated incorrect DOUBLE value: '40000 foo 2000'
132159
## Aggregate functions
133160
USE test;
134161

135-
CREATE TABLE timer_waits (id VARCHAR(10), wait BIGINT(20) UNSIGNED DEFAULT NULL) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
136-
Warnings:
137-
Warning 1681 Integer display width is deprecated and will be removed in a future release.
162+
CREATE TABLE timer_waits (id VARCHAR(10), wait BIGINT UNSIGNED DEFAULT NULL) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
138163

139164
INSERT INTO timer_waits VALUES ('1 sec', 1000000000000);
140165
INSERT INTO timer_waits VALUES ('1 min', 60000000000000);

mysql-test/suite/perfschema/t/native_func_format_bytes.test

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,24 @@ SELECT format_bytes(pow(2,400));
7171
SELECT format_bytes((pow(2, 63) - 1) * 2 + 1);
7272

7373
--echo
74-
--echo ## Bad input
75-
--error ER_DATA_OUT_OF_RANGE
74+
--echo ## Text input
7675
SELECT format_bytes("foo");
7776
--echo
77+
SELECT format_bytes("");
78+
--echo
79+
SELECT format_bytes("118059162071741143500099");
80+
--echo
81+
SELECT format_bytes("-118059162071741143500099");
82+
--echo
83+
--echo ## Recognizes up to first non-numeric
84+
SELECT format_bytes("40000 * 2000");
85+
--echo
86+
SELECT format_bytes("40000 foo 2000");
7887

7988
--echo ## Aggregate functions
8089
USE test;
8190
--echo
82-
CREATE TABLE memory_counts (id VARCHAR(10), bytes BIGINT(20) UNSIGNED DEFAULT NULL) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
91+
CREATE TABLE memory_counts (id VARCHAR(10), bytes BIGINT UNSIGNED DEFAULT NULL) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
8392
--echo
8493
# Max BIGINT unsigned is 18 446 744 073 709 551 615
8594
INSERT INTO memory_counts VALUES ('Bytes', 512);

mysql-test/suite/perfschema/t/native_func_format_time.test

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,24 @@ SELECT format_pico_time(8640000000000000000099 * 2);
6969
--echo
7070

7171
--echo
72-
--echo ## Bad input
73-
--error ER_DATA_OUT_OF_RANGE
72+
--echo ## Text input
7473
SELECT format_pico_time("foo");
7574
--echo
75+
SELECT format_pico_time("");
76+
--echo
77+
SELECT format_pico_time("118059162071741143500099");
78+
--echo
79+
SELECT format_pico_time("-118059162071741143500099");
80+
--echo
81+
--echo ## Recognizes up to first non-numeric
82+
SELECT format_pico_time("40000 * 2000");
83+
--echo
84+
SELECT format_pico_time("40000 foo 2000");
7685

7786
--echo ## Aggregate functions
7887
USE test;
7988
--echo
80-
CREATE TABLE timer_waits (id VARCHAR(10), wait BIGINT(20) UNSIGNED DEFAULT NULL) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
89+
CREATE TABLE timer_waits (id VARCHAR(10), wait BIGINT UNSIGNED DEFAULT NULL) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
8190
--echo
8291
# Max BIGINT unsigned is 18 446 744 073 709 551 615
8392
INSERT INTO timer_waits VALUES ('1 sec', 1000000000000);

mysql-test/suite/sysschema/r/all_sys_objects_exist.result

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,10 @@ SELECT ROUTINE_NAME, ROUTINE_TYPE FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE
106106
ROUTINE_NAME ROUTINE_TYPE
107107
extract_schema_from_file_name FUNCTION
108108
extract_table_from_file_name FUNCTION
109+
format_bytes_orig FUNCTION
109110
format_path FUNCTION
110111
format_statement FUNCTION
112+
format_time FUNCTION
111113
list_add FUNCTION
112114
list_drop FUNCTION
113115
ps_is_account_enabled FUNCTION
@@ -116,6 +118,7 @@ ps_is_instrument_default_enabled FUNCTION
116118
ps_is_instrument_default_timed FUNCTION
117119
ps_is_thread_instrumented FUNCTION
118120
ps_thread_account FUNCTION
121+
ps_thread_id FUNCTION
119122
ps_thread_stack FUNCTION
120123
ps_thread_trx_info FUNCTION
121124
quote_identifier FUNCTION

scripts/sys_schema/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,18 @@ SET(SYS_SCHEMA_SOURCES
3737

3838
functions/extract_schema_from_file_name.sql
3939
functions/extract_table_from_file_name.sql
40+
functions/format_bytes.sql
4041
functions/format_path.sql
4142
functions/format_statement.sql
43+
functions/format_time.sql
4244
functions/list_add.sql
4345
functions/list_drop.sql
4446
functions/ps_is_account_enabled.sql
4547
functions/ps_is_consumer_enabled.sql
4648
functions/ps_is_instrument_default_enabled.sql
4749
functions/ps_is_instrument_default_timed.sql
4850
functions/ps_is_thread_instrumented.sql
51+
functions/ps_thread_id.sql
4952
functions/ps_thread_account.sql
5053
functions/ps_thread_stack.sql
5154
functions/ps_thread_trx_info.sql
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
-- Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
2+
--
3+
-- This program is free software; you can redistribute it and/or modify
4+
-- it under the terms of the GNU General Public License as published by
5+
-- the Free Software Foundation; version 2 of the License.
6+
--
7+
-- This program is distributed in the hope that it will be useful,
8+
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
-- GNU General Public License for more details.
11+
--
12+
-- You should have received a copy of the GNU General Public License
13+
-- 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+
DROP FUNCTION IF EXISTS sys.format_bytes;
17+
18+
DELIMITER $$
19+
20+
CREATE DEFINER='mysql.sys'@'localhost' FUNCTION sys.format_bytes (
21+
-- We feed in and return TEXT here, as aggregates of
22+
-- bytes can return numbers larger than BIGINT UNSIGNED
23+
bytes TEXT
24+
)
25+
RETURNS TEXT
26+
COMMENT '
27+
Description
28+
-----------
29+
30+
Takes a raw bytes value, and converts it to a human readable format.
31+
32+
Parameters
33+
-----------
34+
35+
bytes (TEXT):
36+
A raw bytes value.
37+
38+
Returns
39+
-----------
40+
41+
TEXT
42+
43+
Example
44+
-----------
45+
46+
mysql> SELECT sys.format_bytes(2348723492723746) AS size;
47+
+----------+
48+
| size |
49+
+----------+
50+
| 2.09 PiB |
51+
+----------+
52+
1 row in set (0.00 sec)
53+
54+
mysql> SELECT sys.format_bytes(2348723492723) AS size;
55+
+----------+
56+
| size |
57+
+----------+
58+
| 2.14 TiB |
59+
+----------+
60+
1 row in set (0.00 sec)
61+
62+
mysql> SELECT sys.format_bytes(23487234) AS size;
63+
+-----------+
64+
| size |
65+
+-----------+
66+
| 22.40 MiB |
67+
+-----------+
68+
1 row in set (0.00 sec)
69+
'
70+
SQL SECURITY INVOKER
71+
DETERMINISTIC
72+
NO SQL
73+
BEGIN
74+
IF (bytes IS NULL) THEN
75+
RETURN NULL;
76+
ELSE
77+
RETURN format_bytes(bytes);
78+
END IF;
79+
END$$
80+
81+
DELIMITER ;
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
-- Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
2+
--
3+
-- This program is free software; you can redistribute it and/or modify
4+
-- it under the terms of the GNU General Public License as published by
5+
-- the Free Software Foundation; version 2 of the License.
6+
--
7+
-- This program is distributed in the hope that it will be useful,
8+
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
-- GNU General Public License for more details.
11+
--
12+
-- You should have received a copy of the GNU General Public License
13+
-- 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+
DROP FUNCTION IF EXISTS sys.format_time;
17+
18+
DELIMITER $$
19+
20+
CREATE DEFINER='mysql.sys'@'localhost' FUNCTION sys.format_time (
21+
-- We feed in and return TEXT here, as aggregates of
22+
-- picoseconds can return numbers larger than BIGINT UNSIGNED
23+
picoseconds TEXT
24+
)
25+
RETURNS TEXT CHARSET UTF8MB4
26+
COMMENT '
27+
Description
28+
-----------
29+
30+
Takes a raw picoseconds value, and converts it to a human readable form.
31+
32+
Picoseconds are the precision that all latency values are printed in
33+
within Performance Schema, however are not user friendly when wanting
34+
to scan output from the command line.
35+
36+
Parameters
37+
-----------
38+
39+
picoseconds (TEXT):
40+
The raw picoseconds value to convert.
41+
42+
Returns
43+
-----------
44+
45+
TEXT CHARSET UTF8MB4
46+
47+
Example
48+
-----------
49+
50+
mysql> select format_time(342342342342345);
51+
+------------------------------+
52+
| format_time(342342342342345) |
53+
+------------------------------+
54+
| 00:05:42 |
55+
+------------------------------+
56+
1 row in set (0.00 sec)
57+
58+
mysql> select format_time(342342342);
59+
+------------------------+
60+
| format_time(342342342) |
61+
+------------------------+
62+
| 342.34 us |
63+
+------------------------+
64+
1 row in set (0.00 sec)
65+
66+
mysql> select format_time(34234);
67+
+--------------------+
68+
| format_time(34234) |
69+
+--------------------+
70+
| 34.23 ns |
71+
+--------------------+
72+
1 row in set (0.00 sec)
73+
'
74+
SQL SECURITY INVOKER
75+
DETERMINISTIC
76+
NO SQL
77+
BEGIN
78+
IF picoseconds IS NULL THEN RETURN NULL;
79+
ELSEIF picoseconds >= 604800000000000000 THEN RETURN CONCAT(ROUND(picoseconds / 604800000000000000, 2), ' w');
80+
ELSEIF picoseconds >= 86400000000000000 THEN RETURN CONCAT(ROUND(picoseconds / 86400000000000000, 2), ' d');
81+
ELSEIF picoseconds >= 3600000000000000 THEN RETURN CONCAT(ROUND(picoseconds / 3600000000000000, 2), ' h');
82+
ELSEIF picoseconds >= 60000000000000 THEN RETURN CONCAT(ROUND(picoseconds / 60000000000000, 2), ' m');
83+
ELSEIF picoseconds >= 1000000000000 THEN RETURN CONCAT(ROUND(picoseconds / 1000000000000, 2), ' s');
84+
ELSEIF picoseconds >= 1000000000 THEN RETURN CONCAT(ROUND(picoseconds / 1000000000, 2), ' ms');
85+
ELSEIF picoseconds >= 1000000 THEN RETURN CONCAT(ROUND(picoseconds / 1000000, 2), ' us');
86+
ELSEIF picoseconds >= 1000 THEN RETURN CONCAT(ROUND(picoseconds / 1000, 2), ' ns');
87+
ELSE RETURN CONCAT(picoseconds, ' ps');
88+
END IF;
89+
END$$
90+
91+
DELIMITER ;

0 commit comments

Comments
 (0)