List:Commits« Previous MessageNext Message »
From:marc.alff Date:February 22 2007 11:13pm
Subject:bk commit into 5.0 tree (malff:1.2419) BUG#21554
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of marcsql. When marcsql 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, 2007-02-22 16:13:45-07:00, malff@weblab.(none) +18 -0
  Bug#21554 (sp_cache.cc: violates C++ aliasing rules)
  
  This is a compile bug, reported by the development GCC team with GCC 4.2
  
  The issue is that on linux platforms, for which HAVE_ATOMIC_ADD is defined,
  casting a pointer from an 'unsigned long*' to 'atomic_t*' violates
  assumptions made by GCC when optimizing code, which are that pointers to
  different types do not point to the same memory.
  In case of atomic_t, which is found in linux platforms under the following
  header files (for example, these are the headers on my machine):
  - /usr/include/asm-i386/atomic.h
  - /usr/include/asm-x86_64/atomic.h
  the comments around the definition of atomic_t are very specific:
  "
   atomic_t should be 32 bit signed type
  [...]
   Make sure gcc doesn't try to be clever and move things around
   on us. We need to use _exactly_ the address the user gave us,
   not some alias that contains the same information.
  "
   typedef struct { volatile int counter; } atomic_t;
  
  In MySQL, usage of atomic_t derives from the macro thread_safe_increment.
  
  For sp_cache.cc in MySQL, the code performs the following cast when using
  the variable Cversion:
  - static ulong volatile CVersion --> atomic_t
  
  There are also other issues with using atomic_t from the linux kernel headers
  directly in user code:
  - user code (MySQL) should not include <asm/atomic.h>
  - the code depends on a i386 on CONFIG_SMP,
  which creates the possibility of build issues when a build machine and a
  production machine have mismatched CONFIG_SMP configurations.
  
  There are several issues related to thread_safe_increment that existed before
  this fix:
  
  1)
  The same locking mechanism should always be used when
  guarding a given data, mixing mutexes and atomic functions is not safe.
  
  In particular, the following counters were not consistently protected:
  - sql/ha_berkeley.cc, share->rows is not safe (should be protected by
  share->mutex)
  - mysys/my_fopen.c, my_stream_opened (THR_LOCK_open)
  - mysys/my_open.c, my_file_opened (THR_LOCK_open)
  
  Using sometime the mutex listed and sometime thread_safe_increment
  would actually cause the counter to not be safe on linux.
  
  2)
  Some counters, which are really statistical in nature, would use
  thread_safe_increment instead of statistic_increment,
  making the production builds (SAFE_STATISTICS not defined) slower.
  
  In particular, the following counters :
  - mysys/mf_tempfile.c, my_tmp_file_created
  - sql/sql_insert.c, delayed_rows_in_use
  - sql/sql_insert.c, delayed_insert_writes
  - sql/sql_insert.c, delayed_insert_errors
  would always use a lock.
  
  3)
  Every counter involving thd->status_var, was using locks (in SAFE_STATISTICS
  builds), even when not necessary, since the counter is owned by the running
  thread.
  
  With this fix, usage of thread_safe_increment has been revised.
  
  1) has been fixed by always use explicitly the mutex, and avoid relying
  on thread_safe_increment.
  
  2) has been fixed by replacing some calls to thread_safe_increment
  by calls to statistic_increment,
  
  3) has been fixed by using status_var_increment instead of
     statistic_increment.
  
  After fixing these 3 existing issues, re-evaluating the real usage pattern
  of atomic_t shows that, in a production build (SAFE_STATISTICS not defined),
  there is only one counter in the code that still uses atomic_t api,
  namely Cversion in sql/sp_cache.cc.
  
  Because of the build problem introduced with CONFIG_SMP, the
  thread_safe_increment api has been changed to not rely on atomic_t at all.
  Once atomic apis that are safe to use in user code are available, and safe
  to use without special build considerations (CONFIG_SMP), using atomic helpers
  can be implemented again, so this change is temporary only.
  
  Considering that the cleanup implemented actually avoid locking counters
  when it's not necessary, this change should actually improve performances,
  both in SAFE_STATISTIC builds (lots of locks are not needed) and non
  SAFE_STATISTICS builds (locking of insert delayed related counters and
  my_tmp_file_created not needed).
  
  No automated tests are provided, due to the nature of the problem.

  include/my_pthread.h@stripped, 2007-02-22 16:09:15-07:00, malff@weblab.(none) +27 -8
    General cleanup of thread_safe_increment / statistic_increment

  mysys/mf_tempfile.c@stripped, 2007-02-22 16:09:15-07:00, malff@weblab.(none) +1 -1
    General cleanup of thread_safe_increment / statistic_increment

  mysys/my_fopen.c@stripped, 2007-02-22 16:09:15-07:00, malff@weblab.(none) +3 -1
    General cleanup of thread_safe_increment / statistic_increment
    my_stream_opened should be guarded by THD_LOCK_open only

  mysys/my_open.c@stripped, 2007-02-22 16:09:15-07:00, malff@weblab.(none) +3 -1
    General cleanup of thread_safe_increment / statistic_increment
    my_file_open should be guarded by THD_LOCK_open only

  sql/filesort.cc@stripped, 2007-02-22 16:09:15-07:00, malff@weblab.(none) +3 -4
    General cleanup of thread_safe_increment / statistic_increment

  sql/ha_archive.cc@stripped, 2007-02-22 16:09:15-07:00, malff@weblab.(none) +3 -5
    General cleanup of thread_safe_increment / statistic_increment

  sql/ha_berkeley.cc@stripped, 2007-02-22 16:09:15-07:00, malff@weblab.(none) +14 -20
    General cleanup of thread_safe_increment / statistic_increment
    share->rows should be guarded by share->mutex only

  sql/ha_federated.cc@stripped, 2007-02-22 16:09:15-07:00, malff@weblab.(none) +4 -7
    General cleanup of thread_safe_increment / statistic_increment

  sql/ha_heap.cc@stripped, 2007-02-22 16:09:15-07:00, malff@weblab.(none) +12 -21
    General cleanup of thread_safe_increment / statistic_increment

  sql/ha_innodb.cc@stripped, 2007-02-22 16:09:15-07:00, malff@weblab.(none) +10 -20
    General cleanup of thread_safe_increment / statistic_increment

  sql/ha_myisam.cc@stripped, 2007-02-22 16:09:16-07:00, malff@weblab.(none) +14 -25
    General cleanup of thread_safe_increment / statistic_increment

  sql/ha_myisammrg.cc@stripped, 2007-02-22 16:09:16-07:00, malff@weblab.(none) +13 -23
    General cleanup of thread_safe_increment / statistic_increment

  sql/ha_ndbcluster.cc@stripped, 2007-02-22 16:09:16-07:00, malff@weblab.(none) +12 -17
    General cleanup of thread_safe_increment / statistic_increment

  sql/handler.cc@stripped, 2007-02-22 16:09:16-07:00, malff@weblab.(none) +9 -9
    General cleanup of thread_safe_increment / statistic_increment

  sql/sql_insert.cc@stripped, 2007-02-22 16:09:16-07:00, malff@weblab.(none) +6 -6
    General cleanup of thread_safe_increment / statistic_increment

  sql/sql_parse.cc@stripped, 2007-02-22 16:09:16-07:00, malff@weblab.(none) +17 -27
    General cleanup of thread_safe_increment / statistic_increment

  sql/sql_prepare.cc@stripped, 2007-02-22 16:09:16-07:00, malff@weblab.(none) +6 -6
    General cleanup of thread_safe_increment / statistic_increment

  sql/sql_select.cc@stripped, 2007-02-22 16:09:16-07:00, malff@weblab.(none) +7 -13
    General cleanup of thread_safe_increment / statistic_increment

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	malff
# Host:	weblab.(none)
# Root:	/home/marcsql/TREE/mysql-5.0-21554_b

--- 1.98/include/my_pthread.h	2007-02-22 16:13:51 -07:00
+++ 1.99/include/my_pthread.h	2007-02-22 16:13:51 -07:00
@@ -772,15 +772,16 @@ extern uint my_thread_end_wait_time;
 
 extern uint thd_lib_detected;
 
-	/* statistics_xxx functions are for not essential statistic */
+/*
+  thread_safe_xxx functions are for critical statistic or counters.
+  The implementation is guaranteed to be thread safe, on all platforms.
+  Note that the calling code should *not* assume the counter is protected
+  by the mutex given, as the implementation of these helpers may change
+  to use atomic operations instead, depending of the availability, -- for
+  code in user space --, of such operations for the platform.
+*/
 
 #ifndef thread_safe_increment
-#ifdef HAVE_ATOMIC_ADD
-#define thread_safe_increment(V,L) atomic_inc((atomic_t*) &V)
-#define thread_safe_decrement(V,L) atomic_dec((atomic_t*) &V)
-#define thread_safe_add(V,C,L)     atomic_add((C),(atomic_t*) &V)
-#define thread_safe_sub(V,C,L)     atomic_sub((C),(atomic_t*) &V)
-#else
 #define thread_safe_increment(V,L) \
         (pthread_mutex_lock((L)), (V)++, pthread_mutex_unlock((L)))
 #define thread_safe_decrement(V,L) \
@@ -788,7 +789,18 @@ extern uint thd_lib_detected;
 #define thread_safe_add(V,C,L) (pthread_mutex_lock((L)), (V)+=(C), pthread_mutex_unlock((L)))
 #define thread_safe_sub(V,C,L) \
         (pthread_mutex_lock((L)), (V)-=(C), pthread_mutex_unlock((L)))
-#endif /* HAVE_ATOMIC_ADD */
+
+/*
+  statistics_xxx functions are for non critical statistic,
+  maintained in global variables.
+  When compiling with SAFE_STATISTICS:
+  - race conditions can not occur.
+  - some locking occurs, which may cause performance degradation.
+
+  When compiling without SAFE_STATISTICS:
+  - race conditions can occur, making the result slightly inaccurate.
+  - the lock given is not honored.
+*/
 #ifdef SAFE_STATISTICS
 #define statistic_increment(V,L)   thread_safe_increment((V),(L))
 #define statistic_decrement(V,L)   thread_safe_decrement((V),(L))
@@ -798,6 +810,13 @@ extern uint thd_lib_detected;
 #define statistic_increment(V,L) (V)++
 #define statistic_add(V,C,L)     (V)+=(C)
 #endif /* SAFE_STATISTICS */
+
+/*
+  No locking needed, the counter is owned by the thread
+*/
+#define status_var_increment(V) (V)++
+#define status_var_decrement(V) (V)--
+
 #endif /* thread_safe_increment */
 
 #ifdef  __cplusplus

--- 1.17/mysys/my_fopen.c	2007-02-22 16:13:51 -07:00
+++ 1.18/mysys/my_fopen.c	2007-02-22 16:13:51 -07:00
@@ -68,7 +68,9 @@ FILE *my_fopen(const char *filename, int
     */
     if ((uint) fileno(fd) >= my_file_limit)
     {
-      thread_safe_increment(my_stream_opened,&THR_LOCK_open);
+      pthread_mutex_lock(&THR_LOCK_open);
+      my_stream_opened++;
+      pthread_mutex_unlock(&THR_LOCK_open);
       DBUG_RETURN(fd);				/* safeguard */
     }
     pthread_mutex_lock(&THR_LOCK_open);

--- 1.27/mysys/my_open.c	2007-02-22 16:13:51 -07:00
+++ 1.28/mysys/my_open.c	2007-02-22 16:13:51 -07:00
@@ -145,7 +145,9 @@ File my_register_filename(File fd, const
 		 FileName, my_errno);
       return(-1);
 #endif
-      thread_safe_increment(my_file_opened,&THR_LOCK_open);
+      pthread_mutex_lock(&THR_LOCK_open);
+      my_file_opened++ ;
+      pthread_mutex_unlock(&THR_LOCK_open);
       return(fd);				/* safeguard */
     }
     pthread_mutex_lock(&THR_LOCK_open);

--- 1.113/sql/filesort.cc	2007-02-22 16:13:51 -07:00
+++ 1.114/sql/filesort.cc	2007-02-22 16:13:51 -07:00
@@ -165,11 +165,11 @@ ha_rows filesort(THD *thd, TABLE *table,
 
   if (select && select->quick)
   {
-    statistic_increment(thd->status_var.filesort_range_count, &LOCK_status);
+    status_var_increment(thd->status_var.filesort_range_count);
   }
   else
   {
-    statistic_increment(thd->status_var.filesort_scan_count, &LOCK_status);
+    status_var_increment(thd->status_var.filesort_scan_count);
   }
 #ifdef CAN_TRUST_RANGE
   if (select && select->quick && select->quick->records > 0L)
@@ -1042,8 +1042,7 @@ int merge_buffers(SORTPARAM *param, IO_C
   THD::killed_state not_killable;
   DBUG_ENTER("merge_buffers");
 
-  statistic_increment(current_thd->status_var.filesort_merge_passes,
-		      &LOCK_status);
+  status_var_increment(current_thd->status_var.filesort_merge_passes);
   if (param->not_killable)
   {
     killed= &not_killable;

--- 1.165/sql/ha_berkeley.cc	2007-02-22 16:13:51 -07:00
+++ 1.166/sql/ha_berkeley.cc	2007-02-22 16:13:51 -07:00
@@ -948,7 +948,7 @@ int ha_berkeley::write_row(byte * record
   int error;
   DBUG_ENTER("write_row");
 
-  statistic_increment(table->in_use->status_var.ha_write_count, &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_write_count);
   if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
     table->timestamp_field->set_time();
   if (table->next_number_field && record == table->record[0])
@@ -1181,7 +1181,7 @@ int ha_berkeley::update_row(const byte *
   DBUG_ENTER("update_row");
   LINT_INIT(error);
 
-  statistic_increment(table->in_use->status_var.ha_update_count,&LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_update_count);
   if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
     table->timestamp_field->set_time();
 
@@ -1350,7 +1350,7 @@ int ha_berkeley::delete_row(const byte *
   DBT row, prim_key;
   key_map keys= table->s->keys_in_use;
   DBUG_ENTER("delete_row");
-  statistic_increment(table->in_use->status_var.ha_delete_count,&LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_delete_count);
 
   if ((error=pack_row(&row, record, 0)))
     DBUG_RETURN((error)); /* purecov: inspected */
@@ -1565,8 +1565,7 @@ int ha_berkeley::index_read_last(byte * 
   KEY *key_info= &table->key_info[active_index];
   DBUG_ENTER("ha_berkeley::index_read");
 
-  statistic_increment(table->in_use->status_var.ha_read_key_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_key_count);
   bzero((char*) &row,sizeof(row));
 
   /* read of partial key */
@@ -1590,8 +1589,7 @@ int ha_berkeley::index_next(byte * buf)
 {
   DBT row;
   DBUG_ENTER("index_next");
-  statistic_increment(table->in_use->status_var.ha_read_next_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_next_count);
   bzero((char*) &row,sizeof(row));
   DBUG_RETURN(read_row(cursor->c_get(cursor, &last_key, &row, DB_NEXT),
 		       (char*) buf, active_index, &row, &last_key, 1));
@@ -1602,8 +1600,7 @@ int ha_berkeley::index_next_same(byte * 
   DBT row;
   int error;
   DBUG_ENTER("index_next_same");
-  statistic_increment(table->in_use->status_var.ha_read_next_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_next_count);
   bzero((char*) &row,sizeof(row));
   if (keylen == table->key_info[active_index].key_length &&
       !(table->key_info[active_index].flags & HA_END_SPACE_KEY))
@@ -1624,8 +1621,7 @@ int ha_berkeley::index_prev(byte * buf)
 {
   DBT row;
   DBUG_ENTER("index_prev");
-  statistic_increment(table->in_use->status_var.ha_read_prev_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_prev_count);
   bzero((char*) &row,sizeof(row));
   DBUG_RETURN(read_row(cursor->c_get(cursor, &last_key, &row, DB_PREV),
 		       (char*) buf, active_index, &row, &last_key, 1));
@@ -1636,8 +1632,7 @@ int ha_berkeley::index_first(byte * buf)
 {
   DBT row;
   DBUG_ENTER("index_first");
-  statistic_increment(table->in_use->status_var.ha_read_first_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_first_count);
   bzero((char*) &row,sizeof(row));
   DBUG_RETURN(read_row(cursor->c_get(cursor, &last_key, &row, DB_FIRST),
 		       (char*) buf, active_index, &row, &last_key, 1));
@@ -1647,8 +1642,7 @@ int ha_berkeley::index_last(byte * buf)
 {
   DBT row;
   DBUG_ENTER("index_last");
-  statistic_increment(table->in_use->status_var.ha_read_last_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_last_count);
   bzero((char*) &row,sizeof(row));
   DBUG_RETURN(read_row(cursor->c_get(cursor, &last_key, &row, DB_LAST),
 		       (char*) buf, active_index, &row, &last_key, 0));
@@ -1670,8 +1664,7 @@ int ha_berkeley::rnd_next(byte *buf)
 {
   DBT row;
   DBUG_ENTER("rnd_next");
-  statistic_increment(table->in_use->status_var.ha_read_rnd_next_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_rnd_next_count);
   bzero((char*) &row,sizeof(row));
   DBUG_RETURN(read_row(cursor->c_get(cursor, &last_key, &row, DB_NEXT),
 		       (char*) buf, primary_key, &row, &last_key, 1));
@@ -1705,8 +1698,7 @@ int ha_berkeley::rnd_pos(byte * buf, byt
   DBT db_pos;
   
   DBUG_ENTER("ha_berkeley::rnd_pos");
-  statistic_increment(table->in_use->status_var.ha_read_rnd_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_rnd_count);
   active_index= MAX_KEY;
   DBUG_RETURN(read_row(file->get(file, transaction,
 				 get_pos(&db_pos, pos),
@@ -1880,7 +1872,9 @@ int ha_berkeley::external_lock(THD *thd,
   else
   {
     lock.type=TL_UNLOCK;			// Unlocked
-    thread_safe_add(share->rows, changed_rows, &share->mutex);
+    pthread_mutex_lock(&share->mutex);
+    share->rows+= changed_rows;
+    pthread_mutex_unlock(&share->mutex);
     changed_rows=0;
     if (!--trx->bdb_lock_count)
     {

--- 1.82/sql/ha_heap.cc	2007-02-22 16:13:51 -07:00
+++ 1.83/sql/ha_heap.cc	2007-02-22 16:13:51 -07:00
@@ -171,7 +171,7 @@ void ha_heap::update_key_stats()
 int ha_heap::write_row(byte * buf)
 {
   int res;
-  statistic_increment(table->in_use->status_var.ha_write_count,&LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_write_count);
   if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
     table->timestamp_field->set_time();
   if (table->next_number_field && buf == table->record[0])
@@ -195,7 +195,7 @@ int ha_heap::write_row(byte * buf)
 int ha_heap::update_row(const byte * old_data, byte * new_data)
 {
   int res;
-  statistic_increment(table->in_use->status_var.ha_update_count,&LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_update_count);
   if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
     table->timestamp_field->set_time();
   res= heap_update(file,old_data,new_data);
@@ -214,7 +214,7 @@ int ha_heap::update_row(const byte * old
 int ha_heap::delete_row(const byte * buf)
 {
   int res;
-  statistic_increment(table->in_use->status_var.ha_delete_count,&LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_delete_count);
   res= heap_delete(file,buf);
   if (!res && table->s->tmp_table == NO_TMP_TABLE && 
       ++records_changed*HEAP_STATS_UPDATE_THRESHOLD > file->s->records)
@@ -232,8 +232,7 @@ int ha_heap::index_read(byte * buf, cons
 			enum ha_rkey_function find_flag)
 {
   DBUG_ASSERT(inited==INDEX);
-  statistic_increment(table->in_use->status_var.ha_read_key_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_key_count);
   int error = heap_rkey(file,buf,active_index, key, key_len, find_flag);
   table->status = error ? STATUS_NOT_FOUND : 0;
   return error;
@@ -242,8 +241,7 @@ int ha_heap::index_read(byte * buf, cons
 int ha_heap::index_read_last(byte *buf, const byte *key, uint key_len)
 {
   DBUG_ASSERT(inited==INDEX);
-  statistic_increment(table->in_use->status_var.ha_read_key_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_key_count);
   int error= heap_rkey(file, buf, active_index, key, key_len,
 		       HA_READ_PREFIX_LAST);
   table->status= error ? STATUS_NOT_FOUND : 0;
@@ -253,8 +251,7 @@ int ha_heap::index_read_last(byte *buf, 
 int ha_heap::index_read_idx(byte * buf, uint index, const byte * key,
 			    uint key_len, enum ha_rkey_function find_flag)
 {
-  statistic_increment(table->in_use->status_var.ha_read_key_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_key_count);
   int error = heap_rkey(file, buf, index, key, key_len, find_flag);
   table->status = error ? STATUS_NOT_FOUND : 0;
   return error;
@@ -263,8 +260,7 @@ int ha_heap::index_read_idx(byte * buf, 
 int ha_heap::index_next(byte * buf)
 {
   DBUG_ASSERT(inited==INDEX);
-  statistic_increment(table->in_use->status_var.ha_read_next_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_next_count);
   int error=heap_rnext(file,buf);
   table->status=error ? STATUS_NOT_FOUND: 0;
   return error;
@@ -273,8 +269,7 @@ int ha_heap::index_next(byte * buf)
 int ha_heap::index_prev(byte * buf)
 {
   DBUG_ASSERT(inited==INDEX);
-  statistic_increment(table->in_use->status_var.ha_read_prev_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_prev_count);
   int error=heap_rprev(file,buf);
   table->status=error ? STATUS_NOT_FOUND: 0;
   return error;
@@ -283,8 +278,7 @@ int ha_heap::index_prev(byte * buf)
 int ha_heap::index_first(byte * buf)
 {
   DBUG_ASSERT(inited==INDEX);
-  statistic_increment(table->in_use->status_var.ha_read_first_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_first_count);
   int error=heap_rfirst(file, buf, active_index);
   table->status=error ? STATUS_NOT_FOUND: 0;
   return error;
@@ -293,8 +287,7 @@ int ha_heap::index_first(byte * buf)
 int ha_heap::index_last(byte * buf)
 {
   DBUG_ASSERT(inited==INDEX);
-  statistic_increment(table->in_use->status_var.ha_read_last_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_last_count);
   int error=heap_rlast(file, buf, active_index);
   table->status=error ? STATUS_NOT_FOUND: 0;
   return error;
@@ -307,8 +300,7 @@ int ha_heap::rnd_init(bool scan)
 
 int ha_heap::rnd_next(byte *buf)
 {
-  statistic_increment(table->in_use->status_var.ha_read_rnd_next_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_rnd_next_count);
   int error=heap_scan(file, buf);
   table->status=error ? STATUS_NOT_FOUND: 0;
   return error;
@@ -318,8 +310,7 @@ int ha_heap::rnd_pos(byte * buf, byte *p
 {
   int error;
   HEAP_PTR position;
-  statistic_increment(table->in_use->status_var.ha_read_rnd_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_rnd_count);
   memcpy_fixed((char*) &position,pos,sizeof(HEAP_PTR));
   error=heap_rrnd(file, buf, position);
   table->status=error ? STATUS_NOT_FOUND: 0;

--- 1.174/sql/ha_myisam.cc	2007-02-22 16:13:51 -07:00
+++ 1.175/sql/ha_myisam.cc	2007-02-22 16:13:51 -07:00
@@ -611,7 +611,7 @@ int ha_myisam::close(void)
 
 int ha_myisam::write_row(byte * buf)
 {
-  statistic_increment(table->in_use->status_var.ha_write_count,&LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_write_count);
 
   /* If we have a timestamp column, update it to the current time */
   if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
@@ -1465,7 +1465,7 @@ bool ha_myisam::is_crashed() const
 
 int ha_myisam::update_row(const byte * old_data, byte * new_data)
 {
-  statistic_increment(table->in_use->status_var.ha_update_count,&LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_update_count);
   if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
     table->timestamp_field->set_time();
   return mi_update(file,old_data,new_data);
@@ -1473,7 +1473,7 @@ int ha_myisam::update_row(const byte * o
 
 int ha_myisam::delete_row(const byte * buf)
 {
-  statistic_increment(table->in_use->status_var.ha_delete_count,&LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_delete_count);
   return mi_delete(file,buf);
 }
 
@@ -1481,8 +1481,7 @@ int ha_myisam::index_read(byte * buf, co
 			  uint key_len, enum ha_rkey_function find_flag)
 {
   DBUG_ASSERT(inited==INDEX);
-  statistic_increment(table->in_use->status_var.ha_read_key_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_key_count);
   int error=mi_rkey(file,buf,active_index, key, key_len, find_flag);
   table->status=error ? STATUS_NOT_FOUND: 0;
   return error;
@@ -1491,8 +1490,7 @@ int ha_myisam::index_read(byte * buf, co
 int ha_myisam::index_read_idx(byte * buf, uint index, const byte * key,
 			      uint key_len, enum ha_rkey_function find_flag)
 {
-  statistic_increment(table->in_use->status_var.ha_read_key_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_key_count);
   int error=mi_rkey(file,buf,index, key, key_len, find_flag);
   table->status=error ? STATUS_NOT_FOUND: 0;
   return error;
@@ -1501,8 +1499,7 @@ int ha_myisam::index_read_idx(byte * buf
 int ha_myisam::index_read_last(byte * buf, const byte * key, uint key_len)
 {
   DBUG_ASSERT(inited==INDEX);
-  statistic_increment(table->in_use->status_var.ha_read_key_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_key_count);
   int error=mi_rkey(file,buf,active_index, key, key_len, HA_READ_PREFIX_LAST);
   table->status=error ? STATUS_NOT_FOUND: 0;
   return error;
@@ -1511,8 +1508,7 @@ int ha_myisam::index_read_last(byte * bu
 int ha_myisam::index_next(byte * buf)
 {
   DBUG_ASSERT(inited==INDEX);
-  statistic_increment(table->in_use->status_var.ha_read_next_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_next_count);
   int error=mi_rnext(file,buf,active_index);
   table->status=error ? STATUS_NOT_FOUND: 0;
   return error;
@@ -1521,8 +1517,7 @@ int ha_myisam::index_next(byte * buf)
 int ha_myisam::index_prev(byte * buf)
 {
   DBUG_ASSERT(inited==INDEX);
-  statistic_increment(table->in_use->status_var.ha_read_prev_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_prev_count);
   int error=mi_rprev(file,buf, active_index);
   table->status=error ? STATUS_NOT_FOUND: 0;
   return error;
@@ -1531,8 +1526,7 @@ int ha_myisam::index_prev(byte * buf)
 int ha_myisam::index_first(byte * buf)
 {
   DBUG_ASSERT(inited==INDEX);
-  statistic_increment(table->in_use->status_var.ha_read_first_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_first_count);
   int error=mi_rfirst(file, buf, active_index);
   table->status=error ? STATUS_NOT_FOUND: 0;
   return error;
@@ -1541,8 +1535,7 @@ int ha_myisam::index_first(byte * buf)
 int ha_myisam::index_last(byte * buf)
 {
   DBUG_ASSERT(inited==INDEX);
-  statistic_increment(table->in_use->status_var.ha_read_last_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_last_count);
   int error=mi_rlast(file, buf, active_index);
   table->status=error ? STATUS_NOT_FOUND: 0;
   return error;
@@ -1553,8 +1546,7 @@ int ha_myisam::index_next_same(byte * bu
 			       uint length __attribute__((unused)))
 {
   DBUG_ASSERT(inited==INDEX);
-  statistic_increment(table->in_use->status_var.ha_read_next_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_next_count);
   int error=mi_rnext_same(file,buf);
   table->status=error ? STATUS_NOT_FOUND: 0;
   return error;
@@ -1570,8 +1562,7 @@ int ha_myisam::rnd_init(bool scan)
 
 int ha_myisam::rnd_next(byte *buf)
 {
-  statistic_increment(table->in_use->status_var.ha_read_rnd_next_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_rnd_next_count);
   int error=mi_scan(file, buf);
   table->status=error ? STATUS_NOT_FOUND: 0;
   return error;
@@ -1584,8 +1575,7 @@ int ha_myisam::restart_rnd_next(byte *bu
 
 int ha_myisam::rnd_pos(byte * buf, byte *pos)
 {
-  statistic_increment(table->in_use->status_var.ha_read_rnd_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_rnd_count);
   int error=mi_rrnd(file, buf, my_get_ptr(pos,ref_length));
   table->status=error ? STATUS_NOT_FOUND: 0;
   return error;
@@ -1855,8 +1845,7 @@ int ha_myisam::ft_read(byte * buf)
   if (!ft_handler)
     return -1;
 
-  thread_safe_increment(table->in_use->status_var.ha_read_next_count,
-			&LOCK_status); // why ?
+  status_var_increment(table->in_use->status_var.ha_read_next_count);
 
   error=ft_handler->please->read_next(ft_handler,(char*) buf);
 

--- 1.89/sql/ha_myisammrg.cc	2007-02-22 16:13:51 -07:00
+++ 1.90/sql/ha_myisammrg.cc	2007-02-22 16:13:51 -07:00
@@ -167,7 +167,7 @@ int ha_myisammrg::close(void)
 
 int ha_myisammrg::write_row(byte * buf)
 {
-  statistic_increment(table->in_use->status_var.ha_write_count,&LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_write_count);
 
   if (file->merge_insert_method == MERGE_INSERT_DISABLED || !file->tables)
     return (HA_ERR_TABLE_READONLY);
@@ -185,7 +185,7 @@ int ha_myisammrg::write_row(byte * buf)
 
 int ha_myisammrg::update_row(const byte * old_data, byte * new_data)
 {
-  statistic_increment(table->in_use->status_var.ha_update_count,&LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_update_count);
   if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
     table->timestamp_field->set_time();
   return myrg_update(file,old_data,new_data);
@@ -193,15 +193,14 @@ int ha_myisammrg::update_row(const byte 
 
 int ha_myisammrg::delete_row(const byte * buf)
 {
-  statistic_increment(table->in_use->status_var.ha_delete_count,&LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_delete_count);
   return myrg_delete(file,buf);
 }
 
 int ha_myisammrg::index_read(byte * buf, const byte * key,
 			  uint key_len, enum ha_rkey_function find_flag)
 {
-  statistic_increment(table->in_use->status_var.ha_read_key_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_key_count);
   int error=myrg_rkey(file,buf,active_index, key, key_len, find_flag);
   table->status=error ? STATUS_NOT_FOUND: 0;
   return error;
@@ -210,8 +209,7 @@ int ha_myisammrg::index_read(byte * buf,
 int ha_myisammrg::index_read_idx(byte * buf, uint index, const byte * key,
 				 uint key_len, enum ha_rkey_function find_flag)
 {
-  statistic_increment(table->in_use->status_var.ha_read_key_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_key_count);
   int error=myrg_rkey(file,buf,index, key, key_len, find_flag);
   table->status=error ? STATUS_NOT_FOUND: 0;
   return error;
@@ -219,8 +217,7 @@ int ha_myisammrg::index_read_idx(byte * 
 
 int ha_myisammrg::index_read_last(byte * buf, const byte * key, uint key_len)
 {
-  statistic_increment(table->in_use->status_var.ha_read_key_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_key_count);
   int error=myrg_rkey(file,buf,active_index, key, key_len,
 		      HA_READ_PREFIX_LAST);
   table->status=error ? STATUS_NOT_FOUND: 0;
@@ -229,8 +226,7 @@ int ha_myisammrg::index_read_last(byte *
 
 int ha_myisammrg::index_next(byte * buf)
 {
-  statistic_increment(table->in_use->status_var.ha_read_next_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_next_count);
   int error=myrg_rnext(file,buf,active_index);
   table->status=error ? STATUS_NOT_FOUND: 0;
   return error;
@@ -238,8 +234,7 @@ int ha_myisammrg::index_next(byte * buf)
 
 int ha_myisammrg::index_prev(byte * buf)
 {
-  statistic_increment(table->in_use->status_var.ha_read_prev_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_prev_count);
   int error=myrg_rprev(file,buf, active_index);
   table->status=error ? STATUS_NOT_FOUND: 0;
   return error;
@@ -247,8 +242,7 @@ int ha_myisammrg::index_prev(byte * buf)
 
 int ha_myisammrg::index_first(byte * buf)
 {
-  statistic_increment(table->in_use->status_var.ha_read_first_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_first_count);
   int error=myrg_rfirst(file, buf, active_index);
   table->status=error ? STATUS_NOT_FOUND: 0;
   return error;
@@ -256,8 +250,7 @@ int ha_myisammrg::index_first(byte * buf
 
 int ha_myisammrg::index_last(byte * buf)
 {
-  statistic_increment(table->in_use->status_var.ha_read_last_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_last_count);
   int error=myrg_rlast(file, buf, active_index);
   table->status=error ? STATUS_NOT_FOUND: 0;
   return error;
@@ -267,8 +260,7 @@ int ha_myisammrg::index_next_same(byte *
                                   const byte *key __attribute__((unused)),
                                   uint length __attribute__((unused)))
 {
-  statistic_increment(table->in_use->status_var.ha_read_next_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_next_count);
   int error=myrg_rnext_same(file,buf);
   table->status=error ? STATUS_NOT_FOUND: 0;
   return error;
@@ -281,8 +273,7 @@ int ha_myisammrg::rnd_init(bool scan)
 
 int ha_myisammrg::rnd_next(byte *buf)
 {
-  statistic_increment(table->in_use->status_var.ha_read_rnd_next_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_rnd_next_count);
   int error=myrg_rrnd(file, buf, HA_OFFSET_ERROR);
   table->status=error ? STATUS_NOT_FOUND: 0;
   return error;
@@ -290,8 +281,7 @@ int ha_myisammrg::rnd_next(byte *buf)
 
 int ha_myisammrg::rnd_pos(byte * buf, byte *pos)
 {
-  statistic_increment(table->in_use->status_var.ha_read_rnd_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_rnd_count);
   int error=myrg_rrnd(file, buf, my_get_ptr(pos,ref_length));
   table->status=error ? STATUS_NOT_FOUND: 0;
   return error;

--- 1.226/sql/handler.cc	2007-02-22 16:13:51 -07:00
+++ 1.227/sql/handler.cc	2007-02-22 16:13:51 -07:00
@@ -628,7 +628,7 @@ int ha_prepare(THD *thd)
     for (; *ht; ht++)
     {
       int err;
-      statistic_increment(thd->status_var.ha_prepare_count,&LOCK_status);
+      status_var_increment(thd->status_var.ha_prepare_count);
       if ((*ht)->prepare)
       {
         if ((err= (*(*ht)->prepare)(thd, all)))
@@ -709,7 +709,7 @@ int ha_commit_trans(THD *thd, bool all)
           my_error(ER_ERROR_DURING_COMMIT, MYF(0), err);
           error= 1;
         }
-        statistic_increment(thd->status_var.ha_prepare_count,&LOCK_status);
+        status_var_increment(thd->status_var.ha_prepare_count);
       }
       DBUG_EXECUTE_IF("crash_commit_after_prepare", abort(););
       if (error || (is_real_trans && xid &&
@@ -756,7 +756,7 @@ int ha_commit_one_phase(THD *thd, bool a
         my_error(ER_ERROR_DURING_COMMIT, MYF(0), err);
         error=1;
       }
-      statistic_increment(thd->status_var.ha_commit_count,&LOCK_status);
+      status_var_increment(thd->status_var.ha_commit_count);
       *ht= 0;
     }
     trans->nht=0;
@@ -812,7 +812,7 @@ int ha_rollback_trans(THD *thd, bool all
         my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), err);
         error=1;
       }
-      statistic_increment(thd->status_var.ha_rollback_count,&LOCK_status);
+      status_var_increment(thd->status_var.ha_rollback_count);
       *ht= 0;
     }
     trans->nht=0;
@@ -1185,7 +1185,7 @@ int ha_rollback_to_savepoint(THD *thd, S
       my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), err);
       error=1;
     }
-    statistic_increment(thd->status_var.ha_savepoint_rollback_count,&LOCK_status);
+    status_var_increment(thd->status_var.ha_savepoint_rollback_count);
     trans->no_2pc|=(*ht)->prepare == 0;
   }
   /*
@@ -1200,7 +1200,7 @@ int ha_rollback_to_savepoint(THD *thd, S
       my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), err);
       error=1;
     }
-    statistic_increment(thd->status_var.ha_rollback_count,&LOCK_status);
+    status_var_increment(thd->status_var.ha_rollback_count);
     *ht=0; // keep it conveniently zero-filled
   }
   DBUG_RETURN(error);
@@ -1234,7 +1234,7 @@ int ha_savepoint(THD *thd, SAVEPOINT *sv
       my_error(ER_GET_ERRNO, MYF(0), err);
       error=1;
     }
-    statistic_increment(thd->status_var.ha_savepoint_count,&LOCK_status);
+    status_var_increment(thd->status_var.ha_savepoint_count);
   }
   sv->nht=trans->nht;
 #endif /* USING_TRANSACTIONS */
@@ -1439,7 +1439,7 @@ int handler::read_first_row(byte * buf, 
   register int error;
   DBUG_ENTER("handler::read_first_row");
 
-  statistic_increment(current_thd->status_var.ha_read_first_count,&LOCK_status);
+  status_var_increment(current_thd->status_var.ha_read_first_count);
 
   /*
     If there is very few deleted rows in the table, find the first row by
@@ -2416,7 +2416,7 @@ int ha_discover(THD *thd, const char *db
     error= ndbcluster_discover(thd, db, name, frmblob, frmlen);
 #endif
   if (!error)
-    statistic_increment(thd->status_var.ha_discover_count,&LOCK_status);
+    status_var_increment(thd->status_var.ha_discover_count);
   DBUG_RETURN(error);
 }
 

--- 1.216/sql/sql_insert.cc	2007-02-22 16:13:51 -07:00
+++ 1.217/sql/sql_insert.cc	2007-02-22 16:13:51 -07:00
@@ -1765,7 +1765,7 @@ static int write_delayed(THD *thd,TABLE 
     unlink_blobs(table);
   pthread_cond_signal(&di->cond);
 
-  thread_safe_increment(delayed_rows_in_use,&LOCK_delayed_status);
+  statistic_increment(delayed_rows_in_use, &LOCK_delayed_status);
   pthread_mutex_unlock(&di->mutex);
   DBUG_RETURN(0);
 
@@ -2153,7 +2153,7 @@ bool delayed_insert::handle_inserts(void
     if (write_record(&thd, table, &info))
     {
       info.error_count++;				// Ignore errors
-      thread_safe_increment(delayed_insert_errors,&LOCK_delayed_status);
+      statistic_increment(delayed_insert_errors, &LOCK_delayed_status);
       row->log_query = 0;
       /*
         We must reset next_insert_id. Otherwise all following rows may
@@ -2187,8 +2187,8 @@ bool delayed_insert::handle_inserts(void
     }
     if (table->s->blob_fields)
       free_delayed_insert_blobs(table);
-    thread_safe_sub(delayed_rows_in_use,1,&LOCK_delayed_status);
-    thread_safe_increment(delayed_insert_writes,&LOCK_delayed_status);
+    statistic_decrement(delayed_rows_in_use, &LOCK_delayed_status);
+    statistic_increment(delayed_insert_writes, &LOCK_delayed_status);
     pthread_mutex_lock(&mutex);
 
     delete row;
@@ -2253,12 +2253,12 @@ bool delayed_insert::handle_inserts(void
   while ((row=rows.get()))
   {
     delete row;
-    thread_safe_increment(delayed_insert_errors,&LOCK_delayed_status);
+    statistic_increment(delayed_insert_errors, &LOCK_delayed_status);
     stacked_inserts--;
     DBUG_EXECUTE("error", max_rows++;);
   }
   DBUG_PRINT("error", ("dropped %lu rows after an error", max_rows));
-  thread_safe_increment(delayed_insert_errors, &LOCK_delayed_status);
+  statistic_increment(delayed_insert_errors, &LOCK_delayed_status);
   pthread_mutex_lock(&mutex);
   DBUG_RETURN(1);
 }

--- 1.605/sql/sql_parse.cc	2007-02-22 16:13:51 -07:00
+++ 1.606/sql/sql_parse.cc	2007-02-22 16:13:51 -07:00
@@ -1618,8 +1618,7 @@ bool dispatch_command(enum enum_server_c
   case COM_INIT_DB:
   {
     LEX_STRING tmp;
-    statistic_increment(thd->status_var.com_stat[SQLCOM_CHANGE_DB],
-			&LOCK_status);
+    status_var_increment(thd->status_var.com_stat[SQLCOM_CHANGE_DB]);
     thd->convert_string(&tmp, system_charset_info,
 			packet, strlen(packet), thd->charset());
     if (!mysql_change_db(thd, tmp.str, FALSE))
@@ -1653,7 +1652,7 @@ bool dispatch_command(enum enum_server_c
       break;
     }
 
-    statistic_increment(thd->status_var.com_other, &LOCK_status);
+    status_var_increment(thd->status_var.com_other);
     thd->enable_slow_log= opt_log_slow_admin_statements;
     db= thd->alloc(db_len + tbl_len + 2);
     if (!db)
@@ -1671,7 +1670,7 @@ bool dispatch_command(enum enum_server_c
     thd->change_user();
     thd->clear_error();                         // if errors from rollback
 
-    statistic_increment(thd->status_var.com_other, &LOCK_status);
+    status_var_increment(thd->status_var.com_other);
     char *user= (char*) packet;
     char *passwd= strend(user)+1;
     /*
@@ -1838,8 +1837,7 @@ bool dispatch_command(enum enum_server_c
     lex_start(thd, 0, 0);
 
 
-    statistic_increment(thd->status_var.com_stat[SQLCOM_SHOW_FIELDS],
-			&LOCK_status);
+    status_var_increment(thd->status_var.com_stat[SQLCOM_SHOW_FIELDS]);
     bzero((char*) &table_list,sizeof(table_list));
     if (thd->copy_db_to(&table_list.db, 0))
       break;
@@ -1899,8 +1897,7 @@ bool dispatch_command(enum enum_server_c
       char *db=thd->strdup(packet), *alias;
       HA_CREATE_INFO create_info;
 
-      statistic_increment(thd->status_var.com_stat[SQLCOM_CREATE_DB],
-			  &LOCK_status);
+      status_var_increment(thd->status_var.com_stat[SQLCOM_CREATE_DB]);
       // null test to handle EOM
       if (!db || !(alias= thd->strdup(db)) || check_db_name(db))
       {
@@ -1917,8 +1914,7 @@ bool dispatch_command(enum enum_server_c
     }
   case COM_DROP_DB:				// QQ: To be removed
     {
-      statistic_increment(thd->status_var.com_stat[SQLCOM_DROP_DB],
-			  &LOCK_status);
+      status_var_increment(thd->status_var.com_stat[SQLCOM_DROP_DB]);
       char *db=thd->strdup(packet);
       /*  null test to handle EOM */
       if (!db || check_db_name(db))
@@ -1945,7 +1941,7 @@ bool dispatch_command(enum enum_server_c
       ushort flags;
       uint32 slave_server_id;
 
-      statistic_increment(thd->status_var.com_other,&LOCK_status);
+      status_var_increment(thd->status_var.com_other);
       thd->enable_slow_log= opt_log_slow_admin_statements;
       if (check_global_access(thd, REPL_SLAVE_ACL))
 	break;
@@ -1971,8 +1967,7 @@ bool dispatch_command(enum enum_server_c
   case COM_REFRESH:
   {
     bool not_used;
-    statistic_increment(thd->status_var.com_stat[SQLCOM_FLUSH],
-                        &LOCK_status);
+    status_var_increment(thd->status_var.com_stat[SQLCOM_FLUSH]);
     ulong options= (ulong) (uchar) packet[0];
     if (check_global_access(thd,RELOAD_ACL))
       break;
@@ -1984,7 +1979,7 @@ bool dispatch_command(enum enum_server_c
 #ifndef EMBEDDED_LIBRARY
   case COM_SHUTDOWN:
   {
-    statistic_increment(thd->status_var.com_other, &LOCK_status);
+    status_var_increment(thd->status_var.com_other);
     if (check_global_access(thd,SHUTDOWN_ACL))
       break; /* purecov: inspected */
     /*
@@ -2022,8 +2017,7 @@ bool dispatch_command(enum enum_server_c
   case COM_STATISTICS:
   {
     mysql_log.write(thd,command,NullS);
-    statistic_increment(thd->status_var.com_stat[SQLCOM_SHOW_STATUS],
-			&LOCK_status);
+    status_var_increment(thd->status_var.com_stat[SQLCOM_SHOW_STATUS]);
 #ifndef EMBEDDED_LIBRARY
     char buff[200];
 #else
@@ -2055,12 +2049,11 @@ bool dispatch_command(enum enum_server_c
     break;
   }
   case COM_PING:
-    statistic_increment(thd->status_var.com_other, &LOCK_status);
+    status_var_increment(thd->status_var.com_other);
     send_ok(thd);				// Tell client we are alive
     break;
   case COM_PROCESS_INFO:
-    statistic_increment(thd->status_var.com_stat[SQLCOM_SHOW_PROCESSLIST],
-			&LOCK_status);
+    status_var_increment(thd->status_var.com_stat[SQLCOM_SHOW_PROCESSLIST]);
     if (!thd->security_ctx->priv_user[0] &&
         check_global_access(thd, PROCESS_ACL))
       break;
@@ -2071,15 +2064,14 @@ bool dispatch_command(enum enum_server_c
     break;
   case COM_PROCESS_KILL:
   {
-    statistic_increment(thd->status_var.com_stat[SQLCOM_KILL], &LOCK_status);
+    status_var_increment(thd->status_var.com_stat[SQLCOM_KILL]);
     ulong id=(ulong) uint4korr(packet);
     kill_one_thread(thd,id,false);
     break;
   }
   case COM_SET_OPTION:
   {
-    statistic_increment(thd->status_var.com_stat[SQLCOM_SET_OPTION],
-			&LOCK_status);
+    status_var_increment(thd->status_var.com_stat[SQLCOM_SET_OPTION]);
     enum_mysql_set_option command= (enum_mysql_set_option) uint2korr(packet);
     switch (command) {
     case MYSQL_OPTION_MULTI_STATEMENTS_ON:
@@ -2097,7 +2089,7 @@ bool dispatch_command(enum enum_server_c
     break;
   }
   case COM_DEBUG:
-    statistic_increment(thd->status_var.com_other, &LOCK_status);
+    status_var_increment(thd->status_var.com_other);
     if (check_global_access(thd, SUPER_ACL))
       break;					/* purecov: inspected */
     mysql_print_status();
@@ -2329,8 +2321,7 @@ int prepare_schema_table(THD *thd, LEX *
   TABLE_LIST *table_list= (TABLE_LIST*) select_lex->table_list.first;
   table_list->schema_select_lex= sel;
   table_list->schema_table_reformed= 1;
-  statistic_increment(thd->status_var.com_stat[lex->orig_sql_command],
-                      &LOCK_status);
+  status_var_increment(thd->status_var.com_stat[lex->orig_sql_command]);
   DBUG_RETURN(0);
 }
 
@@ -2559,8 +2550,7 @@ mysql_execute_command(THD *thd)
   } /* endif unlikely slave */
 #endif
   if(lex->orig_sql_command == SQLCOM_END)
-    statistic_increment(thd->status_var.com_stat[lex->sql_command],
-                        &LOCK_status);
+    status_var_increment(thd->status_var.com_stat[lex->sql_command]);
 
   switch (lex->sql_command) {
   case SQLCOM_SELECT:

--- 1.490/sql/sql_select.cc	2007-02-22 16:13:51 -07:00
+++ 1.491/sql/sql_select.cc	2007-02-22 16:13:51 -07:00
@@ -5944,8 +5944,7 @@ make_join_readinfo(JOIN *join, ulonglong
 	join->thd->server_status|=SERVER_QUERY_NO_GOOD_INDEX_USED;
 	tab->read_first_record= join_init_quick_read_record;
 	if (statistics)
-	  statistic_increment(join->thd->status_var.select_range_check_count,
-			      &LOCK_status);
+	  status_var_increment(join->thd->status_var.select_range_check_count);
       }
       else
       {
@@ -5955,15 +5954,13 @@ make_join_readinfo(JOIN *join, ulonglong
 	  if (tab->select && tab->select->quick)
 	  {
 	    if (statistics)
-	      statistic_increment(join->thd->status_var.select_range_count,
-				  &LOCK_status);
+	      status_var_increment(join->thd->status_var.select_range_count);
 	  }
 	  else
 	  {
 	    join->thd->server_status|=SERVER_QUERY_NO_INDEX_USED;
 	    if (statistics)
-	      statistic_increment(join->thd->status_var.select_scan_count,
-				  &LOCK_status);
+	      status_var_increment(join->thd->status_var.select_scan_count);
 	  }
 	}
 	else
@@ -5971,15 +5968,13 @@ make_join_readinfo(JOIN *join, ulonglong
 	  if (tab->select && tab->select->quick)
 	  {
 	    if (statistics)
-	      statistic_increment(join->thd->status_var.select_full_range_join_count,
-				  &LOCK_status);
+	      status_var_increment(join->thd->status_var.select_full_range_join_count);
 	  }
 	  else
 	  {
 	    join->thd->server_status|=SERVER_QUERY_NO_INDEX_USED;
 	    if (statistics)
-	      statistic_increment(join->thd->status_var.select_full_join_count,
-				  &LOCK_status);
+	      status_var_increment(join->thd->status_var.select_full_join_count);
 	  }
 	}
 	if (!table->no_keyread)
@@ -8965,7 +8960,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARA
 		      (int) distinct, (int) save_sum_fields,
 		      (ulong) rows_limit,test(group)));
 
-  statistic_increment(thd->status_var.created_tmp_tables, &LOCK_status);
+  status_var_increment(thd->status_var.created_tmp_tables);
 
   if (use_temp_pool && !(test_flags & TEST_KEEP_TMP_TABLES))
     temp_pool_slot = bitmap_set_next(&temp_pool);
@@ -9816,8 +9811,7 @@ static bool create_myisam_tmp_table(TABL
     table->db_stat=0;
     goto err;
   }
-  statistic_increment(table->in_use->status_var.created_tmp_disk_tables,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.created_tmp_disk_tables);
   table->s->db_record_offset= 1;
   DBUG_RETURN(0);
  err:

--- 1.79/sql/ha_archive.cc	2007-02-22 16:13:51 -07:00
+++ 1.80/sql/ha_archive.cc	2007-02-22 16:13:51 -07:00
@@ -728,7 +728,7 @@ int ha_archive::write_row(byte *buf)
   if (share->crashed)
       DBUG_RETURN(HA_ERR_CRASHED_ON_USAGE);
 
-  statistic_increment(table->in_use->status_var.ha_write_count, &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_write_count);
   if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
     table->timestamp_field->set_time();
   pthread_mutex_lock(&share->mutex);
@@ -885,8 +885,7 @@ int ha_archive::rnd_next(byte *buf)
     DBUG_RETURN(HA_ERR_END_OF_FILE);
   scan_rows--;
 
-  statistic_increment(table->in_use->status_var.ha_read_rnd_next_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_rnd_next_count);
   current_position= gztell(archive);
   rc= get_row(archive, buf);
 
@@ -922,8 +921,7 @@ void ha_archive::position(const byte *re
 int ha_archive::rnd_pos(byte * buf, byte *pos)
 {
   DBUG_ENTER("ha_archive::rnd_pos");
-  statistic_increment(table->in_use->status_var.ha_read_rnd_next_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_rnd_next_count);
   current_position= (z_off_t)my_get_ptr(pos, ref_length);
   (void)gzseek(archive, current_position, SEEK_SET);
 

--- 1.300/sql/ha_ndbcluster.cc	2007-02-22 16:13:51 -07:00
+++ 1.301/sql/ha_ndbcluster.cc	2007-02-22 16:13:51 -07:00
@@ -2233,7 +2233,7 @@ int ha_ndbcluster::write_row(byte *recor
       DBUG_RETURN(peek_res);
   }
 
-  statistic_increment(thd->status_var.ha_write_count, &LOCK_status);
+  status_var_increment(thd->status_var.ha_write_count);
   if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
     table->timestamp_field->set_time();
 
@@ -2412,7 +2412,7 @@ int ha_ndbcluster::update_row(const byte
       DBUG_RETURN(peek_res);
   }
 
-  statistic_increment(thd->status_var.ha_update_count, &LOCK_status);
+  status_var_increment(thd->status_var.ha_update_count);
   if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
   {
     table->timestamp_field->set_time();
@@ -2545,7 +2545,7 @@ int ha_ndbcluster::delete_row(const byte
   NdbOperation *op;
   DBUG_ENTER("delete_row");
 
-  statistic_increment(thd->status_var.ha_delete_count,&LOCK_status);
+  status_var_increment(thd->status_var.ha_delete_count);
   m_rows_changed++;
 
   if (cursor)
@@ -2873,7 +2873,7 @@ int ha_ndbcluster::index_read_idx(byte *
                               const byte *key, uint key_len, 
                               enum ha_rkey_function find_flag)
 {
-  statistic_increment(current_thd->status_var.ha_read_key_count, &LOCK_status);
+  status_var_increment(current_thd->status_var.ha_read_key_count);
   DBUG_ENTER("ha_ndbcluster::index_read_idx");
   DBUG_PRINT("enter", ("index_no: %u, key_len: %u", index_no, key_len));  
   index_init(index_no);  
@@ -2884,8 +2884,7 @@ int ha_ndbcluster::index_read_idx(byte *
 int ha_ndbcluster::index_next(byte *buf)
 {
   DBUG_ENTER("ha_ndbcluster::index_next");
-  statistic_increment(current_thd->status_var.ha_read_next_count,
-                      &LOCK_status);
+  status_var_increment(current_thd->status_var.ha_read_next_count);
   DBUG_RETURN(next_result(buf));
 }
 
@@ -2893,8 +2892,7 @@ int ha_ndbcluster::index_next(byte *buf)
 int ha_ndbcluster::index_prev(byte *buf)
 {
   DBUG_ENTER("ha_ndbcluster::index_prev");
-  statistic_increment(current_thd->status_var.ha_read_prev_count,
-                      &LOCK_status);
+  status_var_increment(current_thd->status_var.ha_read_prev_count);
   DBUG_RETURN(next_result(buf));
 }
 
@@ -2902,8 +2900,7 @@ int ha_ndbcluster::index_prev(byte *buf)
 int ha_ndbcluster::index_first(byte *buf)
 {
   DBUG_ENTER("ha_ndbcluster::index_first");
-  statistic_increment(current_thd->status_var.ha_read_first_count,
-                      &LOCK_status);
+  status_var_increment(current_thd->status_var.ha_read_first_count);
   // Start the ordered index scan and fetch the first row
 
   // Only HA_READ_ORDER indexes get called by index_first
@@ -2914,7 +2911,7 @@ int ha_ndbcluster::index_first(byte *buf
 int ha_ndbcluster::index_last(byte *buf)
 {
   DBUG_ENTER("ha_ndbcluster::index_last");
-  statistic_increment(current_thd->status_var.ha_read_last_count,&LOCK_status);
+  status_var_increment(current_thd->status_var.ha_read_last_count);
   DBUG_RETURN(ordered_index_scan(0, 0, TRUE, TRUE, buf));
 }
 
@@ -3079,8 +3076,7 @@ int ha_ndbcluster::rnd_end()
 int ha_ndbcluster::rnd_next(byte *buf)
 {
   DBUG_ENTER("rnd_next");
-  statistic_increment(current_thd->status_var.ha_read_rnd_next_count,
-                      &LOCK_status);
+  status_var_increment(current_thd->status_var.ha_read_rnd_next_count);
 
   if (!m_active_cursor)
     DBUG_RETURN(full_table_scan(buf));
@@ -3098,10 +3094,9 @@ int ha_ndbcluster::rnd_next(byte *buf)
 int ha_ndbcluster::rnd_pos(byte *buf, byte *pos)
 {
   DBUG_ENTER("rnd_pos");
-  statistic_increment(current_thd->status_var.ha_read_rnd_count,
-                      &LOCK_status);
-  // The primary key for the record is stored in pos
-  // Perform a pk_read using primary key "index"
+  status_var_increment(current_thd->status_var.ha_read_rnd_count);
+  // The primary key for the record is stored in pos Perform a pk_read using
+  // primary key "index"
   DBUG_RETURN(pk_read(pos, ref_length, buf));  
 }
 

--- 1.25/mysys/mf_tempfile.c	2007-02-22 16:13:51 -07:00
+++ 1.26/mysys/mf_tempfile.c	2007-02-22 16:13:51 -07:00
@@ -192,6 +192,6 @@ File create_temp_file(char *to, const ch
   }
 #endif
   if (file >= 0)
-    thread_safe_increment(my_tmp_file_created,&THR_LOCK_open);
+    statistic_increment(my_tmp_file_created, &THR_LOCK_open);
   DBUG_RETURN(file);
 }

--- 1.307/sql/ha_innodb.cc	2007-02-22 16:13:51 -07:00
+++ 1.308/sql/ha_innodb.cc	2007-02-22 16:13:51 -07:00
@@ -3126,8 +3126,7 @@ ha_innobase::write_row(
 		ut_error;
 	}
 
-  	statistic_increment(current_thd->status_var.ha_write_count,
-			    &LOCK_status);
+        status_var_increment(current_thd->status_var.ha_write_count);
 
         if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
                 table->timestamp_field->set_time();
@@ -3775,8 +3774,7 @@ ha_innobase::index_read(
 	ut_ad(prebuilt->trx ==
                 (trx_t*) current_thd->ha_data[innobase_hton.slot]);
 
-  	statistic_increment(current_thd->status_var.ha_read_key_count,
-			    &LOCK_status);
+        status_var_increment(current_thd->status_var.ha_read_key_count);
 
 	if (last_query_id != user_thd->query_id) {
 	        prebuilt->sql_stat_start = TRUE;
@@ -3882,8 +3880,7 @@ ha_innobase::change_active_index(
 {
 	row_prebuilt_t* prebuilt	= (row_prebuilt_t*) innobase_prebuilt;
 	KEY*		key=0;
-	statistic_increment(current_thd->status_var.ha_read_key_count,
-			    &LOCK_status);
+	status_var_increment(current_thd->status_var.ha_read_key_count);
 	DBUG_ENTER("change_active_index");
 
 	ut_ad(user_thd == current_thd);
@@ -4016,8 +4013,7 @@ ha_innobase::index_next(
 	mysql_byte* 	buf)	/* in/out: buffer for next row in MySQL
 				format */
 {
-  	statistic_increment(current_thd->status_var.ha_read_next_count,
-			    &LOCK_status);
+        status_var_increment(current_thd->status_var.ha_read_next_count);
 
 	return(general_fetch(buf, ROW_SEL_NEXT, 0));
 }
@@ -4034,8 +4030,7 @@ ha_innobase::index_next_same(
 	const mysql_byte* key,	/* in: key value */
 	uint 		keylen)	/* in: key value length */
 {
-  	statistic_increment(current_thd->status_var.ha_read_next_count,
-			    &LOCK_status);
+        status_var_increment(current_thd->status_var.ha_read_next_count);
 
 	return(general_fetch(buf, ROW_SEL_NEXT, last_match_mode));
 }
@@ -4052,8 +4047,7 @@ ha_innobase::index_prev(
 	mysql_byte* 	buf)	/* in/out: buffer for previous row in MySQL
 				format */
 {
-  	statistic_increment(current_thd->status_var.ha_read_prev_count,
-			    &LOCK_status);
+        status_var_increment(current_thd->status_var.ha_read_prev_count);
 
 	return(general_fetch(buf, ROW_SEL_PREV, 0));
 }
@@ -4072,8 +4066,7 @@ ha_innobase::index_first(
 	int	error;
 
   	DBUG_ENTER("index_first");
-  	statistic_increment(current_thd->status_var.ha_read_first_count,
-			    &LOCK_status);
+        status_var_increment(current_thd->status_var.ha_read_first_count);
 
   	error = index_read(buf, NULL, 0, HA_READ_AFTER_KEY);
 
@@ -4099,8 +4092,7 @@ ha_innobase::index_last(
 	int	error;
 
   	DBUG_ENTER("index_last");
-  	statistic_increment(current_thd->status_var.ha_read_last_count,
-			    &LOCK_status);
+        status_var_increment(current_thd->status_var.ha_read_last_count);
 
   	error = index_read(buf, NULL, 0, HA_READ_BEFORE_KEY);
 
@@ -4165,8 +4157,7 @@ ha_innobase::rnd_next(
 	int	error;
 
   	DBUG_ENTER("rnd_next");
-  	statistic_increment(current_thd->status_var.ha_read_rnd_next_count,
-			    &LOCK_status);
+        status_var_increment(current_thd->status_var.ha_read_rnd_next_count);
 
   	if (start_of_scan) {
 		error = index_first(buf);
@@ -4202,8 +4193,7 @@ ha_innobase::rnd_pos(
 	DBUG_ENTER("rnd_pos");
 	DBUG_DUMP("key", (char*) pos, ref_length);
 
-	statistic_increment(current_thd->status_var.ha_read_rnd_count,
-			    &LOCK_status);
+	status_var_increment(current_thd->status_var.ha_read_rnd_count);
 
 	ut_ad(prebuilt->trx ==
                 (trx_t*) current_thd->ha_data[innobase_hton.slot]);

--- 1.73/sql/ha_federated.cc	2007-02-22 16:13:51 -07:00
+++ 1.74/sql/ha_federated.cc	2007-02-22 16:13:51 -07:00
@@ -1572,7 +1572,7 @@ int ha_federated::write_row(byte *buf)
   insert_field_value_string.length(0);
   DBUG_ENTER("ha_federated::write_row");
 
-  statistic_increment(table->in_use->status_var.ha_write_count, &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_write_count);
   if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
     table->timestamp_field->set_time();
 
@@ -2014,8 +2014,7 @@ int ha_federated::index_read_idx_with_re
   *result= 0;                                   // In case of errors
   index_string.length(0);
   sql_query.length(0);
-  statistic_increment(table->in_use->status_var.ha_read_key_count,
-                      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_key_count);
 
   sql_query.append(share->select_query);
 
@@ -2129,8 +2128,7 @@ int ha_federated::read_range_next()
 int ha_federated::index_next(byte *buf)
 {
   DBUG_ENTER("ha_federated::index_next");
-  statistic_increment(table->in_use->status_var.ha_read_next_count,
-		      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_next_count);
   DBUG_RETURN(read_next(buf, stored_result));
 }
 
@@ -2330,8 +2328,7 @@ int ha_federated::rnd_pos(byte *buf, byt
 {
   int result;
   DBUG_ENTER("ha_federated::rnd_pos");
-  statistic_increment(table->in_use->status_var.ha_read_rnd_count,
-                      &LOCK_status);
+  status_var_increment(table->in_use->status_var.ha_read_rnd_count);
   if (table->s->primary_key != MAX_KEY)
   {
     /* We have a primary key, so use index_read_idx to find row */

--- 1.194/sql/sql_prepare.cc	2007-02-22 16:13:51 -07:00
+++ 1.195/sql/sql_prepare.cc	2007-02-22 16:13:51 -07:00
@@ -2365,7 +2365,7 @@ void mysql_stmt_fetch(THD *thd, char *pa
 
   /* First of all clear possible warnings from the previous command */
   mysql_reset_thd_for_next_command(thd);
-  statistic_increment(thd->status_var.com_stmt_fetch, &LOCK_status);
+  status_var_increment(thd->status_var.com_stmt_fetch);
   if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_fetch")))
     DBUG_VOID_RETURN;
 
@@ -2429,7 +2429,7 @@ void mysql_stmt_reset(THD *thd, char *pa
   /* First of all clear possible warnings from the previous command */
   mysql_reset_thd_for_next_command(thd);
 
-  statistic_increment(thd->status_var.com_stmt_reset, &LOCK_status);
+  status_var_increment(thd->status_var.com_stmt_reset);
   if (!(stmt= find_prepared_statement(thd, stmt_id, "mysql_stmt_reset")))
     DBUG_VOID_RETURN;
 
@@ -2531,7 +2531,7 @@ void mysql_stmt_get_longdata(THD *thd, c
   char *packet_end= packet + packet_length - 1;
   DBUG_ENTER("mysql_stmt_get_longdata");
 
-  statistic_increment(thd->status_var.com_stmt_send_long_data, &LOCK_status);
+  status_var_increment(thd->status_var.com_stmt_send_long_data);
 #ifndef EMBEDDED_LIBRARY
   /* Minimal size of long data packet is 6 bytes */
   if (packet_length <= MYSQL_LONG_DATA_HEADER)
@@ -2767,7 +2767,7 @@ bool Prepared_statement::prepare(const c
     However, it seems handy if com_stmt_prepare is increased always,
     no matter what kind of prepare is processed.
   */
-  statistic_increment(thd->status_var.com_stmt_prepare, &LOCK_status);
+  status_var_increment(thd->status_var.com_stmt_prepare);
 
   /*
     alloc_query() uses thd->memroot && thd->query, so we should call
@@ -2878,7 +2878,7 @@ bool Prepared_statement::execute(String 
   Query_arena *old_stmt_arena;
   bool error= TRUE;
 
-  statistic_increment(thd->status_var.com_stmt_execute, &LOCK_status);
+  status_var_increment(thd->status_var.com_stmt_execute);
 
   /* Check if we got an error when sending long data */
   if (state == Query_arena::ERROR)
@@ -2991,7 +2991,7 @@ error:
 bool Prepared_statement::deallocate()
 {
   /* We account deallocate in the same manner as mysql_stmt_close */
-  statistic_increment(thd->status_var.com_stmt_close, &LOCK_status);
+  status_var_increment(thd->status_var.com_stmt_close);
   if (flags & (uint) IS_IN_USE)
   {
     my_error(ER_PS_NO_RECURSION, MYF(0));
Thread
bk commit into 5.0 tree (malff:1.2419) BUG#21554marc.alff23 Feb