120 lines
3.0 KiB
Plaintext
120 lines
3.0 KiB
Plaintext
--echo #
|
|
--echo # Tests for the Performance Schema native function format_bytes()
|
|
--echo #
|
|
--echo
|
|
|
|
SELECT format_bytes(NULL);
|
|
--echo
|
|
SELECT format_bytes(0);
|
|
--echo
|
|
SELECT format_bytes(1);
|
|
--echo
|
|
SELECT format_bytes(1023);
|
|
--echo
|
|
SELECT format_bytes(1024);
|
|
--echo
|
|
SELECT format_bytes(1025);
|
|
--echo
|
|
SELECT format_bytes(1024 * 1024 - 200);
|
|
--echo
|
|
SELECT format_bytes(1024 * 1024 - 1);
|
|
--echo
|
|
SELECT format_bytes(1024 * 1024);
|
|
--echo
|
|
SELECT format_bytes(1024 * 1024 + 1);
|
|
--echo
|
|
SELECT format_bytes(1024 * 1024 + 200);
|
|
--echo
|
|
SELECT format_bytes(1024 * 1024 * 1024 - 1);
|
|
--echo
|
|
SELECT format_bytes(1024 * 1024 * 1024);
|
|
--echo
|
|
SELECT format_bytes(1024 * 1024 * 1024 + 1);
|
|
--echo
|
|
SELECT format_bytes(1024 * 1024 * 1024 * 1024 - 1);
|
|
--echo
|
|
SELECT format_bytes(1024 * 1024 * 1024 * 1024);
|
|
--echo
|
|
SELECT format_bytes(1024 * 1024 * 1024 * 1024 + 1);
|
|
--echo
|
|
SELECT format_bytes(1024 * 1024 * 1024 * 1024 * 1024 - 1);
|
|
--echo
|
|
SELECT format_bytes(1024 * 1024 * 1024 * 1024 * 1024);
|
|
--echo
|
|
SELECT format_bytes(1024 * 1024 * 1024 * 1024 * 1024 + 1);
|
|
--echo
|
|
SELECT format_bytes(power(2, 63));
|
|
|
|
--echo
|
|
--echo ## 1024^6 Eib
|
|
SELECT format_bytes(1152921504606846976-1);
|
|
--echo
|
|
SELECT format_bytes(x'1000000000000000'-1);
|
|
|
|
--echo
|
|
SELECT format_bytes(1180591620717411434000);
|
|
|
|
--echo
|
|
--echo ## Negative values are ok
|
|
SELECT format_bytes(1024 * 1024 * -1);
|
|
|
|
--echo
|
|
--echo ## Force exponent format
|
|
SELECT format_bytes(118059162071741143500099);
|
|
--echo
|
|
SELECT format_bytes(-118059162071741143500099);
|
|
--echo
|
|
SELECT format_bytes(pow(2,400));
|
|
|
|
--echo
|
|
--echo ## Valid hybrid number
|
|
SELECT format_bytes((pow(2, 63) - 1) * 2 + 1);
|
|
|
|
--echo
|
|
--echo ## Bad input
|
|
--error ER_DATA_OUT_OF_RANGE
|
|
SELECT format_bytes("foo");
|
|
--echo
|
|
|
|
--echo ## Aggregate functions
|
|
USE test;
|
|
--echo
|
|
CREATE TABLE memory_counts (id VARCHAR(10), bytes BIGINT(20) UNSIGNED DEFAULT NULL) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;
|
|
--echo
|
|
# Max BIGINT unsigned is 18 446 744 073 709 551 615
|
|
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));
|
|
--echo
|
|
SELECT sum(bytes), format_bytes(sum(bytes)) FROM memory_counts;
|
|
|
|
--echo
|
|
INSERT INTO memory_counts VALUES ('30 GiB', 30 * pow(1024,3));
|
|
--echo
|
|
SELECT sum(bytes), format_bytes(sum(bytes)) FROM memory_counts;
|
|
|
|
--echo
|
|
INSERT INTO memory_counts VALUES ('40 TiB', 40 * pow(1024,4));
|
|
--echo
|
|
SELECT sum(bytes), format_bytes(sum(bytes)) FROM memory_counts;
|
|
|
|
--echo
|
|
INSERT INTO memory_counts VALUES ('50 PiB', 50 * pow(1024,5));
|
|
--echo
|
|
SELECT sum(bytes), format_bytes(sum(bytes)) FROM memory_counts;
|
|
|
|
--echo
|
|
INSERT INTO memory_counts VALUES ('1 EiB', pow(1024,6));
|
|
--echo
|
|
SELECT id, format_bytes(bytes), bytes FROM memory_counts;
|
|
--echo
|
|
SELECT sum(bytes), format_bytes(sum(bytes)) FROM memory_counts;
|
|
--echo
|
|
SELECT avg(bytes), format_bytes(avg(bytes)) FROM memory_counts;
|
|
--echo
|
|
SELECT max(bytes), format_bytes(max(bytes)) FROM memory_counts;
|
|
--echo
|
|
SELECT min(bytes), format_bytes(min(bytes)) FROM memory_counts;
|
|
--echo
|
|
DROP TABLE memory_counts;
|