From: Tor Didriksen Date: October 17 2012 2:57pm Subject: bzr push into mysql-5.6 branch (tor.didriksen:4496 to 4497) Bug#14771006 List-Archive: http://lists.mysql.com/commits/145065 X-Bug: 14771006 Message-Id: <20121017145754.21043.36619.4497@atum07.no.oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 4497 Tor Didriksen 2012-10-17 Bug#14771006 SHOW PROCESSLIST SORT ORDER CHANGED IN 5.6 'SHOW PROCESSLIST' has traditionally returned the result ordered by thread_id, so do the same now, even if the THD-list is a std::set. Solution: Convert thread_infos from intrusive list, to array of pointers, and std::sort it. modified: sql/global_threads.h sql/sql_show.cc 4496 Sneha Modi 2012-10-17 Modifying the tests to use the --big-test option. modified: mysql-test/suite/innodb/t/innodb-wl5522.test mysql-test/suite/innodb/t/innodb_bug14704286.test mysql-test/suite/innodb/t/innodb_mysql.test mysql-test/suite/rpl/t/rpl_check_gtid.test mysql-test/suite/rpl/t/rpl_gtid_lost_maintained.test mysql-test/suite/rpl/t/rpl_semi_sync.test mysql-test/t/multi_update2.test === modified file 'sql/global_threads.h' --- a/sql/global_threads.h 2012-04-13 12:00:39 +0000 +++ b/sql/global_threads.h 2012-10-17 14:49:44 +0000 @@ -25,9 +25,10 @@ class THD; extern mysql_mutex_t LOCK_thread_count; extern mysql_cond_t COND_thread_count; -/* +/** We maintail a set of all registered threads. We provide acccessors to iterate over all threads. + There is no guarantee on the order of THDs when iterating. We also provide mutators for inserting, and removing an element: add_global_thread() inserts a THD into the set, and increments the counter. === modified file 'sql/sql_show.cc' --- a/sql/sql_show.cc 2012-10-08 14:19:40 +0000 +++ b/sql/sql_show.cc 2012-10-17 14:49:44 +0000 @@ -1973,7 +1973,8 @@ view_store_create_info(THD *thd, TABLE_L returns for each thread: thread id, user, host, db, command, info ****************************************************************************/ -class thread_info :public ilink { +class thread_info +{ public: static void *operator new(size_t size) { @@ -1990,6 +1991,17 @@ public: CSET_STRING query_string; }; +// For sorting by thread_id. +class thread_info_compare : + public std::binary_function +{ +public: + bool operator() (const thread_info* p1, const thread_info* p2) + { + return p1->thread_id < p2->thread_id; + } +}; + static const char *thread_state_info(THD *tmp) { #ifndef EMBEDDED_LIBRARY @@ -2018,7 +2030,7 @@ void mysqld_list_processes(THD *thd,cons { Item *field; List field_list; - I_List thread_infos; + Mem_root_array thread_infos(thd->mem_root); ulong max_query_length= (verbose ? thd->variables.max_allowed_packet : PROCESS_LIST_WIDTH); Protocol *protocol= thd->protocol; @@ -2043,6 +2055,7 @@ void mysqld_list_processes(THD *thd,cons if (!thd->killed) { mysql_mutex_lock(&LOCK_thread_count); + thread_infos.reserve(get_thread_count()); Thread_iterator it= global_thread_list_begin(); Thread_iterator end= global_thread_list_end(); for (; it != end; ++it) @@ -2092,16 +2105,19 @@ void mysqld_list_processes(THD *thd,cons } mysql_mutex_unlock(&tmp->LOCK_thd_data); thd_info->start_time= tmp->start_time.tv_sec; - thread_infos.push_front(thd_info); + thread_infos.push_back(thd_info); } } mysql_mutex_unlock(&LOCK_thread_count); } - thread_info *thd_info; + // Return list sorted by thread_id. + std::sort(thread_infos.begin(), thread_infos.end(), thread_info_compare()); + time_t now= my_time(0); - while ((thd_info=thread_infos.get())) + for (size_t ix= 0; ix < thread_infos.size(); ++ix) { + thread_info *thd_info= thread_infos.at(ix); protocol->prepare_for_resend(); protocol->store((ulonglong) thd_info->thread_id); protocol->store(thd_info->user, system_charset_info); No bundle (reason: useless for push emails).