SlideShare a Scribd company logo
1 of 39
Download to read offline
MMyySSQQLL QQuueerryy TTuunniinngg 
FFoorr tthhee SSqquueeeemmiisshh 
David.Stokes@Oracle.com 
@stoker
Copyright © 2014 Dave Stokes 2 
MySQL Optimizer 
● The MySQL Cost Based 
Optimizer wants to optimize 
each query, every time. 
Query plans can not be 
locked in as with Oracle. 
● Cost is/was based on disk 
I/O 
● FusionIO, hybrid drives 
changing cost paradigm 
– Cost when cost = 0?!? 
● Checks Syntax 
● Guesstimates costs, looks 
for cheapest way to do 
things 
● May not be the best way 
● How good are your 
statistics? When was your 
last ANALYSE TABLE? 
– Need to run to update 
stats
Logging – find slow queries 
Log slow queries (time configurable) and queries 
w/o indexes. 
MySQL 5.7 allows levels of verbosity. 
PERFORMANCE_SCHEMA, 
INFORMATION_SCEMA has tons of useful data. 
Copyright © 2014 Dave Stokes 3
Chapter 8 of the MySQL Manual 
● All about optimization 
● EXPLAIN 
MySQL 5.6.3 and later permits explainable statements for EXPLAIN are 
SELECT, DELETE, INSERT, REPLACE, and UPDATE. Before MySQL 
5.6.3, SELECT is the only explainable statement. 
● Many developers have been trained in their language of 
choice, JavaScript, JSON/REST, etc. but very, very few 
have any SQL training. And many try to use ORMs to 
make up for their rotten SQL skills or try to force NoSQL 
technologies for relational data. 
Copyright © 2014 Dave Stokes 4
Copyright © 2014 Dave Stokes 5 
Please note
Copyright © 2014 Dave Stokes 6 
Example 1 
This is the ASCII style output of explain versus VE
From the Manual – If you want details 
8.8.4 Estimating Query Performance 
● In most cases, you can estimate query performance by counting disk seeks. For small 
tables, you can usually find a row in one disk seek (because the index is probably 
cached). For bigger tables, you can estimate that, using B-tree indexes, you need this 
many seeks to find a row: log(row_count) / log(index_block_length / 3 * 2 / (index_length 
+ data_pointer_length)) + 1. 
● In MySQL, an index block is usually 1,024 bytes and the data pointer is usually four 
bytes. For a 500,000-row table with a key value length of three bytes (the size of 
MEDIUMINT), the formula indicates log(500,000)/log(1024/3*2/(3+4)) + 1 = 4 seeks. 
● This index would require storage of about 500,000 * 7 * 3/2 = 5.2MB (assuming a typical 
index buffer fill ratio of 2/3), so you probably have much of the index in memory and so 
need only one or two calls to read data to find the row. 
● For writes, however, you need four seek requests to find where to place a new index 
value and normally two seeks to update the index and write the row. 
Copyright © 2014 Dave Stokes 7
Previous slide in simpler terms 
● Use smallest data type possible. No BIGINT for age or 
customer id numbers 
– Are you really going to live to 
18,446,744,073,709,551,615? 
– Use PROCEDUE ANALYSE to find optimal size/type 
● Wasted space is moved from disk to memory, memoery to 
buffer, buffer to network, network to buffer, and/or buffer to 
disk 
– Reading off disk 100,000 slower than memory 
Copyright © 2014 Dave Stokes 8
From the Manual – If you want details 
8.8.4 Estimating Query Performance 
● In most cases, you can estimate query performance by counting disk seeks. For small 
tables, you can usually find a row in one disk seek (because the index is probably 
cached). For bigger tables, you can estimate that, using B-tree indexes, you need this 
many seeks to find a row: log(row_count) / log(index_block_length / 3 * 2 / (index_length 
+ data_pointer_length)) + 1. 
● In MySQL, an index block is usually 1,024 bytes and the data pointer is usually four 
bytes. For a 500,000-row table with a key value length of three bytes (the size of 
MEDIUMINT), the formula indicates log(500,000)/log(1024/3*2/(3+4)) + 1 = 4 seeks. 
● This index would require storage of about 500,000 * 7 * 3/2 = 5.2MB (assuming a typical 
index buffer fill ratio of 2/3), so you probably have much of the index in memory and so 
need only one or two calls to read data to find the row. 
● For writes, however, you need four seek requests to find where to place a new index 
value and normally two seeks to update the index and write the row. 
Copyright © 2014 Dave Stokes 9
Chapter 8 is a treasure 
trove of information. 
Copyright © 2014 Dave Stokes 10
The dreaded B-tree index 
Copyright © 2014 Dave Stokes 11 
● Docs.Oracle.com
Why your query stinks! 
SELECT CONCAT(customer.last_name, ', ', 
customer.first_name) AS customer, 
address.phone, film.title 
FROM rental INNER JOIN customer ON rental.customer_id 
= customer.customer_id 
INNER JOIN address ON customer.address_id = 
Copyright © 2014 Dave Stokes 12 
address.address_id 
INNER JOIN inventory ON rental.inventory_id = 
inventory.inventory_id 
INNER JOIN film ON inventory.film_id = film.film_id 
WHERE rental.return_date IS NULL 
AND rental_date + INTERVAL film.rental_duration DAY < 
CURRENT_DATE() 
LIMIT 5;
Copyright © 2014 Dave Stokes 13 
NULL 
● Usually used to do designate no value or a lack of data. 
– Useful for many applications 
– Screws up indexes as you need to also test values for 
null. Multiple nulls can kill performance
FULL TABLE SCAN – Try to avoid 
● FULL TABLE SCAN means each and every row in your 
table had to be read. If all the table is not in memory, it is 
made so. 
Copyright © 2014 Dave Stokes 14 
– Not all ways bad 
● Sometimes you have to go through all rows 
– Use indexes to find exact record(s) needed
Still have a full table scan 
Copyright © 2014 Dave Stokes 15
Note numbers for rows! Cost!! 
Estimate that it will take 2,000 reads to get desired data 
Copyright © 2014 Dave Stokes 16
Copyright © 2014 Dave Stokes 17 
Simpler Example 
SELECT City.name, Country.Name 
FROM City 
JOIN Country ON (City.CountryCode = Country.Code) 
LIMIT 5;
But I ONLY want FIVE ROWS!! 
SELECT City.name, Country.Name 
FROM City 
JOIN Country ON (City.CountryCode = Country.Code) 
LIMIT 5; 
Copyright © 2014 Dave Stokes 18 
Still needs to do the 
join BEFORE 
grabbing just the 
first FIVE rows.
Add stuff to WHERE to narrow 
search 
SELECT City.name, Country.Name 
FROM City 
JOIN Country ON (City.CountryCode = Country.Code) 
WHERE City.Population > 500000 
AND District = 'Texas' 
LIMIT 5; 
Should really cut down amount of 
data read, right? 
Copyright © 2014 Dave Stokes 19
Copyright © 2014 Dave Stokes 20 
Not Really
Copyright © 2014 Dave Stokes 21 
Another example 
● SELECT * 
FROM City 
WHERE 
Population > 400000
Tossing an index at a problem 
● CREATE INDEX 
CityPopIndex 
ON City (Population) 
Copyright © 2014 Dave Stokes 22 
● SELECT * 
FROM City 
WHERE 
Population > 400000 
Net gain zero
● Optimizer did not use our 
new index!! 
Copyright © 2014 Dave Stokes 23
The best-laid schemes o’ mice 
an’ men Gang aft agley 
● SELECT * 
FROM City 
USE INDEX 
(CityPopindex) 
WHERE Population > 
400000 
● This is a case where even 
forcing the index does not 
help as the Population 
entries are not unique 
enough for the optimizer to 
take advantage of it. 
Copyright © 2014 Dave Stokes 24
Copyright © 2014 Dave Stokes 25 
Another example 
● SELECT Name 
FROM City 
WHERE 
CountryCode = 'USA' 
● 274 rows in world.City 
have USA as the 
CountryCode, better than 
4K total records in a FULL 
TABLE SCAN
Copyright © 2014 Dave Stokes 26 
Using a Join 
● SELECT City.Name, 
Country.name 
FROM City 
Join Country ON 
(Country.code = 
City.CountryCode) 
WHERE Country.Population 
> 4000000 
AND 
City.CountryCode='USA'
Copyright © 2014 Dave Stokes 27 
Indexes 
● An index on City, State, and Zip can be used to look up 
– City, State, Zip 
– City, State 
– City 
● Drags Zip along on City, State and saves a read into 
the data
Add a table for zipcodes 
SHOW CREATE TABLE zipcodesG 
Copyright © 2014 Dave Stokes 28 
Table: zipcodes 
Create Table: CREATE TABLE `zipcodes` ( 
`zip` varchar(5) NOT NULL, 
`type` char(10) DEFAULT NULL, 
`primary_city` varchar(25) DEFAULT NULL, 
`accceptable_cities` varchar(50) DEFAULT 
NULL, 
`unacceptable_city` varchar(50) DEFAULT 
NULL, 
`state` char(2) DEFAULT NULL, 
`county` varchar(30) DEFAULT NULL, 
`tz` char(50) DEFAULT NULL, 
`area_code` varchar(20) DEFAULT NULL, 
`latitude` decimal(5,0) DEFAULT NULL, 
`longitude` decimal(5,0) DEFAULT NULL, 
`world_region` char(4) DEFAULT NULL, 
`country` char(2) DEFAULT NULL, 
`decomissioned` int(2) DEFAULT NULL, 
`est_population` int(10) unsigned 
DEFAULT NULL, 
`notes` char(20) DEFAULT NULL, 
PRIMARY KEY (`zip`), 
) ENGINE=InnoDB 
DEFAULT CHARSET=latin1
Lookup up by city name 
● SELECT primary_city, 
state, zip, 
accceptable_cities 
FROM zipcodes 
WHERE 
primary_city='Roanoke' 
Copyright © 2014 Dave Stokes 29
Copyright © 2014 Dave Stokes 30 
Two factors 
SELECT primary_city, state, zip, 
accceptable_cities 
FROM zipcodes 
WHERE primary_city='Roanoke' 
AND 
state='TX'
What is we specify all three items? 
● SELECT primary_city, state, 
zip, accceptable_cities 
FROM 
zipcodes 
WHERE 
primary_city='Roanoke' 
AND 
state='TX' 
AND 
zip='76262' 
Optimizer is smart 
enough to figure that 
PRIMARY key gives 
all we need the 
cheapest 
Copyright © 2014 Dave Stokes 31
Sometimes indexes help a little 
● CREATE INDEX 
cityindex 
ON 
zipcodes (primary_city); 
An index is added on 
primary_city to facilitate 
searching by city name 
Copyright © 2014 Dave Stokes 32
Yet another example 
SELECT primary_city, 
state, area_code 
FROM zipcodes 
USE INDEX (primary) 
WHERE 
primary_city='Orlando' 
AND 
state='FL' 
● Default is a full table scan 
● CREATE INDEX citystatearea 
ON 
zipcodes 
(primary_city,state,area_code); 
Copyright © 2014 Dave Stokes 33
More complex query 
SELECT CONCAT(c.city, _utf8',', cy.country) AS store, CONCAT(m.first_name, _utf8' ', m.last_name) AS manager, 
SUM(p.amount) AS total_sales 
FROM payment AS p 
INNER JOIN rental AS r ON p.rental_id = r.rental_id 
INNER JOIN inventory AS i ON r.inventory_id = i.inventory_id 
INNER JOIN store AS s ON i.store_id = s.store_id 
INNER JOIN address AS a ON s.address_id = a.address_id 
INNER JOIN city AS c ON a.city_id = c.city_id 
INNER JOIN country AS cy ON c.country_id = cy.country_id 
INNER JOIN staff AS m ON s.manager_staff_id = m.staff_id 
GROUP BY s.store_id 
ORDER BY cy.country, c.city; 
Copyright © 2014 Dave Stokes 34
Workbench – Mouse Over Blocks 
● MySQL Workbench can 
provide information on 
queries 
– Mouse over blocks for 
details. In this case the 
query does not require 
a filesort (slow) to order 
the query. 
– SELECT Name FROM 
City WHERE Population 
> 100000 or 
District='Florida' Order 
by Population limit 10; 
Note: Full 
INDEX scan not 
Full TABLE 
scan 
Copyright © 2014 Dave Stokes 35
Joins – think sets on rows of data 
Copyright © 2014 Dave Stokes 36
Copyright © 2014 Dave Stokes 37 
Books 
● Effective MySQL Optimizing SQL Statements 
– Ronald Bradford 
● High Performance MySQL 
– Schwartz, Zaitsev, Tkachenko
Copyright © 2014 Dave Stokes 38 
Other resources 
● MySQL Manual 
● Planet.MySQL.Com 
● Forums.MySQL.com 
– Forums for Performance, Optimizer & Parser, 
and many more 
● MySQL Central @ OpenWorld 
– Part of Oracle Open World 
– End of September
Copyright © 2014 Dave Stokes 39 
Q/A 
●David.Stokes@Oracle.com 
●@stoker 
●Slideshare.net/davestokes

More Related Content

What's hot

MySQL Server Defaults
MySQL Server DefaultsMySQL Server Defaults
MySQL Server DefaultsMorgan Tocker
 
Percona xtra db cluster(pxc) non blocking operations, what you need to know t...
Percona xtra db cluster(pxc) non blocking operations, what you need to know t...Percona xtra db cluster(pxc) non blocking operations, what you need to know t...
Percona xtra db cluster(pxc) non blocking operations, what you need to know t...Marco Tusa
 
Oracle Database 12.1.0.2 New Features
Oracle Database 12.1.0.2 New FeaturesOracle Database 12.1.0.2 New Features
Oracle Database 12.1.0.2 New FeaturesDeiby Gómez
 
MySQL 5.6 Updates
MySQL 5.6 UpdatesMySQL 5.6 Updates
MySQL 5.6 UpdatesDave Stokes
 
Writing A Foreign Data Wrapper
Writing A Foreign Data WrapperWriting A Foreign Data Wrapper
Writing A Foreign Data Wrapperpsoo1978
 
Scaling MySQL -- Swanseacon.co.uk
Scaling MySQL -- Swanseacon.co.uk Scaling MySQL -- Swanseacon.co.uk
Scaling MySQL -- Swanseacon.co.uk Dave Stokes
 
Introduction to CQL and Data Modeling with Apache Cassandra
Introduction to CQL and Data Modeling with Apache CassandraIntroduction to CQL and Data Modeling with Apache Cassandra
Introduction to CQL and Data Modeling with Apache CassandraJohnny Miller
 
DataStax | Advanced DSE Analytics Client Configuration (Jacek Lewandowski) | ...
DataStax | Advanced DSE Analytics Client Configuration (Jacek Lewandowski) | ...DataStax | Advanced DSE Analytics Client Configuration (Jacek Lewandowski) | ...
DataStax | Advanced DSE Analytics Client Configuration (Jacek Lewandowski) | ...DataStax
 
MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...
MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...
MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...Dave Stokes
 
Mysql 57-upcoming-changes
Mysql 57-upcoming-changesMysql 57-upcoming-changes
Mysql 57-upcoming-changesMorgan Tocker
 
MySQL 8.0 New Features -- September 27th presentation for Open Source Summit
MySQL 8.0 New Features -- September 27th presentation for Open Source SummitMySQL 8.0 New Features -- September 27th presentation for Open Source Summit
MySQL 8.0 New Features -- September 27th presentation for Open Source SummitDave Stokes
 
MySQL 5.7 - What's new and How to upgrade
MySQL 5.7 - What's new and How to upgradeMySQL 5.7 - What's new and How to upgrade
MySQL 5.7 - What's new and How to upgradeAbel Flórez
 
MySQL 8.0 & Unicode: Why, what & how
MySQL 8.0 & Unicode: Why, what & howMySQL 8.0 & Unicode: Why, what & how
MySQL 8.0 & Unicode: Why, what & howBernt Marius Johnsen
 
Upcoming changes in MySQL 5.7
Upcoming changes in MySQL 5.7Upcoming changes in MySQL 5.7
Upcoming changes in MySQL 5.7Morgan Tocker
 
Longhorn PHP - MySQL Indexes, Histograms, Locking Options, and Other Ways to ...
Longhorn PHP - MySQL Indexes, Histograms, Locking Options, and Other Ways to ...Longhorn PHP - MySQL Indexes, Histograms, Locking Options, and Other Ways to ...
Longhorn PHP - MySQL Indexes, Histograms, Locking Options, and Other Ways to ...Dave Stokes
 
From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016
From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016
From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016DataStax
 
MySQL 5.7 New Features to Exploit -- PHPTek/Chicago MySQL User Group May 2014
MySQL 5.7 New Features to Exploit -- PHPTek/Chicago MySQL User Group May 2014MySQL 5.7 New Features to Exploit -- PHPTek/Chicago MySQL User Group May 2014
MySQL 5.7 New Features to Exploit -- PHPTek/Chicago MySQL User Group May 2014Dave Stokes
 
MySQL Enterprise Backup - BnR Scenarios
MySQL Enterprise Backup - BnR ScenariosMySQL Enterprise Backup - BnR Scenarios
MySQL Enterprise Backup - BnR ScenariosKeith Hollman
 

What's hot (20)

MySQL Server Defaults
MySQL Server DefaultsMySQL Server Defaults
MySQL Server Defaults
 
MySQL 5.7 + JSON
MySQL 5.7 + JSONMySQL 5.7 + JSON
MySQL 5.7 + JSON
 
Percona xtra db cluster(pxc) non blocking operations, what you need to know t...
Percona xtra db cluster(pxc) non blocking operations, what you need to know t...Percona xtra db cluster(pxc) non blocking operations, what you need to know t...
Percona xtra db cluster(pxc) non blocking operations, what you need to know t...
 
Oracle Database 12.1.0.2 New Features
Oracle Database 12.1.0.2 New FeaturesOracle Database 12.1.0.2 New Features
Oracle Database 12.1.0.2 New Features
 
MySQL 5.6 Updates
MySQL 5.6 UpdatesMySQL 5.6 Updates
MySQL 5.6 Updates
 
Writing A Foreign Data Wrapper
Writing A Foreign Data WrapperWriting A Foreign Data Wrapper
Writing A Foreign Data Wrapper
 
Scaling MySQL -- Swanseacon.co.uk
Scaling MySQL -- Swanseacon.co.uk Scaling MySQL -- Swanseacon.co.uk
Scaling MySQL -- Swanseacon.co.uk
 
Introduction to CQL and Data Modeling with Apache Cassandra
Introduction to CQL and Data Modeling with Apache CassandraIntroduction to CQL and Data Modeling with Apache Cassandra
Introduction to CQL and Data Modeling with Apache Cassandra
 
Perf Tuning Short
Perf Tuning ShortPerf Tuning Short
Perf Tuning Short
 
DataStax | Advanced DSE Analytics Client Configuration (Jacek Lewandowski) | ...
DataStax | Advanced DSE Analytics Client Configuration (Jacek Lewandowski) | ...DataStax | Advanced DSE Analytics Client Configuration (Jacek Lewandowski) | ...
DataStax | Advanced DSE Analytics Client Configuration (Jacek Lewandowski) | ...
 
MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...
MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...
MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...
 
Mysql 57-upcoming-changes
Mysql 57-upcoming-changesMysql 57-upcoming-changes
Mysql 57-upcoming-changes
 
MySQL 8.0 New Features -- September 27th presentation for Open Source Summit
MySQL 8.0 New Features -- September 27th presentation for Open Source SummitMySQL 8.0 New Features -- September 27th presentation for Open Source Summit
MySQL 8.0 New Features -- September 27th presentation for Open Source Summit
 
MySQL 5.7 - What's new and How to upgrade
MySQL 5.7 - What's new and How to upgradeMySQL 5.7 - What's new and How to upgrade
MySQL 5.7 - What's new and How to upgrade
 
MySQL 8.0 & Unicode: Why, what & how
MySQL 8.0 & Unicode: Why, what & howMySQL 8.0 & Unicode: Why, what & how
MySQL 8.0 & Unicode: Why, what & how
 
Upcoming changes in MySQL 5.7
Upcoming changes in MySQL 5.7Upcoming changes in MySQL 5.7
Upcoming changes in MySQL 5.7
 
Longhorn PHP - MySQL Indexes, Histograms, Locking Options, and Other Ways to ...
Longhorn PHP - MySQL Indexes, Histograms, Locking Options, and Other Ways to ...Longhorn PHP - MySQL Indexes, Histograms, Locking Options, and Other Ways to ...
Longhorn PHP - MySQL Indexes, Histograms, Locking Options, and Other Ways to ...
 
From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016
From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016
From Postgres to Cassandra (Rimas Silkaitis, Heroku) | C* Summit 2016
 
MySQL 5.7 New Features to Exploit -- PHPTek/Chicago MySQL User Group May 2014
MySQL 5.7 New Features to Exploit -- PHPTek/Chicago MySQL User Group May 2014MySQL 5.7 New Features to Exploit -- PHPTek/Chicago MySQL User Group May 2014
MySQL 5.7 New Features to Exploit -- PHPTek/Chicago MySQL User Group May 2014
 
MySQL Enterprise Backup - BnR Scenarios
MySQL Enterprise Backup - BnR ScenariosMySQL Enterprise Backup - BnR Scenarios
MySQL Enterprise Backup - BnR Scenarios
 

Viewers also liked

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
 
56 Query Optimization
56 Query Optimization56 Query Optimization
56 Query OptimizationMYXPLAIN
 
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
 
MySQL Query tuning 101
MySQL Query tuning 101MySQL Query tuning 101
MySQL Query tuning 101Sveta Smirnova
 
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.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
 
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
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index TuningManikanda kumar
 
Percona Live 2012PPT: MySQL Query optimization
Percona Live 2012PPT: MySQL Query optimizationPercona Live 2012PPT: MySQL Query optimization
Percona Live 2012PPT: MySQL Query optimizationmysqlops
 

Viewers also liked (20)

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
 
56 Query Optimization
56 Query Optimization56 Query Optimization
56 Query Optimization
 
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
 
MySQL Query tuning 101
MySQL Query tuning 101MySQL Query tuning 101
MySQL Query tuning 101
 
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.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
 
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
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index Tuning
 
Percona Live 2012PPT: MySQL Query optimization
Percona Live 2012PPT: MySQL Query optimizationPercona Live 2012PPT: MySQL Query optimization
Percona Live 2012PPT: MySQL Query optimization
 

Similar to MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014

How to Think Like the SQL Server Engine
How to Think Like the SQL Server EngineHow to Think Like the SQL Server Engine
How to Think Like the SQL Server EngineBrent Ozar
 
What Your Database Query is Really Doing
What Your Database Query is Really DoingWhat Your Database Query is Really Doing
What Your Database Query is Really DoingDave Stokes
 
Helsinki Cassandra Meetup #2: Introduction to CQL3 and DataModeling
Helsinki Cassandra Meetup #2: Introduction to CQL3 and DataModelingHelsinki Cassandra Meetup #2: Introduction to CQL3 and DataModeling
Helsinki Cassandra Meetup #2: Introduction to CQL3 and DataModelingBruno Amaro Almeida
 
Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...
Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...
Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...Dave Stokes
 
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...Dave Stokes
 
Best Practices for Migrating Legacy Data Warehouses into Amazon Redshift
Best Practices for Migrating Legacy Data Warehouses into Amazon RedshiftBest Practices for Migrating Legacy Data Warehouses into Amazon Redshift
Best Practices for Migrating Legacy Data Warehouses into Amazon RedshiftAmazon Web Services
 
MySQL Indexes and Histograms - RMOUG Training Days 2022
MySQL Indexes and Histograms - RMOUG Training Days 2022MySQL Indexes and Histograms - RMOUG Training Days 2022
MySQL Indexes and Histograms - RMOUG Training Days 2022Dave Stokes
 
Introduction to SQL Server Internals: How to Think Like the Engine
Introduction to SQL Server Internals: How to Think Like the EngineIntroduction to SQL Server Internals: How to Think Like the Engine
Introduction to SQL Server Internals: How to Think Like the EngineBrent Ozar
 
SQL Query Optimization: Why Is It So Hard to Get Right?
SQL Query Optimization: Why Is It So Hard to Get Right?SQL Query Optimization: Why Is It So Hard to Get Right?
SQL Query Optimization: Why Is It So Hard to Get Right?Brent Ozar
 
Five Database Mistakes and how to fix them -- Confoo Vancouver
Five Database Mistakes and how to fix them -- Confoo VancouverFive Database Mistakes and how to fix them -- Confoo Vancouver
Five Database Mistakes and how to fix them -- Confoo VancouverDave Stokes
 
MySQL New Features -- Sunshine PHP 2020 Presentation
MySQL New Features -- Sunshine PHP 2020 PresentationMySQL New Features -- Sunshine PHP 2020 Presentation
MySQL New Features -- Sunshine PHP 2020 PresentationDave Stokes
 
Confoo 2021 - MySQL Indexes & Histograms
Confoo 2021 - MySQL Indexes & HistogramsConfoo 2021 - MySQL Indexes & Histograms
Confoo 2021 - MySQL Indexes & HistogramsDave Stokes
 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server DatabasesColdFusionConference
 
My SQL Skills Killed the Server
My SQL Skills Killed the ServerMy SQL Skills Killed the Server
My SQL Skills Killed the ServerdevObjective
 
cPanel now supports MySQL 8.0 - My Top Seven Features
cPanel now supports MySQL 8.0 - My Top Seven FeaturescPanel now supports MySQL 8.0 - My Top Seven Features
cPanel now supports MySQL 8.0 - My Top Seven FeaturesDave Stokes
 

Similar to MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014 (20)

How to Think Like the SQL Server Engine
How to Think Like the SQL Server EngineHow to Think Like the SQL Server Engine
How to Think Like the SQL Server Engine
 
What Your Database Query is Really Doing
What Your Database Query is Really DoingWhat Your Database Query is Really Doing
What Your Database Query is Really Doing
 
Helsinki Cassandra Meetup #2: Introduction to CQL3 and DataModeling
Helsinki Cassandra Meetup #2: Introduction to CQL3 and DataModelingHelsinki Cassandra Meetup #2: Introduction to CQL3 and DataModeling
Helsinki Cassandra Meetup #2: Introduction to CQL3 and DataModeling
 
Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...
Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...
Open Source 1010 and Quest InSync presentations March 30th, 2021 on MySQL Ind...
 
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...
PHP UK 2020 Tutorial: MySQL Indexes, Histograms And other ways To Speed Up Yo...
 
Best Practices for Migrating Legacy Data Warehouses into Amazon Redshift
Best Practices for Migrating Legacy Data Warehouses into Amazon RedshiftBest Practices for Migrating Legacy Data Warehouses into Amazon Redshift
Best Practices for Migrating Legacy Data Warehouses into Amazon Redshift
 
MySQL Indexes and Histograms - RMOUG Training Days 2022
MySQL Indexes and Histograms - RMOUG Training Days 2022MySQL Indexes and Histograms - RMOUG Training Days 2022
MySQL Indexes and Histograms - RMOUG Training Days 2022
 
Sql Basics And Advanced
Sql Basics And AdvancedSql Basics And Advanced
Sql Basics And Advanced
 
Introduction to SQL Server Internals: How to Think Like the Engine
Introduction to SQL Server Internals: How to Think Like the EngineIntroduction to SQL Server Internals: How to Think Like the Engine
Introduction to SQL Server Internals: How to Think Like the Engine
 
How to think like the engine
How to think like the engineHow to think like the engine
How to think like the engine
 
Do You Have the Time
Do You Have the TimeDo You Have the Time
Do You Have the Time
 
SQL Query Optimization: Why Is It So Hard to Get Right?
SQL Query Optimization: Why Is It So Hard to Get Right?SQL Query Optimization: Why Is It So Hard to Get Right?
SQL Query Optimization: Why Is It So Hard to Get Right?
 
Five Database Mistakes and how to fix them -- Confoo Vancouver
Five Database Mistakes and how to fix them -- Confoo VancouverFive Database Mistakes and how to fix them -- Confoo Vancouver
Five Database Mistakes and how to fix them -- Confoo Vancouver
 
MySQL New Features -- Sunshine PHP 2020 Presentation
MySQL New Features -- Sunshine PHP 2020 PresentationMySQL New Features -- Sunshine PHP 2020 Presentation
MySQL New Features -- Sunshine PHP 2020 Presentation
 
Sq lite module6
Sq lite module6Sq lite module6
Sq lite module6
 
Confoo 2021 - MySQL Indexes & Histograms
Confoo 2021 - MySQL Indexes & HistogramsConfoo 2021 - MySQL Indexes & Histograms
Confoo 2021 - MySQL Indexes & Histograms
 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server Databases
 
My SQL Skills Killed the Server
My SQL Skills Killed the ServerMy SQL Skills Killed the Server
My SQL Skills Killed the Server
 
Sql killedserver
Sql killedserverSql killedserver
Sql killedserver
 
cPanel now supports MySQL 8.0 - My Top Seven Features
cPanel now supports MySQL 8.0 - My Top Seven FeaturescPanel now supports MySQL 8.0 - My Top Seven Features
cPanel now supports MySQL 8.0 - My Top Seven Features
 

More from Dave Stokes

Json within a relational database
Json within a relational databaseJson within a relational database
Json within a relational databaseDave Stokes
 
Database basics for new-ish developers -- All Things Open October 18th 2021
Database basics for new-ish developers  -- All Things Open October 18th 2021Database basics for new-ish developers  -- All Things Open October 18th 2021
Database basics for new-ish developers -- All Things Open October 18th 2021Dave Stokes
 
Php &amp; my sql - how do pdo, mysq-li, and x devapi do what they do
Php &amp; my sql  - how do pdo, mysq-li, and x devapi do what they doPhp &amp; my sql  - how do pdo, mysq-li, and x devapi do what they do
Php &amp; my sql - how do pdo, mysq-li, and x devapi do what they doDave Stokes
 
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScriptJavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScriptDave Stokes
 
Open Source World June '21 -- JSON Within a Relational Database
Open Source World June '21 -- JSON Within a Relational DatabaseOpen Source World June '21 -- JSON Within a Relational Database
Open Source World June '21 -- JSON Within a Relational DatabaseDave Stokes
 
Dutch PHP Conference 2021 - MySQL Indexes and Histograms
Dutch PHP Conference 2021 - MySQL Indexes and HistogramsDutch PHP Conference 2021 - MySQL Indexes and Histograms
Dutch PHP Conference 2021 - MySQL Indexes and HistogramsDave Stokes
 
Validating JSON -- Percona Live 2021 presentation
Validating JSON -- Percona Live 2021 presentationValidating JSON -- Percona Live 2021 presentation
Validating JSON -- Percona Live 2021 presentationDave Stokes
 
Midwest PHP Presentation - New MSQL Features
Midwest PHP Presentation - New MSQL FeaturesMidwest PHP Presentation - New MSQL Features
Midwest PHP Presentation - New MSQL FeaturesDave Stokes
 
Data Love Conference - Window Functions for Database Analytics
Data Love Conference - Window Functions for Database AnalyticsData Love Conference - Window Functions for Database Analytics
Data Love Conference - Window Functions for Database AnalyticsDave Stokes
 
Confoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New FeaturesConfoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New FeaturesDave Stokes
 
Datacon LA - MySQL without the SQL - Oh my!
Datacon LA - MySQL without the SQL - Oh my! Datacon LA - MySQL without the SQL - Oh my!
Datacon LA - MySQL without the SQL - Oh my! Dave Stokes
 
MySQL Replication Update - DEbconf 2020 presentation
MySQL Replication Update - DEbconf 2020 presentationMySQL Replication Update - DEbconf 2020 presentation
MySQL Replication Update - DEbconf 2020 presentationDave Stokes
 
MySQL 8.0 Operational Changes
MySQL 8.0 Operational ChangesMySQL 8.0 Operational Changes
MySQL 8.0 Operational ChangesDave Stokes
 
A Step by Step Introduction to the MySQL Document Store
A Step by Step Introduction to the MySQL Document StoreA Step by Step Introduction to the MySQL Document Store
A Step by Step Introduction to the MySQL Document StoreDave Stokes
 
Discover The Power of NoSQL + MySQL with MySQL
Discover The Power of NoSQL + MySQL with MySQLDiscover The Power of NoSQL + MySQL with MySQL
Discover The Power of NoSQL + MySQL with MySQLDave Stokes
 
Discover the Power of the NoSQL + SQL with MySQL
Discover the Power of the NoSQL + SQL with MySQLDiscover the Power of the NoSQL + SQL with MySQL
Discover the Power of the NoSQL + SQL with MySQLDave Stokes
 
Confoo 202 - MySQL Group Replication and ReplicaSet
Confoo 202 - MySQL Group Replication and ReplicaSetConfoo 202 - MySQL Group Replication and ReplicaSet
Confoo 202 - MySQL Group Replication and ReplicaSetDave Stokes
 
MySQL 8.0 from December London Open Source Database Meetup
MySQL 8.0 from December London Open Source Database MeetupMySQL 8.0 from December London Open Source Database Meetup
MySQL 8.0 from December London Open Source Database MeetupDave Stokes
 
MySQL 8 - UKOUG Techfest Brighton December 2nd, 2019
MySQL 8 - UKOUG Techfest Brighton December 2nd, 2019MySQL 8 - UKOUG Techfest Brighton December 2nd, 2019
MySQL 8 - UKOUG Techfest Brighton December 2nd, 2019Dave Stokes
 
Upgrading to MySQL 8.0 webinar slides November 27th, 2019
Upgrading to MySQL 8.0 webinar slides November 27th, 2019Upgrading to MySQL 8.0 webinar slides November 27th, 2019
Upgrading to MySQL 8.0 webinar slides November 27th, 2019Dave Stokes
 

More from Dave Stokes (20)

Json within a relational database
Json within a relational databaseJson within a relational database
Json within a relational database
 
Database basics for new-ish developers -- All Things Open October 18th 2021
Database basics for new-ish developers  -- All Things Open October 18th 2021Database basics for new-ish developers  -- All Things Open October 18th 2021
Database basics for new-ish developers -- All Things Open October 18th 2021
 
Php &amp; my sql - how do pdo, mysq-li, and x devapi do what they do
Php &amp; my sql  - how do pdo, mysq-li, and x devapi do what they doPhp &amp; my sql  - how do pdo, mysq-li, and x devapi do what they do
Php &amp; my sql - how do pdo, mysq-li, and x devapi do what they do
 
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScriptJavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
 
Open Source World June '21 -- JSON Within a Relational Database
Open Source World June '21 -- JSON Within a Relational DatabaseOpen Source World June '21 -- JSON Within a Relational Database
Open Source World June '21 -- JSON Within a Relational Database
 
Dutch PHP Conference 2021 - MySQL Indexes and Histograms
Dutch PHP Conference 2021 - MySQL Indexes and HistogramsDutch PHP Conference 2021 - MySQL Indexes and Histograms
Dutch PHP Conference 2021 - MySQL Indexes and Histograms
 
Validating JSON -- Percona Live 2021 presentation
Validating JSON -- Percona Live 2021 presentationValidating JSON -- Percona Live 2021 presentation
Validating JSON -- Percona Live 2021 presentation
 
Midwest PHP Presentation - New MSQL Features
Midwest PHP Presentation - New MSQL FeaturesMidwest PHP Presentation - New MSQL Features
Midwest PHP Presentation - New MSQL Features
 
Data Love Conference - Window Functions for Database Analytics
Data Love Conference - Window Functions for Database AnalyticsData Love Conference - Window Functions for Database Analytics
Data Love Conference - Window Functions for Database Analytics
 
Confoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New FeaturesConfoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New Features
 
Datacon LA - MySQL without the SQL - Oh my!
Datacon LA - MySQL without the SQL - Oh my! Datacon LA - MySQL without the SQL - Oh my!
Datacon LA - MySQL without the SQL - Oh my!
 
MySQL Replication Update - DEbconf 2020 presentation
MySQL Replication Update - DEbconf 2020 presentationMySQL Replication Update - DEbconf 2020 presentation
MySQL Replication Update - DEbconf 2020 presentation
 
MySQL 8.0 Operational Changes
MySQL 8.0 Operational ChangesMySQL 8.0 Operational Changes
MySQL 8.0 Operational Changes
 
A Step by Step Introduction to the MySQL Document Store
A Step by Step Introduction to the MySQL Document StoreA Step by Step Introduction to the MySQL Document Store
A Step by Step Introduction to the MySQL Document Store
 
Discover The Power of NoSQL + MySQL with MySQL
Discover The Power of NoSQL + MySQL with MySQLDiscover The Power of NoSQL + MySQL with MySQL
Discover The Power of NoSQL + MySQL with MySQL
 
Discover the Power of the NoSQL + SQL with MySQL
Discover the Power of the NoSQL + SQL with MySQLDiscover the Power of the NoSQL + SQL with MySQL
Discover the Power of the NoSQL + SQL with MySQL
 
Confoo 202 - MySQL Group Replication and ReplicaSet
Confoo 202 - MySQL Group Replication and ReplicaSetConfoo 202 - MySQL Group Replication and ReplicaSet
Confoo 202 - MySQL Group Replication and ReplicaSet
 
MySQL 8.0 from December London Open Source Database Meetup
MySQL 8.0 from December London Open Source Database MeetupMySQL 8.0 from December London Open Source Database Meetup
MySQL 8.0 from December London Open Source Database Meetup
 
MySQL 8 - UKOUG Techfest Brighton December 2nd, 2019
MySQL 8 - UKOUG Techfest Brighton December 2nd, 2019MySQL 8 - UKOUG Techfest Brighton December 2nd, 2019
MySQL 8 - UKOUG Techfest Brighton December 2nd, 2019
 
Upgrading to MySQL 8.0 webinar slides November 27th, 2019
Upgrading to MySQL 8.0 webinar slides November 27th, 2019Upgrading to MySQL 8.0 webinar slides November 27th, 2019
Upgrading to MySQL 8.0 webinar slides November 27th, 2019
 

Recently uploaded

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 

Recently uploaded (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014

  • 1. MMyySSQQLL QQuueerryy TTuunniinngg FFoorr tthhee SSqquueeeemmiisshh David.Stokes@Oracle.com @stoker
  • 2. Copyright © 2014 Dave Stokes 2 MySQL Optimizer ● The MySQL Cost Based Optimizer wants to optimize each query, every time. Query plans can not be locked in as with Oracle. ● Cost is/was based on disk I/O ● FusionIO, hybrid drives changing cost paradigm – Cost when cost = 0?!? ● Checks Syntax ● Guesstimates costs, looks for cheapest way to do things ● May not be the best way ● How good are your statistics? When was your last ANALYSE TABLE? – Need to run to update stats
  • 3. Logging – find slow queries Log slow queries (time configurable) and queries w/o indexes. MySQL 5.7 allows levels of verbosity. PERFORMANCE_SCHEMA, INFORMATION_SCEMA has tons of useful data. Copyright © 2014 Dave Stokes 3
  • 4. Chapter 8 of the MySQL Manual ● All about optimization ● EXPLAIN MySQL 5.6.3 and later permits explainable statements for EXPLAIN are SELECT, DELETE, INSERT, REPLACE, and UPDATE. Before MySQL 5.6.3, SELECT is the only explainable statement. ● Many developers have been trained in their language of choice, JavaScript, JSON/REST, etc. but very, very few have any SQL training. And many try to use ORMs to make up for their rotten SQL skills or try to force NoSQL technologies for relational data. Copyright © 2014 Dave Stokes 4
  • 5. Copyright © 2014 Dave Stokes 5 Please note
  • 6. Copyright © 2014 Dave Stokes 6 Example 1 This is the ASCII style output of explain versus VE
  • 7. From the Manual – If you want details 8.8.4 Estimating Query Performance ● In most cases, you can estimate query performance by counting disk seeks. For small tables, you can usually find a row in one disk seek (because the index is probably cached). For bigger tables, you can estimate that, using B-tree indexes, you need this many seeks to find a row: log(row_count) / log(index_block_length / 3 * 2 / (index_length + data_pointer_length)) + 1. ● In MySQL, an index block is usually 1,024 bytes and the data pointer is usually four bytes. For a 500,000-row table with a key value length of three bytes (the size of MEDIUMINT), the formula indicates log(500,000)/log(1024/3*2/(3+4)) + 1 = 4 seeks. ● This index would require storage of about 500,000 * 7 * 3/2 = 5.2MB (assuming a typical index buffer fill ratio of 2/3), so you probably have much of the index in memory and so need only one or two calls to read data to find the row. ● For writes, however, you need four seek requests to find where to place a new index value and normally two seeks to update the index and write the row. Copyright © 2014 Dave Stokes 7
  • 8. Previous slide in simpler terms ● Use smallest data type possible. No BIGINT for age or customer id numbers – Are you really going to live to 18,446,744,073,709,551,615? – Use PROCEDUE ANALYSE to find optimal size/type ● Wasted space is moved from disk to memory, memoery to buffer, buffer to network, network to buffer, and/or buffer to disk – Reading off disk 100,000 slower than memory Copyright © 2014 Dave Stokes 8
  • 9. From the Manual – If you want details 8.8.4 Estimating Query Performance ● In most cases, you can estimate query performance by counting disk seeks. For small tables, you can usually find a row in one disk seek (because the index is probably cached). For bigger tables, you can estimate that, using B-tree indexes, you need this many seeks to find a row: log(row_count) / log(index_block_length / 3 * 2 / (index_length + data_pointer_length)) + 1. ● In MySQL, an index block is usually 1,024 bytes and the data pointer is usually four bytes. For a 500,000-row table with a key value length of three bytes (the size of MEDIUMINT), the formula indicates log(500,000)/log(1024/3*2/(3+4)) + 1 = 4 seeks. ● This index would require storage of about 500,000 * 7 * 3/2 = 5.2MB (assuming a typical index buffer fill ratio of 2/3), so you probably have much of the index in memory and so need only one or two calls to read data to find the row. ● For writes, however, you need four seek requests to find where to place a new index value and normally two seeks to update the index and write the row. Copyright © 2014 Dave Stokes 9
  • 10. Chapter 8 is a treasure trove of information. Copyright © 2014 Dave Stokes 10
  • 11. The dreaded B-tree index Copyright © 2014 Dave Stokes 11 ● Docs.Oracle.com
  • 12. Why your query stinks! SELECT CONCAT(customer.last_name, ', ', customer.first_name) AS customer, address.phone, film.title FROM rental INNER JOIN customer ON rental.customer_id = customer.customer_id INNER JOIN address ON customer.address_id = Copyright © 2014 Dave Stokes 12 address.address_id INNER JOIN inventory ON rental.inventory_id = inventory.inventory_id INNER JOIN film ON inventory.film_id = film.film_id WHERE rental.return_date IS NULL AND rental_date + INTERVAL film.rental_duration DAY < CURRENT_DATE() LIMIT 5;
  • 13. Copyright © 2014 Dave Stokes 13 NULL ● Usually used to do designate no value or a lack of data. – Useful for many applications – Screws up indexes as you need to also test values for null. Multiple nulls can kill performance
  • 14. FULL TABLE SCAN – Try to avoid ● FULL TABLE SCAN means each and every row in your table had to be read. If all the table is not in memory, it is made so. Copyright © 2014 Dave Stokes 14 – Not all ways bad ● Sometimes you have to go through all rows – Use indexes to find exact record(s) needed
  • 15. Still have a full table scan Copyright © 2014 Dave Stokes 15
  • 16. Note numbers for rows! Cost!! Estimate that it will take 2,000 reads to get desired data Copyright © 2014 Dave Stokes 16
  • 17. Copyright © 2014 Dave Stokes 17 Simpler Example SELECT City.name, Country.Name FROM City JOIN Country ON (City.CountryCode = Country.Code) LIMIT 5;
  • 18. But I ONLY want FIVE ROWS!! SELECT City.name, Country.Name FROM City JOIN Country ON (City.CountryCode = Country.Code) LIMIT 5; Copyright © 2014 Dave Stokes 18 Still needs to do the join BEFORE grabbing just the first FIVE rows.
  • 19. Add stuff to WHERE to narrow search SELECT City.name, Country.Name FROM City JOIN Country ON (City.CountryCode = Country.Code) WHERE City.Population > 500000 AND District = 'Texas' LIMIT 5; Should really cut down amount of data read, right? Copyright © 2014 Dave Stokes 19
  • 20. Copyright © 2014 Dave Stokes 20 Not Really
  • 21. Copyright © 2014 Dave Stokes 21 Another example ● SELECT * FROM City WHERE Population > 400000
  • 22. Tossing an index at a problem ● CREATE INDEX CityPopIndex ON City (Population) Copyright © 2014 Dave Stokes 22 ● SELECT * FROM City WHERE Population > 400000 Net gain zero
  • 23. ● Optimizer did not use our new index!! Copyright © 2014 Dave Stokes 23
  • 24. The best-laid schemes o’ mice an’ men Gang aft agley ● SELECT * FROM City USE INDEX (CityPopindex) WHERE Population > 400000 ● This is a case where even forcing the index does not help as the Population entries are not unique enough for the optimizer to take advantage of it. Copyright © 2014 Dave Stokes 24
  • 25. Copyright © 2014 Dave Stokes 25 Another example ● SELECT Name FROM City WHERE CountryCode = 'USA' ● 274 rows in world.City have USA as the CountryCode, better than 4K total records in a FULL TABLE SCAN
  • 26. Copyright © 2014 Dave Stokes 26 Using a Join ● SELECT City.Name, Country.name FROM City Join Country ON (Country.code = City.CountryCode) WHERE Country.Population > 4000000 AND City.CountryCode='USA'
  • 27. Copyright © 2014 Dave Stokes 27 Indexes ● An index on City, State, and Zip can be used to look up – City, State, Zip – City, State – City ● Drags Zip along on City, State and saves a read into the data
  • 28. Add a table for zipcodes SHOW CREATE TABLE zipcodesG Copyright © 2014 Dave Stokes 28 Table: zipcodes Create Table: CREATE TABLE `zipcodes` ( `zip` varchar(5) NOT NULL, `type` char(10) DEFAULT NULL, `primary_city` varchar(25) DEFAULT NULL, `accceptable_cities` varchar(50) DEFAULT NULL, `unacceptable_city` varchar(50) DEFAULT NULL, `state` char(2) DEFAULT NULL, `county` varchar(30) DEFAULT NULL, `tz` char(50) DEFAULT NULL, `area_code` varchar(20) DEFAULT NULL, `latitude` decimal(5,0) DEFAULT NULL, `longitude` decimal(5,0) DEFAULT NULL, `world_region` char(4) DEFAULT NULL, `country` char(2) DEFAULT NULL, `decomissioned` int(2) DEFAULT NULL, `est_population` int(10) unsigned DEFAULT NULL, `notes` char(20) DEFAULT NULL, PRIMARY KEY (`zip`), ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  • 29. Lookup up by city name ● SELECT primary_city, state, zip, accceptable_cities FROM zipcodes WHERE primary_city='Roanoke' Copyright © 2014 Dave Stokes 29
  • 30. Copyright © 2014 Dave Stokes 30 Two factors SELECT primary_city, state, zip, accceptable_cities FROM zipcodes WHERE primary_city='Roanoke' AND state='TX'
  • 31. What is we specify all three items? ● SELECT primary_city, state, zip, accceptable_cities FROM zipcodes WHERE primary_city='Roanoke' AND state='TX' AND zip='76262' Optimizer is smart enough to figure that PRIMARY key gives all we need the cheapest Copyright © 2014 Dave Stokes 31
  • 32. Sometimes indexes help a little ● CREATE INDEX cityindex ON zipcodes (primary_city); An index is added on primary_city to facilitate searching by city name Copyright © 2014 Dave Stokes 32
  • 33. Yet another example SELECT primary_city, state, area_code FROM zipcodes USE INDEX (primary) WHERE primary_city='Orlando' AND state='FL' ● Default is a full table scan ● CREATE INDEX citystatearea ON zipcodes (primary_city,state,area_code); Copyright © 2014 Dave Stokes 33
  • 34. More complex query SELECT CONCAT(c.city, _utf8',', cy.country) AS store, CONCAT(m.first_name, _utf8' ', m.last_name) AS manager, SUM(p.amount) AS total_sales FROM payment AS p INNER JOIN rental AS r ON p.rental_id = r.rental_id INNER JOIN inventory AS i ON r.inventory_id = i.inventory_id INNER JOIN store AS s ON i.store_id = s.store_id INNER JOIN address AS a ON s.address_id = a.address_id INNER JOIN city AS c ON a.city_id = c.city_id INNER JOIN country AS cy ON c.country_id = cy.country_id INNER JOIN staff AS m ON s.manager_staff_id = m.staff_id GROUP BY s.store_id ORDER BY cy.country, c.city; Copyright © 2014 Dave Stokes 34
  • 35. Workbench – Mouse Over Blocks ● MySQL Workbench can provide information on queries – Mouse over blocks for details. In this case the query does not require a filesort (slow) to order the query. – SELECT Name FROM City WHERE Population > 100000 or District='Florida' Order by Population limit 10; Note: Full INDEX scan not Full TABLE scan Copyright © 2014 Dave Stokes 35
  • 36. Joins – think sets on rows of data Copyright © 2014 Dave Stokes 36
  • 37. Copyright © 2014 Dave Stokes 37 Books ● Effective MySQL Optimizing SQL Statements – Ronald Bradford ● High Performance MySQL – Schwartz, Zaitsev, Tkachenko
  • 38. Copyright © 2014 Dave Stokes 38 Other resources ● MySQL Manual ● Planet.MySQL.Com ● Forums.MySQL.com – Forums for Performance, Optimizer & Parser, and many more ● MySQL Central @ OpenWorld – Part of Oracle Open World – End of September
  • 39. Copyright © 2014 Dave Stokes 39 Q/A ●David.Stokes@Oracle.com ●@stoker ●Slideshare.net/davestokes