Details
-
Task
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
None
Description
Timestamp truncation is currently implemented inside these methods:
- Field_timestamp::store_TIME()
- Field_timestampf::store_TIME()
- Field_timestamp_hires::store_TIME()
This is different comparing to how TIME and DATETIME do:
- store_TIME_with_warn() truncates the value according to the field scale
- store_TIME() gets a ready-to-store value
To implement MDEV-8894 easier, we'll change Field_timestamp the same way:
- rename virtual store_TIME to:
virtual void store_TIMEVAL(const timeval &tv);
and remove all truncation code from all virtual implementations. Move this method to "private" section.
- Fix store_TIME_with_warn() to do truncation, and call store_TIMEVAL() with a ready-to-store value.
- Add a non-virtual public method store_TIME(), because it's used externally. It will have exactly the same prototype as before (only non-virtual), with this implementation:
void store_TIME(my_time_t timestamp, ulong sec_part)
{
timeval tv= {timestamp, (uint) sec_part};
my_timeval_trunc(&tv, decimals());
store_TIMEVAL(tv);
}
- Modify Field_timestamp::store_TIME_with_warnings() to have this layout (similar to Field_time and Field_temporal_with_date, with extra DATETIME-to-TIMESTAMP conversion specific blocks):
int Field_timestamp::store_TIME_with_warning(THD *thd, const Datetime *dt, |
const ErrConv *str, int was_cut) |
{
|
// Handle totally bad values |
...
|
// Handle values that do not need DATETIME to TIMESTAMP conversion (e.g. '0000-00-00 00:00:00') |
...
|
// Convert DATETIME to TIMESTAMP |
...
|
// Adjust and store the value with truncation (and later with rounding) |
...
|
// Calculate return value and send warnings/notes if needed |
...
|
}
|
This is needed:
- To avoid duplicate rounding code in Field_timestamp, Field_timestampf, Field_timestamp_hires
- Rounding will possible issue its own warnings. It's important to have the warnings related code in one method, to avoid duplicate warnings, and to avoid less important notes if there is a truncation or rounding warning.
- For symmetry with the other temporal data implementation. We'll be adding TIMESTAMP WITH TIME ZONE soon. So symmetry gets even more important.
- To reuse store_TIME_return_code_with_warnings(), to guarantee that storeXXX() return the same return values under the same conditions.
Note, '2001-01-01 10:20:30garbage' currently makes Field::storeXXX() produce a return value of 2 for TIME/DATE/DATETIME, but 1 for TIMESTAMP. After this change, TIMESTAMP will also return 2. It will help to use range optimizer later for queries like this:
SELECT * FROM t1 WHERE temporal_column<'2000-01-01 10:20:30garbage'; |
(currently it's not used).
Attachments
Issue Links
- blocks
-
MDEV-4912 Data type plugin API version 1
- Closed
-
MDEV-8894 Inserting fractional seconds into MySQL 5.6 master breaks consistency on MariaDB 10 slave
- Closed
-
MDEV-10018 Timestamp with time zone
- Open