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.