| 1 |
# |
| 2 |
# Tests for the Performance Schema native function format_pico_time() |
| 3 |
# |
| 4 |
|
| 5 |
SELECT format_pico_time(NULL); |
| 6 |
format_pico_time(NULL) |
| 7 |
NULL |
| 8 |
|
| 9 |
SELECT format_pico_time(0); |
| 10 |
format_pico_time(0) |
| 11 |
0 ps |
| 12 |
|
| 13 |
SELECT format_pico_time(1); |
| 14 |
format_pico_time(1) |
| 15 |
1 ps |
| 16 |
|
| 17 |
SELECT format_pico_time(999); |
| 18 |
format_pico_time(999) |
| 19 |
999 ps |
| 20 |
|
| 21 |
SELECT format_pico_time(1000); |
| 22 |
format_pico_time(1000) |
| 23 |
1.00 ns |
| 24 |
|
| 25 |
SELECT format_pico_time(1001); |
| 26 |
format_pico_time(1001) |
| 27 |
1.00 ns |
| 28 |
|
| 29 |
SELECT format_pico_time(999999); |
| 30 |
format_pico_time(999999) |
| 31 |
1000.00 ns |
| 32 |
|
| 33 |
SELECT format_pico_time(1000000); |
| 34 |
format_pico_time(1000000) |
| 35 |
1.00 us |
| 36 |
|
| 37 |
SELECT format_pico_time(1000001); |
| 38 |
format_pico_time(1000001) |
| 39 |
1.00 us |
| 40 |
|
| 41 |
SELECT format_pico_time(1010000); |
| 42 |
format_pico_time(1010000) |
| 43 |
1.01 us |
| 44 |
|
| 45 |
SELECT format_pico_time(987654321); |
| 46 |
format_pico_time(987654321) |
| 47 |
987.65 us |
| 48 |
|
| 49 |
SELECT format_pico_time(1000000000); |
| 50 |
format_pico_time(1000000000) |
| 51 |
1.00 ms |
| 52 |
|
| 53 |
SELECT format_pico_time(999876000000); |
| 54 |
format_pico_time(999876000000) |
| 55 |
999.88 ms |
| 56 |
|
| 57 |
SELECT format_pico_time(999999999999); |
| 58 |
format_pico_time(999999999999) |
| 59 |
1000.00 ms |
| 60 |
|
| 61 |
SELECT format_pico_time(1000000000000); |
| 62 |
format_pico_time(1000000000000) |
| 63 |
1.00 s |
| 64 |
|
| 65 |
SELECT format_pico_time(59000000000000); |
| 66 |
format_pico_time(59000000000000) |
| 67 |
59.00 s |
| 68 |
|
| 69 |
SELECT format_pico_time(60000000000000); |
| 70 |
format_pico_time(60000000000000) |
| 71 |
1.00 min |
| 72 |
|
| 73 |
SELECT format_pico_time(3549000000000000); |
| 74 |
format_pico_time(3549000000000000) |
| 75 |
59.15 min |
| 76 |
|
| 77 |
SELECT format_pico_time(3599000000000000); |
| 78 |
format_pico_time(3599000000000000) |
| 79 |
59.98 min |
| 80 |
|
| 81 |
SELECT format_pico_time(3600000000000000); |
| 82 |
format_pico_time(3600000000000000) |
| 83 |
1.00 h |
| 84 |
|
| 85 |
SELECT format_pico_time(power(2, 63)); |
| 86 |
format_pico_time(power(2, 63)) |
| 87 |
106.75 d |
| 88 |
|
| 89 |
SELECT format_pico_time((power(2, 63) - 1) * 2 + 1); |
| 90 |
format_pico_time((power(2, 63) - 1) * 2 + 1) |
| 91 |
213.50 d |
| 92 |
|
| 93 |
SELECT format_pico_time(36000000.495523); |
| 94 |
format_pico_time(36000000.495523) |
| 95 |
36.00 us |
| 96 |
|
| 97 |
SELECT format_pico_time(1000 * pow(10,12) * 86400); |
| 98 |
format_pico_time(1000 * pow(10,12) * 86400) |
| 99 |
1000.00 d |
| 100 |
|
| 101 |
SELECT format_pico_time(86400000000000000000); |
| 102 |
format_pico_time(86400000000000000000) |
| 103 |
1000.00 d |
| 104 |
|
| 105 |
SELECT format_pico_time(86400000000000000000+5000); |
| 106 |
format_pico_time(86400000000000000000+5000) |
| 107 |
1000.00 d |
| 108 |
|
| 109 |
## Negative values are ok |
| 110 |
SELECT format_pico_time(1010000 * -1); |
| 111 |
format_pico_time(1010000 * -1) |
| 112 |
-1.01 us |
| 113 |
|
| 114 |
## Force exponent |
| 115 |
SELECT format_pico_time(8650000000000000000099); |
| 116 |
format_pico_time(8650000000000000000099) |
| 117 |
1.00e+05 d |
| 118 |
|
| 119 |
SELECT format_pico_time(-8650000000000000000099); |
| 120 |
format_pico_time(-8650000000000000000099) |
| 121 |
-1.00e+05 d |
| 122 |
|
| 123 |
SELECT format_pico_time(8640000000000000000099 * 2); |
| 124 |
format_pico_time(8640000000000000000099 * 2) |
| 125 |
2.00e+05 d |
| 126 |
|
| 127 |
|
| 128 |
## Text input |
| 129 |
SELECT format_pico_time("foo"); |
| 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 |
| 142 |
|
| 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' |
| 159 |
## Aggregate functions |
| 160 |
USE test; |
| 161 |
|
| 162 |
CREATE TABLE timer_waits (id VARCHAR(10), wait BIGINT UNSIGNED DEFAULT NULL) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; |
| 163 |
|
| 164 |
INSERT INTO timer_waits VALUES ('1 sec', 1000000000000); |
| 165 |
INSERT INTO timer_waits VALUES ('1 min', 60000000000000); |
| 166 |
INSERT INTO timer_waits VALUES ('1 hour', 3600000000000000); |
| 167 |
INSERT INTO timer_waits VALUES ('1 day', 86400000000000000); |
| 168 |
INSERT INTO timer_waits VALUES ('100 days', 8640000000000000000); |
| 169 |
|
| 170 |
SELECT id, format_pico_time(wait), wait FROM timer_waits; |
| 171 |
id format_pico_time(wait) wait |
| 172 |
1 sec 1.00 s 1000000000000 |
| 173 |
1 min 1.00 min 60000000000000 |
| 174 |
1 hour 1.00 h 3600000000000000 |
| 175 |
1 day 1.00 d 86400000000000000 |
| 176 |
100 days 100.00 d 8640000000000000000 |
| 177 |
|
| 178 |
SELECT sum(wait), format_pico_time(sum(wait)) FROM timer_waits; |
| 179 |
sum(wait) format_pico_time(sum(wait)) |
| 180 |
8730061000000000000 101.04 d |
| 181 |
|
| 182 |
SELECT avg(wait), format_pico_time(avg(wait)) FROM timer_waits; |
| 183 |
avg(wait) format_pico_time(avg(wait)) |
| 184 |
1746012200000000000.0000 20.21 d |
| 185 |
|
| 186 |
SELECT min(wait), format_pico_time(min(wait)) FROM timer_waits; |
| 187 |
min(wait) format_pico_time(min(wait)) |
| 188 |
1000000000000 1.00 s |
| 189 |
|
| 190 |
SELECT max(wait), format_pico_time(max(wait)) FROM timer_waits; |
| 191 |
max(wait) format_pico_time(max(wait)) |
| 192 |
8640000000000000000 100.00 d |
| 193 |
|
| 194 |
DROP TABLE timer_waits; |
| 195 |
|
| 196 |
## Handling of NULL (bug#30525561) |
| 197 |
SELECT mytime, |
| 198 |
FORMAT_PICO_TIME(mytime) AS PS_TIME, |
| 199 |
sys.format_time(mytime) AS SYS_TIME |
| 200 |
FROM (SELECT 1234 AS mytime |
| 201 |
UNION ALL |
| 202 |
SELECT 1234567890 |
| 203 |
UNION ALL |
| 204 |
SELECT NULL |
| 205 |
UNION ALL |
| 206 |
SELECT 1234 |
| 207 |
UNION ALL |
| 208 |
SELECT 1234567890 |
| 209 |
) t; |
| 210 |
mytime PS_TIME SYS_TIME |
| 211 |
1234 1.23 ns 1.23 ns |
| 212 |
1234567890 1.23 ms 1.23 ms |
| 213 |
NULL NULL NULL |
| 214 |
1234 1.23 ns 1.23 ns |
| 215 |
1234567890 1.23 ms 1.23 ms |