Commit 73f8b4da authored by unknown's avatar unknown

MDEV-4981: Account for queries handled by query-cache in USER_STATISTICS (and in HOST_STATISTICS)

fix for SP & PS
parent 2f4db534
...@@ -2008,7 +2008,74 @@ SELECT_COMMANDS ROWS_SENT EMPTY_QUERIES ...@@ -2008,7 +2008,74 @@ SELECT_COMMANDS ROWS_SENT EMPTY_QUERIES
show status like "Qcache_hits"; show status like "Qcache_hits";
Variable_name Value Variable_name Value
Qcache_hits 2 Qcache_hits 2
FLUSH USER_STATISTICS;
FLUSH CLIENT_STATISTICS;
flush status;
create procedure p1()
select * from t1;
call p1;
a
select SELECT_COMMANDS,ROWS_SENT,EMPTY_QUERIES from INFORMATION_SCHEMA.CLIENT_STATISTICS
where CLIENT="localhost";
SELECT_COMMANDS ROWS_SENT EMPTY_QUERIES
1 0 1
select SELECT_COMMANDS,ROWS_SENT,EMPTY_QUERIES from INFORMATION_SCHEMA.USER_STATISTICS
where USER="root";
SELECT_COMMANDS ROWS_SENT EMPTY_QUERIES
2 1 1
show status like "Qcache_hits";
Variable_name Value
Qcache_hits 0
call p1;
a
call p1;
a
select SELECT_COMMANDS,ROWS_SENT,EMPTY_QUERIES from INFORMATION_SCHEMA.CLIENT_STATISTICS
where CLIENT="localhost";
SELECT_COMMANDS ROWS_SENT EMPTY_QUERIES
5 2 3
select SELECT_COMMANDS,ROWS_SENT,EMPTY_QUERIES from INFORMATION_SCHEMA.USER_STATISTICS
where USER="root";
SELECT_COMMANDS ROWS_SENT EMPTY_QUERIES
6 3 3
show status like "Qcache_hits";
Variable_name Value
Qcache_hits 2
FLUSH USER_STATISTICS;
FLUSH CLIENT_STATISTICS;
flush status;
SET GLOBAL query_cache_size= 0;
call p1;
a
select SELECT_COMMANDS,ROWS_SENT,EMPTY_QUERIES from INFORMATION_SCHEMA.CLIENT_STATISTICS
where CLIENT="localhost";
SELECT_COMMANDS ROWS_SENT EMPTY_QUERIES
1 0 1
select SELECT_COMMANDS,ROWS_SENT,EMPTY_QUERIES from INFORMATION_SCHEMA.USER_STATISTICS
where USER="root";
SELECT_COMMANDS ROWS_SENT EMPTY_QUERIES
2 1 1
show status like "Qcache_hits";
Variable_name Value
Qcache_hits 0
call p1;
a
call p1;
a
select SELECT_COMMANDS,ROWS_SENT,EMPTY_QUERIES from INFORMATION_SCHEMA.CLIENT_STATISTICS
where CLIENT="localhost";
SELECT_COMMANDS ROWS_SENT EMPTY_QUERIES
5 2 3
select SELECT_COMMANDS,ROWS_SENT,EMPTY_QUERIES from INFORMATION_SCHEMA.USER_STATISTICS
where USER="root";
SELECT_COMMANDS ROWS_SENT EMPTY_QUERIES
6 3 3
show status like "Qcache_hits";
Variable_name Value
Qcache_hits 0
drop procedure p1;
drop table t1; drop table t1;
set GLOBAL query_cache_size=1355776;
SET GLOBAL userstat=default; SET GLOBAL userstat=default;
End of 5.5 tests End of 5.5 tests
restore defaults restore defaults
......
...@@ -1665,7 +1665,47 @@ select SELECT_COMMANDS,ROWS_SENT,EMPTY_QUERIES from INFORMATION_SCHEMA.USER_STAT ...@@ -1665,7 +1665,47 @@ select SELECT_COMMANDS,ROWS_SENT,EMPTY_QUERIES from INFORMATION_SCHEMA.USER_STAT
where USER="root"; where USER="root";
show status like "Qcache_hits"; show status like "Qcache_hits";
FLUSH USER_STATISTICS;
FLUSH CLIENT_STATISTICS;
flush status;
create procedure p1()
select * from t1;
call p1;
select SELECT_COMMANDS,ROWS_SENT,EMPTY_QUERIES from INFORMATION_SCHEMA.CLIENT_STATISTICS
where CLIENT="localhost";
select SELECT_COMMANDS,ROWS_SENT,EMPTY_QUERIES from INFORMATION_SCHEMA.USER_STATISTICS
where USER="root";
show status like "Qcache_hits";
call p1;
call p1;
select SELECT_COMMANDS,ROWS_SENT,EMPTY_QUERIES from INFORMATION_SCHEMA.CLIENT_STATISTICS
where CLIENT="localhost";
select SELECT_COMMANDS,ROWS_SENT,EMPTY_QUERIES from INFORMATION_SCHEMA.USER_STATISTICS
where USER="root";
show status like "Qcache_hits";
FLUSH USER_STATISTICS;
FLUSH CLIENT_STATISTICS;
flush status;
SET GLOBAL query_cache_size= 0;
call p1;
select SELECT_COMMANDS,ROWS_SENT,EMPTY_QUERIES from INFORMATION_SCHEMA.CLIENT_STATISTICS
where CLIENT="localhost";
select SELECT_COMMANDS,ROWS_SENT,EMPTY_QUERIES from INFORMATION_SCHEMA.USER_STATISTICS
where USER="root";
show status like "Qcache_hits";
call p1;
call p1;
select SELECT_COMMANDS,ROWS_SENT,EMPTY_QUERIES from INFORMATION_SCHEMA.CLIENT_STATISTICS
where CLIENT="localhost";
select SELECT_COMMANDS,ROWS_SENT,EMPTY_QUERIES from INFORMATION_SCHEMA.USER_STATISTICS
where USER="root";
show status like "Qcache_hits";
drop procedure p1;
drop table t1; drop table t1;
set GLOBAL query_cache_size=1355776;
SET GLOBAL userstat=default; SET GLOBAL userstat=default;
--echo End of 5.5 tests --echo End of 5.5 tests
......
...@@ -3137,7 +3137,15 @@ sp_instr_stmt::execute(THD *thd, uint *nextp) ...@@ -3137,7 +3137,15 @@ sp_instr_stmt::execute(THD *thd, uint *nextp)
log_slow_statement(thd); log_slow_statement(thd);
} }
else else
{
/* change statistics */
enum_sql_command save_sql_command= thd->lex->sql_command;
thd->lex->sql_command= SQLCOM_SELECT;
status_var_increment(thd->status_var.com_stat[SQLCOM_SELECT]);
thd->update_stats();
thd->lex->sql_command= save_sql_command;
*nextp= m_ip+1; *nextp= m_ip+1;
}
thd->set_query(query_backup); thd->set_query(query_backup);
thd->query_name_consts= 0; thd->query_name_consts= 0;
......
...@@ -5791,7 +5791,7 @@ void mysql_parse(THD *thd, char *rawbuf, uint length, ...@@ -5791,7 +5791,7 @@ void mysql_parse(THD *thd, char *rawbuf, uint length,
{ {
/* Update statistics for getting the query from the cache */ /* Update statistics for getting the query from the cache */
thd->lex->sql_command= SQLCOM_SELECT; thd->lex->sql_command= SQLCOM_SELECT;
status_var_increment(thd->status_var.com_stat[thd->lex->sql_command]); status_var_increment(thd->status_var.com_stat[SQLCOM_SELECT]);
thd->update_stats(); thd->update_stats();
} }
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
......
...@@ -3905,6 +3905,12 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor) ...@@ -3905,6 +3905,12 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor)
error= mysql_execute_command(thd); error= mysql_execute_command(thd);
MYSQL_QUERY_EXEC_DONE(error); MYSQL_QUERY_EXEC_DONE(error);
} }
else
{
thd->lex->sql_command= SQLCOM_SELECT;
status_var_increment(thd->status_var.com_stat[SQLCOM_SELECT]);
thd->update_stats();
}
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment