| 1 |
# |
| 2 |
# Tests for the Performance Schema native function format_bytes() |
| 3 |
# |
| 4 |
|
| 5 |
SELECT format_bytes(NULL); |
| 6 |
format_bytes(NULL) |
| 7 |
NULL |
| 8 |
|
| 9 |
SELECT format_bytes(0); |
| 10 |
format_bytes(0) |
| 11 |
0 bytes |
| 12 |
|
| 13 |
SELECT format_bytes(1); |
| 14 |
format_bytes(1) |
| 15 |
1 bytes |
| 16 |
|
| 17 |
SELECT format_bytes(1023); |
| 18 |
format_bytes(1023) |
| 19 |
1023 bytes |
| 20 |
|
| 21 |
SELECT format_bytes(1024); |
| 22 |
format_bytes(1024) |
| 23 |
1.00 KiB |
| 24 |
|
| 25 |
SELECT format_bytes(1025); |
| 26 |
format_bytes(1025) |
| 27 |
1.00 KiB |
| 28 |
|
| 29 |
SELECT format_bytes(1024 * 1024 - 200); |
| 30 |
format_bytes(1024 * 1024 - 200) |
| 31 |
1023.80 KiB |
| 32 |
|
| 33 |
SELECT format_bytes(1024 * 1024 - 1); |
| 34 |
format_bytes(1024 * 1024 - 1) |
| 35 |
1024.00 KiB |
| 36 |
|
| 37 |
SELECT format_bytes(1024 * 1024); |
| 38 |
format_bytes(1024 * 1024) |
| 39 |
1.00 MiB |
| 40 |
|
| 41 |
SELECT format_bytes(1024 * 1024 + 1); |
| 42 |
format_bytes(1024 * 1024 + 1) |
| 43 |
1.00 MiB |
| 44 |
|
| 45 |
SELECT format_bytes(1024 * 1024 + 200); |
| 46 |
format_bytes(1024 * 1024 + 200) |
| 47 |
1.00 MiB |
| 48 |
|
| 49 |
SELECT format_bytes(1024 * 1024 * 1024 - 1); |
| 50 |
format_bytes(1024 * 1024 * 1024 - 1) |
| 51 |
1024.00 MiB |
| 52 |
|
| 53 |
SELECT format_bytes(1024 * 1024 * 1024); |
| 54 |
format_bytes(1024 * 1024 * 1024) |
| 55 |
1.00 GiB |
| 56 |
|
| 57 |
SELECT format_bytes(1024 * 1024 * 1024 + 1); |
| 58 |
format_bytes(1024 * 1024 * 1024 + 1) |
| 59 |
1.00 GiB |
| 60 |
|
| 61 |
SELECT format_bytes(1024 * 1024 * 1024 * 1024 - 1); |
| 62 |
format_bytes(1024 * 1024 * 1024 * 1024 - 1) |
| 63 |
1024.00 GiB |
| 64 |
|
| 65 |
SELECT format_bytes(1024 * 1024 * 1024 * 1024); |
| 66 |
format_bytes(1024 * 1024 * 1024 * 1024) |
| 67 |
1.00 TiB |
| 68 |
|
| 69 |
SELECT format_bytes(1024 * 1024 * 1024 * 1024 + 1); |
| 70 |
format_bytes(1024 * 1024 * 1024 * 1024 + 1) |
| 71 |
1.00 TiB |
| 72 |
|
| 73 |
SELECT format_bytes(1024 * 1024 * 1024 * 1024 * 1024 - 1); |
| 74 |
format_bytes(1024 * 1024 * 1024 * 1024 * 1024 - 1) |
| 75 |
1024.00 TiB |
| 76 |
|
| 77 |
SELECT format_bytes(1024 * 1024 * 1024 * 1024 * 1024); |
| 78 |
format_bytes(1024 * 1024 * 1024 * 1024 * 1024) |
| 79 |
1.00 PiB |
| 80 |
|
| 81 |
SELECT format_bytes(1024 * 1024 * 1024 * 1024 * 1024 + 1); |
| 82 |
format_bytes(1024 * 1024 * 1024 * 1024 * 1024 + 1) |
| 83 |
1.00 PiB |
| 84 |
|
| 85 |
SELECT format_bytes(power(2, 63)); |
| 86 |
format_bytes(power(2, 63)) |
| 87 |
8.00 EiB |
| 88 |
|
| 89 |
## 1024^6 Eib |
| 90 |
SELECT format_bytes(1152921504606846976-1); |
| 91 |
format_bytes(1152921504606846976-1) |
| 92 |
1.00 EiB |
| 93 |
|
| 94 |
SELECT format_bytes(x'1000000000000000'-1); |
| 95 |
format_bytes(x'1000000000000000'-1) |
| 96 |
1.00 EiB |
| 97 |
|
| 98 |
SELECT format_bytes(1180591620717411434000); |
| 99 |
format_bytes(1180591620717411434000) |
| 100 |
1024.00 EiB |
| 101 |
|
| 102 |
## Negative values are ok |
| 103 |
SELECT format_bytes(1024 * 1024 * -1); |
| 104 |
format_bytes(1024 * 1024 * -1) |
| 105 |
-1.00 MiB |
| 106 |
|
| 107 |
## Force exponent format |
| 108 |
SELECT format_bytes(118059162071741143500099); |
| 109 |
format_bytes(118059162071741143500099) |
| 110 |
1.02e+05 EiB |
| 111 |
|
| 112 |
SELECT format_bytes(-118059162071741143500099); |
| 113 |
format_bytes(-118059162071741143500099) |
| 114 |
-1.02e+05 EiB |
| 115 |
|
| 116 |
SELECT format_bytes(pow(2,400)); |
| 117 |
format_bytes(pow(2,400)) |
| 118 |
2.24e+102 EiB |
| 119 |
|
| 120 |
## Valid hybrid number |
| 121 |
SELECT format_bytes((pow(2, 63) - 1) * 2 + 1); |
| 122 |
format_bytes((pow(2, 63) - 1) * 2 + 1) |
| 123 |
16.00 EiB |
| 124 |
|
| 125 |
## Text input |
| 126 |
SELECT format_bytes("foo"); |
| 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 |
| 139 |
|
| 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' |
| 156 |
## Aggregate functions |
| 157 |
USE test; |
| 158 |
|
| 159 |
CREATE TABLE memory_counts (id VARCHAR(10), bytes BIGINT UNSIGNED DEFAULT NULL) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4; |
| 160 |
|
| 161 |
INSERT INTO memory_counts VALUES ('Bytes', 512); |
| 162 |
INSERT INTO memory_counts VALUES ('10 KiB', 10 * 1024); |
| 163 |
INSERT INTO memory_counts VALUES ('20 MiB', 20 * pow(1024,2)); |
| 164 |
|
| 165 |
SELECT sum(bytes), format_bytes(sum(bytes)) FROM memory_counts; |
| 166 |
sum(bytes) format_bytes(sum(bytes)) |
| 167 |
20982272 20.01 MiB |
| 168 |
|
| 169 |
INSERT INTO memory_counts VALUES ('30 GiB', 30 * pow(1024,3)); |
| 170 |
|
| 171 |
SELECT sum(bytes), format_bytes(sum(bytes)) FROM memory_counts; |
| 172 |
sum(bytes) format_bytes(sum(bytes)) |
| 173 |
32233236992 30.02 GiB |
| 174 |
|
| 175 |
INSERT INTO memory_counts VALUES ('40 TiB', 40 * pow(1024,4)); |
| 176 |
|
| 177 |
SELECT sum(bytes), format_bytes(sum(bytes)) FROM memory_counts; |
| 178 |
sum(bytes) format_bytes(sum(bytes)) |
| 179 |
44012698348032 40.03 TiB |
| 180 |
|
| 181 |
INSERT INTO memory_counts VALUES ('50 PiB', 50 * pow(1024,5)); |
| 182 |
|
| 183 |
SELECT sum(bytes), format_bytes(sum(bytes)) FROM memory_counts; |
| 184 |
sum(bytes) format_bytes(sum(bytes)) |
| 185 |
56339008040479232 50.04 PiB |
| 186 |
|
| 187 |
INSERT INTO memory_counts VALUES ('1 EiB', pow(1024,6)); |
| 188 |
|
| 189 |
SELECT id, format_bytes(bytes), bytes FROM memory_counts; |
| 190 |
id format_bytes(bytes) bytes |
| 191 |
Bytes 512 bytes 512 |
| 192 |
10 KiB 10.00 KiB 10240 |
| 193 |
20 MiB 20.00 MiB 20971520 |
| 194 |
30 GiB 30.00 GiB 32212254720 |
| 195 |
40 TiB 40.00 TiB 43980465111040 |
| 196 |
50 PiB 50.00 PiB 56294995342131200 |
| 197 |
1 EiB 1.00 EiB 1152921504606846976 |
| 198 |
|
| 199 |
SELECT sum(bytes), format_bytes(sum(bytes)) FROM memory_counts; |
| 200 |
sum(bytes) format_bytes(sum(bytes)) |
| 201 |
1209260512647326208 1.05 EiB |
| 202 |
|
| 203 |
SELECT avg(bytes), format_bytes(avg(bytes)) FROM memory_counts; |
| 204 |
avg(bytes) format_bytes(avg(bytes)) |
| 205 |
172751501806760886.8571 153.43 PiB |
| 206 |
|
| 207 |
SELECT max(bytes), format_bytes(max(bytes)) FROM memory_counts; |
| 208 |
max(bytes) format_bytes(max(bytes)) |
| 209 |
1152921504606846976 1.00 EiB |
| 210 |
|
| 211 |
SELECT min(bytes), format_bytes(min(bytes)) FROM memory_counts; |
| 212 |
min(bytes) format_bytes(min(bytes)) |
| 213 |
512 512 bytes |
| 214 |
|
| 215 |
DROP TABLE memory_counts; |
| 216 |
|
| 217 |
## Handling of NULL (bug#30525561) |
| 218 |
SELECT mybytes, |
| 219 |
FORMAT_BYTES(mybytes) AS PS_BYTES, |
| 220 |
sys.format_bytes(mybytes) AS SYS_BYTES |
| 221 |
FROM (SELECT 1234 AS mybytes |
| 222 |
UNION ALL |
| 223 |
SELECT 1234567890 |
| 224 |
UNION ALL |
| 225 |
SELECT NULL |
| 226 |
UNION ALL |
| 227 |
SELECT 1234 |
| 228 |
UNION ALL |
| 229 |
SELECT 1234567890 |
| 230 |
) t; |
| 231 |
mybytes PS_BYTES SYS_BYTES |
| 232 |
1234 1.21 KiB 1.21 KiB |
| 233 |
1234567890 1.15 GiB 1.15 GiB |
| 234 |
NULL NULL NULL |
| 235 |
1234 1.21 KiB 1.21 KiB |
| 236 |
1234567890 1.15 GiB 1.15 GiB |
| 237 |
Warnings: |
| 238 |
Note 1585 This function 'format_bytes' has the same name as a native function |