File: native_func_format_bytes.test

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (146 lines) | stat: -rw-r--r-- 3,643 bytes parent folder | download
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
--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 ## Text input
SELECT format_bytes("foo");
--echo
SELECT format_bytes("");
--echo
SELECT format_bytes("118059162071741143500099");
--echo
SELECT format_bytes("-118059162071741143500099");
--echo
--echo ## Recognizes up to first non-numeric
SELECT format_bytes("40000 * 2000");
--echo
SELECT format_bytes("40000 foo 2000");

--echo ## Aggregate functions
USE test;
--echo
CREATE TABLE memory_counts (id VARCHAR(10), bytes BIGINT 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;

--echo
--echo ## 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;