SlideShare a Scribd company logo
1 of 40
Download to read offline
MySQL Query Tuning 101
Sveta Smirnova, Alexander Rubin
April, 16, 2015
• Introduction: where to find slow queries
• Indexes: why and how do they work
• All about EXPLAIN
• More tools
• Where to find more information
Agenda 2
• You develop an application and find out that
some queries are running slow
• After a while you find some slow queries in the
slow query log
• All such queries are always slow
• We would not talk about cases when
concurrency affects performance
When you see slow query first 3
• MySQL has to do some job to execute a select
query
• In the worst case scenario it will do a full table
scan
• CREATE INDEX
• Incorrect index can be used by MySQL
Why query can run slow 4
select * from table select * from table where id=12
1 2 5 6 7 9 12 16 18 21 22 23 24 25
Full table scan 5
• When you add index (except for MEMORY)
MySQL will use B-Tree
• Support equality and “range” operations
MySQL Indexes 6
• select * from table where id = 12
• Scan thru the tree and go directly to 1 leaf
• Stop
B-Tree: Equality search 7
• select * from table where id in (6, 12, 18)
• Scan thru the tree and visit many leafs/nodes
B-Tree: Range 8
• EXPLAIN
– Estimates what happens during query
execution
– EXTENDED
– FORMAT=JSON
– PARTITIONS
• INFORMATION SCHEMA.OPTIMIZER TRACE
– Real data, collected after query was executed
– Advanced topic
How to find out how MySQL uses indexes 9
mysql> explain select * from t1G
*************************** 1. row ***************************
...
rows: 12
Extra: NULL
mysql> explain select * from t1 where f2=12G
*************************** 1. row ***************************
...
key: NULL
...
rows: 12
Extra: Using where
Same number of examined rows for both queries
Effect of indexes: before 10
mysql> alter table t1 add index(f2);
Query OK, 12 rows affected (0.07 sec)
Records: 12 Duplicates: 0 Warnings: 0
mysql> explain select * from t1 where f2=12G
*************************** 1. row ***************************
...
key: f2
key_len: 5
ref: const
rows: 1
Extra: NULL
1 row in set (0.00 sec)
Much more effective!
Only 1 row examined
Effect of indexes: after 11
mysql> explain extended select * from t1 join t2 where t1.int_key=1;
+----+-------------+-------+-------+---------------+---------+---------+-------+------+----------+------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+-------+-------+---------------+---------+---------+-------+------+----------+------------------+
| 1 | SIMPLE | t1 | ref | int_key,ik | int_key | 5 | const | 4 | 100.00 | NULL |
| 1 | SIMPLE | t2 | index | NULL | pk | 9 | NULL | 6 | 100.00 | Using index; |
Using join buffer |
(Block Nested Loop) |
+----+-------------+-------+-------+---------------+---------+---------+-------+------+----------+------------------+
2 rows in set, 1 warning (0.00 sec)
Note (Code 1003): /* select#1 */ select ‘test‘.‘t1‘.‘pk‘ AS ‘pk‘,‘test‘.‘t1‘.‘int_key‘ AS ‘int_key‘,‘test‘.‘t2‘.‘pk‘
AS ‘pk‘,‘test‘.‘t2‘.‘int_key‘ AS ‘int_key‘ from ‘test‘.‘t1‘ join ‘test‘.‘t2‘ where (‘test‘.‘t1‘.‘int_key‘ = 1)
Number of select
Select type
Tables, for which information is printed
How data is accessed
Possible keys
Key, which was actually used
Length of the key
Which columns were compared with the index
Number of examined rows
% of filtered rows
rows x filtered / 100 — number of rows,
which will be joined with another table
Additional information
Table, for which information is printed
Product of rows here: how many rows in all tables will be accessed
For this example estimated value is 4*6 = 24
Actual (optimized) query as executed by MySQL Server
EXPLAIN: overview 12
mysql> explain extended select * from t1 join t2 where...
+----+-------------+-------+-------+***
| id | select_type | table | type |***
+----+-------------+-------+-------+***
| 1 | SIMPLE | t1 | ref |***
| 1 | SIMPLE | t2 | index |***
+----+-------------+-------+-------+***
2 rows in set, 1 warning (0.00 sec)
SIMPLE;PRIMARY;UNION;DEPENDENT UNION;UNION RESULT;
SUBQUERY;DEPENDENT SUBQUERY;DERIVED;MATERIALIZED
system
const
eq ref
ref
fulltext
ref or null
index merge
unique subquery
index subquery
range
index
ALL
EXPLAIN in details 13
mysql> explain extended select * from t1 join t2 where t1.int_key=1;
***+---------------+---------+---------+-------+***
***| possible_keys | key | key_len | ref |***
***+---------------+---------+---------+-------+***
***| int_key,ik | int_key | 5 | const |***
***| NULL | pk | 9 | NULL |***
***+---------------+---------+---------+-------+***
2 rows in set, 1 warning (0.00 sec)
Keys, which can be used for resolving the query
Only one key was actually used
Actual length of the key (Important for multiple-column keys)
Which columns were compared with the index
Constant
Numeric in our case
Index used
to resolve rows
EXPLAIN in details: keys 14
mysql> explain extended select * from t1 join t2 where t1.int_key=1;
***+-------+----------+----------------------------------------------------+
***| rows | filtered | Extra |
***+-------+----------+----------------------------------------------------+
***| 4 | 100.00 | NULL |
***| 6 | 100.00 | Using index; Using join buffer (Block Nested Loop) |
***+-------+----------+----------------------------------------------------+
2 rows in set, 1 warning (0.00 sec)
Number of rows accessed
% of rows filtered
Additional information:
how query is resolved
Using filesort
Using temporary
etc.
4X6
=
24
All rows used
EXPLAIN in details: rows 15
• MySQL or Percona Server 5.6
• Employees test database
– XML: Fusheng Wang and Carlo Zaniolo
– SQL: Giuseppe Maxia and Patrick Crews
– More information
• Download: https://launchpad.net/test-db/
• Install:
– cd employees db
– mysql <employees.sql
EXPLAIN type by example: setup 16
mysql> explain select count(*) from employees where hire_date > ’1995-01-01’
********************** 1. row **********************
id: 1
select_type: SIMPLE
table: employees
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 300157
Extra: Using where
1 row in set (0.00 sec)
All rows in the table examined
Worst plan ever!
EXPLAIN type by example: ALL 17
mysql> explain select count(*) from titles where title=’Senior Engineer’G
********************** 1. row **********************
id: 1
select_type: SIMPLE
table: titles
type: index
possible_keys: NULL
key: emp_no
key_len: 4
ref: NULL
rows: 444033
Extra: Using where; Using index
1 row in set (0.11 sec)
No row in the table was accessed to resolve the query!
Only index used
Still all records in the index were scanned
EXPLAIN type by example: index 18
• We need to add index to table employees first
• mysql> alter table employees 
-> add index(hire_date);
Query OK, 0 rows affected (3.48 sec)
Records: 0 Duplicates: 0 Warnings: 0
EXPLAIN type by example: range 19
mysql> explain select count(*) from employees where hire_date > ’1995-01-01’
********************** 1. row **********************
id: 1
select_type: SIMPLE
table: employees
type: range
possible_keys: hire_date
key: hire_date
key_len: 3
ref: NULL
rows: 68654
Extra: Using where; Using index
1 row in set (0.00 sec)
Only rows from given range used
Compare with ALL:
300157/68654 = 4.3720
4 times less rows examined!
EXPLAIN type by example: range 20
• Consists of two or more columns
• Only leftmost part used
• mysql> alter table City add key
comb(CountryCode, District, Population),
drop key CountryCode;
Combined indexes 21
mysql> explain select * from City where CountryCode = ’USA’G
********************** 1. row ******************
table: City
type: ref
possible_keys: comb
key: comb
key_len: 3
ref: const
rows: 273
Uses first field from the comb key
Combined indexes: example 1 22
mysql> explain select * from City where 
-> District = ’California’ and population > 10000G
********************** 1. row ******************
table: City
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 3868
Can’t use combined index:
not a leftmost part
Does not have the CountryCode
in the where clause
= can’t use comb index
Combined indexes: example 2 23
• Key len = total size (in bytes) of index parts used
• Index: comb(CountryCode, District, Population)
•
Explain: Fields:
key: comb CountryCode char(3)
key len: 3 District char(20)
Population int(11)
3 ->Char(3) ->First field is used
Combined indexes: key len 24
• Covered index = cover all fields in query
• select name from City
where CountryCode = ’USA’
and District = ’Alaska’ and population > 10000
mysql> alter table City add key
cov1(CountryCode, District, population, name);
Uses all fields in the query in particular order
1. Where part 2. Group By/Order (not used now) 3. Select part
Covered indexes 25
mysql> explain select name from City where CountryCode = ’USA’ 
-> and District = ’Alaska’ and population > 10000G
*************************** 1. row ***********
table: City
type: range
possible_keys: cov1
key: cov1
key_len: 27
ref: NULL
rows: 1
Extra: Using where; Using index
Covered index is used
MySQL will only use index
Will not go to the data file
EXPLAIN by example: covered indexes 26
mysql> explain select * from dept_emp where dept_no = ’d005’G
************************ 1. row ************************
id: 1
select_type: SIMPLE
table: dept_emp
type: ref
possible_keys: dept_no
key: dept_no
key_len: 4
ref: const
rows: 145708
Extra: Using where
1 row in set (0.00 sec)
EXPLAIN type by example: ref 27
mysql> explain select * from dept_manager
join employees using(emp_no) limit 10G
************************ 1. row ************************
id: 1
select_type: SIMPLE
table: dept_manager
type: ALL
possible_keys: PRIMARY,emp_no
key: NULL
key_len: NULL
ref: NULL
rows: 24
Extra:
EXPLAIN type by example: eq ref 28
************************ 2. row ************************
id: 1
select_type: SIMPLE
table: employees
type: eq_ref
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: employees.dept_manager.emp_no
rows: 1
Extra:
2 rows in set (0.00 sec)
EXPLAIN type by example: eq ref 29
mysql> explain select * from departments where dept_no=’d005’G
************************ 1. row ************************
id: 1
select_type: SIMPLE
table: departments
type: const
possible_keys: PRIMARY
key: PRIMARY
key_len: 4
ref: const
rows: 1
Extra:
1 row in set (0.00 sec)
EXPLAIN type by example: const 30
• Limitations
– It shows estimates only
• Extensions
– EXTENDED
– PARTITIONS
– FORMAT=JSON
EXPLAIN limitations and extensions 31
mysql> explain partitions select count(*) 
-> from employees_part where hire_date > ’1991-01-01’G
************************ 1. row ************************
id: 1
select_type: SIMPLE
table: employees_part
partitions: p1,p2
type: index
possible_keys: NULL
key: PRIMARY
key_len: 7
ref: NULL
rows: 135214
Extra: Using where; Using index
EXPLAIN PARTITIONS 32
• Gives more information
– Real execution path of the query
– Pushed conditions
– Temporary table and index creation are more
precise
– Reflects execution order of ”group by” and
”order by” operations
– Displays table materializations
EXPLAIN FORMAT=JSON 33
mysql> explain format=json insert
into salaries(emp_no, from_date)
select emp_no, min(from_date) from titles
group by emp_noG
*********************** 1. row ***********************
EXPLAIN: {
"query_block": {
"select_id": 1,
"grouping_operation": {
"using_filesort": false,
"table": {
"table_name": "titles",
EXPLAIN FORMAT=JSON 34
mysql> explain insert into salaries(emp_no, from_date) 
-> select emp_no, min(from_date) from titles
group by emp_noG
********************** 1. row **********************
id: 1
select_type: SIMPLE
table: titles
type: index
possible_keys: NULL
key: emp_no
EXPLAIN for DML: not only SELECT 35
mysql> explain insert into salaries(emp_no, from_date)
select emp_no, min(from_date) from titles
group by emp_noG
...
key_len: 4
ref: NULL
rows: 444058
Extra: Using index
1 row in set, 2 warnings (0.00 sec)
Warning (Code 1364): Field ’salary’ doesn’t have a default value
Warning (Code 1364): Field ’to_date’ doesn’t have a default value
EXPLAIN for DML: not only SELECT 36
• Status variables ’Handler %’
• Performance schema
– events stages %
– events statements %
• INFORMATION SCHEMA.OPTIMIZER TRACE
Other tools 37
• MySQL User Reference Manual
• MySQL Troubleshooting book
• High Performance MySQL book
• MySQL Performance Blog
• Planet MySQL
• Troubleshooting Performance Companion slides
More to learn 38
Thank you! 39
?
Questions? 40

More Related Content

What's hot

Performance Schema for MySQL Troubleshooting
 Performance Schema for MySQL Troubleshooting Performance Schema for MySQL Troubleshooting
Performance Schema for MySQL TroubleshootingSveta Smirnova
 
Troubleshooting MySQL Performance
Troubleshooting MySQL PerformanceTroubleshooting MySQL Performance
Troubleshooting MySQL PerformanceSveta Smirnova
 
Character Encoding - MySQL DevRoom - FOSDEM 2015
Character Encoding - MySQL DevRoom - FOSDEM 2015Character Encoding - MySQL DevRoom - FOSDEM 2015
Character Encoding - MySQL DevRoom - FOSDEM 2015mushupl
 
Troubleshooting MySQL Performance add-ons
Troubleshooting MySQL Performance add-onsTroubleshooting MySQL Performance add-ons
Troubleshooting MySQL Performance add-onsSveta Smirnova
 
Preparse Query Rewrite Plugins
Preparse Query Rewrite PluginsPreparse Query Rewrite Plugins
Preparse Query Rewrite PluginsSveta Smirnova
 
MySQL Performance Schema in Action
MySQL Performance Schema in ActionMySQL Performance Schema in Action
MySQL Performance Schema in ActionSveta Smirnova
 
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]sSveta Smirnova
 
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]sSveta Smirnova
 
0888 learning-mysql
0888 learning-mysql0888 learning-mysql
0888 learning-mysqlsabir18
 
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 actionSveta Smirnova
 
Introduction into MySQL Query Tuning
Introduction into MySQL Query TuningIntroduction into MySQL Query Tuning
Introduction into MySQL Query TuningSveta Smirnova
 
Basic MySQL Troubleshooting for Oracle DBAs
Basic MySQL Troubleshooting for Oracle DBAsBasic MySQL Troubleshooting for Oracle DBAs
Basic MySQL Troubleshooting for Oracle DBAsSveta Smirnova
 
UKOUG 2011: Practical MySQL Tuning
UKOUG 2011: Practical MySQL TuningUKOUG 2011: Practical MySQL Tuning
UKOUG 2011: Practical MySQL TuningFromDual GmbH
 
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013Jaime Crespo
 
Explaining the MySQL Explain
Explaining the MySQL ExplainExplaining the MySQL Explain
Explaining the MySQL ExplainMYXPLAIN
 
Optimizing Queries with Explain
Optimizing Queries with ExplainOptimizing Queries with Explain
Optimizing Queries with ExplainMYXPLAIN
 
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 2013Sergey Petrunya
 
56 Query Optimization
56 Query Optimization56 Query Optimization
56 Query OptimizationMYXPLAIN
 
MySQL 8.0 EXPLAIN ANALYZE
MySQL 8.0 EXPLAIN ANALYZEMySQL 8.0 EXPLAIN ANALYZE
MySQL 8.0 EXPLAIN ANALYZENorvald Ryeng
 

What's hot (20)

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
 
Character Encoding - MySQL DevRoom - FOSDEM 2015
Character Encoding - MySQL DevRoom - FOSDEM 2015Character Encoding - MySQL DevRoom - FOSDEM 2015
Character Encoding - MySQL DevRoom - FOSDEM 2015
 
Troubleshooting MySQL Performance add-ons
Troubleshooting MySQL Performance add-onsTroubleshooting MySQL Performance add-ons
Troubleshooting MySQL Performance add-ons
 
Preparse Query Rewrite Plugins
Preparse Query Rewrite PluginsPreparse Query Rewrite Plugins
Preparse Query Rewrite Plugins
 
MySQL Performance Schema in Action
MySQL Performance Schema in ActionMySQL Performance Schema in Action
MySQL Performance Schema in Action
 
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
 
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
 
0888 learning-mysql
0888 learning-mysql0888 learning-mysql
0888 learning-mysql
 
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
 
Introduction into MySQL Query Tuning
Introduction into MySQL Query TuningIntroduction into MySQL Query Tuning
Introduction into MySQL Query Tuning
 
Basic MySQL Troubleshooting for Oracle DBAs
Basic MySQL Troubleshooting for Oracle DBAsBasic MySQL Troubleshooting for Oracle DBAs
Basic MySQL Troubleshooting for Oracle DBAs
 
UKOUG 2011: Practical MySQL Tuning
UKOUG 2011: Practical MySQL TuningUKOUG 2011: Practical MySQL Tuning
UKOUG 2011: Practical MySQL Tuning
 
Noinject
NoinjectNoinject
Noinject
 
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
Query Optimization with MySQL 5.6: Old and New Tricks - Percona Live London 2013
 
Explaining the MySQL Explain
Explaining the MySQL ExplainExplaining the MySQL Explain
Explaining the MySQL Explain
 
Optimizing Queries with Explain
Optimizing Queries with ExplainOptimizing Queries with Explain
Optimizing Queries with Explain
 
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
 
56 Query Optimization
56 Query Optimization56 Query Optimization
56 Query Optimization
 
MySQL 8.0 EXPLAIN ANALYZE
MySQL 8.0 EXPLAIN ANALYZEMySQL 8.0 EXPLAIN ANALYZE
MySQL 8.0 EXPLAIN ANALYZE
 

Viewers also liked

Applying profilers to my sql (fosdem 2017)
Applying profilers to my sql (fosdem 2017)Applying profilers to my sql (fosdem 2017)
Applying profilers to my sql (fosdem 2017)Valeriy Kravchuk
 
Advanced MySQL Query Tuning
Advanced MySQL Query TuningAdvanced MySQL Query Tuning
Advanced MySQL Query TuningAlexander Rubin
 
Zurich2007 MySQL Query Optimization
Zurich2007 MySQL Query OptimizationZurich2007 MySQL Query Optimization
Zurich2007 MySQL Query OptimizationHiệp Lê Tuấn
 
Building High Performance MySql Query Systems And Analytic Applications
Building High Performance MySql Query Systems And Analytic ApplicationsBuilding High Performance MySql Query Systems And Analytic Applications
Building High Performance MySql Query Systems And Analytic Applicationsguest40cda0b
 
MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014
MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014
MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014Dave Stokes
 
Essential Linux Commands for DBAs
Essential Linux Commands for DBAsEssential Linux Commands for DBAs
Essential Linux Commands for DBAsGokhan Atil
 
MYSQL Query Anti-Patterns That Can Be Moved to Sphinx
MYSQL Query Anti-Patterns That Can Be Moved to SphinxMYSQL Query Anti-Patterns That Can Be Moved to Sphinx
MYSQL Query Anti-Patterns That Can Be Moved to SphinxPythian
 
Mysql query optimization
Mysql query optimizationMysql query optimization
Mysql query optimizationBaohua Cai
 
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 TricksMYXPLAIN
 
Tunning sql query
Tunning sql queryTunning sql query
Tunning sql queryvuhaininh88
 
Advanced MySQL Query and Schema Tuning
Advanced MySQL Query and Schema TuningAdvanced MySQL Query and Schema Tuning
Advanced MySQL Query and Schema TuningMYXPLAIN
 
MySQL Query Optimization
MySQL Query OptimizationMySQL Query Optimization
MySQL Query OptimizationMorgan Tocker
 
Webinar 2013 advanced_query_tuning
Webinar 2013 advanced_query_tuningWebinar 2013 advanced_query_tuning
Webinar 2013 advanced_query_tuning晓 周
 
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricksQuery Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricksJaime Crespo
 
MySQL Query Optimization (Basics)
MySQL Query Optimization (Basics)MySQL Query Optimization (Basics)
MySQL Query Optimization (Basics)Karthik .P.R
 
Modern Linux Performance Tools for Application Troubleshooting
Modern Linux Performance Tools for Application TroubleshootingModern Linux Performance Tools for Application Troubleshooting
Modern Linux Performance Tools for Application TroubleshootingTanel Poder
 
Oracle Enterprise Manager Cloud Control 13c for DBAs
Oracle Enterprise Manager Cloud Control 13c for DBAsOracle Enterprise Manager Cloud Control 13c for DBAs
Oracle Enterprise Manager Cloud Control 13c for DBAsGokhan Atil
 

Viewers also liked (20)

Applying profilers to my sql (fosdem 2017)
Applying profilers to my sql (fosdem 2017)Applying profilers to my sql (fosdem 2017)
Applying profilers to my sql (fosdem 2017)
 
Advanced MySQL Query Tuning
Advanced MySQL Query TuningAdvanced MySQL Query Tuning
Advanced MySQL Query Tuning
 
Zurich2007 MySQL Query Optimization
Zurich2007 MySQL Query OptimizationZurich2007 MySQL Query Optimization
Zurich2007 MySQL Query Optimization
 
Building High Performance MySql Query Systems And Analytic Applications
Building High Performance MySql Query Systems And Analytic ApplicationsBuilding High Performance MySql Query Systems And Analytic Applications
Building High Performance MySql Query Systems And Analytic Applications
 
MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014
MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014
MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014
 
Essential Linux Commands for DBAs
Essential Linux Commands for DBAsEssential Linux Commands for DBAs
Essential Linux Commands for DBAs
 
MYSQL Query Anti-Patterns That Can Be Moved to Sphinx
MYSQL Query Anti-Patterns That Can Be Moved to SphinxMYSQL Query Anti-Patterns That Can Be Moved to Sphinx
MYSQL Query Anti-Patterns That Can Be Moved to Sphinx
 
Mysql query optimization
Mysql query optimizationMysql query optimization
Mysql query optimization
 
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
 
Tunning sql query
Tunning sql queryTunning sql query
Tunning sql query
 
Advanced MySQL Query and Schema Tuning
Advanced MySQL Query and Schema TuningAdvanced MySQL Query and Schema Tuning
Advanced MySQL Query and Schema Tuning
 
MySQL Query Optimization
MySQL Query OptimizationMySQL Query Optimization
MySQL Query Optimization
 
My sql optimization
My sql optimizationMy sql optimization
My sql optimization
 
Webinar 2013 advanced_query_tuning
Webinar 2013 advanced_query_tuningWebinar 2013 advanced_query_tuning
Webinar 2013 advanced_query_tuning
 
MySQL Query Optimization.
MySQL Query Optimization.MySQL Query Optimization.
MySQL Query Optimization.
 
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricksQuery Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
 
MySQL Query Optimization (Basics)
MySQL Query Optimization (Basics)MySQL Query Optimization (Basics)
MySQL Query Optimization (Basics)
 
Sql query patterns, optimized
Sql query patterns, optimizedSql query patterns, optimized
Sql query patterns, optimized
 
Modern Linux Performance Tools for Application Troubleshooting
Modern Linux Performance Tools for Application TroubleshootingModern Linux Performance Tools for Application Troubleshooting
Modern Linux Performance Tools for Application Troubleshooting
 
Oracle Enterprise Manager Cloud Control 13c for DBAs
Oracle Enterprise Manager Cloud Control 13c for DBAsOracle Enterprise Manager Cloud Control 13c for DBAs
Oracle Enterprise Manager Cloud Control 13c for DBAs
 

Similar to MySQL Query tuning 101

MySQL Indexing : Improving Query Performance Using Index (Covering Index)
MySQL Indexing : Improving Query Performance Using Index (Covering Index)MySQL Indexing : Improving Query Performance Using Index (Covering Index)
MySQL Indexing : Improving Query Performance Using Index (Covering Index)Hemant Kumar Singh
 
Covering indexes
Covering indexesCovering indexes
Covering indexesMYXPLAIN
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index TuningManikanda kumar
 
MYSQL using set operators
MYSQL using set operatorsMYSQL using set operators
MYSQL using set operatorsAhmed Farag
 
4. Data Manipulation.ppt
4. Data Manipulation.ppt4. Data Manipulation.ppt
4. Data Manipulation.pptKISHOYIANKISH
 
Migration from mysql to elasticsearch
Migration from mysql to elasticsearchMigration from mysql to elasticsearch
Migration from mysql to elasticsearchRyosuke Nakamura
 
SQL Tuning and VST
SQL Tuning and VST SQL Tuning and VST
SQL Tuning and VST Kyle Hailey
 
Sql Queries
Sql QueriesSql Queries
Sql Querieswebicon
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007paulguerin
 
Efficient Pagination Using MySQL
Efficient Pagination Using MySQLEfficient Pagination Using MySQL
Efficient Pagination Using MySQLEvan Weaver
 
PPC2009_yahoo_mysql_pagination
PPC2009_yahoo_mysql_paginationPPC2009_yahoo_mysql_pagination
PPC2009_yahoo_mysql_paginationmysqlops
 
Optimizer features in recent releases of other databases
Optimizer features in recent releases of other databasesOptimizer features in recent releases of other databases
Optimizer features in recent releases of other databasesSergey Petrunya
 
Understanding Query Execution
Understanding Query ExecutionUnderstanding Query Execution
Understanding Query Executionwebhostingguy
 
Understanding query-execution806
Understanding query-execution806Understanding query-execution806
Understanding query-execution806yubao fu
 
Mysql Explain Explained
Mysql Explain ExplainedMysql Explain Explained
Mysql Explain ExplainedJeremy Coates
 
Discover the power of Recursive SQL and query transformation with Informix da...
Discover the power of Recursive SQL and query transformation with Informix da...Discover the power of Recursive SQL and query transformation with Informix da...
Discover the power of Recursive SQL and query transformation with Informix da...Ajay Gupte
 
Scaling MySQL Strategies for Developers
Scaling MySQL Strategies for DevelopersScaling MySQL Strategies for Developers
Scaling MySQL Strategies for DevelopersJonathan Levin
 
Chasing the optimizer
Chasing the optimizerChasing the optimizer
Chasing the optimizerMauro Pagano
 

Similar to MySQL Query tuning 101 (20)

MySQL Indexing : Improving Query Performance Using Index (Covering Index)
MySQL Indexing : Improving Query Performance Using Index (Covering Index)MySQL Indexing : Improving Query Performance Using Index (Covering Index)
MySQL Indexing : Improving Query Performance Using Index (Covering Index)
 
Covering indexes
Covering indexesCovering indexes
Covering indexes
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index Tuning
 
MySQL performance tuning
MySQL performance tuningMySQL performance tuning
MySQL performance tuning
 
MYSQL using set operators
MYSQL using set operatorsMYSQL using set operators
MYSQL using set operators
 
4. Data Manipulation.ppt
4. Data Manipulation.ppt4. Data Manipulation.ppt
4. Data Manipulation.ppt
 
Migration from mysql to elasticsearch
Migration from mysql to elasticsearchMigration from mysql to elasticsearch
Migration from mysql to elasticsearch
 
SQL Tuning and VST
SQL Tuning and VST SQL Tuning and VST
SQL Tuning and VST
 
Quick Wins
Quick WinsQuick Wins
Quick Wins
 
Sql Queries
Sql QueriesSql Queries
Sql Queries
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007
 
Efficient Pagination Using MySQL
Efficient Pagination Using MySQLEfficient Pagination Using MySQL
Efficient Pagination Using MySQL
 
PPC2009_yahoo_mysql_pagination
PPC2009_yahoo_mysql_paginationPPC2009_yahoo_mysql_pagination
PPC2009_yahoo_mysql_pagination
 
Optimizer features in recent releases of other databases
Optimizer features in recent releases of other databasesOptimizer features in recent releases of other databases
Optimizer features in recent releases of other databases
 
Understanding Query Execution
Understanding Query ExecutionUnderstanding Query Execution
Understanding Query Execution
 
Understanding query-execution806
Understanding query-execution806Understanding query-execution806
Understanding query-execution806
 
Mysql Explain Explained
Mysql Explain ExplainedMysql Explain Explained
Mysql Explain Explained
 
Discover the power of Recursive SQL and query transformation with Informix da...
Discover the power of Recursive SQL and query transformation with Informix da...Discover the power of Recursive SQL and query transformation with Informix da...
Discover the power of Recursive SQL and query transformation with Informix da...
 
Scaling MySQL Strategies for Developers
Scaling MySQL Strategies for DevelopersScaling MySQL Strategies for Developers
Scaling MySQL Strategies for Developers
 
Chasing the optimizer
Chasing the optimizerChasing the optimizer
Chasing the optimizer
 

More from Sveta Smirnova

MySQL 2024: Зачем переходить на MySQL 8, если в 5.х всё устраивает?
MySQL 2024: Зачем переходить на MySQL 8, если в 5.х всё устраивает?MySQL 2024: Зачем переходить на MySQL 8, если в 5.х всё устраивает?
MySQL 2024: Зачем переходить на MySQL 8, если в 5.х всё устраивает?Sveta Smirnova
 
Database in Kubernetes: Diagnostics and Monitoring
Database in Kubernetes: Diagnostics and MonitoringDatabase in Kubernetes: Diagnostics and Monitoring
Database in Kubernetes: Diagnostics and MonitoringSveta Smirnova
 
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 HaveSveta Smirnova
 
MySQL Cookbook: Recipes for Developers
MySQL Cookbook: Recipes for DevelopersMySQL Cookbook: Recipes for Developers
MySQL Cookbook: Recipes for DevelopersSveta Smirnova
 
MySQL Performance for DevOps
MySQL Performance for DevOpsMySQL Performance for DevOps
MySQL Performance for DevOpsSveta Smirnova
 
MySQL Test Framework для поддержки клиентов и верификации багов
MySQL Test Framework для поддержки клиентов и верификации баговMySQL Test Framework для поддержки клиентов и верификации багов
MySQL Test Framework для поддержки клиентов и верификации баговSveta Smirnova
 
MySQL Cookbook: Recipes for Your Business
MySQL Cookbook: Recipes for Your BusinessMySQL Cookbook: Recipes for Your Business
MySQL Cookbook: Recipes for Your BusinessSveta Smirnova
 
Производительность MySQL для DevOps
 Производительность MySQL для DevOps Производительность MySQL для DevOps
Производительность MySQL для DevOpsSveta Smirnova
 
MySQL Performance for DevOps
MySQL Performance for DevOpsMySQL Performance for DevOps
MySQL Performance for DevOpsSveta 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 ClusterSveta Smirnova
 
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 tearsSveta Smirnova
 
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...Sveta Smirnova
 
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?Sveta Smirnova
 
Современному хайлоду - современные решения: MySQL 8.0 и улучшения Percona
Современному хайлоду - современные решения: MySQL 8.0 и улучшения PerconaСовременному хайлоду - современные решения: MySQL 8.0 и улучшения Percona
Современному хайлоду - современные решения: MySQL 8.0 и улучшения PerconaSveta Smirnova
 
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 GaleraSveta Smirnova
 
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?Sveta Smirnova
 
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?Sveta Smirnova
 
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 ...Sveta Smirnova
 
Что нужно знать о трёх топовых фичах MySQL
Что нужно знать  о трёх топовых фичах  MySQLЧто нужно знать  о трёх топовых фичах  MySQL
Что нужно знать о трёх топовых фичах MySQLSveta Smirnova
 
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?Sveta Smirnova
 

More from 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
 
Производительность 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
 
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?
 

Recently uploaded

SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 

Recently uploaded (20)

SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 

MySQL Query tuning 101

  • 1. MySQL Query Tuning 101 Sveta Smirnova, Alexander Rubin April, 16, 2015
  • 2. • Introduction: where to find slow queries • Indexes: why and how do they work • All about EXPLAIN • More tools • Where to find more information Agenda 2
  • 3. • You develop an application and find out that some queries are running slow • After a while you find some slow queries in the slow query log • All such queries are always slow • We would not talk about cases when concurrency affects performance When you see slow query first 3
  • 4. • MySQL has to do some job to execute a select query • In the worst case scenario it will do a full table scan • CREATE INDEX • Incorrect index can be used by MySQL Why query can run slow 4
  • 5. select * from table select * from table where id=12 1 2 5 6 7 9 12 16 18 21 22 23 24 25 Full table scan 5
  • 6. • When you add index (except for MEMORY) MySQL will use B-Tree • Support equality and “range” operations MySQL Indexes 6
  • 7. • select * from table where id = 12 • Scan thru the tree and go directly to 1 leaf • Stop B-Tree: Equality search 7
  • 8. • select * from table where id in (6, 12, 18) • Scan thru the tree and visit many leafs/nodes B-Tree: Range 8
  • 9. • EXPLAIN – Estimates what happens during query execution – EXTENDED – FORMAT=JSON – PARTITIONS • INFORMATION SCHEMA.OPTIMIZER TRACE – Real data, collected after query was executed – Advanced topic How to find out how MySQL uses indexes 9
  • 10. mysql> explain select * from t1G *************************** 1. row *************************** ... rows: 12 Extra: NULL mysql> explain select * from t1 where f2=12G *************************** 1. row *************************** ... key: NULL ... rows: 12 Extra: Using where Same number of examined rows for both queries Effect of indexes: before 10
  • 11. mysql> alter table t1 add index(f2); Query OK, 12 rows affected (0.07 sec) Records: 12 Duplicates: 0 Warnings: 0 mysql> explain select * from t1 where f2=12G *************************** 1. row *************************** ... key: f2 key_len: 5 ref: const rows: 1 Extra: NULL 1 row in set (0.00 sec) Much more effective! Only 1 row examined Effect of indexes: after 11
  • 12. mysql> explain extended select * from t1 join t2 where t1.int_key=1; +----+-------------+-------+-------+---------------+---------+---------+-------+------+----------+------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra | +----+-------------+-------+-------+---------------+---------+---------+-------+------+----------+------------------+ | 1 | SIMPLE | t1 | ref | int_key,ik | int_key | 5 | const | 4 | 100.00 | NULL | | 1 | SIMPLE | t2 | index | NULL | pk | 9 | NULL | 6 | 100.00 | Using index; | Using join buffer | (Block Nested Loop) | +----+-------------+-------+-------+---------------+---------+---------+-------+------+----------+------------------+ 2 rows in set, 1 warning (0.00 sec) Note (Code 1003): /* select#1 */ select ‘test‘.‘t1‘.‘pk‘ AS ‘pk‘,‘test‘.‘t1‘.‘int_key‘ AS ‘int_key‘,‘test‘.‘t2‘.‘pk‘ AS ‘pk‘,‘test‘.‘t2‘.‘int_key‘ AS ‘int_key‘ from ‘test‘.‘t1‘ join ‘test‘.‘t2‘ where (‘test‘.‘t1‘.‘int_key‘ = 1) Number of select Select type Tables, for which information is printed How data is accessed Possible keys Key, which was actually used Length of the key Which columns were compared with the index Number of examined rows % of filtered rows rows x filtered / 100 — number of rows, which will be joined with another table Additional information Table, for which information is printed Product of rows here: how many rows in all tables will be accessed For this example estimated value is 4*6 = 24 Actual (optimized) query as executed by MySQL Server EXPLAIN: overview 12
  • 13. mysql> explain extended select * from t1 join t2 where... +----+-------------+-------+-------+*** | id | select_type | table | type |*** +----+-------------+-------+-------+*** | 1 | SIMPLE | t1 | ref |*** | 1 | SIMPLE | t2 | index |*** +----+-------------+-------+-------+*** 2 rows in set, 1 warning (0.00 sec) SIMPLE;PRIMARY;UNION;DEPENDENT UNION;UNION RESULT; SUBQUERY;DEPENDENT SUBQUERY;DERIVED;MATERIALIZED system const eq ref ref fulltext ref or null index merge unique subquery index subquery range index ALL EXPLAIN in details 13
  • 14. mysql> explain extended select * from t1 join t2 where t1.int_key=1; ***+---------------+---------+---------+-------+*** ***| possible_keys | key | key_len | ref |*** ***+---------------+---------+---------+-------+*** ***| int_key,ik | int_key | 5 | const |*** ***| NULL | pk | 9 | NULL |*** ***+---------------+---------+---------+-------+*** 2 rows in set, 1 warning (0.00 sec) Keys, which can be used for resolving the query Only one key was actually used Actual length of the key (Important for multiple-column keys) Which columns were compared with the index Constant Numeric in our case Index used to resolve rows EXPLAIN in details: keys 14
  • 15. mysql> explain extended select * from t1 join t2 where t1.int_key=1; ***+-------+----------+----------------------------------------------------+ ***| rows | filtered | Extra | ***+-------+----------+----------------------------------------------------+ ***| 4 | 100.00 | NULL | ***| 6 | 100.00 | Using index; Using join buffer (Block Nested Loop) | ***+-------+----------+----------------------------------------------------+ 2 rows in set, 1 warning (0.00 sec) Number of rows accessed % of rows filtered Additional information: how query is resolved Using filesort Using temporary etc. 4X6 = 24 All rows used EXPLAIN in details: rows 15
  • 16. • MySQL or Percona Server 5.6 • Employees test database – XML: Fusheng Wang and Carlo Zaniolo – SQL: Giuseppe Maxia and Patrick Crews – More information • Download: https://launchpad.net/test-db/ • Install: – cd employees db – mysql <employees.sql EXPLAIN type by example: setup 16
  • 17. mysql> explain select count(*) from employees where hire_date > ’1995-01-01’ ********************** 1. row ********************** id: 1 select_type: SIMPLE table: employees type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 300157 Extra: Using where 1 row in set (0.00 sec) All rows in the table examined Worst plan ever! EXPLAIN type by example: ALL 17
  • 18. mysql> explain select count(*) from titles where title=’Senior Engineer’G ********************** 1. row ********************** id: 1 select_type: SIMPLE table: titles type: index possible_keys: NULL key: emp_no key_len: 4 ref: NULL rows: 444033 Extra: Using where; Using index 1 row in set (0.11 sec) No row in the table was accessed to resolve the query! Only index used Still all records in the index were scanned EXPLAIN type by example: index 18
  • 19. • We need to add index to table employees first • mysql> alter table employees -> add index(hire_date); Query OK, 0 rows affected (3.48 sec) Records: 0 Duplicates: 0 Warnings: 0 EXPLAIN type by example: range 19
  • 20. mysql> explain select count(*) from employees where hire_date > ’1995-01-01’ ********************** 1. row ********************** id: 1 select_type: SIMPLE table: employees type: range possible_keys: hire_date key: hire_date key_len: 3 ref: NULL rows: 68654 Extra: Using where; Using index 1 row in set (0.00 sec) Only rows from given range used Compare with ALL: 300157/68654 = 4.3720 4 times less rows examined! EXPLAIN type by example: range 20
  • 21. • Consists of two or more columns • Only leftmost part used • mysql> alter table City add key comb(CountryCode, District, Population), drop key CountryCode; Combined indexes 21
  • 22. mysql> explain select * from City where CountryCode = ’USA’G ********************** 1. row ****************** table: City type: ref possible_keys: comb key: comb key_len: 3 ref: const rows: 273 Uses first field from the comb key Combined indexes: example 1 22
  • 23. mysql> explain select * from City where -> District = ’California’ and population > 10000G ********************** 1. row ****************** table: City type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 3868 Can’t use combined index: not a leftmost part Does not have the CountryCode in the where clause = can’t use comb index Combined indexes: example 2 23
  • 24. • Key len = total size (in bytes) of index parts used • Index: comb(CountryCode, District, Population) • Explain: Fields: key: comb CountryCode char(3) key len: 3 District char(20) Population int(11) 3 ->Char(3) ->First field is used Combined indexes: key len 24
  • 25. • Covered index = cover all fields in query • select name from City where CountryCode = ’USA’ and District = ’Alaska’ and population > 10000 mysql> alter table City add key cov1(CountryCode, District, population, name); Uses all fields in the query in particular order 1. Where part 2. Group By/Order (not used now) 3. Select part Covered indexes 25
  • 26. mysql> explain select name from City where CountryCode = ’USA’ -> and District = ’Alaska’ and population > 10000G *************************** 1. row *********** table: City type: range possible_keys: cov1 key: cov1 key_len: 27 ref: NULL rows: 1 Extra: Using where; Using index Covered index is used MySQL will only use index Will not go to the data file EXPLAIN by example: covered indexes 26
  • 27. mysql> explain select * from dept_emp where dept_no = ’d005’G ************************ 1. row ************************ id: 1 select_type: SIMPLE table: dept_emp type: ref possible_keys: dept_no key: dept_no key_len: 4 ref: const rows: 145708 Extra: Using where 1 row in set (0.00 sec) EXPLAIN type by example: ref 27
  • 28. mysql> explain select * from dept_manager join employees using(emp_no) limit 10G ************************ 1. row ************************ id: 1 select_type: SIMPLE table: dept_manager type: ALL possible_keys: PRIMARY,emp_no key: NULL key_len: NULL ref: NULL rows: 24 Extra: EXPLAIN type by example: eq ref 28
  • 29. ************************ 2. row ************************ id: 1 select_type: SIMPLE table: employees type: eq_ref possible_keys: PRIMARY key: PRIMARY key_len: 4 ref: employees.dept_manager.emp_no rows: 1 Extra: 2 rows in set (0.00 sec) EXPLAIN type by example: eq ref 29
  • 30. mysql> explain select * from departments where dept_no=’d005’G ************************ 1. row ************************ id: 1 select_type: SIMPLE table: departments type: const possible_keys: PRIMARY key: PRIMARY key_len: 4 ref: const rows: 1 Extra: 1 row in set (0.00 sec) EXPLAIN type by example: const 30
  • 31. • Limitations – It shows estimates only • Extensions – EXTENDED – PARTITIONS – FORMAT=JSON EXPLAIN limitations and extensions 31
  • 32. mysql> explain partitions select count(*) -> from employees_part where hire_date > ’1991-01-01’G ************************ 1. row ************************ id: 1 select_type: SIMPLE table: employees_part partitions: p1,p2 type: index possible_keys: NULL key: PRIMARY key_len: 7 ref: NULL rows: 135214 Extra: Using where; Using index EXPLAIN PARTITIONS 32
  • 33. • Gives more information – Real execution path of the query – Pushed conditions – Temporary table and index creation are more precise – Reflects execution order of ”group by” and ”order by” operations – Displays table materializations EXPLAIN FORMAT=JSON 33
  • 34. mysql> explain format=json insert into salaries(emp_no, from_date) select emp_no, min(from_date) from titles group by emp_noG *********************** 1. row *********************** EXPLAIN: { "query_block": { "select_id": 1, "grouping_operation": { "using_filesort": false, "table": { "table_name": "titles", EXPLAIN FORMAT=JSON 34
  • 35. mysql> explain insert into salaries(emp_no, from_date) -> select emp_no, min(from_date) from titles group by emp_noG ********************** 1. row ********************** id: 1 select_type: SIMPLE table: titles type: index possible_keys: NULL key: emp_no EXPLAIN for DML: not only SELECT 35
  • 36. mysql> explain insert into salaries(emp_no, from_date) select emp_no, min(from_date) from titles group by emp_noG ... key_len: 4 ref: NULL rows: 444058 Extra: Using index 1 row in set, 2 warnings (0.00 sec) Warning (Code 1364): Field ’salary’ doesn’t have a default value Warning (Code 1364): Field ’to_date’ doesn’t have a default value EXPLAIN for DML: not only SELECT 36
  • 37. • Status variables ’Handler %’ • Performance schema – events stages % – events statements % • INFORMATION SCHEMA.OPTIMIZER TRACE Other tools 37
  • 38. • MySQL User Reference Manual • MySQL Troubleshooting book • High Performance MySQL book • MySQL Performance Blog • Planet MySQL • Troubleshooting Performance Companion slides More to learn 38