On Fri, Nov 20, 2026 at 3:57 AM Xuneng Zhou <[email protected]> wrote:
>
> "This series deliberately does not change the existing behavior for positive 
> GUC
> values that round to zero.  For example, statement_timeout = ‘0.4ms’ still
> becomes 0.  It also does not address the separate parse_real() unit-conversion
> precision issue."
>
> I am curious why you chose to preserve the existing behavior for
> positive GUC values to zero?
> Another more concerning drawback for this conversion is that it does
> not respect the original value.
>
> it could give wrong values for these:
>
>     statement_timeout = '0.144min'          -> 9s     (8.64 s)
>     statement_timeout = '0.021d'            -> 1h     (30.24 min)
>
> I think this results from 1a83a80a2fe (PG12), convert_to_base_unit()
> rounds a fractional value to the next smaller unit than the input one.
> It was added for the sake of showing memory settings nicely, but
> without taking time value into proper consideration [2].
>
>     cvalue = rint(cvalue / table[i + 1].multiplier) *
>         table[i + 1].multiplier;
>
> Converting time exactly without next-unit rounding seems able to cover
> both the truncation and zeroing well. I understand that this is a
> broader behavior change. But it seems worthwhile to trade a bit of
> readability for accuracy.
>
>     '0.144min'                  -> 8640ms
>     '0.020d'                    -> 1728s
>     '0.021d'                    -> 1814400ms
>    '-0.4ms', '0.4ms'           -> rejected by rule 2
>
> Does this seem sensible to you?

Hi Xuneng,

Thanks for pointing this out. I agree that the intermediate rounding
in convert_to_base_unit() can cause much more significant precision
loss than the examples in my original patch.

I investigated this further, including testing a version that skips
intermediate rounding for time units while preserving the existing
behavior for memory units.

The results confirm your observation. For example:

    statement_timeout = '0.144min'
        current: 9000ms
        proposed: 8640ms

    statement_timeout = '0.020d'
        current: 0 (timeout disabled)
        proposed: 1728000ms

    statement_timeout = '0.021d'
        current: 3600000ms
        proposed: 1814400ms

The second example is particularly concerning, since a positive
timeout of 28.8 minutes currently becomes zero, disabling the timeout
entirely.

I think this is a separate issue from the sign-preservation patch.
The current series addresses the loss of the original input sign
during lossy conversion and rounding, which can allow negative values
to bypass validation. Even without intermediate rounding, a value
such as -0.4ms can still round to zero when stored as an integer
number of milliseconds. So improving conversion precision would not
eliminate the need for the current patch.

There is also a compatibility question with changing the rounding
behavior. The existing next-smaller-unit rule was introduced primarily
for memory settings, and is documented for unit conversion generally.
Removing it for time units produces more accurate values, but can also
change the interpretation of existing configuration files. For example:

    checkpoint_timeout = '1.0001d'
        current: 86400s (accepted)
        proposed: 86409s (rejected)

A previously valid configuration could therefore prevent a server
from starting after an upgrade. Other values, such as '0.020d', would
silently acquire a nonzero timeout where they previously disabled it.

Before proposing another patch, I think it would be useful to agree
on the intended semantics:

- Should time values be converted to the parameter's base unit and
  rounded only to that unit's resolution, while memory values retain
  the existing next-smaller-unit rounding?
- Or should time and memory conversions follow the same rounding rule?
- How much compatibility impact from changing previously accepted
  fractional values would be acceptable?

My preference is to separate unit conversion from the final rounding
policy conceptually, while keeping any implementation change as small
as possible. The time-only approach looks promising, but I would
rather settle the intended behavior first.

Once there is agreement, I can prepare a separate patch for the
time-conversion behavior. I have also tested it together with the
current sign-preservation series, and found no additional functional
regressions in the tested cases, apart from an expected error-message
difference.

>
> [1] https://postgr.es/m/[email protected]
> [2] 
> https://postgr.es/m/[email protected]
>
> --
> Regards,
> Xuneng Zhou
> HighGo Software Co., Ltd.

Thanks,
Haibo


Reply via email to