SlideShare uma empresa Scribd logo
1 de 29
Baixar para ler offline
www.fromdual.com

Need for Speed:
MySQL Indexing
Percona Live 2013,
November 11 – 12, London
Oli Sennhauser
Senior MySQL Consultant at FromDual GmbH

oli.sennhauser@fromdual.com
1 / 29
About FromDual GmbH
●

www.fromdual.com

FromDual provides neutral and
independent:
●
●

Support for all MySQL and Galera Cluster

●

Remote-DBA Services

●

●

Consulting for MySQL, Percona Server, MariaDB

MySQL Training

Oracle Silver Partner (OPN)
www.fromdual.com
2 / 29
Our customers

www.fromdual.com

3 / 29
MySQL and Indexing
●

www.fromdual.com

MySQL documentation says:
The best way to improve the performance of SELECT operations is
to create indexes on one or more of the columns that are tested in
the query.

●

Great! But:
Unnecessary indexes waste space and waste time to determine
which indexes to use. You must find the right balance to achieve
fast queries using the optimal set of indexes.

●

... hmm so we have to think a bit... :-(
4 / 29
What is an Index?
●

Adams, Douglas:
The Hitchhiker's
Guide to the
Galaxy?

www.fromdual.com

●

Sennhauser, Oli,
Uster?

5 / 29
What is an Index technically?

www.fromdual.com

6 / 29
MySQL uses indexes:
●

www.fromdual.com

To enforce uniqueness (PRIMARY KEY, UNIQUE 
KEY)

●

To fast access and filter rows (WHERE)

●

To perform joins fast (JOIN)

●

To find MIN() and MAX() values

●

For sorting and grouping (ORDER BY, GROUP BY)

●

To avoid joins by using covering indexes

●

To enforce FOREIGN KEY Constraints (FOREIGN 
KEY)
7 / 29
WHERE clause 1

www.fromdual.com

SELECT *
FROM customers
WHERE name = 'No Clue ofCREATE TABLE customersG
SHOW MySQL LLC';
CREATE TABLE `customers` (
`customer_id` smallint(5) unsigned
, `name` varchar(64) DEFAULT NULL
, PRIMARY KEY (`customer_id`)
)

EXPLAIN
SELECT *
FROM customers
WHERE name = 'No Clue of MySQL LLC';

+-----------+------+---------------+------+-------+-------------+
| table
| type | possible_keys | key | rows | Extra
|
+-----------+------+---------------+------+-------+-------------+
| customers | ALL | NULL
| NULL | 31978 | Using where |
+-----------+------+---------------+------+-------+-------------+
8 / 29
How to create and Index?

www.fromdual.com

ALTER TABLE …
●

ADD PRIMARY KEY (id);

●

ADD UNIQUE KEY (uuid);

●

ADD FOREIGN KEY (customer_id)
REFERENCES customers (customer_id);

●

ADD INDEX (last_name, first_name);

●

ADD INDEX pre_ind (hash(8));

●

ADD FULLTEXT INDEX (last_name, 
first_name);
9 / 29
WHERE clause 2

www.fromdual.com

ALTER TABLE customers
ADD INDEX (name);

CREATE TABLE `customers` (
`customer_id` smallint(5) unsigned
Gain: 20 ms → 5 ms DEFAULT NULL
, `name` varchar(64)
, PRIMARY KEY (`customer_id`)
, KEY `name` (`name`)
)

+-----------+------+---------------+------+---------+-------+------+
| table
| type | possible_keys | key | key_len | ref
| rows |
+-----------+------+---------------+------+---------+-------+------+
| customers | ref | name
| name | 67
| const |
1 |
+-----------+------+---------------+------+---------+-------+------+
10 / 29
JOIN clause

www.fromdual.com

EXPLAIN SELECT *
FROM customers AS c
JOIN orders AS o ON c.customer_id = o.customer_id
WHERE c.name = 'No Clue of MySQL LLC';
+-------+------+---------------+------+---------+-------+---------+
| table | type | possible_keys | key | key_len | ref
| rows
|
+-------+------+---------------+------+---------+-------+---------+
| c
| ref | PRIMARY,name | name | 67
| const |
1 |
| o
| ALL | NULL
| NULL | NULL
| NULL | 1045105 |
+-------+------+---------------+------+---------+-------+---------+

Gain: 450 ms → 6 ms

ALTER TABLE orders
ADD INDEX (customer_id);
+-------+------+---------------+-------------+---------+---------------+------+
| table | type | possible_keys | key
| key_len | ref
| rows |
+-------+------+---------------+-------------+---------+---------------+------+
| c
| ref | PRIMARY,name | name
| 67
| const
|
1 |
| o
| ref | customer_id
| customer_id | 3
| c.customer_id |
8 |
+-------+------+---------------+-------------+---------+---------------+------+
11 / 29
For sorting/grouping tables

www.fromdual.com

ORDER BY, GROUP BY
EXPLAIN SELECT *
FROM contacts AS c
WHERE last_name = 'Sennhauser'
ORDER BY last_name, first_name;

+-------+------+-----------+------+----------------------------------------------------+
| table | type | key
| rows | Extra
|
+-------+------+-----------+------+----------------------------------------------------+
| c
| ref | last_name | 1561 | Using index condition; Using where; Using filesort |
+-------+------+-----------+------+----------------------------------------------------+

Gain: 20 ms → 7 ms

ALTER TABLE contacts
ADD INDEX (last_name, first_name);

+----------+------+-------------+------+--------------------------+
| table
| type | key
| rows | Extra
|
+----------+------+-------------+------+--------------------------+
| contacts | ref | last_name_2 | 1561 | Using where; Using index |
+----------+------+-------------+------+--------------------------+
12 / 29
Covering Indexes

www.fromdual.com

EXPLAIN
SELECT customer_id, amount
FROM orders AS o
WHERE customer_id = 59349;
+-------+------+-------------+------+-------+
| table | type | key
| rows | Extra |
+-------+------+-------------+------+-------+
| o
| ref | customer_id | what? NULL |
So 15 |
+-------+------+-------------+------+-------+

ALTER TABLE orders
ADD INDEX (customer_id, amount);
+-------+------+---------------+------+-------------+
| table | type | key
| rows | Extra
|
+-------+------+---------------+------+-------------+
| o
| ref | customer_id_2 |
15 | Using index |
+-------+------+---------------+------+-------------+
13 / 29
Benefit of Covering Indexes
●

www.fromdual.com

Why are Covering Indexes beneficial

14 / 29
How-to find missing indexes?

www.fromdual.com

●

ER Diagram? :-(
●

Most of them rely to you business logic...

●

How-to FIND?

●

Slow Query Log

●

MySQL Variables:

●

Since v5.1
on-line!

+-------------------------------+----------+
| Variable_name
| Value
|
+-------------------------------+----------+
| log_queries_not_using_indexes | ON
|
| long_query_time
| 0.250000 |
| min_examined_row_limit
| 100
|
| slow_query_log
| ON
|
| slow_query_log_file
| slow.log |
+-------------------------------+----------+
15 / 29
Indexes are not only good
●

Indexes use space (Disk, hot data in RAM!)

●

www.fromdual.com

Indexes use time to maintain (CPU, RAM, I/O)

●

●

Optimizer needs time to determine which indexes to
use.
Sometimes optimizer is completely confused and
does wrong decisions if too many (similar) indexes
are there.
→ You must find the right
balance to achieve fast
queries using the optimal
set of indexes.
16 / 29
Smaller indexes faster queries

www.fromdual.com

●

Better fit into memory (less I/O)

●

Higher data density (rows/block)

●

Less CPU cycles (to crawl through)

●

Prefixed indexes:
ADD INDEX pre_ind (hash(8));

17 / 29
Avoid indexes

www.fromdual.com

●

Avoid redundant (and thus unnecessary ) indexes

●

How does it happen?
●
●

●

Developer 1: Creates a Foreign Key constraint → done
Developer 2: Ouu! Query is slow → Oli told me to
create an index! → done
Developer 3: Ouu! Query is slow → Developer 2 is
stupid! → Create and index → done

●

Frameworks vs. Developer

●

Upgrade process vs. Developer

●

Avoid indexes which are not used / needed
18 / 29
How to find such indexes?

www.fromdual.com

SHOW CREATE TABLE ...G
mysqldump ­­no­data > structure_dump.sql
●

Since MySQL 5.6: PERFORMANCE_SCHEMA
●

Percona Server / MariaDB: Userstats

●

http://fromdual.com/mysql-performance-schema-hints
SELECT
FROM
WHERE
AND
ORDER

object_schema, object_name, index_name
performance_schema.table_io_waits_summary_by_index_usage
index_name IS NOT NULL
count_star = 0
BY object_schema, object_name;

19 / 29
Avoid partial redundant indexes

www.fromdual.com

●

INDEX (city, last_name, first_name)

●

INDEX (city, last_name)

●

INDEX (city)

●

INDEX (last_name, city) ???

●

INDEX (first_name, last_name) !!!

20 / 29
Bad selectivity

www.fromdual.com

●

Remove indexes with bad selectivity (~= low cardinality)

●

Candidates are:
●

●

gender

●

●

status
active

How to find if field has bad
selectivity?
Indexes (and Joins) are expensive!!!

SELECT status, COUNT(*)
FROM orders
GROUP BY status;
+--------+--------+
| status | cnt
|
+--------+--------+
|
0 | 393216 |
|
1 | 262144 |
|
2 |
12 |
|
3 |
36 |
|
4 |
24 |
|
5 |
4 |
|
6 |
8 |
+--------+--------+

●

Break even between 15% and 66%

●

Lets see if the MySQL optimizer knows about it... :-)

21 / 29
Optimizer is wrong!
SELECT * FROM orders WHERE status = 2;
+--------+------+---------------+--------+------+
| table | type | possible_keys | key
| rows |
+--------+------+---------------+--------+------+
| orders | ref | status
| status |
12 |
+--------+------+---------------+--------+------+
SELECT * FROM orders WHERE status = 0;
1.43 s
+--------+------+---------------+--------+--------+
| table | type | possible_keys | key
| rows
|
+--------+------+---------------+--------+--------+
| orders | ref | status
| status | 327469 |
+--------+------+---------------+--------+--------+

www.fromdual.com

SELECT status, COUNT(*)
FROM orders
GROUP BY status;
+--------+--------+
| status | cnt
|
+--------+--------+
|
0 | 393216 |
|
1 | 262144 |
|
2 |
12 |
|
3 |
36 |
|
4 |
24 |
|
5 |
4 |
|
6 |
8 |
+--------+--------+

SELECT * FROM orders IGNORE INDEX (STATUS) WHERE status = 0;
0.44 s
+--------+------+---------------+------+--------+
| table | type | possible_keys | key | rows
|
+--------+------+---------------+------+--------+
| orders | ALL | NULL
| NULL | 654939 |
+--------+------+---------------+------+--------+

5.6.12 (after analyze table)

22 / 29
InnoDB PK and SK
●

www.fromdual.com

InnoDB has
●

Primary Keys and

●

Secondary Keys

23 / 29
Clustered Index
●

www.fromdual.com

InnoDB: Data = Leaf of Primary Key
●

We call this an Index Clustered Table (IOT)
→ Data are sorted like PK (key is sorted)!
→ PK influences Locality of data (physical
location)

●

AUTO_INCREMENT ~= sorting by time!

●

Good for many things
●

●

where hot data = recent data

Bad for time series
●

Where hot data = per item data
24 / 29
Example: InnoDB

www.fromdual.com

A_I ts v_id xpos ypos ...
   1 17:30 #42 x, y, ...
   2 17:30 #43 x, y, ...
   3 17:30 #44 x, y, ...

#42

every 2'

...
2001 17:32 #42 x, y, ...
2002 17:32 #43 x, y, ...
2003 17:32 #44 x, y, ...
Q1: Δ in rows? ~ 2000 rows
A1: 1 row ~ 100 byte
Q2: Δ in bytes? ~ 200 kbyte
Q3: Default InnoDB block size? default: 16 kbyte
Q4: Avg. # of rows of car #42 in 1 InnoDB block? ~ 1
A2: 3 d and 720 pt/d → ~2000 pt ~ 2000 rec ~ 2000 blk
Q5: How long will this take and why (32 Mbyte)?
~ 2000 IOPS ~ 10s random read!!!
S: All in RAM or strong I/O system or …?

2000 trucks

over the last 3 days
25 / 29
InnoDB PK safes the day!

www.fromdual.com

ts v_id xpos ypos ...
17:30 #42 x, y, ...
17:32 #42 x, y, ...
17:34 #42 x, y, ...

...

#42

every 2'

17:30 #43 x, y, ...
17:32 #43 x, y, ...
17:34 #43 x, y, ...

...
17:30 #44 x, y, ...

2000 trucks

Q1: Avg. # of rows of car #42 in 1 InnoDB block? ~ 120
A1: 3 d and 720 pt/d → ~2000 pt ~ 2000 rec ~ 20 blk
Q2: How long will this take and why (320 kbyte)?
~ 1-2 IOPS ~ 10-20 ms sequential read!
S: Wow f=50 faster! Any drawbacks?

over the last 3 days
26 / 29
Index hints
●

MySQL optimizer is sometimes wrong!
●

●

We have to help (= hint) him...

Index hints are:
●

USE INDEX (ind1, ind2)
●

●

●

Only consider these indexes

FORCE INDEX (ind3)
●

Use this index without considering anything else

IGNORE INDEX (ind1, ind3)
●

●

www.fromdual.com

Do NOT consider these indexes but everything else

Hints should be used only as a last resort
27 / 29
MySQL Variables
●

MySQL variables influencing index use
●

●

●

www.fromdual.com

MyISAM: key_buffer_size
InnoDB: innodb_buffer_pool_size / 
innodb_buffer_pool_instances

InnoDB Change Buffer
●

innodb_change_buffer_max_size

●

innodb_change_buffering

●

Adaptive Hash Index (AHI)

●

MySQL 5.6.3 / 5.5.14 index length 767 → 3072 bytes
●

innodb_large_prefix

28 / 29
Q&A

www.fromdual.com

Questions ?
Discussion?
We have time for some face-to-face talks...
●

FromDual provides neutral and independent:
●

Consulting

●

Remote-DBA

●

Support for MySQL, Galera, Percona Server and MariaDB

●

Training

www.fromdual.com/presentations
29 / 29

Mais conteúdo relacionado

Mais procurados

Window functions in MariaDB 10.2
Window functions in MariaDB 10.2Window functions in MariaDB 10.2
Window functions in MariaDB 10.2Sergey Petrunya
 
ANALYZE for executable statements - a new way to do optimizer troubleshooting...
ANALYZE for executable statements - a new way to do optimizer troubleshooting...ANALYZE for executable statements - a new way to do optimizer troubleshooting...
ANALYZE for executable statements - a new way to do optimizer troubleshooting...Sergey Petrunya
 
Mysqlconf2013 mariadb-cassandra-interoperability
Mysqlconf2013 mariadb-cassandra-interoperabilityMysqlconf2013 mariadb-cassandra-interoperability
Mysqlconf2013 mariadb-cassandra-interoperabilitySergey Petrunya
 
Common Table Expressions in MariaDB 10.2
Common Table Expressions in MariaDB 10.2Common Table Expressions in MariaDB 10.2
Common Table Expressions in MariaDB 10.2Sergey Petrunya
 
Applied Partitioning And Scaling Your Database System Presentation
Applied Partitioning And Scaling Your Database System PresentationApplied Partitioning And Scaling Your Database System Presentation
Applied Partitioning And Scaling Your Database System PresentationRichard Crowley
 
My SQL Idiosyncrasies That Bite OTN
My SQL Idiosyncrasies That Bite OTNMy SQL Idiosyncrasies That Bite OTN
My SQL Idiosyncrasies That Bite OTNRonald Bradford
 
Efficient Pagination Using MySQL
Efficient Pagination Using MySQLEfficient Pagination Using MySQL
Efficient Pagination Using MySQLEvan Weaver
 
SQL WORKSHOP::Lecture 3
SQL WORKSHOP::Lecture 3SQL WORKSHOP::Lecture 3
SQL WORKSHOP::Lecture 3Umair Amjad
 
Oracle dbms_xplan.display_cursor format
Oracle dbms_xplan.display_cursor formatOracle dbms_xplan.display_cursor format
Oracle dbms_xplan.display_cursor formatFranck Pachot
 
SQL WORKSHOP::Lecture 1
SQL WORKSHOP::Lecture 1SQL WORKSHOP::Lecture 1
SQL WORKSHOP::Lecture 1Umair Amjad
 
Optimizing Queries with Explain
Optimizing Queries with ExplainOptimizing Queries with Explain
Optimizing Queries with ExplainMYXPLAIN
 

Mais procurados (16)

Window functions in MariaDB 10.2
Window functions in MariaDB 10.2Window functions in MariaDB 10.2
Window functions in MariaDB 10.2
 
ANALYZE for executable statements - a new way to do optimizer troubleshooting...
ANALYZE for executable statements - a new way to do optimizer troubleshooting...ANALYZE for executable statements - a new way to do optimizer troubleshooting...
ANALYZE for executable statements - a new way to do optimizer troubleshooting...
 
SQLQueries
SQLQueriesSQLQueries
SQLQueries
 
Mysqlconf2013 mariadb-cassandra-interoperability
Mysqlconf2013 mariadb-cassandra-interoperabilityMysqlconf2013 mariadb-cassandra-interoperability
Mysqlconf2013 mariadb-cassandra-interoperability
 
Common Table Expressions in MariaDB 10.2
Common Table Expressions in MariaDB 10.2Common Table Expressions in MariaDB 10.2
Common Table Expressions in MariaDB 10.2
 
Applied Partitioning And Scaling Your Database System Presentation
Applied Partitioning And Scaling Your Database System PresentationApplied Partitioning And Scaling Your Database System Presentation
Applied Partitioning And Scaling Your Database System Presentation
 
My SQL Idiosyncrasies That Bite OTN
My SQL Idiosyncrasies That Bite OTNMy SQL Idiosyncrasies That Bite OTN
My SQL Idiosyncrasies That Bite OTN
 
Efficient Pagination Using MySQL
Efficient Pagination Using MySQLEfficient Pagination Using MySQL
Efficient Pagination Using MySQL
 
Sql 3
Sql 3Sql 3
Sql 3
 
SQL WORKSHOP::Lecture 3
SQL WORKSHOP::Lecture 3SQL WORKSHOP::Lecture 3
SQL WORKSHOP::Lecture 3
 
Oracle dbms_xplan.display_cursor format
Oracle dbms_xplan.display_cursor formatOracle dbms_xplan.display_cursor format
Oracle dbms_xplan.display_cursor format
 
Optimizando MySQL
Optimizando MySQLOptimizando MySQL
Optimizando MySQL
 
SQL WORKSHOP::Lecture 1
SQL WORKSHOP::Lecture 1SQL WORKSHOP::Lecture 1
SQL WORKSHOP::Lecture 1
 
Best sql plsql material
Best sql plsql materialBest sql plsql material
Best sql plsql material
 
Optimizing Queries with Explain
Optimizing Queries with ExplainOptimizing Queries with Explain
Optimizing Queries with Explain
 
Les09
Les09Les09
Les09
 

Semelhante a Need for Speed: Mysql indexing

Need for Speed: MySQL Indexing
Need for Speed: MySQL IndexingNeed for Speed: MySQL Indexing
Need for Speed: MySQL IndexingMYXPLAIN
 
MySQL Indexierung CeBIT 2014
MySQL Indexierung CeBIT 2014MySQL Indexierung CeBIT 2014
MySQL Indexierung CeBIT 2014FromDual GmbH
 
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)Valeriy Kravchuk
 
New optimizer features in MariaDB releases before 10.12
New optimizer features in MariaDB releases before 10.12New optimizer features in MariaDB releases before 10.12
New optimizer features in MariaDB releases before 10.12Sergey Petrunya
 
MySQL 8.0: not only good, it’s GREAT! - PHP UK 2019
MySQL 8.0: not only good, it’s GREAT! - PHP UK 2019MySQL 8.0: not only good, it’s GREAT! - PHP UK 2019
MySQL 8.0: not only good, it’s GREAT! - PHP UK 2019Gabriela Ferrara
 
Advanced Query Optimizer Tuning and Analysis
Advanced Query Optimizer Tuning and AnalysisAdvanced Query Optimizer Tuning and Analysis
Advanced Query Optimizer Tuning and AnalysisMYXPLAIN
 
MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015Dave Stokes
 
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015Dave Stokes
 
MariaDB 10.2 New Features
MariaDB 10.2 New FeaturesMariaDB 10.2 New Features
MariaDB 10.2 New FeaturesFromDual GmbH
 
Modern query optimisation features in MySQL 8.
Modern query optimisation features in MySQL 8.Modern query optimisation features in MySQL 8.
Modern query optimisation features in MySQL 8.Mydbops
 
Window functions in MySQL 8.0
Window functions in MySQL 8.0Window functions in MySQL 8.0
Window functions in MySQL 8.0Mydbops
 
SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?Andrej Pashchenko
 
M|18 Understanding the Query Optimizer
M|18 Understanding the Query OptimizerM|18 Understanding the Query Optimizer
M|18 Understanding the Query OptimizerMariaDB plc
 
IT Tage 2019 MariaDB 10.4 New Features
IT Tage 2019 MariaDB 10.4 New FeaturesIT Tage 2019 MariaDB 10.4 New Features
IT Tage 2019 MariaDB 10.4 New FeaturesFromDual GmbH
 
4. Data Manipulation.ppt
4. Data Manipulation.ppt4. Data Manipulation.ppt
4. Data Manipulation.pptKISHOYIANKISH
 
Basic MySQL Troubleshooting for Oracle Database Administrators
Basic MySQL Troubleshooting for Oracle Database AdministratorsBasic MySQL Troubleshooting for Oracle Database Administrators
Basic MySQL Troubleshooting for Oracle Database AdministratorsSveta Smirnova
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012Roland Bouman
 

Semelhante a Need for Speed: Mysql indexing (20)

Need for Speed: MySQL Indexing
Need for Speed: MySQL IndexingNeed for Speed: MySQL Indexing
Need for Speed: MySQL Indexing
 
MySQL Indexierung CeBIT 2014
MySQL Indexierung CeBIT 2014MySQL Indexierung CeBIT 2014
MySQL Indexierung CeBIT 2014
 
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
MariaDB 10.5 new features for troubleshooting (mariadb server fest 2020)
 
New optimizer features in MariaDB releases before 10.12
New optimizer features in MariaDB releases before 10.12New optimizer features in MariaDB releases before 10.12
New optimizer features in MariaDB releases before 10.12
 
MySQL 8.0: not only good, it’s GREAT! - PHP UK 2019
MySQL 8.0: not only good, it’s GREAT! - PHP UK 2019MySQL 8.0: not only good, it’s GREAT! - PHP UK 2019
MySQL 8.0: not only good, it’s GREAT! - PHP UK 2019
 
Advanced Query Optimizer Tuning and Analysis
Advanced Query Optimizer Tuning and AnalysisAdvanced Query Optimizer Tuning and Analysis
Advanced Query Optimizer Tuning and Analysis
 
MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015
 
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
 
MySQLinsanity
MySQLinsanityMySQLinsanity
MySQLinsanity
 
MariaDB 10.2 New Features
MariaDB 10.2 New FeaturesMariaDB 10.2 New Features
MariaDB 10.2 New Features
 
Modern query optimisation features in MySQL 8.
Modern query optimisation features in MySQL 8.Modern query optimisation features in MySQL 8.
Modern query optimisation features in MySQL 8.
 
Window functions in MySQL 8.0
Window functions in MySQL 8.0Window functions in MySQL 8.0
Window functions in MySQL 8.0
 
SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?
 
M|18 Understanding the Query Optimizer
M|18 Understanding the Query OptimizerM|18 Understanding the Query Optimizer
M|18 Understanding the Query Optimizer
 
IT Tage 2019 MariaDB 10.4 New Features
IT Tage 2019 MariaDB 10.4 New FeaturesIT Tage 2019 MariaDB 10.4 New Features
IT Tage 2019 MariaDB 10.4 New Features
 
MariaDB Temporal Tables
MariaDB Temporal TablesMariaDB Temporal Tables
MariaDB Temporal Tables
 
Part5 sql tune
Part5 sql tunePart5 sql tune
Part5 sql tune
 
4. Data Manipulation.ppt
4. Data Manipulation.ppt4. Data Manipulation.ppt
4. Data Manipulation.ppt
 
Basic MySQL Troubleshooting for Oracle Database Administrators
Basic MySQL Troubleshooting for Oracle Database AdministratorsBasic MySQL Troubleshooting for Oracle Database Administrators
Basic MySQL Troubleshooting for Oracle Database Administrators
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
 

Mais de FromDual GmbH

MariaDB/MySQL pitfalls - And how to come out again...
MariaDB/MySQL pitfalls - And how to come out again...MariaDB/MySQL pitfalls - And how to come out again...
MariaDB/MySQL pitfalls - And how to come out again...FromDual GmbH
 
MariaDB / MySQL tripping hazard and how to get out again?
MariaDB / MySQL tripping hazard and how to get out again?MariaDB / MySQL tripping hazard and how to get out again?
MariaDB / MySQL tripping hazard and how to get out again?FromDual GmbH
 
PXC 5.5 to MariaDB 10.4 Galera Cluster Migration Workshop
PXC 5.5 to MariaDB 10.4 Galera Cluster Migration WorkshopPXC 5.5 to MariaDB 10.4 Galera Cluster Migration Workshop
PXC 5.5 to MariaDB 10.4 Galera Cluster Migration WorkshopFromDual GmbH
 
MariaDB 10.4 New Features
MariaDB 10.4 New FeaturesMariaDB 10.4 New Features
MariaDB 10.4 New FeaturesFromDual GmbH
 
PERFORMANCE_SCHEMA and sys schema
PERFORMANCE_SCHEMA and sys schemaPERFORMANCE_SCHEMA and sys schema
PERFORMANCE_SCHEMA and sys schemaFromDual GmbH
 
MySQL für Oracle DBA's
MySQL für Oracle DBA'sMySQL für Oracle DBA's
MySQL für Oracle DBA'sFromDual GmbH
 
MySQL Backup/Recovery
MySQL Backup/RecoveryMySQL Backup/Recovery
MySQL Backup/RecoveryFromDual GmbH
 
MySQL Beispiele aus der Praxis - Wie setzen Kunden MySQL ein?
MySQL Beispiele aus der Praxis - Wie setzen Kunden MySQL ein?MySQL Beispiele aus der Praxis - Wie setzen Kunden MySQL ein?
MySQL Beispiele aus der Praxis - Wie setzen Kunden MySQL ein?FromDual GmbH
 
MySQL-Server im Teamwork - Replikation und Cluster
MySQL-Server im Teamwork - Replikation und ClusterMySQL-Server im Teamwork - Replikation und Cluster
MySQL-Server im Teamwork - Replikation und ClusterFromDual GmbH
 
Der Datenbank-Backup ist gemacht - was nun?
Der Datenbank-Backup ist gemacht - was nun?Der Datenbank-Backup ist gemacht - was nun?
Der Datenbank-Backup ist gemacht - was nun?FromDual GmbH
 
Weltweite Produktionsdatenverwaltung mit MySQL-Replikation
Weltweite Produktionsdatenverwaltung mit MySQL-ReplikationWeltweite Produktionsdatenverwaltung mit MySQL-Replikation
Weltweite Produktionsdatenverwaltung mit MySQL-ReplikationFromDual GmbH
 
MySQL Performance Tuning für Oracle-DBA's
MySQL Performance Tuning für Oracle-DBA'sMySQL Performance Tuning für Oracle-DBA's
MySQL Performance Tuning für Oracle-DBA'sFromDual GmbH
 
MySQL Security SLAC 2015
MySQL Security SLAC 2015MySQL Security SLAC 2015
MySQL Security SLAC 2015FromDual GmbH
 
MySQL Performance Tuning für Entwickler
MySQL Performance Tuning für EntwicklerMySQL Performance Tuning für Entwickler
MySQL Performance Tuning für EntwicklerFromDual GmbH
 
MySQL Replikation - Die Eier legende Wollmilchsau?
MySQL Replikation - Die Eier legende Wollmilchsau?MySQL Replikation - Die Eier legende Wollmilchsau?
MySQL Replikation - Die Eier legende Wollmilchsau?FromDual GmbH
 
Reading MySQL fingerprints
Reading MySQL fingerprintsReading MySQL fingerprints
Reading MySQL fingerprintsFromDual GmbH
 
High-availability with Galera Cluster for MySQL
High-availability with Galera Cluster for MySQLHigh-availability with Galera Cluster for MySQL
High-availability with Galera Cluster for MySQLFromDual GmbH
 
MySQL always-up with Galera Cluster
MySQL always-up with Galera ClusterMySQL always-up with Galera Cluster
MySQL always-up with Galera ClusterFromDual GmbH
 
MySQL Cluster with Galera Cluster for MySQL
MySQL Cluster with Galera Cluster for MySQLMySQL Cluster with Galera Cluster for MySQL
MySQL Cluster with Galera Cluster for MySQLFromDual GmbH
 

Mais de FromDual GmbH (20)

MariaDB/MySQL pitfalls - And how to come out again...
MariaDB/MySQL pitfalls - And how to come out again...MariaDB/MySQL pitfalls - And how to come out again...
MariaDB/MySQL pitfalls - And how to come out again...
 
MariaDB / MySQL tripping hazard and how to get out again?
MariaDB / MySQL tripping hazard and how to get out again?MariaDB / MySQL tripping hazard and how to get out again?
MariaDB / MySQL tripping hazard and how to get out again?
 
PXC 5.5 to MariaDB 10.4 Galera Cluster Migration Workshop
PXC 5.5 to MariaDB 10.4 Galera Cluster Migration WorkshopPXC 5.5 to MariaDB 10.4 Galera Cluster Migration Workshop
PXC 5.5 to MariaDB 10.4 Galera Cluster Migration Workshop
 
MariaDB 10.4 New Features
MariaDB 10.4 New FeaturesMariaDB 10.4 New Features
MariaDB 10.4 New Features
 
PERFORMANCE_SCHEMA and sys schema
PERFORMANCE_SCHEMA and sys schemaPERFORMANCE_SCHEMA and sys schema
PERFORMANCE_SCHEMA and sys schema
 
MySQL für Oracle DBA's
MySQL für Oracle DBA'sMySQL für Oracle DBA's
MySQL für Oracle DBA's
 
MySQL Backup/Recovery
MySQL Backup/RecoveryMySQL Backup/Recovery
MySQL Backup/Recovery
 
MySQL Beispiele aus der Praxis - Wie setzen Kunden MySQL ein?
MySQL Beispiele aus der Praxis - Wie setzen Kunden MySQL ein?MySQL Beispiele aus der Praxis - Wie setzen Kunden MySQL ein?
MySQL Beispiele aus der Praxis - Wie setzen Kunden MySQL ein?
 
MySQL-Server im Teamwork - Replikation und Cluster
MySQL-Server im Teamwork - Replikation und ClusterMySQL-Server im Teamwork - Replikation und Cluster
MySQL-Server im Teamwork - Replikation und Cluster
 
Der Datenbank-Backup ist gemacht - was nun?
Der Datenbank-Backup ist gemacht - was nun?Der Datenbank-Backup ist gemacht - was nun?
Der Datenbank-Backup ist gemacht - was nun?
 
Weltweite Produktionsdatenverwaltung mit MySQL-Replikation
Weltweite Produktionsdatenverwaltung mit MySQL-ReplikationWeltweite Produktionsdatenverwaltung mit MySQL-Replikation
Weltweite Produktionsdatenverwaltung mit MySQL-Replikation
 
MySQL Performance Tuning für Oracle-DBA's
MySQL Performance Tuning für Oracle-DBA'sMySQL Performance Tuning für Oracle-DBA's
MySQL Performance Tuning für Oracle-DBA's
 
MySQL Security SLAC 2015
MySQL Security SLAC 2015MySQL Security SLAC 2015
MySQL Security SLAC 2015
 
MySQL Performance Tuning für Entwickler
MySQL Performance Tuning für EntwicklerMySQL Performance Tuning für Entwickler
MySQL Performance Tuning für Entwickler
 
MySQL Replikation - Die Eier legende Wollmilchsau?
MySQL Replikation - Die Eier legende Wollmilchsau?MySQL Replikation - Die Eier legende Wollmilchsau?
MySQL Replikation - Die Eier legende Wollmilchsau?
 
Reading MySQL fingerprints
Reading MySQL fingerprintsReading MySQL fingerprints
Reading MySQL fingerprints
 
High-availability with Galera Cluster for MySQL
High-availability with Galera Cluster for MySQLHigh-availability with Galera Cluster for MySQL
High-availability with Galera Cluster for MySQL
 
MySQL always-up with Galera Cluster
MySQL always-up with Galera ClusterMySQL always-up with Galera Cluster
MySQL always-up with Galera Cluster
 
HA with Galera
HA with GaleraHA with Galera
HA with Galera
 
MySQL Cluster with Galera Cluster for MySQL
MySQL Cluster with Galera Cluster for MySQLMySQL Cluster with Galera Cluster for MySQL
MySQL Cluster with Galera Cluster for MySQL
 

Último

2024 03 13 AZ GOP LD4 Gen Meeting Minutes_FINAL.docx
2024 03 13 AZ GOP LD4 Gen Meeting Minutes_FINAL.docx2024 03 13 AZ GOP LD4 Gen Meeting Minutes_FINAL.docx
2024 03 13 AZ GOP LD4 Gen Meeting Minutes_FINAL.docxkfjstone13
 
Dynamics of Destructive Polarisation in Mainstream and Social Media: The Case...
Dynamics of Destructive Polarisation in Mainstream and Social Media: The Case...Dynamics of Destructive Polarisation in Mainstream and Social Media: The Case...
Dynamics of Destructive Polarisation in Mainstream and Social Media: The Case...Axel Bruns
 
Minto-Morley Reforms 1909 (constitution).pptx
Minto-Morley Reforms 1909 (constitution).pptxMinto-Morley Reforms 1909 (constitution).pptx
Minto-Morley Reforms 1909 (constitution).pptxAwaiskhalid96
 
Verified Love Spells in Little Rock, AR (310) 882-6330 Get My Ex-Lover Back
Verified Love Spells in Little Rock, AR (310) 882-6330 Get My Ex-Lover BackVerified Love Spells in Little Rock, AR (310) 882-6330 Get My Ex-Lover Back
Verified Love Spells in Little Rock, AR (310) 882-6330 Get My Ex-Lover BackPsychicRuben LoveSpells
 
₹5.5k {Cash Payment} Independent Greater Noida Call Girls In [Delhi INAYA] 🔝|...
₹5.5k {Cash Payment} Independent Greater Noida Call Girls In [Delhi INAYA] 🔝|...₹5.5k {Cash Payment} Independent Greater Noida Call Girls In [Delhi INAYA] 🔝|...
₹5.5k {Cash Payment} Independent Greater Noida Call Girls In [Delhi INAYA] 🔝|...Diya Sharma
 
N. Chandrababu Naidu Receives Global Agriculture Policy Leadership Award
N. Chandrababu Naidu Receives Global Agriculture Policy Leadership AwardN. Chandrababu Naidu Receives Global Agriculture Policy Leadership Award
N. Chandrababu Naidu Receives Global Agriculture Policy Leadership Awardsrinuseo15
 
AI as Research Assistant: Upscaling Content Analysis to Identify Patterns of ...
AI as Research Assistant: Upscaling Content Analysis to Identify Patterns of ...AI as Research Assistant: Upscaling Content Analysis to Identify Patterns of ...
AI as Research Assistant: Upscaling Content Analysis to Identify Patterns of ...Axel Bruns
 
Defensa de JOH insiste que testimonio de analista de la DEA es falso y solici...
Defensa de JOH insiste que testimonio de analista de la DEA es falso y solici...Defensa de JOH insiste que testimonio de analista de la DEA es falso y solici...
Defensa de JOH insiste que testimonio de analista de la DEA es falso y solici...AlexisTorres963861
 
Kishan Reddy Report To People (2019-24).pdf
Kishan Reddy Report To People (2019-24).pdfKishan Reddy Report To People (2019-24).pdf
Kishan Reddy Report To People (2019-24).pdfKISHAN REDDY OFFICE
 
26042024_First India Newspaper Jaipur.pdf
26042024_First India Newspaper Jaipur.pdf26042024_First India Newspaper Jaipur.pdf
26042024_First India Newspaper Jaipur.pdfFIRST INDIA
 
Pakistan PMLN Election Manifesto 2024.pdf
Pakistan PMLN Election Manifesto 2024.pdfPakistan PMLN Election Manifesto 2024.pdf
Pakistan PMLN Election Manifesto 2024.pdfFahimUddin61
 
Call Girls in Mira Road Mumbai ( Neha 09892124323 ) College Escorts Service i...
Call Girls in Mira Road Mumbai ( Neha 09892124323 ) College Escorts Service i...Call Girls in Mira Road Mumbai ( Neha 09892124323 ) College Escorts Service i...
Call Girls in Mira Road Mumbai ( Neha 09892124323 ) College Escorts Service i...Pooja Nehwal
 
BDSM⚡Call Girls in Sector 135 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 135 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 135 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 135 Noida Escorts >༒8448380779 Escort ServiceDelhi Call girls
 
Roberts Rules Cheat Sheet for LD4 Precinct Commiteemen
Roberts Rules Cheat Sheet for LD4 Precinct CommiteemenRoberts Rules Cheat Sheet for LD4 Precinct Commiteemen
Roberts Rules Cheat Sheet for LD4 Precinct Commiteemenkfjstone13
 
Nara Chandrababu Naidu's Visionary Policies For Andhra Pradesh's Development
Nara Chandrababu Naidu's Visionary Policies For Andhra Pradesh's DevelopmentNara Chandrababu Naidu's Visionary Policies For Andhra Pradesh's Development
Nara Chandrababu Naidu's Visionary Policies For Andhra Pradesh's Developmentnarsireddynannuri1
 
29042024_First India Newspaper Jaipur.pdf
29042024_First India Newspaper Jaipur.pdf29042024_First India Newspaper Jaipur.pdf
29042024_First India Newspaper Jaipur.pdfFIRST INDIA
 
BDSM⚡Call Girls in Indirapuram Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Indirapuram Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Indirapuram Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Indirapuram Escorts >༒8448380779 Escort ServiceDelhi Call girls
 
2024 04 03 AZ GOP LD4 Gen Meeting Minutes FINAL.docx
2024 04 03 AZ GOP LD4 Gen Meeting Minutes FINAL.docx2024 04 03 AZ GOP LD4 Gen Meeting Minutes FINAL.docx
2024 04 03 AZ GOP LD4 Gen Meeting Minutes FINAL.docxkfjstone13
 
Lorenzo D'Emidio_Lavoro sullaNorth Korea .pptx
Lorenzo D'Emidio_Lavoro sullaNorth Korea .pptxLorenzo D'Emidio_Lavoro sullaNorth Korea .pptx
Lorenzo D'Emidio_Lavoro sullaNorth Korea .pptxlorenzodemidio01
 
Israel Palestine Conflict, The issue and historical context!
Israel Palestine Conflict, The issue and historical context!Israel Palestine Conflict, The issue and historical context!
Israel Palestine Conflict, The issue and historical context!Krish109503
 

Último (20)

2024 03 13 AZ GOP LD4 Gen Meeting Minutes_FINAL.docx
2024 03 13 AZ GOP LD4 Gen Meeting Minutes_FINAL.docx2024 03 13 AZ GOP LD4 Gen Meeting Minutes_FINAL.docx
2024 03 13 AZ GOP LD4 Gen Meeting Minutes_FINAL.docx
 
Dynamics of Destructive Polarisation in Mainstream and Social Media: The Case...
Dynamics of Destructive Polarisation in Mainstream and Social Media: The Case...Dynamics of Destructive Polarisation in Mainstream and Social Media: The Case...
Dynamics of Destructive Polarisation in Mainstream and Social Media: The Case...
 
Minto-Morley Reforms 1909 (constitution).pptx
Minto-Morley Reforms 1909 (constitution).pptxMinto-Morley Reforms 1909 (constitution).pptx
Minto-Morley Reforms 1909 (constitution).pptx
 
Verified Love Spells in Little Rock, AR (310) 882-6330 Get My Ex-Lover Back
Verified Love Spells in Little Rock, AR (310) 882-6330 Get My Ex-Lover BackVerified Love Spells in Little Rock, AR (310) 882-6330 Get My Ex-Lover Back
Verified Love Spells in Little Rock, AR (310) 882-6330 Get My Ex-Lover Back
 
₹5.5k {Cash Payment} Independent Greater Noida Call Girls In [Delhi INAYA] 🔝|...
₹5.5k {Cash Payment} Independent Greater Noida Call Girls In [Delhi INAYA] 🔝|...₹5.5k {Cash Payment} Independent Greater Noida Call Girls In [Delhi INAYA] 🔝|...
₹5.5k {Cash Payment} Independent Greater Noida Call Girls In [Delhi INAYA] 🔝|...
 
N. Chandrababu Naidu Receives Global Agriculture Policy Leadership Award
N. Chandrababu Naidu Receives Global Agriculture Policy Leadership AwardN. Chandrababu Naidu Receives Global Agriculture Policy Leadership Award
N. Chandrababu Naidu Receives Global Agriculture Policy Leadership Award
 
AI as Research Assistant: Upscaling Content Analysis to Identify Patterns of ...
AI as Research Assistant: Upscaling Content Analysis to Identify Patterns of ...AI as Research Assistant: Upscaling Content Analysis to Identify Patterns of ...
AI as Research Assistant: Upscaling Content Analysis to Identify Patterns of ...
 
Defensa de JOH insiste que testimonio de analista de la DEA es falso y solici...
Defensa de JOH insiste que testimonio de analista de la DEA es falso y solici...Defensa de JOH insiste que testimonio de analista de la DEA es falso y solici...
Defensa de JOH insiste que testimonio de analista de la DEA es falso y solici...
 
Kishan Reddy Report To People (2019-24).pdf
Kishan Reddy Report To People (2019-24).pdfKishan Reddy Report To People (2019-24).pdf
Kishan Reddy Report To People (2019-24).pdf
 
26042024_First India Newspaper Jaipur.pdf
26042024_First India Newspaper Jaipur.pdf26042024_First India Newspaper Jaipur.pdf
26042024_First India Newspaper Jaipur.pdf
 
Pakistan PMLN Election Manifesto 2024.pdf
Pakistan PMLN Election Manifesto 2024.pdfPakistan PMLN Election Manifesto 2024.pdf
Pakistan PMLN Election Manifesto 2024.pdf
 
Call Girls in Mira Road Mumbai ( Neha 09892124323 ) College Escorts Service i...
Call Girls in Mira Road Mumbai ( Neha 09892124323 ) College Escorts Service i...Call Girls in Mira Road Mumbai ( Neha 09892124323 ) College Escorts Service i...
Call Girls in Mira Road Mumbai ( Neha 09892124323 ) College Escorts Service i...
 
BDSM⚡Call Girls in Sector 135 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 135 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 135 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 135 Noida Escorts >༒8448380779 Escort Service
 
Roberts Rules Cheat Sheet for LD4 Precinct Commiteemen
Roberts Rules Cheat Sheet for LD4 Precinct CommiteemenRoberts Rules Cheat Sheet for LD4 Precinct Commiteemen
Roberts Rules Cheat Sheet for LD4 Precinct Commiteemen
 
Nara Chandrababu Naidu's Visionary Policies For Andhra Pradesh's Development
Nara Chandrababu Naidu's Visionary Policies For Andhra Pradesh's DevelopmentNara Chandrababu Naidu's Visionary Policies For Andhra Pradesh's Development
Nara Chandrababu Naidu's Visionary Policies For Andhra Pradesh's Development
 
29042024_First India Newspaper Jaipur.pdf
29042024_First India Newspaper Jaipur.pdf29042024_First India Newspaper Jaipur.pdf
29042024_First India Newspaper Jaipur.pdf
 
BDSM⚡Call Girls in Indirapuram Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Indirapuram Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Indirapuram Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Indirapuram Escorts >༒8448380779 Escort Service
 
2024 04 03 AZ GOP LD4 Gen Meeting Minutes FINAL.docx
2024 04 03 AZ GOP LD4 Gen Meeting Minutes FINAL.docx2024 04 03 AZ GOP LD4 Gen Meeting Minutes FINAL.docx
2024 04 03 AZ GOP LD4 Gen Meeting Minutes FINAL.docx
 
Lorenzo D'Emidio_Lavoro sullaNorth Korea .pptx
Lorenzo D'Emidio_Lavoro sullaNorth Korea .pptxLorenzo D'Emidio_Lavoro sullaNorth Korea .pptx
Lorenzo D'Emidio_Lavoro sullaNorth Korea .pptx
 
Israel Palestine Conflict, The issue and historical context!
Israel Palestine Conflict, The issue and historical context!Israel Palestine Conflict, The issue and historical context!
Israel Palestine Conflict, The issue and historical context!
 

Need for Speed: Mysql indexing

  • 1. www.fromdual.com Need for Speed: MySQL Indexing Percona Live 2013, November 11 – 12, London Oli Sennhauser Senior MySQL Consultant at FromDual GmbH oli.sennhauser@fromdual.com 1 / 29
  • 2. About FromDual GmbH ● www.fromdual.com FromDual provides neutral and independent: ● ● Support for all MySQL and Galera Cluster ● Remote-DBA Services ● ● Consulting for MySQL, Percona Server, MariaDB MySQL Training Oracle Silver Partner (OPN) www.fromdual.com 2 / 29
  • 4. MySQL and Indexing ● www.fromdual.com MySQL documentation says: The best way to improve the performance of SELECT operations is to create indexes on one or more of the columns that are tested in the query. ● Great! But: Unnecessary indexes waste space and waste time to determine which indexes to use. You must find the right balance to achieve fast queries using the optimal set of indexes. ● ... hmm so we have to think a bit... :-( 4 / 29
  • 5. What is an Index? ● Adams, Douglas: The Hitchhiker's Guide to the Galaxy? www.fromdual.com ● Sennhauser, Oli, Uster? 5 / 29
  • 6. What is an Index technically? www.fromdual.com 6 / 29
  • 7. MySQL uses indexes: ● www.fromdual.com To enforce uniqueness (PRIMARY KEY, UNIQUE  KEY) ● To fast access and filter rows (WHERE) ● To perform joins fast (JOIN) ● To find MIN() and MAX() values ● For sorting and grouping (ORDER BY, GROUP BY) ● To avoid joins by using covering indexes ● To enforce FOREIGN KEY Constraints (FOREIGN  KEY) 7 / 29
  • 8. WHERE clause 1 www.fromdual.com SELECT * FROM customers WHERE name = 'No Clue ofCREATE TABLE customersG SHOW MySQL LLC'; CREATE TABLE `customers` ( `customer_id` smallint(5) unsigned , `name` varchar(64) DEFAULT NULL , PRIMARY KEY (`customer_id`) ) EXPLAIN SELECT * FROM customers WHERE name = 'No Clue of MySQL LLC'; +-----------+------+---------------+------+-------+-------------+ | table | type | possible_keys | key | rows | Extra | +-----------+------+---------------+------+-------+-------------+ | customers | ALL | NULL | NULL | 31978 | Using where | +-----------+------+---------------+------+-------+-------------+ 8 / 29
  • 9. How to create and Index? www.fromdual.com ALTER TABLE … ● ADD PRIMARY KEY (id); ● ADD UNIQUE KEY (uuid); ● ADD FOREIGN KEY (customer_id) REFERENCES customers (customer_id); ● ADD INDEX (last_name, first_name); ● ADD INDEX pre_ind (hash(8)); ● ADD FULLTEXT INDEX (last_name,  first_name); 9 / 29
  • 10. WHERE clause 2 www.fromdual.com ALTER TABLE customers ADD INDEX (name); CREATE TABLE `customers` ( `customer_id` smallint(5) unsigned Gain: 20 ms → 5 ms DEFAULT NULL , `name` varchar(64) , PRIMARY KEY (`customer_id`) , KEY `name` (`name`) ) +-----------+------+---------------+------+---------+-------+------+ | table | type | possible_keys | key | key_len | ref | rows | +-----------+------+---------------+------+---------+-------+------+ | customers | ref | name | name | 67 | const | 1 | +-----------+------+---------------+------+---------+-------+------+ 10 / 29
  • 11. JOIN clause www.fromdual.com EXPLAIN SELECT * FROM customers AS c JOIN orders AS o ON c.customer_id = o.customer_id WHERE c.name = 'No Clue of MySQL LLC'; +-------+------+---------------+------+---------+-------+---------+ | table | type | possible_keys | key | key_len | ref | rows | +-------+------+---------------+------+---------+-------+---------+ | c | ref | PRIMARY,name | name | 67 | const | 1 | | o | ALL | NULL | NULL | NULL | NULL | 1045105 | +-------+------+---------------+------+---------+-------+---------+ Gain: 450 ms → 6 ms ALTER TABLE orders ADD INDEX (customer_id); +-------+------+---------------+-------------+---------+---------------+------+ | table | type | possible_keys | key | key_len | ref | rows | +-------+------+---------------+-------------+---------+---------------+------+ | c | ref | PRIMARY,name | name | 67 | const | 1 | | o | ref | customer_id | customer_id | 3 | c.customer_id | 8 | +-------+------+---------------+-------------+---------+---------------+------+ 11 / 29
  • 12. For sorting/grouping tables www.fromdual.com ORDER BY, GROUP BY EXPLAIN SELECT * FROM contacts AS c WHERE last_name = 'Sennhauser' ORDER BY last_name, first_name; +-------+------+-----------+------+----------------------------------------------------+ | table | type | key | rows | Extra | +-------+------+-----------+------+----------------------------------------------------+ | c | ref | last_name | 1561 | Using index condition; Using where; Using filesort | +-------+------+-----------+------+----------------------------------------------------+ Gain: 20 ms → 7 ms ALTER TABLE contacts ADD INDEX (last_name, first_name); +----------+------+-------------+------+--------------------------+ | table | type | key | rows | Extra | +----------+------+-------------+------+--------------------------+ | contacts | ref | last_name_2 | 1561 | Using where; Using index | +----------+------+-------------+------+--------------------------+ 12 / 29
  • 13. Covering Indexes www.fromdual.com EXPLAIN SELECT customer_id, amount FROM orders AS o WHERE customer_id = 59349; +-------+------+-------------+------+-------+ | table | type | key | rows | Extra | +-------+------+-------------+------+-------+ | o | ref | customer_id | what? NULL | So 15 | +-------+------+-------------+------+-------+ ALTER TABLE orders ADD INDEX (customer_id, amount); +-------+------+---------------+------+-------------+ | table | type | key | rows | Extra | +-------+------+---------------+------+-------------+ | o | ref | customer_id_2 | 15 | Using index | +-------+------+---------------+------+-------------+ 13 / 29
  • 14. Benefit of Covering Indexes ● www.fromdual.com Why are Covering Indexes beneficial 14 / 29
  • 15. How-to find missing indexes? www.fromdual.com ● ER Diagram? :-( ● Most of them rely to you business logic... ● How-to FIND? ● Slow Query Log ● MySQL Variables: ● Since v5.1 on-line! +-------------------------------+----------+ | Variable_name | Value | +-------------------------------+----------+ | log_queries_not_using_indexes | ON | | long_query_time | 0.250000 | | min_examined_row_limit | 100 | | slow_query_log | ON | | slow_query_log_file | slow.log | +-------------------------------+----------+ 15 / 29
  • 16. Indexes are not only good ● Indexes use space (Disk, hot data in RAM!) ● www.fromdual.com Indexes use time to maintain (CPU, RAM, I/O) ● ● Optimizer needs time to determine which indexes to use. Sometimes optimizer is completely confused and does wrong decisions if too many (similar) indexes are there. → You must find the right balance to achieve fast queries using the optimal set of indexes. 16 / 29
  • 17. Smaller indexes faster queries www.fromdual.com ● Better fit into memory (less I/O) ● Higher data density (rows/block) ● Less CPU cycles (to crawl through) ● Prefixed indexes: ADD INDEX pre_ind (hash(8)); 17 / 29
  • 18. Avoid indexes www.fromdual.com ● Avoid redundant (and thus unnecessary ) indexes ● How does it happen? ● ● ● Developer 1: Creates a Foreign Key constraint → done Developer 2: Ouu! Query is slow → Oli told me to create an index! → done Developer 3: Ouu! Query is slow → Developer 2 is stupid! → Create and index → done ● Frameworks vs. Developer ● Upgrade process vs. Developer ● Avoid indexes which are not used / needed 18 / 29
  • 19. How to find such indexes? www.fromdual.com SHOW CREATE TABLE ...G mysqldump ­­no­data > structure_dump.sql ● Since MySQL 5.6: PERFORMANCE_SCHEMA ● Percona Server / MariaDB: Userstats ● http://fromdual.com/mysql-performance-schema-hints SELECT FROM WHERE AND ORDER object_schema, object_name, index_name performance_schema.table_io_waits_summary_by_index_usage index_name IS NOT NULL count_star = 0 BY object_schema, object_name; 19 / 29
  • 20. Avoid partial redundant indexes www.fromdual.com ● INDEX (city, last_name, first_name) ● INDEX (city, last_name) ● INDEX (city) ● INDEX (last_name, city) ??? ● INDEX (first_name, last_name) !!! 20 / 29
  • 21. Bad selectivity www.fromdual.com ● Remove indexes with bad selectivity (~= low cardinality) ● Candidates are: ● ● gender ● ● status active How to find if field has bad selectivity? Indexes (and Joins) are expensive!!! SELECT status, COUNT(*) FROM orders GROUP BY status; +--------+--------+ | status | cnt | +--------+--------+ | 0 | 393216 | | 1 | 262144 | | 2 | 12 | | 3 | 36 | | 4 | 24 | | 5 | 4 | | 6 | 8 | +--------+--------+ ● Break even between 15% and 66% ● Lets see if the MySQL optimizer knows about it... :-) 21 / 29
  • 22. Optimizer is wrong! SELECT * FROM orders WHERE status = 2; +--------+------+---------------+--------+------+ | table | type | possible_keys | key | rows | +--------+------+---------------+--------+------+ | orders | ref | status | status | 12 | +--------+------+---------------+--------+------+ SELECT * FROM orders WHERE status = 0; 1.43 s +--------+------+---------------+--------+--------+ | table | type | possible_keys | key | rows | +--------+------+---------------+--------+--------+ | orders | ref | status | status | 327469 | +--------+------+---------------+--------+--------+ www.fromdual.com SELECT status, COUNT(*) FROM orders GROUP BY status; +--------+--------+ | status | cnt | +--------+--------+ | 0 | 393216 | | 1 | 262144 | | 2 | 12 | | 3 | 36 | | 4 | 24 | | 5 | 4 | | 6 | 8 | +--------+--------+ SELECT * FROM orders IGNORE INDEX (STATUS) WHERE status = 0; 0.44 s +--------+------+---------------+------+--------+ | table | type | possible_keys | key | rows | +--------+------+---------------+------+--------+ | orders | ALL | NULL | NULL | 654939 | +--------+------+---------------+------+--------+ 5.6.12 (after analyze table) 22 / 29
  • 23. InnoDB PK and SK ● www.fromdual.com InnoDB has ● Primary Keys and ● Secondary Keys 23 / 29
  • 24. Clustered Index ● www.fromdual.com InnoDB: Data = Leaf of Primary Key ● We call this an Index Clustered Table (IOT) → Data are sorted like PK (key is sorted)! → PK influences Locality of data (physical location) ● AUTO_INCREMENT ~= sorting by time! ● Good for many things ● ● where hot data = recent data Bad for time series ● Where hot data = per item data 24 / 29
  • 25. Example: InnoDB www.fromdual.com A_I ts v_id xpos ypos ...    1 17:30 #42 x, y, ...    2 17:30 #43 x, y, ...    3 17:30 #44 x, y, ... #42 every 2' ... 2001 17:32 #42 x, y, ... 2002 17:32 #43 x, y, ... 2003 17:32 #44 x, y, ... Q1: Δ in rows? ~ 2000 rows A1: 1 row ~ 100 byte Q2: Δ in bytes? ~ 200 kbyte Q3: Default InnoDB block size? default: 16 kbyte Q4: Avg. # of rows of car #42 in 1 InnoDB block? ~ 1 A2: 3 d and 720 pt/d → ~2000 pt ~ 2000 rec ~ 2000 blk Q5: How long will this take and why (32 Mbyte)? ~ 2000 IOPS ~ 10s random read!!! S: All in RAM or strong I/O system or …? 2000 trucks over the last 3 days 25 / 29
  • 26. InnoDB PK safes the day! www.fromdual.com ts v_id xpos ypos ... 17:30 #42 x, y, ... 17:32 #42 x, y, ... 17:34 #42 x, y, ... ... #42 every 2' 17:30 #43 x, y, ... 17:32 #43 x, y, ... 17:34 #43 x, y, ... ... 17:30 #44 x, y, ... 2000 trucks Q1: Avg. # of rows of car #42 in 1 InnoDB block? ~ 120 A1: 3 d and 720 pt/d → ~2000 pt ~ 2000 rec ~ 20 blk Q2: How long will this take and why (320 kbyte)? ~ 1-2 IOPS ~ 10-20 ms sequential read! S: Wow f=50 faster! Any drawbacks? over the last 3 days 26 / 29
  • 27. Index hints ● MySQL optimizer is sometimes wrong! ● ● We have to help (= hint) him... Index hints are: ● USE INDEX (ind1, ind2) ● ● ● Only consider these indexes FORCE INDEX (ind3) ● Use this index without considering anything else IGNORE INDEX (ind1, ind3) ● ● www.fromdual.com Do NOT consider these indexes but everything else Hints should be used only as a last resort 27 / 29
  • 28. MySQL Variables ● MySQL variables influencing index use ● ● ● www.fromdual.com MyISAM: key_buffer_size InnoDB: innodb_buffer_pool_size /  innodb_buffer_pool_instances InnoDB Change Buffer ● innodb_change_buffer_max_size ● innodb_change_buffering ● Adaptive Hash Index (AHI) ● MySQL 5.6.3 / 5.5.14 index length 767 → 3072 bytes ● innodb_large_prefix 28 / 29
  • 29. Q&A www.fromdual.com Questions ? Discussion? We have time for some face-to-face talks... ● FromDual provides neutral and independent: ● Consulting ● Remote-DBA ● Support for MySQL, Galera, Percona Server and MariaDB ● Training www.fromdual.com/presentations 29 / 29