Commit fc839644 authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-27767 poor scaling with InnoDB and utf8mb3 because of charset stats

Access the all_charsets[] array directly in a hot loop.
This avoids get_charset() that increments a shared counter via
my_collation_statistics_inc_use_count(), causing a scalability issue.

Instead, call get_charset() when a table is opened (and InnoDB
fills in dtype_t values) - this is enough, as charset is marked
ready (MY_CS_READY) only once, on the first get_charset() call,
after that it can be accessed directly.

This also fixes a potential bug in InnoDB. It used to access charsets
directly when filling dtype_t values. This wasn't preceded by any
get_charset() call inside InnoDB. Normally the server would call
get_charset() on reading the frm, but if the table was first opened
from a purge thread InnoDB could, theoretically, access a not-ready
charset in innobase_get_cset_width().
parent 5615a78a
......@@ -2418,7 +2418,7 @@ innobase_get_cset_width(
ut_ad(mbminlen);
ut_ad(mbmaxlen);
cs = all_charsets[cset];
cs = cset ? get_charset((uint)cset, MYF(MY_WME)) : NULL;
if (cs) {
*mbminlen = cs->mbminlen;
*mbmaxlen = cs->mbmaxlen;
......
......@@ -281,15 +281,13 @@ static int cmp_data(ulint mtype, ulint prtype, const byte *data1, ulint len1,
/* fall through */
case DATA_VARMYSQL:
DBUG_ASSERT(is_strnncoll_compatible(prtype & DATA_MYSQL_TYPE_MASK));
if (CHARSET_INFO *cs= get_charset(dtype_get_charset_coll(prtype),
MYF(MY_WME)))
if (CHARSET_INFO *cs= all_charsets[dtype_get_charset_coll(prtype)])
return cs->coll->strnncollsp(cs, data1, len1, data2, len2);
no_collation:
ib::fatal() << "Unable to find charset-collation for " << prtype;
case DATA_MYSQL:
DBUG_ASSERT(is_strnncoll_compatible(prtype & DATA_MYSQL_TYPE_MASK));
if (CHARSET_INFO *cs= get_charset(dtype_get_charset_coll(prtype),
MYF(MY_WME)))
if (CHARSET_INFO *cs= all_charsets[dtype_get_charset_coll(prtype)])
return cs->coll->strnncollsp_nchars(cs, data1, len1, data2, len2,
std::max(len1, len2));
goto no_collation;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment