Commit 71f5f881 authored by unknown's avatar unknown

Fix for Bug#31222: com_% global status counters

behave randomly with mysql_change_user.
  
The problem was that global status variables were not updated
in THD::check_user(), so thread statistics were lost after
COM_CHANGE_USER.
  
The fix is to update global status variables with the thread ones
before preparing the thread for new user.


mysql-test/r/change_user.result:
  Update result file.
mysql-test/t/change_user.test:
  Add a test case for Bug#31222: com_% global status counters
  behave randomly with mysql_change_user.
sql/sql_class.cc:
  Update global status variables when we're handling
  COM_CHANGE_USER for a thread.
parent c36f69b9
...@@ -44,3 +44,10 @@ IS_FREE_LOCK('bug31418') ...@@ -44,3 +44,10 @@ IS_FREE_LOCK('bug31418')
SELECT IS_USED_LOCK('bug31418'); SELECT IS_USED_LOCK('bug31418');
IS_USED_LOCK('bug31418') IS_USED_LOCK('bug31418')
NULL NULL
FLUSH STATUS;
SHOW GLOBAL STATUS LIKE 'com_select';
Variable_name Value
Com_select 112
SHOW GLOBAL STATUS LIKE 'com_select';
Variable_name Value
Com_select 112
...@@ -33,3 +33,31 @@ SELECT IS_USED_LOCK('bug31418') = CONNECTION_ID(); ...@@ -33,3 +33,31 @@ SELECT IS_USED_LOCK('bug31418') = CONNECTION_ID();
--change_user --change_user
SELECT IS_FREE_LOCK('bug31418'); SELECT IS_FREE_LOCK('bug31418');
SELECT IS_USED_LOCK('bug31418'); SELECT IS_USED_LOCK('bug31418');
#
# 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';
...@@ -769,6 +769,10 @@ void THD::init_for_queries() ...@@ -769,6 +769,10 @@ void THD::init_for_queries()
void THD::change_user(void) 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();
killed= NOT_KILLED; killed= NOT_KILLED;
cleanup_done= 0; cleanup_done= 0;
......
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