Description\n-----------\n\nThe 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.\n\nThe 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 length of time they took to execute.\n\nThis feature is based on Percona's Response Time Distribution.\n\nInstalling the Plugin\n\nThis shared library actually consists of a number of different plugins:\n\n QUERY_RESPONSE_TIME - An INFORMATION_SCHEMA plugin that exposes statistics.\n QUERY_RESPONSE_TIME_AUDIT - audit plugin, collects statistics.\n\nBoth plugins need to be installed to get meaningful statistics.\n\nIn addition, these additional plugins are available:\n\n QUERY_RESPONSE_TIME_READ\n QUERY_RESPONSE_TIME_READ_WRITE\n QUERY_RESPONSE_TIME_WRITE\n\nThis shared library actually consists of a number of different plugins:\n\n QUERY_RESPONSE_TIME - An INFORMATION_SCHEMA plugin that exposes statistics.\n QUERY_RESPONSE_TIME_AUDIT - audit plugin, collects statistics.\n\nBoth plugins need to be installed to get meaningful statistics.\n\nAlthough the plugin's shared library is distributed with MariaDB by default, the plugins are not actually installed by MariaDB by default. There are two methods that can be used to install the plugins with MariaDB.\n\nThe first method can be used to install the plugin library without restarting the server. You can install the plugins dynamically by executing INSTALL SONAME or INSTALL PLUGIN:\n\n``sql\nINSTALL SONAME 'query_response_time';\n`\n\nThe second method can be used to tell the server to load the plugin library when it starts up. The plugins 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:\n\n`ini\n[mariadb]\n...\nplugin_load_add = query_response_time\n`\n\nNote that in both cases you have to activate data collection by changing the query_response_time_stats setting to ON, it is OFF by default even when the plugin library is loaded.\n\nYou can change the setting at runtime with\n\n`sql\nSET GLOBAL query_response_time_stats=ON;\n`\n\nor in the options file after the plugin has been loaded:\n\n`ini\n[mariadb]\n...\nplugin_load_add = query_response_time\nquery_response_time_stats=ON;\n`\n\nUninstalling the Plugin\n\nYou can uninstall the plugin dynamically by executing UNINSTALL SONAME or UNINSTALL PLUGIN:\n\n`sql\nUNINSTALL SONAME 'query_response_time';\n`\n\nIf 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.\n\nResponse Time Distribution\n\nThe 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.\n\nEach interval is described as:\n\n`\n(range_base ^ n; range_base ^ (n+1)]\n`\n\nThe range_base is some positive number (see Limitations). The interval is defined as the difference between two nearby powers of the range base.\n\nIf the range base equals 10, we have the following intervals:\n\n`\n(0; 10 ^ -6], (10 ^ -6; 10 ^ -5], (10 ^ -5; 10 ^ -4], ..., \n  (10 ^ -1; 10 ^1], (10^1; 10^2]...(10^7; positive infinity]\n`\n\nor\n\n`\n(0; 0.000001], (0.000001; 0.000010], (0.000010; 0.000100], ..., \n  (0.100000; 1.0]; (1.0; 10.0]...(1000000; positive infinity]\n`\n\nFor each interval, a count is made of the queries with execution times that fell into that interval.\n\nYou can select the range of the intervals by changing the range base. For example, for base range=2 we have the following intervals:\n\n`\n(0; 2 ^ -19], (2 ^ -19; 2 ^ -18], (2 ^ -18; 2 ^ -17], ..., \n  (2 ^ -1; 2 ^1], (2 ^ 1; 2 ^ 2]...(2 ^ 25; positive infinity]\n`\n\nor\n\n`\n(0; 0.000001], (0.000001, 0.000003], ..., \n  (0.25; 0.5], (0.5; 2], (2; 4]...(8388608; positive infinity]\n`\n\nSmall 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:\n\n`sql\nSELECT  FROM INFORMATION_SCHEMA.QUERY_RESPONSE_TIME;\n+----------------+-------+----------------+\n| TIME           | COUNT | TOTAL          |\n+----------------+-------+----------------+\n|       0.000001 |     0 |       0.000000 |\n|       0.000010 |    17 |       0.000094 |\n|       0.000100 |  4301         0.236555 |\n|       0.001000 |  1499 |       0.824450 |\n|       0.010000 | 14851 |      81.680502 |\n|       0.100000 |  8066 |     443.635693 |\n|       1.000000 |     0 |       0.000000 |\n|      10.000000 |     0 |       0.000000 |\n|     100.000000 |     1 |      55.937094 |\n|    1000.000000 |     0 |       0.000000 |\n|   10000.000000 |     0 |       0.000000 |\n|  100000.000000 |     0 |       0.000000 |\n| 1000000.000000 |     0 |       0.000000 |\n| TOO LONG       |     0 | TOO LONG       |\n+----------------+-------+----------------+\n`\n\nThis means there were:\n\n`\n 17 queries with 0.000001 < query execution time < = 0.000010 seconds; total execution time of the 17 queries = 0.000094 seconds\n\n 4301 queries with 0.000010 < query execution time < = 0.000100 seconds; total execution time of the 4301 queries = 0.236555 seconds\n\n 1499 queries with 0.000100 < query execution time < = 0.001000 seconds; total execution time of the 1499 queries = 0.824450 seconds\n\n 14851 queries with 0.001000 < query execution time < = 0.010000 seconds; total execution time of the 14851 queries = 81.680502 seconds\n\n 8066 queries with 0.010000 < query execution time < = 0.100000 seconds; total execution time of the 8066 queries = 443.635693 seconds\n\n 1 query with 10.000000 < query execution time < = 100.0000 seconds; total execution time of the 1 query = 55.937094 seconds\n`\n\nUsing the Plugin\n\nUsing the Information Schema Table\n\nYou can get the distribution by querying the QUERY_RESPONSE_TIME table in the INFORMATION_SCHEMA database:\n\n`sql\nSELECT  FROM INFORMATION_SCHEMA.QUERY_RESPONSE_TIME;\n`\n\nYou can also write more complex queries:\n\n`sql\nSELECT c.count, c.time,\n(SELECT SUM(a.count) FROM INFORMATION_SCHEMA.QUERY_RESPONSE_TIME AS a \n   WHERE a.count != 0) AS query_count,\n(SELECT COUNT()     FROM INFORMATION_SCHEMA.QUERY_RESPONSE_TIME AS b \n  WHERE b.count != 0) AS not_zero_region_count,\n(SELECT COUNT()     FROM INFORMATION_SCHEMA.QUERY_RESPONSE_TIME) AS region_count\nFROM INFORMATION_SCHEMA.QUERY_RESPONSE_TIME AS c \n  WHERE c.count > 0;\n`\n\nNote: If query_response_time_stats is set to ON, then the execution times for these two SELECT queries will also be collected.\n\nUsing the SHOW Statement\n\nAs an alternative to the QUERY_RESPONSE_TIME table in the INFORMATION_SCHEMA database, you can also use the SHOW QUERY_RESPONSE_TIME statement:\n\n`sql\nSHOW QUERY_RESPONSE_TIME;\n`\n\nFlushing Plugin Data\n\nFlushing the plugin data does two things:\n\n Clears the collected times from the QUERY_RESPONSE_TIME table in the INFORMATION_SCHEMA database.\n Reads the value of query_response_time_range_base and uses it to set the range base for the table.\n\nPlugin data can be flushed with the FLUSH QUERY_RESPONSE_TIME statement:\n\n`sql\nFLUSH QUERY_RESPONSE_TIME;\n`\n\nSetting the query_response_time_flush system variable has the same effect:\n\n`sql\nSET GLOBAL query_response_time_flush=1;\n`\n\nIt is possible to specify flushing read and/or write statements with the FLUSH QUERY_RESPONSE_TIME_READ, FLUSH QUERY_RESPONSE_TIME_WRITE and FLUSH QUERY_RESPONSE_TIME_READ_WRITE statements.\n\nIt is not possible to specify flushing read and/or write statements with the FLUSH QUERY_RESPONSE_TIME_READ, FLUSH QUERY_RESPONSE_TIME_WRITE and FLUSH QUERY_RESPONSE_TIME_READ_WRITE statements.\n\nSystem Variables\n\nquery_response_time_flush\n\n Description: Updating this variable flushes the statistics and re-reads query_response_time_range_base.\n Command line: None\n Scope: Global\n Dynamic: Yes\n Data Type: boolean\n Default Value: OFF\n\nquery_response_time_range_base\n\n Description: Select base of log for QUERY_RESPONSE_TIME ranges. WARNING: variable change takes affect only after flush.\n Command line: --query-response-time-range-base=#\n Scope: Global\n Dynamic: Yes\n Data Type: numeric\n Default Value: 10\n Range: 2 to 1000\n\nquery_response_time_exec_time_debug\n\n Description: Pretend queries take this many microseconds. When 0 (the default) use the actual execution time.\n   This system variable is only available when the plugin is a debug build.\n Scope: Global\n Dynamic: Yes\n Data Type: numeric\n Default Value: 0\n Range: 0 to 31536000\n\nquery_response_time_session_stats\n\n Description: Controls query response time statistics collection for the current session: ON - enable, OFF - disable, GLOBAL (default) - use query_response_time_stats value.\n Command line: query-response-time-session-stats=val]\n Scope: Global, Session\n Dynamic: Yes\n Data Type: enum\n Default Value: GLOBAL\n Valid Values: GLOBAL, ON, OFF\n Introduced: MariaDB 11.5\n\nquery_response_time_stats\n\n Description: Enable or disable query response time statistics collecting.\n Command line: query-response-time-stats[={0|1}]\n Scope: Global\n Dynamic: Yes\n Data Type: boolean\n Default Value: OFF\n\nOptions\n\nquery_response_time\n\n Description: Controls how the server should treat the plugin when the server starts up.\n   Valid values are:\n     OFF - Disables the plugin without removing it from the mysql.plugins table.\n     ON - Enables the plugin. If the plugin cannot be initialized, then the server will still continue starting up, but the plugin will be disabled.\n     FORCE - Enables the plugin. If the plugin cannot be initialized, then the server will fail to start with an error.\n     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.\n   See Plugin Overview: Configuring Plugin Activation at Server Startup for more information.\n Command line: --query-response-time=value\n Data Type: enumerated\n Default Value: ON\n Valid Values: OFF, ON, FORCE, FORCE_PLUS_PERMANENT\n\nquery_response_time_audit\n\n Description: Controls how the server should treat the plugin when the server starts up.\n   Valid values are:\n     OFF - Disables the plugin without removing it from the mysql.plugins table.\n     ON - Enables the plugin. If the plugin cannot be initialized, then the server will still continue starting up, but the plugin will be disabled.\n     FORCE - Enables the plugin. If the plugin cannot be initialized, then the server will fail to start with an error.\n     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.\n   See Plugin Overview: Configuring Plugin Activation at Server Startup for more information.\n Command line: --query-response-time-audit=value\n Data Type: enumerated\n Default Value: ON\n* Valid Values: OFF, ON, FORCE, FORCE_PLUS_PERMANENT`\n\nURL: https://mariadb.com/docs/server/reference/plugins/other-plugins/query-response-time-plugin