Skip to content

Commit d9808f7

Browse files
ahmedibrahim404an3l
authored andcommitted
MDEV-19629: format_pico_time implementation
1 parent 31487f4 commit d9808f7

File tree

8 files changed

+548
-2
lines changed

8 files changed

+548
-2
lines changed

libmysqld/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ SET(SQL_EMBEDDED_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc
6464
../sql/item.cc ../sql/item_create.cc ../sql/item_func.cc
6565
../sql/item_geofunc.cc ../sql/item_row.cc ../sql/item_strfunc.cc
6666
../sql/item_subselect.cc ../sql/item_sum.cc ../sql/item_timefunc.cc
67-
../sql/item_xmlfunc.cc ../sql/item_jsonfunc.cc
67+
../sql/item_xmlfunc.cc ../sql/item_jsonfunc.cc ../sql/item_pfsfunc.cc
6868
../sql/key.cc ../sql/lock.cc ../sql/log.cc
6969
../sql/log_event.cc ../sql/log_event_server.cc
7070
../sql/mf_iocache.cc ../sql/my_decimal.cc
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
# MDEV-19629: Implement MySQL 8.0 native functions: format_bytes(), format_pico_time() and ps_thread_id()
2+
#
3+
# Tests for the Performance Schema native function format_pico_time()
4+
#
5+
6+
SELECT format_pico_time(NULL);
7+
format_pico_time(NULL)
8+
NULL
9+
10+
SELECT format_pico_time(0);
11+
format_pico_time(0)
12+
0 ps
13+
14+
SELECT format_pico_time(1);
15+
format_pico_time(1)
16+
1 ps
17+
18+
SELECT format_pico_time(999);
19+
format_pico_time(999)
20+
999 ps
21+
22+
SELECT format_pico_time(1000);
23+
format_pico_time(1000)
24+
1.00 ns
25+
26+
SELECT format_pico_time(1001);
27+
format_pico_time(1001)
28+
1.00 ns
29+
30+
SELECT format_pico_time(999999);
31+
format_pico_time(999999)
32+
1000.00 ns
33+
34+
SELECT format_pico_time(1000000);
35+
format_pico_time(1000000)
36+
1.00 us
37+
38+
SELECT format_pico_time(1000001);
39+
format_pico_time(1000001)
40+
1.00 us
41+
42+
SELECT format_pico_time(1010000);
43+
format_pico_time(1010000)
44+
1.01 us
45+
46+
SELECT format_pico_time(987654321);
47+
format_pico_time(987654321)
48+
987.65 us
49+
50+
SELECT format_pico_time(1000000000);
51+
format_pico_time(1000000000)
52+
1.00 ms
53+
54+
SELECT format_pico_time(999876000000);
55+
format_pico_time(999876000000)
56+
999.88 ms
57+
58+
SELECT format_pico_time(999999999999);
59+
format_pico_time(999999999999)
60+
1000.00 ms
61+
62+
SELECT format_pico_time(1000000000000);
63+
format_pico_time(1000000000000)
64+
1.00 s
65+
66+
SELECT format_pico_time(59000000000000);
67+
format_pico_time(59000000000000)
68+
59.00 s
69+
70+
SELECT format_pico_time(60000000000000);
71+
format_pico_time(60000000000000)
72+
1.00 min
73+
74+
SELECT format_pico_time(3549000000000000);
75+
format_pico_time(3549000000000000)
76+
59.15 min
77+
78+
SELECT format_pico_time(3599000000000000);
79+
format_pico_time(3599000000000000)
80+
59.98 min
81+
82+
SELECT format_pico_time(3600000000000000);
83+
format_pico_time(3600000000000000)
84+
1.00 h
85+
86+
SELECT format_pico_time(power(2, 63));
87+
format_pico_time(power(2, 63))
88+
106.75 d
89+
90+
SELECT format_pico_time((power(2, 63) - 1) * 2 + 1);
91+
format_pico_time((power(2, 63) - 1) * 2 + 1)
92+
213.50 d
93+
94+
SELECT format_pico_time(36000000.495523);
95+
format_pico_time(36000000.495523)
96+
36.00 us
97+
98+
SELECT format_pico_time(1000 * pow(10,12) * 86400);
99+
format_pico_time(1000 * pow(10,12) * 86400)
100+
1000.00 d
101+
102+
SELECT format_pico_time(86400000000000000000);
103+
format_pico_time(86400000000000000000)
104+
1000.00 d
105+
106+
SELECT format_pico_time(86400000000000000000+5000);
107+
format_pico_time(86400000000000000000+5000)
108+
1000.00 d
109+
110+
## Negative values are ok
111+
SELECT format_pico_time(1010000 * -1);
112+
format_pico_time(1010000 * -1)
113+
-1.01 us
114+
115+
## Force exponent
116+
SELECT format_pico_time(8650000000000000000099);
117+
format_pico_time(8650000000000000000099)
118+
1.00e+05 d
119+
120+
SELECT format_pico_time(-8650000000000000000099);
121+
format_pico_time(-8650000000000000000099)
122+
-1.00e+05 d
123+
124+
SELECT format_pico_time(8640000000000000000099 * 2);
125+
format_pico_time(8640000000000000000099 * 2)
126+
2.00e+05 d
127+
128+
129+
## Text input
130+
SELECT format_pico_time("foo");
131+
format_pico_time("foo")
132+
0 ps
133+
Warnings:
134+
Warning 1292 Truncated incorrect DOUBLE value: 'foo'
135+
136+
SELECT format_pico_time("");
137+
format_pico_time("")
138+
0 ps
139+
Warnings:
140+
Warning 1292 Truncated incorrect DOUBLE value: ''
141+
142+
SELECT format_pico_time("118059162071741143500099");
143+
format_pico_time("118059162071741143500099")
144+
1.37e+06 d
145+
146+
SELECT format_pico_time("-118059162071741143500099");
147+
format_pico_time("-118059162071741143500099")
148+
-1.37e+06 d
149+
150+
## Recognizes up to first non-numeric
151+
SELECT format_pico_time("40000 * 2000");
152+
format_pico_time("40000 * 2000")
153+
40.00 ns
154+
Warnings:
155+
Warning 1292 Truncated incorrect DOUBLE value: '40000 * 2000'
156+
157+
SELECT format_pico_time("40000 foo 2000");
158+
format_pico_time("40000 foo 2000")
159+
40.00 ns
160+
Warnings:
161+
Warning 1292 Truncated incorrect DOUBLE value: '40000 foo 2000'
162+
## Aggregate functions
163+
USE test;
164+
165+
CREATE TABLE timer_waits (id VARCHAR(10), wait BIGINT UNSIGNED DEFAULT NULL) DEFAULT CHARSET = utf8mb4;
166+
167+
INSERT INTO timer_waits VALUES ('1 sec', 1000000000000);
168+
INSERT INTO timer_waits VALUES ('1 min', 60000000000000);
169+
INSERT INTO timer_waits VALUES ('1 hour', 3600000000000000);
170+
INSERT INTO timer_waits VALUES ('1 day', 86400000000000000);
171+
INSERT INTO timer_waits VALUES ('100 days', 8640000000000000000);
172+
173+
SELECT id, format_pico_time(wait), wait FROM timer_waits;
174+
id format_pico_time(wait) wait
175+
1 sec 1.00 s 1000000000000
176+
1 min 1.00 min 60000000000000
177+
1 hour 1.00 h 3600000000000000
178+
1 day 1.00 d 86400000000000000
179+
100 days 100.00 d 8640000000000000000
180+
181+
SELECT sum(wait), format_pico_time(sum(wait)) FROM timer_waits;
182+
sum(wait) format_pico_time(sum(wait))
183+
8730061000000000000 101.04 d
184+
185+
SELECT avg(wait), format_pico_time(avg(wait)) FROM timer_waits;
186+
avg(wait) format_pico_time(avg(wait))
187+
1746012200000000000.0000 20.21 d
188+
189+
SELECT min(wait), format_pico_time(min(wait)) FROM timer_waits;
190+
min(wait) format_pico_time(min(wait))
191+
1000000000000 1.00 s
192+
193+
SELECT max(wait), format_pico_time(max(wait)) FROM timer_waits;
194+
max(wait) format_pico_time(max(wait))
195+
8640000000000000000 100.00 d
196+
197+
DROP TABLE timer_waits;
198+
## Using Scientific Notation
199+
SELECT format_pico_time(3e9);
200+
format_pico_time(3e9)
201+
3.00 ms
202+
203+
SELECT format_pico_time(4e6);
204+
format_pico_time(4e6)
205+
4.00 us
206+
207+
SELECT format_pico_time(5e3);
208+
format_pico_time(5e3)
209+
5.00 ns
210+
211+
SELECT format_pico_time(6e2);
212+
format_pico_time(6e2)
213+
600 ps
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Testcases for PFS functions are backported from MySQL
2+
3+
--echo # MDEV-19629: Implement MySQL 8.0 native functions: format_bytes(), format_pico_time() and ps_thread_id()
4+
--echo #
5+
--echo # Tests for the Performance Schema native function format_pico_time()
6+
--echo #
7+
--echo
8+
9+
SELECT format_pico_time(NULL);
10+
--echo
11+
SELECT format_pico_time(0);
12+
--echo
13+
SELECT format_pico_time(1);
14+
--echo
15+
SELECT format_pico_time(999);
16+
--echo
17+
SELECT format_pico_time(1000);
18+
--echo
19+
SELECT format_pico_time(1001);
20+
--echo
21+
SELECT format_pico_time(999999);
22+
--echo
23+
SELECT format_pico_time(1000000);
24+
--echo
25+
SELECT format_pico_time(1000001);
26+
--echo
27+
SELECT format_pico_time(1010000);
28+
--echo
29+
SELECT format_pico_time(987654321);
30+
--echo
31+
SELECT format_pico_time(1000000000);
32+
--echo
33+
SELECT format_pico_time(999876000000);
34+
--echo
35+
SELECT format_pico_time(999999999999);
36+
--echo
37+
SELECT format_pico_time(1000000000000);
38+
--echo
39+
SELECT format_pico_time(59000000000000);
40+
--echo
41+
SELECT format_pico_time(60000000000000);
42+
--echo
43+
SELECT format_pico_time(3549000000000000);
44+
--echo
45+
SELECT format_pico_time(3599000000000000);
46+
--echo
47+
SELECT format_pico_time(3600000000000000);
48+
--echo
49+
SELECT format_pico_time(power(2, 63));
50+
--echo
51+
SELECT format_pico_time((power(2, 63) - 1) * 2 + 1);
52+
--echo
53+
SELECT format_pico_time(36000000.495523);
54+
--echo
55+
SELECT format_pico_time(1000 * pow(10,12) * 86400);
56+
--echo
57+
SELECT format_pico_time(86400000000000000000);
58+
--echo
59+
SELECT format_pico_time(86400000000000000000+5000);
60+
61+
--echo
62+
--echo ## Negative values are ok
63+
SELECT format_pico_time(1010000 * -1);
64+
65+
--echo
66+
--echo ## Force exponent
67+
SELECT format_pico_time(8650000000000000000099);
68+
--echo
69+
SELECT format_pico_time(-8650000000000000000099);
70+
--echo
71+
SELECT format_pico_time(8640000000000000000099 * 2);
72+
--echo
73+
74+
--echo
75+
--echo ## Text input
76+
SELECT format_pico_time("foo");
77+
--echo
78+
SELECT format_pico_time("");
79+
--echo
80+
SELECT format_pico_time("118059162071741143500099");
81+
--echo
82+
SELECT format_pico_time("-118059162071741143500099");
83+
--echo
84+
--echo ## Recognizes up to first non-numeric
85+
SELECT format_pico_time("40000 * 2000");
86+
--echo
87+
SELECT format_pico_time("40000 foo 2000");
88+
89+
--echo ## Aggregate functions
90+
USE test;
91+
--echo
92+
CREATE TABLE timer_waits (id VARCHAR(10), wait BIGINT UNSIGNED DEFAULT NULL) DEFAULT CHARSET = utf8mb4;
93+
--echo
94+
# Max BIGINT unsigned is 18 446 744 073 709 551 615
95+
INSERT INTO timer_waits VALUES ('1 sec', 1000000000000);
96+
INSERT INTO timer_waits VALUES ('1 min', 60000000000000);
97+
INSERT INTO timer_waits VALUES ('1 hour', 3600000000000000);
98+
INSERT INTO timer_waits VALUES ('1 day', 86400000000000000);
99+
INSERT INTO timer_waits VALUES ('100 days', 8640000000000000000);
100+
--echo
101+
SELECT id, format_pico_time(wait), wait FROM timer_waits;
102+
--echo
103+
SELECT sum(wait), format_pico_time(sum(wait)) FROM timer_waits;
104+
--echo
105+
SELECT avg(wait), format_pico_time(avg(wait)) FROM timer_waits;
106+
--echo
107+
SELECT min(wait), format_pico_time(min(wait)) FROM timer_waits;
108+
--echo
109+
SELECT max(wait), format_pico_time(max(wait)) FROM timer_waits;
110+
--echo
111+
DROP TABLE timer_waits;
112+
113+
--echo ## Using Scientific Notation
114+
SELECT format_pico_time(3e9);
115+
--echo
116+
SELECT format_pico_time(4e6);
117+
--echo
118+
SELECT format_pico_time(5e3);
119+
--echo
120+
SELECT format_pico_time(6e2);

sql/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ SET (SQL_SOURCE
104104
handler.cc
105105
hostname.cc init.cc item.cc item_buff.cc item_cmpfunc.cc
106106
item_create.cc item_func.cc item_geofunc.cc item_row.cc
107-
item_strfunc.cc item_subselect.cc item_sum.cc item_timefunc.cc
107+
item_strfunc.cc item_subselect.cc item_sum.cc item_timefunc.cc item_pfsfunc.cc
108108
key.cc log.cc lock.cc
109109
log_event.cc log_event_server.cc
110110
rpl_record.cc rpl_reporting.cc

sql/item.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6371,6 +6371,7 @@ class Item_int_with_ref :public Item_int
63716371
#include "item_jsonfunc.h"
63726372
#include "item_create.h"
63736373
#include "item_vers.h"
6374+
#include "item_pfsfunc.h"
63746375
#endif
63756376

63766377
/**

0 commit comments

Comments
 (0)