[MDEV-19566] Remove Item::name related strlen() calls in constructors of some Item_string descendands Created: 2019-05-23  Updated: 2019-05-23  Resolved: 2019-05-23

Status: Closed
Project: MariaDB Server
Component/s: Data types
Fix Version/s: 10.5.0

Type: Task Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
blocks MDEV-4912 Data type plugin API version 1 Closed

 Description   

The following classes use strlen() when handling name related parameters to constructors:

  • Item_string
  • Item_blob
  • Item_empty_string

Examples:

  // Constructors with an externally provided item name
  Item_string(THD *thd, const char *name_par, const char *str, size_t length,
              CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE)
   :Item_literal(thd)
  {
    str_value.set_or_copy_aligned(str, length, cs);
    fix_from_value(dv, Metadata(&str_value));
    set_name(thd, name_par,safe_strlen(name_par), system_charset_info);
  }
  Item_string(THD *thd, const char *name_par, const char *str, size_t length,
              CHARSET_INFO *cs, Derivation dv, uint repertoire)
   :Item_literal(thd)
  {
    str_value.set_or_copy_aligned(str, length, cs);
    fix_from_value(dv, Metadata(&str_value, repertoire));
    set_name(thd, name_par, safe_strlen(name_par), system_charset_info);
  }

  Item_blob(THD *thd, const char *name_arg, uint length):
    Item_partition_func_safe_string(thd, name_arg, (uint) safe_strlen(name_arg),
                                    &my_charset_bin)
  { max_length= length; }

  Item_empty_string(THD *thd, const char *header,uint length,
                    CHARSET_INFO *cs= NULL):
    Item_partition_func_safe_string(thd, "", 0,
                                    cs ? cs : &my_charset_utf8_general_ci)
    {
      name.str=    header;
      name.length= strlen(name.str);
      max_length= length * collation.collation->mbmaxlen;
    }

We should eventually get rid of all strlen().

Under terms of this tasks we'll move strlen() calls to upper level:

  • change the mentioned constructors to accept LEX_CSTRING instead of a const char pointer
  • let the caller provide length.

This task is needed to do some upcoming Type_handler related changes easier, e.g. decompose create_schema_table in sql_show.cc into implementations virtual in Type_handler.

Additionally, we'll introduce a new version of Item::set_name() accepting LEX_CSTRING as a parameter:

void set_name(THD *thd, const LEX_CSTRING &str, CHARSET_INFO *cs= system_charset_info)
{
   set_name(thd, str.str, str.length, cs);
}

and reuse it in a few places, especially in sql_show.cc, which has a lot calls like this:

     field->set_name(thd, field_info->old_name,
                     strlen(field_info->old_name),
                     system_charset_info);

Also, let's add methods to ST_FIELD_INFO:

  LEX_CSTRING get_name() const
  {
    return LEX_CSTRING({field_name, strlen(field_name)});
  }
  LEX_CSTRING get_old_name() const
  {
    return LEX_CSTRING({old_name, strlen(old_name)});
  }

to reuse new set_name() easier.


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