diff -ruN a/patch_info/userstats.patch b/patch_info/userstats.patch
--- a/patch_info/userstats.patch 1970-01-01 03:00:00.000000000 +0300
+++ b/patch_info/userstats.patch 2010-12-30 00:45:46.000000000 +0300
-@@ -0,0 +1,15 @@
+@@ -0,0 +1,17 @@
+File=userstats.patch
+Name=SHOW USER/TABLE/INDEX statistics
+Version=V2
+YK: fix behavior for prepared statements
+
+2008-11-26
-+YK: add switch variable "userstat_running" to control INFORMATION_SCHEMA.*_STATISTICS (default:OFF)
++YK: add switch variable "userstat" to control INFORMATION_SCHEMA.*_STATISTICS (default:OFF)
+2010-12-31
+Ported to 5.5.8
+2011-1-5
+Fix porting
++2011-02
++Rename variable USERSTAT_RUNNING => USERSTAT
diff -ruN a/sql/handler.cc b/sql/handler.cc
--- a/sql/handler.cc 2010-12-03 20:58:26.000000000 +0300
+++ b/sql/handler.cc 2010-12-30 00:59:23.000000000 +0300
+// Updates the global table stats with the TABLE this handler represents.
+void handler::update_global_table_stats()
+{
-+ if (!opt_userstat_running)
++ if (!opt_userstat)
+ {
+ rows_read= rows_changed= 0;
+ return;
+ if (!table->s || !table->s->table_cache_key.str || !table->s->table_name.str)
+ return;
+
-+ if (!opt_userstat_running)
++ if (!opt_userstat)
+ {
+ for (uint x= 0; x < table->s->keys; ++x)
+ {
/*
Log error with all enabled log event handlers
-@@ -5041,6 +5048,8 @@
+@@ -5042,6 +5049,8 @@
thd->first_successful_insert_id_in_prev_stmt_for_binlog);
if (e.write(file))
goto err;
}
if (thd->auto_inc_intervals_in_cur_stmt_for_binlog.nb_elements() > 0)
{
-@@ -5052,12 +5061,16 @@
+@@ -5053,12 +5062,16 @@
minimum());
if (e.write(file))
goto err;
}
if (thd->user_var_events.elements)
{
-@@ -5080,6 +5093,8 @@
+@@ -5081,6 +5094,8 @@
flags);
if (e.write(file))
goto err;
}
}
}
-@@ -5091,6 +5106,8 @@
+@@ -5092,6 +5107,8 @@
if (event_info->write(file) ||
DBUG_EVALUATE_IF("injecting_fault_writing", 1, 0))
goto err;
error= 0;
err:
-@@ -5276,7 +5293,8 @@
+@@ -5277,7 +5294,8 @@
be reset as a READ_CACHE to be able to read the contents from it.
*/
{
Mutex_sentry sentry(lock_log ? &LOCK_log : NULL);
-@@ -5323,6 +5341,7 @@
+@@ -5324,6 +5342,7 @@
/* write the first half of the split header */
if (my_b_write(&log_file, header, carry))
return ER_ERROR_ON_WRITE;
/*
copy fixed second half of header to cache so the correct
-@@ -5391,6 +5410,7 @@
+@@ -5392,6 +5411,7 @@
/* Write data to the binary log file */
if (my_b_write(&log_file, cache->read_pos, length))
return ER_ERROR_ON_WRITE;
cache->read_pos=cache->read_end; // Mark buffer used up
} while ((length= my_b_fill(cache)));
-@@ -5505,20 +5525,23 @@
+@@ -5506,20 +5526,23 @@
Query_log_event qinfo(thd, STRING_WITH_LEN("BEGIN"), TRUE, FALSE, TRUE, 0);
if (qinfo.write(&log_file))
goto err;
uint opt_debug_sync_timeout= 0;
#endif /* defined(ENABLED_DEBUG_SYNC) */
my_bool opt_old_style_user_limits= 0, trust_function_creators= 0;
-+my_bool opt_userstat_running= 0, opt_thread_statistics= 0;
++my_bool opt_userstat= 0, opt_thread_statistics= 0;
my_bool opt_optimizer_fix= 0;
/*
True if there is at least one per-hour limit for some user, so we should
extern ulonglong slave_type_conversions_options;
extern my_bool read_only, opt_readonly;
extern my_bool lower_case_file_system;
-+extern my_bool opt_userstat_running, opt_thread_statistics;
++extern my_bool opt_userstat, opt_thread_statistics;
extern my_bool opt_optimizer_fix;
extern my_bool opt_enable_named_pipe, opt_sync_frm, opt_allow_suspicious_udfs;
extern my_bool opt_secure_auth;
+// Updates 'diff' stats of a THD.
+void THD::update_stats(bool ran_command)
+{
-+ if (opt_userstat_running)
++ if (opt_userstat)
+ {
+ diff_total_busy_time+= busy_time;
+ diff_total_cpu_time+= cpu_time;
diff -ruN a/sql/sql_class.h b/sql/sql_class.h
--- a/sql/sql_class.h 2010-12-03 20:58:26.000000000 +0300
+++ b/sql/sql_class.h 2010-12-31 05:15:57.000000000 +0300
-@@ -1610,6 +1610,8 @@
+@@ -1617,6 +1617,8 @@
*/
enum enum_server_command command;
uint32 server_id;
uint32 file_id; // for LOAD DATA INFILE
/* remote (peer) port */
uint16 peer_port;
-@@ -2081,6 +2083,8 @@
+@@ -2088,6 +2090,8 @@
*/
enum_tx_isolation tx_isolation;
enum_check_fields count_cuted_fields;
DYNAMIC_ARRAY user_var_events; /* For user variables replication */
MEM_ROOT *user_var_events_alloc; /* Allocate above array elements here */
-@@ -2176,6 +2180,49 @@
+@@ -2183,6 +2187,49 @@
*/
LOG_INFO* current_linfo;
NET* slave_net; // network connection from slave -> m.
/* Used by the sys_var class to store temporary values */
union
{
-@@ -2256,6 +2303,11 @@
+@@ -2263,6 +2310,11 @@
alloc_root.
*/
void init_for_queries();
void change_user(void);
void cleanup(void);
void cleanup_after_query();
-@@ -2727,6 +2779,15 @@
+@@ -2734,6 +2786,15 @@
}
thd_scheduler scheduler;
public:
inline Internal_error_handler *get_internal_handler()
{ return m_internal_handler; }
-@@ -2914,6 +2975,10 @@
+@@ -2921,6 +2982,10 @@
LEX_STRING invoker_host;
};
+ const char* client_string= get_client_host(thd);
+ int return_value= 0;
+
-+ if (!opt_userstat_running)
++ if (!opt_userstat)
+ return return_value;
+
+ if (use_lock)
+// Updates the global stats of a user or client
+void update_global_user_stats(THD* thd, bool create_user, time_t now)
+{
-+ if (opt_userstat_running)
++ if (opt_userstat)
+ {
+ char* user_string= get_valid_user_string(thd->main_security_ctx.user);
+ const char* client_string= get_client_host(thd);
+ double start_cpu_nsecs= 0;
+ double end_cpu_nsecs= 0;
+
-+ if (opt_userstat_running)
++ if (opt_userstat)
+ {
+#ifdef HAVE_CLOCK_GETTIME
+ /* get start cputime */
DBUG_ASSERT(thd->change_list.is_empty());
}
-+ if (opt_userstat_running)
++ if (opt_userstat)
+ {
+ // Gets the end time.
+ if (!(end_time_error= gettimeofday(&end_time, NULL)))
+ double start_cpu_nsecs= 0;
+ double end_cpu_nsecs= 0;
+
-+ if (opt_userstat_running)
++ if (opt_userstat)
+ {
+#ifdef HAVE_CLOCK_GETTIME
+ /* get start cputime */
/* check_prepared_statemnt sends the metadata packet in case of success */
+end:
-+ if (opt_userstat_running)
++ if (opt_userstat)
+ {
+ // Gets the end time.
+ if (!(end_time_error= gettimeofday(&end_time, NULL)))
+ double start_cpu_nsecs= 0;
+ double end_cpu_nsecs= 0;
+
-+ if (opt_userstat_running)
++ if (opt_userstat)
+ {
+#ifdef HAVE_CLOCK_GETTIME
+ /* get start cputime */
DBUG_EXECUTE_IF("close_conn_after_stmt_execute", vio_close(thd->net.vio););
+end:
-+ if (opt_userstat_running)
++ if (opt_userstat)
+ {
+ // Gets the end time.
+ if (!(end_time_error= gettimeofday(&end_time, NULL)))
+ double start_cpu_nsecs= 0;
+ double end_cpu_nsecs= 0;
+
-+ if (opt_userstat_running)
++ if (opt_userstat)
+ {
+#ifdef HAVE_CLOCK_GETTIME
+ /* get start cputime */
thd->stmt_arena= thd;
+end:
-+ if (opt_userstat_running)
++ if (opt_userstat)
+ {
+ // Gets the end time.
+ if (!(end_time_error = gettimeofday(&end_time, NULL)))
+ double start_cpu_nsecs= 0;
+ double end_cpu_nsecs= 0;
+
-+ if (opt_userstat_running)
++ if (opt_userstat)
+ {
+#ifdef HAVE_CLOCK_GETTIME
+ /* get start cputime */
my_ok(thd);
+end:
-+ if (opt_userstat_running)
++ if (opt_userstat)
+ {
+ // Gets the end time.
+ if (!(end_time_error = gettimeofday(&end_time, NULL)))
NO_MUTEX_GUARD, NOT_IN_BINLOG,
ON_CHECK(check_read_only), ON_UPDATE(fix_read_only));
-+static Sys_var_mybool Sys_userstat_running(
-+ "userstat_running",
++static Sys_var_mybool Sys_userstat(
++ "userstat",
+ "Control USER_STATISTICS, CLIENT_STATISTICS, THREAD_STATISTICS, "
+ "INDEX_STATISTICS and TABLE_STATISTICS running",
-+ GLOBAL_VAR(opt_userstat_running), CMD_LINE(OPT_ARG), DEFAULT(FALSE));
++ GLOBAL_VAR(opt_userstat), CMD_LINE(OPT_ARG), DEFAULT(FALSE));
+
+static Sys_var_mybool Sys_thread_statistics(
+ "thread_statistics",
-+ "Control TABLE_STATISTICS running, when userstat_running is enabled",
++ "Control TABLE_STATISTICS running, when userstat is enabled",
+ GLOBAL_VAR(opt_thread_statistics), CMD_LINE(OPT_ARG), DEFAULT(FALSE));
+
// Small lower limit to be able to test MRR