List:Commits« Previous MessageNext Message »
From:Kristofer Pettersson Date:October 8 2008 10:31am
Subject:bzr commit into mysql-5.0-bugteam branch (kpettersson:2693) Bug#24289
View as plain text  
#At file:///home/thek/Development/cpp/mysqlbzr/mysql-5.0-bug24289/

 2693 Kristofer Pettersson	2008-10-08
      Bug#24289 Status Variable "Questions" gets wrong values with Stored Routines
                       
      When running Stored Routines the Status Variable "Questions" was wrongly
      incremented. According to the manual it should contain the "number of
      statements that clients have sent to the server"
                    
      Introduced a new status variable 'questions' to replace the query_id
      variable which currently corresponds badly with the number of statements
      sent by the client.
                  
      The new behavior is ment to be backward compatible with 4.0 and at the
      same time work with new features in a similar way.
                 
      This is a backport from 6.0
added:
  mysql-test/r/status2.result
  mysql-test/t/status2.test
modified:
  sql/mysqld.cc
  sql/sql_class.h
  sql/sql_parse.cc
  sql/sql_show.cc
  sql/structs.h

per-file messages:
  sql/mysqld.cc
    Introduced a new status variable 'questions' to replace the query_id
    variable which currently corresponds badly with the number of statements
    sent by the client.
  sql/sql_class.h
    Introduced a new status variable 'questions' to replace the query_id
    variable which currently corresponds badly with the number of statements
    sent by the client.
  sql/sql_parse.cc
    To be backward compatible with 4.0 and at the same time extend the 
    interpretation of the Question variable, it should be increased on
    all COM-commands but COM_STATISTICS, COM_PING, COM_STMT_PREPARE,
    COM_STMT_CLOSE and COM_STMT_RESET.
    Since COM_QUERY can process multiple statements, there has to be an
    extra increase there as well.
  sql/sql_show.cc
    Removed deprecated SHOW_QUESTION status code.
  sql/structs.h
    Removed deprecated SHOW_QUESTION status code.
=== added file 'mysql-test/r/status2.result'
--- a/mysql-test/r/status2.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/status2.result	2008-10-08 10:31:39 +0000
@@ -0,0 +1,54 @@
+#
+# Bug#24289 Status Variable "Questions" gets wrong values with Stored Routines
+#
+FLUSH STATUS;
+CREATE FUNCTION testQuestion() RETURNS INTEGER
+BEGIN
+DECLARE foo INTEGER;
+DECLARE bar INTEGER;
+SET foo=1;
+SET bar=2;
+RETURN foo;
+END $$
+CREATE PROCEDURE testQuestion2()
+BEGIN
+SELECT 1;
+END $$
+DROP TABLE IF EXISTS t1,t2;
+CREATE TABLE t1 (c1 INT);
+CREATE TABLE t2 (c1 INT);
+INSERT INTO t1 VALUES (1);
+Assert Questions == 7
+SHOW STATUS LIKE 'Questions';
+Variable_name	Value
+Questions	7
+SELECT testQuestion();
+testQuestion()
+1
+Assert Questions == 9
+SHOW STATUS LIKE 'Questions';
+Variable_name	Value
+Questions	9
+CALL testQuestion2();
+1
+1
+Assert Questions == 11
+SHOW STATUS LIKE 'Questions';
+Variable_name	Value
+Questions	11
+SELECT 1;
+1
+1
+Assert Questions == 13
+SHOW STATUS LIKE 'Questions';
+Variable_name	Value
+Questions	13
+SELECT 1;
+1
+1
+Assert Questions == 14
+SHOW STATUS LIKE 'Questions';
+Variable_name	Value
+Questions	14
+DROP TABLE t1,t2;
+End of 6.0 tests

=== added file 'mysql-test/t/status2.test'
--- a/mysql-test/t/status2.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/status2.test	2008-10-08 10:31:39 +0000
@@ -0,0 +1,45 @@
+--echo #
+--echo # Bug#24289 Status Variable "Questions" gets wrong values with Stored Routines
+--echo #
+FLUSH STATUS;
+DELIMITER $$;
+CREATE FUNCTION testQuestion() RETURNS INTEGER
+BEGIN
+  DECLARE foo INTEGER;
+  DECLARE bar INTEGER;
+  SET foo=1;
+  SET bar=2;
+  RETURN foo;
+END $$
+CREATE PROCEDURE testQuestion2()
+BEGIN
+  SELECT 1;
+END $$
+DELIMITER ;$$
+--disable_warnings
+DROP TABLE IF EXISTS t1,t2;
+--enable_warnings
+CREATE TABLE t1 (c1 INT);
+CREATE TABLE t2 (c1 INT);
+INSERT INTO t1 VALUES (1);
+--echo Assert Questions == 7
+SHOW STATUS LIKE 'Questions';
+SELECT testQuestion();
+--echo Assert Questions == 9
+SHOW STATUS LIKE 'Questions';
+CALL testQuestion2();
+--echo Assert Questions == 11
+SHOW STATUS LIKE 'Questions';
+SELECT 1;
+--echo Assert Questions == 13
+SHOW STATUS LIKE 'Questions';
+connect (con1,localhost,root,,);
+connection con1;
+SELECT 1;
+connection default;
+disconnect con1;
+--echo Assert Questions == 14
+SHOW STATUS LIKE 'Questions';
+DROP TABLE t1,t2;
+--echo End of 6.0 tests
+

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2008-08-26 08:32:43 +0000
+++ b/sql/mysqld.cc	2008-10-08 10:31:39 +0000
@@ -6573,7 +6573,9 @@ struct show_var_st status_vars[]= {
   {"Qcache_queries_in_cache",  (char*) &query_cache.queries_in_cache, SHOW_LONG_CONST},
   {"Qcache_total_blocks",      (char*) &query_cache.total_blocks, SHOW_LONG_CONST},
 #endif /*HAVE_QUERY_CACHE*/
-  {"Questions",                (char*) 0,                       SHOW_QUESTION},
+  {"Questions",                (char*) offsetof(STATUS_VAR, questions),
+   SHOW_LONG_STATUS},
+
   {"Rpl_status",               (char*) 0,                 SHOW_RPL_STATUS},
   {"Select_full_join",         (char*) offsetof(STATUS_VAR, select_full_join_count), SHOW_LONG_STATUS},
   {"Select_full_range_join",   (char*) offsetof(STATUS_VAR, select_full_range_join_count), SHOW_LONG_STATUS},

=== modified file 'sql/sql_class.h'
--- a/sql/sql_class.h	2008-09-17 06:34:00 +0000
+++ b/sql/sql_class.h	2008-10-08 10:31:39 +0000
@@ -664,10 +664,17 @@ typedef struct system_status_var
   ulong com_stmt_fetch;
   ulong com_stmt_reset;
   ulong com_stmt_close;
+  /*
+    Number of statements sent from the client
+  */
+  ulong questions;
 
   /*
-    Status variables which it does not make sense to add to
-    global status variable counter
+    IMPORTANT!
+    SEE last_system_status_var DEFINITION BELOW.
+
+    Below 'last_system_status_var' are all variables which doesn't make any
+    sense to add to the /global/ status variable counter.
   */
   double last_query_cost;
 } STATUS_VAR;
@@ -678,7 +685,7 @@ typedef struct system_status_var
   counter
 */
 
-#define last_system_status_var com_stmt_close
+#define last_system_status_var questions
 
 
 void free_tmp_table(THD *thd, TABLE *entry);

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2008-08-26 08:32:43 +0000
+++ b/sql/sql_parse.cc	2008-10-08 10:31:39 +0000
@@ -1690,8 +1690,24 @@ bool dispatch_command(enum enum_server_c
   thd->set_time();
   VOID(pthread_mutex_lock(&LOCK_thread_count));
   thd->query_id= global_query_id;
-  if (command != COM_STATISTICS && command != COM_PING)
+  
+  switch( command ) {
+  /* Ignore these statements. */
+  case COM_STATISTICS:
+  case COM_PING:
+    break;
+  /* Only increase id on these statements but don't count them. */
+  case COM_STMT_PREPARE: 
+  case COM_STMT_CLOSE:
+  case COM_STMT_RESET:
+    next_query_id();
+    break;
+  /* Increase id and count all other statements. */
+  default:
+    statistic_increment(thd->status_var.questions, &LOCK_status);
     next_query_id();
+  }
+  
   thread_running++;
   /* TODO: set thd->lex->sql_command to SQLCOM_END here */
   VOID(pthread_mutex_unlock(&LOCK_thread_count));
@@ -1896,6 +1912,11 @@ bool dispatch_command(enum enum_server_c
       VOID(pthread_mutex_lock(&LOCK_thread_count));
       thd->query_length= length;
       thd->query= next_packet;
+      /*
+        Count each statement from the client.
+      */
+      statistic_increment(thd->status_var.questions, &LOCK_status);
+
       thd->query_id= next_query_id();
       thd->set_time(); /* Reset the query start time. */
       /* TODO: set thd->lex->sql_command to SQLCOM_END here */

=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc	2008-08-15 20:13:27 +0000
+++ b/sql/sql_show.cc	2008-10-08 10:31:39 +0000
@@ -1520,9 +1520,6 @@ static bool show_status_array(THD *thd, 
           nr= (long) (thd->query_start() - server_start_time);
           end= int10_to_str(nr, buff, 10);
           break;
-        case SHOW_QUESTION:
-          end= int10_to_str((long) thd->query_id, buff, 10);
-          break;
 #ifdef HAVE_REPLICATION
         case SHOW_RPL_STATUS:
           end= strmov(buff, rpl_status_type[(int)rpl_status]);

=== modified file 'sql/structs.h'
--- a/sql/structs.h	2007-10-26 10:37:38 +0000
+++ b/sql/structs.h	2008-10-08 10:31:39 +0000
@@ -170,7 +170,7 @@ enum SHOW_TYPE
   SHOW_UNDEF,
   SHOW_LONG, SHOW_LONGLONG, SHOW_INT, SHOW_CHAR, SHOW_CHAR_PTR, 
   SHOW_DOUBLE_STATUS,
-  SHOW_BOOL, SHOW_MY_BOOL, SHOW_OPENTABLES, SHOW_STARTTIME, SHOW_QUESTION,
+  SHOW_BOOL, SHOW_MY_BOOL, SHOW_OPENTABLES, SHOW_STARTTIME, 
   SHOW_LONG_CONST, SHOW_INT_CONST, SHOW_HAVE, SHOW_SYS, SHOW_HA_ROWS,
   SHOW_VARS,
 #ifdef HAVE_OPENSSL

Thread
bzr commit into mysql-5.0-bugteam branch (kpettersson:2693) Bug#24289Kristofer Pettersson10 Oct