From 9a6e05d8b9908b3b0b5bca849f5af66e7c832e7c Mon Sep 17 00:00:00 2001 From: Alexander Nozdrin Date: Thu, 15 Jan 2009 12:36:34 +0300 Subject: [PATCH] Backport patch for Bug#31222 (com_% global status counters behave randomly with mysql_change_user) to 5.0. --- mysql-test/r/not_embedded_server.result | 7 +++++++ mysql-test/t/not_embedded_server.test | 28 +++++++++++++++++++++++++ sql/sql_class.cc | 4 ++++ 3 files changed, 39 insertions(+) diff --git a/mysql-test/r/not_embedded_server.result b/mysql-test/r/not_embedded_server.result index e471b5a3afa..edb698ade83 100644 --- a/mysql-test/r/not_embedded_server.result +++ b/mysql-test/r/not_embedded_server.result @@ -3,3 +3,10 @@ execute stmt1; Id User Host db Command Time State Info number root localhost test Query time NULL show full processlist deallocate prepare stmt1; +FLUSH STATUS; +SHOW GLOBAL STATUS LIKE 'com_select'; +Variable_name Value +Com_select 101 +SHOW GLOBAL STATUS LIKE 'com_select'; +Variable_name Value +Com_select 101 diff --git a/mysql-test/t/not_embedded_server.test b/mysql-test/t/not_embedded_server.test index 83ec03d6706..044d8665a18 100644 --- a/mysql-test/t/not_embedded_server.test +++ b/mysql-test/t/not_embedded_server.test @@ -16,3 +16,31 @@ execute stmt1; deallocate prepare stmt1; # End of 4.1 tests + +# +# Bug#31222: com_% global status counters behave randomly with +# mysql_change_user. +# + +FLUSH STATUS; + +--disable_result_log +--disable_query_log + +let $i = 100; + +while ($i) +{ + dec $i; + + SELECT 1; +} + +--enable_query_log +--enable_result_log + +SHOW GLOBAL STATUS LIKE 'com_select'; + +--change_user + +SHOW GLOBAL STATUS LIKE 'com_select'; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 883291ec460..91c0aa66761 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -391,6 +391,10 @@ void THD::init_for_queries() void THD::change_user(void) { + pthread_mutex_lock(&LOCK_status); + add_to_status(&global_status_var, &status_var); + pthread_mutex_unlock(&LOCK_status); + cleanup(); cleanup_done= 0; init();