diff options
| author | David Rowley <drowley@postgresql.org> | 2024-07-28 22:22:52 +1200 |
|---|---|---|
| committer | David Rowley <drowley@postgresql.org> | 2024-07-28 22:22:52 +1200 |
| commit | b181062aa5727a013c96b64476f884c992b5068d (patch) | |
| tree | 29821bfd371503d1ef124606fb76f197abaa41e2 /src/test | |
| parent | 1e666fd7c6d3bff658cdbad02b4e7bb77dde391d (diff) | |
Fix incorrect return value for pg_size_pretty(bigint)
pg_size_pretty(bigint) would return the value in bytes rather than PB
for the smallest-most bigint value. This happened due to an incorrect
assumption that the absolute value of -9223372036854775808 could be
stored inside a signed 64-bit type.
Here we fix that by instead storing that value in an unsigned 64-bit type.
This bug does exist in versions prior to 15 but the code there is
sufficiently different and the bug seems sufficiently non-critical that
it does not seem worth risking backpatching further.
Author: Joseph Koshakow <koshy44@gmail.com>
Discussion: https://postgr.es/m/CAAvxfHdTsMZPWEHUrZ=h3cky9Ccc3Mtx2whUHygY+ABP-mCmUw@mail.gmail.com
Backpatch-through: 15
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/dbsize.out | 8 | ||||
| -rw-r--r-- | src/test/regress/sql/dbsize.sql | 4 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/test/regress/expected/dbsize.out b/src/test/regress/expected/dbsize.out index f1121a87aa3..97c3bf54be5 100644 --- a/src/test/regress/expected/dbsize.out +++ b/src/test/regress/expected/dbsize.out @@ -79,6 +79,14 @@ SELECT size, pg_size_pretty(size), pg_size_pretty(-1 * size) FROM 11528652096115048448 | 10240 PB | -10240 PB (12 rows) +-- Ensure we get the expected results when passing the extremities of bigint +SELECT pg_size_pretty('-9223372036854775808'::bigint), + pg_size_pretty('9223372036854775807'::bigint); + pg_size_pretty | pg_size_pretty +----------------+---------------- + -8192 PB | 8192 PB +(1 row) + -- pg_size_bytes() tests SELECT size, pg_size_bytes(size) FROM (VALUES ('1'), ('123bytes'), ('256 B'), ('1kB'), ('1MB'), (' 1 GB'), ('1.5 GB '), diff --git a/src/test/regress/sql/dbsize.sql b/src/test/regress/sql/dbsize.sql index b34cf33385e..38b94444007 100644 --- a/src/test/regress/sql/dbsize.sql +++ b/src/test/regress/sql/dbsize.sql @@ -27,6 +27,10 @@ SELECT size, pg_size_pretty(size), pg_size_pretty(-1 * size) FROM (11258449312612351::numeric), (11258449312612352::numeric), (11528652096115048447::numeric), (11528652096115048448::numeric)) x(size); +-- Ensure we get the expected results when passing the extremities of bigint +SELECT pg_size_pretty('-9223372036854775808'::bigint), + pg_size_pretty('9223372036854775807'::bigint); + -- pg_size_bytes() tests SELECT size, pg_size_bytes(size) FROM (VALUES ('1'), ('123bytes'), ('256 B'), ('1kB'), ('1MB'), (' 1 GB'), ('1.5 GB '), |
