There is a code responsible equal constant propagation which includes:
- 1. Field_time::get_equal_const_item()
- 2. Item::get_time_with_conversion()
- 3. datetime_to_time_with_warn()
This code makes automatic conversion from DATETIME to TIME in a special way, with handling of OLD_MODE_ZERO_DATE_TIME_CAST.
- a. In the old mode it takes the mmhhss.ff part for DATETIMEs which have zero YYYYMMDD.
- b. In the old mode it refuses to do propagation if YYYYMMDD is non-zero
- c. In the new mode it calculates TIME by doing subtraction: (DATETIME - CURRENT_DATE)
This is different from how TIME is constructed from DATETIME
in non-propagation context:
- either days are added to hours when YYYYMMDD has
zero year and month and non-zero day
- the entire YYYYMMDD part is truncated
MDEV-8894, in Field_time::get_equal_const_item() we'll need to call Time::round() soon.
To have an instance of Time easier, we'll move the mentioned code from
Item methods and public functions inside Time.
The code in Time() constructors already has the logic for DATETIME to TIME conversion, so Item::get_time_with_conversion() duplicates it in some extent. However, it misses propagation-specific conversion features.
In order to implement the desired behavior inside the Time() constructor, two new modes will be added into Time::datetime_to_time_mode_t:
so it will look like this:
The old methods and functions will be removed:
The calculation of (DATETIME-CURRENT_DATE) will migrate into a new method in Time, approximately like this: