postgresql/src/backend/utils
Tom Lane 210564a744 Fix and simplify some usages of TimestampDifference().
Introduce TimestampDifferenceMilliseconds() to simplify callers
that would rather have the difference in milliseconds, instead of
the select()-oriented seconds-and-microseconds format.  This gets
rid of at least one integer division per call, and it eliminates
some apparently-easy-to-mess-up arithmetic.

Two of these call sites were in fact wrong:

* pg_prewarm's autoprewarm_main() forgot to multiply the seconds
by 1000, thus ending up with a delay 1000X shorter than intended.
That doesn't quite make it a busy-wait, but close.

* postgres_fdw's pgfdw_get_cleanup_result() thought it needed to compute
microseconds not milliseconds, thus ending up with a delay 1000X longer
than intended.  Somebody along the way had noticed this problem but
misdiagnosed the cause, and imposed an ad-hoc 60-second limit rather
than fixing the units.  This was relatively harmless in context, because
we don't care that much about exactly how long this delay is; still,
it's wrong.

There are a few more callers of TimestampDifference() that don't
have a direct need for seconds-and-microseconds, but can't use
TimestampDifferenceMilliseconds() either because they do need
microsecond precision or because they might possibly deal with
intervals long enough to overflow 32-bit milliseconds.  It might be
worth inventing another API to improve that, but that seems outside
the scope of this patch; so those callers are untouched here.

Given the fact that we are fixing some bugs, and the likelihood
that future patches might want to back-patch code that uses this
new API, back-patch to all supported branches.

Alexey Kondratov and Tom Lane

Discussion: https://postgr.es/m/3b1c053a21c07c1ed5e00be3b2b855ef@postgrespro.ru
2020-11-10 22:51:58 -05:00
..
adt Fix and simplify some usages of TimestampDifference(). 2020-11-10 22:51:58 -05:00
cache Preserve clustered index after rewrites with ALTER TABLE 2020-04-06 11:06:07 +09:00
error Disallow setting client_min_messages higher than ERROR. 2018-11-08 17:33:26 -05:00
fmgr Avoid holding a directory FD open across assorted SRF calls. 2020-03-16 21:05:29 -04:00
hash Reorganize our CRC source files again. 2015-04-14 17:03:42 +03:00
init Consistently test for in-use shared memory. 2019-04-12 22:41:42 -07:00
mb Avoid unnecessary out-of-memory errors during encoding conversion. 2019-10-03 17:34:26 -04:00
misc Fix memory leak when guc.c decides a setting can't be applied now. 2020-10-12 13:31:24 -04:00
mmgr Allow repalloc() to give back space when a large chunk is downsized. 2019-10-03 13:56:26 -04:00
resowner Update copyright for 2015 2015-01-06 11:43:47 -05:00
sort Backpatch tuplesort.c assertion. 2020-07-29 16:00:48 -07:00
time Fix pruning of locked and updated tuples. 2017-12-14 18:20:48 -08:00
.gitignore Avoid maintaining three separate copies of the error codes list. 2011-02-03 22:32:49 -05:00
errcodes.txt Redesign tablesample method API, and do extensive code review. 2015-07-25 14:39:00 -04:00
Gen_dummy_probes.pl Remove dependency on psed for MSVC builds. 2016-03-19 18:44:04 -04:00
Gen_dummy_probes.sed Update copyright for 2015 2015-01-06 11:43:47 -05:00
Gen_fmgrtab.pl Allow forcing nullness of columns during bootstrap. 2015-02-21 22:31:54 +01:00
generate-errcodes.pl Update copyright for 2015 2015-01-06 11:43:47 -05:00
Makefile Fix make rules that generate multiple output files. 2018-03-23 13:45:38 -04:00
probes.d Update copyright for 2015 2015-01-06 11:43:47 -05:00