MDEV-23154 Add a data type my_repertoire_t

This commit is contained in:
Alexander Barkov 2020-07-13 16:19:49 +04:00
parent d34eb4b1f6
commit 5967dfdbbf
9 changed files with 47 additions and 24 deletions

View File

@ -226,9 +226,14 @@ extern MY_UNI_CTYPE my_uni_ctype[256];
#define MY_CHARSET_UNDEFINED 0 #define MY_CHARSET_UNDEFINED 0
/* Character repertoire flags */ /* Character repertoire flags */
#define MY_REPERTOIRE_ASCII 1 /* Pure ASCII U+0000..U+007F */ typedef enum enum_repertoire_t
#define MY_REPERTOIRE_EXTENDED 2 /* Extended characters: U+0080..U+FFFF */ {
#define MY_REPERTOIRE_UNICODE30 3 /* ASCII | EXTENDED: U+0000..U+FFFF */ MY_REPERTOIRE_NONE= 0,
MY_REPERTOIRE_ASCII= 1, /* Pure ASCII U+0000..U+007F */
MY_REPERTOIRE_EXTENDED= 2, /* Extended characters: U+0080..U+FFFF */
MY_REPERTOIRE_UNICODE30= 3 /* ASCII | EXTENDED: U+0000..U+FFFF */
} my_repertoire_t;
/* Flags for strxfrm */ /* Flags for strxfrm */
#define MY_STRXFRM_LEVEL1 0x00000001 /* for primary weights */ #define MY_STRXFRM_LEVEL1 0x00000001 /* for primary weights */
@ -1420,14 +1425,15 @@ my_bool my_propagate_complex(CHARSET_INFO *cs, const uchar *str, size_t len);
typedef struct typedef struct
{ {
size_t char_length; size_t char_length;
uint repertoire; my_repertoire_t repertoire;
} MY_STRING_METADATA; } MY_STRING_METADATA;
void my_string_metadata_get(MY_STRING_METADATA *metadata, void my_string_metadata_get(MY_STRING_METADATA *metadata,
CHARSET_INFO *cs, const char *str, size_t len); CHARSET_INFO *cs, const char *str, size_t len);
uint my_string_repertoire(CHARSET_INFO *cs, const char *str, size_t len); my_repertoire_t my_string_repertoire(CHARSET_INFO *cs,
const char *str, size_t len);
my_bool my_charset_is_ascii_based(CHARSET_INFO *cs); my_bool my_charset_is_ascii_based(CHARSET_INFO *cs);
uint my_charset_repertoire(CHARSET_INFO *cs); my_repertoire_t my_charset_repertoire(CHARSET_INFO *cs);
uint my_strxfrm_flag_normalize(uint flags, uint nlevels); uint my_strxfrm_flag_normalize(uint flags, uint nlevels);
void my_strxfrm_desc_and_reverse(uchar *str, uchar *strend, void my_strxfrm_desc_and_reverse(uchar *str, uchar *strend,

View File

@ -2430,7 +2430,7 @@ bool DTCollation::aggregate(const DTCollation &dt, uint flags)
{ {
if (derivation == DERIVATION_EXPLICIT) if (derivation == DERIVATION_EXPLICIT)
{ {
set(0, DERIVATION_NONE, 0); set(0, DERIVATION_NONE, MY_REPERTOIRE_NONE);
return 1; return 1;
} }
if (collation->state & MY_CS_BINSORT && if (collation->state & MY_CS_BINSORT &&
@ -3911,7 +3911,7 @@ Item_null::make_string_literal_concat(THD *thd, const LEX_CSTRING *str)
if (str->length) if (str->length)
{ {
CHARSET_INFO *cs= thd->variables.collation_connection; CHARSET_INFO *cs= thd->variables.collation_connection;
uint repertoire= my_string_repertoire(cs, str->str, str->length); my_repertoire_t repertoire= my_string_repertoire(cs, str->str, str->length);
return new (thd->mem_root) Item_string(thd, return new (thd->mem_root) Item_string(thd,
str->str, (uint) str->length, cs, str->str, (uint) str->length, cs,
DERIVATION_COERCIBLE, repertoire); DERIVATION_COERCIBLE, repertoire);

View File

@ -2767,12 +2767,15 @@ protected:
{ {
my_string_metadata_get(this, str->charset(), str->ptr(), str->length()); my_string_metadata_get(this, str->charset(), str->ptr(), str->length());
} }
Metadata(const String *str, uint repertoire_arg) Metadata(const String *str, my_repertoire_t repertoire_arg)
{ {
MY_STRING_METADATA::repertoire= repertoire_arg; MY_STRING_METADATA::repertoire= repertoire_arg;
MY_STRING_METADATA::char_length= str->numchars(); MY_STRING_METADATA::char_length= str->numchars();
} }
uint repertoire() const { return MY_STRING_METADATA::repertoire; } my_repertoire_t repertoire() const
{
return MY_STRING_METADATA::repertoire;
}
size_t char_length() const { return MY_STRING_METADATA::char_length; } size_t char_length() const { return MY_STRING_METADATA::char_length; }
}; };
void fix_charset_and_length(CHARSET_INFO *cs, void fix_charset_and_length(CHARSET_INFO *cs,
@ -4400,7 +4403,7 @@ public:
} }
// Constructors with the item name set from its value // Constructors with the item name set from its value
Item_string(THD *thd, const char *str, uint length, CHARSET_INFO *cs, Item_string(THD *thd, const char *str, uint length, CHARSET_INFO *cs,
Derivation dv, uint repertoire) Derivation dv, my_repertoire_t repertoire)
:Item_literal(thd) :Item_literal(thd)
{ {
str_value.set_or_copy_aligned(str, length, cs); str_value.set_or_copy_aligned(str, length, cs);
@ -4414,7 +4417,7 @@ public:
fix_and_set_name_from_value(thd, dv, Metadata(&str_value)); fix_and_set_name_from_value(thd, dv, Metadata(&str_value));
} }
Item_string(THD *thd, const String *str, CHARSET_INFO *tocs, uint *conv_errors, Item_string(THD *thd, const String *str, CHARSET_INFO *tocs, uint *conv_errors,
Derivation dv, uint repertoire) Derivation dv, my_repertoire_t repertoire)
:Item_literal(thd) :Item_literal(thd)
{ {
if (str_value.copy(str, tocs, conv_errors)) if (str_value.copy(str, tocs, conv_errors))
@ -4432,7 +4435,7 @@ public:
set_name(thd, name_par); set_name(thd, name_par);
} }
Item_string(THD *thd, const LEX_CSTRING &name_par, const LEX_CSTRING &str, Item_string(THD *thd, const LEX_CSTRING &name_par, const LEX_CSTRING &str,
CHARSET_INFO *cs, Derivation dv, uint repertoire) CHARSET_INFO *cs, Derivation dv, my_repertoire_t repertoire)
:Item_literal(thd) :Item_literal(thd)
{ {
str_value.set_or_copy_aligned(str.str, str.length, cs); str_value.set_or_copy_aligned(str.str, str.length, cs);
@ -4565,7 +4568,7 @@ public:
Item_static_string_func(THD *thd, const LEX_CSTRING &name_par, Item_static_string_func(THD *thd, const LEX_CSTRING &name_par,
const String *str, const String *str,
CHARSET_INFO *tocs, uint *conv_errors, CHARSET_INFO *tocs, uint *conv_errors,
Derivation dv, uint repertoire): Derivation dv, my_repertoire_t repertoire):
Item_string(thd, str, tocs, conv_errors, dv, repertoire), Item_string(thd, str, tocs, conv_errors, dv, repertoire),
func_name(name_par) func_name(name_par)
{} {}

View File

@ -1742,7 +1742,7 @@ bool Item_func_date_format::fix_length_and_dec()
decimals=0; decimals=0;
CHARSET_INFO *cs= thd->variables.collation_connection; CHARSET_INFO *cs= thd->variables.collation_connection;
uint32 repertoire= arg1->collation.repertoire; my_repertoire_t repertoire= arg1->collation.repertoire;
if (!thd->variables.lc_time_names->is_ascii) if (!thd->variables.lc_time_names->is_ascii)
repertoire|= MY_REPERTOIRE_EXTENDED; repertoire|= MY_REPERTOIRE_EXTENDED;
collation.set(cs, arg1->collation.derivation, repertoire); collation.set(cs, arg1->collation.derivation, repertoire);

View File

@ -2493,7 +2493,8 @@ bool THD::to_ident_sys_alloc(Lex_ident_sys_st *to, const Lex_ident_cli_st *ident
Item_basic_constant * Item_basic_constant *
THD::make_string_literal(const char *str, size_t length, uint repertoire) THD::make_string_literal(const char *str, size_t length,
my_repertoire_t repertoire)
{ {
if (!length && (variables.sql_mode & MODE_EMPTY_STRING_IS_NULL)) if (!length && (variables.sql_mode & MODE_EMPTY_STRING_IS_NULL))
return new (mem_root) Item_null(this, 0, variables.collation_connection); return new (mem_root) Item_null(this, 0, variables.collation_connection);

View File

@ -3935,10 +3935,10 @@ public:
@param repertoire - the repertoire of the string @param repertoire - the repertoire of the string
*/ */
Item_basic_constant *make_string_literal(const char *str, size_t length, Item_basic_constant *make_string_literal(const char *str, size_t length,
uint repertoire); my_repertoire_t repertoire);
Item_basic_constant *make_string_literal(const Lex_string_with_metadata_st &str) Item_basic_constant *make_string_literal(const Lex_string_with_metadata_st &str)
{ {
uint repertoire= str.repertoire(variables.character_set_client); my_repertoire_t repertoire= str.repertoire(variables.character_set_client);
return make_string_literal(str.str, str.length, repertoire); return make_string_literal(str.str, str.length, repertoire);
} }
Item_basic_constant *make_string_literal_nchar(const Lex_string_with_metadata_st &str); Item_basic_constant *make_string_literal_nchar(const Lex_string_with_metadata_st &str);

View File

@ -85,13 +85,13 @@ public:
bool is_quoted() const { return m_quote != '\0'; } bool is_quoted() const { return m_quote != '\0'; }
char quote() const { return m_quote; } char quote() const { return m_quote; }
// Get string repertoire by the 8-bit flag and the character set // Get string repertoire by the 8-bit flag and the character set
uint repertoire(CHARSET_INFO *cs) const my_repertoire_t repertoire(CHARSET_INFO *cs) const
{ {
return !m_is_8bit && my_charset_is_ascii_based(cs) ? return !m_is_8bit && my_charset_is_ascii_based(cs) ?
MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30; MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30;
} }
// Get string repertoire by the 8-bit flag, for ASCII-based character sets // Get string repertoire by the 8-bit flag, for ASCII-based character sets
uint repertoire() const my_repertoire_t repertoire() const
{ {
return !m_is_8bit ? MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30; return !m_is_8bit ? MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30;
} }

View File

@ -60,7 +60,7 @@ public:
grouping(grouping_par), grouping(grouping_par),
errmsgs(errmsgs_par) errmsgs(errmsgs_par)
{} {}
uint repertoire() const my_repertoire_t repertoire() const
{ return is_ascii ? MY_REPERTOIRE_ASCII : MY_REPERTOIRE_EXTENDED; } { return is_ascii ? MY_REPERTOIRE_ASCII : MY_REPERTOIRE_EXTENDED; }
}; };
/* Exported variables */ /* Exported variables */

View File

@ -2712,6 +2712,19 @@ public:
#define MY_REPERTOIRE_NUMERIC MY_REPERTOIRE_ASCII #define MY_REPERTOIRE_NUMERIC MY_REPERTOIRE_ASCII
static inline my_repertoire_t operator|(const my_repertoire_t a,
const my_repertoire_t b)
{
return (my_repertoire_t) ((uint) a | (uint) b);
}
static inline my_repertoire_t &operator|=(my_repertoire_t &a,
const my_repertoire_t b)
{
return a= (my_repertoire_t) ((uint) a | (uint) b);
}
enum Derivation enum Derivation
{ {
DERIVATION_IGNORABLE= 6, DERIVATION_IGNORABLE= 6,
@ -2733,7 +2746,7 @@ class DTCollation {
public: public:
CHARSET_INFO *collation; CHARSET_INFO *collation;
enum Derivation derivation; enum Derivation derivation;
uint repertoire; my_repertoire_t repertoire;
void set_repertoire_from_charset(CHARSET_INFO *cs) void set_repertoire_from_charset(CHARSET_INFO *cs)
{ {
@ -2769,7 +2782,7 @@ public:
} }
DTCollation(CHARSET_INFO *collation_arg, DTCollation(CHARSET_INFO *collation_arg,
Derivation derivation_arg, Derivation derivation_arg,
uint repertoire_arg) my_repertoire_t repertoire_arg)
:collation(collation_arg), :collation(collation_arg),
derivation(derivation_arg), derivation(derivation_arg),
repertoire(repertoire_arg) repertoire(repertoire_arg)
@ -2786,7 +2799,7 @@ public:
} }
void set(CHARSET_INFO *collation_arg, void set(CHARSET_INFO *collation_arg,
Derivation derivation_arg, Derivation derivation_arg,
uint repertoire_arg) my_repertoire_t repertoire_arg)
{ {
collation= collation_arg; collation= collation_arg;
derivation= derivation_arg; derivation= derivation_arg;