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;
extern MYSQL_PLUGIN_IMPORT CHARSET_INFO *all_charsets[MY_ALL_CHARSETS_SIZE];
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 */
extern ulong my_file_opened,my_stream_opened, my_tmp_file_created;
extern ulong my_file_total_opened;
......
......@@ -10,3 +10,12 @@ FEEDBACK_SEND_RETRY_WAIT 60
FEEDBACK_SEND_TIMEOUT 60
FEEDBACK_URL http://mariadb.org/feedback_plugin/post
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
--sorted_result
select * from information_schema.feedback where variable_name like 'feed%'
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)
static my_pthread_once_t charsets_initialized= 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)
{
char fname[FN_REFLEN + sizeof(MY_CHARSET_INDEX)];
......@@ -490,6 +534,7 @@ static void init_available_charsets(void)
MY_CHARSET_LOADER loader;
bzero((char*) &all_charsets,sizeof(all_charsets));
bzero((char*) &my_collation_statistics, sizeof(my_collation_statistics));
init_compiled_charsets(MYF(0));
/* Copy compiled charsets */
......@@ -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->state & MY_CS_READY) /* if CS is already initialized */
{
my_collation_statistics_inc_use_count(cs_number);
return cs;
}
/*
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)
else
cs->state|= MY_CS_READY;
}
my_collation_statistics_inc_use_count(cs_number);
}
else
cs= NULL;
......
......@@ -217,7 +217,8 @@ int fill_feedback(THD *thd, TABLE_LIST *tables, COND *unused)
tables->schema_table= i_s_feedback;
res= res || fill_plugin_version(thd, tables)
|| fill_misc_data(thd, tables)
|| fill_linux_info(thd, tables);
|| fill_linux_info(thd, tables)
|| fill_collation_statistics(thd, tables);
return res;
}
......
......@@ -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_misc_data(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;
extern char server_uid_buf[SERVER_UID_SIZE+1], *user_info;
......
......@@ -383,6 +383,25 @@ int fill_misc_data(THD *thd, TABLE_LIST *tables)
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
......
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