forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit02ddd49
committed
Change floating-point output format for improved performance.
Previously, floating-point output was done by rounding to a specificdecimal precision; by default, to 6 or 15 decimal digits (losinginformation) or as requested using extra_float_digits. Drivers thatwanted exact float values, and applications like pg_dump that mustpreserve values exactly, set extra_float_digits=3 (or sometimes 2 forhistorical reasons, though this isn't enough for float4).Unfortunately, decimal rounded output is slow enough to become anoticable bottleneck when dealing with large result sets or COPY oflarge tables when many floating-point values are involved.Floating-point output can be done much faster when the output is notrounded to a specific decimal length, but rather is chosen as theshortest decimal representation that is closer to the original floatvalue than to any other value representable in the same precision. Therecently published Ryu algorithm by Ulf Adams is both relativelysimple and remarkably fast.Accordingly, change float4out/float8out to output shortest decimalrepresentations if extra_float_digits is greater than 0, and make thatthe new default. Applications that need rounded output can setextra_float_digits back to 0 or below, and take the resultingperformance hit.We make one concession to portability for systems with buggyfloating-point input: we do not output decimal values that fallexactly halfway between adjacent representable binary values (whichwould rely on the reader doing round-to-nearest-even correctly). Thisis known to be a problem at least for VS2013 on Windows.Our version of the Ryu code originates fromhttps://github.com/ulfjack/ryu/ at commit c9c3fb1979, but with thefollowing (significant) modifications: - Output format is changed to use fixed-point notation for small exponents, as printf would, and also to use lowercase 'e', a minimum of 2 exponent digits, and a mandatory sign on the exponent, to keep the formatting as close as possible to previous output. - The output of exact midpoint values is disabled as noted above. - The integer fast-path code is changed somewhat (since we have fixed-point output and the upstream did not). - Our project style has been largely applied to the code with the exception of C99 declaration-after-statement, which has been retained as an exception to our present policy. - Most of upstream's debugging and conditionals are removed, and we use our own configure tests to determine things like uint128 availability.Changing the float output format obviously affects a number ofregression tests. This patch uses an explicit setting ofextra_float_digits=0 for test output that is not expected to beexactly reproducible (e.g. due to numerical instability or differingalgorithms for transcendental functions).Conversions from floats to numeric are unchanged by this patch. Thesemay appear in index expressions and it is not yet clear whether anychange should be made, so that can be left for another day.This patch assumes that the only supported floating point format isnow IEEE format, and the documentation is updated to reflect that.Code by me, adapting the work of Ulf Adams and other contributors.References:https://dl.acm.org/citation.cfm?id=3192369Reviewed-by: Tom Lane, Andres Freund, Donald DongDiscussion:https://postgr.es/m/87r2el1bx6.fsf@news-spur.riddles.org.uk1 parentf397e08 commit02ddd49
File tree
50 files changed
+5466
-368
lines changed- contrib
- btree_gist/expected
- cube
- expected
- sql
- pg_trgm
- expected
- sql
- seg/expected
- doc/src/sgml
- src
- backend/utils
- adt
- misc
- common
- include/common
- test/regress
- expected
- sql
- tools/msvc
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
50 files changed
+5466
-368
lines changedLines changed: 9 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
732 | 732 |
| |
733 | 733 |
| |
734 | 734 |
| |
| 735 | + | |
735 | 736 |
| |
736 | 737 |
| |
737 | 738 |
| |
| |||
5261 | 5262 |
| |
5262 | 5263 |
| |
5263 | 5264 |
| |
| 5265 | + | |
5264 | 5266 |
| |
5265 | 5267 |
| |
5266 | 5268 |
| |
| |||
5301 | 5303 |
| |
5302 | 5304 |
| |
5303 | 5305 |
| |
5304 |
| - | |
| 5306 | + | |
| 5307 | + | |
| 5308 | + | |
| 5309 | + | |
| 5310 | + | |
| 5311 | + | |
| 5312 | + | |
5305 | 5313 |
| |
5306 | 5314 |
| |
5307 | 5315 |
| |
|
Lines changed: 8 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
476 | 476 |
| |
477 | 477 |
| |
478 | 478 |
| |
| 479 | + | |
479 | 480 |
| |
480 |
| - | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
481 | 488 |
| |
482 | 489 |
| |
483 | 490 |
| |
|
Lines changed: 10 additions & 10 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
33 | 33 |
| |
34 | 34 |
| |
35 | 35 |
| |
36 |
| - | |
37 |
| - | |
38 |
| - | |
39 |
| - | |
40 |
| - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
41 | 41 |
| |
42 | 42 |
| |
43 | 43 |
| |
| |||
82 | 82 |
| |
83 | 83 |
| |
84 | 84 |
| |
85 |
| - | |
86 |
| - | |
87 |
| - | |
88 |
| - | |
89 |
| - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
90 | 90 |
| |
91 | 91 |
|
Lines changed: 10 additions & 10 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
33 | 33 |
| |
34 | 34 |
| |
35 | 35 |
| |
36 |
| - | |
37 |
| - | |
38 |
| - | |
39 |
| - | |
40 |
| - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
41 | 41 |
| |
42 | 42 |
| |
43 | 43 |
| |
| |||
82 | 82 |
| |
83 | 83 |
| |
84 | 84 |
| |
85 |
| - | |
86 |
| - | |
87 |
| - | |
88 |
| - | |
89 |
| - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
90 | 90 |
| |
91 | 91 |
|
Lines changed: 19 additions & 13 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
81 | 81 |
| |
82 | 82 |
| |
83 | 83 |
| |
84 |
| - | |
85 |
| - | |
86 |
| - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
87 | 87 |
| |
88 | 88 |
| |
89 | 89 |
| |
90 |
| - | |
91 |
| - | |
92 |
| - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
93 | 93 |
| |
94 | 94 |
| |
95 | 95 |
| |
96 |
| - | |
97 |
| - | |
98 |
| - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
99 | 99 |
| |
100 | 100 |
| |
101 | 101 |
| |
| |||
943 | 943 |
| |
944 | 944 |
| |
945 | 945 |
| |
946 |
| - | |
947 |
| - | |
948 |
| - | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
949 | 949 |
| |
950 | 950 |
| |
951 | 951 |
| |
| |||
1356 | 1356 |
| |
1357 | 1357 |
| |
1358 | 1358 |
| |
1359 |
| - | |
| 1359 | + | |
1360 | 1360 |
| |
| 1361 | + | |
1361 | 1362 |
| |
1362 | 1363 |
| |
1363 | 1364 |
| |
| |||
1370 | 1371 |
| |
1371 | 1372 |
| |
1372 | 1373 |
| |
| 1374 | + | |
1373 | 1375 |
| |
1374 | 1376 |
| |
1375 | 1377 |
| |
| |||
1557 | 1559 |
| |
1558 | 1560 |
| |
1559 | 1561 |
| |
| 1562 | + | |
1560 | 1563 |
| |
1561 | 1564 |
| |
1562 | 1565 |
| |
| |||
1567 | 1570 |
| |
1568 | 1571 |
| |
1569 | 1572 |
| |
| 1573 | + | |
1570 | 1574 |
| |
1571 | 1575 |
| |
1572 | 1576 |
| |
| |||
1751 | 1755 |
| |
1752 | 1756 |
| |
1753 | 1757 |
| |
| 1758 | + | |
1754 | 1759 |
| |
1755 | 1760 |
| |
1756 | 1761 |
| |
| |||
1761 | 1766 |
| |
1762 | 1767 |
| |
1763 | 1768 |
| |
| 1769 | + | |
1764 | 1770 |
| |
1765 | 1771 |
| |
1766 | 1772 |
| |
|
Lines changed: 9 additions & 9 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
87 | 87 |
| |
88 | 88 |
| |
89 | 89 |
| |
90 |
| - | |
91 |
| - | |
92 |
| - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
93 | 93 |
| |
94 | 94 |
| |
95 | 95 |
| |
96 |
| - | |
97 |
| - | |
98 |
| - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
99 | 99 |
| |
100 | 100 |
| |
101 | 101 |
| |
102 |
| - | |
103 |
| - | |
104 |
| - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
105 | 105 |
| |
106 | 106 |
|
Lines changed: 7 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
336 | 336 |
| |
337 | 337 |
| |
338 | 338 |
| |
339 |
| - | |
| 339 | + | |
340 | 340 |
| |
| 341 | + | |
341 | 342 |
| |
342 | 343 |
| |
| 344 | + | |
343 | 345 |
| |
344 | 346 |
| |
345 | 347 |
| |
| |||
395 | 397 |
| |
396 | 398 |
| |
397 | 399 |
| |
| 400 | + | |
398 | 401 |
| |
| 402 | + | |
399 | 403 |
| |
400 | 404 |
| |
401 | 405 |
| |
| |||
412 | 416 |
| |
413 | 417 |
| |
414 | 418 |
| |
| 419 | + | |
415 | 420 |
| |
| 421 | + | |
416 | 422 |
| |
417 | 423 |
| |
418 | 424 |
| |
|
Lines changed: 2 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1 | 1 |
| |
2 | 2 |
| |
3 | 3 |
| |
| 4 | + | |
| 5 | + | |
4 | 6 |
| |
5 | 7 |
| |
6 | 8 |
| |
|
Lines changed: 2 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
10 | 10 |
| |
11 | 11 |
| |
12 | 12 |
| |
| 13 | + | |
| 14 | + | |
13 | 15 |
| |
14 | 16 |
| |
15 | 17 |
| |
|
Lines changed: 2 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1 | 1 |
| |
2 | 2 |
| |
| 3 | + | |
| 4 | + | |
3 | 5 |
| |
4 | 6 |
| |
5 | 7 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2 | 2 |
| |
3 | 3 |
| |
4 | 4 |
| |
| 5 | + | |
| 6 | + | |
| 7 | + | |
5 | 8 |
| |
6 | 9 |
| |
7 | 10 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
9 | 9 |
| |
10 | 10 |
| |
11 | 11 |
| |
| 12 | + | |
| 13 | + | |
| 14 | + | |
12 | 15 |
| |
13 | 16 |
| |
14 | 17 |
| |
|
Lines changed: 3 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2 | 2 |
| |
3 | 3 |
| |
4 | 4 |
| |
| 5 | + | |
| 6 | + | |
| 7 | + | |
5 | 8 |
| |
6 | 9 |
| |
7 | 10 |
| |
|
Lines changed: 3 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1127 | 1127 |
| |
1128 | 1128 |
| |
1129 | 1129 |
| |
1130 |
| - | |
| 1130 | + | |
1131 | 1131 |
| |
1132 | 1132 |
| |
1133 | 1133 |
| |
| |||
1155 | 1155 |
| |
1156 | 1156 |
| |
1157 | 1157 |
| |
1158 |
| - | |
| 1158 | + | |
1159 | 1159 |
| |
1160 | 1160 |
| |
1161 | 1161 |
| |
| |||
1244 | 1244 |
| |
1245 | 1245 |
| |
1246 | 1246 |
| |
1247 |
| - | |
| 1247 | + | |
1248 | 1248 |
| |
1249 | 1249 |
| |
1250 | 1250 |
| |
|
0 commit comments
Comments
(0)