diff options
-rw-r--r-- | include/my_sys.h | 5 | ||||
-rw-r--r-- | mysql-test/suite/plugins/r/feedback_plugin_load.result | 9 | ||||
-rw-r--r-- | mysql-test/suite/plugins/t/feedback_plugin_load.test | 13 | ||||
-rw-r--r-- | mysys/charset.c | 51 | ||||
-rw-r--r-- | plugin/feedback/feedback.cc | 3 | ||||
-rw-r--r-- | plugin/feedback/feedback.h | 1 | ||||
-rw-r--r-- | plugin/feedback/utils.cc | 19 |
7 files changed, 99 insertions, 2 deletions
diff --git a/include/my_sys.h b/include/my_sys.h index 4b4e5b7a22f..9913ee8c79b 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -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; diff --git a/mysql-test/suite/plugins/r/feedback_plugin_load.result b/mysql-test/suite/plugins/r/feedback_plugin_load.result index 443b91bf0cc..e5d1296ae53 100644 --- a/mysql-test/suite/plugins/r/feedback_plugin_load.result +++ b/mysql-test/suite/plugins/r/feedback_plugin_load.result @@ -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 diff --git a/mysql-test/suite/plugins/t/feedback_plugin_load.test b/mysql-test/suite/plugins/t/feedback_plugin_load.test index 5ad301667b4..b1bcb2a6bbd 100644 --- a/mysql-test/suite/plugins/t/feedback_plugin_load.test +++ b/mysql-test/suite/plugins/t/feedback_plugin_load.test @@ -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; diff --git a/mysys/charset.c b/mysys/charset.c index b7e535136a5..ad3eb78ae0e 100644 --- a/mysys/charset.c +++ b/mysys/charset.c @@ -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 */ - return cs; + { + 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; diff --git a/plugin/feedback/feedback.cc b/plugin/feedback/feedback.cc index 54459ae6f17..f644bd597d9 100644 --- a/plugin/feedback/feedback.cc +++ b/plugin/feedback/feedback.cc @@ -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; } diff --git a/plugin/feedback/feedback.h b/plugin/feedback/feedback.h index c5acbb5ef72..c2091afdedc 100644 --- a/plugin/feedback/feedback.h +++ b/plugin/feedback/feedback.h @@ -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; diff --git a/plugin/feedback/utils.cc b/plugin/feedback/utils.cc index 0510140aee9..b83b69be0ce 100644 --- a/plugin/feedback/utils.cc +++ b/plugin/feedback/utils.cc @@ -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 |