Useless division(s) in interval_cmp_value

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-hackers@lists.postgresql.org
Date: 2021-09-26T17:01:53Z
Lists: pgsql-hackers

Attachments

While thinking about Isaac Morland's patch to add abs(interval),
I happened to notice that interval_cmp_value() seems rather
inefficently written: it's expending an int64 division -- or
even two of them, if the compiler's not very smart -- to split
up the "time" field into days and microseconds.  That's quite
pointless, since we're immediately going to recombine the results
into microseconds.  Integer divisions are pretty expensive, too,
on a lot of hardware.

I suppose this is a hangover from when the code supported float
as well as int64 time fields; but since that's long gone, I see
no reason not to do the attached.

			regards, tom lane

Commits

  1. Avoid unnecessary division in interval_cmp_value().