Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-16938

Move Item::get_time_with_conversion() to Time

    XMLWordPrintable

Details

    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());
        }
      

      Attachments

        Issue Links

          Activity

            People

              bar Alexander Barkov
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.