Erik Nordström c5a202476e Fix timestamp overflow in time_bucket optimization
An optimization for `time_bucket` transforms expressions of the form
`time_bucket(10, time) < 100` to `time < 100 + 10` in order to do
chunk exclusion and make better use of indexes on the time
column. However, since one bucket is added to the timestamp when doing
this transformation, the timestamp can overflow.

While a check for such overflows already exists, it uses `+Infinity`
(INT64_MAX/DT_NOEND) as the upper bound instead of the actual end of
the valid timestamp range. A further complication arises because
TimescaleDB internally converts timestamps to UNIX epoch time, thus
losing a little bit of the valid timestamp range in the process. Dates
are further restricted by the fact that they are internally first
converted to timestamps (thus limited by the timestamp range) and then
converted to UNIX epoch.

This change fixes the overflow issue by only applying the
transformation if the resulting timestamps or dates stay within the
valid (TimescaleDB-specific) ranges.

A test has also been added to show the valid timestamp and date
ranges, both PostgreSQL and TimescaleDB-specific ones.
2020-08-27 19:16:24 +02:00
..
2020-08-25 14:36:15 +02:00
2020-05-20 14:39:54 +02:00
2020-05-18 20:16:03 -04:00
2019-07-13 17:18:57 +02:00
2020-05-28 18:35:09 +02:00
2019-08-21 14:37:29 -04:00
2019-01-13 23:30:22 +01:00
2020-05-27 17:31:09 +02:00
2020-05-28 18:35:09 +02:00
2020-05-28 18:35:09 +02:00
2020-05-28 18:35:09 +02:00
2020-05-28 18:35:09 +02:00
2020-05-18 20:16:03 -04:00
2020-05-18 20:16:03 -04:00
2019-04-30 22:57:12 +02:00
2019-01-19 00:02:01 +01:00
2020-07-29 15:30:39 -04:00