[MDEV-12770] Add Type_handler::decimal_precision() Created: 2017-05-10  Updated: 2017-05-10  Resolved: 2017-05-10

Status: Closed
Project: MariaDB Server
Component/s: OTHER
Fix Version/s: 10.3.1

Type: Task Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: datatype, refactoring

Issue Links:
Blocks
blocks MDEV-4912 Data type plugin API version 1 Closed
Relates
relates to MDEV-12769 Arithmetic operators with temporal ty... Closed

 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}

 Comments   
Comment by Alexander Barkov [ 2017-05-10 ]

Pushed to bb-10.2-ext

Generated at Thu Feb 08 08:00:20 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.