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

Move TIMESTAMP truncation code to Field_timestamp::store_TIME_with_warn

    XMLWordPrintable

Details

    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

          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.