SlideShare a Scribd company logo
1 of 51
Download to read offline
Query 
Optimization 
Morgan 
Tocker 
MySQL 
Community 
Manager 
October, 
2014 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
|
Safe 
Harbor 
Statement 
The 
following 
is 
intended 
to 
outline 
our 
general 
product 
direction. 
It 
is 
intended 
for 
information 
purposes 
only, 
and 
may 
not 
be 
incorporated 
into 
any 
contract. 
It 
is 
not 
a 
commitment 
to 
deliver 
any 
material, 
code, 
or 
functionality, 
and 
should 
not 
be 
relied 
upon 
in 
making 
purchasing 
decisions. 
The 
development, 
release, 
and 
timing 
of 
any 
features 
or 
functionality 
described 
for 
Oracleā€™s 
products 
remains 
at 
the 
sole 
discretion 
of 
Oracle. 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
3
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
4 
Todayā€™s 
Agenda 
Introduction 
World 
Schema 
IMDB 
Schema 
Advanced 
Topics 
1 
2 
3 
4
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
Introduction 
ā€¢ SQL 
is 
declarative. 
ā€¢ You 
say 
what 
you 
want, 
not 
how 
to 
process. 
ā€¢ Canā€™t 
sight 
check 
a 
query 
to 
understand 
how 
it 
executes. 
ā€¢ Database 
management 
chooses 
the 
best 
possible 
way 
-Ā­ā€ 
think 
like 
a 
GPS 
navigator. 
5
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
GPS 
Software 
6
MySQL 
Optimizer 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
7
Diagnostic 
Commands 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
ā€¢ EXPLAIN 
(all 
versions) 
ā€¢ EXPLAIN 
FORMAT=JSON 
(MySQL 
5.6+) 
ā€¢ Workbench 
supports 
visual 
format. 
ā€¢ OPTIMIZER 
TRACE 
(MySQL 
5.6+) 
8
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
9 
Todayā€™s 
Agenda 
Introduction 
World 
Schema 
IMDB 
Schema 
Advanced 
Topics 
1 
2 
3 
4
The 
World 
Schema 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
ā€¢ Contains 
cities, 
countries 
and 
language 
statistics. 
ā€¢ Download 
From: 
ā€¢ http://dev.mysql.com/doc/index-Ā­ā€other.html 
ā€¢ Very 
small 
data 
set 
-Ā­ā€ 
good 
for 
learning. 
ā€¢ Not 
perfect 
for 
explaining 
performance 
differences 
10
Find 
Countries 
in 
Asia 
with 
Population 
>5M 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
11 
mysql> EXPLAIN SELECT * FROM Country WHERE Continent = 
'Asia' AND population > 5000000G 
********************** 1. row ********************** 
id: 1 
select_type: SIMPLE 
table: Country 
partitions: NULL 
type: ALL 
possible_keys: NULL 
key: NULL 
key_len: NULL 
ref: NULL 
rows: 239 
filtered: 4.76 
Extra: Using where 
1 row in set, 1 warning (0.00 sec)
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 12 
EXPLAIN: { 
"query_block": { 
"select_id": 1, 
"cost_info": { 
"query_cost": "53.80" 
}, 
"table": { 
"table_name": "Country", 
"access_type": "ALL", 
"rows_examined_per_scan": 239, 
"rows_produced_per_join": 11, 
"filtered": 4.7614, 
"cost_info": { 
"read_cost": "51.52", 
"eval_cost": "2.28", 
"prefix_cost": "53.80", 
"data_read_per_join": "2K" 
}, 
"used_columns": [ 
"Code", 
.. 
"Capital", 
"Code2" 
], 
"attached_condition": "((`world`.`country`.`Continent` = 'Asia') and 
(`world`.`country`.`Population` > 5000000))" 
} 
} 
} 
FORMAT=JSON 
Available 
since 
MySQL 
5.6. 
Expanded 
in 
5.7 
to 
add 
cost 
information.
What 
indexes 
will 
make 
this 
query 
faster? 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
ā€¢ Some 
suggestions: 
ā€¢ Index 
on 
(population) 
ā€¢ Index 
on 
(continent) 
ā€¢ Index 
on 
(population, 
continent) 
ā€¢ Index 
on 
(continent, 
population) 
13 
SELECT * FROM Country WHERE Continent = 
'Asia' AND population > 5000000;
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
Next 
Question 
ā€¢ Given 
so 
many 
choices, 
which 
is 
the 
best 
choice? 
ā€¢ A 
good 
GPS 
navigator 
understands 
traffic 
and 
finds 
the 
fastest 
route. 
ā€¢ A 
good 
query 
optimizer 
does 
similar. 
14
Query 
Optimizer 
Strategy 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
ā€¢ Pick 
the 
plan 
that 
consumes 
the 
least 
amount 
of 
resources 
(CPU, 
IO). 
15
Query 
Optimizer 
Strategy 
(cont.) 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
ā€¢ Use 
statistics 
available 
to 
identify 
good 
and 
bad 
plans. 
ā€¢ Decisions 
may 
include: 
ā€¢ Which 
indexes 
are 
good/bad. 
ā€¢ Which 
order 
to 
join 
tables 
in. 
ā€¢ If 
indexes 
should 
be 
read 
in 
a 
particular 
order 
to 
avoid 
sorting, 
or 
if 
sorting 
is 
not 
expensive. 
16
Using 
single 
column 
indexes 
firstā€¦. 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
ā€¢ p 
(population) 
ā€¢ c 
(continent) 
17
mysql> ALTER TABLE Country ADD INDEX p (population); 
Query OK, 0 rows affected (0.04 sec) 
Records: 0 Duplicates: 0 Warnings: 0 
mysql> EXPLAIN SELECT * FROM Country WHERE Continent = 
'Asia' AND population > 5000000G 
************************ 1. row ************************ 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 18 
id: 1 
select_type: SIMPLE 
table: Country 
partitions: NULL 
type: ALL 
possible_keys: p 
key: NULL 
key_len: NULL 
ref: NULL 
rows: 239 
filtered: 6.46 
Extra: Using where 
1 row in set, 1 warning (0.00 sec)
Why 
would 
an 
index 
not 
be 
used? 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
19 
mysql> EXPLAIN FORMAT=JSON 
SELECT * FROM Country FORCE 
INDEX (p) WHERE Continent = 
'Asia' AND population > 
5000000G 
******* 1. row ******* 
EXPLAIN: { 
"query_block": { 
"select_id": 1, 
"cost_info": { 
"query_cost": "152.21" 
}, 
"table": { 
"table_name": "Country", 
"access_type": "range", 
"possible_keys": [ 
"p" 
], 
Using 
MySQL 
5.7+ 
mysql> EXPLAIN FORMAT=JSON 
SELECT * FROM Country WHERE 
Continent = 'Asia' AND 
population > 5000000G 
******* 1. row ******* 
EXPLAIN: { 
"query_block": { 
"select_id": 1, 
"cost_info": { 
"query_cost": "53.80" 
}, 
"table": { 
"table_name": "Country", 
"access_type": "ALL", 
"possible_keys": [ 
"p" 
],
Modifying 
the 
query 
range: 
>50M 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
20 
mysql> EXPLAIN SELECT * FROM Country WHERE Continent = 
'Asia' AND population > 50000000G 
********************** 1. row ********************** 
id: 1 
select_type: SIMPLE 
table: Country 
partitions: NULL 
type: range 
possible_keys: p 
key: p 
key_len: 4 
ref: NULL 
rows: 24 
filtered: 14.29 
Extra: Using index condition; Using where 
1 row in set, 1 warning (0.00 sec)
mysql> ALTER TABLE Country ADD INDEX c (continent); 
Query OK, 0 rows affected (0.04 sec) 
Records: 0 Duplicates: 0 Warnings: 0 
mysql> EXPLAIN SELECT * FROM Country WHERE Continent = 
'Asia' AND population > 5000000G 
*********************** 1. row *********************** 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 21 
id: 1 
select_type: SIMPLE 
table: Country 
partitions: NULL 
type: ref 
possible_keys: p,c 
key: c 
key_len: 1 
ref: const 
rows: 51 
filtered: 45.19 
Extra: Using where 
1 row in set, 1 warning (0.00 sec)
Modifying 
the 
query 
range: 
>500M 
mysql> EXPLAIN SELECT * FROM Country WHERE Continent = 
'Asia' AND population > 500000000G 
********************** 1. row ********************** 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 22 
id: 1 
select_type: SIMPLE 
table: Country 
partitions: NULL 
type: range 
possible_keys: p,c 
key: p 
key_len: 4 
ref: NULL 
rows: 2 
filtered: 21.34 
Extra: Using index condition; Using where 
1 row in set, 1 warning (0.00 sec)
Composite 
Indexes 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
ā€¢ On 
>50M 
which 
is 
better? 
ā€¢ (population, 
continent) 
ā€¢ (continent, 
population) 
23
mysql> ALTER TABLE Country ADD INDEX pc (pop..on, co..nt); 
Query OK, 0 rows affected (0.02 sec) 
Records: 0 Duplicates: 0 Warnings: 0 
mysql> EXPLAIN SELECT * FROM Country WHERE Continent = 
'Asia' AND population > 50000000G 
********************** 1. row ********************** 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 24 
id: 1 
select_type: SIMPLE 
table: Country 
partitions: NULL 
type: ref 
possible_keys: p,c,pc 
key: c 
key_len: 1 
ref: const 
rows: 51 
filtered: 10.04 
Extra: Using where 
1 row in set, 1 warning (0.00 sec)
FORCE 
INDEX 
mysql> EXPLAIN SELECT * FROM Country FORCE INDEX (pc) 
WHERE Continent = 'Asia' AND population > 50000000G 
********************** 1. row ********************** 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 25 
id: 1 
select_type: SIMPLE 
table: Country 
partitions: NULL 
type: range 
possible_keys: pc 
key: pc 
key_len: 4 
ref: NULL 
rows: 24 
filtered: 14.29 
Extra: Using index condition 
1 row in set, 1 warning (0.00 sec)
mysql> EXPLAIN FORMAT=JSON SELECT * FROM Country FORCE 
INDEX (pc) WHERE Continent = 'Asia' AND population > 
50000000G 
********************** 1. row ********************** 
EXPLAIN: { 
"query_block": { 
"select_id": 1, 
"cost_info": { 
"query_cost": "34.61" 
}, 
"table": { 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 26 
.. 
], 
"key": "pc", 
"used_key_parts": [ 
"Population" 
], 
.. 
Easier 
to 
see 
with 
JSON 
EXPLAIN
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
Rule 
of 
Thumb 
ā€¢ Index 
on 
(const, 
range) 
instead 
of 
(range, 
const). 
ā€¢ Applies 
to 
all 
databases. 
27
mysql> ALTER TABLE Country ADD INDEX cp (co..nt, pop..on); 
Query OK, 0 rows affected (0.02 sec) 
Records: 0 Duplicates: 0 Warnings: 0 
mysql> EXPLAIN SELECT * FROM Country WHERE Continent = 
'Asia' AND population > 50000000G 
********************** 1. row ********************** 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 28 
id: 1 
select_type: SIMPLE 
table: Country 
partitions: NULL 
type: range 
possible_keys: p,c,pc,cp 
key: cp 
key_len: 5 
ref: NULL 
rows: 11 
filtered: 100.00 
Extra: Using index condition 
1 row in set, 1 warning (0.00 sec)
Where 
Population 
>N. 
Lower 
is 
better. 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
Cost 
Estimates 
29 
5M 50M 500M 
Table 
Scan 53.80 53.80 53.80 
(Population) 152.21 34.61 3.81 
(Continent) 28.20 28.20 28.20 
(Population, 
152.21 34.61 3.81 
Continent) 
(Continent, 
Population) 
24.83 16.41 3.81
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
30 
Todayā€™s 
Agenda 
Introduction 
World 
Schema 
IMDB 
Schema 
Advanced 
Topics 
1 
2 
3 
4
Examples 
Using 
IMDB 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
ā€¢ Larger 
than 
world 
database 
schema. 
ā€¢ Better 
to 
understand 
performance 
differences. 
ā€¢ License 
requires 
data 
to 
be 
regenerated: 
ā€¢ http://imdbpy.sourceforge.net/ 
31
mysql> EXPLAIN SELECT * FROM title WHERE 
title = 'The Lion King'G 
********************** 1. row ********************** 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 32 
id: 1 
select_type: SIMPLE 
table: title 
partitions: NULL 
type: ALL 
possible_keys: NULL 
key: NULL 
key_len: NULL 
ref: NULL 
rows: 2387523 
filtered: 0.50 
Extra: Using where 
1 row in set, 1 warning (0.00 sec) 
Ignore 
EXPLAIN 
time 
Actual 
run 
time 
is 
2.9 
seconds 
(Not 
shown)
mysql> ALTER TABLE title ADD INDEX (title(100)); 
Query OK, 0 rows affected (4.73 sec) 
Records: 0 Duplicates: 0 Warnings: 0 
mysql> EXPLAIN SELECT * FROM title WHERE 
title = 'The Lion King'G 
********************** 1. row ********************** 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 33 
id: 1 
select_type: SIMPLE 
table: title 
partitions: NULL 
type: ref 
possible_keys: title 
key: title 
key_len: 102 
ref: const 
rows: 4 
filtered: 100.00 
Extra: Using where 
1 row in set, 1 warning (0.01 sec) 
From 
2.9 
seconds 
to 
0.0 
seconds 
(!!!)
How 
does 
LIKE 
work? 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
34 
mysql> EXPLAIN SELECT * FROM title WHERE 
title LIKE 'The Lion %'G 
********************** 1. row ********************** 
id: 1 
select_type: SIMPLE 
table: title 
partitions: NULL 
type: range 
possible_keys: title 
key: title 
key_len: 102 
ref: NULL 
rows: 109 
filtered: 100.00 
Extra: Using where 
1 row in set, 1 warning (0.01 sec)
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
LIKE 
(cont.) 
35 
mysql> EXPLAIN SELECT * FROM title WHERE title 
LIKE 'The%'G 
********************** 1. row ********************** 
id: 1 
select_type: SIMPLE 
table: title 
partitions: NULL 
type: range 
possible_keys: title 
key: title 
key_len: 102 
ref: NULL 
rows: 325548 
filtered: 100.00 
Extra: Using where 
1 row in set, 1 warning (0.00 sec) 
VS 
Very 
Close. 
Estimate 
is 
that 
it 
is 
almost 
as 
fast 
to 
table 
scan. 
Run 
Time 
is 
1.9 
sec
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
Sorting 
36 
mysql> EXPLAIN SELECT * FROM title WHERE 
title = 'The Lion King' ORDER BY production_yearG 
********************** 1. row ********************** 
id: 1 
select_type: SIMPLE 
table: title 
partitions: NULL 
type: ref 
possible_keys: title 
key: title 
key_len: 102 
ref: const 
rows: 4 
filtered: 100.00 
Extra: Using where; Using filesort 
1 row in set, 1 warning (0.00 sec)
SELECT movie_info.* FROM title INNER JOIN movie_info ON 
title.id=movie_info.movie_id WHERE title=ā€˜The Lion Kingā€™G 
********************** 1. row ********************** 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 37 
id: 1 
select_type: SIMPLE 
table: movie_info 
type: ALL 
possible_keys: NULL 
key: NULL 
key_len: NULL 
ref: NULL 
rows: 1212187 
Extra: NULL 
********************** 2. row ********************** 
id: 1 
select_type: SIMPLE 
table: title 
type: eq_ref 
possible_keys: PRIMARY,title 
key: PRIMARY 
key_len: 4 
ref: imdb.movie_info.movie_id 
rows: 1 
Extra: Using where
mysql> ALTER TABLE movie_info ADD INDEX mi (movie_id); 
Query OK, 0 rows affected (1.95 sec) 
Records: 0 Duplicates: 0 Warnings: 0 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 38
EXPLAIN SELECT movie_info.* FROM title INNER .. WHERE 
title='The Lion King'G 
********************** 1. row ********************** 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 39 
id: 1 
select_type: SIMPLE 
table: title 
type: ref 
possible_keys: PRIMARY,title 
key: title 
key_len: 102 
ref: const 
rows: 4 
Extra: Using where 
********************** 2. row ********************** 
id: 1 
select_type: SIMPLE 
table: movie_info 
type: ref 
possible_keys: mi 
key: mi 
key_len: 4 
ref: imdb.title.id 
rows: 7 
Extra: NULL
mysql> EXPLAIN SELECT * FROM movie_info WHERE movie_id IN 
(SELECT id FROM title WHERE title = 'The Lion King')G 
********************** 1. row ********************** 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 40 
id: 1 
select_type: SIMPLE 
table: title 
type: ref 
possible_keys: PRIMARY,title 
key: title 
key_len: 102 
ref: const 
rows: 4 
Extra: Using where 
********************** 2. row ********************** 
id: 1 
select_type: SIMPLE 
table: movie_info 
type: ref 
possible_keys: mi 
key: mi 
key_len: 4 
ref: imdb.title.id 
rows: 7 
Extra: NULL
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
41 
Todayā€™s 
Agenda 
Introduction 
World 
Schema 
IMDB 
Schema 
Advanced 
Topics 
1 
2 
3 
4
Optimizer 
Hints 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
ā€¢ USE 
INDEX 
ā€¢ FORCE 
INDEX 
ā€¢ IGNORE 
INDEX 
ā€¢ STRAIGHT 
JOIN 
42
Optimizer 
Hints 
(cont.) 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
43 
Expanded 
in 
MySQL 
5.6 
mysql> select @@optimizer_switchG 
********************** 1. row ********************** 
@@optimizer_switch: 
index_merge=on,index_merge_union=on,index_merge_sort_union 
=on,index_merge_intersection=on,engine_condition_pushdown= 
on,index_condition_pushdown=on,mrr=on,mrr_cost_based=on,bl 
ock_nested_loop=on,batched_key_access=off,materialization= 
on,semijoin=on,loosescan=on,firstmatch=on,subquery_materia 
lization_cost_based=on,use_index_extensions=on,condition_f 
anout_filter=on 
1 row in set (0.00 sec)
Statistics 
Sampling 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
ā€¢ Some 
decisions 
based 
on 
pre-Ā­ā€computed 
statistics. 
ā€¢ For 
example, 
which 
order 
to 
join 
tables. 
ā€¢ Accuracy 
of 
statistics 
greatly 
improved 
in 
MySQL 
5.6. 
ā€¢ Feature 
is 
called 
ā€œInnoDB 
persistent 
statisticsā€. 
44
Optimizer 
Decision 
Visibility 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
ā€¢ Intended 
for 
MySQL 
developer 
usage, 
and 
reporting 
optimizer 
bugs. 
ā€¢ Yet 
totally 
practical 
for 
advanced 
usage 
:) 
45 
New 
to 
MySQL 
5.6 
SET optimizer_trace="enabled=on"; 
SELECT /* query here */; 
SELECT * FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE;
Optimizer 
Trace 
Output 
ā€¢ Includes 
why 
decisions 
were 
not 
made: 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
46 
.. 
"index": "pc", 
"ranges": [ 
"50000000 < Population" 
], 
"index_dives_for_eq_ranges": true, 
"rowid_ordered": false, 
"using_mrr": false, 
"index_only": false, 
"rows": 24, 
"cost": 29.81, 
"chosen": false, 
"cause": "cost" 
},
Too 
many 
indexes 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
ā€¢ Slows 
down 
modifications 
due 
to 
maintenance 
cost. 
ā€¢ i.e. 
Slower 
INSERT/UPDATE/DELETE 
ā€¢ May 
also 
lead 
to 
worse 
decisions 
being 
made 
by 
optimizer. 
ā€¢ Too 
many 
similar 
choices. 
ā€¢ Only 
limited 
time 
window 
to 
evaluate 
suitability. 
ā€¢ Space 
requirements 
in 
memory 
and 
storage. 
47
MySQL 
5.7 
and 
beyond 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
ā€¢ We 
are 
working 
on 
a 
new 
cost 
model. 
ā€¢ Better 
adapt 
to 
new 
hardware 
with 
different 
costs 
(i.e. 
SSDs 
have 
cheap 
random 
IO). 
ā€¢ Memory 
buffer 
aware 
cost 
estimates. 
48
Cost 
constants 
configurable 
per 
engine 
in 
5.7 
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
ā€¢ Previously 
hard-Ā­ā€coded 
constants. 
ā€¢ Better 
adapts 
to 
differences 
in 
hardware. 
49
Copyright 
Ā© 
2014 
Oracle 
and/or 
its 
affiliates. 
All 
rights 
reserved. 
| 
50
MySQL Query Optimization

More Related Content

What's hot

Performance Schema and Sys Schema in MySQL 5.7
Performance Schema and Sys Schema in MySQL 5.7Performance Schema and Sys Schema in MySQL 5.7
Performance Schema and Sys Schema in MySQL 5.7Mark Leith
Ā 
PhĆ¢n tĆ­ch, thiįŗæt kįŗæ hį»‡ thį»‘ng thĆ“ng tin quįŗ£n lĆ½ nhĆ¢n sį»± tįŗ”i CĆ“ng ty Du Lį»‹ch
PhĆ¢n tĆ­ch, thiįŗæt kįŗæ hį»‡ thį»‘ng thĆ“ng tin quįŗ£n lĆ½ nhĆ¢n sį»± tįŗ”i CĆ“ng ty Du Lį»‹chPhĆ¢n tĆ­ch, thiįŗæt kįŗæ hį»‡ thį»‘ng thĆ“ng tin quįŗ£n lĆ½ nhĆ¢n sį»± tįŗ”i CĆ“ng ty Du Lį»‹ch
PhĆ¢n tĆ­ch, thiįŗæt kįŗæ hį»‡ thį»‘ng thĆ“ng tin quįŗ£n lĆ½ nhĆ¢n sį»± tįŗ”i CĆ“ng ty Du Lį»‹chDį»‹ch vį»„ LĆ m Luįŗ­n Văn 0936885877
Ā 
PhĆ¢n tĆ­ch cįŗ£m xĆŗc trong tiįŗæng viį»‡t bįŗ±ng phĘ°Ę”ng phĆ”p mĆ”y hį»c.pdf
PhĆ¢n tĆ­ch cįŗ£m xĆŗc trong tiįŗæng viį»‡t bįŗ±ng phĘ°Ę”ng phĆ”p mĆ”y hį»c.pdfPhĆ¢n tĆ­ch cįŗ£m xĆŗc trong tiįŗæng viį»‡t bįŗ±ng phĘ°Ę”ng phĆ”p mĆ”y hį»c.pdf
PhĆ¢n tĆ­ch cįŗ£m xĆŗc trong tiįŗæng viį»‡t bįŗ±ng phĘ°Ę”ng phĆ”p mĆ”y hį»c.pdfMan_Ebook
Ā 
Lab mcsa 2016 tieng viet new star
Lab mcsa 2016 tieng viet   new starLab mcsa 2016 tieng viet   new star
Lab mcsa 2016 tieng viet new starNinhnd Nguyen
Ā 
bao cao linux
bao cao linuxbao cao linux
bao cao linuxbinhnv186
Ā 
Disaster Recovery with MySQL InnoDB ClusterSet - What is it and how do I use it?
Disaster Recovery with MySQL InnoDB ClusterSet - What is it and how do I use it?Disaster Recovery with MySQL InnoDB ClusterSet - What is it and how do I use it?
Disaster Recovery with MySQL InnoDB ClusterSet - What is it and how do I use it?Miguel AraĆŗjo
Ā 
NghiĆŖn cį»©u vĆ  triį»ƒn khai hį»‡ thį»‘ng Private Cloud cho cĆ”c į»©ng dį»„ng đƠo tįŗ”o vĆ  t...
NghiĆŖn cį»©u vĆ  triį»ƒn khai hį»‡ thį»‘ng Private Cloud cho cĆ”c į»©ng dį»„ng đƠo tįŗ”o vĆ  t...NghiĆŖn cį»©u vĆ  triį»ƒn khai hį»‡ thį»‘ng Private Cloud cho cĆ”c į»©ng dį»„ng đƠo tįŗ”o vĆ  t...
NghiĆŖn cį»©u vĆ  triį»ƒn khai hį»‡ thį»‘ng Private Cloud cho cĆ”c į»©ng dį»„ng đƠo tįŗ”o vĆ  t...Nhįŗ­n Viįŗæt Đį» TĆ i Trį»n GĆ³i ZALO 0932091562
Ā 
MySQL Performance Schema in 20 Minutes
 MySQL Performance Schema in 20 Minutes MySQL Performance Schema in 20 Minutes
MySQL Performance Schema in 20 MinutesSveta Smirnova
Ā 
MySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA ToolMySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA ToolMiguel AraĆŗjo
Ā 
[Đį»“ Ć”n mĆ“n hį»c] - Đį» tĆ i: NghiĆŖn cį»©u xĆ¢y dį»±ng giįŗ£i phĆ”p thu thįŗ­p vĆ  quįŗ£n lĆ½ ...
[Đį»“ Ć”n mĆ“n hį»c] - Đį» tĆ i: NghiĆŖn cį»©u xĆ¢y dį»±ng giįŗ£i phĆ”p thu thįŗ­p  vĆ  quįŗ£n lĆ½ ...[Đį»“ Ć”n mĆ“n hį»c] - Đį» tĆ i: NghiĆŖn cį»©u xĆ¢y dį»±ng giįŗ£i phĆ”p thu thįŗ­p  vĆ  quįŗ£n lĆ½ ...
[Đį»“ Ć”n mĆ“n hį»c] - Đį» tĆ i: NghiĆŖn cį»©u xĆ¢y dį»±ng giįŗ£i phĆ”p thu thįŗ­p vĆ  quįŗ£n lĆ½ ...Ɲ NhĘ° LĆŖ
Ā 
MySQL Database Architectures - InnoDB ReplicaSet & Cluster
MySQL Database Architectures - InnoDB ReplicaSet & ClusterMySQL Database Architectures - InnoDB ReplicaSet & Cluster
MySQL Database Architectures - InnoDB ReplicaSet & ClusterKenny Gryp
Ā 
JSON improvements in MySQL 8.0
JSON improvements in MySQL 8.0JSON improvements in MySQL 8.0
JSON improvements in MySQL 8.0Mydbops
Ā 
BĆ i giįŗ£ng an toĆ n į»©ng dį»„ng web vĆ  csdl PTIT
BĆ i giįŗ£ng an toĆ n į»©ng dį»„ng web vĆ  csdl PTITBĆ i giįŗ£ng an toĆ n į»©ng dį»„ng web vĆ  csdl PTIT
BĆ i giįŗ£ng an toĆ n į»©ng dį»„ng web vĆ  csdl PTITNguynMinh294
Ā 
The MySQL Query Optimizer Explained Through Optimizer Trace
The MySQL Query Optimizer Explained Through Optimizer TraceThe MySQL Query Optimizer Explained Through Optimizer Trace
The MySQL Query Optimizer Explained Through Optimizer Traceoysteing
Ā 
MySQL Day Roma - MySQL Shell and Visual Studio Code Extension
MySQL Day Roma - MySQL Shell and Visual Studio Code ExtensionMySQL Day Roma - MySQL Shell and Visual Studio Code Extension
MySQL Day Roma - MySQL Shell and Visual Studio Code ExtensionFrederic Descamps
Ā 
AWS RDS Benchmark - Instance comparison
AWS RDS Benchmark - Instance comparisonAWS RDS Benchmark - Instance comparison
AWS RDS Benchmark - Instance comparisonRoberto Gaiser
Ā 
Sį»­ dį»„ng API Leaflet chi tiįŗæt cĆ”c chį»©c năng
Sį»­ dį»„ng API Leaflet chi tiįŗæt cĆ”c chį»©c năngSį»­ dį»„ng API Leaflet chi tiįŗæt cĆ”c chį»©c năng
Sį»­ dį»„ng API Leaflet chi tiįŗæt cĆ”c chį»©c năngHao CT
Ā 
Lįŗ­p trƬnh hĘ°į»›ng đį»‘i tĘ°į»£ng vį»›i C++
Lįŗ­p trƬnh hĘ°į»›ng đį»‘i tĘ°į»£ng vį»›i C++Lįŗ­p trƬnh hĘ°į»›ng đį»‘i tĘ°į»£ng vį»›i C++
Lįŗ­p trƬnh hĘ°į»›ng đį»‘i tĘ°į»£ng vį»›i C++Trįŗ§n ThiĆŖn Đįŗ”i
Ā 
Introduction to the Mysteries of ClickHouse Replication, By Robert Hodges and...
Introduction to the Mysteries of ClickHouse Replication, By Robert Hodges and...Introduction to the Mysteries of ClickHouse Replication, By Robert Hodges and...
Introduction to the Mysteries of ClickHouse Replication, By Robert Hodges and...Altinity Ltd
Ā 

What's hot (20)

Performance Schema and Sys Schema in MySQL 5.7
Performance Schema and Sys Schema in MySQL 5.7Performance Schema and Sys Schema in MySQL 5.7
Performance Schema and Sys Schema in MySQL 5.7
Ā 
PhĆ¢n tĆ­ch, thiįŗæt kįŗæ hį»‡ thį»‘ng thĆ“ng tin quįŗ£n lĆ½ nhĆ¢n sį»± tįŗ”i CĆ“ng ty Du Lį»‹ch
PhĆ¢n tĆ­ch, thiįŗæt kįŗæ hį»‡ thį»‘ng thĆ“ng tin quįŗ£n lĆ½ nhĆ¢n sį»± tįŗ”i CĆ“ng ty Du Lį»‹chPhĆ¢n tĆ­ch, thiįŗæt kįŗæ hį»‡ thį»‘ng thĆ“ng tin quįŗ£n lĆ½ nhĆ¢n sį»± tįŗ”i CĆ“ng ty Du Lį»‹ch
PhĆ¢n tĆ­ch, thiįŗæt kįŗæ hį»‡ thį»‘ng thĆ“ng tin quįŗ£n lĆ½ nhĆ¢n sį»± tįŗ”i CĆ“ng ty Du Lį»‹ch
Ā 
PhĆ¢n tĆ­ch cįŗ£m xĆŗc trong tiįŗæng viį»‡t bįŗ±ng phĘ°Ę”ng phĆ”p mĆ”y hį»c.pdf
PhĆ¢n tĆ­ch cįŗ£m xĆŗc trong tiįŗæng viį»‡t bįŗ±ng phĘ°Ę”ng phĆ”p mĆ”y hį»c.pdfPhĆ¢n tĆ­ch cįŗ£m xĆŗc trong tiįŗæng viį»‡t bįŗ±ng phĘ°Ę”ng phĆ”p mĆ”y hį»c.pdf
PhĆ¢n tĆ­ch cįŗ£m xĆŗc trong tiįŗæng viį»‡t bįŗ±ng phĘ°Ę”ng phĆ”p mĆ”y hį»c.pdf
Ā 
Lab mcsa 2016 tieng viet new star
Lab mcsa 2016 tieng viet   new starLab mcsa 2016 tieng viet   new star
Lab mcsa 2016 tieng viet new star
Ā 
bao cao linux
bao cao linuxbao cao linux
bao cao linux
Ā 
Disaster Recovery with MySQL InnoDB ClusterSet - What is it and how do I use it?
Disaster Recovery with MySQL InnoDB ClusterSet - What is it and how do I use it?Disaster Recovery with MySQL InnoDB ClusterSet - What is it and how do I use it?
Disaster Recovery with MySQL InnoDB ClusterSet - What is it and how do I use it?
Ā 
NghiĆŖn cį»©u vĆ  triį»ƒn khai hį»‡ thį»‘ng Private Cloud cho cĆ”c į»©ng dį»„ng đƠo tįŗ”o vĆ  t...
NghiĆŖn cį»©u vĆ  triį»ƒn khai hį»‡ thį»‘ng Private Cloud cho cĆ”c į»©ng dį»„ng đƠo tįŗ”o vĆ  t...NghiĆŖn cį»©u vĆ  triį»ƒn khai hį»‡ thį»‘ng Private Cloud cho cĆ”c į»©ng dį»„ng đƠo tįŗ”o vĆ  t...
NghiĆŖn cį»©u vĆ  triį»ƒn khai hį»‡ thį»‘ng Private Cloud cho cĆ”c į»©ng dį»„ng đƠo tįŗ”o vĆ  t...
Ā 
MySQL Performance Schema in 20 Minutes
 MySQL Performance Schema in 20 Minutes MySQL Performance Schema in 20 Minutes
MySQL Performance Schema in 20 Minutes
Ā 
MySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA ToolMySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA Tool
Ā 
[Đį»“ Ć”n mĆ“n hį»c] - Đį» tĆ i: NghiĆŖn cį»©u xĆ¢y dį»±ng giįŗ£i phĆ”p thu thįŗ­p vĆ  quįŗ£n lĆ½ ...
[Đį»“ Ć”n mĆ“n hį»c] - Đį» tĆ i: NghiĆŖn cį»©u xĆ¢y dį»±ng giįŗ£i phĆ”p thu thįŗ­p  vĆ  quįŗ£n lĆ½ ...[Đį»“ Ć”n mĆ“n hį»c] - Đį» tĆ i: NghiĆŖn cį»©u xĆ¢y dį»±ng giįŗ£i phĆ”p thu thįŗ­p  vĆ  quįŗ£n lĆ½ ...
[Đį»“ Ć”n mĆ“n hį»c] - Đį» tĆ i: NghiĆŖn cį»©u xĆ¢y dį»±ng giįŗ£i phĆ”p thu thįŗ­p vĆ  quįŗ£n lĆ½ ...
Ā 
MySQL Database Architectures - InnoDB ReplicaSet & Cluster
MySQL Database Architectures - InnoDB ReplicaSet & ClusterMySQL Database Architectures - InnoDB ReplicaSet & Cluster
MySQL Database Architectures - InnoDB ReplicaSet & Cluster
Ā 
JSON improvements in MySQL 8.0
JSON improvements in MySQL 8.0JSON improvements in MySQL 8.0
JSON improvements in MySQL 8.0
Ā 
Luįŗ­n văn: TƬm hiį»ƒu giįŗ£i phĆ”p įŗ£o hĆ³a docker vĆ  į»©ng dį»„ng, HOT
Luįŗ­n văn: TƬm hiį»ƒu giįŗ£i phĆ”p įŗ£o hĆ³a docker vĆ  į»©ng dį»„ng, HOTLuįŗ­n văn: TƬm hiį»ƒu giįŗ£i phĆ”p įŗ£o hĆ³a docker vĆ  į»©ng dį»„ng, HOT
Luįŗ­n văn: TƬm hiį»ƒu giįŗ£i phĆ”p įŗ£o hĆ³a docker vĆ  į»©ng dį»„ng, HOT
Ā 
BĆ i giįŗ£ng an toĆ n į»©ng dį»„ng web vĆ  csdl PTIT
BĆ i giįŗ£ng an toĆ n į»©ng dį»„ng web vĆ  csdl PTITBĆ i giįŗ£ng an toĆ n į»©ng dį»„ng web vĆ  csdl PTIT
BĆ i giįŗ£ng an toĆ n į»©ng dį»„ng web vĆ  csdl PTIT
Ā 
The MySQL Query Optimizer Explained Through Optimizer Trace
The MySQL Query Optimizer Explained Through Optimizer TraceThe MySQL Query Optimizer Explained Through Optimizer Trace
The MySQL Query Optimizer Explained Through Optimizer Trace
Ā 
MySQL Day Roma - MySQL Shell and Visual Studio Code Extension
MySQL Day Roma - MySQL Shell and Visual Studio Code ExtensionMySQL Day Roma - MySQL Shell and Visual Studio Code Extension
MySQL Day Roma - MySQL Shell and Visual Studio Code Extension
Ā 
AWS RDS Benchmark - Instance comparison
AWS RDS Benchmark - Instance comparisonAWS RDS Benchmark - Instance comparison
AWS RDS Benchmark - Instance comparison
Ā 
Sį»­ dį»„ng API Leaflet chi tiįŗæt cĆ”c chį»©c năng
Sį»­ dį»„ng API Leaflet chi tiįŗæt cĆ”c chį»©c năngSį»­ dį»„ng API Leaflet chi tiįŗæt cĆ”c chį»©c năng
Sį»­ dį»„ng API Leaflet chi tiįŗæt cĆ”c chį»©c năng
Ā 
Lįŗ­p trƬnh hĘ°į»›ng đį»‘i tĘ°į»£ng vį»›i C++
Lįŗ­p trƬnh hĘ°į»›ng đį»‘i tĘ°į»£ng vį»›i C++Lįŗ­p trƬnh hĘ°į»›ng đį»‘i tĘ°į»£ng vį»›i C++
Lįŗ­p trƬnh hĘ°į»›ng đį»‘i tĘ°į»£ng vį»›i C++
Ā 
Introduction to the Mysteries of ClickHouse Replication, By Robert Hodges and...
Introduction to the Mysteries of ClickHouse Replication, By Robert Hodges and...Introduction to the Mysteries of ClickHouse Replication, By Robert Hodges and...
Introduction to the Mysteries of ClickHouse Replication, By Robert Hodges and...
Ā 

Viewers also liked

MySQL Architecture and Engine
MySQL Architecture and EngineMySQL Architecture and Engine
MySQL Architecture and EngineAbdul Manaf
Ā 
MariaDB: Connect Storage Engine
MariaDB: Connect Storage EngineMariaDB: Connect Storage Engine
MariaDB: Connect Storage EngineKangaroot
Ā 
InnoDB Architecture and Performance Optimization, Peter Zaitsev
InnoDB Architecture and Performance Optimization, Peter ZaitsevInnoDB Architecture and Performance Optimization, Peter Zaitsev
InnoDB Architecture and Performance Optimization, Peter ZaitsevFuenteovejuna
Ā 
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
Ā 
Advanced MySQL Query Tuning
Advanced MySQL Query TuningAdvanced MySQL Query Tuning
Advanced MySQL Query TuningAlexander Rubin
Ā 
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
Ā 
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
Ā 
Locking and Concurrency Control
Locking and Concurrency ControlLocking and Concurrency Control
Locking and Concurrency ControlMorgan Tocker
Ā 
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 Tuningļæ¼Advanced MySQL Query and Schema Tuning
ļæ¼Advanced MySQL Query and Schema TuningMYXPLAIN
Ā 
My sql optimization
My sql optimizationMy sql optimization
My sql optimizationPrelovacMedia
Ā 
Optimizing MySQL
Optimizing MySQLOptimizing MySQL
Optimizing MySQLMorgan Tocker
Ā 
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.Remote MySQL DBA
Ā 
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
Ā 

Viewers also liked (20)

MySQL Architecture and Engine
MySQL Architecture and EngineMySQL Architecture and Engine
MySQL Architecture and Engine
Ā 
MariaDB: Connect Storage Engine
MariaDB: Connect Storage EngineMariaDB: Connect Storage Engine
MariaDB: Connect Storage Engine
Ā 
InnoDB Architecture and Performance Optimization, Peter Zaitsev
InnoDB Architecture and Performance Optimization, Peter ZaitsevInnoDB Architecture and Performance Optimization, Peter Zaitsev
InnoDB Architecture and Performance Optimization, Peter Zaitsev
Ā 
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
Ā 
Zurich2007 MySQL Query Optimization
Zurich2007 MySQL Query OptimizationZurich2007 MySQL Query Optimization
Zurich2007 MySQL Query Optimization
Ā 
Advanced MySQL Query Tuning
Advanced MySQL Query TuningAdvanced MySQL Query Tuning
Advanced MySQL Query Tuning
Ā 
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
Ā 
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
Ā 
Locking and Concurrency Control
Locking and Concurrency ControlLocking and Concurrency Control
Locking and Concurrency Control
Ā 
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 Tuningļæ¼Advanced MySQL Query and Schema Tuning
ļæ¼Advanced MySQL Query and Schema Tuning
Ā 
My sql optimization
My sql optimizationMy sql optimization
My sql optimization
Ā 
Optimizing MySQL
Optimizing MySQLOptimizing MySQL
Optimizing MySQL
Ā 
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
Ā 

Similar to MySQL Query Optimization

MySQL 8.0 Released Update
MySQL 8.0 Released UpdateMySQL 8.0 Released Update
MySQL 8.0 Released UpdateKeith Hollman
Ā 
Five more things about Oracle SQL and PLSQL
Five more things about Oracle SQL and PLSQLFive more things about Oracle SQL and PLSQL
Five more things about Oracle SQL and PLSQLConnor McDonald
Ā 
Solr JDBC - Lucene/Solr Revolution 2016
Solr JDBC - Lucene/Solr Revolution 2016Solr JDBC - Lucene/Solr Revolution 2016
Solr JDBC - Lucene/Solr Revolution 2016Kevin Risden
Ā 
Histogram Support in MySQL 8.0
Histogram Support in MySQL 8.0Histogram Support in MySQL 8.0
Histogram Support in MySQL 8.0oysteing
Ā 
Sql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices ISql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices ICarlos Oliveira
Ā 
Developers' mDay 2017. - Bogdan Kecman Oracle
Developers' mDay 2017. - Bogdan Kecman OracleDevelopers' mDay 2017. - Bogdan Kecman Oracle
Developers' mDay 2017. - Bogdan Kecman OraclemCloud
Ā 
Developersā€™ mDay u Banjoj Luci - Bogdan Kecman, Oracle ā€“ MySQL Server 8.0
Developersā€™ mDay u Banjoj Luci - Bogdan Kecman, Oracle ā€“ MySQL Server 8.0Developersā€™ mDay u Banjoj Luci - Bogdan Kecman, Oracle ā€“ MySQL Server 8.0
Developersā€™ mDay u Banjoj Luci - Bogdan Kecman, Oracle ā€“ MySQL Server 8.0mCloud
Ā 
Advanced SQL - Quebec 2014
Advanced SQL - Quebec 2014Advanced SQL - Quebec 2014
Advanced SQL - Quebec 2014Connor McDonald
Ā 
Lessons learned from Isbank - A Story of a DB2 for z/OS Initiative
Lessons learned from Isbank - A Story of a DB2 for z/OS InitiativeLessons learned from Isbank - A Story of a DB2 for z/OS Initiative
Lessons learned from Isbank - A Story of a DB2 for z/OS InitiativeCuneyt Goksu
Ā 
Solr JDBC: Presented by Kevin Risden, Avalon Consulting
Solr JDBC: Presented by Kevin Risden, Avalon ConsultingSolr JDBC: Presented by Kevin Risden, Avalon Consulting
Solr JDBC: Presented by Kevin Risden, Avalon ConsultingLucidworks
Ā 
Top 10 tips for Oracle performance
Top 10 tips for Oracle performanceTop 10 tips for Oracle performance
Top 10 tips for Oracle performanceGuy Harrison
Ā 
MySQL 5.7: Core Server Changes
MySQL 5.7: Core Server ChangesMySQL 5.7: Core Server Changes
MySQL 5.7: Core Server ChangesMorgan Tocker
Ā 
How to analyze and tune sql queries for better performance percona15
How to analyze and tune sql queries for better performance percona15How to analyze and tune sql queries for better performance percona15
How to analyze and tune sql queries for better performance percona15oysteing
Ā 
OQL querying and indexes with Apache Geode (incubating)
OQL querying and indexes with Apache Geode (incubating)OQL querying and indexes with Apache Geode (incubating)
OQL querying and indexes with Apache Geode (incubating)Jason Huynh
Ā 
What's New MySQL 8.0?
What's New MySQL 8.0?What's New MySQL 8.0?
What's New MySQL 8.0?OracleMySQL
Ā 
MySQL Troubleshooting with the Performance Schema
MySQL Troubleshooting with the Performance SchemaMySQL Troubleshooting with the Performance Schema
MySQL Troubleshooting with the Performance SchemaSveta Smirnova
Ā 
Confoo 2021 - MySQL Indexes & Histograms
Confoo 2021 - MySQL Indexes & HistogramsConfoo 2021 - MySQL Indexes & Histograms
Confoo 2021 - MySQL Indexes & HistogramsDave Stokes
Ā 
How to analyze and tune sql queries for better performance webinar
How to analyze and tune sql queries for better performance webinarHow to analyze and tune sql queries for better performance webinar
How to analyze and tune sql queries for better performance webinaroysteing
Ā 
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)Dave Stokes
Ā 

Similar to MySQL Query Optimization (20)

MySQL 8.0 Released Update
MySQL 8.0 Released UpdateMySQL 8.0 Released Update
MySQL 8.0 Released Update
Ā 
Five more things about Oracle SQL and PLSQL
Five more things about Oracle SQL and PLSQLFive more things about Oracle SQL and PLSQL
Five more things about Oracle SQL and PLSQL
Ā 
Solr JDBC - Lucene/Solr Revolution 2016
Solr JDBC - Lucene/Solr Revolution 2016Solr JDBC - Lucene/Solr Revolution 2016
Solr JDBC - Lucene/Solr Revolution 2016
Ā 
Histogram Support in MySQL 8.0
Histogram Support in MySQL 8.0Histogram Support in MySQL 8.0
Histogram Support in MySQL 8.0
Ā 
Sql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices ISql and PL/SQL Best Practices I
Sql and PL/SQL Best Practices I
Ā 
Developers' mDay 2017. - Bogdan Kecman Oracle
Developers' mDay 2017. - Bogdan Kecman OracleDevelopers' mDay 2017. - Bogdan Kecman Oracle
Developers' mDay 2017. - Bogdan Kecman Oracle
Ā 
Developersā€™ mDay u Banjoj Luci - Bogdan Kecman, Oracle ā€“ MySQL Server 8.0
Developersā€™ mDay u Banjoj Luci - Bogdan Kecman, Oracle ā€“ MySQL Server 8.0Developersā€™ mDay u Banjoj Luci - Bogdan Kecman, Oracle ā€“ MySQL Server 8.0
Developersā€™ mDay u Banjoj Luci - Bogdan Kecman, Oracle ā€“ MySQL Server 8.0
Ā 
Advanced SQL - Quebec 2014
Advanced SQL - Quebec 2014Advanced SQL - Quebec 2014
Advanced SQL - Quebec 2014
Ā 
Day 6.pptx
Day 6.pptxDay 6.pptx
Day 6.pptx
Ā 
Lessons learned from Isbank - A Story of a DB2 for z/OS Initiative
Lessons learned from Isbank - A Story of a DB2 for z/OS InitiativeLessons learned from Isbank - A Story of a DB2 for z/OS Initiative
Lessons learned from Isbank - A Story of a DB2 for z/OS Initiative
Ā 
Solr JDBC: Presented by Kevin Risden, Avalon Consulting
Solr JDBC: Presented by Kevin Risden, Avalon ConsultingSolr JDBC: Presented by Kevin Risden, Avalon Consulting
Solr JDBC: Presented by Kevin Risden, Avalon Consulting
Ā 
Top 10 tips for Oracle performance
Top 10 tips for Oracle performanceTop 10 tips for Oracle performance
Top 10 tips for Oracle performance
Ā 
MySQL 5.7: Core Server Changes
MySQL 5.7: Core Server ChangesMySQL 5.7: Core Server Changes
MySQL 5.7: Core Server Changes
Ā 
How to analyze and tune sql queries for better performance percona15
How to analyze and tune sql queries for better performance percona15How to analyze and tune sql queries for better performance percona15
How to analyze and tune sql queries for better performance percona15
Ā 
OQL querying and indexes with Apache Geode (incubating)
OQL querying and indexes with Apache Geode (incubating)OQL querying and indexes with Apache Geode (incubating)
OQL querying and indexes with Apache Geode (incubating)
Ā 
What's New MySQL 8.0?
What's New MySQL 8.0?What's New MySQL 8.0?
What's New MySQL 8.0?
Ā 
MySQL Troubleshooting with the Performance Schema
MySQL Troubleshooting with the Performance SchemaMySQL Troubleshooting with the Performance Schema
MySQL Troubleshooting with the Performance Schema
Ā 
Confoo 2021 - MySQL Indexes & Histograms
Confoo 2021 - MySQL Indexes & HistogramsConfoo 2021 - MySQL Indexes & Histograms
Confoo 2021 - MySQL Indexes & Histograms
Ā 
How to analyze and tune sql queries for better performance webinar
How to analyze and tune sql queries for better performance webinarHow to analyze and tune sql queries for better performance webinar
How to analyze and tune sql queries for better performance webinar
Ā 
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
MySQL 8 -- A new beginning : Sunshine PHP/PHP UK (updated)
Ā 

More from Morgan Tocker

Introducing Spirit - Online Schema Change
Introducing Spirit - Online Schema ChangeIntroducing Spirit - Online Schema Change
Introducing Spirit - Online Schema ChangeMorgan Tocker
Ā 
MySQL Usability Guidelines
MySQL Usability GuidelinesMySQL Usability Guidelines
MySQL Usability GuidelinesMorgan Tocker
Ā 
My First 90 days with Vitess
My First 90 days with VitessMy First 90 days with Vitess
My First 90 days with VitessMorgan Tocker
Ā 
FOSDEM MySQL and Friends Devroom
FOSDEM MySQL and Friends DevroomFOSDEM MySQL and Friends Devroom
FOSDEM MySQL and Friends DevroomMorgan Tocker
Ā 
Introducing TiDB - Percona Live Frankfurt
Introducing TiDB - Percona Live FrankfurtIntroducing TiDB - Percona Live Frankfurt
Introducing TiDB - Percona Live FrankfurtMorgan Tocker
Ā 
TiDB Introduction - Boston MySQL Meetup Group
TiDB Introduction - Boston MySQL Meetup GroupTiDB Introduction - Boston MySQL Meetup Group
TiDB Introduction - Boston MySQL Meetup GroupMorgan Tocker
Ā 
TiDB Introduction - San Francisco MySQL Meetup
TiDB Introduction - San Francisco MySQL MeetupTiDB Introduction - San Francisco MySQL Meetup
TiDB Introduction - San Francisco MySQL MeetupMorgan Tocker
Ā 
TiDB Introduction
TiDB IntroductionTiDB Introduction
TiDB IntroductionMorgan Tocker
Ā 
MySQL Server Defaults
MySQL Server DefaultsMySQL Server Defaults
MySQL Server DefaultsMorgan Tocker
Ā 
MySQL Cloud Service Deep Dive
MySQL Cloud Service Deep DiveMySQL Cloud Service Deep Dive
MySQL Cloud Service Deep DiveMorgan Tocker
Ā 
MySQL 5.7 + JSON
MySQL 5.7 + JSONMySQL 5.7 + JSON
MySQL 5.7 + JSONMorgan Tocker
Ā 
Using MySQL in Automated Testing
Using MySQL in Automated TestingUsing MySQL in Automated Testing
Using MySQL in Automated TestingMorgan Tocker
Ā 
Upcoming changes in MySQL 5.7
Upcoming changes in MySQL 5.7Upcoming changes in MySQL 5.7
Upcoming changes in MySQL 5.7Morgan Tocker
Ā 
MySQL Performance Metrics that Matter
MySQL Performance Metrics that MatterMySQL Performance Metrics that Matter
MySQL Performance Metrics that MatterMorgan Tocker
Ā 
MySQL For Linux Sysadmins
MySQL For Linux SysadminsMySQL For Linux Sysadmins
MySQL For Linux SysadminsMorgan Tocker
Ā 
MySQL: From Single Instance to Big Data
MySQL: From Single Instance to Big DataMySQL: From Single Instance to Big Data
MySQL: From Single Instance to Big DataMorgan Tocker
Ā 
MySQL NoSQL APIs
MySQL NoSQL APIsMySQL NoSQL APIs
MySQL NoSQL APIsMorgan Tocker
Ā 
MySQL 5.6 - Operations and Diagnostics Improvements
MySQL 5.6 - Operations and Diagnostics ImprovementsMySQL 5.6 - Operations and Diagnostics Improvements
MySQL 5.6 - Operations and Diagnostics ImprovementsMorgan Tocker
Ā 
The InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQLThe InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQLMorgan Tocker
Ā 
My sql 5.7-upcoming-changes-v2
My sql 5.7-upcoming-changes-v2My sql 5.7-upcoming-changes-v2
My sql 5.7-upcoming-changes-v2Morgan Tocker
Ā 

More from Morgan Tocker (20)

Introducing Spirit - Online Schema Change
Introducing Spirit - Online Schema ChangeIntroducing Spirit - Online Schema Change
Introducing Spirit - Online Schema Change
Ā 
MySQL Usability Guidelines
MySQL Usability GuidelinesMySQL Usability Guidelines
MySQL Usability Guidelines
Ā 
My First 90 days with Vitess
My First 90 days with VitessMy First 90 days with Vitess
My First 90 days with Vitess
Ā 
FOSDEM MySQL and Friends Devroom
FOSDEM MySQL and Friends DevroomFOSDEM MySQL and Friends Devroom
FOSDEM MySQL and Friends Devroom
Ā 
Introducing TiDB - Percona Live Frankfurt
Introducing TiDB - Percona Live FrankfurtIntroducing TiDB - Percona Live Frankfurt
Introducing TiDB - Percona Live Frankfurt
Ā 
TiDB Introduction - Boston MySQL Meetup Group
TiDB Introduction - Boston MySQL Meetup GroupTiDB Introduction - Boston MySQL Meetup Group
TiDB Introduction - Boston MySQL Meetup Group
Ā 
TiDB Introduction - San Francisco MySQL Meetup
TiDB Introduction - San Francisco MySQL MeetupTiDB Introduction - San Francisco MySQL Meetup
TiDB Introduction - San Francisco MySQL Meetup
Ā 
TiDB Introduction
TiDB IntroductionTiDB Introduction
TiDB Introduction
Ā 
MySQL Server Defaults
MySQL Server DefaultsMySQL Server Defaults
MySQL Server Defaults
Ā 
MySQL Cloud Service Deep Dive
MySQL Cloud Service Deep DiveMySQL Cloud Service Deep Dive
MySQL Cloud Service Deep Dive
Ā 
MySQL 5.7 + JSON
MySQL 5.7 + JSONMySQL 5.7 + JSON
MySQL 5.7 + JSON
Ā 
Using MySQL in Automated Testing
Using MySQL in Automated TestingUsing MySQL in Automated Testing
Using MySQL in Automated Testing
Ā 
Upcoming changes in MySQL 5.7
Upcoming changes in MySQL 5.7Upcoming changes in MySQL 5.7
Upcoming changes in MySQL 5.7
Ā 
MySQL Performance Metrics that Matter
MySQL Performance Metrics that MatterMySQL Performance Metrics that Matter
MySQL Performance Metrics that Matter
Ā 
MySQL For Linux Sysadmins
MySQL For Linux SysadminsMySQL For Linux Sysadmins
MySQL For Linux Sysadmins
Ā 
MySQL: From Single Instance to Big Data
MySQL: From Single Instance to Big DataMySQL: From Single Instance to Big Data
MySQL: From Single Instance to Big Data
Ā 
MySQL NoSQL APIs
MySQL NoSQL APIsMySQL NoSQL APIs
MySQL NoSQL APIs
Ā 
MySQL 5.6 - Operations and Diagnostics Improvements
MySQL 5.6 - Operations and Diagnostics ImprovementsMySQL 5.6 - Operations and Diagnostics Improvements
MySQL 5.6 - Operations and Diagnostics Improvements
Ā 
The InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQLThe InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQL
Ā 
My sql 5.7-upcoming-changes-v2
My sql 5.7-upcoming-changes-v2My sql 5.7-upcoming-changes-v2
My sql 5.7-upcoming-changes-v2
Ā 

Recently uploaded

EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
Ā 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
Ā 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
Ā 
Russian Call Girls in Karol Bagh Aasnvi āž”ļø 8264348440 šŸ’‹šŸ“ž Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi āž”ļø 8264348440 šŸ’‹šŸ“ž Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi āž”ļø 8264348440 šŸ’‹šŸ“ž Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi āž”ļø 8264348440 šŸ’‹šŸ“ž Independent Escort S...soniya singh
Ā 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
Ā 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
Ā 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
Ā 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto GonzƔlez Trastoy
Ā 
Call Girls in Naraina Delhi šŸ’ÆCall Us šŸ”8264348440šŸ”
Call Girls in Naraina Delhi šŸ’ÆCall Us šŸ”8264348440šŸ”Call Girls in Naraina Delhi šŸ’ÆCall Us šŸ”8264348440šŸ”
Call Girls in Naraina Delhi šŸ’ÆCall Us šŸ”8264348440šŸ”soniya singh
Ā 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
Ā 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
Ā 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
Ā 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
Ā 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
Ā 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
Ā 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
Ā 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
Ā 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
Ā 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
Ā 

Recently uploaded (20)

EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
Ā 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
Ā 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
Ā 
Call Girls In Mukherjee Nagar šŸ“± 9999965857 šŸ¤© Delhi šŸ«¦ HOT AND SEXY VVIP šŸŽ SE...
Call Girls In Mukherjee Nagar šŸ“±  9999965857  šŸ¤© Delhi šŸ«¦ HOT AND SEXY VVIP šŸŽ SE...Call Girls In Mukherjee Nagar šŸ“±  9999965857  šŸ¤© Delhi šŸ«¦ HOT AND SEXY VVIP šŸŽ SE...
Call Girls In Mukherjee Nagar šŸ“± 9999965857 šŸ¤© Delhi šŸ«¦ HOT AND SEXY VVIP šŸŽ SE...
Ā 
Russian Call Girls in Karol Bagh Aasnvi āž”ļø 8264348440 šŸ’‹šŸ“ž Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi āž”ļø 8264348440 šŸ’‹šŸ“ž Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi āž”ļø 8264348440 šŸ’‹šŸ“ž Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi āž”ļø 8264348440 šŸ’‹šŸ“ž Independent Escort S...
Ā 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Ā 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
Ā 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
Ā 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Ā 
Call Girls in Naraina Delhi šŸ’ÆCall Us šŸ”8264348440šŸ”
Call Girls in Naraina Delhi šŸ’ÆCall Us šŸ”8264348440šŸ”Call Girls in Naraina Delhi šŸ’ÆCall Us šŸ”8264348440šŸ”
Call Girls in Naraina Delhi šŸ’ÆCall Us šŸ”8264348440šŸ”
Ā 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
Ā 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
Ā 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
Ā 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
Ā 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
Ā 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
Ā 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
Ā 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Ā 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
Ā 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
Ā 

MySQL Query Optimization

  • 1.
  • 2. Query Optimization Morgan Tocker MySQL Community Manager October, 2014 Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. |
  • 3. Safe Harbor Statement The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracleā€™s products remains at the sole discretion of Oracle. Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | 3
  • 4. Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | 4 Todayā€™s Agenda Introduction World Schema IMDB Schema Advanced Topics 1 2 3 4
  • 5. Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | Introduction ā€¢ SQL is declarative. ā€¢ You say what you want, not how to process. ā€¢ Canā€™t sight check a query to understand how it executes. ā€¢ Database management chooses the best possible way -Ā­ā€ think like a GPS navigator. 5
  • 6. Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | GPS Software 6
  • 7. MySQL Optimizer Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | 7
  • 8. Diagnostic Commands Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | ā€¢ EXPLAIN (all versions) ā€¢ EXPLAIN FORMAT=JSON (MySQL 5.6+) ā€¢ Workbench supports visual format. ā€¢ OPTIMIZER TRACE (MySQL 5.6+) 8
  • 9. Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | 9 Todayā€™s Agenda Introduction World Schema IMDB Schema Advanced Topics 1 2 3 4
  • 10. The World Schema Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | ā€¢ Contains cities, countries and language statistics. ā€¢ Download From: ā€¢ http://dev.mysql.com/doc/index-Ā­ā€other.html ā€¢ Very small data set -Ā­ā€ good for learning. ā€¢ Not perfect for explaining performance differences 10
  • 11. Find Countries in Asia with Population >5M Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | 11 mysql> EXPLAIN SELECT * FROM Country WHERE Continent = 'Asia' AND population > 5000000G ********************** 1. row ********************** id: 1 select_type: SIMPLE table: Country partitions: NULL type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 239 filtered: 4.76 Extra: Using where 1 row in set, 1 warning (0.00 sec)
  • 12. Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | 12 EXPLAIN: { "query_block": { "select_id": 1, "cost_info": { "query_cost": "53.80" }, "table": { "table_name": "Country", "access_type": "ALL", "rows_examined_per_scan": 239, "rows_produced_per_join": 11, "filtered": 4.7614, "cost_info": { "read_cost": "51.52", "eval_cost": "2.28", "prefix_cost": "53.80", "data_read_per_join": "2K" }, "used_columns": [ "Code", .. "Capital", "Code2" ], "attached_condition": "((`world`.`country`.`Continent` = 'Asia') and (`world`.`country`.`Population` > 5000000))" } } } FORMAT=JSON Available since MySQL 5.6. Expanded in 5.7 to add cost information.
  • 13. What indexes will make this query faster? Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | ā€¢ Some suggestions: ā€¢ Index on (population) ā€¢ Index on (continent) ā€¢ Index on (population, continent) ā€¢ Index on (continent, population) 13 SELECT * FROM Country WHERE Continent = 'Asia' AND population > 5000000;
  • 14. Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | Next Question ā€¢ Given so many choices, which is the best choice? ā€¢ A good GPS navigator understands traffic and finds the fastest route. ā€¢ A good query optimizer does similar. 14
  • 15. Query Optimizer Strategy Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | ā€¢ Pick the plan that consumes the least amount of resources (CPU, IO). 15
  • 16. Query Optimizer Strategy (cont.) Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | ā€¢ Use statistics available to identify good and bad plans. ā€¢ Decisions may include: ā€¢ Which indexes are good/bad. ā€¢ Which order to join tables in. ā€¢ If indexes should be read in a particular order to avoid sorting, or if sorting is not expensive. 16
  • 17. Using single column indexes firstā€¦. Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | ā€¢ p (population) ā€¢ c (continent) 17
  • 18. mysql> ALTER TABLE Country ADD INDEX p (population); Query OK, 0 rows affected (0.04 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> EXPLAIN SELECT * FROM Country WHERE Continent = 'Asia' AND population > 5000000G ************************ 1. row ************************ Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | 18 id: 1 select_type: SIMPLE table: Country partitions: NULL type: ALL possible_keys: p key: NULL key_len: NULL ref: NULL rows: 239 filtered: 6.46 Extra: Using where 1 row in set, 1 warning (0.00 sec)
  • 19. Why would an index not be used? Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | 19 mysql> EXPLAIN FORMAT=JSON SELECT * FROM Country FORCE INDEX (p) WHERE Continent = 'Asia' AND population > 5000000G ******* 1. row ******* EXPLAIN: { "query_block": { "select_id": 1, "cost_info": { "query_cost": "152.21" }, "table": { "table_name": "Country", "access_type": "range", "possible_keys": [ "p" ], Using MySQL 5.7+ mysql> EXPLAIN FORMAT=JSON SELECT * FROM Country WHERE Continent = 'Asia' AND population > 5000000G ******* 1. row ******* EXPLAIN: { "query_block": { "select_id": 1, "cost_info": { "query_cost": "53.80" }, "table": { "table_name": "Country", "access_type": "ALL", "possible_keys": [ "p" ],
  • 20. Modifying the query range: >50M Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | 20 mysql> EXPLAIN SELECT * FROM Country WHERE Continent = 'Asia' AND population > 50000000G ********************** 1. row ********************** id: 1 select_type: SIMPLE table: Country partitions: NULL type: range possible_keys: p key: p key_len: 4 ref: NULL rows: 24 filtered: 14.29 Extra: Using index condition; Using where 1 row in set, 1 warning (0.00 sec)
  • 21. mysql> ALTER TABLE Country ADD INDEX c (continent); Query OK, 0 rows affected (0.04 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> EXPLAIN SELECT * FROM Country WHERE Continent = 'Asia' AND population > 5000000G *********************** 1. row *********************** Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | 21 id: 1 select_type: SIMPLE table: Country partitions: NULL type: ref possible_keys: p,c key: c key_len: 1 ref: const rows: 51 filtered: 45.19 Extra: Using where 1 row in set, 1 warning (0.00 sec)
  • 22. Modifying the query range: >500M mysql> EXPLAIN SELECT * FROM Country WHERE Continent = 'Asia' AND population > 500000000G ********************** 1. row ********************** Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | 22 id: 1 select_type: SIMPLE table: Country partitions: NULL type: range possible_keys: p,c key: p key_len: 4 ref: NULL rows: 2 filtered: 21.34 Extra: Using index condition; Using where 1 row in set, 1 warning (0.00 sec)
  • 23. Composite Indexes Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | ā€¢ On >50M which is better? ā€¢ (population, continent) ā€¢ (continent, population) 23
  • 24. mysql> ALTER TABLE Country ADD INDEX pc (pop..on, co..nt); Query OK, 0 rows affected (0.02 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> EXPLAIN SELECT * FROM Country WHERE Continent = 'Asia' AND population > 50000000G ********************** 1. row ********************** Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | 24 id: 1 select_type: SIMPLE table: Country partitions: NULL type: ref possible_keys: p,c,pc key: c key_len: 1 ref: const rows: 51 filtered: 10.04 Extra: Using where 1 row in set, 1 warning (0.00 sec)
  • 25. FORCE INDEX mysql> EXPLAIN SELECT * FROM Country FORCE INDEX (pc) WHERE Continent = 'Asia' AND population > 50000000G ********************** 1. row ********************** Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | 25 id: 1 select_type: SIMPLE table: Country partitions: NULL type: range possible_keys: pc key: pc key_len: 4 ref: NULL rows: 24 filtered: 14.29 Extra: Using index condition 1 row in set, 1 warning (0.00 sec)
  • 26. mysql> EXPLAIN FORMAT=JSON SELECT * FROM Country FORCE INDEX (pc) WHERE Continent = 'Asia' AND population > 50000000G ********************** 1. row ********************** EXPLAIN: { "query_block": { "select_id": 1, "cost_info": { "query_cost": "34.61" }, "table": { Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | 26 .. ], "key": "pc", "used_key_parts": [ "Population" ], .. Easier to see with JSON EXPLAIN
  • 27. Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | Rule of Thumb ā€¢ Index on (const, range) instead of (range, const). ā€¢ Applies to all databases. 27
  • 28. mysql> ALTER TABLE Country ADD INDEX cp (co..nt, pop..on); Query OK, 0 rows affected (0.02 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> EXPLAIN SELECT * FROM Country WHERE Continent = 'Asia' AND population > 50000000G ********************** 1. row ********************** Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | 28 id: 1 select_type: SIMPLE table: Country partitions: NULL type: range possible_keys: p,c,pc,cp key: cp key_len: 5 ref: NULL rows: 11 filtered: 100.00 Extra: Using index condition 1 row in set, 1 warning (0.00 sec)
  • 29. Where Population >N. Lower is better. Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | Cost Estimates 29 5M 50M 500M Table Scan 53.80 53.80 53.80 (Population) 152.21 34.61 3.81 (Continent) 28.20 28.20 28.20 (Population, 152.21 34.61 3.81 Continent) (Continent, Population) 24.83 16.41 3.81
  • 30. Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | 30 Todayā€™s Agenda Introduction World Schema IMDB Schema Advanced Topics 1 2 3 4
  • 31. Examples Using IMDB Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | ā€¢ Larger than world database schema. ā€¢ Better to understand performance differences. ā€¢ License requires data to be regenerated: ā€¢ http://imdbpy.sourceforge.net/ 31
  • 32. mysql> EXPLAIN SELECT * FROM title WHERE title = 'The Lion King'G ********************** 1. row ********************** Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | 32 id: 1 select_type: SIMPLE table: title partitions: NULL type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 2387523 filtered: 0.50 Extra: Using where 1 row in set, 1 warning (0.00 sec) Ignore EXPLAIN time Actual run time is 2.9 seconds (Not shown)
  • 33. mysql> ALTER TABLE title ADD INDEX (title(100)); Query OK, 0 rows affected (4.73 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> EXPLAIN SELECT * FROM title WHERE title = 'The Lion King'G ********************** 1. row ********************** Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | 33 id: 1 select_type: SIMPLE table: title partitions: NULL type: ref possible_keys: title key: title key_len: 102 ref: const rows: 4 filtered: 100.00 Extra: Using where 1 row in set, 1 warning (0.01 sec) From 2.9 seconds to 0.0 seconds (!!!)
  • 34. How does LIKE work? Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | 34 mysql> EXPLAIN SELECT * FROM title WHERE title LIKE 'The Lion %'G ********************** 1. row ********************** id: 1 select_type: SIMPLE table: title partitions: NULL type: range possible_keys: title key: title key_len: 102 ref: NULL rows: 109 filtered: 100.00 Extra: Using where 1 row in set, 1 warning (0.01 sec)
  • 35. Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | LIKE (cont.) 35 mysql> EXPLAIN SELECT * FROM title WHERE title LIKE 'The%'G ********************** 1. row ********************** id: 1 select_type: SIMPLE table: title partitions: NULL type: range possible_keys: title key: title key_len: 102 ref: NULL rows: 325548 filtered: 100.00 Extra: Using where 1 row in set, 1 warning (0.00 sec) VS Very Close. Estimate is that it is almost as fast to table scan. Run Time is 1.9 sec
  • 36. Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | Sorting 36 mysql> EXPLAIN SELECT * FROM title WHERE title = 'The Lion King' ORDER BY production_yearG ********************** 1. row ********************** id: 1 select_type: SIMPLE table: title partitions: NULL type: ref possible_keys: title key: title key_len: 102 ref: const rows: 4 filtered: 100.00 Extra: Using where; Using filesort 1 row in set, 1 warning (0.00 sec)
  • 37. SELECT movie_info.* FROM title INNER JOIN movie_info ON title.id=movie_info.movie_id WHERE title=ā€˜The Lion Kingā€™G ********************** 1. row ********************** Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | 37 id: 1 select_type: SIMPLE table: movie_info type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 1212187 Extra: NULL ********************** 2. row ********************** id: 1 select_type: SIMPLE table: title type: eq_ref possible_keys: PRIMARY,title key: PRIMARY key_len: 4 ref: imdb.movie_info.movie_id rows: 1 Extra: Using where
  • 38. mysql> ALTER TABLE movie_info ADD INDEX mi (movie_id); Query OK, 0 rows affected (1.95 sec) Records: 0 Duplicates: 0 Warnings: 0 Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | 38
  • 39. EXPLAIN SELECT movie_info.* FROM title INNER .. WHERE title='The Lion King'G ********************** 1. row ********************** Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | 39 id: 1 select_type: SIMPLE table: title type: ref possible_keys: PRIMARY,title key: title key_len: 102 ref: const rows: 4 Extra: Using where ********************** 2. row ********************** id: 1 select_type: SIMPLE table: movie_info type: ref possible_keys: mi key: mi key_len: 4 ref: imdb.title.id rows: 7 Extra: NULL
  • 40. mysql> EXPLAIN SELECT * FROM movie_info WHERE movie_id IN (SELECT id FROM title WHERE title = 'The Lion King')G ********************** 1. row ********************** Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | 40 id: 1 select_type: SIMPLE table: title type: ref possible_keys: PRIMARY,title key: title key_len: 102 ref: const rows: 4 Extra: Using where ********************** 2. row ********************** id: 1 select_type: SIMPLE table: movie_info type: ref possible_keys: mi key: mi key_len: 4 ref: imdb.title.id rows: 7 Extra: NULL
  • 41. Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | 41 Todayā€™s Agenda Introduction World Schema IMDB Schema Advanced Topics 1 2 3 4
  • 42. Optimizer Hints Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | ā€¢ USE INDEX ā€¢ FORCE INDEX ā€¢ IGNORE INDEX ā€¢ STRAIGHT JOIN 42
  • 43. Optimizer Hints (cont.) Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | 43 Expanded in MySQL 5.6 mysql> select @@optimizer_switchG ********************** 1. row ********************** @@optimizer_switch: index_merge=on,index_merge_union=on,index_merge_sort_union =on,index_merge_intersection=on,engine_condition_pushdown= on,index_condition_pushdown=on,mrr=on,mrr_cost_based=on,bl ock_nested_loop=on,batched_key_access=off,materialization= on,semijoin=on,loosescan=on,firstmatch=on,subquery_materia lization_cost_based=on,use_index_extensions=on,condition_f anout_filter=on 1 row in set (0.00 sec)
  • 44. Statistics Sampling Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | ā€¢ Some decisions based on pre-Ā­ā€computed statistics. ā€¢ For example, which order to join tables. ā€¢ Accuracy of statistics greatly improved in MySQL 5.6. ā€¢ Feature is called ā€œInnoDB persistent statisticsā€. 44
  • 45. Optimizer Decision Visibility Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | ā€¢ Intended for MySQL developer usage, and reporting optimizer bugs. ā€¢ Yet totally practical for advanced usage :) 45 New to MySQL 5.6 SET optimizer_trace="enabled=on"; SELECT /* query here */; SELECT * FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE;
  • 46. Optimizer Trace Output ā€¢ Includes why decisions were not made: Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | 46 .. "index": "pc", "ranges": [ "50000000 < Population" ], "index_dives_for_eq_ranges": true, "rowid_ordered": false, "using_mrr": false, "index_only": false, "rows": 24, "cost": 29.81, "chosen": false, "cause": "cost" },
  • 47. Too many indexes Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | ā€¢ Slows down modifications due to maintenance cost. ā€¢ i.e. Slower INSERT/UPDATE/DELETE ā€¢ May also lead to worse decisions being made by optimizer. ā€¢ Too many similar choices. ā€¢ Only limited time window to evaluate suitability. ā€¢ Space requirements in memory and storage. 47
  • 48. MySQL 5.7 and beyond Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | ā€¢ We are working on a new cost model. ā€¢ Better adapt to new hardware with different costs (i.e. SSDs have cheap random IO). ā€¢ Memory buffer aware cost estimates. 48
  • 49. Cost constants configurable per engine in 5.7 Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | ā€¢ Previously hard-Ā­ā€coded constants. ā€¢ Better adapts to differences in hardware. 49
  • 50. Copyright Ā© 2014 Oracle and/or its affiliates. All rights reserved. | 50