Column_definition::Column_definition(THD *thd, Field *old_field,
                                               Field *orig_field)
{
  on_update=  NULL;
  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();
  set_handler(old_field->type_handler());
  charset=    old_field->charset();		// May be NULL ptr
  comment=    old_field->comment;
  decimals=   old_field->decimals();
  vcol_info=  old_field->vcol_info;
  option_list= old_field->option_list;
  pack_flag= 0;
  compression_method_ptr= 0;
  versioning= VERSIONING_NOT_SET;
  invisible= old_field->invisible;

  if (orig_field)
  {
    default_value= orig_field->default_value;
    check_constraint= orig_field->check_constraint;
    if (orig_field->unireg_check == Field::TMYSQL_COMPRESSED)
    {
      unireg_check= Field::TMYSQL_COMPRESSED;
      compression_method_ptr= zlib_compression_method;
    }
  }
  else
  {
    default_value= 0;
    check_constraint= 0;
  }

  switch (real_field_type()) {
  case MYSQL_TYPE_TINY_BLOB:
  case MYSQL_TYPE_BLOB:
  case MYSQL_TYPE_MEDIUM_BLOB:
  case MYSQL_TYPE_LONG_BLOB:
    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)
      set_handler(&type_handler_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 -
            MY_TEST(old_field->compression_method());
    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;

  interval_list.empty(); // prepare_interval_field() needs this

  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;
    }
  }
}