SlideShare une entreprise Scribd logo
1  sur  69
Télécharger pour lire hors ligne
Advanced MySQL Query Tuning
Alexander Rubin
July 21, 2013
www.percona.com
About Me
•  Working with MySQL for over 10 years
–  Started at MySQL AB, then Sun Microsystems,
–  then Oracle (MySQL Consulting)
–  Joined Percona recently
•  Helping customers improve MySQL performance
–  performance tuning
–  full text search
–  high availability
–  Reporting, database infrastructure scale-outs
–  Big data
My name is Alexander Rubin
www.percona.com
§  Indexes
– How B-tree works
– Range scans
§  Queries
– Temporary Tables and Filesort in MySQL
– GROUP BY Optimizations
– ORDER BY Optimizations
§  Social Graph Example
Agenda
www.percona.com
How to Deal with Slow Performance
Indexes
www.percona.com
MySQL Index Types: B-Tree
•  When you add index (except for MEMORY)
MySQL will use B-Tree
•  Support equality and “range” operations
Default index type (except for MEMORY tables)
http://en.wikipedia.org/wiki/B-tree
www.percona.com
MySQL Index Types: B-Tree
•  Scan thru the tree and go directly to 1 leaf
•  Stop
Equality search: select * from table where id = 12
http://en.wikipedia.org/wiki/B-tree
www.percona.com
MySQL Index Types: B-Tree
•  Scan thru the tree and visit many leafs/nodes
Range: select * from table where id in (6, 12, 18)
http://en.wikipedia.org/wiki/B-tree
www.percona.com
CREATE TABLE City (!
ID int(11) NOT NULL AUTO_INCREMENT,!
Name char(35) NOT NULL DEFAULT '',!
CountryCode char(3) NOT NULL DEFAULT '',!
District char(20) NOT NULL DEFAULT '',!
Population int(11) NOT NULL DEFAULT '0',!
PRIMARY KEY (ID),!
KEY CountryCode (CountryCode)!
) Engine=InnoDB;!
www.percona.com
• MySQL will use 1 (best) index
mysql> explain select * from City where ID = 1;!
+-------+-------+---------------+---------+---------+-------+------+-------+!
| table | type | possible_keys | key | key_len | ref | rows | Extra |!
+-------+-------+---------------+---------+---------+-------+------+-------+!
| City | const | PRIMARY | PRIMARY | 4 | const | 1 | |!
+-------+-------+---------------+---------+---------+-------+------+-------+!
!
mysql> explain select * from City where CountryCode = 'USA';!
+-------+------+---------------+-------------+---------+-------+------+------------+!
| table | type | possible_keys | key | key_len | ref | rows | Extra |!
+-------+------+---------------+-------------+---------+-------+------+------------+!
| City | ref | CountryCode | CountryCode | 3 | const | 274 | Using where|!
+-------+------+---------------+-------------+---------+-------+------+------------+!
!
www.percona.com
•  Leftmost part of combined index
mysql> alter table City add key !
comb(CountryCode, District, Population), !
drop key CountryCode;!
!
!
!
!
www.percona.com
• Leftmost part of combined index
mysql> explain select * from City !
where CountryCode = 'USA'G!
********************** 1. row ******************!
table: City!
type: ref!
possible_keys: comb!
key: comb!
key_len: 3!
ref: const!
rows: 273!
!
Uses first field from the comb key
www.percona.com
•  Key_len = total size (in bytes) of index parts used
Index: comb(CountryCode, District, Population)!
!
!
!
Explain:
key: comb!
key_len: 3!
!
!
Fields:
CountryCode char(3)!
District char(20) !
Population int(11)!
!
!
!
3 -> Char(3) -> First field is used
www.percona.com
• 2 Leftmost Fields
mysql> explain select * from City !
where CountryCode = 'USA' and District = 'California'G!
********************** 1. row ******************!
table: City!
type: ref!
possible_keys: comb!
key: comb!
key_len: 23!
ref: const,const!
rows: 68!
!
Uses 2 first fields from the comb key
CountryCode = 3 chars
District = 20 chars
Total = 23
www.percona.com
• 3 Leftmost Fields
mysql> explain select * from City !
where CountryCode = 'USA' and District = 'California’!
and population > 10000G!
********************** 1. row ******************!
table: City!
type: range!
possible_keys: comb!
key: comb!
key_len: 27!
ref: NULL!
rows: 68!
Uses all fields from the comb key
CountryCode = 3 chars/bytes
District = 20 chars/bytes
Population = 4 bytes (INT)
Total = 27
www.percona.com
• Can’t use combined index – not a leftmost part
mysql> explain select * from City where !
District = 'California' and population > 10000G!
********************** 1. row ******************!
table: City!
type: ALL!
possible_keys: NULL!
key: NULL!
key_len: NULL!
ref: NULL!
rows: 3868
!
Does not have the CountryCode
in the where clause
= can’t use comb index
www.percona.com
• Covered index = cover all fields in query
select name from City where CountryCode = 'USA'
and District = 'Alaska' and population > 10000!
!
mysql> alter table City add key !
cov1(CountryCode, District, population, name);!
!
! Uses all fields in the query in particular
order:
1.  Where part
2.  Group By/Order (not used now)
3.  Select part (here: name)
www.percona.com
• Explain
mysql> explain select name from City where CountryCode =
'USA' and District = 'Alaska' and population > 10000G!
*************************** 1. row ***********!
table: City!
type: range!
possible_keys: cov1!
key: cov1!
key_len: 27!
ref: NULL!
rows: 1!
Extra: Using where; Using index!
!
Using index = covered index is
used
MySQL will only use index
Will not go to the data file
www.percona.com
Order of Fields in Index
•  select * from City where district = 'California' and
population > 30000
•  Index (district, population) in this order
•  Rule of thumb: “Const” first, “Range” second
–  Depends on query
Range and “const” scans: use “effective” cardinality
www.percona.com
Order of Fields in Index: Example
mysql> alter table City add key comb1(district, population);!
!
mysql> explain select name from City where !
district = 'California' and population > 10000G!
********************** 1. row ***************************!
table: City!
type: range!
possible_keys: comb1!
key: comb1!
key_len: 24!
ref: NULL!
rows: 68!
!
Good: Index is used to restrict
rows
Key_len = 24 – both fields used
www.percona.com
Order of Fields in Index: Example
mysql> alter table City add key comb2(population, district);!
!
mysql> explain select name from City where !
district = 'California' and population > 3000G!
! ! !
! ! table: City!
type: ALL!
possible_keys: comb2!
key: NULL!
key_len: NULL!
ref: NULL!
rows: 4162!
Extra: Using where!
BAD! MySQL decided not to use index
at all
Why?
MySQL can only use “population” part
Too many cities with population > 3000
www.percona.com
Simplified BTree Scan Example I
Root
CA
10K –
15K
… …
100K-105K
… …
… … NC
Comb1(district,population)
1.  Go “directly”* to the district
(CA)
2.  Do range scan by population
starting with “CA”
*via index scan
www.percona.com
Simplified BTree Scan Example II
Root
10K –
15K
CA
…
NC
… …
100K
-105K
CA
…
NC
Comb1(population,district)
1.  Do range scan by population
2.  For each scanned index record
Check for correct district (CA)
3.  = Only use “population” part
of the index
www.percona.com
Index Cardinality: Example
mysql> alter table City !
add key comb2(population, District);!
!
explain select name from City where !
District = 'California' and population > 1000000G!
*********************** 1. row ***************************!
table: City!
type: range!
possible_keys: comb2!
key: comb2!
key_len: 4!
ref: NULL!
rows: 237!
Extra: Using where!
Uses Index
BUT:
key_len = 4 (INT)
Only population part is used
Cardinality = number of unique values
www.percona.com
How to Deal with Slow Performance
Queries
www.percona.com
Complex Slow Queries
The World’s Most Popular Open Source Database
… Group By …
… Order By …
Select distinct …
Filesort
Temporary
tables
www.percona.com
GROUP BY Queries
www.percona.com
mysql> explain select CountryCode, count(*) from City
group by CountryCodeG
id: 1
select_type: SIMPLE
table: City
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 4079
Extra: Using temporary; Using filesort
Temporary tables are slow!
How many cities in each country?
www.percona.com
Temporary Tables: Theory
www.percona.com
•  MySQL can create temporary tables when query uses:
•  GROUP BY
•  Range + ORDER BY
•  Some other expressions
Main performance issues
•  2 types of temporary tables
•  MEMORY
•  On-disk
www.percona.com
•  First, MySQL tries to create temporary table in memory
•  MySQL configuration variables:
•  tmp_table_size
•  maximum size for in Memory temporary tables
•  max_heap_table_size
•  Sets the maximum size for MEMORY tables
www.percona.com
MySQL
temp table
>
tmp_table_
size
OR
MySQL
temp table
>
max_heap_
table_size
convert to
MyISAM
temporary
table on
disk
www.percona.com
•  MEMORY engine does not support BLOB/TEXT
•  select blob_field from table group by field1
•  select concat(...string>512 chars) group by field1
• Create on-disk temporary table right away
•  Percona server uses the new MEMORY engine with BLOB/TEXT
Support
•  BUT: it is not used for the temp tables
www.percona.com
Temporary Tables: Practice
www.percona.com
6M rows, ~2G in size
CREATE TABLE ontime_2012 (
YearD int(11) DEFAULT NULL,
MonthD tinyint(4) DEFAULT NULL,
DayofMonth tinyint(4) DEFAULT NULL,
DayOfWeek tinyint(4) DEFAULT NULL,
Carrier char(2) DEFAULT NULL,
Origin char(5) DEFAULT NULL,
DepDelayMinutes int(11) DEFAULT NULL,
...
) ENGINE=InnoDB DEFAULT CHARSET=latin1
http://www.transtats.bts.gov/DL_SelectFields.asp?
Table_ID=236&DB_Short_Name=On-Time
www.percona.com
SELECT max(DepDelayMinutes),
carrier, dayofweek
FROM ontime_2012
WHERE dayofweek = 7
GROUP BY Carrier
•  Find maximum delay for flights on Sunday
•  Group by airline
www.percona.com
select max(DepDelayMinutes), carrier, dayofweek
from ontime_2012
where dayofweek = 7
group by Carrier
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 4833086
Extra: Using where; Using temporary; Using
filesort
Full table scan!
Temporary table!
www.percona.com
mysql> alter table ontime_2012 add key (dayofweek);
explain select max(DepDelayMinutes), Carrier,
dayofweek from ontime_2012 where dayofweek =7
group by CarrierG
type: ref
possible_keys: DayOfWeek
key: DayOfWeek
key_len: 2
ref: const
rows: 817258
Extra: Using where; Using temporary; Using filesort
Index is used = better
BUT: Large temporary table!
www.percona.com
mysql> alter table ontime_2012
add key covered(dayofweek, Carrier, DepDelayMinutes);
explain select max(DepDelayMinutes), Carrier, dayofweek from
ontime_2012 where dayofweek =7 group by CarrierG
...
possible_keys: DayOfWeek,covered
key: covered
key_len: 2
ref: const
rows: 905138
Extra: Using where; Using index
•  Called “tight index scan”
No temporary table!
MySQL will only use index
www.percona.com
mysql> explain select max(DepDelayMinutes), Carrier,
dayofweek from ontime_2012
where dayofweek > 3 group by Carrier, dayofweekG
...
type: range
possible_keys: covered
key: covered
key_len: 2
ref: NULL
rows: 2441781
Extra: Using where; Using index; Using temporary;
Using filesort
Range scan
www.percona.com
(select max(DepDelayMinutes), Carrier, dayofweek
from ontime_2012
where dayofweek = 3
group by Carrier, dayofweek)
union
(select max(DepDelayMinutes), Carrier, dayofweek
from ontime_2012
where dayofweek = 4
group by Carrier, dayofweek)
www.percona.com
*************************** 1. row ***************************
table: ontime_2012
key: covered
...
Extra: Using where; Using index
*************************** 2. row ***************************
table: ontime_2012
key: covered
…
Extra: Using where; Using index
*************************** 3. row ***************************
id: NULL
select_type: UNION RESULT
table: <union1,2>
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: NULL
Extra: Using temporary
www.percona.com
GROUP BY: Loose index scan
•  Loose index scan:
•  considers only a fraction of the keys in an
index
•  Following rules apply:
•  The query is over a single table.
•  The GROUP BY names only columns that form
a leftmost prefix of the index and no other
columns.
•  The only aggregate functions used in the select
list (if any) are MIN() and MAX(), same column
www.percona.com
Loose index scan example
mysql> alter table ontime_2012 add key loose_index_scan
(Carrier, dayofweek, DepDelayMinutes);
mysql> explain select max(DepDelayMinutes), Carrier,
dayofweek from ontime_2012 where dayofweek > 5 group
by Carrier, dayofweekG
...
table: ontime_2012
type: range
possible_keys: NULL
key: loose_index_scan
key_len: 5
ref: NULL
rows: 201
Extra: Using where; Using index for group-by
Loose index scan
Very fast
“Range” works!
www.percona.com
GROUP BY: Tight index scan
•  Full index scan or a range index scan
•  Can work if loose index scan can t be used
•  Allow to scan index and AVOID creating tmp table
•  Find ALL keys => group
•  = Covered index
www.percona.com
Loose index scan vs. tight index scan
Table: ontime_2012, 6M rows, data: 2G, index: 210M
CREATE TABLE ontime_2012 (
YearD int(11) DEFAULT NULL,
MonthD tinyint(4) DEFAULT NULL,
DayofMonth tinyint(4) DEFAULT NULL,
DayOfWeek tinyint(4) DEFAULT NULL,
Carrier char(2) DEFAULT NULL,
Origin char(5) DEFAULT NULL,
DepDelayMinutes int(11) DEFAULT NULL,
...
KEY loose_index_scan (Carrier,DayOfWeek,DepDelayMinutes),
KEY covered (DayOfWeek,Carrier,DepDelayMinutes)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
www.percona.com
Loose index scan vs. tight index scan
Loose index scan
select max(DepDelayMinutes) as ddm, Carrier, dayofweek from ontime_2012
where dayofweek = 5 group by Carrier, dayofweek
table: ontime_2012
type: range
possible_keys: covered
key: loose_index_scan
key_len: 5
ref: NULL
rows: 201
Extra: Using where; Using index for group-by
mysql> select ...
+------+---------+-----------+
| ddm | Carrier | dayofweek |
+------+---------+-----------+
| 1606 | AA | 7 |
..
30 rows in set (0.00 sec)
Carrier,
DayOfWeek,
DepDelayMinutes
www.percona.com
Loose index scan vs. tight index scan
Loose index scan
select max(DepDelayMinutes) as ddm, Carrier, dayofweek from ontime_2012
where dayofweek > 5 group by Carrier, dayofweek;
table: ontime_2012
type: range
possible_keys: covered
key: loose_index_scan
key_len: 5
ref: NULL
rows: 213
Extra: Using where; Using index for group-by;
mysql> select ...
+------+---------+-----------+
| ddm | Carrier | dayofweek |
+------+---------+-----------+
| 1606 | AA | 7 |
..
30 rows in set (0.00 sec)
Carrier,
DayOfWeek,
DepDelayMinutes
www.percona.com
Loose index scan vs. tight index scan
Loose index scan
select max(DepDelayMinutes) as ddm, Carrier, dayofweek from ontime_2012
where dayofweek > 5 group by Carrier, dayofweek order by ddm desc;
table: ontime_2012
type: range
possible_keys: covered
key: loose_index_scan
key_len: 5
ref: NULL
rows: 213
Extra: Using where; Using index for group-by; Using temporary;
Using filesort
mysql> select ...
+------+---------+-----------+
| ddm | Carrier | dayofweek |
+------+---------+-----------+
| 1606 | AA | 7 |
..
30 rows in set (0.00 sec)
Carrier,
DayOfWeek,
DepDelayMinutes
www.percona.com
Loose index scan vs. tight index scan
Temporary table
select max(DepDelayMinutes) as ddm, Carrier, dayofweek from ontime_2012
ignore index(loose_index_scan) where dayofweek > 5
group by Carrier, dayofweek
table: ontime_2012
type: range
key: covered
key_len: 2
ref: NULL
rows: 2302412
Extra: Using where; Using index;
Using temporary; Using filesort
mysql> select ...
+------+---------+-----------+
| ddm | Carrier | dayofweek |
+------+---------+-----------+
| 1606 | AA | 7 |
...
30 rows in set (1.30 sec)
1.  Range scan
2.  Temp table and filesort of
2M rows
www.percona.com
Loose index scan vs. tight index scan
Tight Index Scan
select max(DepDelayMinutes) as ddm, Carrier, dayofweek from ontime_2012
ignore index(loose_index_scan) where dayofweek = 5
group by Carrier, dayofweek
table: ontime_2012
type: ref
key: covered
key_len: 2
ref: NULL
rows: 2302412
Extra: Using where; Using index;
mysql> select ...
+------+---------+-----------+
| ddm | Carrier | dayofweek |
+------+---------+-----------+
| 1606 | AA | 7 |
...
30 rows in set (0.37 sec)
1.  Covered index
2.  No temp table
3.  BUT: have to scan 2M rows
DayOfWeek, Carrier,
DepDelayMinutes
www.percona.com
Loose index scan vs. tight index scan
Results
0
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
Loose index scan Tight Index Scan Temporary table
www.percona.com
Where loose index scan is not supported
•  AVG() + Group By – loose index scan is not supported
mysql> explain select avg(DepDelayMinutes) as ddm, Carrier, dayofweek
from ontime_2012 where dayofweek >5 group by Carrier, dayofweek G
table: ontime_2012
type: range
key: covered
key_len: 2
ref: NULL
rows: 2961617
Extra: Using where; Using index; Using temporary; Using filesort
mysql> select ...
+---------+---------+-----------+
| ddm | Carrier | dayofweek |
+---------+---------+-----------+
| 10.8564 | AA | 6 |
...
30 rows in set (1.39 sec)
1.  No loose index scan
2.  Filter by key
3.  Group by filesort
www.percona.com
ORDER BY and filesort
www.percona.com
mysql> explain select district, name, population from City
where CountryCode = 'USA' order by population desc limit 10G
table: City
type: ALL
possible_keys: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 4079
Extra: Using where; Using filesort
www.percona.com
mysql> alter table City
add key my_sort2 (CountryCode, population);
mysql> explain select district, name, population from City
where CountryCode = 'USA' order by population desc limit 10G
table: City
type: ref
key: my_sort2
key_len: 3
ref: const
rows: 207
Extra: Using where
No filesort
www.percona.com
mysql> alter table ontime_2012 add key (DepDelayMinutes);
Query OK, 0 rows affected (38.68 sec)
mysql> explain select * from ontime_2012
where dayofweek in (6,7) order by DepDelayMinutes desc
limit 10G
type: index
possible_keys: DayOfWeek,covered
key: DepDelayMinutes
key_len: 5
ref: NULL
rows: 24
Extra: Using where
10 rows in set (0.00 sec)
1.  Index is sorted
2.  Scan the whole table in the
order of the index
3.  Filter results
4.  Stop after finding 10 rows
matching the “where” condition
www.percona.com
If Index points to the beginning of the table (physically) = fast
As it stops after 10 rows (LIMIT 10)
www.percona.com
If Index points to the end of table (physically) or random = slower
Much more rows to scan (and skip)
www.percona.com
Example: Social Graph
www.percona.com
https://blog.twitter.com/2010/introducing-flockdb
•  Source_id = <YOU>
•  Destination_id = IDs of people following <YOU>
•  Position = date (unix_timestamp) when <Destination_id> added <YOU>
•  State = {0,1, 2,3} 0 = normal, 2 = removed, 3 = archived (Example)
www.percona.com
CREATE TABLE social_graph (
source_id bigint(20) unsigned NOT NULL,
destination_id bigint(20) unsigned NOT NULL,
position bigint(20) unsigned NOT NULL,
state tinyint(4) NOT NULL,
...
PRIMARY KEY (source_id,destination_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
www.percona.com
mysql> explain select * from social_graph where source_id = 927
and state in (0) order by position desc limit 100G
select_type: SIMPLE
table: social_graph
type: ref
possible_keys: PRIMARY
key: PRIMARY
key_len: 8
ref: const
rows: 957874
Extra: Using where; Using filesort
1 row in set (0.00 sec)
Time:
100 rows in set (0.20 sec)
Celebrity!
Almost 1M followers! J
www.percona.com
mysql> alter table social_graph add key
src_state_position(source_id, state, position);
mysql> select * from social_graph
where source_id = 927 and state in (0)
order by position desc
limit 100;
...
100 rows in set (0.00 sec)
www.percona.com
mysql> explain select * from social_graph where
source_id = 927 and state in (0) order by position
desc limit 100G
table: social_graph
type: ref
possible_keys: PRIMARY,src_state_position
key: src_state_position
key_len: 9
ref: const,const
rows: 957874
Extra: Using where; Using index
No filesort
Using Index
www.percona.com
mysql> explain select * from where source_id = 927
and state in (0,2) order by position desc limit 100G
select_type: SIMPLE
table: social_graph
type: ref
possible_keys: PRIMARY,src_state_position
key: src_state_position
key_len: 8
ref: const
rows: 923251
Extra: Using where; Using filesort
100 rows in set (0.54 sec)
In (N,N) = Range
Only first field of index is used
www.percona.com
mysql> alter table social_graph
add key src_position(source_id, position);
mysql> explain select * from social_graph where source_id =
927 and state in (0,2) order by position desc limit 100G
select_type: SIMPLE
table: social_graph
type: range
possible_keys: PRIMARY,src_state_position,src_position
key: src_position
key_len: 8
ref: NULL
rows: 923922
Extra: Using where
100 rows in set (0.00 sec)
Scan by source_id, correct order
Filter out “wrong” state(s)
Stop after finding 100 rows
www.percona.com
mysql> explain select * from social_graph where
source_id = 927 and state in (1,2) order by position
desc limit 100G
select_type: SIMPLE
table: social_graph
type: range
possible_keys: PRIMARY,src_state_position,src_position
key: src_state_position
key_len: 9
ref: NULL
rows: 28
Extra: Using where; Using filesort
100 rows in set (0.00 sec)
Use proper index
Scan 28 rows is faster
even with filesort
+-------+----------+
| state | count(*) |
+-------+----------+
| 0 | 456156 |
| 1 | 27 |
| 2 | 1 |
+-------+----------+
www.percona.com
mysql> explain select * from social_graph
ignore index (src_state_position)
where source_id = 927 and state in (1,2) order by
position desc limit 100G
select_type: SIMPLE
table: social_graph
type: ref
possible_keys: PRIMARY,src_position
key: src_position
key_len: 8
ref: const
rows: 923922
Extra: Using where
27 rows in set (0.54 sec)
•  Will stop only after “discarding”
400K rows.
•  27 rows returned
•  filtering + filesort is faster in
this case
+-------+----------+
| state | count(*) |
+-------+----------+
| 0 | 456156 |
| 1 | 27 |
| 2 | 1 |
+-------+----------+
www.percona.com
Questions?
Thank you!

Contenu connexe

Tendances

MySQL: Indexing for Better Performance
MySQL: Indexing for Better PerformanceMySQL: Indexing for Better Performance
MySQL: Indexing for Better Performancejkeriaki
 
MySQL Indexing : Improving Query Performance Using Index (Covering Index)
MySQL Indexing : Improving Query Performance Using Index (Covering Index)MySQL Indexing : Improving Query Performance Using Index (Covering Index)
MySQL Indexing : Improving Query Performance Using Index (Covering Index)Hemant Kumar Singh
 
MYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-havingMYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-havingAhmed Farag
 
Sql modifying data - MYSQL part I
Sql modifying data - MYSQL part ISql modifying data - MYSQL part I
Sql modifying data - MYSQL part IAhmed Farag
 
MySQL Index Cookbook
MySQL Index CookbookMySQL Index Cookbook
MySQL Index CookbookMYXPLAIN
 
Advanced MySQL Query Tuning
Advanced MySQL Query TuningAdvanced MySQL Query Tuning
Advanced MySQL Query TuningAlexander Rubin
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007paulguerin
 
Работа с индексами - лучшие практики для MySQL 5.6, Петр Зайцев (Percona)
Работа с индексами - лучшие практики для MySQL 5.6, Петр Зайцев (Percona)Работа с индексами - лучшие практики для MySQL 5.6, Петр Зайцев (Percona)
Работа с индексами - лучшие практики для MySQL 5.6, Петр Зайцев (Percona)Ontico
 
SQL Fundamentals
SQL FundamentalsSQL Fundamentals
SQL FundamentalsBrian Foote
 
New T-SQL Features in SQL Server 2012
New T-SQL Features in SQL Server 2012 New T-SQL Features in SQL Server 2012
New T-SQL Features in SQL Server 2012 Richie Rump
 
Optimizing queries MySQL
Optimizing queries MySQLOptimizing queries MySQL
Optimizing queries MySQLGeorgi Sotirov
 
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
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functionsVikas Gupta
 

Tendances (20)

MySQL: Indexing for Better Performance
MySQL: Indexing for Better PerformanceMySQL: Indexing for Better Performance
MySQL: Indexing for Better Performance
 
MySQL Indexing : Improving Query Performance Using Index (Covering Index)
MySQL Indexing : Improving Query Performance Using Index (Covering Index)MySQL Indexing : Improving Query Performance Using Index (Covering Index)
MySQL Indexing : Improving Query Performance Using Index (Covering Index)
 
MYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-havingMYSQL single rowfunc-multirowfunc-groupby-having
MYSQL single rowfunc-multirowfunc-groupby-having
 
MYSQL join
MYSQL joinMYSQL join
MYSQL join
 
Sql modifying data - MYSQL part I
Sql modifying data - MYSQL part ISql modifying data - MYSQL part I
Sql modifying data - MYSQL part I
 
MySQL Index Cookbook
MySQL Index CookbookMySQL Index Cookbook
MySQL Index Cookbook
 
Advanced MySQL Query Tuning
Advanced MySQL Query TuningAdvanced MySQL Query Tuning
Advanced MySQL Query Tuning
 
advanced sql(database)
advanced sql(database)advanced sql(database)
advanced sql(database)
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007
 
Работа с индексами - лучшие практики для MySQL 5.6, Петр Зайцев (Percona)
Работа с индексами - лучшие практики для MySQL 5.6, Петр Зайцев (Percona)Работа с индексами - лучшие практики для MySQL 5.6, Петр Зайцев (Percona)
Работа с индексами - лучшие практики для MySQL 5.6, Петр Зайцев (Percona)
 
Lab1 select statement
Lab1 select statementLab1 select statement
Lab1 select statement
 
SQL Fundamentals
SQL FundamentalsSQL Fundamentals
SQL Fundamentals
 
New T-SQL Features in SQL Server 2012
New T-SQL Features in SQL Server 2012 New T-SQL Features in SQL Server 2012
New T-SQL Features in SQL Server 2012
 
Views, Triggers, Functions, Stored Procedures, Indexing and Joins
Views, Triggers, Functions, Stored Procedures,  Indexing and JoinsViews, Triggers, Functions, Stored Procedures,  Indexing and Joins
Views, Triggers, Functions, Stored Procedures, Indexing and Joins
 
Sql select
Sql select Sql select
Sql select
 
Optimizing queries MySQL
Optimizing queries MySQLOptimizing queries MySQL
Optimizing queries MySQL
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
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
 
Mysql cheatsheet
Mysql cheatsheetMysql cheatsheet
Mysql cheatsheet
 
SQL select statement and functions
SQL select statement and functionsSQL select statement and functions
SQL select statement and functions
 

En vedette

MySQL Performance Tuning: Top 10 Tips
MySQL Performance Tuning: Top 10 TipsMySQL Performance Tuning: Top 10 Tips
MySQL Performance Tuning: Top 10 TipsOSSCube
 
MySQL Webinar 2/4 Performance tuning, hardware, optimisation
MySQL Webinar 2/4 Performance tuning, hardware, optimisationMySQL Webinar 2/4 Performance tuning, hardware, optimisation
MySQL Webinar 2/4 Performance tuning, hardware, optimisationMark Swarbrick
 
Join-fu: The Art of SQL Tuning for MySQL
Join-fu: The Art of SQL Tuning for MySQLJoin-fu: The Art of SQL Tuning for MySQL
Join-fu: The Art of SQL Tuning for MySQLZendCon
 
浅析My sql事务隔离级别与锁 seanlook
浅析My sql事务隔离级别与锁 seanlook浅析My sql事务隔离级别与锁 seanlook
浅析My sql事务隔离级别与锁 seanlook晓 周
 
MySQL Performance Tips & Best Practices
MySQL Performance Tips & Best PracticesMySQL Performance Tips & Best Practices
MySQL Performance Tips & Best PracticesIsaac Mosquera
 
Mysql performance tuning
Mysql performance tuningMysql performance tuning
Mysql performance tuningPhilip Zhong
 
LAPORAN HASIL PRAKTEK PEMROGRAMAN KOMPUTER (DLPHI 7)
LAPORAN HASIL PRAKTEK  PEMROGRAMAN KOMPUTER (DLPHI 7)LAPORAN HASIL PRAKTEK  PEMROGRAMAN KOMPUTER (DLPHI 7)
LAPORAN HASIL PRAKTEK PEMROGRAMAN KOMPUTER (DLPHI 7)YOHANIS SAHABAT
 
Zurich2007 MySQL Query Optimization
Zurich2007 MySQL Query OptimizationZurich2007 MySQL Query Optimization
Zurich2007 MySQL Query OptimizationHiệp Lê Tuấn
 
Building High Performance MySql Query Systems And Analytic Applications
Building High Performance MySql Query Systems And Analytic ApplicationsBuilding High Performance MySql Query Systems And Analytic Applications
Building High Performance MySql Query Systems And Analytic Applicationsguest40cda0b
 
MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014
MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014
MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014Dave Stokes
 
56 Query Optimization
56 Query Optimization56 Query Optimization
56 Query OptimizationMYXPLAIN
 
Mysql query optimization
Mysql query optimizationMysql query optimization
Mysql query optimizationBaohua Cai
 
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
 
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
 
MySQL Query Optimization
MySQL Query OptimizationMySQL Query Optimization
MySQL Query OptimizationMorgan Tocker
 

En vedette (20)

MySQL Performance Tuning: Top 10 Tips
MySQL Performance Tuning: Top 10 TipsMySQL Performance Tuning: Top 10 Tips
MySQL Performance Tuning: Top 10 Tips
 
MySQL Webinar 2/4 Performance tuning, hardware, optimisation
MySQL Webinar 2/4 Performance tuning, hardware, optimisationMySQL Webinar 2/4 Performance tuning, hardware, optimisation
MySQL Webinar 2/4 Performance tuning, hardware, optimisation
 
Join-fu: The Art of SQL Tuning for MySQL
Join-fu: The Art of SQL Tuning for MySQLJoin-fu: The Art of SQL Tuning for MySQL
Join-fu: The Art of SQL Tuning for MySQL
 
Performance Tuning
Performance TuningPerformance Tuning
Performance Tuning
 
浅析My sql事务隔离级别与锁 seanlook
浅析My sql事务隔离级别与锁 seanlook浅析My sql事务隔离级别与锁 seanlook
浅析My sql事务隔离级别与锁 seanlook
 
MySQL Performance Tips & Best Practices
MySQL Performance Tips & Best PracticesMySQL Performance Tips & Best Practices
MySQL Performance Tips & Best Practices
 
How to Design Indexes, Really
How to Design Indexes, ReallyHow to Design Indexes, Really
How to Design Indexes, Really
 
Mysql performance tuning
Mysql performance tuningMysql performance tuning
Mysql performance tuning
 
Joinfu Part Two
Joinfu Part TwoJoinfu Part Two
Joinfu Part Two
 
LAPORAN HASIL PRAKTEK PEMROGRAMAN KOMPUTER (DLPHI 7)
LAPORAN HASIL PRAKTEK  PEMROGRAMAN KOMPUTER (DLPHI 7)LAPORAN HASIL PRAKTEK  PEMROGRAMAN KOMPUTER (DLPHI 7)
LAPORAN HASIL PRAKTEK PEMROGRAMAN KOMPUTER (DLPHI 7)
 
Zurich2007 MySQL Query Optimization
Zurich2007 MySQL Query OptimizationZurich2007 MySQL Query Optimization
Zurich2007 MySQL Query Optimization
 
Building High Performance MySql Query Systems And Analytic Applications
Building High Performance MySql Query Systems And Analytic ApplicationsBuilding High Performance MySql Query Systems And Analytic Applications
Building High Performance MySql Query Systems And Analytic Applications
 
MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014
MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014
MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014
 
56 Query Optimization
56 Query Optimization56 Query Optimization
56 Query Optimization
 
Mysql query optimization
Mysql query optimizationMysql query optimization
Mysql 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
 
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
 
MySQL Query Optimization
MySQL Query OptimizationMySQL Query Optimization
MySQL Query Optimization
 

Similaire à Webinar 2013 advanced_query_tuning

Introduction into MySQL Query Tuning
Introduction into MySQL Query TuningIntroduction into MySQL Query Tuning
Introduction into MySQL Query TuningSveta Smirnova
 
MySQL Indexing - Best practices for MySQL 5.6
MySQL Indexing - Best practices for MySQL 5.6MySQL Indexing - Best practices for MySQL 5.6
MySQL Indexing - Best practices for MySQL 5.6MYXPLAIN
 
Why Use EXPLAIN FORMAT=JSON?
 Why Use EXPLAIN FORMAT=JSON?  Why Use EXPLAIN FORMAT=JSON?
Why Use EXPLAIN FORMAT=JSON? Sveta Smirnova
 
Parallel Query in AWS Aurora MySQL
Parallel Query in AWS Aurora MySQLParallel Query in AWS Aurora MySQL
Parallel Query in AWS Aurora MySQLMydbops
 
Troubleshooting MySQL Performance
Troubleshooting MySQL PerformanceTroubleshooting MySQL Performance
Troubleshooting MySQL PerformanceSveta Smirnova
 
Introduction to MySQL Query Tuning for Dev[Op]s
Introduction to MySQL Query Tuning for Dev[Op]sIntroduction to MySQL Query Tuning for Dev[Op]s
Introduction to MySQL Query Tuning for Dev[Op]sSveta Smirnova
 
Ten Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQLTen Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQLanandology
 
Migration from mysql to elasticsearch
Migration from mysql to elasticsearchMigration from mysql to elasticsearch
Migration from mysql to elasticsearchRyosuke Nakamura
 
4. Data Manipulation.ppt
4. Data Manipulation.ppt4. Data Manipulation.ppt
4. Data Manipulation.pptKISHOYIANKISH
 
MySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellMySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellEmily Ikuta
 
5_MariaDB_What's New in MariaDB Server 10.2 and Big Data Analytics with Maria...
5_MariaDB_What's New in MariaDB Server 10.2 and Big Data Analytics with Maria...5_MariaDB_What's New in MariaDB Server 10.2 and Big Data Analytics with Maria...
5_MariaDB_What's New in MariaDB Server 10.2 and Big Data Analytics with Maria...Kangaroot
 
MySQL 5.7 innodb_enhance_partii_20160527
MySQL 5.7 innodb_enhance_partii_20160527MySQL 5.7 innodb_enhance_partii_20160527
MySQL 5.7 innodb_enhance_partii_20160527Saewoong Lee
 
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019Dave Stokes
 
MariaDB with SphinxSE
MariaDB with SphinxSEMariaDB with SphinxSE
MariaDB with SphinxSEColin Charles
 
MariaDB for developers
MariaDB for developersMariaDB for developers
MariaDB for developersColin Charles
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeWim Godden
 
Big Data LDN 2017: Big Data Analytics with MariaDB ColumnStore
Big Data LDN 2017: Big Data Analytics with MariaDB ColumnStoreBig Data LDN 2017: Big Data Analytics with MariaDB ColumnStore
Big Data LDN 2017: Big Data Analytics with MariaDB ColumnStoreMatt Stubbs
 

Similaire à Webinar 2013 advanced_query_tuning (20)

Introduction into MySQL Query Tuning
Introduction into MySQL Query TuningIntroduction into MySQL Query Tuning
Introduction into MySQL Query Tuning
 
MySQL Indexing - Best practices for MySQL 5.6
MySQL Indexing - Best practices for MySQL 5.6MySQL Indexing - Best practices for MySQL 5.6
MySQL Indexing - Best practices for MySQL 5.6
 
Why Use EXPLAIN FORMAT=JSON?
 Why Use EXPLAIN FORMAT=JSON?  Why Use EXPLAIN FORMAT=JSON?
Why Use EXPLAIN FORMAT=JSON?
 
Quick Wins
Quick WinsQuick Wins
Quick Wins
 
Parallel Query in AWS Aurora MySQL
Parallel Query in AWS Aurora MySQLParallel Query in AWS Aurora MySQL
Parallel Query in AWS Aurora MySQL
 
Troubleshooting MySQL Performance
Troubleshooting MySQL PerformanceTroubleshooting MySQL Performance
Troubleshooting MySQL Performance
 
Introduction to MySQL Query Tuning for Dev[Op]s
Introduction to MySQL Query Tuning for Dev[Op]sIntroduction to MySQL Query Tuning for Dev[Op]s
Introduction to MySQL Query Tuning for Dev[Op]s
 
Ten Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQLTen Reasons Why You Should Prefer PostgreSQL to MySQL
Ten Reasons Why You Should Prefer PostgreSQL to MySQL
 
Migration from mysql to elasticsearch
Migration from mysql to elasticsearchMigration from mysql to elasticsearch
Migration from mysql to elasticsearch
 
4. Data Manipulation.ppt
4. Data Manipulation.ppt4. Data Manipulation.ppt
4. Data Manipulation.ppt
 
MySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellMySQL 5.7 in a Nutshell
MySQL 5.7 in a Nutshell
 
5_MariaDB_What's New in MariaDB Server 10.2 and Big Data Analytics with Maria...
5_MariaDB_What's New in MariaDB Server 10.2 and Big Data Analytics with Maria...5_MariaDB_What's New in MariaDB Server 10.2 and Big Data Analytics with Maria...
5_MariaDB_What's New in MariaDB Server 10.2 and Big Data Analytics with Maria...
 
Mysql basics1
Mysql basics1Mysql basics1
Mysql basics1
 
MySQL 5.7 innodb_enhance_partii_20160527
MySQL 5.7 innodb_enhance_partii_20160527MySQL 5.7 innodb_enhance_partii_20160527
MySQL 5.7 innodb_enhance_partii_20160527
 
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019
MySQL Baics - Texas Linxufest beginners tutorial May 31st, 2019
 
MySQLinsanity
MySQLinsanityMySQLinsanity
MySQLinsanity
 
MariaDB with SphinxSE
MariaDB with SphinxSEMariaDB with SphinxSE
MariaDB with SphinxSE
 
MariaDB for developers
MariaDB for developersMariaDB for developers
MariaDB for developers
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
 
Big Data LDN 2017: Big Data Analytics with MariaDB ColumnStore
Big Data LDN 2017: Big Data Analytics with MariaDB ColumnStoreBig Data LDN 2017: Big Data Analytics with MariaDB ColumnStore
Big Data LDN 2017: Big Data Analytics with MariaDB ColumnStore
 

Dernier

Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
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
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
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
 
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
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
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
 
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
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutionsmonugehlot87
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 

Dernier (20)

Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
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
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
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
 
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
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
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🔝
 
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
 
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...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutions
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 

Webinar 2013 advanced_query_tuning

  • 1. Advanced MySQL Query Tuning Alexander Rubin July 21, 2013
  • 2. www.percona.com About Me •  Working with MySQL for over 10 years –  Started at MySQL AB, then Sun Microsystems, –  then Oracle (MySQL Consulting) –  Joined Percona recently •  Helping customers improve MySQL performance –  performance tuning –  full text search –  high availability –  Reporting, database infrastructure scale-outs –  Big data My name is Alexander Rubin
  • 3. www.percona.com §  Indexes – How B-tree works – Range scans §  Queries – Temporary Tables and Filesort in MySQL – GROUP BY Optimizations – ORDER BY Optimizations §  Social Graph Example Agenda
  • 4. www.percona.com How to Deal with Slow Performance Indexes
  • 5. www.percona.com MySQL Index Types: B-Tree •  When you add index (except for MEMORY) MySQL will use B-Tree •  Support equality and “range” operations Default index type (except for MEMORY tables) http://en.wikipedia.org/wiki/B-tree
  • 6. www.percona.com MySQL Index Types: B-Tree •  Scan thru the tree and go directly to 1 leaf •  Stop Equality search: select * from table where id = 12 http://en.wikipedia.org/wiki/B-tree
  • 7. www.percona.com MySQL Index Types: B-Tree •  Scan thru the tree and visit many leafs/nodes Range: select * from table where id in (6, 12, 18) http://en.wikipedia.org/wiki/B-tree
  • 8. www.percona.com CREATE TABLE City (! ID int(11) NOT NULL AUTO_INCREMENT,! Name char(35) NOT NULL DEFAULT '',! CountryCode char(3) NOT NULL DEFAULT '',! District char(20) NOT NULL DEFAULT '',! Population int(11) NOT NULL DEFAULT '0',! PRIMARY KEY (ID),! KEY CountryCode (CountryCode)! ) Engine=InnoDB;!
  • 9. www.percona.com • MySQL will use 1 (best) index mysql> explain select * from City where ID = 1;! +-------+-------+---------------+---------+---------+-------+------+-------+! | table | type | possible_keys | key | key_len | ref | rows | Extra |! +-------+-------+---------------+---------+---------+-------+------+-------+! | City | const | PRIMARY | PRIMARY | 4 | const | 1 | |! +-------+-------+---------------+---------+---------+-------+------+-------+! ! mysql> explain select * from City where CountryCode = 'USA';! +-------+------+---------------+-------------+---------+-------+------+------------+! | table | type | possible_keys | key | key_len | ref | rows | Extra |! +-------+------+---------------+-------------+---------+-------+------+------------+! | City | ref | CountryCode | CountryCode | 3 | const | 274 | Using where|! +-------+------+---------------+-------------+---------+-------+------+------------+! !
  • 10. www.percona.com •  Leftmost part of combined index mysql> alter table City add key ! comb(CountryCode, District, Population), ! drop key CountryCode;! ! ! ! !
  • 11. www.percona.com • Leftmost part of combined index mysql> explain select * from City ! where CountryCode = 'USA'G! ********************** 1. row ******************! table: City! type: ref! possible_keys: comb! key: comb! key_len: 3! ref: const! rows: 273! ! Uses first field from the comb key
  • 12. www.percona.com •  Key_len = total size (in bytes) of index parts used Index: comb(CountryCode, District, Population)! ! ! ! Explain: key: comb! key_len: 3! ! ! Fields: CountryCode char(3)! District char(20) ! Population int(11)! ! ! ! 3 -> Char(3) -> First field is used
  • 13. www.percona.com • 2 Leftmost Fields mysql> explain select * from City ! where CountryCode = 'USA' and District = 'California'G! ********************** 1. row ******************! table: City! type: ref! possible_keys: comb! key: comb! key_len: 23! ref: const,const! rows: 68! ! Uses 2 first fields from the comb key CountryCode = 3 chars District = 20 chars Total = 23
  • 14. www.percona.com • 3 Leftmost Fields mysql> explain select * from City ! where CountryCode = 'USA' and District = 'California’! and population > 10000G! ********************** 1. row ******************! table: City! type: range! possible_keys: comb! key: comb! key_len: 27! ref: NULL! rows: 68! Uses all fields from the comb key CountryCode = 3 chars/bytes District = 20 chars/bytes Population = 4 bytes (INT) Total = 27
  • 15. www.percona.com • Can’t use combined index – not a leftmost part mysql> explain select * from City where ! District = 'California' and population > 10000G! ********************** 1. row ******************! table: City! type: ALL! possible_keys: NULL! key: NULL! key_len: NULL! ref: NULL! rows: 3868 ! Does not have the CountryCode in the where clause = can’t use comb index
  • 16. www.percona.com • Covered index = cover all fields in query select name from City where CountryCode = 'USA' and District = 'Alaska' and population > 10000! ! mysql> alter table City add key ! cov1(CountryCode, District, population, name);! ! ! Uses all fields in the query in particular order: 1.  Where part 2.  Group By/Order (not used now) 3.  Select part (here: name)
  • 17. www.percona.com • Explain mysql> explain select name from City where CountryCode = 'USA' and District = 'Alaska' and population > 10000G! *************************** 1. row ***********! table: City! type: range! possible_keys: cov1! key: cov1! key_len: 27! ref: NULL! rows: 1! Extra: Using where; Using index! ! Using index = covered index is used MySQL will only use index Will not go to the data file
  • 18. www.percona.com Order of Fields in Index •  select * from City where district = 'California' and population > 30000 •  Index (district, population) in this order •  Rule of thumb: “Const” first, “Range” second –  Depends on query Range and “const” scans: use “effective” cardinality
  • 19. www.percona.com Order of Fields in Index: Example mysql> alter table City add key comb1(district, population);! ! mysql> explain select name from City where ! district = 'California' and population > 10000G! ********************** 1. row ***************************! table: City! type: range! possible_keys: comb1! key: comb1! key_len: 24! ref: NULL! rows: 68! ! Good: Index is used to restrict rows Key_len = 24 – both fields used
  • 20. www.percona.com Order of Fields in Index: Example mysql> alter table City add key comb2(population, district);! ! mysql> explain select name from City where ! district = 'California' and population > 3000G! ! ! ! ! ! table: City! type: ALL! possible_keys: comb2! key: NULL! key_len: NULL! ref: NULL! rows: 4162! Extra: Using where! BAD! MySQL decided not to use index at all Why? MySQL can only use “population” part Too many cities with population > 3000
  • 21. www.percona.com Simplified BTree Scan Example I Root CA 10K – 15K … … 100K-105K … … … … NC Comb1(district,population) 1.  Go “directly”* to the district (CA) 2.  Do range scan by population starting with “CA” *via index scan
  • 22. www.percona.com Simplified BTree Scan Example II Root 10K – 15K CA … NC … … 100K -105K CA … NC Comb1(population,district) 1.  Do range scan by population 2.  For each scanned index record Check for correct district (CA) 3.  = Only use “population” part of the index
  • 23. www.percona.com Index Cardinality: Example mysql> alter table City ! add key comb2(population, District);! ! explain select name from City where ! District = 'California' and population > 1000000G! *********************** 1. row ***************************! table: City! type: range! possible_keys: comb2! key: comb2! key_len: 4! ref: NULL! rows: 237! Extra: Using where! Uses Index BUT: key_len = 4 (INT) Only population part is used Cardinality = number of unique values
  • 24. www.percona.com How to Deal with Slow Performance Queries
  • 25. www.percona.com Complex Slow Queries The World’s Most Popular Open Source Database … Group By … … Order By … Select distinct … Filesort Temporary tables
  • 27. www.percona.com mysql> explain select CountryCode, count(*) from City group by CountryCodeG id: 1 select_type: SIMPLE table: City type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 4079 Extra: Using temporary; Using filesort Temporary tables are slow! How many cities in each country?
  • 29. www.percona.com •  MySQL can create temporary tables when query uses: •  GROUP BY •  Range + ORDER BY •  Some other expressions Main performance issues •  2 types of temporary tables •  MEMORY •  On-disk
  • 30. www.percona.com •  First, MySQL tries to create temporary table in memory •  MySQL configuration variables: •  tmp_table_size •  maximum size for in Memory temporary tables •  max_heap_table_size •  Sets the maximum size for MEMORY tables
  • 32. www.percona.com •  MEMORY engine does not support BLOB/TEXT •  select blob_field from table group by field1 •  select concat(...string>512 chars) group by field1 • Create on-disk temporary table right away •  Percona server uses the new MEMORY engine with BLOB/TEXT Support •  BUT: it is not used for the temp tables
  • 34. www.percona.com 6M rows, ~2G in size CREATE TABLE ontime_2012 ( YearD int(11) DEFAULT NULL, MonthD tinyint(4) DEFAULT NULL, DayofMonth tinyint(4) DEFAULT NULL, DayOfWeek tinyint(4) DEFAULT NULL, Carrier char(2) DEFAULT NULL, Origin char(5) DEFAULT NULL, DepDelayMinutes int(11) DEFAULT NULL, ... ) ENGINE=InnoDB DEFAULT CHARSET=latin1 http://www.transtats.bts.gov/DL_SelectFields.asp? Table_ID=236&DB_Short_Name=On-Time
  • 35. www.percona.com SELECT max(DepDelayMinutes), carrier, dayofweek FROM ontime_2012 WHERE dayofweek = 7 GROUP BY Carrier •  Find maximum delay for flights on Sunday •  Group by airline
  • 36. www.percona.com select max(DepDelayMinutes), carrier, dayofweek from ontime_2012 where dayofweek = 7 group by Carrier type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 4833086 Extra: Using where; Using temporary; Using filesort Full table scan! Temporary table!
  • 37. www.percona.com mysql> alter table ontime_2012 add key (dayofweek); explain select max(DepDelayMinutes), Carrier, dayofweek from ontime_2012 where dayofweek =7 group by CarrierG type: ref possible_keys: DayOfWeek key: DayOfWeek key_len: 2 ref: const rows: 817258 Extra: Using where; Using temporary; Using filesort Index is used = better BUT: Large temporary table!
  • 38. www.percona.com mysql> alter table ontime_2012 add key covered(dayofweek, Carrier, DepDelayMinutes); explain select max(DepDelayMinutes), Carrier, dayofweek from ontime_2012 where dayofweek =7 group by CarrierG ... possible_keys: DayOfWeek,covered key: covered key_len: 2 ref: const rows: 905138 Extra: Using where; Using index •  Called “tight index scan” No temporary table! MySQL will only use index
  • 39. www.percona.com mysql> explain select max(DepDelayMinutes), Carrier, dayofweek from ontime_2012 where dayofweek > 3 group by Carrier, dayofweekG ... type: range possible_keys: covered key: covered key_len: 2 ref: NULL rows: 2441781 Extra: Using where; Using index; Using temporary; Using filesort Range scan
  • 40. www.percona.com (select max(DepDelayMinutes), Carrier, dayofweek from ontime_2012 where dayofweek = 3 group by Carrier, dayofweek) union (select max(DepDelayMinutes), Carrier, dayofweek from ontime_2012 where dayofweek = 4 group by Carrier, dayofweek)
  • 41. www.percona.com *************************** 1. row *************************** table: ontime_2012 key: covered ... Extra: Using where; Using index *************************** 2. row *************************** table: ontime_2012 key: covered … Extra: Using where; Using index *************************** 3. row *************************** id: NULL select_type: UNION RESULT table: <union1,2> type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: NULL Extra: Using temporary
  • 42. www.percona.com GROUP BY: Loose index scan •  Loose index scan: •  considers only a fraction of the keys in an index •  Following rules apply: •  The query is over a single table. •  The GROUP BY names only columns that form a leftmost prefix of the index and no other columns. •  The only aggregate functions used in the select list (if any) are MIN() and MAX(), same column
  • 43. www.percona.com Loose index scan example mysql> alter table ontime_2012 add key loose_index_scan (Carrier, dayofweek, DepDelayMinutes); mysql> explain select max(DepDelayMinutes), Carrier, dayofweek from ontime_2012 where dayofweek > 5 group by Carrier, dayofweekG ... table: ontime_2012 type: range possible_keys: NULL key: loose_index_scan key_len: 5 ref: NULL rows: 201 Extra: Using where; Using index for group-by Loose index scan Very fast “Range” works!
  • 44. www.percona.com GROUP BY: Tight index scan •  Full index scan or a range index scan •  Can work if loose index scan can t be used •  Allow to scan index and AVOID creating tmp table •  Find ALL keys => group •  = Covered index
  • 45. www.percona.com Loose index scan vs. tight index scan Table: ontime_2012, 6M rows, data: 2G, index: 210M CREATE TABLE ontime_2012 ( YearD int(11) DEFAULT NULL, MonthD tinyint(4) DEFAULT NULL, DayofMonth tinyint(4) DEFAULT NULL, DayOfWeek tinyint(4) DEFAULT NULL, Carrier char(2) DEFAULT NULL, Origin char(5) DEFAULT NULL, DepDelayMinutes int(11) DEFAULT NULL, ... KEY loose_index_scan (Carrier,DayOfWeek,DepDelayMinutes), KEY covered (DayOfWeek,Carrier,DepDelayMinutes) ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  • 46. www.percona.com Loose index scan vs. tight index scan Loose index scan select max(DepDelayMinutes) as ddm, Carrier, dayofweek from ontime_2012 where dayofweek = 5 group by Carrier, dayofweek table: ontime_2012 type: range possible_keys: covered key: loose_index_scan key_len: 5 ref: NULL rows: 201 Extra: Using where; Using index for group-by mysql> select ... +------+---------+-----------+ | ddm | Carrier | dayofweek | +------+---------+-----------+ | 1606 | AA | 7 | .. 30 rows in set (0.00 sec) Carrier, DayOfWeek, DepDelayMinutes
  • 47. www.percona.com Loose index scan vs. tight index scan Loose index scan select max(DepDelayMinutes) as ddm, Carrier, dayofweek from ontime_2012 where dayofweek > 5 group by Carrier, dayofweek; table: ontime_2012 type: range possible_keys: covered key: loose_index_scan key_len: 5 ref: NULL rows: 213 Extra: Using where; Using index for group-by; mysql> select ... +------+---------+-----------+ | ddm | Carrier | dayofweek | +------+---------+-----------+ | 1606 | AA | 7 | .. 30 rows in set (0.00 sec) Carrier, DayOfWeek, DepDelayMinutes
  • 48. www.percona.com Loose index scan vs. tight index scan Loose index scan select max(DepDelayMinutes) as ddm, Carrier, dayofweek from ontime_2012 where dayofweek > 5 group by Carrier, dayofweek order by ddm desc; table: ontime_2012 type: range possible_keys: covered key: loose_index_scan key_len: 5 ref: NULL rows: 213 Extra: Using where; Using index for group-by; Using temporary; Using filesort mysql> select ... +------+---------+-----------+ | ddm | Carrier | dayofweek | +------+---------+-----------+ | 1606 | AA | 7 | .. 30 rows in set (0.00 sec) Carrier, DayOfWeek, DepDelayMinutes
  • 49. www.percona.com Loose index scan vs. tight index scan Temporary table select max(DepDelayMinutes) as ddm, Carrier, dayofweek from ontime_2012 ignore index(loose_index_scan) where dayofweek > 5 group by Carrier, dayofweek table: ontime_2012 type: range key: covered key_len: 2 ref: NULL rows: 2302412 Extra: Using where; Using index; Using temporary; Using filesort mysql> select ... +------+---------+-----------+ | ddm | Carrier | dayofweek | +------+---------+-----------+ | 1606 | AA | 7 | ... 30 rows in set (1.30 sec) 1.  Range scan 2.  Temp table and filesort of 2M rows
  • 50. www.percona.com Loose index scan vs. tight index scan Tight Index Scan select max(DepDelayMinutes) as ddm, Carrier, dayofweek from ontime_2012 ignore index(loose_index_scan) where dayofweek = 5 group by Carrier, dayofweek table: ontime_2012 type: ref key: covered key_len: 2 ref: NULL rows: 2302412 Extra: Using where; Using index; mysql> select ... +------+---------+-----------+ | ddm | Carrier | dayofweek | +------+---------+-----------+ | 1606 | AA | 7 | ... 30 rows in set (0.37 sec) 1.  Covered index 2.  No temp table 3.  BUT: have to scan 2M rows DayOfWeek, Carrier, DepDelayMinutes
  • 51. www.percona.com Loose index scan vs. tight index scan Results 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 Loose index scan Tight Index Scan Temporary table
  • 52. www.percona.com Where loose index scan is not supported •  AVG() + Group By – loose index scan is not supported mysql> explain select avg(DepDelayMinutes) as ddm, Carrier, dayofweek from ontime_2012 where dayofweek >5 group by Carrier, dayofweek G table: ontime_2012 type: range key: covered key_len: 2 ref: NULL rows: 2961617 Extra: Using where; Using index; Using temporary; Using filesort mysql> select ... +---------+---------+-----------+ | ddm | Carrier | dayofweek | +---------+---------+-----------+ | 10.8564 | AA | 6 | ... 30 rows in set (1.39 sec) 1.  No loose index scan 2.  Filter by key 3.  Group by filesort
  • 54. www.percona.com mysql> explain select district, name, population from City where CountryCode = 'USA' order by population desc limit 10G table: City type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 4079 Extra: Using where; Using filesort
  • 55. www.percona.com mysql> alter table City add key my_sort2 (CountryCode, population); mysql> explain select district, name, population from City where CountryCode = 'USA' order by population desc limit 10G table: City type: ref key: my_sort2 key_len: 3 ref: const rows: 207 Extra: Using where No filesort
  • 56. www.percona.com mysql> alter table ontime_2012 add key (DepDelayMinutes); Query OK, 0 rows affected (38.68 sec) mysql> explain select * from ontime_2012 where dayofweek in (6,7) order by DepDelayMinutes desc limit 10G type: index possible_keys: DayOfWeek,covered key: DepDelayMinutes key_len: 5 ref: NULL rows: 24 Extra: Using where 10 rows in set (0.00 sec) 1.  Index is sorted 2.  Scan the whole table in the order of the index 3.  Filter results 4.  Stop after finding 10 rows matching the “where” condition
  • 57. www.percona.com If Index points to the beginning of the table (physically) = fast As it stops after 10 rows (LIMIT 10)
  • 58. www.percona.com If Index points to the end of table (physically) or random = slower Much more rows to scan (and skip)
  • 60. www.percona.com https://blog.twitter.com/2010/introducing-flockdb •  Source_id = <YOU> •  Destination_id = IDs of people following <YOU> •  Position = date (unix_timestamp) when <Destination_id> added <YOU> •  State = {0,1, 2,3} 0 = normal, 2 = removed, 3 = archived (Example)
  • 61. www.percona.com CREATE TABLE social_graph ( source_id bigint(20) unsigned NOT NULL, destination_id bigint(20) unsigned NOT NULL, position bigint(20) unsigned NOT NULL, state tinyint(4) NOT NULL, ... PRIMARY KEY (source_id,destination_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8
  • 62. www.percona.com mysql> explain select * from social_graph where source_id = 927 and state in (0) order by position desc limit 100G select_type: SIMPLE table: social_graph type: ref possible_keys: PRIMARY key: PRIMARY key_len: 8 ref: const rows: 957874 Extra: Using where; Using filesort 1 row in set (0.00 sec) Time: 100 rows in set (0.20 sec) Celebrity! Almost 1M followers! J
  • 63. www.percona.com mysql> alter table social_graph add key src_state_position(source_id, state, position); mysql> select * from social_graph where source_id = 927 and state in (0) order by position desc limit 100; ... 100 rows in set (0.00 sec)
  • 64. www.percona.com mysql> explain select * from social_graph where source_id = 927 and state in (0) order by position desc limit 100G table: social_graph type: ref possible_keys: PRIMARY,src_state_position key: src_state_position key_len: 9 ref: const,const rows: 957874 Extra: Using where; Using index No filesort Using Index
  • 65. www.percona.com mysql> explain select * from where source_id = 927 and state in (0,2) order by position desc limit 100G select_type: SIMPLE table: social_graph type: ref possible_keys: PRIMARY,src_state_position key: src_state_position key_len: 8 ref: const rows: 923251 Extra: Using where; Using filesort 100 rows in set (0.54 sec) In (N,N) = Range Only first field of index is used
  • 66. www.percona.com mysql> alter table social_graph add key src_position(source_id, position); mysql> explain select * from social_graph where source_id = 927 and state in (0,2) order by position desc limit 100G select_type: SIMPLE table: social_graph type: range possible_keys: PRIMARY,src_state_position,src_position key: src_position key_len: 8 ref: NULL rows: 923922 Extra: Using where 100 rows in set (0.00 sec) Scan by source_id, correct order Filter out “wrong” state(s) Stop after finding 100 rows
  • 67. www.percona.com mysql> explain select * from social_graph where source_id = 927 and state in (1,2) order by position desc limit 100G select_type: SIMPLE table: social_graph type: range possible_keys: PRIMARY,src_state_position,src_position key: src_state_position key_len: 9 ref: NULL rows: 28 Extra: Using where; Using filesort 100 rows in set (0.00 sec) Use proper index Scan 28 rows is faster even with filesort +-------+----------+ | state | count(*) | +-------+----------+ | 0 | 456156 | | 1 | 27 | | 2 | 1 | +-------+----------+
  • 68. www.percona.com mysql> explain select * from social_graph ignore index (src_state_position) where source_id = 927 and state in (1,2) order by position desc limit 100G select_type: SIMPLE table: social_graph type: ref possible_keys: PRIMARY,src_position key: src_position key_len: 8 ref: const rows: 923922 Extra: Using where 27 rows in set (0.54 sec) •  Will stop only after “discarding” 400K rows. •  27 rows returned •  filtering + filesort is faster in this case +-------+----------+ | state | count(*) | +-------+----------+ | 0 | 456156 | | 1 | 27 | | 2 | 1 | +-------+----------+