Below is the list of changes that have just been committed into a local
6.0 repository of thek. When thek 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, 2008-04-09 11:04:34+02:00, thek@adventure.(none) +5 -0
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.
mysql-test/r/status2.result@stripped, 2008-04-09 11:04:30+02:00, thek@adventure.(none) +73 -0
New status test file which supports PS-protocol and embedded server.
mysql-test/r/status2.result@stripped, 2008-04-09 11:04:30+02:00, thek@adventure.(none) +0 -0
mysql-test/t/status2.test@stripped, 2008-04-09 11:04:30+02:00, thek@adventure.(none) +66 -0
New status test file which supports PS-protocol and embedded server.
mysql-test/t/status2.test@stripped, 2008-04-09 11:04:30+02:00, thek@adventure.(none) +0 -0
sql/mysqld.cc@stripped, 2008-04-09 11:04:29+02:00, thek@adventure.(none) +1 -8
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@stripped, 2008-04-09 11:04:30+02:00, thek@adventure.(none) +12 -3
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@stripped, 2008-04-09 11:04:30+02:00, thek@adventure.(none) +22 -2
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.
diff -Nrup a/mysql-test/r/status2.result b/mysql-test/r/status2.result
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/mysql-test/r/status2.result 2008-04-09 11:04:30 +02:00
@@ -0,0 +1,73 @@
+#
+# 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);
+CREATE EVENT ev1 ON SCHEDULE EVERY 1 SECOND
+DO 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
+CREATE TRIGGER trigg1 AFTER INSERT ON t1
+FOR EACH ROW BEGIN
+INSERT INTO t2 VALUES (1);
+END;
+$$
+Assert Questions == 16
+SHOW STATUS LIKE 'Questions';
+Variable_name Value
+Questions 16
+INSERT INTO t1 VALUES (1);
+Assert Questions == 18
+SHOW STATUS LIKE 'Questions';
+Variable_name Value
+Questions 18
+DROP PROCEDURE testQuestion2;
+DROP TRIGGER trigg1;
+DROP FUNCTION testQuestion;
+DROP EVENT ev1;
+DROP TABLE t1,t2;
+End of 6.0 tests
diff -Nrup a/mysql-test/t/status2.test b/mysql-test/t/status2.test
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/mysql-test/t/status2.test 2008-04-09 11:04:30 +02:00
@@ -0,0 +1,66 @@
+--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);
+CREATE EVENT ev1 ON SCHEDULE EVERY 1 SECOND
+ DO 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';
+DELIMITER $$;
+CREATE TRIGGER trigg1 AFTER INSERT ON t1
+ FOR EACH ROW BEGIN
+ INSERT INTO t2 VALUES (1);
+ END;
+$$
+DELIMITER ;$$
+--echo Assert Questions == 16
+SHOW STATUS LIKE 'Questions';
+INSERT INTO t1 VALUES (1);
+--echo Assert Questions == 18
+SHOW STATUS LIKE 'Questions';
+# TODO: Uncomment the lines below when FLUSH GLOBAL STATUS is implemented.
+# FLUSH STATUS;
+# SHOW GLOBAL STATUS LIKE 'Questions';
+DROP PROCEDURE testQuestion2;
+DROP TRIGGER trigg1;
+DROP FUNCTION testQuestion;
+DROP EVENT ev1;
+DROP TABLE t1,t2;
+--echo End of 6.0 tests
+
diff -Nrup a/sql/mysqld.cc b/sql/mysqld.cc
--- a/sql/mysqld.cc 2008-03-19 13:16:03 +01:00
+++ b/sql/mysqld.cc 2008-04-09 11:04:29 +02:00
@@ -6926,13 +6926,6 @@ The minimum value for this variable is 4
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
-static int show_question(THD *thd, SHOW_VAR *var, char *buff)
-{
- var->type= SHOW_LONGLONG;
- var->value= (char *)&thd->query_id;
- return 0;
-}
-
static int show_net_compression(THD *thd, SHOW_VAR *var, char *buff)
{
var->type= SHOW_MY_BOOL;
@@ -7381,7 +7374,7 @@ SHOW_VAR status_vars[]= {
{"Qcache_queries_in_cache", (char*) &query_cache.queries_in_cache, SHOW_LONG_NOFLUSH},
{"Qcache_total_blocks", (char*) &query_cache.total_blocks, SHOW_LONG_NOFLUSH},
#endif /*HAVE_QUERY_CACHE*/
- {"Questions", (char*) &show_question, SHOW_FUNC},
+ {"Questions", (char*) offsetof(STATUS_VAR, questions), SHOW_LONG_STATUS},
#ifdef HAVE_REPLICATION
{"Rpl_status", (char*) &show_rpl_status, SHOW_FUNC},
#endif
diff -Nrup a/sql/sql_class.h b/sql/sql_class.h
--- a/sql/sql_class.h 2008-03-18 11:54:34 +01:00
+++ b/sql/sql_class.h 2008-04-09 11:04:30 +02:00
@@ -455,12 +455,21 @@ 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;
/*
@@ -469,7 +478,7 @@ typedef struct system_status_var
counter
*/
-#define last_system_status_var com_stmt_close
+#define last_system_status_var questions
void mark_transaction_to_rollback(THD *thd, bool all);
diff -Nrup a/sql/sql_parse.cc b/sql/sql_parse.cc
--- a/sql/sql_parse.cc 2008-03-18 11:54:34 +01:00
+++ b/sql/sql_parse.cc 2008-04-09 11:04:30 +02:00
@@ -797,7 +797,6 @@ static my_bool deny_updates_if_read_only
DBUG_RETURN(FALSE);
}
-
/**
Perform one connection-level (COM_XXXX) command.
@@ -837,8 +836,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));
@@ -1058,10 +1073,15 @@ bool dispatch_command(enum enum_server_c
VOID(pthread_mutex_lock(&LOCK_thread_count));
thd->query_length= length;
thd->query= beginning_of_next_stmt;
+ /*
+ 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 */
VOID(pthread_mutex_unlock(&LOCK_thread_count));
+
mysql_parse(thd, beginning_of_next_stmt, length, &end_of_stmt);
}
| Thread |
|---|
| • bk commit into 6.0 tree (thek:1.2610) BUG#24289 | kpettersson | 9 Apr |