| From: | Tình Trần <tranvantinhnbk(at)gmail(dot)com> |
|---|---|
| To: | Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com> |
| Cc: | pgsql-hackers(at)lists(dot)postgresql(dot)org, Ishjaap Singh <ishjaap(dot)singh07(at)gmail(dot)com> |
| Subject: | Re: [PATCH] Fix interval input at minimum signed field values (BUG #19746) |
| Date: | 2026-12-05 04:46:09 |
| Message-ID: | CAEPgAbHmvMMXq50hn_NMaVtJdp=ADpZmUFUVNyK+F+74qLfwJw@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Subject: Re: [PATCH] Fix interval input at minimum signed field values (BUG
#19746)
Hi Ishjaap and Zsolt,
Thanks for testing v4 and for the review. Attached is v5.
Zsolt, I checked the AdjustFract* calls in DecodeInterval(), and you're
right: none of them can overflow. The temporary starts at zero for each
field. Even if the fraction rounds to 1 in magnitude, the largest value
we add is one day in microseconds, 30 days, or 12,000 months, depending
on the unit. Each fits in its field.
I removed those 12 checks in v5 and added a short comment explaining
why. The ISO seconds parser still needs the check in the shared helper.
It adds the whole seconds first, so adding the fractional microseconds
can push the total over the limit.
I moved int128_negate() into int128.h and kept the fractional day/week
fix in this patch. Ishjaap's clock-limit example shows why the final
range check matters: half a day fits the temporary, but adding it to
INT64_MAX microseconds exceeds the interval range in either order.
The regression tests cover both orders and the 1.5-week example.
I also documented the SQLSTATE changes. An out-of-range signed clock
field such as '-1:60' now reports 22015, like '1:60'. A duplicate unit
can now report 22007 where it previously reported 22015.
The patch is tracked at https://commitfest.postgresql.org/patch/7620/.
Regards,
Tinh
Vào Thứ 5, 26 thg 11, 2026 vào lúc 05:50 Zsolt Parragi <
zsolt(dot)parragi(at)percona(dot)com> đã viết:
> +/* Negate an accumulator value; the parser's input bounds exclude
> INT128_MIN. */
> +static INT128
> +NegateIntervalValue(INT128 value)
> +{
> +#if USE_NATIVE_INT128
> + return -value;
> +#else
> + value.hi = ~value.hi;
> + value.lo = ~value.lo;
> + int128_add_int64(&value, 1);
> + return value;
> +#endif
> +}
> +
>
> Looking at USE_NATIVE_INT128, it has no uses outside int128.h/c, and
> it most likely should remain so. Maybe it should go into int128.h as
> int128_negate, following the functions of the other functions there?
>
> + if
> (!AdjustFractMicroseconds(fval, 1, &fraction))
> return
> DTERR_FIELD_OVERFLOW;
>
> Another mostly nitpick question, can these AdjustFract* overflow
> actually happen?
>
> > Could you take another look would you also prefer the fractional day/week
> > fix as a separate patch?
>
> I think keeping it together is fine, they are closely related and
> basically in the same code.
>
> You should also create an entry for your patch at the commitfest, so
> it doesn't get lost: https://commitfest.postgresql.org/
>
| Attachment | Content-Type | Size |
|---|---|---|
| v5-0001-Fix-interval-input-at-minimum-signed-field-values.patch | application/octet-stream | 33.8 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | shihao zhong | 2026-12-05 04:48:35 | Re: REPACK (CONCURRENTLY): do not block the table while waiting for the final lock |
| Previous Message | shihao zhong | 2026-12-05 04:39:28 | Re: examine_variable ignored CollateExpr |