Commit 2f4db534 authored by unknown's avatar unknown

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

Added collection statistics for queries resolved via query cache.
parent eae0a45f
......@@ -1932,6 +1932,85 @@ set local query_cache_type= on;
select @@query_cache_size, @@global.query_cache_type, @@local.query_cache_type;
@@query_cache_size @@global.query_cache_type @@local.query_cache_type
20971520 ON ON
#
# MDEV-4981: Account for queries handled by query-cache in
# USER_STATISTICS (and in HOST_STATISTICS)
#
SET GLOBAL userstat=1;
set GLOBAL query_cache_size=1355776;
FLUSH USER_STATISTICS;
FLUSH CLIENT_STATISTICS;
reset query cache;
flush status;
create table t1 (a int);
insert into t1 values (1);
select * from t1;
a
1
select SELECT_COMMANDS,ROWS_SENT,EMPTY_QUERIES from INFORMATION_SCHEMA.CLIENT_STATISTICS
where CLIENT="localhost";
SELECT_COMMANDS ROWS_SENT EMPTY_QUERIES
1 1 0
select SELECT_COMMANDS,ROWS_SENT,EMPTY_QUERIES from INFORMATION_SCHEMA.USER_STATISTICS
where USER="root";
SELECT_COMMANDS ROWS_SENT EMPTY_QUERIES
2 2 0
show status like "Qcache_hits";
Variable_name Value
Qcache_hits 0
select * from t1;
a
1
select * from t1;
a
1
select SELECT_COMMANDS,ROWS_SENT,EMPTY_QUERIES from INFORMATION_SCHEMA.CLIENT_STATISTICS
where CLIENT="localhost";
SELECT_COMMANDS ROWS_SENT EMPTY_QUERIES
5 5 0
select SELECT_COMMANDS,ROWS_SENT,EMPTY_QUERIES from INFORMATION_SCHEMA.USER_STATISTICS
where USER="root";
SELECT_COMMANDS ROWS_SENT EMPTY_QUERIES
6 6 0
show status like "Qcache_hits";
Variable_name Value
Qcache_hits 2
drop table t1;
FLUSH USER_STATISTICS;
FLUSH CLIENT_STATISTICS;
flush status;
create table t1 (a int);
select * from t1;
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
select * from t1;
a
select * from t1;
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
drop table t1;
SET GLOBAL userstat=default;
End of 5.5 tests
restore defaults
SET GLOBAL query_cache_type= default;
SET GLOBAL query_cache_size= default;
......
......@@ -1617,6 +1617,58 @@ select @@query_cache_size, @@global.query_cache_type, @@local.query_cache_type;
set local query_cache_type= on;
select @@query_cache_size, @@global.query_cache_type, @@local.query_cache_type;
--echo #
--echo # MDEV-4981: Account for queries handled by query-cache in
--echo # USER_STATISTICS (and in HOST_STATISTICS)
--echo #
SET GLOBAL userstat=1;
set GLOBAL query_cache_size=1355776;
FLUSH USER_STATISTICS;
FLUSH CLIENT_STATISTICS;
reset query cache;
flush status;
create table t1 (a int);
insert into t1 values (1);
select * from t1;
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";
select * from t1;
select * from t1;
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 table t1;
FLUSH USER_STATISTICS;
FLUSH CLIENT_STATISTICS;
flush status;
create table t1 (a int);
select * from t1;
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";
select * from t1;
select * from t1;
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 table t1;
SET GLOBAL userstat=default;
--echo End of 5.5 tests
--echo restore defaults
SET GLOBAL query_cache_type= default;
......
......@@ -2074,9 +2074,13 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d",
}
#endif /*!EMBEDDED_LIBRARY*/
thd->limit_found_rows = query->found_rows();
thd->sent_row_count= thd->limit_found_rows = query->found_rows();
thd->status_var.last_query_cost= 0.0;
thd->query_plan_flags= (thd->query_plan_flags & ~QPLAN_QC_NO) | QPLAN_QC;
if (!thd->sent_row_count)
status_var_increment(thd->status_var.empty_queries);
else
status_var_add(thd->status_var.rows_sent, thd->sent_row_count);
/*
End the statement transaction potentially started by an
......
......@@ -4656,6 +4656,7 @@ static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables)
/* Count number of empty select queries */
if (!thd->sent_row_count)
status_var_increment(thd->status_var.empty_queries);
else
status_var_add(thd->status_var.rows_sent, thd->sent_row_count);
return res;
}
......@@ -5790,6 +5791,8 @@ void mysql_parse(THD *thd, char *rawbuf, uint length,
{
/* Update statistics for getting the query from the cache */
thd->lex->sql_command= SQLCOM_SELECT;
status_var_increment(thd->status_var.com_stat[thd->lex->sql_command]);
thd->update_stats();
}
DBUG_VOID_RETURN;
}
......
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