SlideShare une entreprise Scribd logo
1  sur  16
Improving Performance
                                                                           with Better Indexes

                                                                                                      Ronald Bradford
                                                                                                 http://ronaldbradford.com
The only active MySQL group in New York
 http://www.meetup.com/EffectiveMySQL/                                                                     2011.05

 EffectiveMySQL.com - Its all about Performance and Scalability   EffectiveMySQL.com - Its all about Performance and Scalability




                       OBJECTIVE                                                                                      ABOUT
                                                                                                             Ronald BRADFORD

        Improve query performance,                                     12 years with MySQL / 22 years with RDBMS
                                       therefore                           Senior Consultant at MySQL Inc (06-08)

          Increase server throughput,                                  7 years presenting MySQL content
                                       therefore                       All time top MySQL blogger                                      Available NOW
                                                                                                                                        for consulting
             Reduce H/W to run your                                    Published author
                  application                                          Top industry recognitions and awards
                                                                                                                                   http://NYMySQLExpert.com
                                                                                                                                    http://RonaldBradford.com
 EffectiveMySQL.com - Its all about Performance and Scalability   EffectiveMySQL.com - Its all about Performance and Scalability
SOLUTIon                                                                      SQL REVIEW
                                                                                                                                                                Six step process
                                                                                               1. Capture
                                                                                               2. Identify

Extra: Using Index                                                                             3. Confirm
                                                                                               4. Analyze
                                                                                               5. Optimize
                                                                                               6. Verify

EffectiveMySQL.com - Its all about Performance and Scalability                                 EffectiveMySQL.com - Its all about Performance and Scalability




                                 Capture                                                                                        Capture
                                                                                                                                                                      Example




                                                            1 1
                                                                       Not discussed
                                                                 in detail this presentation
     General Query Log                                                                              Application Logging
     TCP/IP                                                                                         TCP/IP
     Connectors
     Application
     Proxy
     Plugin
     ...
EffectiveMySQL.com - Its all about Performance and Scalability                                 EffectiveMySQL.com - Its all about Performance and Scalability
Example                                                                                     Example




                                                            1 1
// Global replace mysql_query with db_query                                                 function db_query($sql) {
                                                                                              $start_time = microtime(true);
                                                                                              $rs = mysql_query($sql);
function db_query($sql) {                                                                     $exec_time = microtime(true) - $start_time;
  $rs = mysql_query($sql);                                                                    debug(format_time($exec_time) . ' ' . $sql . "n");
  return $rs;                                                                                 return $rs;
}                                                                                           }

                                                                                            function debug($str) {
                                                                                              if (DEBUG) echo $str;
                                                                                              return 0;
                                                                                            }

                                                                                            function format_time($time) {
                                                                                              return number_format($time, 8, '.', '');
                                                                                            }




EffectiveMySQL.com - Its all about Performance and Scalability                              EffectiveMySQL.com - Its all about Performance and Scalability




                                                                 Example                                                                                     Example




                                                            1 1
0.00010109      SELECT     ip FROM ...                                                      $ sudo tcpdump -i any port 3306 -s 65535 -x -nn -q -tttt
0.00005198      SELECT     name, value FROM ...                                             -c 10000 | mk-query-digest --type tcpdump
0.00005984      SELECT     id, status, ...
0.17592907      SELECT     g.id, c.id, ...                        24 statements on page     # Profile
0.00047803      SELECT     DISTINCT id_c FROM camp...            Easy to spot worst query   # Rank Query ID           Response time Calls R/Call Apdx V/M     Item
0.00741315      SELECT     DISTINCT id_c FROM camp..                                        # ==== ================== ============= ===== ====== ==== =====   ======
                                                                                            #    1 0xE5C8D4B9F7BDCCAF 0.5044 18.7%      1 0.5044 1.00 0.00    SELECT   ..
0.00058198      SELECT     id_c FROM cr ...                                                 #    2 0x813031B8BBC3B329 0.4893 18.2%     23 0.0213 1.00 0.01    COMMIT
0.00161815      SELECT     id_c FROM cr ...                                                 #    3 0x04AB3BC1A33D3B48 0.4107 15.2%      1 0.4107 1.00 0.00    SELECT   ..
0.00032806      SELECT     id_c FROM cr ...                                                 #    4 0xD15CA257BAF77DAF 0.3356 12.5%    321 0.0010 1.00 0.00    SELECT   ..
0.00007200      SELECT     DISTINCT id_a FROM arb ...                                       #    5 0x228B1F36C5EBCF1F 0.2177 8.1%       2 0.1089 1.00 0.22    SELECT   ..
0.00005412      SELECT     DISTINCT id_a FROM asw ...
0.00004697      SELECT     id_adv FROM arw
0.00004601      SELECT     id_adv FROM arw
0.00009012      SELECT     gk.id, k.value ...
0.00009084      SELECT     gk.id, k.value ...
0.00006318      SELECT     gk.id, k.value ...
0.00005794      SELECT     gk.id, k.value ...
0.00005603      SELECT     gk.id, k.value ...                                                                              http://effectiveMySQL.com/article/mk-query-digest

EffectiveMySQL.com - Its all about Performance and Scalability                              EffectiveMySQL.com - Its all about Performance and Scalability
IDENTIFY
                                                                                                                                                                           Example




                                                            2 2
                                                                       Not discussed                        Frequency
                                                                 in detail this presentation   //TODO
     By Duration of time                                                                       # Profile
                                                                                               # Rank Query ID           Response time Calls R/Call Apdx V/M                   Item
                                                                                               # ==== ================== ============= ===== ====== ==== =====                 ======
     By Frequency of execution                                                                 #
                                                                                               #
                                                                                                    1 0xE5C8D4B9F7BDCCAF 0.5044 18.7%
                                                                                                    2 0x813031B8BBC3B329 0.4893 18.2%
                                                                                                                                           1 0.5044 1.00 0.00
                                                                                                                                          23 0.0213 1.00 0.01
                                                                                                                                                                               SELECT
                                                                                                                                                                               COMMIT
                                                                                                                                                                                         ..

                                                                                               #    3 0x04AB3BC1A33D3B48 0.4107 15.2%      1 0.4107 1.00 0.00                  SELECT    ..
                                                                                               #    4 0xD15CA257BAF77DAF 0.3356 12.5%    321 0.0010 1.00 0.00                  SELECT    ..
                                                                                               #    5 0x228B1F36C5EBCF1F 0.2177 8.1%       2 0.1089 1.00 0.22                  SELECT    ..

                                                                                                                                                                          Duration




EffectiveMySQL.com - Its all about Performance and Scalability                                 EffectiveMySQL.com - Its all about Performance and Scalability




                                  CONFIRM                                                                                        CONFIRM




                                                            3 3
                                                                       Not discussed                                                                                  Not discussed
                                                                 in detail this presentation                                                                    in detail this presentation
     Via                                                                                            Watch & Isolate
         Application Logging                                                                            Locking
         mysql client                                                                                   Load
         SHOW PROFILES                                                                                  Caching




EffectiveMySQL.com - Its all about Performance and Scalability                                 EffectiveMySQL.com - Its all about Performance and Scalability
Example                                                                                     Example




                                                            3 3
                                                                       mysql client                                                                               mysql client
                                                                 10 millisecond precision                                                                    microsecond precision
mysql> SELECT ...                                                                           mysql> SELECT ...
1 row in set (0.00 sec)                                                                     1 row in set (0.00 sec)


                                                                                            # What you really want is?

                                                                                            mysql> SELECT ...
                                                                                            1 row in set (0.008110 sec)




                                                                                                                           http://j.mp/gM3Hb3
EffectiveMySQL.com - Its all about Performance and Scalability                              EffectiveMySQL.com - Its all about Performance and Scalability




                                                                                                                                ANALYZE
                                                                  Example




                                                            3 4
mysql> SET PROFILING=1;                                            Quick verification
                                                                 microsecond precision
                                                                                                 EXPLAIN
mysql> SELECT SLEEP(1);
mysql> SELECT SLEEP(2);                                                                          SHOW CREATE TABLE
mysql> SHOW PROFILES;                                                                            SHOW INDEXES FROM
+----------+------------+-----------------+
| Query_ID | Duration   | Query           |                                                      INFORMATION_SCHEMA.TABLES
+----------+------------+-----------------+
|
|
         1 | 1.00135300 | SELECT SLEEP(1) |
         2 | 2.00215600 | SELECT SLEEP(2) |                                                      SHOW TABLE STATUS LIKE
+----------+------------+-----------------+
                                                                                                 EXPLAIN EXTENDED

EffectiveMySQL.com - Its all about Performance and Scalability                              EffectiveMySQL.com - Its all about Performance and Scalability
Example                                                                                              Example




                                                            4 4
mysql> EXPLAIN SELECT p.amt, p.reference                                                        mysql> SHOW CREATE TABLE wp_users G
FROM       payment p
JOIN       invoice i ON i.inv_id = p.inv_id                                                     CREATE TABLE `wp_users` (
WHERE      i.due_date = '2009-10-14'                                                              `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
AND        i.user_id = 1                                                                          `user_login` varchar(60) NOT NULL DEFAULT '',
AND        i.account_id = 10                                                                      `user_pass` varchar(64) NOT NULL DEFAULT '',
                                                                                                  `user_nicename` varchar(50) NOT NULL DEFAULT '',
AND        p.amt > 0
                                                                                                  `user_email` varchar(100) NOT NULL DEFAULT '',
                                                                                                  `user_url` varchar(100) NOT NULL DEFAULT '',
+----+-------------+-------+------+---------------+------+---------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | rows | Extra        |
                                                                                                  `user_registered` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
+----+-------------+-------+------+---------------+------+---------+------+-------------+         `user_activation_key` varchar(60) NOT NULL DEFAULT '',
| 1 | SIMPLE       | i     | ref | PRIMARY,u,a,d | u     | 4       |    1 | Using where |         `user_status` int(11) NOT NULL DEFAULT '0',
| 1 | SIMPLE       | p     | ref | i              | i    | 4       |    6 | Using where |         `display_name` varchar(250) NOT NULL DEFAULT '',
+----+-------------+-------+------+---------------+------+---------+------+-------------+         PRIMARY KEY (`ID`),
                                                                                                  KEY `user_login_key` (`user_login`),
                                                                                                  KEY `user_nicename` (`user_nicename`)
                                                                           Format modified for   ) ENGINE=MyISAM DEFAULT CHARSET=utf8
                                                                             display purposes




EffectiveMySQL.com - Its all about Performance and Scalability                                  EffectiveMySQL.com - Its all about Performance and Scalability




                                                                         Example                                                                                              Example




                                                            4 4
mysql> SHOW INDEXES FROM wp_posts;                                                              mysql> SHOW INDEXES FROM ...;

...+------------+------------------+--------------+-------------+...                            +------------+--------------+--------------+-----------------+-----------+-------------+
...| Non_unique | Key_name         | Seq_in_index | Cardinality |...                            | Non_unique | Key_name     | Seq_in_index | Column_name     | Collation | Cardinality |
                                                                                                +------------+--------------+--------------+-----------------+-----------+-------------+
...+------------+------------------+--------------+-------------+...                            |          0 | PRIMARY      |            1 | id              | A         |      100085 |
...|          0 | PRIMARY          |            1 |        2606 |...                            |          1 | is_available |            1 | is_available    | A         |           4 |
...|          1 | post_name        |            1 |        2606 |...                            |          1 | is_active    |            1 | is_active       | A         |           4 |
                                                                                                |          1 | market       |            1 | is_active       | A         |          36 |
...|          1 | type_status_date |            1 |           4 |...                            |          1 | market       |            2 | is_available    | A         |          36 |
...|          1 | type_status_date |            2 |           6 |...                            |          1 | market       |            3 | is_proposed     | A         |         238 |
...|          1 | type_status_date |            3 |        2606 |...                            +------------+--------------+--------------+-----------------+-----------+-------------+
...|          1 | type_status_date |            4 |        2606 |...
...|          1 | post_parent      |            1 |         217 |...
...|          1 | post_author      |            1 |           1 |...
...+------------+------------------+--------------+-------------+...




EffectiveMySQL.com - Its all about Performance and Scalability                                  EffectiveMySQL.com - Its all about Performance and Scalability
Example                                                                               Example




                                                                         4 4
mysql> SELECT table_schema,table_name,engine,                                                                    mysql> SHOW TABLE STATUS LIKE 'wp_posts'G
          row_format,table_rows, avg_row_length,                                                                            Name: wp_posts
         (data_length+index_length)/1024/1024 as total_mb,                                                                Engine: MyISAM
         (data_length)/1024/1024 as data_mb,                                                                             Version: 10
         (index_length)/1024/1024 as index_mb                                                                         Row_format: Dynamic
FROM     INFORMATION_SCHEMA.TABLES
                                                                                                                            Rows: 2649
WHERE    table_schema=DATABASE()
AND      table_name = 'example'G
                                                                                                                  Avg_row_length: 2850
                                                                                                                     Data_length: 7550800
  table_schema:           example                                                                                Max_data_length: 281474976710655
    table_name:           example                                                                                   Index_length: 259072
        engine:           MyISAM                                                                                       Data_free: 0
    row_format:           Dynamic                                                                                 Auto_increment: 3586
    table_rows:           260006
                                                                                                                     Create_time: 2011-02-02 12:04:21
avg_row_length:           2798
      total_mb:           700.20174026                                                                               Update_time: 2011-03-19 11:42:12
       data_mb:           600.95564651                                                                                Check_time: 2011-02-02 12:04:21
      index_mb:            99.24609375                                                                                 Collation: utf8_general_ci



EffectiveMySQL.com - Its all about Performance and Scalability                                                   EffectiveMySQL.com - Its all about Performance and Scalability




                                                                                            Example                                                                               Example




                                                                         4 4
mysql> EXPLAIN SELECT x.uuid, ..., y.uniqueid                                                                    mysql> EXPLAIN EXTENDED SELECT x.uuid, ..., y.uniqueid
       FROM table1 x, table2 y                                                                                          FROM table1 x, table2 y
       WHERE x.uuid=y.uniqueid;                                                                                         WHERE x.uuid = y.uniqueid;
                                                                                                                 mysql> SHOW WARNINGS;
+----+---------+-------+--------+-----------+---------+---------+------+----------+--------------------------+
| id | select_ | table | type   | possible_ | key     | key_len | ref | rows      | Extra                    |     Level: Note
+----+---------+-------+--------+-----------+---------+---------+------+----------+--------------------------+
| 1 | SIMPLE | x       | ALL    | NULL      | NULL    | NULL    | NULL | 29960165 |                          |      Code: 10031
| 1 | SIMPLE | y       | eq_ref | PRIMARY   | PRIMARY | 194     | func |        1 | Using where; Using index |
+----+---------+-------+--------+-----------+---------+---------+------+----------+--------------------------+   Message: select `schema`.`x`.`uuid` AS `uuid`, ...
                                                                                                                 `schema`.`y`.`uniqueid` AS `uniqueid` from
                                                                                                                 `schema`.`table1` `x` join `schema`.`table2` `y`
                                                                                                                 where (convert(`schema`.`x`.`uuid` using utf8) =
                                                                                                                 `test`.`y`.`uniqueid`




EffectiveMySQL.com - Its all about Performance and Scalability                                                   EffectiveMySQL.com - Its all about Performance and Scalability
OPTIMIZE                                                                                          THEORY
                                                                                                                                                         Example




                                                            5 5
                                                                    Not discussed
                                                                 in this presentation   CREATE TABLE posts (
     Adding Indexes                                                                       id      INT UNSIGNED NOT NULL AUTO_INCREMENT,
                                                                                          author INT UNSIGNED NOT NULL,
                                                                                          status VARCHAR(20) NOT NULL DEFAULT 'publish',
     Query simplification                                                                  name    VARCHAR(100) NOT NULL,
                                                                                          content TEXT NOT NULL,
                                                                                          comment_count INT UNSIGNED NOT NULL,
     Eliminate queries                                                                    PRIMARY KEY (id),
                                                                                          KEY name (name)

     MySQL configuration                                                                 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;



     Schema design
     ...

EffectiveMySQL.com - Its all about Performance and Scalability                          EffectiveMySQL.com - Its all about Performance and Scalability




                                                                         Example                                                                         Example




                                                            5 5
                                                                                        mysql> ALTER TABLE posts ADD INDEX (author);
mysql> EXPLAIN                                                                          mysql> EXPLAIN
       SELECT COUNT(*) FROM posts                                                              SELECT COUNT(*) FROM posts
       WHERE author=2 AND status='draft' G                                                    WHERE author=2 AND status='draft' G

           id:          1                                                                          id:          1
  select_type:          SIMPLE                                                            select_type:          SIMPLE                                   Adding an index
        table:          posts                                                                   table:          posts
         type:          ALL                                                                      type:          ref
possible_keys:          NULL                                                            possible_keys:          author
          key:          NULL                                                                      key:          author
      key_len:          NULL                                                                  key_len:          4
          ref:          NULL                                                                      ref:          const
         rows:          2649                                                                     rows:          373
        Extra:          Using where                                                             Extra:          Using where




EffectiveMySQL.com - Its all about Performance and Scalability                          EffectiveMySQL.com - Its all about Performance and Scalability
COVERING INDEX
                                                                   Example




                                                            5 5
mysql> ALTER TABLE posts ADD INDEX (author,status);
mysql> EXPLAIN                                                                                Extra: Using Index
       SELECT COUNT(*) FROM posts
       WHERE author=2 AND status='draft' G
                                                                                                  Does not mean using index
           id:          1
  select_type:
        table:
                        SIMPLE
                        posts
                                                                 Adding a better index            Means using ONLY the index
         type:          ref
possible_keys:          author                                                                All query columns are satisfied by index
          key:          author
      key_len:          66
          ref:          const,const
         rows:          31
        Extra:          Using where; Using index




EffectiveMySQL.com - Its all about Performance and Scalability                           EffectiveMySQL.com - Its all about Performance and Scalability




COVERING INDEX
                                                                                                                                                          Example




                                                            5 5
                                                                                         mysql> ALTER TABLE posts ENGINE=MyISAM;
     Storage Engines matter                                                              mysql> EXPLAIN
                                                                                                SELECT id FROM posts
         MyISAM Indexes                                                                         WHERE author=2 AND status='draft' G

                                                                                                    id:          1
         InnoDB Indexes                                                                    select_type:
                                                                                                 table:
                                                                                                                 SIMPLE
                                                                                                                 posts
                                                                                                  type:          ref
                                                                                         possible_keys:          author
                                                                                                   key:          author
                                                                                               key_len:          66
                                                                                                   ref:          const,const
                                                                                                  rows:          31
                                                                                                 Extra:          Using where




EffectiveMySQL.com - Its all about Performance and Scalability                           EffectiveMySQL.com - Its all about Performance and Scalability
Parent/Child
                                                                                     Example                                                                                        Example




                                                                   5 5
mysql> ALTER TABLE posts ENGINE=InnoDB;                                                        CREATE TABLE invoice (
mysql> EXPLAIN                                                                                   inv_id         INT UNSIGNED NOT NULL,                                                 Master/Child
                                                                                                 user_id        INT UNSIGNED NOT NULL,
       SELECT id FROM posts                                                                      account_id     INT UNSIGNED NOT NULL,                                                 Relationship
       WHERE author=2 AND status='draft' G                                                      invoice_date   DATE NOT NULL,
                                                                                                 due_date       DATE NOT NULL,
           id:             1                                                                   PRIMARY KEY pk (inv_id),
  select_type:             SIMPLE                                                              INDEX u (user_id),
        table:             posts                                                               INDEX a (account_id),
                                                                                               INDEX d (due_date)
         type:             ref                                                                 ) ENGINE=InnoDB;
possible_keys:             author                                                              CREATE TABLE payment (
          key:             author                                                                pay_id     INT UNSIGNED NOT NULL AUTO_INCREMENT,
      key_len:             66                                                                    inv_id     INT UNSIGNED NOT NULL,
          ref:             const,const                                                           amt        DECIMAL (10,2) NOT NULL,
         rows:             34                                                                    reference VARCHAR(20) NOT NULL,
                                                                                               PRIMARY KEY pk (pay_id),
        Extra:             Using where; Using index                                            INDEX i (inv_id)
                                                                                               ) ENGINE=InnoDB;



EffectiveMySQL.com - Its all about Performance and Scalability                                 EffectiveMySQL.com - Its all about Performance and Scalability




                                                                                     Example                                                                                        Example




                                                                   5 5
EXPLAIN                                                                                        EXPLAIN
SELECT      p.amt, p.reference                                                                 SELECT      p.amt, p.reference
FROM        payment p                                                                          FROM        payment p
JOIN        invoice i ON i.inv_id = p.inv_id                                                   JOIN        invoice i ON i.inv_id = p.inv_id
WHERE       i.due_date = '2009-10-14'                                                          WHERE       i.due_date = '2009-10-14'
AND         i.user_id = 1                                                                      AND         i.user_id = 1
AND
AND
            i.account_id = 10
            p.amt > 0
                                                                  Important Start              AND
                                                                                               AND
                                                                                                           i.account_id = 10
                                                                                                           p.amt > 0
                                                                                                                                                                 Important Start
+----+-------------+-------+------+---------------+------+---------+------+-------------+      +----+-------------+-------+------+---------------+------+---------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | rows | Extra        |      | id | select_type | table | type | possible_keys | key | key_len | rows | Extra        |
+----+-------------+-------+------+---------------+------+---------+------+-------------+      +----+-------------+-------+------+---------------+------+---------+------+-------------+
| 1 | SIMPLE       | i     | ref | PRIMARY,u,a,d | u     | 4       |    1 | Using where |      | 1 | SIMPLE       | i     | ref | PRIMARY,u,a,d | u     | 4       |    1 | Using where |
| 1 | SIMPLE       | p     | ref | i              | i    | 4       |    6 | Using where |      | 1 | SIMPLE       | p     | ref | i              | i    | 4       |    6 | Using where |
+----+-------------+-------+------+---------------+------+---------+------+-------------+      +----+-------------+-------+------+---------------+------+---------+------+-------------+

                                                                                               SHOW CREATE TABLE payment G
                                                                                               ...
                                                                                               PRIMARY KEY pk (pay_id),
                                                                                               INDEX i (inv_id)
                                                                                               ) ENGINE=InnoDB;




EffectiveMySQL.com - Its all about Performance and Scalability                                 EffectiveMySQL.com - Its all about Performance and Scalability
Example                                                                                           Example




                                                            5 5
                                                                                Before
SELECT     p.amt, p.reference
FROM       payment p                                                            +----+-------------+-------+------+---------------+------+---------+------+-------------+
JOIN       invoice i ON i.inv_id = p.inv_id                                     | id | select_type | table | type | possible_keys | key | key_len | rows | Extra        |
                                                                                +----+-------------+-------+------+---------------+------+---------+------+-------------+
WHERE      i.due_date = '2009-10-14'
AND
AND
           i.user_id = 1
           i.account_id = 10
                                                          Identify additional   | 1 | SIMPLE
                                                                                | 1 | SIMPLE
                                                                                                   | i
                                                                                                   | p
                                                                                                           | ref | PRIMARY,u,a,d | u
                                                                                                           | ref | i              | i
                                                                                                                                         | 4
                                                                                                                                         | 4
                                                                                                                                                   |
                                                                                                                                                   |
                                                                                                                                                        1 | Using where |
                                                                                                                                                        6 | Using where |
                                                                                +----+-------------+-------+------+---------------+------+---------+------+-------------+

AND        p.amt > 0                                           column
                                                                                After
ALTER TABLE payment                                                             +----+-------------+-------+------+---------------+------+---------+------+-------------+
DROP INDEX i, ADD INDEX i (inv_id, amt);                                        | id | select_type | table | type | possible_keys | key | key_len | rows | Extra        |
                                                                                +----+-------------+-------+------+---------------+------+---------+------+-------------+
                                                                                | 1 | SIMPLE       | i     | ref | PRIMARY,u,a,d | u     | 4       |    1 | Using where |
                                                                                | 1 | SIMPLE       | p     | ref | i              | i    | 4       |    6 | Using where |
                                                                                +----+-------------+-------+------+---------------+------+---------+------+-------------+




                                                                                                                                              Zero Improvement

EffectiveMySQL.com - Its all about Performance and Scalability                  EffectiveMySQL.com - Its all about Performance and Scalability




                                                                   Example                                                                                           Example




                                                            5 5
SELECT     p.amt, p.reference                                                   Before
FROM       payment p
JOIN       invoice i ON i.inv_id = p.inv_id                                     +----+-------------+-------+------+---------------+------+---------+------+-------------+
WHERE      i.due_date = '2009-10-14'                                            | id | select_type | table | type | possible_keys | key | key_len | rows | Extra        |
                                                                                +----+-------------+-------+------+---------------+------+---------+------+-------------+
AND
AND
           i.user_id = 1
           i.account_id = 10                            Identify additional     | 1 | SIMPLE
                                                                                | 1 | SIMPLE
                                                                                                   | i
                                                                                                   | p
                                                                                                           | ref | PRIMARY,u,a,d | u
                                                                                                           | ref | i              | i
                                                                                                                                         | 4
                                                                                                                                         | 4
                                                                                                                                                   |
                                                                                                                                                   |
                                                                                                                                                        1 | Using where |
                                                                                                                                                        6 | Using where |
                                                                                +----+-------------+-------+------+---------------+------+---------+------+-------------+
AND        p.amt > 0
                                                             column
                                                                                After
ALTER TABLE payment
DROP INDEX i, ADD INDEX i (inv_id, amt, reference);                             +----+-------------+-------+------+---------------+------+---------+------+--------------------------+
                                                                                | id | select_type | table | type | possible_keys | key | key_len | rows | Extra                     |
                                                                                +----+-------------+-------+------+---------------+------+---------+------+--------------------------+
                                                                                | 1 | SIMPLE       | i     | ref | PRIMARY,u,a,d | u     | 4       |    1 | Using where              |
                                                                                | 1 | SIMPLE       | p     | ref | i              | i    | 4       |    6 | Using where; Using index |
                                                                                +----+-------------+-------+------+---------------+------+---------+------+--------------------------+




                                                                                                                            Covering Index

EffectiveMySQL.com - Its all about Performance and Scalability                  EffectiveMySQL.com - Its all about Performance and Scalability
Example                                                                               Example




                                                                   5 5
SELECT      p.amt, p.reference                                                                           SELECT     p.amt, p.reference
FROM        payment p                                                                                    FROM       payment p
JOIN        invoice i ON i.inv_id = p.inv_id                                                             JOIN       invoice i ON i.inv_id = p.inv_id
WHERE       i.due_date = '2009-10-14'                                                                    WHERE      i.due_date = '2009-10-14'
AND
AND
            i.user_id = 1
            i.account_id = 10
                                                                                                         AND
                                                                                                         AND
                                                                                                                    i.user_id = 1
                                                                                                                    i.account_id = 10                            Identify additional
AND         p.amt > 0

+----+-------------+-------+------+---------------+------+---------+------+-------------+
                                                                                                         AND        p.amt > 0
                                                                                                                                                                      column
| id | select_type | table | type | possible_keys | key | key_len | rows | Extra        |                ALTER TABLE invoice
+----+-------------+-------+------+---------------+------+---------+------+-------------+
| 1 | SIMPLE       | i     | ref | PRIMARY,u,a,d | u     | 4       |    1 | Using where |                DROP INDEX u, ADD INDEX u (user_id, account_id);
| 1 | SIMPLE       | p     | ref | i              | i    | 4       |    6 | Using where |
+----+-------------+-------+------+---------------+------+---------+------+-------------+

CREATE TABLE invoice (
...                                                                                                                                                                        Is account_id index
PRIMARY KEY pk (inv_id),                                                                                                                                                       needed now?
INDEX u (user_id),
INDEX a (account_id),
INDEX d (due_date)
) ENGINE=InnoDB;



EffectiveMySQL.com - Its all about Performance and Scalability                                           EffectiveMySQL.com - Its all about Performance and Scalability




                                                                                     Example                                                                               Example




                                                                   5 5
Before                                                                                                   SELECT     p.amt, p.reference
                                                                                                         FROM       payment p
+----+-------------+-------+------+---------------+------+---------+------+--------------------------+   JOIN       invoice i ON i.inv_id = p.inv_id
| id | select_type | table | type | possible_keys | key | key_len | rows | Extra                     |   WHERE      i.due_date = '2009-10-14'
+----+-------------+-------+------+---------------+------+---------+------+--------------------------+
| 1 | SIMPLE
| 1 | SIMPLE
                   | i
                   | p
                           | ref | PRIMARY,u,a,d | u
                           | ref | i              | i
                                                         | 4
                                                         | 4
                                                                   |
                                                                   |
                                                                        1 | Using where              |
                                                                        6 | Using where; Using index |
+----+-------------+-------+------+---------------+------+---------+------+--------------------------+
                                                                                                         AND
                                                                                                         AND
                                                                                                                    i.user_id = 1
                                                                                                                    i.account_id = 10                            Identify additional
After
                                                                                                         AND        p.amt > 0
                                                                                                                                                                      column
+----+-------------+-------+------+---------------+------+---------+------+--------------------------+
                                                                                                         ALTER TABLE invoice
| id | select_type | table | type | possible_keys | key | key_len | rows | Extra                     |   DROP INDEX u, ADD INDEX u (user_id, account_id, due_date);
+----+-------------+-------+------+---------------+------+---------+------+--------------------------+
| 1 | SIMPLE       | i     | ref | u              | u    | 8       |    1 | Using where              |
| 1 | SIMPLE       | p     | ref | i              | i    | 4       |    6 | Using where; Using index |
+----+-------------+-------+------+---------------+------+---------+------+--------------------------+




                                       Better Index Usage

EffectiveMySQL.com - Its all about Performance and Scalability                                           EffectiveMySQL.com - Its all about Performance and Scalability
VERIFY
                                                                                     Example




                                                                   5 6
Before
                                                                                                              Quantifiable
+----+-------------+-------+------+---------------+------+---------+------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | rows | Extra                     |
+----+-------------+-------+------+---------------+------+---------+------+--------------------------+
| 1 | SIMPLE
| 1 | SIMPLE
                   | i
                   | p
                           | ref | u
                           | ref | i
                                                  | u
                                                  | i
                                                         | 8
                                                         | 4
                                                                   |
                                                                   |
                                                                        1 | Using where              |
                                                                        6 | Using where; Using index |
                                                                                                              Reproducable
+----+-------------+-------+------+---------------+------+---------+------+--------------------------+


After
+----+-------------+-------+------+---------------+------+---------+------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | rows | Extra                     |
+----+-------------+-------+------+---------------+------+---------+------+--------------------------+
| 1 | SIMPLE       | i     | ref | u              | u    | 11      |    1 | Using index              |
| 1 | SIMPLE       | p     | ref | i              | i    | 4       |    6 | Using where; Using index |
+----+-------------+-------+------+---------------+------+---------+------+--------------------------+




                                                                Covering Index
                     Better Index Usage

EffectiveMySQL.com - Its all about Performance and Scalability                                           EffectiveMySQL.com - Its all about Performance and Scalability




        REAL WORLD                                                                                             REAL WORLD
                                                                                     Example                                                                              Example




                                                                   6 6
+----+---------+----+--------+------+------+-------------+                                               +----+---------+----+--------+------+------+--------------------------+
| id | select_t| tab| key    | key_ | rows | Extra       |                                               | id | select_t| tab| key    | key_ | rows | Extra                    |
+----+---------+----+--------+------+------+-------------+                                               +----+---------+----+--------+------+------+--------------------------+
| 1 | PRIMARY | c | statu | 1       |   74 | Using where |                                               | 1 | PRIMARY | e | statu | 1       |   33 | Using where; Using index |
| 1 | PRIMARY | e | PRIMA | 4       |    1 | Using where |                                               | 1 | PRIMARY | c | adver | 4       |    7 | Using where              |
| 1 | PRIMARY | g | campa | 4       |    1 | Using where |                                               | 1 | PRIMARY | g | campa | 4       |    1 | Using where              |
| 10 | DEPENDEN| crb| id_ca | 4     | 253 | Using where |                                  BEFORE        | 10 | DEPENDEN| crb| id_ca | 66    |    1 | Using where           AFTER
                                                                                                                                                                               |
| 9 | DEPENDEN| csb| pub_s | 98     |    1 | Using where |                                               | 9 | DEPENDEN| csb| pub_s | 98     |    1 | Using where              |
| 8 | DEPENDEN| arb| id_ad | 4      | 901 | Using where |                                                | 8 | DEPENDEN| arb| id_ad | 26     |    1 | Using where              |
| 7 | DEPENDEN| asb| pub_s | 34     |    1 | Using where |                                               | 7 | DEPENDEN| asb| id_ad | 40     |    1 | Using where; Using index |
| 6 | DEPENDEN| pm | id_adr | 4     |   42 | Using where |                                               | 6 | DEPENDEN| pm | id_adr | 12    |    1 | Using index              |
| 5 | DEPENDEN| tgv| searc | 4      |    2 | Using where |                                               | 5 | DEPENDEN| tgv| searc | 10     |    1 | Using where; Using index |
| 4 | DEPENDEN| st | id_sc | 4      |    7 | Using where |                                               | 4 | DEPENDEN| st | id_sc | 4      |    7 | Using where; Using index |
| 4 | DEPENDEN| t | PRIMA | 4       |    1 | Using where |                                               | 4 | DEPENDEN| t | PRIMA | 4       |    1 | Using where              |
| 3 | DEPENDEN| k2 | keywo | 302 |       4 | Using where |                                               | 3 | DEPENDEN| k2 | keywo | 302 |       3 | Using where; Using index |
| 3 | DEPENDEN| gk2| PRIMA | 100 |       1 | Using where |                                               | 3 | DEPENDEN| gk2| PRIMA | 100 |       1 | Using where              |
| 2 | DEPENDEN| k1 | keywo | 302 |       3 | Using where |                                               | 2 | DEPENDEN| k1 | keywo | 302 |       2 | Using where; Using index |
| 2 | DEPENDEN| gk1| PRIMA | 100 |       1 | Using where |                                               | 2 | DEPENDEN| gk1| PRIMA | 100 |       1 | Using where              |
+----+---------+----+--------+------+------+-------------+                                               +----+---------+----+--------+------+------+--------------------------+

                                                                                       175ms                                                                              10ms

EffectiveMySQL.com - Its all about Performance and Scalability                                           EffectiveMySQL.com - Its all about Performance and Scalability
REAL WORLD
                                                                         Example




                                                                    6 6
+----+---------+----+--------+------+------+-------------+
                                    +----+---------+----+--------+------+--------------------------+
| id | select_t| tab| key    | key_ || id | select_t| tab| |
                                        rows | Extra        key  | key_ | Extra                    |



                                                                                                                 Sometimes a
+----+---------+----+--------+------+------+-------------+
                                    +----+---------+----+--------+------+--------------------------+
| 1 | PRIMARY | c | statu | 1       || 1 74 PRIMARY |where |
                                          | | Using c | adver | 4       | Using where              |
| 1 | PRIMARY | e | PRIMA | 4       || 1 |1 PRIMARY |where |
                                              | Using e | statu | 1     | Using where; Using index |
| 1 | PRIMARY | g | campa | 4       || 1 |1 PRIMARY |where |
                                              | Using g | campa | 4     | Using where              |
| 10 | DEPENDEN| crb| id_ca | 4     || 10253 DEPENDEN|where |
                                          | | Using crb| id_ca | 66     | Using where              |



                                                                                                                Covering Index
| 9 | DEPENDEN| csb| pub_s | 98 || 9 |1 DEPENDEN|where |
                                              | Using csb| pub_s | 98   | Using where              |
| 8 | DEPENDEN| arb| id_ad | 4      || 8901 DEPENDEN|where |
                                          | | Using arb| id_ad | 26     | Using where              |
| 7 | DEPENDEN| asb| pub_s | 34 || 7 |1 DEPENDEN|where |
                                              | Using asb| id_ad | 40   | Using where; Using index |
| 6 | DEPENDEN| pm | id_adr | 4     || 6 42 DEPENDEN|where |
                                          | | Using pm | id_adr | 12    | Using index              |
| 5 | DEPENDEN| tgv| searc | 4      || 5 |2 DEPENDEN|where |
                                              | Using tgv| searc | 10   | Using where; Using index |



                                                                                                                 is ineffective
| 4 | DEPENDEN| st | id_sc | 4      || 4 |7 DEPENDEN|where |
                                              | Using st | id_sc | 4    | Using where; Using index |
| 4 | DEPENDEN| t | PRIMA | 4       || 4 |1 DEPENDEN|where |
                                              | Using t | PRIMA | 4     | Using where              |
| 3 | DEPENDEN| k2 | keywo | 302 || 3 |4 DEPENDEN|where |
                                              | Using k2 | keywo | 302 | Using where; Using index |
| 3 | DEPENDEN| gk2| PRIMA | 100 || 3 |1 DEPENDEN|where |
                                              | Using gk2| PRIMA | 100 | Using where               |
| 2 | DEPENDEN| k1 | keywo | 302 || 2 |3 DEPENDEN|where |
                                              | Using k1 | keywo | 302 | Using where; Using index |
| 2 | DEPENDEN| gk1| PRIMA | 100 || 2 |1 DEPENDEN|where |
                                              | Using gk1| PRIMA | 100 | Using where               |
+----+---------+----+--------+------+------+-------------+
                                    +----+---------+----+--------+------+--------------------------+

                                                                         10ms

        EffectiveMySQL.com - Its all about Performance and Scalability                                 EffectiveMySQL.com - Its all about Performance and Scalability




                                                                                                                                                                        Example




                                                                    6 6
                                                                                                       +----+---------+----+--------+------+------+-------------+
                                                                                                       | id | select_t| tab| key    | key_ | rows | Extra       |
                                                                                                       +----+---------+----+--------+------+------+-------------+
                                                                                                       ...
                                                                                                       | 10 | DEPENDEN| crb| id_ca | 4     | 253 | Using where |
                                                                                                       ....




                 Partial Column                                                                        +----+---------+----+--------+------+------+--------------------------+



                      Index
                                                                                                       | id | select_t| tab| key    | key_ | rows | Extra                    |
                                                                                                       +----+---------+----+--------+------+------+--------------------------+
                                                                                                       ...
                                                                                                       | 10 | DEPENDEN| crb| id_ca | 66    |    1 | Using where              |
                                                                                                       ...




        EffectiveMySQL.com - Its all about Performance and Scalability                                 EffectiveMySQL.com - Its all about Performance and Scalability
Re-OPTIMIZE
                                                                 Example




                                                            6 5
...
NOT EXISTS (                                                                    Change data types
  SELECT 1
  FROM   crb
  WHERE crb.id = p.id AND crb.value = 'xyz')                                    Simplify query                                               Optimizing SQL is an
...                                                                                                                                          iterative process
                                                                                Removed normalization
CREATE TABLE crb(
  id     INT UNSIGNED NOT NULL,                                                 Other secrets ...
  value VARCHAR(100) NOT NULL,
  ....

   INDEX (id, value(20))
);




EffectiveMySQL.com - Its all about Performance and Scalability             EffectiveMySQL.com - Its all about Performance and Scalability




                                               VERIFY                                                                     VERIFY




                                                            6 6
                                                                                                                                            VERY, VERY IMPORTANT
                                                                           Cardinal Sin
                      Repeat as                                                 Indexes affect all queries on table

                      necessary
     175ms to 10ms to 3ms
     Happy client is now more happy

EffectiveMySQL.com - Its all about Performance and Scalability             EffectiveMySQL.com - Its all about Performance and Scalability
CONCLUSION




                                                    C ?
     6 steps to successful SQL review                                      Tell me your
     Optimization is an iterative process
     Rows, storage engines, configuration &
                                                                          success stories!
     MySQL version affect results over time                                               ronald@EffectiveMySQL.com

     Indexes are not the only optimization                       Saved 50% daily hosting = $500 p.d = $180,000 p.y.
     Indexes are not the best optimization
                                                                                   http://effectiveMySQL.com/presentations


EffectiveMySQL.com - Its all about Performance and Scalability   EffectiveMySQL.com - Its all about Performance and Scalability




EffectiveMySQL.com - Its all about Performance and Scalability

Contenu connexe

Tendances

GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012Arun Gupta
 
Java EE Technical Keynote at JavaOne Latin America 2011
Java EE Technical Keynote at JavaOne Latin America 2011Java EE Technical Keynote at JavaOne Latin America 2011
Java EE Technical Keynote at JavaOne Latin America 2011Arun Gupta
 
Java EE 7: Developing for the Cloud at Geecon, JEEConf, Johannesburg
Java EE 7: Developing for the Cloud at Geecon, JEEConf, JohannesburgJava EE 7: Developing for the Cloud at Geecon, JEEConf, Johannesburg
Java EE 7: Developing for the Cloud at Geecon, JEEConf, JohannesburgArun Gupta
 
Java EE 7 at JAX London 2011 and JFall 2011
Java EE 7 at JAX London 2011 and JFall 2011Java EE 7 at JAX London 2011 and JFall 2011
Java EE 7 at JAX London 2011 and JFall 2011Arun Gupta
 
GlassFish Community Update @ JavaOne 2011
GlassFish Community Update @ JavaOne 2011GlassFish Community Update @ JavaOne 2011
GlassFish Community Update @ JavaOne 2011Arun Gupta
 
The State of Java under Oracle at JCertif 2011
The State of Java under Oracle at JCertif 2011The State of Java under Oracle at JCertif 2011
The State of Java under Oracle at JCertif 2011Arun Gupta
 
Jfokus 2012 : The Java EE 7 Platform: Developing for the Cloud
Jfokus 2012 : The Java EE 7 Platform: Developing for the CloudJfokus 2012 : The Java EE 7 Platform: Developing for the Cloud
Jfokus 2012 : The Java EE 7 Platform: Developing for the CloudArun Gupta
 
Java EE / GlassFish Strategy & Roadmap @ JavaOne 2011
Java EE / GlassFish Strategy & Roadmap @ JavaOne 2011Java EE / GlassFish Strategy & Roadmap @ JavaOne 2011
Java EE / GlassFish Strategy & Roadmap @ JavaOne 2011Arun Gupta
 
PaaSing a Java EE 6 Application at Geecon 2012
PaaSing a Java EE 6 Application at Geecon 2012PaaSing a Java EE 6 Application at Geecon 2012
PaaSing a Java EE 6 Application at Geecon 2012Arun Gupta
 
JAX-RS 2.0: RESTful Web services on steroids at Geecon 2012
JAX-RS 2.0: RESTful Web services on steroids at Geecon 2012JAX-RS 2.0: RESTful Web services on steroids at Geecon 2012
JAX-RS 2.0: RESTful Web services on steroids at Geecon 2012Arun Gupta
 
Running your Java EE 6 applications in the Cloud
Running your Java EE 6 applications in the CloudRunning your Java EE 6 applications in the Cloud
Running your Java EE 6 applications in the CloudArun Gupta
 
Glassfish Overview Fontys 20090520
Glassfish Overview Fontys 20090520Glassfish Overview Fontys 20090520
Glassfish Overview Fontys 20090520Eugene Bogaart
 
The Java EE 7 Platform: Developing for the Cloud
The Java EE 7 Platform: Developing for the CloudThe Java EE 7 Platform: Developing for the Cloud
The Java EE 7 Platform: Developing for the Cloudcodemotion_es
 
GIDS 2012: PaaSing a Java EE Application
GIDS 2012: PaaSing a Java EE ApplicationGIDS 2012: PaaSing a Java EE Application
GIDS 2012: PaaSing a Java EE ApplicationArun Gupta
 
Java Summit Chennai: JAX-RS 2.0
Java Summit Chennai: JAX-RS 2.0Java Summit Chennai: JAX-RS 2.0
Java Summit Chennai: JAX-RS 2.0Arun Gupta
 
OSGi-enabled Java EE Applications using GlassFish at JCertif 2011
OSGi-enabled Java EE Applications using GlassFish at JCertif 2011OSGi-enabled Java EE Applications using GlassFish at JCertif 2011
OSGi-enabled Java EE Applications using GlassFish at JCertif 2011Arun Gupta
 
TDC 2011: The Java EE 7 Platform: Developing for the Cloud
TDC 2011: The Java EE 7 Platform: Developing for the CloudTDC 2011: The Java EE 7 Platform: Developing for the Cloud
TDC 2011: The Java EE 7 Platform: Developing for the CloudArun Gupta
 
GIDS 2012: Java Message Service 2.0
GIDS 2012: Java Message Service 2.0GIDS 2012: Java Message Service 2.0
GIDS 2012: Java Message Service 2.0Arun Gupta
 
The Java Ee 6 Platform Normandy Jug
The Java Ee 6 Platform Normandy JugThe Java Ee 6 Platform Normandy Jug
The Java Ee 6 Platform Normandy JugSaagie
 
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...Arun Gupta
 

Tendances (20)

GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012GlassFish REST Administration Backend at JavaOne India 2012
GlassFish REST Administration Backend at JavaOne India 2012
 
Java EE Technical Keynote at JavaOne Latin America 2011
Java EE Technical Keynote at JavaOne Latin America 2011Java EE Technical Keynote at JavaOne Latin America 2011
Java EE Technical Keynote at JavaOne Latin America 2011
 
Java EE 7: Developing for the Cloud at Geecon, JEEConf, Johannesburg
Java EE 7: Developing for the Cloud at Geecon, JEEConf, JohannesburgJava EE 7: Developing for the Cloud at Geecon, JEEConf, Johannesburg
Java EE 7: Developing for the Cloud at Geecon, JEEConf, Johannesburg
 
Java EE 7 at JAX London 2011 and JFall 2011
Java EE 7 at JAX London 2011 and JFall 2011Java EE 7 at JAX London 2011 and JFall 2011
Java EE 7 at JAX London 2011 and JFall 2011
 
GlassFish Community Update @ JavaOne 2011
GlassFish Community Update @ JavaOne 2011GlassFish Community Update @ JavaOne 2011
GlassFish Community Update @ JavaOne 2011
 
The State of Java under Oracle at JCertif 2011
The State of Java under Oracle at JCertif 2011The State of Java under Oracle at JCertif 2011
The State of Java under Oracle at JCertif 2011
 
Jfokus 2012 : The Java EE 7 Platform: Developing for the Cloud
Jfokus 2012 : The Java EE 7 Platform: Developing for the CloudJfokus 2012 : The Java EE 7 Platform: Developing for the Cloud
Jfokus 2012 : The Java EE 7 Platform: Developing for the Cloud
 
Java EE / GlassFish Strategy & Roadmap @ JavaOne 2011
Java EE / GlassFish Strategy & Roadmap @ JavaOne 2011Java EE / GlassFish Strategy & Roadmap @ JavaOne 2011
Java EE / GlassFish Strategy & Roadmap @ JavaOne 2011
 
PaaSing a Java EE 6 Application at Geecon 2012
PaaSing a Java EE 6 Application at Geecon 2012PaaSing a Java EE 6 Application at Geecon 2012
PaaSing a Java EE 6 Application at Geecon 2012
 
JAX-RS 2.0: RESTful Web services on steroids at Geecon 2012
JAX-RS 2.0: RESTful Web services on steroids at Geecon 2012JAX-RS 2.0: RESTful Web services on steroids at Geecon 2012
JAX-RS 2.0: RESTful Web services on steroids at Geecon 2012
 
Running your Java EE 6 applications in the Cloud
Running your Java EE 6 applications in the CloudRunning your Java EE 6 applications in the Cloud
Running your Java EE 6 applications in the Cloud
 
Glassfish Overview Fontys 20090520
Glassfish Overview Fontys 20090520Glassfish Overview Fontys 20090520
Glassfish Overview Fontys 20090520
 
The Java EE 7 Platform: Developing for the Cloud
The Java EE 7 Platform: Developing for the CloudThe Java EE 7 Platform: Developing for the Cloud
The Java EE 7 Platform: Developing for the Cloud
 
GIDS 2012: PaaSing a Java EE Application
GIDS 2012: PaaSing a Java EE ApplicationGIDS 2012: PaaSing a Java EE Application
GIDS 2012: PaaSing a Java EE Application
 
Java Summit Chennai: JAX-RS 2.0
Java Summit Chennai: JAX-RS 2.0Java Summit Chennai: JAX-RS 2.0
Java Summit Chennai: JAX-RS 2.0
 
OSGi-enabled Java EE Applications using GlassFish at JCertif 2011
OSGi-enabled Java EE Applications using GlassFish at JCertif 2011OSGi-enabled Java EE Applications using GlassFish at JCertif 2011
OSGi-enabled Java EE Applications using GlassFish at JCertif 2011
 
TDC 2011: The Java EE 7 Platform: Developing for the Cloud
TDC 2011: The Java EE 7 Platform: Developing for the CloudTDC 2011: The Java EE 7 Platform: Developing for the Cloud
TDC 2011: The Java EE 7 Platform: Developing for the Cloud
 
GIDS 2012: Java Message Service 2.0
GIDS 2012: Java Message Service 2.0GIDS 2012: Java Message Service 2.0
GIDS 2012: Java Message Service 2.0
 
The Java Ee 6 Platform Normandy Jug
The Java Ee 6 Platform Normandy JugThe Java Ee 6 Platform Normandy Jug
The Java Ee 6 Platform Normandy Jug
 
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
Java EE 6 & GlassFish 3: Light-weight, Extensible, and Powerful @ Silicon Val...
 

En vedette

Kisi kisi-un-sma-ma-sederajat-2017
Kisi kisi-un-sma-ma-sederajat-2017Kisi kisi-un-sma-ma-sederajat-2017
Kisi kisi-un-sma-ma-sederajat-2017Totok Isnantyo
 
Entrinsik's new Enrole
Entrinsik's new EnroleEntrinsik's new Enrole
Entrinsik's new EnroleEntrinsik
 
Διαδίκτυο
ΔιαδίκτυοΔιαδίκτυο
Διαδίκτυο2epal
 
Visual Art and Social Media:
Visual Art and Social Media:Visual Art and Social Media:
Visual Art and Social Media:John Barbera Jr.
 
Felicidades
FelicidadesFelicidades
FelicidadesYAYAFINA
 
Feliz2010paratodosmisamigos
Feliz2010paratodosmisamigosFeliz2010paratodosmisamigos
Feliz2010paratodosmisamigosLuis Ramos
 
Ultimate hair transplant guide
Ultimate hair transplant guideUltimate hair transplant guide
Ultimate hair transplant guideilhtdubai1
 
Need for Speed: MySQL Indexing
Need for Speed: MySQL IndexingNeed for Speed: MySQL Indexing
Need for Speed: MySQL IndexingMYXPLAIN
 
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
 
Advanced Query Optimizer Tuning and Analysis
Advanced Query Optimizer Tuning and AnalysisAdvanced Query Optimizer Tuning and Analysis
Advanced Query Optimizer Tuning and AnalysisMYXPLAIN
 

En vedette (12)

Kisi kisi-un-sma-ma-sederajat-2017
Kisi kisi-un-sma-ma-sederajat-2017Kisi kisi-un-sma-ma-sederajat-2017
Kisi kisi-un-sma-ma-sederajat-2017
 
Entrinsik's new Enrole
Entrinsik's new EnroleEntrinsik's new Enrole
Entrinsik's new Enrole
 
Διαδίκτυο
ΔιαδίκτυοΔιαδίκτυο
Διαδίκτυο
 
Visual Art and Social Media:
Visual Art and Social Media:Visual Art and Social Media:
Visual Art and Social Media:
 
Felicidades
FelicidadesFelicidades
Felicidades
 
Feliz2010paratodosmisamigos
Feliz2010paratodosmisamigosFeliz2010paratodosmisamigos
Feliz2010paratodosmisamigos
 
Ultimate hair transplant guide
Ultimate hair transplant guideUltimate hair transplant guide
Ultimate hair transplant guide
 
Need for Speed: MySQL Indexing
Need for Speed: MySQL IndexingNeed for Speed: MySQL Indexing
Need for Speed: MySQL Indexing
 
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
 
Advanced Query Optimizer Tuning and Analysis
Advanced Query Optimizer Tuning and AnalysisAdvanced Query Optimizer Tuning and Analysis
Advanced Query Optimizer Tuning and Analysis
 
Presentation Turkey
Presentation TurkeyPresentation Turkey
Presentation Turkey
 
Seminario joaquín careaga
Seminario joaquín careagaSeminario joaquín careaga
Seminario joaquín careaga
 

Similaire à Improving Performance with Better Indexes

MySQL Tech Tour 2015 - Alt Intro
MySQL Tech Tour 2015 - Alt IntroMySQL Tech Tour 2015 - Alt Intro
MySQL Tech Tour 2015 - Alt IntroMark Swarbrick
 
MySQL 5.6 Updates
MySQL 5.6 UpdatesMySQL 5.6 Updates
MySQL 5.6 UpdatesDave Stokes
 
The History and Future of the MySQL ecosystem
The History and Future of the MySQL ecosystemThe History and Future of the MySQL ecosystem
The History and Future of the MySQL ecosystemRonald Bradford
 
Successful Scalability Principles - Part 1
Successful Scalability Principles - Part 1Successful Scalability Principles - Part 1
Successful Scalability Principles - Part 1Ronald Bradford
 
MySQL London Tech Tour March 2015 - Whats New
MySQL London Tech Tour March 2015 - Whats NewMySQL London Tech Tour March 2015 - Whats New
MySQL London Tech Tour March 2015 - Whats NewMark Swarbrick
 
Efficient Performance Analysis and Tuning with MySQL Enterprise Monitor
Efficient Performance Analysis and Tuning with MySQL Enterprise MonitorEfficient Performance Analysis and Tuning with MySQL Enterprise Monitor
Efficient Performance Analysis and Tuning with MySQL Enterprise MonitorMark Matthews
 
Mysql User Camp : 20th June - Mysql New Features
Mysql User Camp : 20th June - Mysql New FeaturesMysql User Camp : 20th June - Mysql New Features
Mysql User Camp : 20th June - Mysql New FeaturesTarique Saleem
 
Mysql User Camp : 20-June-14 : Mysql New features and NoSQL Support
 Mysql User Camp : 20-June-14 : Mysql New features and NoSQL Support Mysql User Camp : 20-June-14 : Mysql New features and NoSQL Support
Mysql User Camp : 20-June-14 : Mysql New features and NoSQL SupportMysql User Camp
 
MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...
MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...
MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...GeneXus
 
My sqlstrategyroadmap
My sqlstrategyroadmapMy sqlstrategyroadmap
My sqlstrategyroadmapslidethanks
 
MySQL Strategy&Roadmap
MySQL Strategy&RoadmapMySQL Strategy&Roadmap
MySQL Strategy&Roadmapslidethanks
 
MySQL Manchester TT - MySQL Enterprise Edition
MySQL Manchester TT - MySQL Enterprise EditionMySQL Manchester TT - MySQL Enterprise Edition
MySQL Manchester TT - MySQL Enterprise EditionMark Swarbrick
 
My sql performance tuning course
My sql performance tuning courseMy sql performance tuning course
My sql performance tuning courseAlberto Centanni
 
20140722 Taiwan MySQL User Group Meeting Tech Updates
20140722 Taiwan MySQL User Group Meeting Tech Updates20140722 Taiwan MySQL User Group Meeting Tech Updates
20140722 Taiwan MySQL User Group Meeting Tech UpdatesRyusuke Kajiyama
 
ODTUG_NoPlsql_vs_SmartDB_Part1_and_2.pptx
ODTUG_NoPlsql_vs_SmartDB_Part1_and_2.pptxODTUG_NoPlsql_vs_SmartDB_Part1_and_2.pptx
ODTUG_NoPlsql_vs_SmartDB_Part1_and_2.pptxToon Koppelaars
 
Revolutionizing the Data Abstraction Layer with IBM Optim pureQuery and DB2
Revolutionizing the Data Abstraction Layer with IBM Optim pureQuery and DB2Revolutionizing the Data Abstraction Layer with IBM Optim pureQuery and DB2
Revolutionizing the Data Abstraction Layer with IBM Optim pureQuery and DB2Vladimir Bacvanski, PhD
 
Whatsnew in-my sql-primary
Whatsnew in-my sql-primaryWhatsnew in-my sql-primary
Whatsnew in-my sql-primaryKaizenlogcom
 
Introducing Performance Awareness in an Integrated Specification Environment
Introducing Performance Awareness in an Integrated Specification EnvironmentIntroducing Performance Awareness in an Integrated Specification Environment
Introducing Performance Awareness in an Integrated Specification EnvironmentFabian Keller
 
TWJUG August, What's new in MySQL 5.7 RC
TWJUG August, What's new in MySQL 5.7 RCTWJUG August, What's new in MySQL 5.7 RC
TWJUG August, What's new in MySQL 5.7 RCRyusuke Kajiyama
 

Similaire à Improving Performance with Better Indexes (20)

MySQL Tech Tour 2015 - Alt Intro
MySQL Tech Tour 2015 - Alt IntroMySQL Tech Tour 2015 - Alt Intro
MySQL Tech Tour 2015 - Alt Intro
 
MySQL 5.6 Updates
MySQL 5.6 UpdatesMySQL 5.6 Updates
MySQL 5.6 Updates
 
The History and Future of the MySQL ecosystem
The History and Future of the MySQL ecosystemThe History and Future of the MySQL ecosystem
The History and Future of the MySQL ecosystem
 
Successful Scalability Principles - Part 1
Successful Scalability Principles - Part 1Successful Scalability Principles - Part 1
Successful Scalability Principles - Part 1
 
MySQL London Tech Tour March 2015 - Whats New
MySQL London Tech Tour March 2015 - Whats NewMySQL London Tech Tour March 2015 - Whats New
MySQL London Tech Tour March 2015 - Whats New
 
MySQL Latest News
MySQL Latest NewsMySQL Latest News
MySQL Latest News
 
Efficient Performance Analysis and Tuning with MySQL Enterprise Monitor
Efficient Performance Analysis and Tuning with MySQL Enterprise MonitorEfficient Performance Analysis and Tuning with MySQL Enterprise Monitor
Efficient Performance Analysis and Tuning with MySQL Enterprise Monitor
 
Mysql User Camp : 20th June - Mysql New Features
Mysql User Camp : 20th June - Mysql New FeaturesMysql User Camp : 20th June - Mysql New Features
Mysql User Camp : 20th June - Mysql New Features
 
Mysql User Camp : 20-June-14 : Mysql New features and NoSQL Support
 Mysql User Camp : 20-June-14 : Mysql New features and NoSQL Support Mysql User Camp : 20-June-14 : Mysql New features and NoSQL Support
Mysql User Camp : 20-June-14 : Mysql New features and NoSQL Support
 
MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...
MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...
MySQL 20 años: pasado, presente y futuro; conoce las nuevas características d...
 
My sqlstrategyroadmap
My sqlstrategyroadmapMy sqlstrategyroadmap
My sqlstrategyroadmap
 
MySQL Strategy&Roadmap
MySQL Strategy&RoadmapMySQL Strategy&Roadmap
MySQL Strategy&Roadmap
 
MySQL Manchester TT - MySQL Enterprise Edition
MySQL Manchester TT - MySQL Enterprise EditionMySQL Manchester TT - MySQL Enterprise Edition
MySQL Manchester TT - MySQL Enterprise Edition
 
My sql performance tuning course
My sql performance tuning courseMy sql performance tuning course
My sql performance tuning course
 
20140722 Taiwan MySQL User Group Meeting Tech Updates
20140722 Taiwan MySQL User Group Meeting Tech Updates20140722 Taiwan MySQL User Group Meeting Tech Updates
20140722 Taiwan MySQL User Group Meeting Tech Updates
 
ODTUG_NoPlsql_vs_SmartDB_Part1_and_2.pptx
ODTUG_NoPlsql_vs_SmartDB_Part1_and_2.pptxODTUG_NoPlsql_vs_SmartDB_Part1_and_2.pptx
ODTUG_NoPlsql_vs_SmartDB_Part1_and_2.pptx
 
Revolutionizing the Data Abstraction Layer with IBM Optim pureQuery and DB2
Revolutionizing the Data Abstraction Layer with IBM Optim pureQuery and DB2Revolutionizing the Data Abstraction Layer with IBM Optim pureQuery and DB2
Revolutionizing the Data Abstraction Layer with IBM Optim pureQuery and DB2
 
Whatsnew in-my sql-primary
Whatsnew in-my sql-primaryWhatsnew in-my sql-primary
Whatsnew in-my sql-primary
 
Introducing Performance Awareness in an Integrated Specification Environment
Introducing Performance Awareness in an Integrated Specification EnvironmentIntroducing Performance Awareness in an Integrated Specification Environment
Introducing Performance Awareness in an Integrated Specification Environment
 
TWJUG August, What's new in MySQL 5.7 RC
TWJUG August, What's new in MySQL 5.7 RCTWJUG August, What's new in MySQL 5.7 RC
TWJUG August, What's new in MySQL 5.7 RC
 

Plus de MYXPLAIN

MySQL Index Cookbook
MySQL Index CookbookMySQL Index Cookbook
MySQL Index CookbookMYXPLAIN
 
Advanced MySQL Query and Schema Tuning
Advanced MySQL Query and Schema TuningAdvanced MySQL Query and Schema Tuning
Advanced MySQL Query and Schema TuningMYXPLAIN
 
Are You Getting the Best of your MySQL Indexes
Are You Getting the Best of your MySQL IndexesAre You Getting the Best of your MySQL Indexes
Are You Getting the Best of your MySQL IndexesMYXPLAIN
 
How to Design Indexes, Really
How to Design Indexes, ReallyHow to Design Indexes, Really
How to Design Indexes, ReallyMYXPLAIN
 
MySQL 5.6 Performance
MySQL 5.6 PerformanceMySQL 5.6 Performance
MySQL 5.6 PerformanceMYXPLAIN
 
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
 
56 Query Optimization
56 Query Optimization56 Query Optimization
56 Query OptimizationMYXPLAIN
 
Tools and Techniques for Index Design
Tools and Techniques for Index DesignTools and Techniques for Index Design
Tools and Techniques for Index DesignMYXPLAIN
 
Powerful Explain in MySQL 5.6
Powerful Explain in MySQL 5.6Powerful Explain in MySQL 5.6
Powerful Explain in MySQL 5.6MYXPLAIN
 
Optimizing Queries with Explain
Optimizing Queries with ExplainOptimizing Queries with Explain
Optimizing Queries with ExplainMYXPLAIN
 
The Power of MySQL Explain
The Power of MySQL ExplainThe Power of MySQL Explain
The Power of MySQL ExplainMYXPLAIN
 
Explaining the MySQL Explain
Explaining the MySQL ExplainExplaining the MySQL Explain
Explaining the MySQL ExplainMYXPLAIN
 
Covering indexes
Covering indexesCovering indexes
Covering indexesMYXPLAIN
 
MySQL Optimizer Overview
MySQL Optimizer OverviewMySQL Optimizer Overview
MySQL Optimizer OverviewMYXPLAIN
 
Advanced query optimization
Advanced query optimizationAdvanced query optimization
Advanced query optimizationMYXPLAIN
 

Plus de MYXPLAIN (15)

MySQL Index Cookbook
MySQL Index CookbookMySQL Index Cookbook
MySQL Index Cookbook
 
Advanced MySQL Query and Schema Tuning
Advanced MySQL Query and Schema TuningAdvanced MySQL Query and Schema Tuning
Advanced MySQL Query and Schema Tuning
 
Are You Getting the Best of your MySQL Indexes
Are You Getting the Best of your MySQL IndexesAre You Getting the Best of your MySQL Indexes
Are You Getting the Best of your MySQL Indexes
 
How to Design Indexes, Really
How to Design Indexes, ReallyHow to Design Indexes, Really
How to Design Indexes, Really
 
MySQL 5.6 Performance
MySQL 5.6 PerformanceMySQL 5.6 Performance
MySQL 5.6 Performance
 
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
 
56 Query Optimization
56 Query Optimization56 Query Optimization
56 Query Optimization
 
Tools and Techniques for Index Design
Tools and Techniques for Index DesignTools and Techniques for Index Design
Tools and Techniques for Index Design
 
Powerful Explain in MySQL 5.6
Powerful Explain in MySQL 5.6Powerful Explain in MySQL 5.6
Powerful Explain in MySQL 5.6
 
Optimizing Queries with Explain
Optimizing Queries with ExplainOptimizing Queries with Explain
Optimizing Queries with Explain
 
The Power of MySQL Explain
The Power of MySQL ExplainThe Power of MySQL Explain
The Power of MySQL Explain
 
Explaining the MySQL Explain
Explaining the MySQL ExplainExplaining the MySQL Explain
Explaining the MySQL Explain
 
Covering indexes
Covering indexesCovering indexes
Covering indexes
 
MySQL Optimizer Overview
MySQL Optimizer OverviewMySQL Optimizer Overview
MySQL Optimizer Overview
 
Advanced query optimization
Advanced query optimizationAdvanced query optimization
Advanced query optimization
 

Dernier

A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 

Dernier (20)

A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 

Improving Performance with Better Indexes

  • 1. Improving Performance with Better Indexes Ronald Bradford http://ronaldbradford.com The only active MySQL group in New York http://www.meetup.com/EffectiveMySQL/ 2011.05 EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability OBJECTIVE ABOUT Ronald BRADFORD Improve query performance, 12 years with MySQL / 22 years with RDBMS therefore Senior Consultant at MySQL Inc (06-08) Increase server throughput, 7 years presenting MySQL content therefore All time top MySQL blogger Available NOW for consulting Reduce H/W to run your Published author application Top industry recognitions and awards http://NYMySQLExpert.com http://RonaldBradford.com EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability
  • 2. SOLUTIon SQL REVIEW Six step process 1. Capture 2. Identify Extra: Using Index 3. Confirm 4. Analyze 5. Optimize 6. Verify EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability Capture Capture Example 1 1 Not discussed in detail this presentation General Query Log Application Logging TCP/IP TCP/IP Connectors Application Proxy Plugin ... EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability
  • 3. Example Example 1 1 // Global replace mysql_query with db_query function db_query($sql) { $start_time = microtime(true); $rs = mysql_query($sql); function db_query($sql) { $exec_time = microtime(true) - $start_time; $rs = mysql_query($sql); debug(format_time($exec_time) . ' ' . $sql . "n"); return $rs; return $rs; } } function debug($str) { if (DEBUG) echo $str; return 0; } function format_time($time) { return number_format($time, 8, '.', ''); } EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability Example Example 1 1 0.00010109 SELECT ip FROM ... $ sudo tcpdump -i any port 3306 -s 65535 -x -nn -q -tttt 0.00005198 SELECT name, value FROM ... -c 10000 | mk-query-digest --type tcpdump 0.00005984 SELECT id, status, ... 0.17592907 SELECT g.id, c.id, ... 24 statements on page # Profile 0.00047803 SELECT DISTINCT id_c FROM camp... Easy to spot worst query # Rank Query ID Response time Calls R/Call Apdx V/M Item 0.00741315 SELECT DISTINCT id_c FROM camp.. # ==== ================== ============= ===== ====== ==== ===== ====== # 1 0xE5C8D4B9F7BDCCAF 0.5044 18.7% 1 0.5044 1.00 0.00 SELECT .. 0.00058198 SELECT id_c FROM cr ... # 2 0x813031B8BBC3B329 0.4893 18.2% 23 0.0213 1.00 0.01 COMMIT 0.00161815 SELECT id_c FROM cr ... # 3 0x04AB3BC1A33D3B48 0.4107 15.2% 1 0.4107 1.00 0.00 SELECT .. 0.00032806 SELECT id_c FROM cr ... # 4 0xD15CA257BAF77DAF 0.3356 12.5% 321 0.0010 1.00 0.00 SELECT .. 0.00007200 SELECT DISTINCT id_a FROM arb ... # 5 0x228B1F36C5EBCF1F 0.2177 8.1% 2 0.1089 1.00 0.22 SELECT .. 0.00005412 SELECT DISTINCT id_a FROM asw ... 0.00004697 SELECT id_adv FROM arw 0.00004601 SELECT id_adv FROM arw 0.00009012 SELECT gk.id, k.value ... 0.00009084 SELECT gk.id, k.value ... 0.00006318 SELECT gk.id, k.value ... 0.00005794 SELECT gk.id, k.value ... 0.00005603 SELECT gk.id, k.value ... http://effectiveMySQL.com/article/mk-query-digest EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability
  • 4. IDENTIFY Example 2 2 Not discussed Frequency in detail this presentation //TODO By Duration of time # Profile # Rank Query ID Response time Calls R/Call Apdx V/M Item # ==== ================== ============= ===== ====== ==== ===== ====== By Frequency of execution # # 1 0xE5C8D4B9F7BDCCAF 0.5044 18.7% 2 0x813031B8BBC3B329 0.4893 18.2% 1 0.5044 1.00 0.00 23 0.0213 1.00 0.01 SELECT COMMIT .. # 3 0x04AB3BC1A33D3B48 0.4107 15.2% 1 0.4107 1.00 0.00 SELECT .. # 4 0xD15CA257BAF77DAF 0.3356 12.5% 321 0.0010 1.00 0.00 SELECT .. # 5 0x228B1F36C5EBCF1F 0.2177 8.1% 2 0.1089 1.00 0.22 SELECT .. Duration EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability CONFIRM CONFIRM 3 3 Not discussed Not discussed in detail this presentation in detail this presentation Via Watch & Isolate Application Logging Locking mysql client Load SHOW PROFILES Caching EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability
  • 5. Example Example 3 3 mysql client mysql client 10 millisecond precision microsecond precision mysql> SELECT ... mysql> SELECT ... 1 row in set (0.00 sec) 1 row in set (0.00 sec) # What you really want is? mysql> SELECT ... 1 row in set (0.008110 sec) http://j.mp/gM3Hb3 EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability ANALYZE Example 3 4 mysql> SET PROFILING=1; Quick verification microsecond precision EXPLAIN mysql> SELECT SLEEP(1); mysql> SELECT SLEEP(2); SHOW CREATE TABLE mysql> SHOW PROFILES; SHOW INDEXES FROM +----------+------------+-----------------+ | Query_ID | Duration | Query | INFORMATION_SCHEMA.TABLES +----------+------------+-----------------+ | | 1 | 1.00135300 | SELECT SLEEP(1) | 2 | 2.00215600 | SELECT SLEEP(2) | SHOW TABLE STATUS LIKE +----------+------------+-----------------+ EXPLAIN EXTENDED EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability
  • 6. Example Example 4 4 mysql> EXPLAIN SELECT p.amt, p.reference mysql> SHOW CREATE TABLE wp_users G FROM payment p JOIN invoice i ON i.inv_id = p.inv_id CREATE TABLE `wp_users` ( WHERE i.due_date = '2009-10-14' `ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT, AND i.user_id = 1 `user_login` varchar(60) NOT NULL DEFAULT '', AND i.account_id = 10 `user_pass` varchar(64) NOT NULL DEFAULT '', `user_nicename` varchar(50) NOT NULL DEFAULT '', AND p.amt > 0 `user_email` varchar(100) NOT NULL DEFAULT '', `user_url` varchar(100) NOT NULL DEFAULT '', +----+-------------+-------+------+---------------+------+---------+------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | rows | Extra | `user_registered` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', +----+-------------+-------+------+---------------+------+---------+------+-------------+ `user_activation_key` varchar(60) NOT NULL DEFAULT '', | 1 | SIMPLE | i | ref | PRIMARY,u,a,d | u | 4 | 1 | Using where | `user_status` int(11) NOT NULL DEFAULT '0', | 1 | SIMPLE | p | ref | i | i | 4 | 6 | Using where | `display_name` varchar(250) NOT NULL DEFAULT '', +----+-------------+-------+------+---------------+------+---------+------+-------------+ PRIMARY KEY (`ID`), KEY `user_login_key` (`user_login`), KEY `user_nicename` (`user_nicename`) Format modified for ) ENGINE=MyISAM DEFAULT CHARSET=utf8 display purposes EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability Example Example 4 4 mysql> SHOW INDEXES FROM wp_posts; mysql> SHOW INDEXES FROM ...; ...+------------+------------------+--------------+-------------+... +------------+--------------+--------------+-----------------+-----------+-------------+ ...| Non_unique | Key_name | Seq_in_index | Cardinality |... | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | +------------+--------------+--------------+-----------------+-----------+-------------+ ...+------------+------------------+--------------+-------------+... | 0 | PRIMARY | 1 | id | A | 100085 | ...| 0 | PRIMARY | 1 | 2606 |... | 1 | is_available | 1 | is_available | A | 4 | ...| 1 | post_name | 1 | 2606 |... | 1 | is_active | 1 | is_active | A | 4 | | 1 | market | 1 | is_active | A | 36 | ...| 1 | type_status_date | 1 | 4 |... | 1 | market | 2 | is_available | A | 36 | ...| 1 | type_status_date | 2 | 6 |... | 1 | market | 3 | is_proposed | A | 238 | ...| 1 | type_status_date | 3 | 2606 |... +------------+--------------+--------------+-----------------+-----------+-------------+ ...| 1 | type_status_date | 4 | 2606 |... ...| 1 | post_parent | 1 | 217 |... ...| 1 | post_author | 1 | 1 |... ...+------------+------------------+--------------+-------------+... EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability
  • 7. Example Example 4 4 mysql> SELECT table_schema,table_name,engine, mysql> SHOW TABLE STATUS LIKE 'wp_posts'G row_format,table_rows, avg_row_length, Name: wp_posts (data_length+index_length)/1024/1024 as total_mb, Engine: MyISAM (data_length)/1024/1024 as data_mb, Version: 10 (index_length)/1024/1024 as index_mb Row_format: Dynamic FROM INFORMATION_SCHEMA.TABLES Rows: 2649 WHERE table_schema=DATABASE() AND table_name = 'example'G Avg_row_length: 2850 Data_length: 7550800 table_schema: example Max_data_length: 281474976710655 table_name: example Index_length: 259072 engine: MyISAM Data_free: 0 row_format: Dynamic Auto_increment: 3586 table_rows: 260006 Create_time: 2011-02-02 12:04:21 avg_row_length: 2798 total_mb: 700.20174026 Update_time: 2011-03-19 11:42:12 data_mb: 600.95564651 Check_time: 2011-02-02 12:04:21 index_mb: 99.24609375 Collation: utf8_general_ci EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability Example Example 4 4 mysql> EXPLAIN SELECT x.uuid, ..., y.uniqueid mysql> EXPLAIN EXTENDED SELECT x.uuid, ..., y.uniqueid FROM table1 x, table2 y FROM table1 x, table2 y WHERE x.uuid=y.uniqueid; WHERE x.uuid = y.uniqueid; mysql> SHOW WARNINGS; +----+---------+-------+--------+-----------+---------+---------+------+----------+--------------------------+ | id | select_ | table | type | possible_ | key | key_len | ref | rows | Extra | Level: Note +----+---------+-------+--------+-----------+---------+---------+------+----------+--------------------------+ | 1 | SIMPLE | x | ALL | NULL | NULL | NULL | NULL | 29960165 | | Code: 10031 | 1 | SIMPLE | y | eq_ref | PRIMARY | PRIMARY | 194 | func | 1 | Using where; Using index | +----+---------+-------+--------+-----------+---------+---------+------+----------+--------------------------+ Message: select `schema`.`x`.`uuid` AS `uuid`, ... `schema`.`y`.`uniqueid` AS `uniqueid` from `schema`.`table1` `x` join `schema`.`table2` `y` where (convert(`schema`.`x`.`uuid` using utf8) = `test`.`y`.`uniqueid` EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability
  • 8. OPTIMIZE THEORY Example 5 5 Not discussed in this presentation CREATE TABLE posts ( Adding Indexes id INT UNSIGNED NOT NULL AUTO_INCREMENT, author INT UNSIGNED NOT NULL, status VARCHAR(20) NOT NULL DEFAULT 'publish', Query simplification name VARCHAR(100) NOT NULL, content TEXT NOT NULL, comment_count INT UNSIGNED NOT NULL, Eliminate queries PRIMARY KEY (id), KEY name (name) MySQL configuration ) ENGINE=MyISAM DEFAULT CHARSET=utf8; Schema design ... EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability Example Example 5 5 mysql> ALTER TABLE posts ADD INDEX (author); mysql> EXPLAIN mysql> EXPLAIN SELECT COUNT(*) FROM posts SELECT COUNT(*) FROM posts WHERE author=2 AND status='draft' G WHERE author=2 AND status='draft' G id: 1 id: 1 select_type: SIMPLE select_type: SIMPLE Adding an index table: posts table: posts type: ALL type: ref possible_keys: NULL possible_keys: author key: NULL key: author key_len: NULL key_len: 4 ref: NULL ref: const rows: 2649 rows: 373 Extra: Using where Extra: Using where EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability
  • 9. COVERING INDEX Example 5 5 mysql> ALTER TABLE posts ADD INDEX (author,status); mysql> EXPLAIN Extra: Using Index SELECT COUNT(*) FROM posts WHERE author=2 AND status='draft' G Does not mean using index id: 1 select_type: table: SIMPLE posts Adding a better index Means using ONLY the index type: ref possible_keys: author All query columns are satisfied by index key: author key_len: 66 ref: const,const rows: 31 Extra: Using where; Using index EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability COVERING INDEX Example 5 5 mysql> ALTER TABLE posts ENGINE=MyISAM; Storage Engines matter mysql> EXPLAIN SELECT id FROM posts MyISAM Indexes WHERE author=2 AND status='draft' G id: 1 InnoDB Indexes select_type: table: SIMPLE posts type: ref possible_keys: author key: author key_len: 66 ref: const,const rows: 31 Extra: Using where EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability
  • 10. Parent/Child Example Example 5 5 mysql> ALTER TABLE posts ENGINE=InnoDB; CREATE TABLE invoice ( mysql> EXPLAIN inv_id INT UNSIGNED NOT NULL, Master/Child user_id INT UNSIGNED NOT NULL, SELECT id FROM posts account_id INT UNSIGNED NOT NULL, Relationship WHERE author=2 AND status='draft' G invoice_date DATE NOT NULL, due_date DATE NOT NULL, id: 1 PRIMARY KEY pk (inv_id), select_type: SIMPLE INDEX u (user_id), table: posts INDEX a (account_id), INDEX d (due_date) type: ref ) ENGINE=InnoDB; possible_keys: author CREATE TABLE payment ( key: author pay_id INT UNSIGNED NOT NULL AUTO_INCREMENT, key_len: 66 inv_id INT UNSIGNED NOT NULL, ref: const,const amt DECIMAL (10,2) NOT NULL, rows: 34 reference VARCHAR(20) NOT NULL, PRIMARY KEY pk (pay_id), Extra: Using where; Using index INDEX i (inv_id) ) ENGINE=InnoDB; EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability Example Example 5 5 EXPLAIN EXPLAIN SELECT p.amt, p.reference SELECT p.amt, p.reference FROM payment p FROM payment p JOIN invoice i ON i.inv_id = p.inv_id JOIN invoice i ON i.inv_id = p.inv_id WHERE i.due_date = '2009-10-14' WHERE i.due_date = '2009-10-14' AND i.user_id = 1 AND i.user_id = 1 AND AND i.account_id = 10 p.amt > 0 Important Start AND AND i.account_id = 10 p.amt > 0 Important Start +----+-------------+-------+------+---------------+------+---------+------+-------------+ +----+-------------+-------+------+---------------+------+---------+------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | rows | Extra | | id | select_type | table | type | possible_keys | key | key_len | rows | Extra | +----+-------------+-------+------+---------------+------+---------+------+-------------+ +----+-------------+-------+------+---------------+------+---------+------+-------------+ | 1 | SIMPLE | i | ref | PRIMARY,u,a,d | u | 4 | 1 | Using where | | 1 | SIMPLE | i | ref | PRIMARY,u,a,d | u | 4 | 1 | Using where | | 1 | SIMPLE | p | ref | i | i | 4 | 6 | Using where | | 1 | SIMPLE | p | ref | i | i | 4 | 6 | Using where | +----+-------------+-------+------+---------------+------+---------+------+-------------+ +----+-------------+-------+------+---------------+------+---------+------+-------------+ SHOW CREATE TABLE payment G ... PRIMARY KEY pk (pay_id), INDEX i (inv_id) ) ENGINE=InnoDB; EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability
  • 11. Example Example 5 5 Before SELECT p.amt, p.reference FROM payment p +----+-------------+-------+------+---------------+------+---------+------+-------------+ JOIN invoice i ON i.inv_id = p.inv_id | id | select_type | table | type | possible_keys | key | key_len | rows | Extra | +----+-------------+-------+------+---------------+------+---------+------+-------------+ WHERE i.due_date = '2009-10-14' AND AND i.user_id = 1 i.account_id = 10 Identify additional | 1 | SIMPLE | 1 | SIMPLE | i | p | ref | PRIMARY,u,a,d | u | ref | i | i | 4 | 4 | | 1 | Using where | 6 | Using where | +----+-------------+-------+------+---------------+------+---------+------+-------------+ AND p.amt > 0 column After ALTER TABLE payment +----+-------------+-------+------+---------------+------+---------+------+-------------+ DROP INDEX i, ADD INDEX i (inv_id, amt); | id | select_type | table | type | possible_keys | key | key_len | rows | Extra | +----+-------------+-------+------+---------------+------+---------+------+-------------+ | 1 | SIMPLE | i | ref | PRIMARY,u,a,d | u | 4 | 1 | Using where | | 1 | SIMPLE | p | ref | i | i | 4 | 6 | Using where | +----+-------------+-------+------+---------------+------+---------+------+-------------+ Zero Improvement EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability Example Example 5 5 SELECT p.amt, p.reference Before FROM payment p JOIN invoice i ON i.inv_id = p.inv_id +----+-------------+-------+------+---------------+------+---------+------+-------------+ WHERE i.due_date = '2009-10-14' | id | select_type | table | type | possible_keys | key | key_len | rows | Extra | +----+-------------+-------+------+---------------+------+---------+------+-------------+ AND AND i.user_id = 1 i.account_id = 10 Identify additional | 1 | SIMPLE | 1 | SIMPLE | i | p | ref | PRIMARY,u,a,d | u | ref | i | i | 4 | 4 | | 1 | Using where | 6 | Using where | +----+-------------+-------+------+---------------+------+---------+------+-------------+ AND p.amt > 0 column After ALTER TABLE payment DROP INDEX i, ADD INDEX i (inv_id, amt, reference); +----+-------------+-------+------+---------------+------+---------+------+--------------------------+ | id | select_type | table | type | possible_keys | key | key_len | rows | Extra | +----+-------------+-------+------+---------------+------+---------+------+--------------------------+ | 1 | SIMPLE | i | ref | PRIMARY,u,a,d | u | 4 | 1 | Using where | | 1 | SIMPLE | p | ref | i | i | 4 | 6 | Using where; Using index | +----+-------------+-------+------+---------------+------+---------+------+--------------------------+ Covering Index EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability
  • 12. Example Example 5 5 SELECT p.amt, p.reference SELECT p.amt, p.reference FROM payment p FROM payment p JOIN invoice i ON i.inv_id = p.inv_id JOIN invoice i ON i.inv_id = p.inv_id WHERE i.due_date = '2009-10-14' WHERE i.due_date = '2009-10-14' AND AND i.user_id = 1 i.account_id = 10 AND AND i.user_id = 1 i.account_id = 10 Identify additional AND p.amt > 0 +----+-------------+-------+------+---------------+------+---------+------+-------------+ AND p.amt > 0 column | id | select_type | table | type | possible_keys | key | key_len | rows | Extra | ALTER TABLE invoice +----+-------------+-------+------+---------------+------+---------+------+-------------+ | 1 | SIMPLE | i | ref | PRIMARY,u,a,d | u | 4 | 1 | Using where | DROP INDEX u, ADD INDEX u (user_id, account_id); | 1 | SIMPLE | p | ref | i | i | 4 | 6 | Using where | +----+-------------+-------+------+---------------+------+---------+------+-------------+ CREATE TABLE invoice ( ... Is account_id index PRIMARY KEY pk (inv_id), needed now? INDEX u (user_id), INDEX a (account_id), INDEX d (due_date) ) ENGINE=InnoDB; EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability Example Example 5 5 Before SELECT p.amt, p.reference FROM payment p +----+-------------+-------+------+---------------+------+---------+------+--------------------------+ JOIN invoice i ON i.inv_id = p.inv_id | id | select_type | table | type | possible_keys | key | key_len | rows | Extra | WHERE i.due_date = '2009-10-14' +----+-------------+-------+------+---------------+------+---------+------+--------------------------+ | 1 | SIMPLE | 1 | SIMPLE | i | p | ref | PRIMARY,u,a,d | u | ref | i | i | 4 | 4 | | 1 | Using where | 6 | Using where; Using index | +----+-------------+-------+------+---------------+------+---------+------+--------------------------+ AND AND i.user_id = 1 i.account_id = 10 Identify additional After AND p.amt > 0 column +----+-------------+-------+------+---------------+------+---------+------+--------------------------+ ALTER TABLE invoice | id | select_type | table | type | possible_keys | key | key_len | rows | Extra | DROP INDEX u, ADD INDEX u (user_id, account_id, due_date); +----+-------------+-------+------+---------------+------+---------+------+--------------------------+ | 1 | SIMPLE | i | ref | u | u | 8 | 1 | Using where | | 1 | SIMPLE | p | ref | i | i | 4 | 6 | Using where; Using index | +----+-------------+-------+------+---------------+------+---------+------+--------------------------+ Better Index Usage EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability
  • 13. VERIFY Example 5 6 Before Quantifiable +----+-------------+-------+------+---------------+------+---------+------+--------------------------+ | id | select_type | table | type | possible_keys | key | key_len | rows | Extra | +----+-------------+-------+------+---------------+------+---------+------+--------------------------+ | 1 | SIMPLE | 1 | SIMPLE | i | p | ref | u | ref | i | u | i | 8 | 4 | | 1 | Using where | 6 | Using where; Using index | Reproducable +----+-------------+-------+------+---------------+------+---------+------+--------------------------+ After +----+-------------+-------+------+---------------+------+---------+------+--------------------------+ | id | select_type | table | type | possible_keys | key | key_len | rows | Extra | +----+-------------+-------+------+---------------+------+---------+------+--------------------------+ | 1 | SIMPLE | i | ref | u | u | 11 | 1 | Using index | | 1 | SIMPLE | p | ref | i | i | 4 | 6 | Using where; Using index | +----+-------------+-------+------+---------------+------+---------+------+--------------------------+ Covering Index Better Index Usage EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability REAL WORLD REAL WORLD Example Example 6 6 +----+---------+----+--------+------+------+-------------+ +----+---------+----+--------+------+------+--------------------------+ | id | select_t| tab| key | key_ | rows | Extra | | id | select_t| tab| key | key_ | rows | Extra | +----+---------+----+--------+------+------+-------------+ +----+---------+----+--------+------+------+--------------------------+ | 1 | PRIMARY | c | statu | 1 | 74 | Using where | | 1 | PRIMARY | e | statu | 1 | 33 | Using where; Using index | | 1 | PRIMARY | e | PRIMA | 4 | 1 | Using where | | 1 | PRIMARY | c | adver | 4 | 7 | Using where | | 1 | PRIMARY | g | campa | 4 | 1 | Using where | | 1 | PRIMARY | g | campa | 4 | 1 | Using where | | 10 | DEPENDEN| crb| id_ca | 4 | 253 | Using where | BEFORE | 10 | DEPENDEN| crb| id_ca | 66 | 1 | Using where AFTER | | 9 | DEPENDEN| csb| pub_s | 98 | 1 | Using where | | 9 | DEPENDEN| csb| pub_s | 98 | 1 | Using where | | 8 | DEPENDEN| arb| id_ad | 4 | 901 | Using where | | 8 | DEPENDEN| arb| id_ad | 26 | 1 | Using where | | 7 | DEPENDEN| asb| pub_s | 34 | 1 | Using where | | 7 | DEPENDEN| asb| id_ad | 40 | 1 | Using where; Using index | | 6 | DEPENDEN| pm | id_adr | 4 | 42 | Using where | | 6 | DEPENDEN| pm | id_adr | 12 | 1 | Using index | | 5 | DEPENDEN| tgv| searc | 4 | 2 | Using where | | 5 | DEPENDEN| tgv| searc | 10 | 1 | Using where; Using index | | 4 | DEPENDEN| st | id_sc | 4 | 7 | Using where | | 4 | DEPENDEN| st | id_sc | 4 | 7 | Using where; Using index | | 4 | DEPENDEN| t | PRIMA | 4 | 1 | Using where | | 4 | DEPENDEN| t | PRIMA | 4 | 1 | Using where | | 3 | DEPENDEN| k2 | keywo | 302 | 4 | Using where | | 3 | DEPENDEN| k2 | keywo | 302 | 3 | Using where; Using index | | 3 | DEPENDEN| gk2| PRIMA | 100 | 1 | Using where | | 3 | DEPENDEN| gk2| PRIMA | 100 | 1 | Using where | | 2 | DEPENDEN| k1 | keywo | 302 | 3 | Using where | | 2 | DEPENDEN| k1 | keywo | 302 | 2 | Using where; Using index | | 2 | DEPENDEN| gk1| PRIMA | 100 | 1 | Using where | | 2 | DEPENDEN| gk1| PRIMA | 100 | 1 | Using where | +----+---------+----+--------+------+------+-------------+ +----+---------+----+--------+------+------+--------------------------+ 175ms 10ms EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability
  • 14. REAL WORLD Example 6 6 +----+---------+----+--------+------+------+-------------+ +----+---------+----+--------+------+--------------------------+ | id | select_t| tab| key | key_ || id | select_t| tab| | rows | Extra key | key_ | Extra | Sometimes a +----+---------+----+--------+------+------+-------------+ +----+---------+----+--------+------+--------------------------+ | 1 | PRIMARY | c | statu | 1 || 1 74 PRIMARY |where | | | Using c | adver | 4 | Using where | | 1 | PRIMARY | e | PRIMA | 4 || 1 |1 PRIMARY |where | | Using e | statu | 1 | Using where; Using index | | 1 | PRIMARY | g | campa | 4 || 1 |1 PRIMARY |where | | Using g | campa | 4 | Using where | | 10 | DEPENDEN| crb| id_ca | 4 || 10253 DEPENDEN|where | | | Using crb| id_ca | 66 | Using where | Covering Index | 9 | DEPENDEN| csb| pub_s | 98 || 9 |1 DEPENDEN|where | | Using csb| pub_s | 98 | Using where | | 8 | DEPENDEN| arb| id_ad | 4 || 8901 DEPENDEN|where | | | Using arb| id_ad | 26 | Using where | | 7 | DEPENDEN| asb| pub_s | 34 || 7 |1 DEPENDEN|where | | Using asb| id_ad | 40 | Using where; Using index | | 6 | DEPENDEN| pm | id_adr | 4 || 6 42 DEPENDEN|where | | | Using pm | id_adr | 12 | Using index | | 5 | DEPENDEN| tgv| searc | 4 || 5 |2 DEPENDEN|where | | Using tgv| searc | 10 | Using where; Using index | is ineffective | 4 | DEPENDEN| st | id_sc | 4 || 4 |7 DEPENDEN|where | | Using st | id_sc | 4 | Using where; Using index | | 4 | DEPENDEN| t | PRIMA | 4 || 4 |1 DEPENDEN|where | | Using t | PRIMA | 4 | Using where | | 3 | DEPENDEN| k2 | keywo | 302 || 3 |4 DEPENDEN|where | | Using k2 | keywo | 302 | Using where; Using index | | 3 | DEPENDEN| gk2| PRIMA | 100 || 3 |1 DEPENDEN|where | | Using gk2| PRIMA | 100 | Using where | | 2 | DEPENDEN| k1 | keywo | 302 || 2 |3 DEPENDEN|where | | Using k1 | keywo | 302 | Using where; Using index | | 2 | DEPENDEN| gk1| PRIMA | 100 || 2 |1 DEPENDEN|where | | Using gk1| PRIMA | 100 | Using where | +----+---------+----+--------+------+------+-------------+ +----+---------+----+--------+------+--------------------------+ 10ms EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability Example 6 6 +----+---------+----+--------+------+------+-------------+ | id | select_t| tab| key | key_ | rows | Extra | +----+---------+----+--------+------+------+-------------+ ... | 10 | DEPENDEN| crb| id_ca | 4 | 253 | Using where | .... Partial Column +----+---------+----+--------+------+------+--------------------------+ Index | id | select_t| tab| key | key_ | rows | Extra | +----+---------+----+--------+------+------+--------------------------+ ... | 10 | DEPENDEN| crb| id_ca | 66 | 1 | Using where | ... EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability
  • 15. Re-OPTIMIZE Example 6 5 ... NOT EXISTS ( Change data types SELECT 1 FROM crb WHERE crb.id = p.id AND crb.value = 'xyz') Simplify query Optimizing SQL is an ... iterative process Removed normalization CREATE TABLE crb( id INT UNSIGNED NOT NULL, Other secrets ... value VARCHAR(100) NOT NULL, .... INDEX (id, value(20)) ); EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability VERIFY VERIFY 6 6 VERY, VERY IMPORTANT Cardinal Sin Repeat as Indexes affect all queries on table necessary 175ms to 10ms to 3ms Happy client is now more happy EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability
  • 16. CONCLUSION C ? 6 steps to successful SQL review Tell me your Optimization is an iterative process Rows, storage engines, configuration & success stories! MySQL version affect results over time ronald@EffectiveMySQL.com Indexes are not the only optimization Saved 50% daily hosting = $500 p.d = $180,000 p.y. Indexes are not the best optimization http://effectiveMySQL.com/presentations EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability EffectiveMySQL.com - Its all about Performance and Scalability