aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2021-09-26 14:24:03 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2021-09-26 14:24:03 -0400
commite94c1a55dada49772622d2be2d17a2a9973b2661 (patch)
tree848acb7ba233c031c47057e7c61f3c700fd032f9 /src
parent7c1d8a243f8bd46604c9b292f392aab170eed821 (diff)
downloadpostgresql-e94c1a55dada49772622d2be2d17a2a9973b2661.tar.gz
postgresql-e94c1a55dada49772622d2be2d17a2a9973b2661.zip
Avoid unnecessary division in interval_cmp_value().
Splitting the time field into days and microseconds is pretty useless when we're just going to recombine those values. It's unclear if anyone will notice the speedup in real-world cases, but a cycle shaved is a cycle earned. Discussion: https://postgr.es/m/2629129.1632675713@sss.pgh.pa.us
Diffstat (limited to 'src')
-rw-r--r--src/backend/utils/adt/timestamp.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index 1c0bf0aa5c8..cb9faff0bbc 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -2352,20 +2352,17 @@ static inline INT128
interval_cmp_value(const Interval *interval)
{
INT128 span;
- int64 dayfraction;
int64 days;
/*
- * Separate time field into days and dayfraction, then add the month and
- * day fields to the days part. We cannot overflow int64 days here.
+ * Combine the month and day fields into an integral number of days.
+ * Because the inputs are int32, int64 arithmetic suffices here.
*/
- dayfraction = interval->time % USECS_PER_DAY;
- days = interval->time / USECS_PER_DAY;
- days += interval->month * INT64CONST(30);
+ days = interval->month * INT64CONST(30);
days += interval->day;
- /* Widen dayfraction to 128 bits */
- span = int64_to_int128(dayfraction);
+ /* Widen time field to 128 bits */
+ span = int64_to_int128(interval->time);
/* Scale up days to microseconds, forming a 128-bit product */
int128_add_int64_mul_int64(&span, days, USECS_PER_DAY);