Commit 22a64047 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-6274 Collation usage statistics

Adding collation usage statistics into the feedback plugin I_S table.
parent 4105cbf4
...@@ -242,6 +242,11 @@ extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *default_charset_info; ...@@ -242,6 +242,11 @@ extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *default_charset_info;
extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *all_charsets[MY_ALL_CHARSETS_SIZE]; extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *all_charsets[MY_ALL_CHARSETS_SIZE];
extern struct charset_info_st compiled_charsets[]; extern struct charset_info_st compiled_charsets[];
/* Collation properties and use statistics */
extern my_bool my_collation_is_known_id(uint id);
extern ulonglong my_collation_statistics_get_use_count(uint id);
extern const char *my_collation_get_tailoring(uint id);
/* statistics */ /* statistics */
extern ulong my_file_opened,my_stream_opened, my_tmp_file_created; extern ulong my_file_opened,my_stream_opened, my_tmp_file_created;
extern ulong my_file_total_opened; extern ulong my_file_total_opened;
......
...@@ -10,3 +10,12 @@ FEEDBACK_SEND_RETRY_WAIT 60 ...@@ -10,3 +10,12 @@ FEEDBACK_SEND_RETRY_WAIT 60
FEEDBACK_SEND_TIMEOUT 60 FEEDBACK_SEND_TIMEOUT 60
FEEDBACK_URL http://mariadb.org/feedback_plugin/post FEEDBACK_URL http://mariadb.org/feedback_plugin/post
FEEDBACK_USER_INFO mysql-test FEEDBACK_USER_INFO mysql-test
SELECT VARIABLE_VALUE>0, VARIABLE_NAME FROM INFORMATION_SCHEMA.FEEDBACK
WHERE VARIABLE_NAME LIKE 'Collation used %'
ORDER BY VARIABLE_NAME;
VARIABLE_VALUE>0 VARIABLE_NAME
1 Collation used binary
1 Collation used latin1_bin
1 Collation used latin1_swedish_ci
1 Collation used utf8_bin
1 Collation used utf8_general_ci
...@@ -8,3 +8,16 @@ select plugin_status from information_schema.plugins where plugin_name='feedback ...@@ -8,3 +8,16 @@ select plugin_status from information_schema.plugins where plugin_name='feedback
--sorted_result --sorted_result
select * from information_schema.feedback where variable_name like 'feed%' select * from information_schema.feedback where variable_name like 'feed%'
and variable_name not like '%_uid'; and variable_name not like '%_uid';
# Embedded server does not use the table mysqld.user and thus
# does not automatically use latin1_bin on startup. Use it manually.
--disable_query_log
if (`SELECT VERSION() LIKE '%embedded%'`)
{
DO _latin1'test' COLLATE latin1_bin;
}
--enable_query_log
SELECT VARIABLE_VALUE>0, VARIABLE_NAME FROM INFORMATION_SCHEMA.FEEDBACK
WHERE VARIABLE_NAME LIKE 'Collation used %'
ORDER BY VARIABLE_NAME;
...@@ -483,6 +483,50 @@ void add_compiled_collation(struct charset_info_st *cs) ...@@ -483,6 +483,50 @@ void add_compiled_collation(struct charset_info_st *cs)
static my_pthread_once_t charsets_initialized= MY_PTHREAD_ONCE_INIT; static my_pthread_once_t charsets_initialized= MY_PTHREAD_ONCE_INIT;
static my_pthread_once_t charsets_template= MY_PTHREAD_ONCE_INIT; static my_pthread_once_t charsets_template= MY_PTHREAD_ONCE_INIT;
typedef struct
{
ulonglong use_count;
} MY_COLLATION_STATISTICS;
static MY_COLLATION_STATISTICS my_collation_statistics[MY_ALL_CHARSETS_SIZE];
my_bool my_collation_is_known_id(uint id)
{
return id > 0 && id < array_elements(all_charsets) && all_charsets[id] ?
TRUE : FALSE;
}
/*
Collation use statistics functions do not lock
counters to avoid mutex contention. This can lose
some counter increments with high thread concurrency.
But this should be Ok, as we don't need exact numbers.
*/
static inline void my_collation_statistics_inc_use_count(uint id)
{
DBUG_ASSERT(my_collation_is_known_id(id));
my_collation_statistics[id].use_count++;
}
ulonglong my_collation_statistics_get_use_count(uint id)
{
DBUG_ASSERT(my_collation_is_known_id(id));
return my_collation_statistics[id].use_count;
}
const char *my_collation_get_tailoring(uint id)
{
/* all_charsets[id]->tailoring is never changed after server startup. */
DBUG_ASSERT(my_collation_is_known_id(id));
return all_charsets[id]->tailoring;
}
static void init_available_charsets(void) static void init_available_charsets(void)
{ {
char fname[FN_REFLEN + sizeof(MY_CHARSET_INDEX)]; char fname[FN_REFLEN + sizeof(MY_CHARSET_INDEX)];
...@@ -490,6 +534,7 @@ static void init_available_charsets(void) ...@@ -490,6 +534,7 @@ static void init_available_charsets(void)
MY_CHARSET_LOADER loader; MY_CHARSET_LOADER loader;
bzero((char*) &all_charsets,sizeof(all_charsets)); bzero((char*) &all_charsets,sizeof(all_charsets));
bzero((char*) &my_collation_statistics, sizeof(my_collation_statistics));
init_compiled_charsets(MYF(0)); init_compiled_charsets(MYF(0));
/* Copy compiled charsets */ /* Copy compiled charsets */
...@@ -608,7 +653,10 @@ get_internal_charset(MY_CHARSET_LOADER *loader, uint cs_number, myf flags) ...@@ -608,7 +653,10 @@ get_internal_charset(MY_CHARSET_LOADER *loader, uint cs_number, myf flags)
if ((cs= (struct charset_info_st*) all_charsets[cs_number])) if ((cs= (struct charset_info_st*) all_charsets[cs_number]))
{ {
if (cs->state & MY_CS_READY) /* if CS is already initialized */ if (cs->state & MY_CS_READY) /* if CS is already initialized */
{
my_collation_statistics_inc_use_count(cs_number);
return cs; return cs;
}
/* /*
To make things thread safe we are not allowing other threads to interfere To make things thread safe we are not allowing other threads to interfere
...@@ -636,6 +684,7 @@ get_internal_charset(MY_CHARSET_LOADER *loader, uint cs_number, myf flags) ...@@ -636,6 +684,7 @@ get_internal_charset(MY_CHARSET_LOADER *loader, uint cs_number, myf flags)
else else
cs->state|= MY_CS_READY; cs->state|= MY_CS_READY;
} }
my_collation_statistics_inc_use_count(cs_number);
} }
else else
cs= NULL; cs= NULL;
......
...@@ -217,7 +217,8 @@ int fill_feedback(THD *thd, TABLE_LIST *tables, COND *unused) ...@@ -217,7 +217,8 @@ int fill_feedback(THD *thd, TABLE_LIST *tables, COND *unused)
tables->schema_table= i_s_feedback; tables->schema_table= i_s_feedback;
res= res || fill_plugin_version(thd, tables) res= res || fill_plugin_version(thd, tables)
|| fill_misc_data(thd, tables) || fill_misc_data(thd, tables)
|| fill_linux_info(thd, tables); || fill_linux_info(thd, tables)
|| fill_collation_statistics(thd, tables);
return res; return res;
} }
......
...@@ -22,6 +22,7 @@ int fill_feedback(THD *thd, TABLE_LIST *tables, COND *cond); ...@@ -22,6 +22,7 @@ int fill_feedback(THD *thd, TABLE_LIST *tables, COND *cond);
int fill_plugin_version(THD *thd, TABLE_LIST *tables); int fill_plugin_version(THD *thd, TABLE_LIST *tables);
int fill_misc_data(THD *thd, TABLE_LIST *tables); int fill_misc_data(THD *thd, TABLE_LIST *tables);
int fill_linux_info(THD *thd, TABLE_LIST *tables); int fill_linux_info(THD *thd, TABLE_LIST *tables);
int fill_collation_statistics(THD *thd, TABLE_LIST *tables);
static const int SERVER_UID_SIZE= 29; static const int SERVER_UID_SIZE= 29;
extern char server_uid_buf[SERVER_UID_SIZE+1], *user_info; extern char server_uid_buf[SERVER_UID_SIZE+1], *user_info;
......
...@@ -383,6 +383,25 @@ int fill_misc_data(THD *thd, TABLE_LIST *tables) ...@@ -383,6 +383,25 @@ int fill_misc_data(THD *thd, TABLE_LIST *tables)
return 0; return 0;
} }
int fill_collation_statistics(THD *thd, TABLE_LIST *tables)
{
TABLE *table= tables->table;
for (uint id= 1; id < MY_ALL_CHARSETS_SIZE; id++)
{
ulonglong count;
if (my_collation_is_known_id(id) &&
(count= my_collation_statistics_get_use_count(id)))
{
char name[MY_CS_NAME_SIZE + 32];
size_t namelen= my_snprintf(name, sizeof(name),
"Collation used %s",
get_charset_name(id));
INSERT2(name, namelen, (count, UNSIGNED));
}
}
return 0;
};
/** /**
calculates the server unique identifier calculates the server unique identifier
......
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