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

Move fractional second truncation from Item_xxx_typecast::get_date() to Time and Datetime constructors

    XMLWordPrintable

Details

    Description

      This task is self-sufficient change MDEV-16991.

      To make the main MDEV-16991 patch simpler, we'll move fractional second truncation from these methods:

      Item_time_typecast::get_date()
      Item_datetime_typecast::get_date()
      

      inside new truncating Time and Datetime constructors.

      Time(Item *item, const Options opt, uint dec)
       :Temporal(Time(item, opt))
      {
        trunc(dec);
      }
       
      Datetime(THD *thd, Item *item, sql_mode_t flags, uint dec)
       :Temporal_with_date(Datetime(thd, item, flags))
      {
        trunc(dec);
      }
      

      Later, in the main patch for MDEV-16991, all truncating Time and Datetime constructors will be fixed to choose between truncation and rounding, according to the current session options. So CAST will automatically start using proper truncation mode.

      Additionally, we'll do the following changes:

      • in Item_date_typecast::get_date(), replace the call for make_date_with_warn() to a constructor call Date().
      • Remove the function make_date_with_warn()
      • Remove the check_date_with_warn() call in Item_time_typecast::get_date() that was added in MDEV-4653 in 5.3.13. It is not needed any more. After recent changes, in the scenario described by MDEV-4653 (with old_mode=ZERO_DATE_TIME_CAST), dates are checked inside the constructor of Temporal_with_date() on the caller level.
      • Add a placement "new" operator the for class Temporal:

        static void *operator new(size_t size, MYSQL_TIME *ltime) throw()
        {
          DBUG_ASSERT(size == sizeof(MYSQL_TIME));
          return ltime;
        }
        

        to be able to put values of Time, Date and Datetime directly into an existing MYSQL_TIME structure.

      As a result the get_date() implementations for the affected classes will look as simple as:

      bool Item_time_typecast::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
      {
        Time *tm= new(ltime) Time(args[0], Time::Options_for_cast(),
                                  MY_MIN(decimals, TIME_SECOND_PART_DIGITS));
        return (null_value= !tm->is_valid_time());
      }
       
       
      bool Item_date_typecast::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
      {
        fuzzy_date= (fuzzy_date | sql_mode_for_dates(current_thd)) & ~TIME_TIME_ONLY;
        Date *d= new(ltime) Date(current_thd, args[0], fuzzy_date);
        return (null_value= !d->is_valid_date());
      }
       
       
      bool Item_datetime_typecast::get_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
      {
        fuzzy_date= (fuzzy_date | sql_mode_for_dates(current_thd)) & ~TIME_TIME_ONLY;
        Datetime *dt= new(ltime) Datetime(current_thd, args[0], fuzzy_date,
                                          MY_MIN(decimals, TIME_SECOND_PART_DIGITS));
        return (null_value= !dt->is_valid_datetime());
      }
      

      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.