Re: [PATCH] Fix interval input at minimum signed field values (BUG #19746)

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-11-17 15:47:01
Message-ID: CAEPgAbHKi1yf=FQFwG51JrJOTsz839XTzd5kWn9pugXbUrByNw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Zsolt Parragi,

Thanks for the review! Attached is v4. it nice catch with the old bug i
have the
change draft base on your suggestions
The bellowing attachment is current my update approach for your review

I changed the clock-time assignment to addition, added tests for fractional
days/weeks in both orders, and fixed the comments. Negation now avoids the
newer int128 helpers to ease backpatching.

Once we agree on the approach, I think i can prepare and test backpatches
for the
affected maintained branches, back to PG15 upward ?

Could you take another look would you also prefer the fractional day/week
fix
as a separate patch?

Regards,

Vào Thứ 3, 17 thg 11, 2026 vào lúc 05:23 Zsolt Parragi <
zsolt(dot)parragi(at)percona(dot)com> đã viết:

> Hello
>
> Thanks for working on this!
>
> + itm_in->tm_usec = int64_to_int128(itm.tm_usec);
> + int128_add_int64_mul_int64(&itm_in->tm_usec, itm.tm_hour,
> USECS_PER_HOUR);
> + int128_add_int64_mul_int64(&itm_in->tm_usec, itm.tm_min,
> USECS_PER_MINUTE);
>
> There's also a related preexisting bug: time field overwrites the
> fractional part of a day/week unit
>
> SELECT '01:00:00 1.5 days'::interval AS a, '1.5 days 01:00:00'::interval
> AS b;
> a | b
> ----------------+----------------
> 1 day 01:00:00 | 1 day 13:00:00
>
> SELECT '01:00 0.5 weeks'::interval, '0.5 weeks 01:00'::interval;
> 3 days 01:00:00 | 3 days 13:00:00
>
> int128_add_int64(&itm_in->tm_usec, itm.tm_usec) would also fix this
>
>
> There are also some stale comments now:
>
> * dtype and itm_in are output parameters.
> ...
> * itm_in remains undefined for infinite interval values for which dtype
> alone
> * suffices.
>
>
> +/* Private wide arithmetic for the general interval parser. */
> +static INT128
> +NegateIntervalValue(INT128 value)
> +{
> + INT128 result = make_int128(~PG_INT128_HI_INT64(value),
> +
> ~PG_INT128_LO_UINT64(value));
> +
> + int128_add_int64(&result, 1);
> + return result;
> +}
> +
>
> The bug exists on 15+, and this function uses PG19 functions - that is
> fine, but this part will need a different solution on older branches.
>
>
> +/*
> + * Keep general interval input wider than its stored representation until
> AGO
> + * has been applied. There are at most MAXDATEFIELDS int64 input values,
> and
> + * even the largest unit scale fits comfortably in this accumulator.
> + */
>
> I am not sure how good this comment is outside this patch, as it
> mostly seems to explain implementation details, not the type.
>

Attachment Content-Type Size
v4-0001-Fix-interval-input-at-minimum-signed-field-values.patch application/octet-stream 28.5 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Manu 2026-11-17 15:58:56 Quadratic constraint naming for FKs to partitioned tables
Previous Message Zhijie Hou 2026-11-17 15:20:54 Re: WAL_LOG CREATE DATABASE strategy broken for non-standard page layouts