mariadb/sql/sql_i_s.h
Alexander Barkov 133446828c MDEV-27009 Add UCA-14.0.0 collations
- Added one neutral and 22 tailored (language specific) collations based on
  Unicode Collation Algorithm version 14.0.0.

  Collations were added for Unicode character sets
  utf8mb3, utf8mb4, ucs2, utf16, utf32.

  Every tailoring was added with four accent and case
  sensitivity flag combinations, e.g:

  * utf8mb4_uca1400_swedish_as_cs
  * utf8mb4_uca1400_swedish_as_ci
  * utf8mb4_uca1400_swedish_ai_cs
  * utf8mb4_uca1400_swedish_ai_ci

  and their _nopad_ variants:

  * utf8mb4_uca1400_swedish_nopad_as_cs
  * utf8mb4_uca1400_swedish_nopad_as_ci
  * utf8mb4_uca1400_swedish_nopad_ai_cs
  * utf8mb4_uca1400_swedish_nopad_ai_ci

- Introducing a conception of contextually typed named collations:

  CREATE DATABASE db1 CHARACTER SET utf8mb4;
  CREATE TABLE db1.t1 (a CHAR(10) COLLATE uca1400_as_ci);

  The idea is that there is no a need to specify the character set prefix
  in the new collation names. It's enough to type just the suffix
  "uca1400_as_ci". The character set is taken from the context.

  In the above example script the context character set is utf8mb4.
  So the CREATE TABLE will make a column with the collation
  utf8mb4_uca1400_as_ci.

  Short collations names can be used in any parts of the SQL syntax
  where the COLLATE clause is understood.

- New collations are displayed only one time
  (without character set combinations) by these statements:

     SELECT * FROM INFORMATION_SCHEMA.COLLATIONS;
     SHOW COLLATION;

  For example, all these collations:
  - utf8mb3_uca1400_swedish_as_ci
  - utf8mb4_uca1400_swedish_as_ci
  - ucs2_uca1400_swedish_as_ci
  - utf16_uca1400_swedish_as_ci
  - utf32_uca1400_swedish_as_ci
  have just one entry in INFORMATION_SCHEMA.COLLATIONS and SHOW COLLATION,
  with COLLATION_NAME equal to "uca1400_swedish_as_ci", which is the suffix
  without the character set name:

SELECT COLLATION_NAME FROM INFORMATION_SCHEMA.COLLATIONS
WHERE COLLATION_NAME LIKE '%uca1400_swedish_as_ci';

+-----------------------+
| COLLATION_NAME        |
+-----------------------+
| uca1400_swedish_as_ci |
+-----------------------+

  Note, the behaviour of old collations did not change.
  Non-unicode collations (e.g. latin1_swedish_ci) and
  old UCA-4.0.0 collations (e.g. utf8mb4_unicode_ci)
  are still displayed with the character set prefix, as before.

- The structure of the table INFORMATION_SCHEMA.COLLATIONS was changed.

  The NOT NULL constraint was removed from these columns:
  - CHARACTER_SET_NAME
  - ID
  - IS_DEFAULT
  and from the corresponding columns in SHOW COLLATION.

  For example:

SELECT COLLATION_NAME, CHARACTER_SET_NAME, ID, IS_DEFAULT
FROM INFORMATION_SCHEMA.COLLATIONS
WHERE COLLATION_NAME LIKE '%uca1400_swedish_as_ci';
+-----------------------+--------------------+------+------------+
| COLLATION_NAME        | CHARACTER_SET_NAME | ID   | IS_DEFAULT |
+-----------------------+--------------------+------+------------+
| uca1400_swedish_as_ci | NULL               | NULL | NULL       |
+-----------------------+--------------------+------+------------+

  The NULL value in these columns now means that the collation
  is applicable to multiple character sets.
  The behavioir of old collations did not change.
  Make sure your client programs can handle NULL values in these columns.

- The structure of the table
  INFORMATION_SCHEMA.COLLATION_CHARACTER_SET_APPLICABILITY was changed.

  Three new NOT NULL columns were added:
  - FULL_COLLATION_NAME
  - ID
  - IS_DEFAULT

  New collations have multiple entries in COLLATION_CHARACTER_SET_APPLICABILITY.
  The column COLLATION_NAME contains the collation name without the character
  set prefix. The column FULL_COLLATION_NAME contains the collation name with
  the character set prefix.

  Old collations have full collation name in both FULL_COLLATION_NAME and
  COLLATION_NAME.

SELECT COLLATION_NAME, FULL_COLLATION_NAME, CHARACTER_SET_NAME, ID, IS_DEFAULT
FROM INFORMATION_SCHEMA.COLLATION_CHARACTER_SET_APPLICABILITY
WHERE FULL_COLLATION_NAME RLIKE '^(utf8mb4|latin1).*swedish.*ci$';
+-----------------------------+-------------------------------------+--------------------+------+------------+
| COLLATION_NAME              | FULL_COLLATION_NAME                 | CHARACTER_SET_NAME | ID   | IS_DEFAULT |
+-----------------------------+-------------------------------------+--------------------+------+------------+
| latin1_swedish_ci           | latin1_swedish_ci                   | latin1             |    8 | Yes        |
| latin1_swedish_nopad_ci     | latin1_swedish_nopad_ci             | latin1             | 1032 |            |
| utf8mb4_swedish_ci          | utf8mb4_swedish_ci                  | utf8mb4            |  232 |            |
| uca1400_swedish_ai_ci       | utf8mb4_uca1400_swedish_ai_ci       | utf8mb4            | 2368 |            |
| uca1400_swedish_as_ci       | utf8mb4_uca1400_swedish_as_ci       | utf8mb4            | 2370 |            |
| uca1400_swedish_nopad_ai_ci | utf8mb4_uca1400_swedish_nopad_ai_ci | utf8mb4            | 2372 |            |
| uca1400_swedish_nopad_as_ci | utf8mb4_uca1400_swedish_nopad_as_ci | utf8mb4            | 2374 |            |
+-----------------------------+-------------------------------------+--------------------+------+------------+

- Other INFORMATION_SCHEMA queries:

  SELECT COLLATION_NAME FROM INFORMATION_SCHEMA.COLUMNS;
  SELECT COLLATION_NAME FROM INFORMATION_SCHEMA.PARAMETERS;
  SELECT TABLE_COLLATION FROM INFORMATION_SCHEMA.TABLES;
  SELECT DEFAULT_COLLATION_NAME FROM INFORMATION_SCHEMA.SCHEMATA;
  SELECT COLLATION_NAME FROM INFORMATION_SCHEMA.ROUTINES;
  SELECT COLLATION_CONNECTION FROM INFORMATION_SCHEMA.EVENTS;
  SELECT DATABASE_COLLATION FROM INFORMATION_SCHEMA.EVENTS;
  SELECT COLLATION_CONNECTION FROM INFORMATION_SCHEMA.ROUTINES;
  SELECT DATABASE_COLLATION FROM INFORMATION_SCHEMA.ROUTINES;
  SELECT COLLATION_CONNECTION FROM INFORMATION_SCHEMA.TRIGGERS;
  SELECT DATABASE_COLLATION FROM INFORMATION_SCHEMA.TRIGGERS;
  SELECT COLLATION_CONNECTION FROM INFORMATION_SCHEMA.VIEWS;

  display full collation names, including character sets prefix,
  for all collations, including new collations.

  Corresponding SHOW commands also display full collation names
  in collation related columns:

  SHOW CREATE TABLE t1;
  SHOW CREATE DATABASE db1;
  SHOW TABLE STATUS;
  SHOW CREATE FUNCTION f1;
  SHOW CREATE PROCEDURE p1;
  SHOW CREATE EVENT ev1;
  SHOW CREATE TRIGGER tr1;
  SHOW CREATE VIEW;

  These INFORMATION_SCHEMA queries and SHOW statements may change in
  the future, to display show collation names.
2022-08-10 15:04:24 +02:00

349 lines
8.3 KiB
C++

#ifndef SQL_I_S_INCLUDED
#define SQL_I_S_INCLUDED
/* Copyright (c) 2000, 2017, Oracle and/or its affiliates.
Copyright (c) 2009, 2019, MariaDB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
#include "sql_const.h" // MAX_FIELD_VARCHARLENGTH
#include "sql_basic_types.h" // enum_nullability
#include "sql_string.h" // strlen, MY_CS_CHARACTER_SET_NAME_SIZE
#include "lex_string.h" // LEX_CSTRING
#include "mysql_com.h" // enum_field_types
#include "my_time.h" // TIME_SECOND_PART_DIGITS
#include "sql_type.h" // Type_handler_xxx
struct TABLE_LIST;
struct TABLE;
typedef class Item COND;
#ifdef MYSQL_CLIENT
#error MYSQL_CLIENT must not be defined
#endif // MYSQL_CLIENT
bool schema_table_store_record(THD *thd, TABLE *table);
COND *make_cond_for_info_schema(THD *thd, COND *cond, TABLE_LIST *table);
enum enum_show_open_table
{
SKIP_OPEN_TABLE= 0U, // do not open table
OPEN_FRM_ONLY= 1U, // open FRM file only
OPEN_FULL_TABLE= 2U // open FRM,MYD, MYI files
};
namespace Show {
class Type
{
/**
This denotes data type for the column. For the most part, there seems to
be one entry in the enum for each SQL data type, although there seem to
be a number of additional entries in the enum.
*/
const Type_handler *m_type_handler;
/**
For string-type columns, this is the maximum number of
characters. Otherwise, it is the 'display-length' for the column.
*/
uint m_char_length;
uint m_unsigned_flag;
const Typelib *m_typelib;
public:
Type(const Type_handler *th, uint length, uint unsigned_flag,
const Typelib *typelib= NULL)
:m_type_handler(th), m_char_length(length), m_unsigned_flag(unsigned_flag),
m_typelib(typelib)
{ }
const Type_handler *type_handler() const { return m_type_handler; }
uint char_length() const { return m_char_length; }
decimal_digits_t decimal_precision() const
{ return (decimal_digits_t) ((m_char_length / 100) % 100); }
decimal_digits_t decimal_scale() const
{ return (decimal_digits_t) (m_char_length % 10); }
uint fsp() const
{
DBUG_ASSERT(m_char_length <= TIME_SECOND_PART_DIGITS);
return m_char_length;
}
uint unsigned_flag() const { return m_unsigned_flag; }
const Typelib *typelib() const { return m_typelib; }
};
} // namespace Show
class ST_FIELD_INFO: public Show::Type
{
protected:
LEX_CSTRING m_name; // I_S column name
enum_nullability m_nullability; // NULLABLE or NOT NULL
LEX_CSTRING m_old_name; // SHOW column name
enum_show_open_table m_open_method;
public:
ST_FIELD_INFO(const LEX_CSTRING &name, const Type &type,
enum_nullability nullability,
LEX_CSTRING &old_name,
enum_show_open_table open_method)
:Type(type), m_name(name),
m_nullability(nullability),
m_old_name(old_name),
m_open_method(open_method)
{ }
ST_FIELD_INFO(const char *name, const Type &type,
enum_nullability nullability,
const char *old_name,
enum_show_open_table open_method)
:Type(type),
m_nullability(nullability),
m_open_method(open_method)
{
m_name.str= name;
m_name.length= safe_strlen(name);
m_old_name.str= old_name;
m_old_name.length= safe_strlen(old_name);
}
const LEX_CSTRING &name() const { return m_name; }
bool nullable() const { return m_nullability == NULLABLE; }
const LEX_CSTRING &old_name() const { return m_old_name; }
enum_show_open_table open_method() const { return m_open_method; }
bool end_marker() const { return m_name.str == NULL; }
};
namespace Show
{
class Enum: public Type
{
public:
Enum(const Typelib *typelib) :Type(&type_handler_enum, 0, false, typelib) { }
};
class Blob: public Type
{
public:
Blob(uint length) :Type(&type_handler_blob, length, false) { }
};
class Varchar: public Type
{
public:
Varchar(uint length) :Type(&type_handler_varchar, length, false)
{
DBUG_ASSERT(length * 3 <= MAX_FIELD_VARCHARLENGTH);
}
};
class Longtext: public Type
{
public:
Longtext(uint length) :Type(&type_handler_varchar, length, false) { }
};
class Yes_or_empty: public Varchar
{
public:
Yes_or_empty(): Varchar(3) { }
static LEX_CSTRING value(bool val)
{
return val ? Lex_cstring(STRING_WITH_LEN("Yes")) :
Lex_cstring();
}
};
class Catalog: public Varchar
{
public:
Catalog(): Varchar(FN_REFLEN) { }
};
class Name: public Varchar
{
public:
Name(): Varchar(NAME_CHAR_LEN) { }
};
class Definer: public Varchar
{
public:
Definer(): Varchar(DEFINER_CHAR_LENGTH) { }
};
class Userhost: public Varchar
{
public:
Userhost(): Varchar(USERNAME_CHAR_LENGTH + HOSTNAME_LENGTH + 2) { }
};
class CSName: public Varchar
{
public:
CSName(): Varchar(MY_CS_CHARACTER_SET_NAME_SIZE) { }
};
class CLName: public Varchar
{
public:
CLName(): Varchar(MY_CS_COLLATION_NAME_SIZE) { }
};
class SQLMode: public Varchar
{
public:
SQLMode(): Varchar(32*256) { }
};
class Datetime: public Type
{
public:
Datetime(uint dec) :Type(&type_handler_datetime2, dec, false) { }
};
class Decimal: public Type
{
public:
Decimal(uint length) :Type(&type_handler_newdecimal, length, false) { }
};
class ULonglong: public Type
{
public:
ULonglong(uint length) :Type(&type_handler_ulonglong, length, true) { }
ULonglong() :ULonglong(MY_INT64_NUM_DECIMAL_DIGITS) { }
};
class ULong: public Type
{
public:
ULong(uint length) :Type(&type_handler_ulong, length, true) { }
ULong() :ULong(MY_INT32_NUM_DECIMAL_DIGITS) { }
};
class SLonglong: public Type
{
public:
SLonglong(uint length) :Type(&type_handler_slonglong, length, false) { }
SLonglong() :SLonglong(MY_INT64_NUM_DECIMAL_DIGITS) { }
};
class SLong: public Type
{
public:
SLong(uint length) :Type(&type_handler_slong, length, false) { }
SLong() :SLong(MY_INT32_NUM_DECIMAL_DIGITS) { }
};
class SShort: public Type
{
public:
SShort(uint length) :Type(&type_handler_sshort, length, false) { }
};
class STiny: public Type
{
public:
STiny(uint length) :Type(&type_handler_stiny, length, false) { }
};
class Double: public Type
{
public:
Double(uint length) :Type(&type_handler_double, length, false) { }
};
class Float: public Type
{
public:
Float(uint length) :Type(&type_handler_float, length, false) { }
};
class Column: public ST_FIELD_INFO
{
public:
Column(const char *name, const Type &type,
enum_nullability nullability,
const char *old_name,
enum_show_open_table open_method= SKIP_OPEN_TABLE)
:ST_FIELD_INFO(name, type, nullability,
old_name, open_method)
{ }
Column(const char *name, const Type &type,
enum_nullability nullability,
enum_show_open_table open_method= SKIP_OPEN_TABLE)
:ST_FIELD_INFO(name, type, nullability,
NullS, open_method)
{ }
};
// End marker
class CEnd: public Column
{
public:
CEnd() :Column(NullS, Varchar(0), NOT_NULL, NullS, SKIP_OPEN_TABLE) { }
};
} // namespace Show
struct TABLE_LIST;
typedef class Item COND;
typedef struct st_schema_table
{
const char *table_name;
ST_FIELD_INFO *fields_info;
/* for FLUSH table_name */
int (*reset_table) ();
/* Fill table with data */
int (*fill_table) (THD *thd, TABLE_LIST *tables, COND *cond);
/* Handle fileds for old SHOW */
int (*old_format) (THD *thd, struct st_schema_table *schema_table);
int (*process_table) (THD *thd, TABLE_LIST *tables, TABLE *table,
bool res, const LEX_CSTRING *db_name,
const LEX_CSTRING *table_name);
int idx_field1, idx_field2;
bool hidden;
uint i_s_requested_object; /* the object we need to open(TABLE | VIEW) */
} ST_SCHEMA_TABLE;
#endif // SQL_I_S_INCLUDED