List:Commits« Previous MessageNext Message »
From:ramil Date:June 8 2006 9:45am
Subject:bk commit into 5.0 tree (ramil:1.2168) BUG#10210
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of ram. When ram 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
  1.2168 06/06/08 14:45:17 ramil@stripped +3 -0
  Fix for bug #10210: running SHOW STATUS increments counters it shouldn't
    - don't change thread's statistics for SHOW STATUS commands.

  sql/sql_select.cc
    1.422 06/06/08 14:45:07 ramil@stripped +19 -0
    Fix for bug #10210: running SHOW STATUS increments counters it shouldn't
      - save thread's status variables before SHOW STATUS query processing then restore it 
        and update global statistics.

  sql/sql_class.h
    1.289 06/06/08 14:45:07 ramil@stripped +7 -0
    Fix for bug #10210: running SHOW STATUS increments counters it shouldn't
      - add_diff_to_status() introduced.

  sql/sql_class.cc
    1.235 06/06/08 14:45:06 ramil@stripped +25 -0
    Fix for bug #10210: running SHOW STATUS increments counters it shouldn't
      - add_diff_to_status() introduced.

# 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:	ramil
# Host:	myoffice.izhnet.ru
# Root:	/usr/home/ram/work/5.0.b10210

--- 1.234/sql/sql_class.cc	2006-05-31 13:47:10 +05:00
+++ 1.235/sql/sql_class.cc	2006-06-08 14:45:06 +05:00
@@ -471,6 +471,31 @@ void add_to_status(STATUS_VAR *to_var, S
 }
 
 
+/*
+  Add the difference between two status variable arrays to another one.
+
+  SYNOPSIS
+    add_diff_to_status
+    to_var       add to this array
+    from_var     from this array
+    dec_var      minus this array
+  
+  NOTE
+    This function assumes that all variables are long/ulong.
+*/
+
+void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
+                        STATUS_VAR *dec_var, uint length)
+{
+  ulong *to= (ulong*) to_var;
+  ulong *end= (ulong*) ((byte*) to_var + length);
+  ulong *from= (ulong*) from_var, *dec= (ulong*) dec_var;
+
+  while (to != end)
+    *(to++)+= *(from++) - *(dec++);
+}
+
+
 void THD::awake(THD::killed_state state_to_set)
 {
   THD_CHECK_SENTRY(this);

--- 1.288/sql/sql_class.h	2006-04-13 12:25:52 +05:00
+++ 1.289/sql/sql_class.h	2006-06-08 14:45:07 +05:00
@@ -651,6 +651,11 @@ typedef struct system_status_var
 
 #define last_system_status_var com_stmt_close
 
+/*
+  Size of the buffer used to save/restore status variables
+*/
+
+#define status_var_buf_size offsetof(STATUS_VAR, last_query_cost)
 
 void free_tmp_table(THD *thd, TABLE *entry);
 
@@ -2107,3 +2112,5 @@ public:
 /* Functions in sql_class.cc */
 
 void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var);
+void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
+                        STATUS_VAR *dec_var, uint length);

--- 1.421/sql/sql_select.cc	2006-05-26 13:51:17 +05:00
+++ 1.422/sql/sql_select.cc	2006-06-08 14:45:07 +05:00
@@ -1836,6 +1836,7 @@ mysql_select(THD *thd, Item ***rref_poin
 {
   bool err;
   bool free_join= 1;
+  byte *saved_status_var= 0;
   DBUG_ENTER("mysql_select");
 
   select_lex->context.resolve_in_select_list= TRUE;
@@ -1885,6 +1886,13 @@ mysql_select(THD *thd, Item ***rref_poin
     }
   }
 
+  if ((thd->lex->orig_sql_command == SQLCOM_SHOW_STATUS) &&
+      (saved_status_var= (byte*) thd->alloc(status_var_buf_size)))
+  {
+    /* Save status variables */
+    memcpy(saved_status_var, &thd->status_var, status_var_buf_size);
+  }
+
   if ((err= join->optimize()))
   {
     goto err;					// 1
@@ -1918,6 +1926,17 @@ mysql_select(THD *thd, Item ***rref_poin
   }
 
 err:
+  if ((thd->lex->orig_sql_command == SQLCOM_SHOW_STATUS) && saved_status_var)
+  {
+    /* Update global statistics */
+    pthread_mutex_lock(&LOCK_status);
+    add_diff_to_status(&global_status_var, &thd->status_var,
+                       (STATUS_VAR*) saved_status_var,  status_var_buf_size);
+    pthread_mutex_unlock(&LOCK_status);
+    /* Restore status variables */
+    memcpy(&thd->status_var, saved_status_var, status_var_buf_size);
+  }
+
   if (free_join)
   {
     thd->proc_info="end";
Thread
bk commit into 5.0 tree (ramil:1.2168) BUG#10210ramil8 Jun