Optimizing MySQL
Upcoming SlideShare
Loading in...5
×
 

Optimizing MySQL

on

  • 843 views

Drupal Meetup Group Toronto

Drupal Meetup Group Toronto

Statistics

Views

Total Views
843
Views on SlideShare
718
Embed Views
125

Actions

Likes
0
Downloads
16
Comments
0

12 Embeds 125

http://www.tocker.ca 71
http://www.feedspot.com 12
http://localhost 11
http://feedreader.com 11
http://cloud.feedly.com 9
http://feeds.feedburner.com 4
http://linkup25.rssing.com 2
http://digg.com 1
http://10.0.1.4 1
http://d1qhe8io1bro9v.cloudfront.net 1
http://www.inoreader.com 1
http://feedly.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Optimizing MySQL Optimizing MySQL Presentation Transcript

    • <Insert Picture Here> Optimizing MySQL
 Morgan Tocker, MySQL Community Manager
 http://www.tocker.ca/

    • Safe Harbor Statement The  following  is  intended  to  outline  our  general  product  direction.   It  is  intended  for  information  purposes  only,  and  may  not  be   incorporated  into  any  contract.  It  is  not  a  commitment  to  deliver   any  material,  code,  or  functionality,  and  should  not  be  relied  upon   in  making  purchasing  decisions.   
 The  development,  release,  and  timing  of  any  features  or   functionality  described  for  Oracle’s  products  remains  at  the  sole   discretion  of  Oracle.
    • Options • • • • Upgrade Hardware and/or MySQL Version Optimize Configuration Optimize Queries Optimize Schema
    • Commentary • There are some specific cases where upgrades can make individual queries faster (i.e. subqueries). When I like this optimization the most, is to increase“capacity”. Lots of multi-core, multi-disk enhancements in 5.5 / 5.6. • MySQL 5.6 comes with a much more optimized configuration. There are now only 3-4 settings that need to change. • Optimizing queries is my favourite method :) There can be some big wins here. • Optimizing schema relates to query optimization. Sometimes you have to change schema to support certain queries, but it always starts with the queries.
    • Optimizing Queries • Allows you to focus on queries that damage user experiences rather than just slow. • Best method is to install a profiler. • MySQL also supports slow query logging + Performance Schema (5.6+).
    • # Continent Asia + population > 5M! mysql> EXPLAIN SELECT * FROM Country WHERE continent='Asia' 
 AND population > 5000000G! *************************** 1. row ***************************! id: 1! select_type: SIMPLE! table: Country! type: ALL! possible_keys: NULL! key: NULL! key_len: NULL! ref: NULL! rows: 267! Extra: Using where! 1 row in set (0.00 sec)
    • mysql> ALTER TABLE Country ADD INDEX p (population);! Query OK, 0 rows affected (0.02 sec)! Records: 0 Duplicates: 0 Warnings: 0! ! mysql> EXPLAIN SELECT * FROM Country WHERE continent='Asia' 
 AND population > 5000000G! *************************** 1. row ***************************! id: 1! select_type: SIMPLE! table: Country! type: ALL! possible_keys: p! key: NULL! key_len: NULL! ref: NULL! rows: 264! Extra: Using where! 1 row in set (0.01 sec)
    • # 50 Million! mysql> EXPLAIN SELECT * FROM Country WHERE continent='Asia' 
 AND population > 50000000G! *************************** 1. row ***************************! id: 1! select_type: SIMPLE! table: Country! type: range! possible_keys: p! key: p! key_len: 4! ref: NULL! rows: 24! Extra: Using index condition; Using where! 1 row in set (0.00 sec)
    • mysql> ALTER TABLE Country ADD INDEX c (continent);! Query OK, 0 rows affected (0.02 sec)! Records: 0 Duplicates: 0 Warnings: 0! ! mysql> EXPLAIN SELECT * FROM Country WHERE continent='Asia' ! AND population > 50000000G! *************************** 1. row ***************************! id: 1! select_type: SIMPLE! table: Country! type: ref! possible_keys: p,c! key: c! key_len: 1! ref: const! rows: 51! Extra: Using index condition; Using where! 1 row in set (0.00 sec)
    • mysql> ALTER TABLE Country ADD INDEX pc (population,continent);! Query OK, 0 rows affected (0.02 sec)! Records: 0 Duplicates: 0 Warnings: 0! ! mysql> EXPLAIN SELECT * FROM Country WHERE continent='Asia' ! AND population > 50000000G! *************************** 1. row ***************************! id: 1! select_type: SIMPLE! table: Country! type: ref! possible_keys: p,c,pc! key: c! key_len: 1! ref: const! rows: 51! Extra: Using index condition; Using where! 1 row in set (0.00 sec)
    • mysql> ALTER TABLE Country ADD INDEX cp (continent,population);! Query OK, 0 rows affected (0.01 sec)! Records: 0 Duplicates: 0 Warnings: 0! ! mysql> EXPLAIN SELECT * FROM Country WHERE continent='Asia' ! AND population > 50000000G! *************************** 1. row ***************************! id: 1! select_type: SIMPLE! table: Country! type: range! possible_keys: p,c,pc,cp! key: cp! key_len: 5! ref: NULL! rows: 11! Extra: Using index condition! 1 row in set (0.00 sec)
    • Tips • Think of where you can use indexes to eliminate rows - that’s the column you typically index. • Read: http://dev.mysql.com/doc/refman/5.6/en/ explain.html • Composite indexes somewhat an advanced topic: • Useful when a single column does not eliminate enough work. • “Ranges to the right”