SOURCES: mysql-userstats.patch - for 5.1

arekm arekm at pld-linux.org
Sun Dec 7 16:14:42 CET 2008


Author: arekm                        Date: Sun Dec  7 15:14:42 2008 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- for 5.1

---- Files affected:
SOURCES:
   mysql-userstats.patch (1.1 -> 1.2) 

---- Diffs:

================================================================
Index: SOURCES/mysql-userstats.patch
diff -u /dev/null SOURCES/mysql-userstats.patch:1.2
--- /dev/null	Sun Dec  7 16:14:43 2008
+++ SOURCES/mysql-userstats.patch	Sun Dec  7 16:14:36 2008
@@ -0,0 +1,1471 @@
+diff -r ab66c8ca382a include/mysql_com.h
+--- a/include/mysql_com.h	Thu Sep 04 12:08:00 2008 -0700
++++ b/include/mysql_com.h	Thu Sep 04 12:12:44 2008 -0700
+@@ -115,6 +115,8 @@
+ 					   thread */
+ #define REFRESH_MASTER          128     /* Remove all bin logs in the index
+ 					   and truncate the index */
++#define REFRESH_TABLE_STATS     256     /* Refresh table stats hash table */
++#define REFRESH_INDEX_STATS     512     /* Refresh index stats hash table */
+ 
+ /* The following can't be set with mysql_refresh() */
+ #define REFRESH_READ_LOCK	16384	/* Lock tables for read */
+diff -r ab66c8ca382a patch_info/userstats.info
+--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
++++ b/patch_info/userstats.info	Thu Sep 04 12:12:44 2008 -0700
+@@ -0,0 +1,6 @@
++File=userstats.patch
++Name=SHOW USER/TABLE/INDEX statistics
++Version=1.0
++Author=Google
++License=GPL
++Comment=Added INFORMATION_SCHEMA.*_STATISTICS
+diff -r ab66c8ca382a sql/handler.cc
+--- a/sql/handler.cc	Thu Sep 04 12:08:00 2008 -0700
++++ b/sql/handler.cc	Thu Sep 04 12:12:44 2008 -0700
+@@ -1168,6 +1168,7 @@
+         error=1;
+       }
+       status_var_increment(thd->status_var.ha_commit_count);
++      thd->diff_commit_trans++;
+       ha_info_next= ha_info->next();
+       ha_info->reset(); /* keep it conveniently zero-filled */
+     }
+@@ -1235,6 +1236,7 @@
+         error=1;
+       }
+       status_var_increment(thd->status_var.ha_rollback_count);
++      thd->diff_rollback_trans++;
+       ha_info_next= ha_info->next();
+       ha_info->reset(); /* keep it conveniently zero-filled */
+     }
+@@ -1682,6 +1684,7 @@
+       error=1;
+     }
+     status_var_increment(thd->status_var.ha_rollback_count);
++    thd->diff_rollback_trans++;
+     ha_info_next= ha_info->next();
+     ha_info->reset(); /* keep it conveniently zero-filled */
+   }
+@@ -2016,6 +2019,8 @@
+       dup_ref=ref+ALIGN_SIZE(ref_length);
+     cached_table_flags= table_flags();
+   }
++  rows_read = rows_changed = 0;
++  memset(index_rows_read, 0, sizeof(index_rows_read));
+   DBUG_RETURN(error);
+ }
+ 
+@@ -3448,6 +3453,97 @@
+   return;
+ }
+ 
++// Updates the global table stats with the TABLE this handler represents.
++void handler::update_global_table_stats() {
++  if (!rows_read && !rows_changed) return;  // Nothing to update.
++  // table_cache_key is db_name + '\0' + table_name + '\0'.
++  if (!table->s || !table->s->table_cache_key.str || !table->s->table_name.str) return;
++
++  TABLE_STATS* table_stats;
++  char key[NAME_LEN * 2 + 2];
++  // [db] + '.' + [table]
++  sprintf(key, "%s.%s", table->s->table_cache_key.str, table->s->table_name.str);
++
++  pthread_mutex_lock(&LOCK_global_table_stats);
++  // Gets the global table stats, creating one if necessary.
++  if (!(table_stats = (TABLE_STATS*)hash_search(&global_table_stats,
++                                                (uchar*)key,
++                                                strlen(key)))) {
++    if (!(table_stats = ((TABLE_STATS*)
++                         my_malloc(sizeof(TABLE_STATS), MYF(MY_WME))))) {
++      // Out of memory.
++      sql_print_error("Allocating table stats failed.");
++      goto end;
++    }
++    strncpy(table_stats->table, key, sizeof(table_stats->table));
++    table_stats->rows_read = 0;
++    table_stats->rows_changed = 0;
++    table_stats->rows_changed_x_indexes = 0;
++
++    if (my_hash_insert(&global_table_stats, (uchar*)table_stats)) {
++      // Out of memory.
++      sql_print_error("Inserting table stats failed.");
++      my_free((char*)table_stats, 0);
++      goto end;
++    }
++  }
++  // Updates the global table stats.
++  table_stats->rows_read += rows_read;
++  table_stats->rows_changed += rows_changed;
++  table_stats->rows_changed_x_indexes +=
++      rows_changed * (table->s->keys ? table->s->keys : 1);
++  rows_read = rows_changed = 0;
++end:
++  pthread_mutex_unlock(&LOCK_global_table_stats);
++}
++
++// Updates the global index stats with this handler's accumulated index reads.
++void handler::update_global_index_stats() {
++  // table_cache_key is db_name + '\0' + table_name + '\0'.
++  if (!table->s || !table->s->table_cache_key.str || !table->s->table_name.str) return;
++
++  for (int x = 0; x < table->s->keys; x++) {
++    if (index_rows_read[x]) {
++      // Rows were read using this index.
++      KEY* key_info = &table->key_info[x];
++
++      if (!key_info->name) continue;
++
++      INDEX_STATS* index_stats;
++      char key[NAME_LEN * 3 + 3];
++      // [db] + '.' + [table] + '.' + [index]
++      sprintf(key, "%s.%s.%s",  table->s->table_cache_key.str,
++              table->s->table_name.str, key_info->name);
++
++      pthread_mutex_lock(&LOCK_global_index_stats);
++      // Gets the global index stats, creating one if necessary.
++      if (!(index_stats = (INDEX_STATS*)hash_search(&global_index_stats,
++                                                    (uchar*)key,
++                                                    strlen(key)))) {
++        if (!(index_stats = ((INDEX_STATS*)
++                             my_malloc(sizeof(INDEX_STATS), MYF(MY_WME))))) {
++          // Out of memory.
++          sql_print_error("Allocating index stats failed.");
++          goto end;
++        }
++        strncpy(index_stats->index, key, sizeof(index_stats->index));
++        index_stats->rows_read = 0;
++
++        if (my_hash_insert(&global_index_stats, (uchar*)index_stats)) {
++          // Out of memory.
++          sql_print_error("Inserting index stats failed.");
++          my_free((char*)index_stats, 0);
++          goto end;
++        }
++      }
++      // Updates the global index stats.
++      index_stats->rows_read += index_rows_read[x];
++      index_rows_read[x] = 0;
++end:
++      pthread_mutex_unlock(&LOCK_global_index_stats);
++    }
++  }
++}
+ 
+ /****************************************************************************
+ ** Some general functions that isn't in the handler class
+diff -r ab66c8ca382a sql/handler.h
+--- a/sql/handler.h	Thu Sep 04 12:08:00 2008 -0700
++++ b/sql/handler.h	Thu Sep 04 12:12:44 2008 -0700
+@@ -29,6 +29,10 @@
+ #endif
+ 
+ #define USING_TRANSACTIONS
++
++#if MAX_KEY > 128
++#error MAX_KEY is too large.  Values up to 128 are supported.
++#endif
+ 
+ // the following is for checking tables
+ 
+@@ -690,6 +694,7 @@
+    */
+    enum log_status (*get_log_status)(handlerton *hton, char *log);
+ 
++
+    /*
+      Iterators creator.
+      Presence of the pointer should be checked before using
+@@ -1130,6 +1135,10 @@
+   */
+   Discrete_interval auto_inc_interval_for_cur_row;
+ 
++   ulonglong rows_read;
++   ulonglong rows_changed;
++   ulonglong index_rows_read[MAX_KEY];
++
+   handler(handlerton *ht_arg, TABLE_SHARE *share_arg)
+     :table_share(share_arg), table(0),
+     estimation_rows_to_insert(0), ht(ht_arg),
+@@ -1154,8 +1154,10 @@
+     ft_handler(0), inited(NONE),
+     locked(FALSE), implicit_emptied(0),
+     pushed_cond(0), next_insert_id(0), insert_id_for_cur_row(0),
+-    auto_inc_intervals_count(0)
+-    {}
++    auto_inc_intervals_count(0), rows_read(0), rows_changed(0)
++    {
++      memset(index_rows_read, 0, sizeof(index_rows_read));
++    }
+   virtual ~handler(void)
+   {
+     DBUG_ASSERT(locked == FALSE);
+@@ -1262,7 +1273,13 @@
+   {
+     table= table_arg;
+     table_share= share;
++    rows_read = rows_changed = 0;
++    memset(index_rows_read, 0, sizeof(index_rows_read));
+   }
++  
++  void update_global_table_stats();
++  void update_global_index_stats();
++
+   virtual double scan_time()
+   { return ulonglong2double(stats.data_file_length) / IO_SIZE + 2; }
+   virtual double read_time(uint index, uint ranges, ha_rows rows)
+diff -r ab66c8ca382a sql/lex.h
+--- a/sql/lex.h	Thu Sep 04 12:08:00 2008 -0700
++++ b/sql/lex.h	Thu Sep 04 12:12:44 2008 -0700
+@@ -245,6 +245,7 @@
+   { "IN",		SYM(IN_SYM)},
+   { "INDEX",		SYM(INDEX_SYM)},
+   { "INDEXES",		SYM(INDEXES)},
++  { "INDEX_STATISTICS",	SYM(INDEX_STATS_SYM)},
+   { "INFILE",		SYM(INFILE)},
+   { "INITIAL_SIZE",	SYM(INITIAL_SIZE_SYM)},
+   { "INNER",		SYM(INNER_SYM)},
+@@ -528,6 +529,7 @@
+   { "TABLES",		SYM(TABLES)},
+   { "TABLESPACE",	        SYM(TABLESPACE)},
+   { "TABLE_CHECKSUM",	SYM(TABLE_CHECKSUM_SYM)},
++  { "TABLE_STATISTICS",	SYM(TABLE_STATS_SYM)},
+   { "TEMPORARY",	SYM(TEMPORARY)},
+   { "TEMPTABLE",	SYM(TEMPTABLE_SYM)},
+   { "TERMINATED",	SYM(TERMINATED)},
+@@ -570,6 +572,7 @@
+   { "USE",		SYM(USE_SYM)},
+   { "USER",		SYM(USER)},
+   { "USER_RESOURCES",	SYM(RESOURCES)},
++  { "USER_STATISTICS",	SYM(USER_STATS_SYM)},
+   { "USE_FRM",		SYM(USE_FRM)},
+   { "USING",		SYM(USING)},
+   { "UTC_DATE",         SYM(UTC_DATE_SYM)},
+diff -r ab66c8ca382a sql/mysql_priv.h
+--- a/sql/mysql_priv.h	Thu Sep 04 12:08:00 2008 -0700
++++ b/sql/mysql_priv.h	Thu Sep 04 12:12:44 2008 -0700
+@@ -1058,7 +1058,19 @@
+ bool multi_delete_set_locks_and_link_aux_tables(LEX *lex);
+ void init_max_user_conn(void);
+ void init_update_queries(void);
++void init_global_user_stats(void);
++void init_global_table_stats(void);
++void init_global_index_stats(void);
+ void free_max_user_conn(void);
++void free_global_user_stats(void);
++void free_global_table_stats(void);
++void free_global_index_stats(void);
++// Uses the THD to update the global stats.
++void update_global_user_stats(THD* thd);
++// Set stats for concurrent connections displayed by mysqld_show().
++void set_concurrent_connections_stats();
++// Increments connection count for user.
++int increment_connection_count(THD* thd, bool use_lock);
+ pthread_handler_t handle_bootstrap(void *arg);
+ int mysql_execute_command(THD *thd);
+ bool do_command(THD *thd);
+@@ -2009,6 +2021,12 @@
+ extern struct system_variables max_system_variables;
+ extern struct system_status_var global_status_var;
+ extern struct rand_struct sql_rand;
++extern HASH global_user_stats;
++extern pthread_mutex_t LOCK_global_user_stats;
++extern HASH global_table_stats;
++extern pthread_mutex_t LOCK_global_table_stats;
++extern HASH global_index_stats;
++extern pthread_mutex_t LOCK_global_index_stats;
+ 
+ extern const char *opt_date_time_formats[];
+ extern KNOWN_DATE_TIME_FORMAT known_date_time_formats[];
+diff -r ab66c8ca382a sql/mysqld.cc
+--- a/sql/mysqld.cc	Thu Sep 04 12:08:00 2008 -0700
++++ b/sql/mysqld.cc	Thu Sep 04 12:12:44 2008 -0700
+@@ -588,6 +588,11 @@
+ 	        LOCK_global_system_variables,
+ 		LOCK_user_conn, LOCK_slave_list, LOCK_active_mi,
+                 LOCK_connection_count;
++
++pthread_mutex_t LOCK_global_user_stats;
++pthread_mutex_t LOCK_global_table_stats;
++pthread_mutex_t LOCK_global_index_stats;
++
+ /**
+   The below lock protects access to two global server variables:
+   max_prepared_stmt_count and prepared_stmt_count. These variables
+@@ -1265,6 +1270,9 @@
+   x_free(opt_secure_file_priv);
+   bitmap_free(&temp_pool);
+   free_max_user_conn();
++  free_global_user_stats();
++  free_global_table_stats();
++  free_global_index_stats();
+ #ifdef HAVE_REPLICATION
+   end_slave_list();
+ #endif
+@@ -1377,6 +1385,9 @@
+   (void) pthread_cond_destroy(&COND_thread_cache);
+   (void) pthread_cond_destroy(&COND_flush_thread_cache);
+   (void) pthread_cond_destroy(&COND_manager);
++  (void) pthread_mutex_destroy(&LOCK_global_user_stats);
++  (void) pthread_mutex_destroy(&LOCK_global_table_stats);
++  (void) pthread_mutex_destroy(&LOCK_global_index_stats);
+ }
+ 
+ #endif /*EMBEDDED_LIBRARY*/
+@@ -3069,6 +3080,7 @@
+   {"show_function_status", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_STATUS_FUNC]), SHOW_LONG_STATUS},
+   {"show_grants",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_GRANTS]), SHOW_LONG_STATUS},
+   {"show_keys",            (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_KEYS]), SHOW_LONG_STATUS},
++  {"show_index_stats",     (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_INDEX_STATS]), SHOW_LONG_STATUS},
+   {"show_master_status",   (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_MASTER_STAT]), SHOW_LONG_STATUS},
+   {"show_new_master",      (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_NEW_MASTER]), SHOW_LONG_STATUS},
+   {"show_open_tables",     (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_OPEN_TABLES]), SHOW_LONG_STATUS},
+@@ -3085,9 +3097,11 @@
+   {"show_slave_status",    (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_SLAVE_STAT]), SHOW_LONG_STATUS},
+   {"show_status",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_STATUS]), SHOW_LONG_STATUS},
+   {"show_storage_engines", (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_STORAGE_ENGINES]), SHOW_LONG_STATUS},
++  {"show_table_stats",     (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_TABLE_STATS]), SHOW_LONG_STATUS},
+   {"show_table_status",    (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_TABLE_STATUS]), SHOW_LONG_STATUS},
+   {"show_tables",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_TABLES]), SHOW_LONG_STATUS},
+   {"show_triggers",        (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_TRIGGERS]), SHOW_LONG_STATUS},
++  {"show_user_stats",      (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_USER_STATS]), SHOW_LONG_STATUS},
+   {"show_variables",       (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_VARIABLES]), SHOW_LONG_STATUS},
+   {"show_warnings",        (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SHOW_WARNS]), SHOW_LONG_STATUS},
+   {"slave_start",          (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_SLAVE_START]), SHOW_LONG_STATUS},
+@@ -3503,6 +3517,9 @@
+ #endif
+   (void) pthread_mutex_init(&LOCK_server_started, MY_MUTEX_INIT_FAST);
+   (void) pthread_cond_init(&COND_server_started,NULL);
++  (void) pthread_mutex_init(&LOCK_global_user_stats, MY_MUTEX_INIT_FAST);
++  (void) pthread_mutex_init(&LOCK_global_table_stats, MY_MUTEX_INIT_FAST);
++  (void) pthread_mutex_init(&LOCK_global_index_stats, MY_MUTEX_INIT_FAST);
+   sp_cache_init();
+ #ifdef HAVE_EVENT_SCHEDULER
+   Events::init_mutexes();
+@@ -3872,6 +3889,9 @@
+   if (!errmesg[0][0])
+     unireg_abort(1);
+ 
++   init_global_table_stats();
++   init_global_index_stats();
++
+   /* We have to initialize the storage engines before CSV logging */
+   if (ha_init())
+   {
+@@ -4018,6 +4038,7 @@
+ 
+   init_max_user_conn();
+   init_update_queries();
++  init_global_user_stats();
+   DBUG_RETURN(0);
+ }
+ 
+diff -r ab66c8ca382a sql/sql_base.cc
+--- a/sql/sql_base.cc	Thu Sep 04 12:08:00 2008 -0700
++++ b/sql/sql_base.cc	Thu Sep 04 12:12:44 2008 -0700
+@@ -1342,6 +1342,12 @@
+   DBUG_ASSERT(!table->file || table->file->inited == handler::NONE);
+   DBUG_PRINT("tcache", ("table: '%s'.'%s' 0x%lx", table->s->db.str,
+                         table->s->table_name.str, (long) table));
++
++  if(table->file)
++  {
++    table->file->update_global_table_stats();
++    table->file->update_global_index_stats();
++  }
+ 
+   *table_ptr=table->next;
+   /*
+@@ -1880,6 +1886,9 @@
+   DBUG_ENTER("close_temporary");
+   DBUG_PRINT("tmptable", ("closing table: '%s'.'%s'",
+                           table->s->db.str, table->s->table_name.str));
++ 
++  table->file->update_global_table_stats();
++  table->file->update_global_index_stats();
+ 
+   free_io_cache(table);
+   closefrm(table, 0);
+diff -r ab66c8ca382a sql/sql_class.cc
+--- a/sql/sql_class.cc	Thu Sep 04 12:08:00 2008 -0700
++++ b/sql/sql_class.cc	Thu Sep 04 12:12:44 2008 -0700
+@@ -577,6 +577,8 @@
+   bzero(ha_data, sizeof(ha_data));
+   mysys_var=0;
+   binlog_evt_union.do_union= FALSE;
++  busy_time = 0;
++  updated_row_count = 0;
+   enable_slow_log= 0;
+ #ifndef DBUG_OFF
+   dbug_sentry=THD_SENTRY_MAGIC;
+@@ -761,8 +763,55 @@
+   update_charset();
+   reset_current_stmt_binlog_row_based();
+   bzero((char *) &status_var, sizeof(status_var));
++  reset_stats();
+ }
+ 
++// Resets stats in a THD.
++void THD::reset_stats(void) {
++  current_connect_time = time(NULL);
++  last_global_update_time = current_connect_time;
++  reset_diff_stats();
++}
++
++// Resets the 'diff' stats, which are used to update global stats.
++void THD::reset_diff_stats(void) {
++  diff_total_busy_time = 0;
++  diff_total_sent_rows = 0;
++  diff_total_updated_rows = 0;
++  diff_select_commands = 0;
++  diff_update_commands = 0;
++  diff_other_commands = 0;
++  diff_commit_trans = 0;
++  diff_rollback_trans = 0;
++}
++
++// Updates 'diff' stats of a THD.
++void THD::update_stats() {
++  diff_total_busy_time += busy_time;
++  diff_total_sent_rows += sent_row_count;
++  diff_total_updated_rows += updated_row_count;
++  // The replication thread has the COM_CONNECT command.
++  if ((old_command == COM_QUERY || command == COM_CONNECT) &&
++      (lex->sql_command >= 0 && lex->sql_command < SQLCOM_END)) {
++    // A SQL query.
++    if (lex->sql_command == SQLCOM_SELECT) {
++      if (!(sql_command_flags[lex->sql_command] & CF_STATUS_COMMAND)) {
++        diff_select_commands++;
++      } else {
++        // 'SHOW ' commands become SQLCOM_SELECT.
++        diff_other_commands++;
++        // 'SHOW ' commands shouldn't inflate total sent row count.
++        diff_total_sent_rows -= sent_row_count;
++      }
++    } else if (is_update_query(lex->sql_command)) {
++      diff_update_commands++;
++    } else {
++      diff_other_commands++;
++    }
++  }
++  // diff_commit_trans is updated in handler.cc.
++  // diff_rollback_trans is updated in handler.cc.
++}
+ 
+ /*
+   Init THD for query processing.
+diff -r ab66c8ca382a sql/sql_class.h
+--- a/sql/sql_class.h	Thu Sep 04 12:08:00 2008 -0700
++++ b/sql/sql_class.h	Thu Sep 04 12:12:44 2008 -0700
+@@ -1310,6 +1310,8 @@
+     first byte of the packet in do_command()
+   */
+   enum enum_server_command command;
++  // Used to save the command, before it is set to COM_SLEEP.
++  enum enum_server_command old_command;
+   uint32     server_id;
+   uint32     file_id;			// for LOAD DATA INFILE
+   /* remote (peer) port */
+@@ -1584,6 +1586,7 @@
+   ulonglong  options;           /* Bitmap of states */
+   longlong   row_count_func;    /* For the ROW_COUNT() function */
+   ha_rows    cuted_fields;
++  ha_rows    updated_row_count;
+ 
+   /*
+     number of rows we actually sent to the client, including "synthetic"
+@@ -1735,6 +1738,27 @@
+   */
+   LOG_INFO*  current_linfo;
+   NET*       slave_net;			// network connection from slave -> m.
++
++  /*
++    Used to update global user stats.  The global user stats are updated
++    occasionally with the 'diff' variables.  After the update, the 'diff'
++    variables are reset to 0.
++   */
++  // Time when the current thread connected to MySQL.
++  time_t current_connect_time;
++  // Last time when THD stats were updated in global_user_stats.
++  time_t last_global_update_time;
++  // Busy (non-idle) time for just one command.
++  double busy_time;
++  // Busy time not updated in global_user_stats yet.
++  double diff_total_busy_time;
++  // Number of rows not reflected in global_user_stats yet.
++  ha_rows diff_total_sent_rows, diff_total_updated_rows;
++  // Number of commands not reflected in global_user_stats yet.
++  ulonglong diff_select_commands, diff_update_commands, diff_other_commands;
++  // Number of transactions not reflected in global_user_stats yet.
++  ulonglong diff_commit_trans, diff_rollback_trans;
++
+   /* Used by the sys_var class to store temporary values */
+   union
+   {
+@@ -1797,6 +1821,9 @@
+     alloc_root. 
+   */
+   void init_for_queries();
++  void reset_stats(void);
++  void reset_diff_stats(void);
++  void update_stats(void);
+   void change_user(void);
+   void cleanup(void);
+   void cleanup_after_query();
+diff -r ab66c8ca382a sql/sql_connect.cc
+--- a/sql/sql_connect.cc	Thu Sep 04 12:08:00 2008 -0700
++++ b/sql/sql_connect.cc	Thu Sep 04 12:12:44 2008 -0700
+@@ -520,6 +520,14 @@
+ 		   0,0,
+ 		   (hash_get_key) get_key_conn, (hash_free_key) free_user,
+ 		   0);
++  if (hash_init(&hash_user_connections,system_charset_info,max_connections,
++                0,0,
++                (hash_get_key) get_key_conn, (hash_free_key) free_user,
++                0)) {
++    sql_print_error("Initializing hash_user_connections failed.");
++    exit(1);
++  }
++
+ #endif
+ }
+ 
+@@ -1107,6 +1115,13 @@
+     if (login_connection(thd))
+       goto end_thread;
+ 
++    thd->reset_stats();
++    // Updates global user connection stats.
++    if (increment_connection_count(thd, true)) {
++      net_send_error(thd, ER_OUTOFMEMORY);  // Out of memory
++      goto end_thread;
++    }
++
+     prepare_new_connection_state(thd);
+ 
+     while (!net->error && net->vio != 0 &&
+@@ -1119,6 +1134,8 @@
+    
+ end_thread:
+     close_connection(thd, 0, 1);
++    thd->update_stats();
++    update_global_user_stats(thd);
+     if (thread_scheduler.end_thread(thd,1))
+       return 0;                                 // Probably no-threads
+ 
+diff -r ab66c8ca382a sql/sql_delete.cc
+--- a/sql/sql_delete.cc	Thu Sep 04 12:08:00 2008 -0700
++++ b/sql/sql_delete.cc	Thu Sep 04 12:12:44 2008 -0700
+@@ -402,6 +402,7 @@
+     my_ok(thd, (ha_rows) thd->row_count_func);
+     DBUG_PRINT("info",("%ld records deleted",(long) deleted));
+   }
++  thd->updated_row_count += deleted;
+   DBUG_RETURN(error >= 0 || thd->is_error());
+ }
+ 
+@@ -938,6 +939,7 @@
+     thd->row_count_func= deleted;
+     ::my_ok(thd, (ha_rows) thd->row_count_func);
+   }
++  thd->updated_row_count += deleted;
+   return 0;
+ }
+ 
+diff -r ab66c8ca382a sql/sql_insert.cc
+--- a/sql/sql_insert.cc	Thu Sep 04 12:08:00 2008 -0700
++++ b/sql/sql_insert.cc	Thu Sep 04 12:12:44 2008 -0700
+@@ -969,6 +969,7 @@
+     thd->row_count_func= info.copied + info.deleted + updated;
+     ::my_ok(thd, (ulong) thd->row_count_func, id, buff);
+   }
++  thd->updated_row_count += thd->row_count_func;
+   thd->abort_on_warning= 0;
+   DBUG_RETURN(FALSE);
+ 
+diff -r ab66c8ca382a sql/sql_lex.h
+--- a/sql/sql_lex.h	Thu Sep 04 12:08:00 2008 -0700
++++ b/sql/sql_lex.h	Thu Sep 04 12:12:44 2008 -0700
+@@ -118,7 +118,7 @@
+   SQLCOM_SHOW_CREATE_TRIGGER,
+   SQLCOM_ALTER_DB_UPGRADE,
<<Diff was trimmed, longer than 597 lines>>

---- CVS-web:
    http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/SOURCES/mysql-userstats.patch?r1=1.1&r2=1.2&f=u



More information about the pld-cvs-commit mailing list