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

Make Field_time, Field_datetime, Field_timestamp abstract

    XMLWordPrintable

Details

    Description

      Currenly classes Field_time, Field_datetime, Field_timestamp are parent classes for all TIME, DATETIME, TIMESTAMP field implementations, and at the same time are instantiable classes implementing the pre-mysql-5.6 style TIME(0), DATETIME(0), TIMESTAMP(0).

      The class hierarchy looks like this:

      Field_temporal
        Field_temporal_with_date
          Field_datetime              -- instantiable
            Field_datetime_with_dec   -- abstract
              Field_datetime_hires    -- instantiable
              Field_datetimef         -- instantiable
       
        Field_timestamp               -- instantiable
          Field_timestamp_with_dec    -- abstract
            Field_timestamp_hires     -- instantiable
            Field_timestampf          -- instantiable
       
        Field_time                    -- instantiable
          Field_time_with_dec         -- abstract
            Field_time_hires          -- instantiable
            Field_timef               -- instantiable
      

      This hierarchy style is too hard to follow because of multiple overriding, and is error prone because children classes can easily forget to override important methods.

      For example, Field_datetimef has to overload the following Field_datetime methods:

        enum ha_base_keytype key_type() const override;
        double val_real() override;
        longlong val_int() override;
        String *val_str(String *, String *) override;
        bool send_binary(Protocol *protocol) override;
        int cmp(const uchar *,const uchar *) const override;
        void sort_string(uchar *buff,uint length) override;
        uint32 pack_length() const override;
        bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate) override;
        uchar *pack(uchar* to, const uchar *from, uint) override;
        const uchar *unpack(uchar* to, const uchar *from, const uchar *from_end,
                            uint) override;
        uint size_of() const override;
      

      The same style of multiple overriding happens in all instantiable Field_datetime, Field_timestamp, Field_time descendant classes.

      MDEV-19906 would have to introduce more multiple overriding and make things harder to follow.

      Let's do the following changes:

      • Introduce instantiable classes Field_datetime0, Field_timestamp0, Field_time0 implementing pre-mysql-5.6 DATETIME(0), TIMESTAMP(0), TIME(0) respectively.
      • Change Field_datetime, Field_timestamp, Field_time to be abstract

      Implementation of the methods mentioned above will

      • migrate from Field_datetime to Field_datetime0, Field_timestamp to Field_timestamp0, Field_time to Field_time0.
      • become zero pointers in the abstract classes Field_datetime, Field_timestamp, Field_time, so it won't be possible to leave these methods unimplemented in the instrantiable descendants

      The new hierarchy will look like this:

      Field_temporal
        Field_temporal_with_date
          Field_datetime              -- abstract
            Field_datetime0           -- instantiable
            Field_datetime_with_dec   -- abstract
              Field_datetime_hires    -- instantiable
              Field_datetimef         -- instantiable
       
        Field_timestamp               -- abstract
          Field_timestamp0            -- instantiable
          Field_timestamp_with_dec    -- abstract
            Field_timestamp_hires     -- instantiable
            Field_timestampf          -- instantiable
       
        Field_time                    -- abstract
          Field_time0                 -- instantiable
          Field_time_with_dec         -- abstract
            Field_time_hires          -- instantiable
            Field_timef               -- instantiable
      

      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.