| From: | Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com> |
|---|---|
| To: | Tình Trần <tranvantinhnbk(at)gmail(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-16 22:23:18 |
| Message-ID: | CAN4CZFNCxboJBpxj4saXjt4wgb42rRPA6PNHvfqm31qK9weFTg@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
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.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Heikki Linnakangas | 2026-11-16 22:32:28 | Fix two race conditions in processing interrupts |
| Previous Message | Bharath Rupireddy | 2026-11-16 22:05:00 | Re: Report oldest xmin source when autovacuum cannot remove tuples |