[MDEV-19772] Add helper classes for ST_FIELD_INFO Created: 2019-06-16  Updated: 2022-04-28  Resolved: 2019-06-17

Status: Closed
Project: MariaDB Server
Component/s: Data types, Information Schema
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
blocks MDEV-19810 Reuse new I_S table definition helper... Closed
blocks MDEV-19818 Reuse new I_S table definition helper... Closed
blocks MDEV-19832 Reuse new I_S table definition helper... Closed
blocks MDEV-19833 Reuse new I_S table definition helper... Closed
blocks MDEV-19836 Reuse new I_S table definition helper... Closed
blocks MDEV-19843 Modify ST_FIELD_INFO to use Type_hand... Closed

 Description   

ST_FIELD_INFO is used to define INFORMATION_SCHEMA columns. A typical INFORMATION_SCHEMA table definition looks like this:

ST_FIELD_INFO schema_fields_info[]=
{
  {"CATALOG_NAME", FN_REFLEN, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE},
  {"SCHEMA_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Database",
   SKIP_OPEN_TABLE},
  {"DEFAULT_CHARACTER_SET_NAME", MY_CS_NAME_SIZE, MYSQL_TYPE_STRING, 0, 0, 0,
   SKIP_OPEN_TABLE},
  {"DEFAULT_COLLATION_NAME", MY_CS_NAME_SIZE, MYSQL_TYPE_STRING, 0, 0, 0,
   SKIP_OPEN_TABLE},
  {"SQL_PATH", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE},
  {"SCHEMA_COMMENT", DATABASE_COMMENT_MAXLEN, MYSQL_TYPE_STRING, 0, 0, 0,
   SKIP_OPEN_TABLE},
  {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
};

It has two problems:

  • It's not friently for user plugins, which may want to create INFORMATION_SCHEMA tables with their own data types.
  • When a Field is created inside Type_handler_xxx::make_schema_field(), strlen() is called for ST_FIELD_INFO::field_name, for every column, every time an INFORMATION_SCHEMA query is done. This is not performance wise.

To solve these problems let do the following:

  • Add a namespace Show
  • Add a helper class Show::Column
  • Add a number of Show classes for various data types, with this hierarchy:

    Type
      Blob
      Varchar
        Yesno
        Catalog
        Name
        Definer
        Userhost
        CSName
        SQLMode
      Longtext
      Datetime
      Decimal
      ULonglong
      ULong
      SLonglong
      SLong
      SShort
      STiny
      Double
    

This will hide internal implementation details of ST_FIELD_INFO from the upper level code. An INFORMATION_SCHEMA table definition will look like this:

namespace Show {
 
ST_FIELD_INFO schema_fields_info[]=
{
  Column("CATALOG_NAME",               Catalog(),        NOT_NULL),
  Column("SCHEMA_NAME",                Name(),           NOT_NULL, "Database"),
  Column("DEFAULT_CHARACTER_SET_NAME", CSName(),         NOT_NULL),
  Column("DEFAULT_COLLATION_NAME",     CSName(),         NOT_NULL),
  Column("SQL_PATH",                   Str(FN_REFLEN),   NULLABLE),
  Column("SCHEMA_COMMENT", Str(DATABASE_COMMENT_MAXLEN), NOT_NULL),
  CEnd()
};
...
} // namespace Show

This task covers the code in /sql and /plugins.

As the next step, in separate patchs, we'll do the following:

  • Fix the code in /storage to use the new classes instead of direct ST_FIELD_INFO initialization.
  • In ST_FIELD_INFO, replace enum_field_types field_type to const Type_handler *handler.
  • In ST_FIELD_INFO, replace const char *field_name to LEX_CSTRING field_name.
    which will solve the two mentioned problems.

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