[MDEV-16938] Move Item::get_time_with_conversion() to Time Created: 2018-08-11  Updated: 2018-08-11  Resolved: 2018-08-11

Status: Closed
Project: MariaDB Server
Component/s: Data types, Temporal Types
Fix Version/s: 10.4.0

Type: Task Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
blocks MDEV-8894 Inserting fractional seconds into My... Closed

 Description   

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

For 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:

  • DATETIME_TO_TIME_YYYYMMDD_00000000_ONLY
  • DATETIME_TO_TIME_MINUS_CURRENT_DATE

so it will look like this:

  enum datetime_to_time_mode_t
  {
    DATETIME_TO_TIME_YYYYMMDD_000000DD_MIX_TO_HOURS,
    DATETIME_TO_TIME_YYYYMMDD_TRUNCATE,
    DATETIME_TO_TIME_YYYYMMDD_00000000_ONLY,
    DATETIME_TO_TIME_MINUS_CURRENT_DATE
  };

The old methods and functions will be removed:

  • Item::get_time_with_conversion()
  • datetime_to_time_with_warn()
  • datetime_to_time()

The calculation of (DATETIME-CURRENT_DATE) will migrate into a new method in Time, approximately like this:

  void datetime_to_time_minus_current_date(THD *thd)
  {
    MYSQL_TIME current_date, tmp;
    set_current_date(thd, &current_date);
    calc_time_diff(this, &current_date, 1, &tmp, 0);
    static_cast<MYSQL_TIME*>(this)[0]= tmp;
    int warnings= 0;
    (void) check_time_range(this, TIME_SECOND_PART_DIGITS, &warnings);
    DBUG_ASSERT(is_valid_time());
  }


Generated at Thu Feb 08 08:32:41 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.