SlideShare ist ein Scribd-Unternehmen logo
1 von 74
Downloaden Sie, um offline zu lesen
Performance Schema
for MySQL Troubleshooting
April, 20, 2016
Sveta Smirnova
•Overview and Configuration
•Statements
•Memory usage
•Lock diagnostics
•Variables and status
•Connections diagnostic
•Replication
•Server Internals
Table of Contents
2
Overview and Configuration
3
• Version 5.6
• 52 tables
• 554 instruments
• 31 variables
• Version 5.7
• 87 tables
• 1019 instruments
• 42 variables
What is inside?
4
• Which statements are less optimal
• Which operations take most of the time
• Which locks and mutexes taken most often
• What happens inside session
• How much memory is allocated
• Why users cannot connect from a host
• More
What can be found?
5
• ON by default
• Only global, thread, statements and
transactions instrumentation enabled
• All other consumers are disabled
Performance Schema defaults
6
• Memory allocated on demand
• You don’t need to limit size of tables anymore
• Sys schema included into standard MySQL
distribution
• You can turn statistics ON or OFF for
particular host and/or user
• Size of SQL DIGEST is tunable
Configuraiton improvements in 5.7
7
• Use pattern
update performance_schema.setup_consumers set enabled=’yes’ 
where name like ’OUR_REQUIREMENT_%’;
update performance_schema.setup_instruments set enabled=’yes’, 
timed=’yes’ where name like ’OUR_REQUIREMENT_%’;
How to Configure
8
• Use pattern
• Or easier
call sys.ps_setup_enable_consumer(YOUR_CONSUMER);
Requires sys schema
call sys.ps_setup_enable_instrument(YOUR_INSTRUMENT);
Needs separate install before 5.7
How to Configure
8
• Use pattern
• Or easier
• Be careful!
• They are memory and CPU intensive
• Do not turn them all ON until needed
How to Configure
8
Statements
9
• For regular SQL statements
• Prepared statements
• Stored routines
• Stages of statements execution
Statements instrumentation
10
• Why statements are slow?
• Per-query statistics
• Most evolving stages
• What was executed inside stored routine?
What can we discover?
11
• events statements * and
prepared statements instances tables
• Important field names
CREATED TMP DISK TABLES
CREATED TMP TABLES
SELECT FULL JOIN
SELECT RANGE CHECK
SELECT SCAN
SORT MERGE PASSES
SORT SCAN
• Views in sys schema
Why statements are slow?
12
• events statements * and
prepared statements instances tables
• Views in sys schema
• Important view names
statement analysis
statements with full table scans
statements with runtimes in 95th percentile
statements with sorting
statements with temp tables
statements with errors or warnings
Why statements are slow?
12
mysql> SELECT THREAD_ID TID, SUBSTR(SQL_TEXT, 1, 50) SQL_TEXT, ROWS_SENT RS,
-> ROWS_EXAMINED RE,CREATED_TMP_TABLES,NO_INDEX_USED,NO_GOOD_INDEX_USED
-> FROM performance_schema.events_statements_history
-> WHERE NO_INDEX_USED=1 OR NO_GOOD_INDEX_USED=1G
********************** 1. row **********************
TID: 10124
SQL_TEXT: select emp_no, first_name, last_name from employee
RS: 97750
RE: 397774
CREATED_TMP_TABLES: 0
NO_INDEX_USED: 1
NO_GOOD_INDEX_USED: 0
...
Which queries do not use indexes?
13
mysql> SELECT query, total_latency, no_index_used_count, rows_sent,
-> rows_examined
-> FROM sys.statements_with_full_table_scans
-> WHERE db=’employees’ AND query NOT LIKE ’%performance_schema%’G
********************** 1. row **********************
query: SELECT COUNT ( ‘emp_no‘ ) FROM ... ‘emp_no‘ )
WHERE ‘title‘ = ?
total_latency: 805.37 ms
no_index_used_count: 1
rows_sent: 1
rows_examined: 397774
...
Take it easy: Index usage with sys schema
14
mysql> prepare stmt from ’select dept_no, sum(salary) from employees e ...
mysql> set @d1=’d001’, @d2=’d002’, @d3=’d003’, @d4=’d004’;
mysql> execute stmt using @d1, @d2, @d3, @d4;
+---------+-------------+
| dept_no | sum(salary) |
+---------+-------------+
| d001 | 13725425266 |
| d002 | 11650834677 |
| d003 | 9363811425 |
| d004 | 41554438942 |
| d005 | 2494260927 |
...
Prepared statements diagnostics
15
mysql> select * from performance_schema.prepared_statements_instancesG
*************************** 1. row ***************************
OBJECT_INSTANCE_BEGIN: 139956274327632
STATEMENT_ID: 1
STATEMENT_NAME: stmt
SQL_TEXT: select dept_no, sum(salary) from employees e...
OWNER_THREAD_ID: 28
...
COUNT_REPREPARE: 0
COUNT_EXECUTE: 1
...
Prepared statements diagnostics
16
...
SUM_ROWS_SENT: 9
SUM_ROWS_EXAMINED: 2011495
SUM_CREATED_TMP_DISK_TABLES: 0
SUM_CREATED_TMP_TABLES: 1
...
SUM_SELECT_SCAN: 1
...
SUM_SORT_ROWS: 9
SUM_SORT_SCAN: 1
Prepared statements diagnostics
17
• What happens inside a routine
• Queries, called from the routine
• statement/sp/statement
Stored routines instrumentation
18
• We will use this procedure
CREATE DEFINER=‘root‘@‘localhost‘ PROCEDURE ‘sp_test‘(val int)
BEGIN
DECLARE CONTINUE HANDLER FOR 1364, 1048, 1366
BEGIN
INSERT IGNORE INTO t1 VALUES(’Some string’);
GET STACKED DIAGNOSTICS CONDITION 1 @st_state = RETURNED_SQLSTATE;
GET STACKED DIAGNOSTICS CONDITION 1 @stacked_msg = MESSAGE_TEXT;
END;
INSERT INTO t1 VALUES(val);
END
• When HANDLER called?
Stored routines: example
19
mysql> call sp_test(1);
Query OK, 1 row affected (0.07 sec)
mysql> select thread_id, event_name, sql_text from events_statements_history
-> where event_name like ’statement/sp%’;
+-----------+-------------------------+----------------------------+
| thread_id | event_name | sql_text |
+-----------+-------------------------+----------------------------+
| 24 | statement/sp/hpush_jump | NULL |
| 24 | statement/sp/stmt | INSERT INTO t1 VALUES(val) |
| 24 | statement/sp/hpop | NULL |
+-----------+-------------------------+----------------------------+
3 rows in set (0.00 sec)
Correct value
20
mysql> call sp_test(NULL);
Query OK, 1 row affected (0.07 sec)
mysql> select thread_id, event_name, sql_text from events_statements_history
-> where event_name like ’statement/sp%’;
+-----------+-------------------------+--------------------------------------
| thread_id | event_name | sql_text
+-----------+-------------------------+--------------------------------------
| 24 | statement/sp/hpush_jump | NULL
| 24 | statement/sp/stmt | INSERT INTO t1 VALUES(val)
| 24 | statement/sp/stmt | INSERT IGNORE INTO t1 VALUES(’Som...
| 24 | statement/sp/stmt | GET STACKED DIAGNOSTICS CONDITION...
| 24 | statement/sp/stmt | GET STACKED DIAGNOSTICS CONDITION...
| 24 | statement/sp/hreturn | NULL
| 24 | statement/sp/hpop | NULL
HANDLER call
21
• events stages * tables
• Same information as in table
INFORMATION SCHEMA.PROCESSLIST
or SHOW PROCESSLIST output
• init
• executing
• Opening tables
• Replacement for SHOW PROFILE
• Only server-level
• No storage engine information!
Statements deep dive
22
• Everything, related to temporary tables
• EVENT NAME LIKE ’stage/sql/%tmp%’
• Everything, related to locks
• EVENT NAME LIKE ’stage/sql/%lock%’
• Everything in state ”Waiting for”
• EVENT NAME LIKE ’stage/%/Waiting for%’
• Frequently met issues
Stages shortcuts
23
• Everything, related to temporary tables
• Everything, related to locks
• Everything in state ”Waiting for”
• Frequently met issues
• EVENT NAME=’stage/sql/freeing items’
• EVENT NAME=’stage/sql/Sending data’
• EVENT NAME=’stage/sql/cleaning up’
• EVENT NAME=’stage/sql/closing tables’
• EVENT NAME=’stage/sql/end’
Stages shortcuts
23
mysql> SELECT eshl.event_name, sql_text, eshl.timer_wait/1000000000000 w_s
-> FROM performance_schema.events_stages_history_long eshl
-> JOIN performance_schema.events_statements_history_long esthl
-> ON (eshl.nesting_event_id = esthl.event_id)
-> WHERE eshl.timer_wait > 1*10000000000G
*************************** 1. row ***************************
event_name: stage/sql/Sending data
sql_text: SELECT COUNT(emp_no) FROM employees JOIN salaries USING(emp_no)
WHERE hire_date=from_date
w_s: 0.8170
1 row in set (0.00 sec)
Stages example: which stage took critically long time?
24
Memory usage anlysys
25
• Since version 5.7
• Answers on question: where did my
memory go?
• Overall and detailed statistics
Memory instrumentation
26
• Since version 5.7
• Answers on question: where did my
memory go?
• Overall and detailed statistics
• Memory usage per server
mysql> select * from sys.memory_global_total;
+-----------------+
| total_allocated |
+-----------------+
| 319.69 MiB |
+-----------------+
1 row in set (0.05 sec)
Memory instrumentation
26
mysql> select thread_id tid, user, current_allocated ca, total_allocated
-> from sys.memory_by_thread_by_current_bytes;
+----------+--------------------+-------------+-----------------+
| tid | user | ca | total_allocated |
+----------+--------------------+-------------+-----------------+
| 1 | sql/main | 2.53 GiB | 2.69 GiB |
| 150 | root@127.0.0.1 | 4.06 MiB | 32.17 MiB |
| 146 | sql/slave_sql | 1.31 MiB | 1.44 MiB |
| 145 | sql/slave_io | 1.08 MiB | 2.79 MiB |
...
| 4 | innodb/io_log_thread | -2880 bytes | 132.38 KiB |
| 72 | innodb/io_write_thread | -7632 bytes | 1.10 MiB |
+----------+--------------------+-------------+-----------
145 rows in set (2.65 sec)
Detailed Memory Statistics
27
• memory summary by account by event name
• memory summary by host by event name
• memory summary by thread by event name
• memory summary by user by event name
• memory summary global by event name
• sys schema also includes information about
user name
RAW Performance Schema tables
28
• NAME@HOST - regular user
• System users
• sql/main
• innodb/*
• ...
• Data comes from table THREADS
Users in sys.memory * tables
29
Locks diagnostics
30
• Metadata locks
• Table METADATA LOCKS
• Table-level locks
• Table TABLE HANDLES
• Engine-dependent locks, transactions
• Tables EVENTS TRANSACTIONS *
• This is not exactly lock information!
What can block your queries?
31
• Table METADATA LOCKS
• Which thread is waiting for a lock
• Which thread holds the lock
• Not only for tables:
GLOBAL, SCHEMA, TABLE, FUNCTION, PROCEDURE, EVENT, COMMIT, USER LEVEL
LOCK, TABLESPACE
Metadata Locks
32
mysql> select processlist_id, object_type, lock_type, lock_status, source
-> from metadata_locks join threads on (owner_thread_id=thread_id)
-> where object_schema=’employees’ and object_name=’titles’G
*************************** 1. row ***************************
processlist_id: 4
object_type: TABLE
lock_type: EXCLUSIVE
lock_status: PENDING -- waits
source: mdl.cc:3263
*************************** 2. row ***************************
processlist_id: 5
object_type: TABLE
lock_type: SHARED_READ
lock_status: GRANTED -- holds
METADATA LOCKS: example
33
• Table TABLE HANDLES
• Not only locks, but also information about
open tables
• FLUSH TABLES removes data from this table
Table locks
34
mysql> select * from table_handlesG
*************************** 1. row ***************************
OBJECT_TYPE: TABLE
OBJECT_SCHEMA: employees
OBJECT_NAME: titles
OBJECT_INSTANCE_BEGIN: 140663937105248
OWNER_THREAD_ID: 28
OWNER_EVENT_ID: 951
INTERNAL_LOCK: NULL
EXTERNAL_LOCK: READ EXTERNAL - Read lock
(I run LOCK TABLE ... READ)
Table locks: example
35
*************************** 2. row ***************************
OBJECT_TYPE: TABLE
OBJECT_SCHEMA: employees
OBJECT_NAME: emp
OBJECT_INSTANCE_BEGIN: 140663879605856
OWNER_THREAD_ID: 26
OWNER_EVENT_ID: 10419193
INTERNAL_LOCK: WRITE - Table lock for MyISAM table
EXTERNAL_LOCK: WRITE EXTERNAL - Write lock
2 rows in set (0.00 sec)
Table locks: example
36
• Tables EVENTS TRANSACTIONS *
• Transaction information even if engine is not
transactional - One more tool to hunt MDL
• GTIDs
• Background transactions
Transactions at server level
37
mysql> select processlist_ID, STATE, GTID, SOURCE, ACCESS_MODE,
-> ISOLATION_LEVEL, AUTOCOMMIT
-> from events_transactions_current join threads using(thread_id)G
************************ 1. row ************************
processlist_ID: NULL
STATE: COMMITTED
GTID: NULL
SOURCE: handler.cc:1248
ACCESS_MODE: READ WRITE
ISOLATION_LEVEL: REPEATABLE READ
AUTOCOMMIT: YES
...
Background transaction
38
mysql> select processlist_ID, STATE, GTID, SOURCE,
-> ACCESS_MODE, ISOLATION_LEVEL, AUTOCOMMIT
-> from events_transactions_current join threads using(thread_id)G
************************ 2. row ************************
processlist_ID: 4
STATE: COMMITTED
GTID: AUTOMATIC - GTID information here
SOURCE: transaction.cc:150
ACCESS_MODE: READ WRITE
ISOLATION_LEVEL: REPEATABLE READ
AUTOCOMMIT: NO
Transaction in BEGIN ... COMMIT block
39
mysql> select processlist_ID, STATE, GTID, SOURCE,
-> ACCESS_MODE, ISOLATION_LEVEL, AUTOCOMMIT
-> from events_transactions_current join threads using(thread_id)G
************************ 3. row ************************
processlist_ID: 5
STATE: COMMITTED
GTID: NULL
SOURCE: handler.cc:1248
ACCESS_MODE: READ WRITE
ISOLATION_LEVEL: REPEATABLE READ
AUTOCOMMIT: YES
...
Autocommitted transaction
40
Variables and status
41
• Now in Performance Schema
• Global
• Session
• User-defined - First time ever!
• Tables in Information Schema are
deprecated in 5.7
Variables and Status
42
• Variables
• Global
• Session
• By thread
• User variables
• By thread
• Status variables
• Global
• Session
• Account
• Host
• User
• Thread
Groupped by
43
• Variables
mysql> select * from variables_by_thread
-> where variable_name=’tx_isolation’;
+-----------+---------------+-----------------+
| THREAD_ID | VARIABLE_NAME | VARIABLE_VALUE |
+-----------+---------------+-----------------+
| 71 | tx_isolation | REPEATABLE-READ |
| 83 | tx_isolation | REPEATABLE-READ |
| 84 | tx_isolation | SERIALIZABLE |
+-----------+---------------+-----------------+
3 rows in set, 3 warnings (0.00 sec)
• User variables
• Status variables
Variables and status: example
44
• Variables
• User variables
mysql> select * from user_variables_by_thread;
+-----------+---------------+----------------+
| THREAD_ID | VARIABLE_NAME | VARIABLE_VALUE |
+-----------+---------------+----------------+
| 71 | baz | boo |
| 84 | foo | bar |
+-----------+---------------+----------------+
2 rows in set (0.00 sec)
• Status variables
Variables and status: example
44
• Variables
• User variables
• Status variables
mysql> select * from status_by_thread
-> where variable_name=’Handler_write’;
+-----------+---------------+----------------+
| THREAD_ID | VARIABLE_NAME | VARIABLE_VALUE |
+-----------+---------------+----------------+
| 71 | Handler_write | 94 |
| 83 | Handler_write | 477 | -- Most writes
| 84 | Handler_write | 101 |
+-----------+---------------+----------------+
3 rows in set (0.00 sec)
Variables and status: example
44
Connections diagnostic
45
• Tables accounts, users, hosts
mysql> select user, host, current_connections as cur,
-> total_connections as total from accounts;
+------+-----------+-----+-------+
| user | host | cur | total |
+------+-----------+-----+-------+
| foo | localhost | 0 | 3 |
| root | localhost | 1 | 3 |
| NULL | NULL | 14 | 17 |
+------+-----------+-----+-------+
3 rows in set (0.01 sec)
• Connection attributes
Connection diagnostic
46
• Connection attributes
mysql> SELECT ATTR_NAME, ATTR_VALUE FROM session_account_connect_attrs
-> WHERE processlist_id != @@pseudo_thread_id;
+-----------------+--------------------------+
| ATTR_NAME | ATTR_VALUE |
+-----------------+--------------------------+
| _os | Linux |
| _client_name | libmysql |
| _pid | 4729 |
| program_name | PLMCE-2016 |
| _platform | x86_64 |
| session | MySQL Performance Schema |
| author | Sveta Smirnova |
| _client_version | 5.7.11 |
Connection diagnostic
46
• Content of DNS cache
• Errors from:
• Name Server
• Connection
• Authentication
• max connect errors, max user errors, etc.
• Your first assistant in case of connection
issue
Host Cache
47
Replication
48
• Data from SHOW SLAVE STATUS available
in replication * tables
• Not full replacement
• Binary, relay log names and positions are in
mysql.slave * tables
• GTID information for single-threaded slave
missed is in gtid executed variable
• Support of Replication Channels
(Multi-threaded slave)
• GTID instrumentation
Replication diagnostics
49
• No need to parse SHOW output
• Configuration
• IO thread
• SQL thread
SLAVE STATUS
50
• No need to parse SHOW output
• Configuration
• replication connection configuration
• replication applier configuration
• IO thread
• SQL thread
SLAVE STATUS
50
• No need to parse SHOW output
• Configuration
• IO thread
• replication connection status
• SQL thread
SLAVE STATUS
50
• No need to parse SHOW output
• Configuration
• IO thread
• SQL thread
• replication applier status
• replication applier status by coordinator
• replication applier status by worker - MTS only
SLAVE STATUS
50
• Configuration
mysql> select * from replication_connection_configuration
-> join replication_applier_configuration using(channel_name)G
*************************** 1. row ***************************
CHANNEL_NAME:
HOST: 127.0.0.1
PORT: 13000
USER: root
NETWORK_INTERFACE:
AUTO_POSITION: 1
SSL_ALLOWED: NO
SSL_CA_FILE:
...
SLAVE STATUS
51
• Configuration
...
CONNECTION_RETRY_INTERVAL: 60
CONNECTION_RETRY_COUNT: 10
HEARTBEAT_INTERVAL: 60.000
CHANNEL_NAME:
DESIRED_DELAY: 0
1 row in set (0.00 sec)
SLAVE STATUS
52
• State of IO Thread
mysql> select * from replication_connection_statusG
*************************** 1. row ***************************
CHANNEL_NAME:
GROUP_NAME:
SOURCE_UUID: d0753e78-14ec-11e5-b3fb-28b2bd7442fd
THREAD_ID: 21
SERVICE_STATE: ON
COUNT_RECEIVED_HEARTBEATS: 17
LAST_HEARTBEAT_TIMESTAMP: 2015-06-17 15:49:08
RECEIVED_TRANSACTION_SET:
LAST_ERROR_NUMBER: 0
LAST_ERROR_MESSAGE:
LAST_ERROR_TIMESTAMP: 0000-00-00 00:00:00
SLAVE STATUS
53
• State of SQL Thread
mysql> select * from replication_applier_status join
-> replication_applier_status_by_coordinator using(channel_name)G
*************************** 1. row ***************************
CHANNEL_NAME:
SERVICE_STATE: ON
REMAINING_DELAY: NULL
COUNT_TRANSACTIONS_RETRIES: 0
THREAD_ID: 22
SERVICE_STATE: ON
LAST_ERROR_NUMBER: 0
LAST_ERROR_MESSAGE:
LAST_ERROR_TIMESTAMP: 0000-00-00 00:00:00
1 row in set (0.00 sec)
SLAVE STATUS
54
Server Internals
55
• EVENTS WAITS * tables
• EVENT NAME
wait/synch/rwlock/innodb/dict operation lock
• SOURCE
Line of the source code
• OPERATION
Kind of operation: read, lock, write
Server Internals
56
• wait/lock - Metadata and table locks
• wait/synch/cond - InnoDB, MyISAM, sql
• wait/synch/mutex - sql, mysys, engines
• wait/synch/rwlock - sql, InnoDB, MyISAM
• wait/synch/sxlock - InnoDB global locks
• wait/io/file - Operations with files
• wait/io/socket
• wait/io/table/sql/handler
Which kind of events can we examine?
57
• file instances - Opened files
• socket instances - Connections
• cond instances
• rwlock instances
select * from rwlock_instances where READ_LOCKED_BY_COUNT > 0;
select * from rwlock_instances where WRITE_LOCKED_BY_THREAD_ID > 0;
• mutex instances -
LOCKED BY THREAD ID
* INSTANCES tables
58
• Tables in sys schema
• io *
• host summary *
• user summary *
• waits *
• Digests events waits summary *
Diagnostic sugar
59
• Tables in sys schema
• Digests events waits summary *
• *by account by event name
• *by host by event name
• *by instance
• *by thread by event name
• *by user by event name
• *by event name
Diagnostic sugar
59
• Blog of developers team
• Blog of Mark Leith: author of sys schema
• Official reference manual
More informaiton
60
???
Place for your questions
61
http://www.slideshare.net/SvetaSmirnova
https://twitter.com/svetsmirnova
Thank you!
62

Weitere ähnliche Inhalte

Was ist angesagt?

UKOUG 2011: Practical MySQL Tuning
UKOUG 2011: Practical MySQL TuningUKOUG 2011: Practical MySQL Tuning
UKOUG 2011: Practical MySQL Tuning
FromDual GmbH
 
MySQL/MariaDB query optimizer tuning tutorial from Percona Live 2013
MySQL/MariaDB query optimizer tuning tutorial from Percona Live 2013MySQL/MariaDB query optimizer tuning tutorial from Percona Live 2013
MySQL/MariaDB query optimizer tuning tutorial from Percona Live 2013
Sergey Petrunya
 
MySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossukMySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossuk
Valeriy Kravchuk
 

Was ist angesagt? (20)

Troubleshooting MySQL Performance
Troubleshooting MySQL PerformanceTroubleshooting MySQL Performance
Troubleshooting MySQL Performance
 
Performance Schema for MySQL Troubleshooting
 Performance Schema for MySQL Troubleshooting Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL Troubleshooting
 
Troubleshooting MySQL Performance
Troubleshooting MySQL PerformanceTroubleshooting MySQL Performance
Troubleshooting MySQL Performance
 
Basic MySQL Troubleshooting for Oracle DBAs
Basic MySQL Troubleshooting for Oracle DBAsBasic MySQL Troubleshooting for Oracle DBAs
Basic MySQL Troubleshooting for Oracle DBAs
 
MySQL Performance Schema in Action
MySQL Performance Schema in ActionMySQL Performance Schema in Action
MySQL Performance Schema in Action
 
Preparse Query Rewrite Plugins
Preparse Query Rewrite PluginsPreparse Query Rewrite Plugins
Preparse Query Rewrite Plugins
 
UKOUG 2011: Practical MySQL Tuning
UKOUG 2011: Practical MySQL TuningUKOUG 2011: Practical MySQL Tuning
UKOUG 2011: Practical MySQL Tuning
 
Full Table Scan: friend or foe
Full Table Scan: friend or foeFull Table Scan: friend or foe
Full Table Scan: friend or foe
 
SQL Tuning, takes 3 to tango
SQL Tuning, takes 3 to tangoSQL Tuning, takes 3 to tango
SQL Tuning, takes 3 to tango
 
Performance Schema for MySQL troubleshooting
Performance Schema for MySQL troubleshootingPerformance Schema for MySQL troubleshooting
Performance Schema for MySQL troubleshooting
 
New features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in actionNew features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in action
 
MySQL/MariaDB query optimizer tuning tutorial from Percona Live 2013
MySQL/MariaDB query optimizer tuning tutorial from Percona Live 2013MySQL/MariaDB query optimizer tuning tutorial from Percona Live 2013
MySQL/MariaDB query optimizer tuning tutorial from Percona Live 2013
 
MySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossukMySQL Performance schema missing_manual_flossuk
MySQL Performance schema missing_manual_flossuk
 
Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingPerformance Schema for MySQL Troubleshooting
Performance Schema for MySQL Troubleshooting
 
Noinject
NoinjectNoinject
Noinject
 
Adapting to Adaptive Plans on 12c
Adapting to Adaptive Plans on 12cAdapting to Adaptive Plans on 12c
Adapting to Adaptive Plans on 12c
 
Introduction to MySQL Query Tuning for Dev[Op]s
Introduction to MySQL Query Tuning for Dev[Op]sIntroduction to MySQL Query Tuning for Dev[Op]s
Introduction to MySQL Query Tuning for Dev[Op]s
 
Histograms in 12c era
Histograms in 12c eraHistograms in 12c era
Histograms in 12c era
 
Introduction into MySQL Query Tuning
Introduction into MySQL Query TuningIntroduction into MySQL Query Tuning
Introduction into MySQL Query Tuning
 
SQL Plan Directives explained
SQL Plan Directives explainedSQL Plan Directives explained
SQL Plan Directives explained
 

Andere mochten auch

2.medical missionary and the final crisis
2.medical missionary and the final crisis2.medical missionary and the final crisis
2.medical missionary and the final crisis
Antonio Bernard
 
1.medical missionary and the final crisis
1.medical missionary and the final crisis1.medical missionary and the final crisis
1.medical missionary and the final crisis
Antonio Bernard
 
Performance Schema in MySQL (Danil Zburivsky)
Performance Schema in MySQL (Danil Zburivsky)Performance Schema in MySQL (Danil Zburivsky)
Performance Schema in MySQL (Danil Zburivsky)
Ontico
 

Andere mochten auch (20)

Using Apache Spark and MySQL for Data Analysis
Using Apache Spark and MySQL for Data AnalysisUsing Apache Spark and MySQL for Data Analysis
Using Apache Spark and MySQL for Data Analysis
 
FOSDEM 2015: gdb tips and tricks for MySQL DBAs
FOSDEM 2015: gdb tips and tricks for MySQL DBAsFOSDEM 2015: gdb tips and tricks for MySQL DBAs
FOSDEM 2015: gdb tips and tricks for MySQL DBAs
 
MySQL 5.5 Guide to InnoDB Status
MySQL 5.5 Guide to InnoDB StatusMySQL 5.5 Guide to InnoDB Status
MySQL 5.5 Guide to InnoDB Status
 
OpenSource SQL Databases Enter Millions Queries per Second Era
OpenSource SQL Databases Enter Millions Queries per Second EraOpenSource SQL Databases Enter Millions Queries per Second Era
OpenSource SQL Databases Enter Millions Queries per Second Era
 
WiredTiger In-Memory vs WiredTiger B-Tree
WiredTiger In-Memory vs WiredTiger B-TreeWiredTiger In-Memory vs WiredTiger B-Tree
WiredTiger In-Memory vs WiredTiger B-Tree
 
Эффективная отладка репликации MySQL
Эффективная отладка репликации MySQLЭффективная отладка репликации MySQL
Эффективная отладка репликации MySQL
 
Open Source SQL databases enters millions queries per second era
Open Source SQL databases enters millions queries per second eraOpen Source SQL databases enters millions queries per second era
Open Source SQL databases enters millions queries per second era
 
Жизнь, удивительные приключения и смерть бага MySQL
Жизнь, удивительные приключения и смерть бага MySQLЖизнь, удивительные приключения и смерть бага MySQL
Жизнь, удивительные приключения и смерть бага MySQL
 
Отладка производительности СУБД MySQL
Отладка производительности СУБД MySQLОтладка производительности СУБД MySQL
Отладка производительности СУБД MySQL
 
2.medical missionary and the final crisis
2.medical missionary and the final crisis2.medical missionary and the final crisis
2.medical missionary and the final crisis
 
Performance Schema and Sys Schema in MySQL 5.7
Performance Schema and Sys Schema in MySQL 5.7Performance Schema and Sys Schema in MySQL 5.7
Performance Schema and Sys Schema in MySQL 5.7
 
1.medical missionary and the final crisis
1.medical missionary and the final crisis1.medical missionary and the final crisis
1.medical missionary and the final crisis
 
MySQL Replication Troubleshooting for Oracle DBAs
MySQL Replication Troubleshooting for Oracle DBAsMySQL Replication Troubleshooting for Oracle DBAs
MySQL Replication Troubleshooting for Oracle DBAs
 
MySQL Troubleshooting with the Performance Schema
MySQL Troubleshooting with the Performance SchemaMySQL Troubleshooting with the Performance Schema
MySQL Troubleshooting with the Performance Schema
 
The MySQL Performance Schema & New SYS Schema
The MySQL Performance Schema & New SYS SchemaThe MySQL Performance Schema & New SYS Schema
The MySQL Performance Schema & New SYS Schema
 
MySQL Performance - SydPHP October 2011
MySQL Performance - SydPHP October 2011MySQL Performance - SydPHP October 2011
MySQL Performance - SydPHP October 2011
 
Performance Schema in MySQL (Danil Zburivsky)
Performance Schema in MySQL (Danil Zburivsky)Performance Schema in MySQL (Danil Zburivsky)
Performance Schema in MySQL (Danil Zburivsky)
 
MySQL Oslayer performace optimization
MySQL  Oslayer performace optimizationMySQL  Oslayer performace optimization
MySQL Oslayer performace optimization
 
An Overview to MySQL SYS Schema
An Overview to MySQL SYS Schema An Overview to MySQL SYS Schema
An Overview to MySQL SYS Schema
 
MySQL Monitoring Mechanisms
MySQL Monitoring MechanismsMySQL Monitoring Mechanisms
MySQL Monitoring Mechanisms
 

Ähnlich wie Performance Schema for MySQL Troubleshooting

MySQL Performance Schema in 20 Minutes
 MySQL Performance Schema in 20 Minutes MySQL Performance Schema in 20 Minutes
MySQL Performance Schema in 20 Minutes
Sveta Smirnova
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
Roland Bouman
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
Roland Bouman
 
Applied Partitioning And Scaling Your Database System Presentation
Applied Partitioning And Scaling Your Database System PresentationApplied Partitioning And Scaling Your Database System Presentation
Applied Partitioning And Scaling Your Database System Presentation
Richard Crowley
 
Writing efficient sql
Writing efficient sqlWriting efficient sql
Writing efficient sql
j9soto
 
Highload Perf Tuning
Highload Perf TuningHighload Perf Tuning
Highload Perf Tuning
HighLoad2009
 

Ähnlich wie Performance Schema for MySQL Troubleshooting (20)

MySQL Performance Schema in 20 Minutes
 MySQL Performance Schema in 20 Minutes MySQL Performance Schema in 20 Minutes
MySQL Performance Schema in 20 Minutes
 
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
 
Performance schema and sys schema
Performance schema and sys schemaPerformance schema and sys schema
Performance schema and sys schema
 
Query Optimization with MySQL 5.6: Old and New Tricks
Query Optimization with MySQL 5.6: Old and New TricksQuery Optimization with MySQL 5.6: Old and New Tricks
Query Optimization with MySQL 5.6: Old and New Tricks
 
MySQL Performance Schema in Action
MySQL Performance Schema in ActionMySQL Performance Schema in Action
MySQL Performance Schema in Action
 
Advanced Query Optimizer Tuning and Analysis
Advanced Query Optimizer Tuning and AnalysisAdvanced Query Optimizer Tuning and Analysis
Advanced Query Optimizer Tuning and Analysis
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
 
Mysql tracing
Mysql tracingMysql tracing
Mysql tracing
 
Mysql tracing
Mysql tracingMysql tracing
Mysql tracing
 
MySQL Performance Schema in Action: the Complete Tutorial
MySQL Performance Schema in Action: the Complete TutorialMySQL Performance Schema in Action: the Complete Tutorial
MySQL Performance Schema in Action: the Complete Tutorial
 
sveta smirnova - my sql performance schema in action
sveta smirnova - my sql performance schema in actionsveta smirnova - my sql performance schema in action
sveta smirnova - my sql performance schema in action
 
Performance Schema in Action: demo
Performance Schema in Action: demoPerformance Schema in Action: demo
Performance Schema in Action: demo
 
Perf Tuning Short
Perf Tuning ShortPerf Tuning Short
Perf Tuning Short
 
16 MySQL Optimization #burningkeyboards
16 MySQL Optimization #burningkeyboards16 MySQL Optimization #burningkeyboards
16 MySQL Optimization #burningkeyboards
 
Applied Partitioning And Scaling Your Database System Presentation
Applied Partitioning And Scaling Your Database System PresentationApplied Partitioning And Scaling Your Database System Presentation
Applied Partitioning And Scaling Your Database System Presentation
 
MySQL sys schema deep dive
MySQL sys schema deep diveMySQL sys schema deep dive
MySQL sys schema deep dive
 
Tek tutorial
Tek tutorialTek tutorial
Tek tutorial
 
Writing efficient sql
Writing efficient sqlWriting efficient sql
Writing efficient sql
 
Highload Perf Tuning
Highload Perf TuningHighload Perf Tuning
Highload Perf Tuning
 

Mehr von Sveta Smirnova

MySQL Test Framework для поддержки клиентов и верификации багов
MySQL Test Framework для поддержки клиентов и верификации баговMySQL Test Framework для поддержки клиентов и верификации багов
MySQL Test Framework для поддержки клиентов и верификации багов
Sveta Smirnova
 
How to Avoid Pitfalls in Schema Upgrade with Percona XtraDB Cluster
How to Avoid Pitfalls in Schema Upgrade with Percona XtraDB ClusterHow to Avoid Pitfalls in Schema Upgrade with Percona XtraDB Cluster
How to Avoid Pitfalls in Schema Upgrade with Percona XtraDB Cluster
Sveta Smirnova
 
Современному хайлоду - современные решения: MySQL 8.0 и улучшения Percona
Современному хайлоду - современные решения: MySQL 8.0 и улучшения PerconaСовременному хайлоду - современные решения: MySQL 8.0 и улучшения Percona
Современному хайлоду - современные решения: MySQL 8.0 и улучшения Percona
Sveta Smirnova
 

Mehr von Sveta Smirnova (20)

MySQL 2024: Зачем переходить на MySQL 8, если в 5.х всё устраивает?
MySQL 2024: Зачем переходить на MySQL 8, если в 5.х всё устраивает?MySQL 2024: Зачем переходить на MySQL 8, если в 5.х всё устраивает?
MySQL 2024: Зачем переходить на MySQL 8, если в 5.х всё устраивает?
 
Database in Kubernetes: Diagnostics and Monitoring
Database in Kubernetes: Diagnostics and MonitoringDatabase in Kubernetes: Diagnostics and Monitoring
Database in Kubernetes: Diagnostics and Monitoring
 
MySQL Database Monitoring: Must, Good and Nice to Have
MySQL Database Monitoring: Must, Good and Nice to HaveMySQL Database Monitoring: Must, Good and Nice to Have
MySQL Database Monitoring: Must, Good and Nice to Have
 
MySQL Cookbook: Recipes for Developers
MySQL Cookbook: Recipes for DevelopersMySQL Cookbook: Recipes for Developers
MySQL Cookbook: Recipes for Developers
 
MySQL Performance for DevOps
MySQL Performance for DevOpsMySQL Performance for DevOps
MySQL Performance for DevOps
 
MySQL Test Framework для поддержки клиентов и верификации багов
MySQL Test Framework для поддержки клиентов и верификации баговMySQL Test Framework для поддержки клиентов и верификации багов
MySQL Test Framework для поддержки клиентов и верификации багов
 
MySQL Cookbook: Recipes for Your Business
MySQL Cookbook: Recipes for Your BusinessMySQL Cookbook: Recipes for Your Business
MySQL Cookbook: Recipes for Your Business
 
Introduction into MySQL Query Tuning for Dev[Op]s
Introduction into MySQL Query Tuning for Dev[Op]sIntroduction into MySQL Query Tuning for Dev[Op]s
Introduction into MySQL Query Tuning for Dev[Op]s
 
Производительность MySQL для DevOps
 Производительность MySQL для DevOps Производительность MySQL для DevOps
Производительность MySQL для DevOps
 
MySQL Performance for DevOps
MySQL Performance for DevOpsMySQL Performance for DevOps
MySQL Performance for DevOps
 
How to Avoid Pitfalls in Schema Upgrade with Percona XtraDB Cluster
How to Avoid Pitfalls in Schema Upgrade with Percona XtraDB ClusterHow to Avoid Pitfalls in Schema Upgrade with Percona XtraDB Cluster
How to Avoid Pitfalls in Schema Upgrade with Percona XtraDB Cluster
 
How to migrate from MySQL to MariaDB without tears
How to migrate from MySQL to MariaDB without tearsHow to migrate from MySQL to MariaDB without tears
How to migrate from MySQL to MariaDB without tears
 
Modern solutions for modern database load: improvements in the latest MariaDB...
Modern solutions for modern database load: improvements in the latest MariaDB...Modern solutions for modern database load: improvements in the latest MariaDB...
Modern solutions for modern database load: improvements in the latest MariaDB...
 
How Safe is Asynchronous Master-Master Setup?
How Safe is Asynchronous Master-Master Setup?How Safe is Asynchronous Master-Master Setup?
How Safe is Asynchronous Master-Master Setup?
 
Современному хайлоду - современные решения: MySQL 8.0 и улучшения Percona
Современному хайлоду - современные решения: MySQL 8.0 и улучшения PerconaСовременному хайлоду - современные решения: MySQL 8.0 и улучшения Percona
Современному хайлоду - современные решения: MySQL 8.0 и улучшения Percona
 
How to Avoid Pitfalls in Schema Upgrade with Galera
How to Avoid Pitfalls in Schema Upgrade with GaleraHow to Avoid Pitfalls in Schema Upgrade with Galera
How to Avoid Pitfalls in Schema Upgrade with Galera
 
How Safe is Asynchronous Master-Master Setup?
 How Safe is Asynchronous Master-Master Setup? How Safe is Asynchronous Master-Master Setup?
How Safe is Asynchronous Master-Master Setup?
 
Billion Goods in Few Categories: How Histograms Save a Life?
Billion Goods in Few Categories: How Histograms Save a Life?Billion Goods in Few Categories: How Histograms Save a Life?
Billion Goods in Few Categories: How Histograms Save a Life?
 
A Billion Goods in a Few Categories: When Optimizer Histograms Help and When ...
A Billion Goods in a Few Categories: When Optimizer Histograms Help and When ...A Billion Goods in a Few Categories: When Optimizer Histograms Help and When ...
A Billion Goods in a Few Categories: When Optimizer Histograms Help and When ...
 
Что нужно знать о трёх топовых фичах MySQL
Что нужно знать  о трёх топовых фичах  MySQLЧто нужно знать  о трёх топовых фичах  MySQL
Что нужно знать о трёх топовых фичах MySQL
 

Kürzlich hochgeladen

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Kürzlich hochgeladen (20)

8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 

Performance Schema for MySQL Troubleshooting

  • 1. Performance Schema for MySQL Troubleshooting April, 20, 2016 Sveta Smirnova
  • 2. •Overview and Configuration •Statements •Memory usage •Lock diagnostics •Variables and status •Connections diagnostic •Replication •Server Internals Table of Contents 2
  • 4. • Version 5.6 • 52 tables • 554 instruments • 31 variables • Version 5.7 • 87 tables • 1019 instruments • 42 variables What is inside? 4
  • 5. • Which statements are less optimal • Which operations take most of the time • Which locks and mutexes taken most often • What happens inside session • How much memory is allocated • Why users cannot connect from a host • More What can be found? 5
  • 6. • ON by default • Only global, thread, statements and transactions instrumentation enabled • All other consumers are disabled Performance Schema defaults 6
  • 7. • Memory allocated on demand • You don’t need to limit size of tables anymore • Sys schema included into standard MySQL distribution • You can turn statistics ON or OFF for particular host and/or user • Size of SQL DIGEST is tunable Configuraiton improvements in 5.7 7
  • 8. • Use pattern update performance_schema.setup_consumers set enabled=’yes’ where name like ’OUR_REQUIREMENT_%’; update performance_schema.setup_instruments set enabled=’yes’, timed=’yes’ where name like ’OUR_REQUIREMENT_%’; How to Configure 8
  • 9. • Use pattern • Or easier call sys.ps_setup_enable_consumer(YOUR_CONSUMER); Requires sys schema call sys.ps_setup_enable_instrument(YOUR_INSTRUMENT); Needs separate install before 5.7 How to Configure 8
  • 10. • Use pattern • Or easier • Be careful! • They are memory and CPU intensive • Do not turn them all ON until needed How to Configure 8
  • 12. • For regular SQL statements • Prepared statements • Stored routines • Stages of statements execution Statements instrumentation 10
  • 13. • Why statements are slow? • Per-query statistics • Most evolving stages • What was executed inside stored routine? What can we discover? 11
  • 14. • events statements * and prepared statements instances tables • Important field names CREATED TMP DISK TABLES CREATED TMP TABLES SELECT FULL JOIN SELECT RANGE CHECK SELECT SCAN SORT MERGE PASSES SORT SCAN • Views in sys schema Why statements are slow? 12
  • 15. • events statements * and prepared statements instances tables • Views in sys schema • Important view names statement analysis statements with full table scans statements with runtimes in 95th percentile statements with sorting statements with temp tables statements with errors or warnings Why statements are slow? 12
  • 16. mysql> SELECT THREAD_ID TID, SUBSTR(SQL_TEXT, 1, 50) SQL_TEXT, ROWS_SENT RS, -> ROWS_EXAMINED RE,CREATED_TMP_TABLES,NO_INDEX_USED,NO_GOOD_INDEX_USED -> FROM performance_schema.events_statements_history -> WHERE NO_INDEX_USED=1 OR NO_GOOD_INDEX_USED=1G ********************** 1. row ********************** TID: 10124 SQL_TEXT: select emp_no, first_name, last_name from employee RS: 97750 RE: 397774 CREATED_TMP_TABLES: 0 NO_INDEX_USED: 1 NO_GOOD_INDEX_USED: 0 ... Which queries do not use indexes? 13
  • 17. mysql> SELECT query, total_latency, no_index_used_count, rows_sent, -> rows_examined -> FROM sys.statements_with_full_table_scans -> WHERE db=’employees’ AND query NOT LIKE ’%performance_schema%’G ********************** 1. row ********************** query: SELECT COUNT ( ‘emp_no‘ ) FROM ... ‘emp_no‘ ) WHERE ‘title‘ = ? total_latency: 805.37 ms no_index_used_count: 1 rows_sent: 1 rows_examined: 397774 ... Take it easy: Index usage with sys schema 14
  • 18. mysql> prepare stmt from ’select dept_no, sum(salary) from employees e ... mysql> set @d1=’d001’, @d2=’d002’, @d3=’d003’, @d4=’d004’; mysql> execute stmt using @d1, @d2, @d3, @d4; +---------+-------------+ | dept_no | sum(salary) | +---------+-------------+ | d001 | 13725425266 | | d002 | 11650834677 | | d003 | 9363811425 | | d004 | 41554438942 | | d005 | 2494260927 | ... Prepared statements diagnostics 15
  • 19. mysql> select * from performance_schema.prepared_statements_instancesG *************************** 1. row *************************** OBJECT_INSTANCE_BEGIN: 139956274327632 STATEMENT_ID: 1 STATEMENT_NAME: stmt SQL_TEXT: select dept_no, sum(salary) from employees e... OWNER_THREAD_ID: 28 ... COUNT_REPREPARE: 0 COUNT_EXECUTE: 1 ... Prepared statements diagnostics 16
  • 20. ... SUM_ROWS_SENT: 9 SUM_ROWS_EXAMINED: 2011495 SUM_CREATED_TMP_DISK_TABLES: 0 SUM_CREATED_TMP_TABLES: 1 ... SUM_SELECT_SCAN: 1 ... SUM_SORT_ROWS: 9 SUM_SORT_SCAN: 1 Prepared statements diagnostics 17
  • 21. • What happens inside a routine • Queries, called from the routine • statement/sp/statement Stored routines instrumentation 18
  • 22. • We will use this procedure CREATE DEFINER=‘root‘@‘localhost‘ PROCEDURE ‘sp_test‘(val int) BEGIN DECLARE CONTINUE HANDLER FOR 1364, 1048, 1366 BEGIN INSERT IGNORE INTO t1 VALUES(’Some string’); GET STACKED DIAGNOSTICS CONDITION 1 @st_state = RETURNED_SQLSTATE; GET STACKED DIAGNOSTICS CONDITION 1 @stacked_msg = MESSAGE_TEXT; END; INSERT INTO t1 VALUES(val); END • When HANDLER called? Stored routines: example 19
  • 23. mysql> call sp_test(1); Query OK, 1 row affected (0.07 sec) mysql> select thread_id, event_name, sql_text from events_statements_history -> where event_name like ’statement/sp%’; +-----------+-------------------------+----------------------------+ | thread_id | event_name | sql_text | +-----------+-------------------------+----------------------------+ | 24 | statement/sp/hpush_jump | NULL | | 24 | statement/sp/stmt | INSERT INTO t1 VALUES(val) | | 24 | statement/sp/hpop | NULL | +-----------+-------------------------+----------------------------+ 3 rows in set (0.00 sec) Correct value 20
  • 24. mysql> call sp_test(NULL); Query OK, 1 row affected (0.07 sec) mysql> select thread_id, event_name, sql_text from events_statements_history -> where event_name like ’statement/sp%’; +-----------+-------------------------+-------------------------------------- | thread_id | event_name | sql_text +-----------+-------------------------+-------------------------------------- | 24 | statement/sp/hpush_jump | NULL | 24 | statement/sp/stmt | INSERT INTO t1 VALUES(val) | 24 | statement/sp/stmt | INSERT IGNORE INTO t1 VALUES(’Som... | 24 | statement/sp/stmt | GET STACKED DIAGNOSTICS CONDITION... | 24 | statement/sp/stmt | GET STACKED DIAGNOSTICS CONDITION... | 24 | statement/sp/hreturn | NULL | 24 | statement/sp/hpop | NULL HANDLER call 21
  • 25. • events stages * tables • Same information as in table INFORMATION SCHEMA.PROCESSLIST or SHOW PROCESSLIST output • init • executing • Opening tables • Replacement for SHOW PROFILE • Only server-level • No storage engine information! Statements deep dive 22
  • 26. • Everything, related to temporary tables • EVENT NAME LIKE ’stage/sql/%tmp%’ • Everything, related to locks • EVENT NAME LIKE ’stage/sql/%lock%’ • Everything in state ”Waiting for” • EVENT NAME LIKE ’stage/%/Waiting for%’ • Frequently met issues Stages shortcuts 23
  • 27. • Everything, related to temporary tables • Everything, related to locks • Everything in state ”Waiting for” • Frequently met issues • EVENT NAME=’stage/sql/freeing items’ • EVENT NAME=’stage/sql/Sending data’ • EVENT NAME=’stage/sql/cleaning up’ • EVENT NAME=’stage/sql/closing tables’ • EVENT NAME=’stage/sql/end’ Stages shortcuts 23
  • 28. mysql> SELECT eshl.event_name, sql_text, eshl.timer_wait/1000000000000 w_s -> FROM performance_schema.events_stages_history_long eshl -> JOIN performance_schema.events_statements_history_long esthl -> ON (eshl.nesting_event_id = esthl.event_id) -> WHERE eshl.timer_wait > 1*10000000000G *************************** 1. row *************************** event_name: stage/sql/Sending data sql_text: SELECT COUNT(emp_no) FROM employees JOIN salaries USING(emp_no) WHERE hire_date=from_date w_s: 0.8170 1 row in set (0.00 sec) Stages example: which stage took critically long time? 24
  • 30. • Since version 5.7 • Answers on question: where did my memory go? • Overall and detailed statistics Memory instrumentation 26
  • 31. • Since version 5.7 • Answers on question: where did my memory go? • Overall and detailed statistics • Memory usage per server mysql> select * from sys.memory_global_total; +-----------------+ | total_allocated | +-----------------+ | 319.69 MiB | +-----------------+ 1 row in set (0.05 sec) Memory instrumentation 26
  • 32. mysql> select thread_id tid, user, current_allocated ca, total_allocated -> from sys.memory_by_thread_by_current_bytes; +----------+--------------------+-------------+-----------------+ | tid | user | ca | total_allocated | +----------+--------------------+-------------+-----------------+ | 1 | sql/main | 2.53 GiB | 2.69 GiB | | 150 | root@127.0.0.1 | 4.06 MiB | 32.17 MiB | | 146 | sql/slave_sql | 1.31 MiB | 1.44 MiB | | 145 | sql/slave_io | 1.08 MiB | 2.79 MiB | ... | 4 | innodb/io_log_thread | -2880 bytes | 132.38 KiB | | 72 | innodb/io_write_thread | -7632 bytes | 1.10 MiB | +----------+--------------------+-------------+----------- 145 rows in set (2.65 sec) Detailed Memory Statistics 27
  • 33. • memory summary by account by event name • memory summary by host by event name • memory summary by thread by event name • memory summary by user by event name • memory summary global by event name • sys schema also includes information about user name RAW Performance Schema tables 28
  • 34. • NAME@HOST - regular user • System users • sql/main • innodb/* • ... • Data comes from table THREADS Users in sys.memory * tables 29
  • 36. • Metadata locks • Table METADATA LOCKS • Table-level locks • Table TABLE HANDLES • Engine-dependent locks, transactions • Tables EVENTS TRANSACTIONS * • This is not exactly lock information! What can block your queries? 31
  • 37. • Table METADATA LOCKS • Which thread is waiting for a lock • Which thread holds the lock • Not only for tables: GLOBAL, SCHEMA, TABLE, FUNCTION, PROCEDURE, EVENT, COMMIT, USER LEVEL LOCK, TABLESPACE Metadata Locks 32
  • 38. mysql> select processlist_id, object_type, lock_type, lock_status, source -> from metadata_locks join threads on (owner_thread_id=thread_id) -> where object_schema=’employees’ and object_name=’titles’G *************************** 1. row *************************** processlist_id: 4 object_type: TABLE lock_type: EXCLUSIVE lock_status: PENDING -- waits source: mdl.cc:3263 *************************** 2. row *************************** processlist_id: 5 object_type: TABLE lock_type: SHARED_READ lock_status: GRANTED -- holds METADATA LOCKS: example 33
  • 39. • Table TABLE HANDLES • Not only locks, but also information about open tables • FLUSH TABLES removes data from this table Table locks 34
  • 40. mysql> select * from table_handlesG *************************** 1. row *************************** OBJECT_TYPE: TABLE OBJECT_SCHEMA: employees OBJECT_NAME: titles OBJECT_INSTANCE_BEGIN: 140663937105248 OWNER_THREAD_ID: 28 OWNER_EVENT_ID: 951 INTERNAL_LOCK: NULL EXTERNAL_LOCK: READ EXTERNAL - Read lock (I run LOCK TABLE ... READ) Table locks: example 35
  • 41. *************************** 2. row *************************** OBJECT_TYPE: TABLE OBJECT_SCHEMA: employees OBJECT_NAME: emp OBJECT_INSTANCE_BEGIN: 140663879605856 OWNER_THREAD_ID: 26 OWNER_EVENT_ID: 10419193 INTERNAL_LOCK: WRITE - Table lock for MyISAM table EXTERNAL_LOCK: WRITE EXTERNAL - Write lock 2 rows in set (0.00 sec) Table locks: example 36
  • 42. • Tables EVENTS TRANSACTIONS * • Transaction information even if engine is not transactional - One more tool to hunt MDL • GTIDs • Background transactions Transactions at server level 37
  • 43. mysql> select processlist_ID, STATE, GTID, SOURCE, ACCESS_MODE, -> ISOLATION_LEVEL, AUTOCOMMIT -> from events_transactions_current join threads using(thread_id)G ************************ 1. row ************************ processlist_ID: NULL STATE: COMMITTED GTID: NULL SOURCE: handler.cc:1248 ACCESS_MODE: READ WRITE ISOLATION_LEVEL: REPEATABLE READ AUTOCOMMIT: YES ... Background transaction 38
  • 44. mysql> select processlist_ID, STATE, GTID, SOURCE, -> ACCESS_MODE, ISOLATION_LEVEL, AUTOCOMMIT -> from events_transactions_current join threads using(thread_id)G ************************ 2. row ************************ processlist_ID: 4 STATE: COMMITTED GTID: AUTOMATIC - GTID information here SOURCE: transaction.cc:150 ACCESS_MODE: READ WRITE ISOLATION_LEVEL: REPEATABLE READ AUTOCOMMIT: NO Transaction in BEGIN ... COMMIT block 39
  • 45. mysql> select processlist_ID, STATE, GTID, SOURCE, -> ACCESS_MODE, ISOLATION_LEVEL, AUTOCOMMIT -> from events_transactions_current join threads using(thread_id)G ************************ 3. row ************************ processlist_ID: 5 STATE: COMMITTED GTID: NULL SOURCE: handler.cc:1248 ACCESS_MODE: READ WRITE ISOLATION_LEVEL: REPEATABLE READ AUTOCOMMIT: YES ... Autocommitted transaction 40
  • 47. • Now in Performance Schema • Global • Session • User-defined - First time ever! • Tables in Information Schema are deprecated in 5.7 Variables and Status 42
  • 48. • Variables • Global • Session • By thread • User variables • By thread • Status variables • Global • Session • Account • Host • User • Thread Groupped by 43
  • 49. • Variables mysql> select * from variables_by_thread -> where variable_name=’tx_isolation’; +-----------+---------------+-----------------+ | THREAD_ID | VARIABLE_NAME | VARIABLE_VALUE | +-----------+---------------+-----------------+ | 71 | tx_isolation | REPEATABLE-READ | | 83 | tx_isolation | REPEATABLE-READ | | 84 | tx_isolation | SERIALIZABLE | +-----------+---------------+-----------------+ 3 rows in set, 3 warnings (0.00 sec) • User variables • Status variables Variables and status: example 44
  • 50. • Variables • User variables mysql> select * from user_variables_by_thread; +-----------+---------------+----------------+ | THREAD_ID | VARIABLE_NAME | VARIABLE_VALUE | +-----------+---------------+----------------+ | 71 | baz | boo | | 84 | foo | bar | +-----------+---------------+----------------+ 2 rows in set (0.00 sec) • Status variables Variables and status: example 44
  • 51. • Variables • User variables • Status variables mysql> select * from status_by_thread -> where variable_name=’Handler_write’; +-----------+---------------+----------------+ | THREAD_ID | VARIABLE_NAME | VARIABLE_VALUE | +-----------+---------------+----------------+ | 71 | Handler_write | 94 | | 83 | Handler_write | 477 | -- Most writes | 84 | Handler_write | 101 | +-----------+---------------+----------------+ 3 rows in set (0.00 sec) Variables and status: example 44
  • 53. • Tables accounts, users, hosts mysql> select user, host, current_connections as cur, -> total_connections as total from accounts; +------+-----------+-----+-------+ | user | host | cur | total | +------+-----------+-----+-------+ | foo | localhost | 0 | 3 | | root | localhost | 1 | 3 | | NULL | NULL | 14 | 17 | +------+-----------+-----+-------+ 3 rows in set (0.01 sec) • Connection attributes Connection diagnostic 46
  • 54. • Connection attributes mysql> SELECT ATTR_NAME, ATTR_VALUE FROM session_account_connect_attrs -> WHERE processlist_id != @@pseudo_thread_id; +-----------------+--------------------------+ | ATTR_NAME | ATTR_VALUE | +-----------------+--------------------------+ | _os | Linux | | _client_name | libmysql | | _pid | 4729 | | program_name | PLMCE-2016 | | _platform | x86_64 | | session | MySQL Performance Schema | | author | Sveta Smirnova | | _client_version | 5.7.11 | Connection diagnostic 46
  • 55. • Content of DNS cache • Errors from: • Name Server • Connection • Authentication • max connect errors, max user errors, etc. • Your first assistant in case of connection issue Host Cache 47
  • 57. • Data from SHOW SLAVE STATUS available in replication * tables • Not full replacement • Binary, relay log names and positions are in mysql.slave * tables • GTID information for single-threaded slave missed is in gtid executed variable • Support of Replication Channels (Multi-threaded slave) • GTID instrumentation Replication diagnostics 49
  • 58. • No need to parse SHOW output • Configuration • IO thread • SQL thread SLAVE STATUS 50
  • 59. • No need to parse SHOW output • Configuration • replication connection configuration • replication applier configuration • IO thread • SQL thread SLAVE STATUS 50
  • 60. • No need to parse SHOW output • Configuration • IO thread • replication connection status • SQL thread SLAVE STATUS 50
  • 61. • No need to parse SHOW output • Configuration • IO thread • SQL thread • replication applier status • replication applier status by coordinator • replication applier status by worker - MTS only SLAVE STATUS 50
  • 62. • Configuration mysql> select * from replication_connection_configuration -> join replication_applier_configuration using(channel_name)G *************************** 1. row *************************** CHANNEL_NAME: HOST: 127.0.0.1 PORT: 13000 USER: root NETWORK_INTERFACE: AUTO_POSITION: 1 SSL_ALLOWED: NO SSL_CA_FILE: ... SLAVE STATUS 51
  • 63. • Configuration ... CONNECTION_RETRY_INTERVAL: 60 CONNECTION_RETRY_COUNT: 10 HEARTBEAT_INTERVAL: 60.000 CHANNEL_NAME: DESIRED_DELAY: 0 1 row in set (0.00 sec) SLAVE STATUS 52
  • 64. • State of IO Thread mysql> select * from replication_connection_statusG *************************** 1. row *************************** CHANNEL_NAME: GROUP_NAME: SOURCE_UUID: d0753e78-14ec-11e5-b3fb-28b2bd7442fd THREAD_ID: 21 SERVICE_STATE: ON COUNT_RECEIVED_HEARTBEATS: 17 LAST_HEARTBEAT_TIMESTAMP: 2015-06-17 15:49:08 RECEIVED_TRANSACTION_SET: LAST_ERROR_NUMBER: 0 LAST_ERROR_MESSAGE: LAST_ERROR_TIMESTAMP: 0000-00-00 00:00:00 SLAVE STATUS 53
  • 65. • State of SQL Thread mysql> select * from replication_applier_status join -> replication_applier_status_by_coordinator using(channel_name)G *************************** 1. row *************************** CHANNEL_NAME: SERVICE_STATE: ON REMAINING_DELAY: NULL COUNT_TRANSACTIONS_RETRIES: 0 THREAD_ID: 22 SERVICE_STATE: ON LAST_ERROR_NUMBER: 0 LAST_ERROR_MESSAGE: LAST_ERROR_TIMESTAMP: 0000-00-00 00:00:00 1 row in set (0.00 sec) SLAVE STATUS 54
  • 67. • EVENTS WAITS * tables • EVENT NAME wait/synch/rwlock/innodb/dict operation lock • SOURCE Line of the source code • OPERATION Kind of operation: read, lock, write Server Internals 56
  • 68. • wait/lock - Metadata and table locks • wait/synch/cond - InnoDB, MyISAM, sql • wait/synch/mutex - sql, mysys, engines • wait/synch/rwlock - sql, InnoDB, MyISAM • wait/synch/sxlock - InnoDB global locks • wait/io/file - Operations with files • wait/io/socket • wait/io/table/sql/handler Which kind of events can we examine? 57
  • 69. • file instances - Opened files • socket instances - Connections • cond instances • rwlock instances select * from rwlock_instances where READ_LOCKED_BY_COUNT > 0; select * from rwlock_instances where WRITE_LOCKED_BY_THREAD_ID > 0; • mutex instances - LOCKED BY THREAD ID * INSTANCES tables 58
  • 70. • Tables in sys schema • io * • host summary * • user summary * • waits * • Digests events waits summary * Diagnostic sugar 59
  • 71. • Tables in sys schema • Digests events waits summary * • *by account by event name • *by host by event name • *by instance • *by thread by event name • *by user by event name • *by event name Diagnostic sugar 59
  • 72. • Blog of developers team • Blog of Mark Leith: author of sys schema • Official reference manual More informaiton 60
  • 73. ??? Place for your questions 61