mariadb/mysql-test/main/log_slow_innodb.test
Monty 99bd226059 MDEV-31558 Add InnoDB engine information to the slow query log
The new statistics is enabled by adding the "engine", "innodb" or "full"
option to --log-slow-verbosity

Example output:

 # Pages_accessed: 184  Pages_read: 95  Pages_updated: 0  Old_rows_read: 1
 # Pages_read_time: 17.0204  Engine_time: 248.1297

Page_read_time is time doing physical reads inside a storage engine.
(Writes cannot be tracked as these are usually done in the background).
Engine_time is the time spent inside the storage engine for the full
duration of the read/write/update calls. It uses the same code as
'analyze statement' for calculating the time spent.

The engine statistics is done with a generic interface that should be
easy for any engine to use. It can also easily be extended to provide
even more statistics.

Currently only InnoDB has counters for Pages_% and Undo_% status.
Engine_time works for all engines.

Implementation details:

class ha_handler_stats holds all engine stats.  This class is included
in handler and THD classes.
While a query is running, all statistics is updated in the handler. In
close_thread_tables() the statistics is added to the THD.

handler::handler_stats is a pointer to where statistics should be
collected. This is set to point to handler::active_handler_stats if
stats are requested. If not, it is set to 0.
handler_stats has also an element, 'active' that is 1 if stats are
requested. This is to allow engines to avoid doing any 'if's while
updating the statistics.

Cloned or partition tables have the pointer set to the base table if
status are requested.

There is a small performance impact when using --log-slow-verbosity=engine:
- All engine calls in 'select' will be timed.
- IO calls for InnoDB reads will be timed.
- Incrementation of counters are done on local variables and accesses
  are inline, so these should have very little impact.
- Statistics has to be reset for each statement for the THD and each
  used handler. This is only 40 bytes, which should be neglectable.
- For partition tables we have to loop over all partitions to update
  the handler_status as part of table_init(). Can be optimized in the
  future to only do this is log-slow-verbosity changes. For this to work
  we have to update handler_status for all opened partitions and
  also for all partitions opened in the future.

Other things:
- Added options 'engine' and 'full' to log-slow-verbosity.
- Some of the new files in the test suite comes from Percona server, which
  has similar status information.
- buf_page_optimistic_get(): Do not increment any counter, since we are
  only validating a pointer, not performing any buf_pool.page_hash lookup.
- Added THD argument to save_explain_data_intern().
- Switched arguments for save_explain_.*_data() to have
  always THD first (generates better code as other functions also have THD
  first).
2023-07-07 12:53:18 +03:00

75 lines
2.1 KiB
Text

#
# Test the extended slow query log output format for various log_slow_verbosity values.
# Test that InnoDB stats for the extended slow query log are collected.
#
# This test file is based on tests from Percona server
#
--source include/have_innodb.inc
--source include/have_sequence.inc
--source include/log_slow_prepare.inc
# Cannot be used with view protocol as number of temporary tables changes
--source include/no_view_protocol.inc
--let $log_slow_prefix=log_slow_innodb
# Force cold buffer pool
#--let $restart_parameters=--innodb_buffer_pool_load_at_startup=OFF
#--source include/restart_mysqld.inc
CREATE TABLE t1(a INT primary key, b int) ENGINE=InnoDB;
INSERT INTO t1 select seq, seq from seq_1_to_1000;
SET SESSION min_examined_row_limit=0;
SET SESSION long_query_time=0;
#
# Test all enabled options with InnoDB-involving query
#
SET SESSION log_slow_verbosity='innodb,query_plan';
--let log_file=$log_slow_prefix-verbosity_1
--source include/log_slow_start.inc
SELECT sum(a+b) FROM t1;
UPDATE t1 set b=b+1 where a=1 or a=999;
--source include/log_slow_stop.inc
--let log_slow_verbosity_expected_matches= 3
--let log_slow_verbosity_queryplan_matches= 1
--let log_slow_verbosity_innodb_expected_matches= 2
--let log_slow_verbosity_tmptable_expected_matches= 0
--source include/log_slow_grep.inc
#
# Test for "No InnoDB statistics available" in output when InnoDB stats are requested
# but the query does not involve InnoDB tables
#
SET SESSION log_slow_verbosity='innodb,query_plan';
--let log_file=$log_slow_prefix-verbosity_2
--source include/log_slow_start.inc
SELECT 1;
--source include/log_slow_stop.inc
--let log_slow_verbosity_expected_matches= 2
--let log_slow_verbosity_queryplan_matches= 1
--let log_slow_verbosity_innodb_expected_matches= 0
--source include/log_slow_grep.inc
#
# Test 'query_plan'
#
SET SESSION log_slow_verbosity='query_plan';
let log_file=$log_slow_prefix-verbosity_3
--source include/log_slow_start.inc
INSERT INTO t1 VALUE(1000);
--source include/log_slow_stop.inc
--let log_slow_verbosity_innodb_expected_matches= 1
--source include/log_slow_grep.inc
DROP TABLE t1;
--source include/log_slow_cleanup.inc