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

Add Type_handler::decimal_precision()

    Details

      Description

      The code in Item::decimal_precision():

      uint Item::decimal_precision() const
      {
        Item_result restype= result_type();
       
        if ((restype == DECIMAL_RESULT) || (restype == INT_RESULT))
        {
          uint prec= 
            my_decimal_length_to_precision(max_char_length(), decimals,
                                           unsigned_flag);
          return MY_MIN(prec, DECIMAL_MAX_PRECISION);
        }
        uint res= max_char_length();
        /*
          Return at least one decimal digit, even if Item::max_char_length()
          returned  0. This is important to avoid attempts to create fields of types
          INT(0) or DECIMAL(0,0) when converting NULL or empty strings to INT/DECIMAL:
            CREATE TABLE t1 AS SELECT CONVERT(NULL,SIGNED) AS a;
        */
        return res ? MY_MIN(res, DECIMAL_MAX_PRECISION) : 1;
      }
      
      

      • is not friendly to pluggable types
      • does not handle temporal types properly (e.g. MDEV-12769)

      We'll introduce a new method in Type_handler:

      virtual uint Item_decimal_precision(const Item *item) const;
      

      and split Item::decimal_precision() into implementations of the relevant Type_handler_xxx.

      The implementation of Item::decimal_precision() will change to:

       

      virtual uint decimal_precision() const

      { return type_handler()->Item_decimal_precision(this); } {cpp}

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: