Column_definition::Column_definition(THD *thd, Field *old_field,
                                               Field *orig_field)
{
  field_name= old_field->field_name;
  length=     old_field->field_length;
  flags=      old_field->flags;
  unireg_check=old_field->unireg_check;
  pack_length=old_field->pack_length();
  key_length= old_field->key_length();
  sql_type=   old_field->real_type();
  charset=    old_field->charset();		// May be NULL ptr
  comment=    old_field->comment;
  decimals=   old_field->decimals();
  vcol_info=  old_field->vcol_info;
  default_value= orig_field ? orig_field->default_value : 0;
  check_constraint= orig_field ? orig_field->check_constraint : 0;
  option_list= old_field->option_list;

  switch (sql_type) {
  case MYSQL_TYPE_BLOB:
    switch (pack_length - portable_sizeof_char_ptr) {
    case  1: sql_type= MYSQL_TYPE_TINY_BLOB; break;
    case  2: sql_type= MYSQL_TYPE_BLOB; break;
    case  3: sql_type= MYSQL_TYPE_MEDIUM_BLOB; break;
    default: sql_type= MYSQL_TYPE_LONG_BLOB; break;
    }
    length/= charset->mbmaxlen;
    key_length/= charset->mbmaxlen;
    break;
  case MYSQL_TYPE_STRING:
    /* Change CHAR -> VARCHAR if dynamic record length */
    if (old_field->type() == MYSQL_TYPE_VAR_STRING)
      sql_type= MYSQL_TYPE_VARCHAR;
    /* fall through */

  case MYSQL_TYPE_ENUM:
  case MYSQL_TYPE_SET:
  case MYSQL_TYPE_VARCHAR:
  case MYSQL_TYPE_VAR_STRING:
    /* This is corrected in create_length_to_internal_length */
    length= (length+charset->mbmaxlen-1) / charset->mbmaxlen;
    break;
#ifdef HAVE_SPATIAL
  case MYSQL_TYPE_GEOMETRY:
    geom_type= ((Field_geom*)old_field)->geom_type;
    srid= ((Field_geom*)old_field)->srid;
    break;
#endif
  case MYSQL_TYPE_YEAR:
    if (length != 4)
    {
      char buff[sizeof("YEAR()") + MY_INT64_NUM_DECIMAL_DIGITS + 1];
      my_snprintf(buff, sizeof(buff), "YEAR(%llu)", length);
      push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE,
                          ER_WARN_DEPRECATED_SYNTAX,
                          ER_THD(thd, ER_WARN_DEPRECATED_SYNTAX),
                          buff, "YEAR(4)");
    }
    break;
  case MYSQL_TYPE_FLOAT:
  case MYSQL_TYPE_DOUBLE:
    /*
      Floating points are stored with FLOATING_POINT_DECIMALS but internally
      in MariaDB used with NOT_FIXED_DEC, which is >= FLOATING_POINT_DECIMALS.
    */
    if (decimals >= FLOATING_POINT_DECIMALS)
      decimals= NOT_FIXED_DEC;
    break;
  default:
    break;
  }

  if (flags & (ENUM_FLAG | SET_FLAG))
    interval= ((Field_enum*) old_field)->typelib;
  else
    interval=0;
  char_length= (uint)length;

  /*
    Copy the default (constant/function) from the column object orig_field, if
    supplied. We do this if all these conditions are met:

    - The column allows a default.

    - The column type is not a BLOB type (as BLOB's doesn't have constant
      defaults)

    - The original column (old_field) was properly initialized with a record
      buffer pointer.

    - The column didn't have a default expression
  */
  if (!(flags & (NO_DEFAULT_VALUE_FLAG | BLOB_FLAG)) &&
      old_field->ptr != NULL && orig_field != NULL)
  {
    if (orig_field->unireg_check != Field::NEXT_NUMBER)
      unireg_check= orig_field->unireg_check;

    /* Get the value from default_values */
    const uchar *dv= orig_field->table->s->default_values;
    if (!default_value && !orig_field->is_null_in_record(dv))
    {
      StringBuffer<MAX_FIELD_WIDTH> tmp(charset);
      String *res= orig_field->val_str(&tmp, orig_field->ptr_in_record(dv));
      char *pos= (char*) thd->strmake(res->ptr(), res->length());
      default_value= new (thd->mem_root) Virtual_column_info();
      default_value->expr=
        new (thd->mem_root) Item_string(thd, pos, res->length(), charset);
      default_value->utf8= 0;
    }
  }
}