The query_response_time
plugin was first released in MariaDB 10.0.4.
The query_response_time
plugin creates the QUERY_RESPONSE_TIME
table in the INFORMATION_SCHEMA
database. The plugin also adds the SHOW QUERY_RESPONSE_TIME
and FLUSH QUERY_RESPONSE_TIME
statements.
The slow query log provides exact information about queries that take a long time to execute. However, sometimes there are a large number of queries that each take a very short amount of time to execute. This feature provides a tool for analyzing that information by counting and displaying the number of queries according to the the length of time they took to execute.
This feature is based on Percona's Response Time Distribution.
This shared library actually consists of two different plugins:
QUERY_RESPONSE_TIME
- An INFORMATION_SCHEMA plugin that exposes statistics. QUERY_RESPONSE_TIME_AUDIT
- audit plugin, collects statistics. Both plugins need to be installed to get meaningful statistics.
Although the plugin's shared library is distributed with MariaDB by default, the plugin is not actually installed by MariaDB by default. There are two methods that can be used to install the plugin with MariaDB.
The first method can be used to install the plugin without restarting the server. You can install the plugin dynamically by executing INSTALL SONAME
or INSTALL PLUGIN
. For example:
INSTALL SONAME 'query_response_time';
The second method can be used to tell the server to load the plugin when it starts up. The plugin can be installed this way by providing the --plugin-load
or the --plugin-load-add
options. This can be specified as a command-line argument to mysqld
or it can be specified in a relevant server option group in an option file. For example:
[mariadb] ... plugin_load_add = query_response_time
You can uninstall the plugin dynamically by executing UNINSTALL SONAME
or UNINSTALL PLUGIN
. For example:
UNINSTALL SONAME 'query_response_time';
If you installed the plugin by providing the --plugin-load
or the --plugin-load-add
options in a relevant server option group in an option file, then those options should be removed to prevent the plugin from being loaded the next time the server is restarted.
The user can define time intervals that divide the range 0 to positive infinity into smaller intervals and then collect the number of commands whose execution times fall into each of those intervals.
Each interval is described as:
(range_base ^ n; range_base ^ (n+1)]
The range_base is some positive number (see Limitations). The interval is defined as the difference between two nearby powers of the range base.
For example, if the range base=10, we have the following intervals:
(0; 10 ^ -6], (10 ^ -6; 10 ^ -5], (10 ^ -5; 10 ^ -4], ..., (10 ^ -1; 10 ^1], (10^1; 10^2]...(10^7; positive infinity]
or
(0; 0.000001], (0.000001; 0.000010], (0.000010; 0.000100], ..., (0.100000; 1.0]; (1.0; 10.0]...(1000000; positive infinity]
For each interval, a count is made of the queries with execution times that fell into that interval.
You can select the range of the intervals by changing the range base. For example, for base range=2 we have the following intervals:
(0; 2 ^ -19], (2 ^ -19; 2 ^ -18], (2 ^ -18; 2 ^ -17], ..., (2 ^ -1; 2 ^1], (2 ^ 1; 2 ^ 2]...(2 ^ 25; positive infinity]
or
(0; 0.000001], (0.000001, 0.000003], ..., (0.25; 0.5], (0.5; 2], (2; 4]...(8388608; positive infinity]
Small numbers look strange (i.e., don’t look like powers of 2), because we lose precision on division when the ranges are calculated at runtime. In the resulting table, you look at the high boundary of the range.
For example, you may see:
SELECT * FROM INFORMATION_SCHEMA.QUERY_RESPONSE_TIME; +----------------+-------+----------------+ | TIME | COUNT | TOTAL | +----------------+-------+----------------+ | 0.000001 | 0 | 0.000000 | | 0.000010 | 17 | 0.000094 | | 0.000100 | 4301 0.236555 | | 0.001000 | 1499 | 0.824450 | | 0.010000 | 14851 | 81.680502 | | 0.100000 | 8066 | 443.635693 | | 1.000000 | 0 | 0.000000 | | 10.000000 | 0 | 0.000000 | | 100.000000 | 1 | 55.937094 | | 1000.000000 | 0 | 0.000000 | | 10000.000000 | 0 | 0.000000 | | 100000.000000 | 0 | 0.000000 | | 1000000.000000 | 0 | 0.000000 | | TOO LONG | 0 | TOO LONG | +----------------+-------+----------------+
This means there were:
* 17 queries with 0.000001 < query execution time < = 0.000010 seconds; total execution time of the 17 queries = 0.000094 seconds * 4301 queries with 0.000010 < query execution time < = 0.000100 seconds; total execution time of the 4301 queries = 0.236555 seconds * 1499 queries with 0.000100 < query execution time < = 0.001000 seconds; total execution time of the 1499 queries = 0.824450 seconds * 14851 queries with 0.001000 < query execution time < = 0.010000 seconds; total execution time of the 14851 queries = 81.680502 seconds * 8066 queries with 0.010000 < query execution time < = 0.100000 seconds; total execution time of the 8066 queries = 443.635693 seconds * 1 query with 10.000000 < query execution time < = 100.0000 seconds; total execution time of the 1 query = 55.937094 seconds
You can get the distribution by querying the the QUERY_RESPONSE_TIME
table in the INFORMATION_SCHEMA
database. For example:
SELECT * FROM INFORMATION_SCHEMA.QUERY_RESPONSE_TIME;
You can also write more complex queries. For example:
SELECT c.count, c.time, (SELECT SUM(a.count) FROM INFORMATION_SCHEMA.QUERY_RESPONSE_TIME as a WHERE a.count != 0) as query_count, (SELECT COUNT(*) FROM INFORMATION_SCHEMA.QUERY_RESPONSE_TIME as b WHERE b.count != 0) as not_zero_region_count, (SELECT COUNT(*) FROM INFORMATION_SCHEMA.QUERY_RESPONSE_TIME) as region_count FROM INFORMATION_SCHEMA.QUERY_RESPONSE_TIME as c WHERE c.count > 0;
Note: If query_response_time_stats
is set to ON
, then the execution times for these two SELECT queries will also be collected.
Starting with MariaDB 10.1.1, as an alternative to the QUERY_RESPONSE_TIME
table in the INFORMATION_SCHEMA
database, you can also use the SHOW QUERY_RESPONSE_TIME
statement. For example:
SHOW QUERY_RESPONSE_TIME;
Prior to MariaDB 10.1.1, the SHOW QUERY_RESPONSE_TIME
statement is not supported.
Flushing the plugin data does two things:
QUERY_RESPONSE_TIME
table in the INFORMATION_SCHEMA
database. query_response_time_range_base
and uses it to set the range base for the table. Starting with MariaDB 10.1.1, plugin data can be flushed with the FLUSH QUERY_RESPONSE_TIME
statement. For example:
FLUSH QUERY_RESPONSE_TIME;
Setting the query_response_time_flush
system variable has the same effect. For example:
SET GLOBAL query_response_time_flush=1;
Prior to MariaDB 10.1.1, the FLUSH QUERY_RESPONSE_TIME
statement is not supported. To flush plugin data, set the query_response_time_flush
system variable. For example:
SET GLOBAL query_response_time_flush=1;
Version | Status | Introduced |
---|---|---|
1.0 | Stable | MariaDB 10.1.13 |
1.0 | Gamma | MariaDB 10.0.10 |
1.0 | Alpha | MariaDB 10.0.4 |
query_response_time_flush
boolean
OFF
query_response_time_range_base
QUERY_RESPONSE_TIME
ranges. WARNING: variable change takes affect only after flush. --query-response-time-range-base=#
numeric
10
2
to 1000
query_response_time_exec_time_debug
numeric
0
0
to 31536000
query_response_time_stats
query-response-time-stats[={0|1}]
boolean
OFF
query_response_time
OFF
- Disables the plugin without removing it from the mysql.plugins
table. ON
- Enables the plugin. If the plugin cannot be initialized, then the server will still continue starting up, but the plugin will be disabled. FORCE
- Enables the plugin. If the plugin cannot be initialized, then the server will fail to start with an error. FORCE_PLUS_PERMANENT
- Enables the plugin. If the plugin cannot be initialized, then the server will fail to start with an error. In addition, the plugin cannot be uninstalled with UNINSTALL SONAME
or UNINSTALL PLUGIN
while the server is running. --query-response-time=value
enumerated
ON
OFF
, ON
, FORCE
, FORCE_PLUS_PERMANENT
query_response_time_audit
OFF
- Disables the plugin without removing it from the mysql.plugins
table. ON
- Enables the plugin. If the plugin cannot be initialized, then the server will still continue starting up, but the plugin will be disabled. FORCE
- Enables the plugin. If the plugin cannot be initialized, then the server will fail to start with an error. FORCE_PLUS_PERMANENT
- Enables the plugin. If the plugin cannot be initialized, then the server will fail to start with an error. In addition, the plugin cannot be uninstalled with UNINSTALL SONAME
or UNINSTALL PLUGIN
while the server is running. --query-response-time-audit=value
enumerated
ON
OFF
, ON
, FORCE
, FORCE_PLUS_PERMANENT
© 2019 MariaDB
Licensed under the Creative Commons Attribution 3.0 Unported License and the GNU Free Documentation License.
https://mariadb.com/kb/en/query-response-time-plugin/