Skip to content

Commit 653f687

Browse files
committed
MDEV-35865 atomic.alter_table times out often
The problem was that get_collation_number_internal() loops over all collations for finding a collation based on name. For looking up utf8mb4_0900_ aliases it used 22633 character strings comparisons at startup. Fixed by adding the MariaDB internal collation number in the "0900" alias lookup array. This is fine as collation numbers never changes. Discussed-with: serg@mariadb.com
1 parent b22eacc commit 653f687

File tree

3 files changed

+77
-66
lines changed

3 files changed

+77
-66
lines changed

include/my_sys.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,8 +1121,8 @@ extern my_bool init_compiled_charsets(myf flags);
11211121
extern void add_compiled_collation(struct charset_info_st *cs);
11221122
extern void add_compiled_extra_collation(struct charset_info_st *cs);
11231123
extern my_bool add_alias_for_collation(LEX_CSTRING *collation_name,
1124-
LEX_CSTRING *alias,
1125-
uint alias_id);
1124+
uint collation_id,
1125+
LEX_CSTRING *alias, uint alias_id);
11261126
extern size_t escape_string_for_mysql(CHARSET_INFO *charset_info,
11271127
char *to, size_t to_length,
11281128
const char *from, size_t length,

mysys/charset.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -646,21 +646,27 @@ void add_compiled_extra_collation(struct charset_info_st *cs)
646646
corresponding utf8mb4_1400 collation
647647
*/
648648

649-
my_bool add_alias_for_collation(LEX_CSTRING *collation_name, LEX_CSTRING *alias,
650-
uint alias_id)
649+
my_bool add_alias_for_collation(LEX_CSTRING *collation_name, uint org_id,
650+
LEX_CSTRING *alias, uint alias_id)
651651
{
652652
char *coll_name, *comment;
653653
struct charset_info_st *new_ci;
654654
CHARSET_INFO *org;
655655
MY_CHARSET_LOADER loader;
656656
char comment_buff[64+15];
657657
size_t comment_length;
658-
uint org_id= get_collation_number_internal(collation_name->str);
659-
DBUG_ASSERT(org_id);
660658
DBUG_ASSERT(all_charsets[org_id]);
661659

662660
if (!(org= all_charsets[org_id]))
663661
return 1;
662+
663+
DBUG_ASSERT(!my_strcasecmp(&my_charset_latin1, org->coll_name.str,
664+
collation_name->str));
665+
#ifdef DEBUG_PRINT_ALIAS
666+
fprintf(stderr, "alias: %s collation: %s org_id: %u\n",
667+
alias->str, collation_name->str, org_id);
668+
#endif
669+
664670
/*
665671
We have to init the character set to ensure it is not changed after we copy
666672
it.

strings/ctype-uca.c

Lines changed: 65 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -39567,81 +39567,87 @@ LEX_CSTRING my_ci_get_collation_name_uca(CHARSET_INFO *cs,
3956739567

3956839568
/*
3956939569
Add support for MySQL 8.0 utf8mb4_0900_.. collations
39570+
39571+
The collation id's where collected from fprintf() in add_alias_for_collation()
3957039572
*/
3957139573

3957239574
#define mysql_0900_collation_start 255
3957339575

3957439576
struct mysql_0900_to_mariadb_1400_mapping
3957539577
{
3957639578
const char *mysql_col_name, *mariadb_col_name, *case_sensitivity;
39579+
uint collation_id;
3957739580
};
3957839581

3957939582
struct mysql_0900_to_mariadb_1400_mapping mysql_0900_mapping[]=
3958039583
{
3958139584
/* 255 Ascent insensitive, Case insensitive 'ai_ci' */
39582-
{"", "", "ai_ci"},
39583-
{"de_pb", "german2", "ai_ci"},
39584-
{"is", "icelandic", "ai_ci"},
39585-
{"lv", "latvian", "ai_ci"},
39586-
{"ro", "romanian", "ai_ci"},
39587-
{"sl", "slovenian", "ai_ci"},
39588-
{"pl", "polish", "ai_ci"},
39589-
{"et", "estonian", "ai_ci"},
39590-
{"es", "spanish", "ai_ci"},
39591-
{"sv", "swedish", "ai_ci"},
39592-
{"tr", "turkish", "ai_ci"},
39593-
{"cs", "czech", "ai_ci"},
39594-
{"da", "danish", "ai_ci"},
39595-
{"lt", "lithuanian", "ai_ci"},
39596-
{"sk", "slovak", "ai_ci"},
39597-
{"es_trad", "spanish2", "ai_ci"},
39598-
{"la", "roman", "ai_ci"},
39599-
{"fa", NullS, "ai_ci"}, // Disabled in MySQL
39600-
{"eo", "esperanto", "ai_ci"},
39601-
{"hu", "hungarian", "ai_ci"},
39602-
{"hr", "croatian", "ai_ci"},
39603-
{"si", NullS, "ai_ci"}, // Disabled in MySQL
39604-
{"vi", "vietnamese", "ai_ci"},
39585+
{"", "", "ai_ci", 2308},
39586+
{"de_pb", "german2", "ai_ci", 2468},
39587+
{"is", "icelandic", "ai_ci", 2316},
39588+
{"lv", "latvian", "ai_ci", 2324},
39589+
{"ro", "romanian", "ai_ci", 2332},
39590+
{"sl", "slovenian", "ai_ci", 2340},
39591+
{"pl", "polish", "ai_ci", 2348},
39592+
{"et", "estonian", "ai_ci", 2356},
39593+
{"es", "spanish", "ai_ci", 2364},
39594+
{"sv", "swedish", "ai_ci", 2372},
39595+
{"tr", "turkish", "ai_ci", 2380},
39596+
{"cs", "czech", "ai_ci", 2388},
39597+
{"da", "danish", "ai_ci", 2396},
39598+
{"lt", "lithuanian", "ai_ci", 2404},
39599+
{"sk", "slovak", "ai_ci", 2412},
39600+
{"es_trad", "spanish2", "ai_ci", 2420},
39601+
{"la", "roman", "ai_ci", 2428},
39602+
{"fa", NullS, "ai_ci", 0}, // Disabled in MySQL
39603+
{"eo", "esperanto", "ai_ci", 2444},
39604+
{"hu", "hungarian", "ai_ci", 2452},
39605+
{"hr", "croatian", "ai_ci", 2500},
39606+
{"si", NullS, "ai_ci", 0}, // Disabled in MySQL
39607+
{"vi", "vietnamese", "ai_ci", 2492},
3960539608

3960639609
/* 278 Ascent sensitive, Case sensitive 'as_cs' */
39607-
{"","", "as_cs"},
39608-
{"de_pb", "german2", "as_cs"},
39609-
{"is", "icelandic", "as_cs"},
39610-
{"lv", "latvian", "as_cs"},
39611-
{"ro", "romanian", "as_cs"},
39612-
{"sl", "slovenian", "as_cs"},
39613-
{"pl", "polish", "as_cs"},
39614-
{"et", "estonian", "as_cs"},
39615-
{"es", "spanish", "as_cs"},
39616-
{"sv", "swedish", "as_cs"},
39617-
{"tr", "turkish", "as_cs"},
39618-
{"cs", "czech", "as_cs"},
39619-
{"da", "danish", "as_cs"},
39620-
{"lt", "lithuanian", "as_cs"},
39621-
{"sk", "slovak", "as_cs"},
39622-
{"es_trad", "spanish2", "as_cs"},
39623-
{"la", "roman", "as_cs"},
39624-
{"fa", NullS, "as_cs"}, // Disabled in MySQL
39625-
{"eo", "esperanto", "as_cs"},
39626-
{"hu", "hungarian", "as_cs"},
39627-
{"hr", "croatian", "as_cs"},
39628-
{"si", NullS, "as_cs"}, // Disabled in MySQL
39629-
{"vi", "vietnamese", "as_cs"},
39630-
39631-
{"", NullS, "as_cs"}, // Missing
39632-
{"", NullS, "as_cs"}, // Missing
39633-
{"_ja_0900_as_cs", NullS, "as_cs"}, // Not supported
39634-
{"_ja_0900_as_cs_ks", NullS, "as_cs"}, // Not supported
39610+
{"","", "as_cs", 2311},
39611+
{"de_pb", "german2", "as_cs", 2471},
39612+
{"is", "icelandic", "as_cs", 2319},
39613+
{"lv", "latvian", "as_cs", 2327},
39614+
{"ro", "romanian", "as_cs", 2335},
39615+
{"sl", "slovenian", "as_cs", 2343},
39616+
{"pl", "polish", "as_cs", 2351},
39617+
{"et", "estonian", "as_cs", 2359},
39618+
{"es", "spanish", "as_cs", 2367},
39619+
{"sv", "swedish", "as_cs", 2375},
39620+
{"tr", "turkish", "as_cs", 2383},
39621+
{"cs", "czech", "as_cs", 2391},
39622+
{"da", "danish", "as_cs", 2399},
39623+
{"lt", "lithuanian", "as_cs", 2407},
39624+
{"sk", "slovak", "as_cs", 2415},
39625+
{"es_trad", "spanish2", "as_cs", 2423},
39626+
{"la", "roman", "as_cs", 2431},
39627+
{"fa", NullS, "as_cs", 0}, // Disabled in MySQL
39628+
{"eo", "esperanto", "as_cs", 2447},
39629+
{"hu", "hungarian", "as_cs", 2455},
39630+
{"hr", "croatian", "as_cs", 2503},
39631+
{"si", NullS, "as_cs", 0}, // Disabled in MySQL
39632+
{"vi", "vietnamese", "as_cs", 2495},
39633+
39634+
{"", NullS, "as_cs", 0}, // Missing
39635+
{"", NullS, "as_cs", 0}, // Missing
39636+
{"_ja_0900_as_cs", NullS, "as_cs", 0}, // Not supported
39637+
{"_ja_0900_as_cs_ks", NullS, "as_cs", 0}, // Not supported
3963539638

3963639639
/* 305 Ascent-sensitive, Case insensitive 'as_ci' */
39637-
{"","", "as_ci"},
39638-
{"ru", NullS, "ai_ci"}, // Not supported
39639-
{"ru", NullS, "as_cs"}, // Not supported
39640-
{"zh", NullS, "as_cs"}, // Not supported
39641-
{NullS, NullS, ""}
39640+
{"","", "as_ci", 2310},
39641+
{"ru", NullS, "ai_ci", 0}, // Not supported
39642+
{"ru", NullS, "as_cs", 0}, // Not supported
39643+
{"zh", NullS, "as_cs", 0}, // Not supported
39644+
{NullS, NullS, "", 0}
3964239645
};
3964339646

3964439647

39648+
static LEX_CSTRING mysql_utf8_bin= { STRING_WITH_LEN("utf8mb4_0900_bin") };
39649+
static LEX_CSTRING mariadb_utf8_bin= { STRING_WITH_LEN("utf8mb4_bin") };
39650+
3964539651
/*
3964639652
Map mysql character sets to MariaDB using the same definition but with
3964739653
with the MySQL collation name and id.
@@ -39651,8 +39657,6 @@ my_bool mysql_utf8mb4_0900_collation_definitions_add()
3965139657
{
3965239658
uint id= mysql_0900_collation_start;
3965339659
struct mysql_0900_to_mariadb_1400_mapping *map;
39654-
LEX_CSTRING mysql_utf8_bin= { STRING_WITH_LEN("utf8mb4_0900_bin") };
39655-
LEX_CSTRING mariadb_utf8_bin= { STRING_WITH_LEN("utf8mb4_bin") };
3965639660

3965739661
for (map= mysql_0900_mapping; map->mysql_col_name ; map++, id++)
3965839662
{
@@ -39680,12 +39684,13 @@ my_bool mysql_utf8mb4_0900_collation_definitions_add()
3968039684
alias_name.str= alias;
3968139685
alias_name.length= ali_length;
3968239686

39683-
if (add_alias_for_collation(&org_name, &alias_name, id))
39687+
if (add_alias_for_collation(&org_name, map->collation_id, &alias_name,
39688+
id))
3968439689
return 1;
3968539690
}
3968639691
}
3968739692

39688-
if (add_alias_for_collation(&mariadb_utf8_bin, &mysql_utf8_bin, 309))
39693+
if (add_alias_for_collation(&mariadb_utf8_bin, 46, &mysql_utf8_bin, 309))
3968939694
return 1;
3969039695
return 0;
3969139696
}

0 commit comments

Comments
 (0)