pg.ddx.io pgsql-committers@postgresql.org mailing list archive
help / color / mirror / Atom feedpgsql: Fix incorrect return value in pg_size_pretty(bigint)
9+ messages / 2 participants
[nested] [flat]
Commits from this thread:
2021-07-09 87103002c8 b186211393 137af4f27a dd76aa54a3 3e474a7087 Add missing Int64GetDatum macro in dbsize.c
* pgsql: Fix incorrect return value in pg_size_pretty(bigint)
@ 2021-07-09 02:05 David Rowley <drowley@postgresql.org>
0 siblings, 1 reply; 9+ messages in thread
From: David Rowley @ 2021-07-09 02:05 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Fix incorrect return value in pg_size_pretty(bigint)
Due to how pg_size_pretty(bigint) was implemented, it's possible that when
given a negative number of bytes that the returning value would not match
the equivalent positive return value when given the equivalent positive
number of bytes. This was due to two separate issues.
1. The function used bit shifting to convert the number of bytes into
larger units. The rounding performed by bit shifting is not the same as
dividing. For example -3 >> 1 = -2, but -3 / 2 = -1. These two
operations are only equivalent with positive numbers.
2. The half_rounded() macro rounded towards positive infinity. This meant
that negative numbers rounded towards zero and positive numbers rounded
away from zero.
Here we fix #1 by dividing the values instead of bit shifting. We fix #2
by adjusting the half_rounded macro always to round away from zero.
Additionally, adjust the pg_size_pretty(numeric) function to be more
explicit that it's using division rather than bit shifting. A casual
observer might have believed bit shifting was used due to a static
function being named numeric_shift_right. However, that function was
calculating the divisor from the number of bits and performed division.
Here we make that more clear. This change is just cosmetic and does not
affect the return value of the numeric version of the function.
Here we also add a set of regression tests both versions of
pg_size_pretty() which test the values directly before and after the
function switches to the next unit.
This bug was introduced in 8a1fab36a. Prior to that negative values were
always displayed in bytes.
Author: Dean Rasheed, David Rowley
Discussion: https://postgr.es/m/CAEZATCXnNW4HsmZnxhfezR5FuiGgp+mkY4AzcL5eRGO4fuadWg@mail.gmail.com
Backpatch-through: 9.6, where the bug was introduced.
Branch
------
REL9_6_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/674ee3b7669444dbfd9a6ec47aa49ead8444349e
Modified Files
--------------
src/backend/utils/adt/dbsize.c | 39 +++++++++++++++++----------------
src/test/regress/expected/dbsize.out | 42 ++++++++++++++++++++++++++++++++++++
src/test/regress/sql/dbsize.sql | 16 ++++++++++++++
3 files changed, 79 insertions(+), 18 deletions(-)
^ permalink raw reply [nested|flat] 9+ messages in thread
* pgsql: Fix incorrect return value in pg_size_pretty(bigint)
@ 2021-07-09 02:06 David Rowley <drowley@postgresql.org>
0 siblings, 0 replies; 9+ messages in thread
From: David Rowley @ 2021-07-09 02:06 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Fix incorrect return value in pg_size_pretty(bigint)
Due to how pg_size_pretty(bigint) was implemented, it's possible that when
given a negative number of bytes that the returning value would not match
the equivalent positive return value when given the equivalent positive
number of bytes. This was due to two separate issues.
1. The function used bit shifting to convert the number of bytes into
larger units. The rounding performed by bit shifting is not the same as
dividing. For example -3 >> 1 = -2, but -3 / 2 = -1. These two
operations are only equivalent with positive numbers.
2. The half_rounded() macro rounded towards positive infinity. This meant
that negative numbers rounded towards zero and positive numbers rounded
away from zero.
Here we fix #1 by dividing the values instead of bit shifting. We fix #2
by adjusting the half_rounded macro always to round away from zero.
Additionally, adjust the pg_size_pretty(numeric) function to be more
explicit that it's using division rather than bit shifting. A casual
observer might have believed bit shifting was used due to a static
function being named numeric_shift_right. However, that function was
calculating the divisor from the number of bits and performed division.
Here we make that more clear. This change is just cosmetic and does not
affect the return value of the numeric version of the function.
Here we also add a set of regression tests both versions of
pg_size_pretty() which test the values directly before and after the
function switches to the next unit.
This bug was introduced in 8a1fab36a. Prior to that negative values were
always displayed in bytes.
Author: Dean Rasheed, David Rowley
Discussion: https://postgr.es/m/CAEZATCXnNW4HsmZnxhfezR5FuiGgp+mkY4AzcL5eRGO4fuadWg@mail.gmail.com
Backpatch-through: 9.6, where the bug was introduced.
Branch
------
REL_10_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/1efcd57208523b80682cc2dd77bfc2b8a59a928c
Modified Files
--------------
src/backend/utils/adt/dbsize.c | 39 +++++++++++++++++----------------
src/test/regress/expected/dbsize.out | 42 ++++++++++++++++++++++++++++++++++++
src/test/regress/sql/dbsize.sql | 16 ++++++++++++++
3 files changed, 79 insertions(+), 18 deletions(-)
^ permalink raw reply [nested|flat] 9+ messages in thread
* pgsql: Fix incorrect return value in pg_size_pretty(bigint)
@ 2021-07-09 02:06 David Rowley <drowley@postgresql.org>
0 siblings, 0 replies; 9+ messages in thread
From: David Rowley @ 2021-07-09 02:06 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Fix incorrect return value in pg_size_pretty(bigint)
Due to how pg_size_pretty(bigint) was implemented, it's possible that when
given a negative number of bytes that the returning value would not match
the equivalent positive return value when given the equivalent positive
number of bytes. This was due to two separate issues.
1. The function used bit shifting to convert the number of bytes into
larger units. The rounding performed by bit shifting is not the same as
dividing. For example -3 >> 1 = -2, but -3 / 2 = -1. These two
operations are only equivalent with positive numbers.
2. The half_rounded() macro rounded towards positive infinity. This meant
that negative numbers rounded towards zero and positive numbers rounded
away from zero.
Here we fix #1 by dividing the values instead of bit shifting. We fix #2
by adjusting the half_rounded macro always to round away from zero.
Additionally, adjust the pg_size_pretty(numeric) function to be more
explicit that it's using division rather than bit shifting. A casual
observer might have believed bit shifting was used due to a static
function being named numeric_shift_right. However, that function was
calculating the divisor from the number of bits and performed division.
Here we make that more clear. This change is just cosmetic and does not
affect the return value of the numeric version of the function.
Here we also add a set of regression tests both versions of
pg_size_pretty() which test the values directly before and after the
function switches to the next unit.
This bug was introduced in 8a1fab36a. Prior to that negative values were
always displayed in bytes.
Author: Dean Rasheed, David Rowley
Discussion: https://postgr.es/m/CAEZATCXnNW4HsmZnxhfezR5FuiGgp+mkY4AzcL5eRGO4fuadWg@mail.gmail.com
Backpatch-through: 9.6, where the bug was introduced.
Branch
------
REL_11_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/45bad6a398ced09b16a3fa47a2a39c37bbc73222
Modified Files
--------------
src/backend/utils/adt/dbsize.c | 39 +++++++++++++++++----------------
src/test/regress/expected/dbsize.out | 42 ++++++++++++++++++++++++++++++++++++
src/test/regress/sql/dbsize.sql | 16 ++++++++++++++
3 files changed, 79 insertions(+), 18 deletions(-)
^ permalink raw reply [nested|flat] 9+ messages in thread
* pgsql: Fix incorrect return value in pg_size_pretty(bigint)
@ 2021-07-09 02:07 David Rowley <drowley@postgresql.org>
0 siblings, 0 replies; 9+ messages in thread
From: David Rowley @ 2021-07-09 02:07 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Fix incorrect return value in pg_size_pretty(bigint)
Due to how pg_size_pretty(bigint) was implemented, it's possible that when
given a negative number of bytes that the returning value would not match
the equivalent positive return value when given the equivalent positive
number of bytes. This was due to two separate issues.
1. The function used bit shifting to convert the number of bytes into
larger units. The rounding performed by bit shifting is not the same as
dividing. For example -3 >> 1 = -2, but -3 / 2 = -1. These two
operations are only equivalent with positive numbers.
2. The half_rounded() macro rounded towards positive infinity. This meant
that negative numbers rounded towards zero and positive numbers rounded
away from zero.
Here we fix #1 by dividing the values instead of bit shifting. We fix #2
by adjusting the half_rounded macro always to round away from zero.
Additionally, adjust the pg_size_pretty(numeric) function to be more
explicit that it's using division rather than bit shifting. A casual
observer might have believed bit shifting was used due to a static
function being named numeric_shift_right. However, that function was
calculating the divisor from the number of bits and performed division.
Here we make that more clear. This change is just cosmetic and does not
affect the return value of the numeric version of the function.
Here we also add a set of regression tests both versions of
pg_size_pretty() which test the values directly before and after the
function switches to the next unit.
This bug was introduced in 8a1fab36a. Prior to that negative values were
always displayed in bytes.
Author: Dean Rasheed, David Rowley
Discussion: https://postgr.es/m/CAEZATCXnNW4HsmZnxhfezR5FuiGgp+mkY4AzcL5eRGO4fuadWg@mail.gmail.com
Backpatch-through: 9.6, where the bug was introduced.
Branch
------
REL_12_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/efc42a1e18b53e376955ee2c12d89982e80b0830
Modified Files
--------------
src/backend/utils/adt/dbsize.c | 39 +++++++++++++++++----------------
src/test/regress/expected/dbsize.out | 42 ++++++++++++++++++++++++++++++++++++
src/test/regress/sql/dbsize.sql | 16 ++++++++++++++
3 files changed, 79 insertions(+), 18 deletions(-)
^ permalink raw reply [nested|flat] 9+ messages in thread
* pgsql: Fix incorrect return value in pg_size_pretty(bigint)
@ 2021-07-09 02:07 David Rowley <drowley@postgresql.org>
0 siblings, 0 replies; 9+ messages in thread
From: David Rowley @ 2021-07-09 02:07 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Fix incorrect return value in pg_size_pretty(bigint)
Due to how pg_size_pretty(bigint) was implemented, it's possible that when
given a negative number of bytes that the returning value would not match
the equivalent positive return value when given the equivalent positive
number of bytes. This was due to two separate issues.
1. The function used bit shifting to convert the number of bytes into
larger units. The rounding performed by bit shifting is not the same as
dividing. For example -3 >> 1 = -2, but -3 / 2 = -1. These two
operations are only equivalent with positive numbers.
2. The half_rounded() macro rounded towards positive infinity. This meant
that negative numbers rounded towards zero and positive numbers rounded
away from zero.
Here we fix #1 by dividing the values instead of bit shifting. We fix #2
by adjusting the half_rounded macro always to round away from zero.
Additionally, adjust the pg_size_pretty(numeric) function to be more
explicit that it's using division rather than bit shifting. A casual
observer might have believed bit shifting was used due to a static
function being named numeric_shift_right. However, that function was
calculating the divisor from the number of bits and performed division.
Here we make that more clear. This change is just cosmetic and does not
affect the return value of the numeric version of the function.
Here we also add a set of regression tests both versions of
pg_size_pretty() which test the values directly before and after the
function switches to the next unit.
This bug was introduced in 8a1fab36a. Prior to that negative values were
always displayed in bytes.
Author: Dean Rasheed, David Rowley
Discussion: https://postgr.es/m/CAEZATCXnNW4HsmZnxhfezR5FuiGgp+mkY4AzcL5eRGO4fuadWg@mail.gmail.com
Backpatch-through: 9.6, where the bug was introduced.
Branch
------
REL_13_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/6f88b68ff4adfe17a80c0befdf9bb8b0a8218def
Modified Files
--------------
src/backend/utils/adt/dbsize.c | 39 +++++++++++++++++----------------
src/test/regress/expected/dbsize.out | 42 ++++++++++++++++++++++++++++++++++++
src/test/regress/sql/dbsize.sql | 16 ++++++++++++++
3 files changed, 79 insertions(+), 18 deletions(-)
^ permalink raw reply [nested|flat] 9+ messages in thread
* pgsql: Fix incorrect return value in pg_size_pretty(bigint)
@ 2021-07-09 02:08 David Rowley <drowley@postgresql.org>
0 siblings, 0 replies; 9+ messages in thread
From: David Rowley @ 2021-07-09 02:08 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Fix incorrect return value in pg_size_pretty(bigint)
Due to how pg_size_pretty(bigint) was implemented, it's possible that when
given a negative number of bytes that the returning value would not match
the equivalent positive return value when given the equivalent positive
number of bytes. This was due to two separate issues.
1. The function used bit shifting to convert the number of bytes into
larger units. The rounding performed by bit shifting is not the same as
dividing. For example -3 >> 1 = -2, but -3 / 2 = -1. These two
operations are only equivalent with positive numbers.
2. The half_rounded() macro rounded towards positive infinity. This meant
that negative numbers rounded towards zero and positive numbers rounded
away from zero.
Here we fix #1 by dividing the values instead of bit shifting. We fix #2
by adjusting the half_rounded macro always to round away from zero.
Additionally, adjust the pg_size_pretty(numeric) function to be more
explicit that it's using division rather than bit shifting. A casual
observer might have believed bit shifting was used due to a static
function being named numeric_shift_right. However, that function was
calculating the divisor from the number of bits and performed division.
Here we make that more clear. This change is just cosmetic and does not
affect the return value of the numeric version of the function.
Here we also add a set of regression tests both versions of
pg_size_pretty() which test the values directly before and after the
function switches to the next unit.
This bug was introduced in 8a1fab36a. Prior to that negative values were
always displayed in bytes.
Author: Dean Rasheed, David Rowley
Discussion: https://postgr.es/m/CAEZATCXnNW4HsmZnxhfezR5FuiGgp+mkY4AzcL5eRGO4fuadWg@mail.gmail.com
Backpatch-through: 9.6, where the bug was introduced.
Branch
------
REL_14_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/6de3a21bbc0601b22cd465311d10978acca7cc0b
Modified Files
--------------
src/backend/utils/adt/dbsize.c | 37 +++++++++++++++++--------------
src/test/regress/expected/dbsize.out | 42 ++++++++++++++++++++++++++++++++++++
src/test/regress/sql/dbsize.sql | 16 ++++++++++++++
3 files changed, 79 insertions(+), 16 deletions(-)
^ permalink raw reply [nested|flat] 9+ messages in thread
* pgsql: Fix incorrect return value in pg_size_pretty(bigint)
@ 2021-07-09 02:08 David Rowley <drowley@postgresql.org>
0 siblings, 0 replies; 9+ messages in thread
From: David Rowley @ 2021-07-09 02:08 UTC (permalink / raw)
To: pgsql-committers@lists.postgresql.org
Fix incorrect return value in pg_size_pretty(bigint)
Due to how pg_size_pretty(bigint) was implemented, it's possible that when
given a negative number of bytes that the returning value would not match
the equivalent positive return value when given the equivalent positive
number of bytes. This was due to two separate issues.
1. The function used bit shifting to convert the number of bytes into
larger units. The rounding performed by bit shifting is not the same as
dividing. For example -3 >> 1 = -2, but -3 / 2 = -1. These two
operations are only equivalent with positive numbers.
2. The half_rounded() macro rounded towards positive infinity. This meant
that negative numbers rounded towards zero and positive numbers rounded
away from zero.
Here we fix #1 by dividing the values instead of bit shifting. We fix #2
by adjusting the half_rounded macro always to round away from zero.
Additionally, adjust the pg_size_pretty(numeric) function to be more
explicit that it's using division rather than bit shifting. A casual
observer might have believed bit shifting was used due to a static
function being named numeric_shift_right. However, that function was
calculating the divisor from the number of bits and performed division.
Here we make that more clear. This change is just cosmetic and does not
affect the return value of the numeric version of the function.
Here we also add a set of regression tests both versions of
pg_size_pretty() which test the values directly before and after the
function switches to the next unit.
This bug was introduced in 8a1fab36a. Prior to that negative values were
always displayed in bytes.
Author: Dean Rasheed, David Rowley
Discussion: https://postgr.es/m/CAEZATCXnNW4HsmZnxhfezR5FuiGgp+mkY4AzcL5eRGO4fuadWg@mail.gmail.com
Backpatch-through: 9.6, where the bug was introduced.
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/55fe609387685de1c754332e260b2d0e17d257dc
Modified Files
--------------
src/backend/utils/adt/dbsize.c | 37 +++++++++++++++++--------------
src/test/regress/expected/dbsize.out | 42 ++++++++++++++++++++++++++++++++++++
src/test/regress/sql/dbsize.sql | 16 ++++++++++++++
3 files changed, 79 insertions(+), 16 deletions(-)
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: pgsql: Fix incorrect return value in pg_size_pretty(bigint)
@ 2021-07-09 02:39 David Rowley <dgrowleyml@gmail.com>
parent: David Rowley <drowley@postgresql.org>
0 siblings, 1 reply; 9+ messages in thread
From: David Rowley @ 2021-07-09 02:39 UTC (permalink / raw)
To: David Rowley <drowley@postgresql.org>; +Cc: pgsql-committers@lists.postgresql.org
On Fri, 9 Jul 2021 at 14:06, David Rowley <drowley@postgresql.org> wrote:
>
> Fix incorrect return value in pg_size_pretty(bigint)
> Branch
> ------
> REL9_6_STABLE
It looks like locust is not a fan of this change [1].
I've no good ideas yet, but I'm looking.
David
[1] https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=locust&dt=2021-07-09%2002%3A22%3A54
^ permalink raw reply [nested|flat] 9+ messages in thread
* Re: pgsql: Fix incorrect return value in pg_size_pretty(bigint)
@ 2021-07-09 02:54 David Rowley <dgrowleyml@gmail.com>
parent: David Rowley <dgrowleyml@gmail.com>
0 siblings, 0 replies; 9+ messages in thread
From: David Rowley @ 2021-07-09 02:54 UTC (permalink / raw)
To: David Rowley <drowley@postgresql.org>; +Cc: pgsql-committers@lists.postgresql.org
On Fri, 9 Jul 2021 at 14:39, David Rowley <dgrowleyml@gmail.com> wrote:
> I've no good ideas yet, but I'm looking.
It looks like I didn't do a good job of adjusting the code to account
for 0aa8f7640 and missed an Int64GetDatum().
I suspect all the 32-bit machines are about to fail.
I'm just checking that now.
David
^ permalink raw reply [nested|flat] 9+ messages in thread
end of thread, other threads:[~2021-07-09 02:54 UTC | newest]
Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-07-09 02:05 pgsql: Fix incorrect return value in pg_size_pretty(bigint) David Rowley <drowley@postgresql.org>
2021-07-09 02:39 ` David Rowley <dgrowleyml@gmail.com>
2021-07-09 02:54 ` David Rowley <dgrowleyml@gmail.com>
2021-07-09 02:06 pgsql: Fix incorrect return value in pg_size_pretty(bigint) David Rowley <drowley@postgresql.org>
2021-07-09 02:06 pgsql: Fix incorrect return value in pg_size_pretty(bigint) David Rowley <drowley@postgresql.org>
2021-07-09 02:07 pgsql: Fix incorrect return value in pg_size_pretty(bigint) David Rowley <drowley@postgresql.org>
2021-07-09 02:07 pgsql: Fix incorrect return value in pg_size_pretty(bigint) David Rowley <drowley@postgresql.org>
2021-07-09 02:08 pgsql: Fix incorrect return value in pg_size_pretty(bigint) David Rowley <drowley@postgresql.org>
2021-07-09 02:08 pgsql: Fix incorrect return value in pg_size_pretty(bigint) David Rowley <drowley@postgresql.org>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox