|
| 1 | +# MDEV-19629: Implement MySQL 8.0 native functions: format_bytes(), format_pico_time() and ps_thread_id() |
| 2 | +# |
| 3 | +# Tests for the Performance Schema native function format_pico_time() |
| 4 | +# |
| 5 | + |
| 6 | +SELECT format_pico_time(NULL); |
| 7 | +format_pico_time(NULL) |
| 8 | +NULL |
| 9 | + |
| 10 | +SELECT format_pico_time(0); |
| 11 | +format_pico_time(0) |
| 12 | + 0 ps |
| 13 | + |
| 14 | +SELECT format_pico_time(1); |
| 15 | +format_pico_time(1) |
| 16 | + 1 ps |
| 17 | + |
| 18 | +SELECT format_pico_time(999); |
| 19 | +format_pico_time(999) |
| 20 | +999 ps |
| 21 | + |
| 22 | +SELECT format_pico_time(1000); |
| 23 | +format_pico_time(1000) |
| 24 | +1.00 ns |
| 25 | + |
| 26 | +SELECT format_pico_time(1001); |
| 27 | +format_pico_time(1001) |
| 28 | +1.00 ns |
| 29 | + |
| 30 | +SELECT format_pico_time(999999); |
| 31 | +format_pico_time(999999) |
| 32 | +1000.00 ns |
| 33 | + |
| 34 | +SELECT format_pico_time(1000000); |
| 35 | +format_pico_time(1000000) |
| 36 | +1.00 us |
| 37 | + |
| 38 | +SELECT format_pico_time(1000001); |
| 39 | +format_pico_time(1000001) |
| 40 | +1.00 us |
| 41 | + |
| 42 | +SELECT format_pico_time(1010000); |
| 43 | +format_pico_time(1010000) |
| 44 | +1.01 us |
| 45 | + |
| 46 | +SELECT format_pico_time(987654321); |
| 47 | +format_pico_time(987654321) |
| 48 | +987.65 us |
| 49 | + |
| 50 | +SELECT format_pico_time(1000000000); |
| 51 | +format_pico_time(1000000000) |
| 52 | +1.00 ms |
| 53 | + |
| 54 | +SELECT format_pico_time(999876000000); |
| 55 | +format_pico_time(999876000000) |
| 56 | +999.88 ms |
| 57 | + |
| 58 | +SELECT format_pico_time(999999999999); |
| 59 | +format_pico_time(999999999999) |
| 60 | +1000.00 ms |
| 61 | + |
| 62 | +SELECT format_pico_time(1000000000000); |
| 63 | +format_pico_time(1000000000000) |
| 64 | +1.00 s |
| 65 | + |
| 66 | +SELECT format_pico_time(59000000000000); |
| 67 | +format_pico_time(59000000000000) |
| 68 | +59.00 s |
| 69 | + |
| 70 | +SELECT format_pico_time(60000000000000); |
| 71 | +format_pico_time(60000000000000) |
| 72 | +1.00 min |
| 73 | + |
| 74 | +SELECT format_pico_time(3549000000000000); |
| 75 | +format_pico_time(3549000000000000) |
| 76 | +59.15 min |
| 77 | + |
| 78 | +SELECT format_pico_time(3599000000000000); |
| 79 | +format_pico_time(3599000000000000) |
| 80 | +59.98 min |
| 81 | + |
| 82 | +SELECT format_pico_time(3600000000000000); |
| 83 | +format_pico_time(3600000000000000) |
| 84 | +1.00 h |
| 85 | + |
| 86 | +SELECT format_pico_time(power(2, 63)); |
| 87 | +format_pico_time(power(2, 63)) |
| 88 | +106.75 d |
| 89 | + |
| 90 | +SELECT format_pico_time((power(2, 63) - 1) * 2 + 1); |
| 91 | +format_pico_time((power(2, 63) - 1) * 2 + 1) |
| 92 | +213.50 d |
| 93 | + |
| 94 | +SELECT format_pico_time(36000000.495523); |
| 95 | +format_pico_time(36000000.495523) |
| 96 | +36.00 us |
| 97 | + |
| 98 | +SELECT format_pico_time(1000 * pow(10,12) * 86400); |
| 99 | +format_pico_time(1000 * pow(10,12) * 86400) |
| 100 | +1000.00 d |
| 101 | + |
| 102 | +SELECT format_pico_time(86400000000000000000); |
| 103 | +format_pico_time(86400000000000000000) |
| 104 | +1000.00 d |
| 105 | + |
| 106 | +SELECT format_pico_time(86400000000000000000+5000); |
| 107 | +format_pico_time(86400000000000000000+5000) |
| 108 | +1000.00 d |
| 109 | + |
| 110 | +## Negative values are ok |
| 111 | +SELECT format_pico_time(1010000 * -1); |
| 112 | +format_pico_time(1010000 * -1) |
| 113 | +-1.01 us |
| 114 | + |
| 115 | +## Force exponent |
| 116 | +SELECT format_pico_time(8650000000000000000099); |
| 117 | +format_pico_time(8650000000000000000099) |
| 118 | +1.00e+05 d |
| 119 | + |
| 120 | +SELECT format_pico_time(-8650000000000000000099); |
| 121 | +format_pico_time(-8650000000000000000099) |
| 122 | +-1.00e+05 d |
| 123 | + |
| 124 | +SELECT format_pico_time(8640000000000000000099 * 2); |
| 125 | +format_pico_time(8640000000000000000099 * 2) |
| 126 | +2.00e+05 d |
| 127 | + |
| 128 | + |
| 129 | +## Text input |
| 130 | +SELECT format_pico_time("foo"); |
| 131 | +format_pico_time("foo") |
| 132 | + 0 ps |
| 133 | +Warnings: |
| 134 | +Warning 1292 Truncated incorrect DOUBLE value: 'foo' |
| 135 | + |
| 136 | +SELECT format_pico_time(""); |
| 137 | +format_pico_time("") |
| 138 | + 0 ps |
| 139 | +Warnings: |
| 140 | +Warning 1292 Truncated incorrect DOUBLE value: '' |
| 141 | + |
| 142 | +SELECT format_pico_time("118059162071741143500099"); |
| 143 | +format_pico_time("118059162071741143500099") |
| 144 | +1.37e+06 d |
| 145 | + |
| 146 | +SELECT format_pico_time("-118059162071741143500099"); |
| 147 | +format_pico_time("-118059162071741143500099") |
| 148 | +-1.37e+06 d |
| 149 | + |
| 150 | +## Recognizes up to first non-numeric |
| 151 | +SELECT format_pico_time("40000 * 2000"); |
| 152 | +format_pico_time("40000 * 2000") |
| 153 | +40.00 ns |
| 154 | +Warnings: |
| 155 | +Warning 1292 Truncated incorrect DOUBLE value: '40000 * 2000' |
| 156 | + |
| 157 | +SELECT format_pico_time("40000 foo 2000"); |
| 158 | +format_pico_time("40000 foo 2000") |
| 159 | +40.00 ns |
| 160 | +Warnings: |
| 161 | +Warning 1292 Truncated incorrect DOUBLE value: '40000 foo 2000' |
| 162 | +## Aggregate functions |
| 163 | +USE test; |
| 164 | + |
| 165 | +CREATE TABLE timer_waits (id VARCHAR(10), wait BIGINT UNSIGNED DEFAULT NULL) DEFAULT CHARSET = utf8mb4; |
| 166 | + |
| 167 | +INSERT INTO timer_waits VALUES ('1 sec', 1000000000000); |
| 168 | +INSERT INTO timer_waits VALUES ('1 min', 60000000000000); |
| 169 | +INSERT INTO timer_waits VALUES ('1 hour', 3600000000000000); |
| 170 | +INSERT INTO timer_waits VALUES ('1 day', 86400000000000000); |
| 171 | +INSERT INTO timer_waits VALUES ('100 days', 8640000000000000000); |
| 172 | + |
| 173 | +SELECT id, format_pico_time(wait), wait FROM timer_waits; |
| 174 | +id format_pico_time(wait) wait |
| 175 | +1 sec 1.00 s 1000000000000 |
| 176 | +1 min 1.00 min 60000000000000 |
| 177 | +1 hour 1.00 h 3600000000000000 |
| 178 | +1 day 1.00 d 86400000000000000 |
| 179 | +100 days 100.00 d 8640000000000000000 |
| 180 | + |
| 181 | +SELECT sum(wait), format_pico_time(sum(wait)) FROM timer_waits; |
| 182 | +sum(wait) format_pico_time(sum(wait)) |
| 183 | +8730061000000000000 101.04 d |
| 184 | + |
| 185 | +SELECT avg(wait), format_pico_time(avg(wait)) FROM timer_waits; |
| 186 | +avg(wait) format_pico_time(avg(wait)) |
| 187 | +1746012200000000000.0000 20.21 d |
| 188 | + |
| 189 | +SELECT min(wait), format_pico_time(min(wait)) FROM timer_waits; |
| 190 | +min(wait) format_pico_time(min(wait)) |
| 191 | +1000000000000 1.00 s |
| 192 | + |
| 193 | +SELECT max(wait), format_pico_time(max(wait)) FROM timer_waits; |
| 194 | +max(wait) format_pico_time(max(wait)) |
| 195 | +8640000000000000000 100.00 d |
| 196 | + |
| 197 | +DROP TABLE timer_waits; |
| 198 | +## Using Scientific Notation |
| 199 | +SELECT format_pico_time(3e9); |
| 200 | +format_pico_time(3e9) |
| 201 | +3.00 ms |
| 202 | + |
| 203 | +SELECT format_pico_time(4e6); |
| 204 | +format_pico_time(4e6) |
| 205 | +4.00 us |
| 206 | + |
| 207 | +SELECT format_pico_time(5e3); |
| 208 | +format_pico_time(5e3) |
| 209 | +5.00 ns |
| 210 | + |
| 211 | +SELECT format_pico_time(6e2); |
| 212 | +format_pico_time(6e2) |
| 213 | +600 ps |
0 commit comments