forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commitb5489b7
committed
Fix overflow when calculating timestamp distance in BRIN
When calculating distances for timestamp values for BRIN minmax-multiindexes, we need to be careful about overflows for extreme values. Ifthe value overflows into a negative value, the index may be inefficient.The new regression test checks this for the timestamp type by adding atable with enough values to force range compaction/merging. The valuesare close to min/max, which means a risk of overflow.Fixed by converting the int64 values to double first, before calculatingthe distance. This prevents the overflow. We may lose some precision, ofcourse, but that's good enough. In the worst case we build a slightlyless efficient index, but for large distances this won't matter.This only affects minmax-multi indexes on timestamp columns, with rangescontaining values sufficiently distant to cause an overflow. That seemslike a fairly rare case in practice.Backpatch to 14, where minmax-multi indexes were introduced.Reported-by: Ashutosh BapatReviewed-by: Ashutosh Bapat, Dean RasheedBackpatch-through: 14Discussion:https://postgr.es/m/eef0ea8c-4aaa-8d0d-027f-58b1f35dd170@enterprisedb.com1 parent16ace6f commitb5489b7
File tree
3 files changed
+37
-1
lines changed- src
- backend/access/brin
- test/regress
- expected
- sql
3 files changed
+37
-1
lines changedLines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2144 | 2144 |
| |
2145 | 2145 |
| |
2146 | 2146 |
| |
2147 |
| - | |
| 2147 | + | |
2148 | 2148 |
| |
2149 | 2149 |
| |
2150 | 2150 |
| |
|
Lines changed: 15 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
823 | 823 |
| |
824 | 824 |
| |
825 | 825 |
| |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + |
Lines changed: 21 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
586 | 586 |
| |
587 | 587 |
| |
588 | 588 |
| |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + |
0 commit comments
Comments
(0)