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