Below is the list of changes that have just been committed into a local
5.1 repository of anozdrin. When anozdrin does a push these changes
will be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2008-02-06 15:13:55+03:00, anozdrin@quad. +2 -0
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.
sql/sql_class.cc@stripped, 2008-02-06 15:13:54+03:00, anozdrin@quad. +4 -0
Update global status variables when we're handling
COM_CHANGE_USER for a thread.
tests/mysql_client_test.c@stripped, 2008-02-06 15:13:54+03:00, anozdrin@quad. +103 -0
Add a test case for Bug#31222: com_% global status counters
behave randomly with mysql_change_user.
diff -Nrup a/sql/sql_class.cc b/sql/sql_class.cc
--- a/sql/sql_class.cc 2008-01-23 01:45:42 +03:00
+++ b/sql/sql_class.cc 2008-02-06 15:13:54 +03:00
@@ -769,6 +769,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();
killed= NOT_KILLED;
cleanup_done= 0;
diff -Nrup a/tests/mysql_client_test.c b/tests/mysql_client_test.c
--- a/tests/mysql_client_test.c 2008-01-11 04:04:30 +03:00
+++ b/tests/mysql_client_test.c 2008-02-06 15:13:54 +03:00
@@ -17232,6 +17232,108 @@ static void test_bug31669()
}
/*
+ Bug#31222: com_% global status counters behave randomly with
+ mysql_change_user.
+*/
+
+static void test_bug31222()
+{
+ MYSQL con;
+ MYSQL_RES *rs;
+ MYSQL_ROW row;
+
+ int i;
+ int com_select_1;
+ int com_select_2;
+
+ /***********************************************************************
+ Prepare: create a new connection, flush statistics.
+ ***********************************************************************/
+
+ DIE_UNLESS(mysql_init(&con));
+
+ DIE_UNLESS(mysql_real_connect(&con,
+ opt_host,
+ opt_user,
+ opt_password,
+ opt_db ? opt_db : "test",
+ opt_port,
+ opt_unix_socket,
+ CLIENT_FOUND_ROWS));
+
+ DIE_IF(mysql_query(&con, "FLUSH STATUS"));
+
+ /***********************************************************************
+ Do 100 SELECTs.
+ ***********************************************************************/
+
+ for (i= 0; i < 100; ++i)
+ {
+ DIE_IF(mysql_query(&con, "SELECT now()"));
+ DIE_UNLESS(rs= mysql_store_result(&con));
+
+ while (1)
+ {
+ MYSQL_ROW row= mysql_fetch_row(rs);
+
+ if (!row)
+ break;
+ }
+
+ mysql_free_result(rs);
+ }
+
+ /***********************************************************************
+ SHOW GLOBAL STATUS.
+ ***********************************************************************/
+
+ DIE_IF(mysql_query(&con, "SHOW GLOBAL STATUS LIKE 'com_select'"));
+ DIE_UNLESS(rs= mysql_store_result(&con));
+ DIE_UNLESS(row= mysql_fetch_row(rs));
+
+ DIE_UNLESS(row[1]);
+
+ com_select_1= atoi(row[1]);
+
+ mysql_free_result(rs);
+
+ /***********************************************************************
+ mysql_change_user().
+ ***********************************************************************/
+
+ DIE_IF(mysql_change_user(&con,
+ opt_user,
+ opt_password,
+ opt_db ? opt_db : "test"));
+
+ /***********************************************************************
+ SHOW GLOBAL STATUS.
+ ***********************************************************************/
+
+ DIE_IF(mysql_query(&con, "SHOW GLOBAL STATUS LIKE 'com_select'"));
+ DIE_UNLESS(rs= mysql_store_result(&con));
+ DIE_UNLESS(row= mysql_fetch_row(rs));
+
+ DIE_UNLESS(row[1]);
+
+ com_select_2= atoi(row[1]);
+
+ mysql_free_result(rs);
+
+ /***********************************************************************
+ Check.
+ ***********************************************************************/
+
+ DIE_UNLESS(com_select_1 == com_select_2);
+
+ /***********************************************************************
+ That's it. Cleanup.
+ ***********************************************************************/
+
+ mysql_close(&con);
+}
+
+/*
Read and parse arguments and MySQL options from my.cnf
*/
@@ -17535,6 +17637,7 @@ static struct my_tests_st my_tests[]= {
{ "test_bug20023", test_bug20023 },
{ "test_bug31418", test_bug31418 },
{ "test_bug31669", test_bug31669 },
+ { "test_bug31222", test_bug31222 },
{ 0, 0 }
};