1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-01 03:47:19 +03:00

MDEV-25900 Assertion octets < 1024' failed in Binlog_type_info_fixed_string::Binlog_type_info_fixed_string OR Assertion field_length < 1024' failed in Field_string::save_field_metadata

A CHAR column cannot be longer than 1024, because
Binlog_type_info_fixed_string::Binlog_type_info_fixed_string
replies on this fact - it cannot store binlog metadata for longer columns.

In case of the filename character set mbmaxlen is equal to 5,
so only 1024/5=204 characters can fit into the 1024 limit.
- In strict mode:
  Disallowing creation of a CHAR column with octet length grater than 1024.
- In non-strict mode:
  Automatically convert CHAR with octet length>1024 into VARCHAR.
This commit is contained in:
Alexander Barkov
2024-09-17 08:44:20 +04:00
parent 222744c54e
commit a1adabdd5c
3 changed files with 76 additions and 0 deletions

View File

@ -4734,6 +4734,33 @@ bool Column_definition::prepare_blob_field(THD *thd)
{
DBUG_ENTER("Column_definition::prepare_blob_field");
if (real_field_type() == FIELD_TYPE_STRING && length > 1024)
{
DBUG_ASSERT(charset->mbmaxlen > 4);
/*
Convert long CHAR columns to VARCHAR.
CHAR has an octet length limit of 1024 bytes.
The code in Binlog_type_info_fixed_string::Binlog_type_info_fixed_string
relies on this limit. If octet length of a CHAR column is greater
than 1024, then it cannot write its metadata to binlog properly.
In case of the filename character set with mbmaxlen=5,
the maximum possible character length is 1024/5=204 characters.
Upgrade to VARCHAR if octet length is greater than 1024.
*/
char warn_buff[MYSQL_ERRMSG_SIZE];
if (thd->is_strict_mode())
{
my_error(ER_TOO_BIG_FIELDLENGTH, MYF(0), field_name.str,
static_cast<ulong>(1024 / charset->mbmaxlen));
DBUG_RETURN(1);
}
set_handler(&type_handler_varchar);
my_snprintf(warn_buff, sizeof(warn_buff), ER_THD(thd, ER_AUTO_CONVERT),
field_name.str, "CHAR", "VARCHAR");
push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, ER_AUTO_CONVERT,
warn_buff);
}
if (length > MAX_FIELD_VARCHARLENGTH && !(flags & BLOB_FLAG))
{
/* Convert long VARCHAR columns to TEXT or BLOB */