- Notifications
You must be signed in to change notification settings - Fork4.9k
Commit6f88b68
committed
Fix incorrect return value in pg_size_pretty(bigint)
Due to how pg_size_pretty(bigint) was implemented, it's possible that whengiven a negative number of bytes that the returning value would not matchthe equivalent positive return value when given the equivalent positivenumber of bytes. This was due to two separate issues.1. The function used bit shifting to convert the number of bytes intolarger units. The rounding performed by bit shifting is not the same asdividing. For example -3 >> 1 = -2, but -3 / 2 = -1. These twooperations are only equivalent with positive numbers.2. The half_rounded() macro rounded towards positive infinity. This meantthat negative numbers rounded towards zero and positive numbers roundedaway from zero.Here wefix#1 by dividing the values instead of bit shifting. Wefix#2by adjusting the half_rounded macro always to round away from zero.Additionally, adjust the pg_size_pretty(numeric) function to be moreexplicit that it's using division rather than bit shifting. A casualobserver might have believed bit shifting was used due to a staticfunction being named numeric_shift_right. However, that function wascalculating the divisor from the number of bits and performed division.Here we make that more clear. This change is just cosmetic and does notaffect the return value of the numeric version of the function.Here we also add a set of regression tests both versions ofpg_size_pretty() which test the values directly before and after thefunction switches to the next unit.This bug was introduced in8a1fab3. Prior to that negative values werealways displayed in bytes.Author: Dean Rasheed, David RowleyDiscussion:https://postgr.es/m/CAEZATCXnNW4HsmZnxhfezR5FuiGgp+mkY4AzcL5eRGO4fuadWg@mail.gmail.comBackpatch-through: 9.6, where the bug was introduced.1 parent306c5e0 commit6f88b68
File tree
3 files changed
+79
-18
lines changed- src
- backend/utils/adt
- test/regress
- expected
- sql
3 files changed
+79
-18
lines changedLines changed: 21 additions & 18 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
31 | 31 |
| |
32 | 32 |
| |
33 | 33 |
| |
34 |
| - | |
35 |
| - | |
| 34 | + | |
| 35 | + | |
36 | 36 |
| |
37 | 37 |
| |
38 | 38 |
| |
| |||
542 | 542 |
| |
543 | 543 |
| |
544 | 544 |
| |
545 |
| - | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
546 | 550 |
| |
547 | 551 |
| |
548 | 552 |
| |
549 | 553 |
| |
550 | 554 |
| |
551 |
| - | |
| 555 | + | |
552 | 556 |
| |
553 | 557 |
| |
554 | 558 |
| |
555 | 559 |
| |
556 | 560 |
| |
557 |
| - | |
| 561 | + | |
558 | 562 |
| |
559 | 563 |
| |
560 | 564 |
| |
561 | 565 |
| |
562 | 566 |
| |
563 |
| - | |
| 567 | + | |
564 | 568 |
| |
565 | 569 |
| |
566 | 570 |
| |
| |||
629 | 633 |
| |
630 | 634 |
| |
631 | 635 |
| |
632 |
| - | |
| 636 | + | |
633 | 637 |
| |
634 | 638 |
| |
635 |
| - | |
636 | 639 |
| |
637 | 640 |
| |
638 | 641 |
| |
639 |
| - | |
640 |
| - | |
| 642 | + | |
641 | 643 |
| |
642 | 644 |
| |
643 | 645 |
| |
| |||
660 | 662 |
| |
661 | 663 |
| |
662 | 664 |
| |
663 |
| - | |
664 |
| - | |
| 665 | + | |
| 666 | + | |
665 | 667 |
| |
666 | 668 |
| |
667 | 669 |
| |
| |||
670 | 672 |
| |
671 | 673 |
| |
672 | 674 |
| |
673 |
| - | |
674 |
| - | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
675 | 678 |
| |
676 | 679 |
| |
677 | 680 |
| |
678 | 681 |
| |
679 | 682 |
| |
680 | 683 |
| |
681 | 684 |
| |
682 |
| - | |
683 |
| - | |
| 685 | + | |
| 686 | + | |
684 | 687 |
| |
685 | 688 |
| |
686 | 689 |
| |
| |||
689 | 692 |
| |
690 | 693 |
| |
691 | 694 |
| |
692 |
| - | |
693 |
| - | |
| 695 | + | |
| 696 | + | |
694 | 697 |
| |
695 | 698 |
| |
696 | 699 |
| |
|
Lines changed: 42 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
35 | 35 |
| |
36 | 36 |
| |
37 | 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 | + | |
38 | 80 |
| |
39 | 81 |
| |
40 | 82 |
| |
|
Lines changed: 16 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
11 | 11 |
| |
12 | 12 |
| |
13 | 13 |
| |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
14 | 30 |
| |
15 | 31 |
| |
16 | 32 |
| |
|
0 commit comments
Comments
(0)