[PATCH v1 0/2] Preserve input sign across numeric parameter parsing

From: Haibo Yan <tristan(dot)yim(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: [PATCH v1 0/2] Preserve input sign across numeric parameter parsing
Date: 2026-09-11 21:16:02
Message-ID: CABXr29FwyX8mWg0htA2Uc-bQdKxTJoLq+aj+b=v5bRTfyZWHhQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi hackers,

While looking at the WAIT FOR timeout parsing issue, I noticed that the
underlying problem is not specific to WAIT FOR. parse_int() and parse_real()
can lose information about the original value during unit conversion and
rounding, before the caller gets a chance to validate it.

For example, these are currently accepted:

SET statement_timeout = '-0.5ms';
CREATE TABLE t (i int) WITH (parallel_workers = -0.4);
VACUUM (BUFFER_USAGE_LIMIT '-512B') t;

The first is stored as 0, the reloption is accepted after -0.4 rounds to 0, and
the VACUUM option is interpreted as the special value 0 (“no ring
buffer limit”).
WAIT FOR has the same issue: a timeout of ‘-0.4ms’ passes the negative check
after rounding and becomes an indefinite wait.

Patch 0001 adds parse_int_with_sign() and parse_real_with_sign(), which preserve
the sign of the input quantity before unit conversion or rounding. The existing
parse_int()/parse_real() interfaces are unchanged. GUC and integer reloption
validation use the preserved sign so that a negative input cannot become valid
merely by rounding to zero.

Patch 0002 uses the same information for WAIT FOR and VACUUM, where zero has
special semantics. An explicit zero remains valid, while a nonzero value that
collapses to zero is rejected.

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.

For WAIT FOR, I chose to reject positive timeouts below the 1 ms resolution
rather than silently turn them into an indefinite wait or clamp them to 1 ms.
I’m happy to change that if another behavior is preferred.

The series passes the regression tests and recovery/049_wait_for_lsn, as well
as the full Meson test suite on Linux x86_64 with assertions enabled.

Regards,
Haibo

Attachment Content-Type Size
v1-0001-Preserve-the-sign-of-a-numeric-parameter-value-ac.patch application/octet-stream 17.2 KB
v1-0002-Reject-nonzero-command-option-values-that-round-t.patch application/octet-stream 8.9 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Haibo Yan 2026-09-11 21:20:35 Re: Temporal fkey bugs
Previous Message Andres Freund 2026-09-11 21:07:40 Re: Temporal fkey bugs