1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

MDEV-32188 make TIMESTAMP use whole 32-bit unsigned range

This patch extends the timestamp from
2038-01-19 03:14:07.999999 to 2106-02-07 06:28:15.999999
for 64 bit hardware and OS where 'long' is 64 bits.
This is true for 64 bit Linux but not for Windows.

This is done by treating the 32 bit stored int as unsigned instead of
signed.  This is safe as MariaDB has never accepted dates before the epoch
(1970).
The benefit of this approach that for normal timestamp the storage is
compatible with earlier version.

However for tables using system versioning we before stored a
timestamp with the year 2038 as the 'max timestamp', which is used to
detect current values.  This patch stores the new 2106 year max value
as the max timestamp. This means that old tables using system
versioning needs to be updated with mariadb-upgrade when moving them
to 11.4. That will be done in a separate commit.
This commit is contained in:
Monty
2023-09-11 17:58:22 +03:00
committed by Sergei Golubchik
parent ce6cce85d4
commit dfdedd46e4
90 changed files with 1227 additions and 354 deletions

View File

@@ -30,15 +30,26 @@ C_MODE_START
extern MYSQL_PLUGIN_IMPORT ulonglong log_10_int[20];
extern uchar days_in_month[];
#if SIZEOF_LONG == 4
#define MY_TIME_T_MAX LONG_MAX
#define MY_TIME_T_MIN LONG_MIN
/* Time handling defaults */
#define TIMESTAMP_MAX_YEAR 2038
#define TIMESTAMP_MIN_YEAR (1900 + YY_PART_YEAR - 1)
#define TIMESTAMP_MAX_MONTH 1
#define TIMESTAMP_MAX_DAY 19
#define TIMESTAMP_MAX_VALUE INT_MAX32
#define TIMESTAMP_MIN_VALUE 0
#else
/* Use 4 byte unsigned timestamp */
#define MY_TIME_T_MAX ((longlong) UINT_MAX32)
#define MY_TIME_T_MIN 0
#define TIMESTAMP_MAX_YEAR 2106
#define TIMESTAMP_MIN_VALUE 0
#define TIMESTAMP_MAX_VALUE ((longlong) UINT_MAX32)
#define TIMESTAMP_MAX_MONTH 2
#define TIMESTAMP_MAX_DAY 7
#endif /* SIZEOF_LONG */
#define TIMESTAMP_MIN_YEAR (1900 + YY_PART_YEAR - 1)
/* two-digit years < this are 20..; >= this are 19.. */
#define YY_PART_YEAR 70
@@ -48,8 +59,8 @@ extern uchar days_in_month[];
*/
#if SIZEOF_TIME_T > 4 || defined(TIME_T_UNSIGNED)
# define IS_TIME_T_VALID_FOR_TIMESTAMP(x) \
((x) <= TIMESTAMP_MAX_VALUE && \
(x) >= TIMESTAMP_MIN_VALUE)
((ulonglong) (x) <= TIMESTAMP_MAX_VALUE && \
((x) >= TIMESTAMP_MIN_VALUE)
#else
# define IS_TIME_T_VALID_FOR_TIMESTAMP(x) \
((x) >= TIMESTAMP_MIN_VALUE)
@@ -181,7 +192,6 @@ void my_init_time(void);
static inline my_bool validate_timestamp_range(const MYSQL_TIME *t)
{
if ((t->year > TIMESTAMP_MAX_YEAR || t->year < TIMESTAMP_MIN_YEAR) ||
(t->year == TIMESTAMP_MAX_YEAR && (t->month > 1 || t->day > 19)) ||
(t->year == TIMESTAMP_MIN_YEAR && (t->month < 12 || t->day < 31)))
return FALSE;