Index: sql/sql_class.h =================================================================== --- sql/sql_class.h (revision 1) +++ sql/sql_class.h (working copy) @@ -1890,6 +1890,7 @@ */ CHANGED_TABLE_LIST* changed_tables; MEM_ROOT mem_root; // Transaction-life memory allocation pool + time_t start_time; // Start time of the transaction void cleanup() { DBUG_ENTER("thd::cleanup"); @@ -1912,6 +1913,7 @@ } st_transactions() { + start_time= 0; bzero((char*)this, sizeof(*this)); xid_state.xid.null(); init_sql_alloc(&mem_root, ALLOC_ROOT_MIN_BLOCK_SIZE, 0); Index: sql/sql_show.cc =================================================================== --- sql/sql_show.cc (revision 1) +++ sql/sql_show.cc (working copy) @@ -2110,6 +2110,7 @@ ulong thread_id; time_t start_time; + time_t trans_start_time; uint command; const char *user,*host,*db,*proc_info,*state_info; CSET_STRING query_string; @@ -2161,6 +2162,7 @@ field->maybe_null=1; field_list.push_back(new Item_empty_string("Command",16)); field_list.push_back(field= new Item_return_int("Time",7, MYSQL_TYPE_LONG)); + field_list.push_back(field= new Item_return_int("Trans_active",7, MYSQL_TYPE_LONG)); field->unsigned_flag= 0; field_list.push_back(field=new Item_empty_string("State",30)); field->maybe_null=1; @@ -2242,6 +2244,7 @@ else thd_info->progress= 0.0; thd_info->start_time= tmp->start_time; + thd_info->trans_start_time= tmp->transaction.start_time; mysql_mutex_unlock(&tmp->LOCK_thd_data); thread_infos.append(thd_info); } @@ -2269,6 +2272,12 @@ protocol->store_long ((longlong) (now - thd_info->start_time)); else protocol->store_null(); + + if (thd_info->trans_start_time) + protocol->store_long ((longlong) (now - thd_info->trans_start_time)); + else + protocol->store_long((longlong)0); + protocol->store(thd_info->state_info, system_charset_info); protocol->store(thd_info->query_string.str(), thd_info->query_string.charset()); Index: sql/handler.cc =================================================================== --- sql/handler.cc (revision 1) +++ sql/handler.cc (working copy) @@ -1039,6 +1039,9 @@ ha_info->register_ha(trans, ht_arg); + if (!thd->transaction.start_time && ha_info->is_started()) + thd->transaction.start_time= time(NULL); + trans->no_2pc|=(ht_arg->prepare==0); if (thd->transaction.xid_state.xid.is_null()) thd->transaction.xid_state.xid.set(thd->query_id); @@ -1426,6 +1429,7 @@ trans->no_2pc=0; if (all) { + thd->transaction.start_time= 0; #ifdef HAVE_QUERY_CACHE if (thd->transaction.changed_tables) query_cache.invalidate(thd, thd->transaction.changed_tables); @@ -1511,7 +1515,10 @@ if (is_real_trans) thd->transaction.cleanup(); if (all) + { + thd->transaction.start_time= 0; thd->transaction_rollback_request= FALSE; + } /* If a non-transactional table was updated, warn; don't warn if this is a