SlideShare una empresa de Scribd logo
1 de 43
Learn How MySQL 5.6 Makes
  Query Optimization Easier
                       Jaime Crespo
          Percona Technical Webinars
                     March 15, 2013
About This Presentation
    • 5.6 from a pure technical view
      •   Only query tuning, not other optimization or profiling
          features
      •   Practical, simple examples but with real data (not
          “best cases”)
    • NOT benchmarks
      •   Only response time/query strategy, not extra
          CPU/memory/locking
      •   No comparisons with Percona Server or MariaDB
    • 5.6 optimizer has a lot of room for improvement,
      specially for query plan decision
      •   Some features are poorly documented
2                                                  www.percona.com
Agenda
    • MySQL 5.6 Optimizer New Features
      •   Filesort with short LIMIT
      •   ICP
      •   MRR
      •   BKA
      •   Index merge
      •   Other Subquery and JOIN Optimizations
    • MySQL 5.6 Query Plan Information
      •   EXPLAIN for DML
      •   Structured EXPLAIN and Query Plan Profiler
      •   Persistent Optimizer Statistics
      •   Duplicate Key Check
3                                              www.percona.com
Test Platform for Queries
    • We will compare official Oracle’s MySQL 5.5.30 vs
      5.6.10 binary tarballs
    • Base platform:
      •    CentOS 6.3
      •    4 Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz
      •    32 GB RAM
      •    Software RAID1 of SATA 6 GB/s HDD 7200 rpm
    • Standard options (not default) except otherwise noted
      •    E.g. bigger transaction log and buffer pool, disabled P_S
    • Queries are executed several times between reboots
    • We will be using FORCE INDEX quite liberally
      •    Not a good general practice

4                                                     www.percona.com
Original Test Schema
    CREATE TABLE `cast_info` (                 CREATE TABLE `movie_info` (
      `id` int(11) NOT NULL AUTO_INCREMENT,      `id` int(11) NOT NULL AUTO_INCREMENT,
      `person_id` int(11) NOT NULL,              `movie_id` int(11) NOT NULL,
      `movie_id` int(11) NOT NULL,               `info_type_id` int(11) NOT NULL,
      `person_role_id` int(11) DEFAULT NULL,     `info` text NOT NULL,
      `note` text DEFAULT NULL,                  `note` text,
      `nr_order` int(11) DEFAULT NULL,           PRIMARY KEY (`id`),
      `role_id` int(11) NOT NULL,              ) ENGINE=InnoDB AUTO_INCREMENT=9748371 DEFAULT
      PRIMARY KEY (`id`),                      CHARSET=utf8;
    ) ENGINE=InnoDB AUTO_INCREMENT=22187769
    DEFAULT CHARSET=utf8;                      CREATE TABLE `title` (
                                                 `id` int(11) NOT NULL AUTO_INCREMENT,
    CREATE TABLE `char_name` (                   `title` text NOT NULL,
      `id` int(11) NOT NULL AUTO_INCREMENT,      `imdb_index` varchar(12) DEFAULT NULL,
      `name` text NOT NULL,                      `kind_id` int(11) NOT NULL,
      `imdb_index` varchar(12) DEFAULT NULL,     `production_year` int(11) DEFAULT NULL,
      `imdb_id` int(11) DEFAULT NULL,            `imdb_id` int(11) DEFAULT NULL,
      `name_pcode_nf` varchar(5) DEFAULT NULL,   `phonetic_code` varchar(5) DEFAULT NULL,
      `surname_pcode` varchar(5) DEFAULT NULL,   `episode_of_id` int(11) DEFAULT NULL,
      PRIMARY KEY (`id`),                        `season_nr` int(11) DEFAULT NULL,
    ) ENGINE=InnoDB AUTO_INCREMENT=2406562       `episode_nr` int(11) DEFAULT NULL,
    DEFAULT CHARSET=utf8;                        `series_years` varchar(49) DEFAULT NULL,
                                                 `title_crc32` int(10) unsigned DEFAULT NULL,
                                                 PRIMARY KEY (`id`),
                                               ) ENGINE=InnoDB AUTO_INCREMENT=1543721 DEFAULT
                                               CHARSET=utf8;

5                                                                       www.percona.com
Learn How MySQL 5.6 Makes Query Optimization Easier



    OPTIMIZER NEW FEATURES

6                                                   www.percona.com   5
Filesort with Short LIMIT
    • Queries that require a filesort but only the first
      records are selected can benefit from this
      optimization:
       mysql> EXPLAIN select * from movie_info
       ORDER BY info LIMIT 100G
       ********************* 1. row *********************
                  id: 1
         select_type: SIMPLE
               table: movie_info
                type: ALL
       possible_keys: NULL
                 key: NULL
             key_len: NULL
                 ref: NULL
                rows: 6927988
               Extra: Using filesort
       1 row in set (0.00 sec)

    Note: Both EXPLAIN and the STATUS Handlers show the same outcome
7                                                      www.percona.com   5
Filesort with Short LIMIT
                 (cont.)
    • SELECT * FROM movie_info ORDER
      BY info LIMIT 100;
      • MySQL 5.5: 20.06 sec
      • MySQL 5.6 (P_S on): 9.14 sec
      • MySQL 5.6 (P_S off): 8.51 sec
    • Over 2x faster.
      • Exact speed-up may depend on the
        original sort buffer size


8                                       www.percona.com   5
Index Condition Pushdown
    • Let’s prepare a use case:
      UPDATE cast_info SET note = left(note,
      250);
      ALTER TABLE cast_info MODIFY note
      varchar(250), ADD INDEX role_id_note
      (role_id, note);
    • We want to execute:
      SELECT * FROM cast_info
      WHERE role_id = 1
      and note like '%Jaime%‘;
9                                    www.percona.com   5
Without ICP (5.5)
     mysql> EXPLAIN SELECT *        mysql> SHOW STATUS like 'Hand%';
     FROM cast_info                 +----------------------------+---------+
                                    | Variable_name              | Value   |
     WHERE role_id = 1              +----------------------------+---------+
     and note like '%Jaime%'G      | Handler_commit             | 1       |
                                    | Handler_delete             | 0       |
     ********** 1. row **********   | Handler_discover           | 0       |
                id: 1               | Handler_prepare            | 0       |
                                    | Handler_read_first         | 0       |
       select_type: SIMPLE          | Handler_read_key           | 1       |
             table: cast_info       | Handler_read_last          | 0       |
                                    | Handler_read_next          | 8346769 |
              type: ref             | Handler_read_prev          | 0       |
     possible_keys: role_id_note    | Handler_read_rnd           | 0       |
                                    | Handler_read_rnd_next      | 0       |
               key: role_id_note    | Handler_rollback           | 0       |
                                    | Handler_savepoint          | 0       |
           key_len: 4               | Handler_savepoint_rollback | 0       |
               ref: const           | Handler_update             | 0       |
                                    | Handler_write              | 0       |
              rows: 11553718        +----------------------------+---------+
             Extra: Using where     16 rows in set (0.00 sec)
     1 row in set (0.01 sec)



10                                                       www.percona.com       5
With ICP (5.6)
     mysql> EXPLAIN SELECT *            mysql> SHOW STATUS like 'Hand%';
     FROM cast_info                     +----------------------------+-------+
                                        | Variable_name              | Value |
     WHERE role_id = 1 and note like    +----------------------------+-------+
     '%Jaime%'G                        | Handler_commit             | 1     |
     ************ 1. row ************   | Handler_delete             | 0     |
                 id: 1                  | Handler_discover           | 0     |
                                        | Handler_external_lock      | 2     |
       select_type: SIMPLE              | Handler_mrr_init           | 0     |
             table: cast_info           | Handler_prepare            | 0     |
               type: ref                | Handler_read_first         | 0     |
     possible_keys: role_id_note        | Handler_read_key           | 1     |
                                        | Handler_read_last          | 0     |
                key: role_id_note       | Handler_read_next          | 266   |
           key_len: 4                   | Handler_read_prev          | 0     |
                ref: const              | Handler_read_rnd           | 0     |
               rows: 10259274           | Handler_read_rnd_next      | 0     |
                                        | Handler_rollback           | 0     |
             Extra: Using index         | Handler_savepoint          | 0     |
     condition                          | Handler_savepoint_rollback | 0     |
     1 row in set (0.00 sec)            | Handler_update             | 0     |
                                        | Handler_write              | 0     |
                                        +----------------------------+-------+
                                        18 rows in set (0.00 sec)


11                                                           www.percona.com     5
Comparison of ICP Execution
     • Execution time for this example:
        • MySQL 5.5: 5.76 sec
        • MySQL 5.6: 1.09 sec
     • Over 5x faster
     • In this example, it would not work with a
       prefix index (e.g. TEXT/BLOB), as it must
       search the whole field
     • Fun fact: if covering technique is tried, it actually runs
       slower than with ICP for this case/hardware (#68554)


12                                                     www.percona.com   5
ICP and Indexing
     • ICP will change the way we index our tables
       SELECT * FROM cast_info
       FORCE INDEX(person_role_id_role_id)
       WHERE person_role_id > 0
       and person_role_id < 150000
       and role_id > 1 and role_id < 7;
     • For example, a multiple column index can be, in
       some cases, efficiently used for a range
       condition on several columns:
       •   Effectiveness is highly dependent on how selective
           is the second part of the index (an “index scan” is
           still done at engine level)
13                                                www.percona.com
                                                                    13
MySQL Option Change
     • For the next test cases, we will change
       the Buffer Pool size to:
       innodb_buffer_pool_size = 100M
       as the next optimizations depend on data
       being accessed mainly on disk




14                                     www.percona.com
Multi-Range Read (MRR)
     • Reorders access to table data when using
       a secondary index on disk for sequential
       I/O
        • Like ICP, its efficiency is highly dependent on
          data distribution and memory contents
     • It also depends on hardware sequential
       access (e.g., InnoDB’s read ahead)
        • Not useful on SSDs
     • Not compatible with Using index
     • Only for range access and equi-joins

15                                              www.percona.com   5
MRR Example
     • We want to execute:
       SELECT * FROM cast_info
       WHERE person_role_id > 0
       and person_role_id < 150000;
       SELECT * FROM cast_info
       WHERE role_id = 3
       and person_role_id > 0
       and person_role_id < 500000 ;
     • We will use these indexes, respectively:
       ALTER TABLE cast_info
       ADD INDEX person_role_id (person_role_id);
       ALTER TABLE cast_info
       ADD INDEX person_role_id_role_id (person_role_id,
       role_id);


16                                            www.percona.com   5
Without MRR (5.5)
     mysql> EXPLAIN SELECT * FROM     mysql> SHOW STATUS like 'Hand%';
                                      +----------------------------+---------+
     cast_info FORCE                  | Variable_name              | Value   |
     INDEX(person_role_id) WHERE      +----------------------------+---------+
                                      | Handler_commit             | 1       |
     person_role_id > 0 and           | Handler_delete             | 0       |
     person_role_id < 150000G        | Handler_discover           | 0       |
                                      | Handler_prepare            | 0       |
     *********** 1. row ***********   | Handler_read_first         | 0       |
                id: 1                 | Handler_read_key           | 1       |
                                      | Handler_read_last          | 0       |
       select_type: SIMPLE            | Handler_read_next          | 4654312 |
             table: cast_info         | Handler_read_prev          | 0       |
              type: range             | Handler_read_rnd           | 0       |
                                      | Handler_read_rnd_next      | 0       |
     possible_keys: person_role_id    | Handler_rollback           | 0       |
               key: person_role_id    | Handler_savepoint          | 0       |
           key_len: 5                 | Handler_savepoint_rollback | 0       |
                                      | Handler_update             | 0       |
               ref: NULL              | Handler_write              | 0       |
              rows: 8966490           +----------------------------+---------+
                                      16 rows in set (0.00 sec)
             Extra: Using where
     1 row in set (0.00 sec)




17                                                              www.percona.com   5
With MRR (5.6)
     mysql> EXPLAIN SELECT * FROM     mysql> SHOW STATUS like 'Hand%';
                                      +----------------------------+---------+
     cast_info FORCE                  | Variable_name              | Value   |
     INDEX(person_role_id) WHERE      +----------------------------+---------+
                                      | Handler_commit             | 1       |
     person_role_id > 0 and           | Handler_delete             | 0       |
     person_role_id < 150000G        | Handler_discover           | 0       |
                                      | Handler_external_lock      | 4       |
     *********** 1. row ***********   | Handler_mrr_init           | 0       |
                id: 1                 | Handler_prepare            | 0       |
                                      | Handler_read_first         | 0       |
       select_type: SIMPLE            | Handler_read_key           | 4654313 |
             table: cast_info         | Handler_read_last          | 0       |
              type: range             | Handler_read_next          | 4654312 |
                                      | Handler_read_prev          | 0       |
     possible_keys: person_role_id    | Handler_read_rnd           | 4654312 |
               key: person_role_id    | Handler_read_rnd_next      | 0       |
           key_len: 5                 | Handler_rollback           | 0       |
                                      | Handler_savepoint          | 0       |
               ref: NULL              | Handler_savepoint_rollback | 0       |
              rows: 8966490           | Handler_update             | 0       |
                                      | Handler_write              | 0       |
             Extra: Using index
                                      +----------------------------+---------+
     condition; Using MRR             18 rows in set (0.00 sec)
     1 row in set (0.00 sec)



18                                                              www.percona.com   5
Comparison of MRR
                Execution
     • Execution time for this example:
       •   MySQL 5.5: 4654312 rows in set (1 min 4.79 sec)
       •   MySQL 5.6 (w/MRR, wo/ICP): 4654312 rows in set
           (48.64 sec)
     • Consistent 33% execution improvement
       for this test case
       •   Difficult to see for smaller resultsets
     • What has changed?
       •   15% more “read_ahead”s, resulting in a 40% less data reads
       •   Reordering has an overhead, can be tuned with
           read_rnd_buffer_size

19                                                      www.percona.com   5
What’s the Point for the
             ‘FORCE INDEX’?
     • For demonstration purposes (full table scan
       is better here)
     • Some features are not properly detected yet:
       SELECT *
       FROM cast_info FORCE INDEX(person_role_id_role_id)
       WHERE role_id = 3
       and person_role_id > 0
       and person_role_id < 500000;

     • Full table scan (any version): Empty set
       (8.08 sec)
     • MySQL 5.5: Empty set (1 min 16.88 sec)
     • MySQL 5.6 ICP+MRR*: Empty set (0.46 sec)
       *ICP is responsible for the dramatic change in execution time, not MRR

20                                                                          www.percona.com
Batched Key Access (BKA)
     • It retrieves keys in batches and allows
       MRR usage for JOINs, as an alternative to
       standard Nested Loop Join execution
     • Not enabled by default
       SET optimizer_switch=
       'mrr=on,mrr_cost_based=off,batched_key_access=on';




21                                            www.percona.com
Without BKA (5.5) - EXPLAIN
     mysql> EXPLAIN                               ...
     SELECT cast_info.note, char_name.name
     FROM cast_info FORCE index(person_role_id)   ************* 2. row *************
     JOIN char_name                                          id: 1
     ON cast_info.person_role_id = char_name.id
     WHERE cast_info.person_role_id > 0 and         select_type: SIMPLE
     cast_info.person_role_id < 150000                    table: cast_info
     ************ 1. row ************                      type: ref
                id: 1                             possible_keys: person_role_id
       select_type: SIMPLE
                                                            key: person_role_id
             table: char_name                           key_len: 5
              type: range                                   ref: imdb.char_name.id
     possible_keys: PRIMARY                                rows: 4
               key: PRIMARY                               Extra: NULL
           key_len: 4
                                                  2 rows in set (0.00 sec)
               ref: NULL
              rows: 313782
             Extra: Using where
     ...


22                                                                   www.percona.com
Without BKA (5.5) - Handlers
           mysql> SHOW STATUS like ‘Hand%’;
           +----------------------------+---------+
           | Variable_name              | Value   |
           +----------------------------+---------+
           | Handler_commit             | 1       |
           | Handler_delete             | 0       |
           | Handler_discover           | 0       |
           | Handler_prepare            | 0       |
           | Handler_read_first         | 0       |
           | Handler_read_key           | 150000 |
           | Handler_read_last          | 0       |
           | Handler_read_next          | 4804311 |
           | Handler_read_prev          | 0       |
           | Handler_read_rnd           | 0       |
           | Handler_read_rnd_next      | 0       |
           | Handler_rollback           | 0       |
           | Handler_savepoint          | 0       |
           | Handler_savepoint_rollback | 0       |
           | Handler_update             | 0       |
           | Handler_write              | 0       |
           +----------------------------+---------+
           18 rows in set (0.00 sec)




23                                                    www.percona.com
With BKA (5.6) - EXPLAIN
     mysql> EXPLAIN                               ...
     SELECT cast_info.note, char_name.name
     FROM cast_info FORCE index(person_role_id)   ************ 2. row ************
     JOIN char_name ON cast_info.person_role_id              id: 1
     = char_name.id
     WHERE cast_info.person_role_id > 0 and         select_type: SIMPLE
     cast_info.person_role_id < 150000G                  table: cast_info
     ************ 1. row ************                      type: ref
                id: 1                             possible_keys: person_role_id
       select_type: SIMPLE                                  key: person_role_id
             table: char_name                           key_len: 5
              type: range                                   ref: imdb.char_name.id
     possible_keys: PRIMARY                                rows: 4
               key: PRIMARY                               Extra: Using join buffer
           key_len: 4                             (Batched Key Access)
               ref: NULL                          2 rows in set (0.00 sec)
              rows: 313782
             Extra: Using where
     ...


24                                                                   www.percona.com
With BKA (5.6) - Handlers
          mysql> SHOW STATUS like ‘Hand%’;
          +----------------------------+---------+
          | Variable_name              | Value   |
          +----------------------------+---------+
          | Handler_commit             | 1       |
          | Handler_delete             | 0       |
          | Handler_discover           | 0       |
          | Handler_external_lock      | 6       |
          | Handler_mrr_init           | 1       |
          | Handler_prepare            | 0       |
          | Handler_read_first         | 0       |
          | Handler_read_key           | 4804312 |
          | Handler_read_last          | 0       |
          | Handler_read_next          | 4804311 |
          | Handler_read_prev          | 0       |
          | Handler_read_rnd           | 4654312 |
          | Handler_read_rnd_next      | 0       |
          | Handler_rollback           | 0       |
          | Handler_savepoint          | 0       |
          | Handler_savepoint_rollback | 0       |
          | Handler_update             | 0       |
          | Handler_write              | 0       |
          +----------------------------+---------+
          18 rows in set (0.00 sec)


25                                                   www.percona.com
Comparison of BKA
                 Execution
     • Execution time for this example:
       •   MySQL 5.5: 4654312 rows in set (1 min 6.78 sec)
       •   MySQL 5.6 (w/MRR, w/BKA): 4654312 rows in set
           (1 min 0.47 sec)
     • The results are consistent between
       executions, but the gain is not too big. But
       if we change the join_buffer_size…
       •   MySQL 5.6 (w/MRR, w/BKA, join_buffer_size =
           50M): 4654312 rows in set (19.54 sec)
           (join_buffer_size does not affect execution time in the 5.5 version)



26                                                               www.percona.com   5
Better Index Merge
     •         In this example, it avoids a full table scan:
         mysql> EXPLAIN SELECT COUNT(*) FROM title WHERE (title =
         'Pilot' OR production_year > 2010) AND kind_id < 4G
         ************************ 1. row ************************
                    id: 1
           select_type: SIMPLE
                 table: title
                  type: index_merge
         possible_keys: title,production_year
                   key: title,production_year
               key_len: 77,5
                   ref: NULL
                  rows: 4434
                 Extra: Using sort_union(title,production_year);
         Using where
         1 row in set (0.00 sec)
         (almost all titles have kind_id < 4)

     •         MySQL 5.5: 0.79s – MySQL 5.6: 0.01s
27                                                       www.percona.com   5
Extended Secondary Keys
     • Implicit primary keys inside secondary keys
       can be used for filtering (ref, range, etc), not
       only for covering index or sorting.
     • Requires use_index_extensions=on
       (default)
       ALTER TABLE title add index
       (title(25));
       SELECT COUNT(*) FROM title
       WHERE title = 'Pilot'
       AND id BETWEEN 1000 AND 1000000;

28                                           www.percona.com   5
Extended Secondary Keys
     mysql> EXPLAIN SELECT COUNT(*) FROM title WHERE
     title = 'Pilot' AND id BETWEEN 1000 AND
     1000000G
     ****************** 1. row *******************
                 id: 1
       select_type: SIMPLE
             table: title
               type: range
     possible_keys: PRIMARY,title
                key: title
           key_len: 81
                ref: NULL
               rows: 531
             Extra: Using index condition; Using
     where
     1 row in set (0.00 sec)

29                                        www.percona.com   5
JOINs and Subqueries
     • Lazy Subquery Materialization
        • Useful for FROM subqueries if further
          filtering is done
     • Better detection of IN + non-dependent
       subqueries
        • Do not need to be converted to JOIN
          anymore for better execution
     • Join Order with Many Tables
        • Table order algorithm has been
          optimized, which leads to better query
          plans

30                                       www.percona.com   5
Learn How MySQL 5.6 Makes Query Optimization Easier



     OPTIMIZER PROFILING AND TOOLS

31                                                   www.percona.com   5
EXPLAIN on DML
     • EXPLAIN is now available also for
       INSERT, UPDATE and DELETE
     mysql> EXPLAIN DELETE FROM title WHERE title = 'Pilot'G
     ********************* 1. row *********************
                id: 1
       select_type: SIMPLE
             table: title
              type: range
     possible_keys: PRIMARY,title
               key: title
           key_len: 77
               ref: NULL
              rows: 1380
             Extra: Using where
     1 row in set (0.00 sec)

32                                                   www.percona.com   5
Structured EXPLAIN
     mysql> EXPLAIN FORMAT=JSON SELECT COUNT(*) FROM title
     WHERE (title = 'Pilot' OR production_year > 2010)
     AND kind_id < 4G
     *************************** 1. row ***************************
     EXPLAIN: {
       "query_block": {
         "select_id": 1,
         "table": {
           "table_name": "title",
           "access_type": "index_merge",
           "possible_keys": [
              "title",
              "production_year"
           ],
           "key": "sort_union(title,production_year)",
           "key_length": "77,5",
           "rows": 4434,
           "filtered": 100,
           "attached_condition": "(((`imdb`.`title`.`title` = 'Pilot') or
     (`imdb`.`title`.`production_year` > 2010)) and
     (`imdb`.`title`.`kind_id` < 4))"
         }
       }
     }


33                                                         www.percona.com   5
Optimizer Trace
     • Allows profiling of MySQL query planner
     • It shows not only information about the
       final query plan (EXPLAIN), but also about
       other discarded strategies, and its
       “execution cost”
     • It can be accessed via the
       INFORMATION_SCHEMA database
     • It is off by default

34                                     www.percona.com   5
Checking the Optimizer Trace
     • mysql> SET optimizer_trace="enabled=on";
     • mysql> SELECT COUNT(*) FROM title WHERE
       (title = 'Pilot' OR production_year >
       2010) AND kind_id < 4;
       +----------+
       | COUNT(*) |
       +----------+
       |     3050 |
       +----------+
       1 row in set (0.01 sec)
     • mysql> SELECT trace FROM
       information_schema.optimizer_trace;

35                                    www.percona.com   5
Checking the Optimizer Trace
                (cont.)
               {
                   "range_scan_alternatives": [
                     {
                       "index": "production_year",
                       "ranges": [
                         "2010 < production_year"
                       ],
                       "index_dives_for_eq_ranges": true,
                       "rowid_ordered": false,
                       "using_mrr": false,
                       "index_only": true,
                       "rows": 3054,
                       "cost": 615.16,
                       "chosen": true
                     }
                   ],
                   "index_to_merge": "production_year",
                   "cumulated_cost": 905.69
               }
             ],
             "cost_of_reading_ranges": 905.69,
             "cost_sort_rowid_and_read_disk": 3672.8,
             "cost_duplicate_removal": 9467.6,
             "total_cost": 14046
            }
          ],
          "chosen_range_access_summary": {
            "range_access_plan": {
              "type": "index_merge",
              "index_merge_of": [


36                                                          www.percona.com   5
Persistent Optimizer
                  Statistics
     • InnoDB index statistics are no longer
       discarded on server shutdown and
       recomputed the next time a table is
       accessed
     • Controlled by variable:
       innodb_stats_persistent = ON
       (default)
     • Remember that SHOW commands/accessing to
       I_S do not automatically regenerate statistics by
       default
37                                           www.percona.com   5
Duplicated Key Check
     mysql> alter table title add index (production_year);
     Query OK, 0 rows affected (10.08 sec)
     Records: 0 Duplicates: 0 Warnings: 0
     mysql> alter table title add index (production_year);
     Query OK, 0 rows affected, 1 warning (5.11 sec)
     Records: 0 Duplicates: 0 Warnings: 1

     mysql> show warningsG
     ************************* 1. row *************************
       Level: Note
        Code: 1831
     Message: Duplicate index 'production_year_2' defined on
     the table 'imdb.title'. This is deprecated and will be
     disallowed in a future release.
     1 row in set (0.00 sec)

38                                                 www.percona.com   5
Learn How MySQL 5.6 Makes Query Optimization Easier



     CONCLUSION

39                                                   www.percona.com   5
5.6 is a Great Release
     • Many optimizer changes that can
        potentially improve query execution time
     • Some of them are transparent, some
        others require tuning and understanding
     • Some old tricks and indexing strategies
        become obsolete in 5.6
      • pt-upgrade, from Percona Toolkit, and
        Percona Playback can be great tools to
        analyze improvements and regressions
40                                      www.percona.com
Where to Learn More ?
     • More query and server optimization
       techniques in our training courses
       (http://www.percona.com/training):
        • Chicago, begins Monday, April 8, 2013
        • London, begins Monday, April 8, 2013
        • 15% discount for April training with
           coupon code W15
     • Stay tuned for our new MySQL 5.6 course in
       May
     • http://www.mysqlperformanceblog.com

41                                      www.percona.com
Percona Live
          Conference and Expo



•   Use Discount Code: “PerWebinar1” to receive 15% discount
•   For more information and to register:
          Visit: http://www.percona.com/live/mysql-conference-2013/
Thank You!
            Jaime Crespo
     jaime.crespo@percona.com




43                              www.percona.com
                                 www.percona.com

Más contenido relacionado

La actualidad más candente

Advanced MySQL Query and Schema Tuning
Advanced MySQL Query and Schema TuningAdvanced MySQL Query and Schema Tuning
Advanced MySQL Query and Schema TuningMYXPLAIN
 
Advanced MySQL Query Tuning
Advanced MySQL Query TuningAdvanced MySQL Query Tuning
Advanced MySQL Query TuningAlexander Rubin
 
Mysql Explain Explained
Mysql Explain ExplainedMysql Explain Explained
Mysql Explain ExplainedJeremy Coates
 
MySQL Query tuning 101
MySQL Query tuning 101MySQL Query tuning 101
MySQL Query tuning 101Sveta Smirnova
 
How to Design Indexes, Really
How to Design Indexes, ReallyHow to Design Indexes, Really
How to Design Indexes, ReallyMYXPLAIN
 
Optimizing queries MySQL
Optimizing queries MySQLOptimizing queries MySQL
Optimizing queries MySQLGeorgi Sotirov
 
Optimizer Histograms: When they Help and When Do Not?
Optimizer Histograms: When they Help and When Do Not?Optimizer Histograms: When they Help and When Do Not?
Optimizer Histograms: When they Help and When Do Not?Sveta Smirnova
 
Introduction into MySQL Query Tuning for Dev[Op]s
Introduction into MySQL Query Tuning for Dev[Op]sIntroduction into MySQL Query Tuning for Dev[Op]s
Introduction into MySQL Query Tuning for Dev[Op]sSveta Smirnova
 
Efficient Pagination Using MySQL
Efficient Pagination Using MySQLEfficient Pagination Using MySQL
Efficient Pagination Using MySQLEvan Weaver
 
New features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in actionNew features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in actionSveta Smirnova
 
MySQL Index Cookbook
MySQL Index CookbookMySQL Index Cookbook
MySQL Index CookbookMYXPLAIN
 
Powerful Explain in MySQL 5.6
Powerful Explain in MySQL 5.6Powerful Explain in MySQL 5.6
Powerful Explain in MySQL 5.6MYXPLAIN
 
MySQL partitions tutorial
MySQL partitions tutorialMySQL partitions tutorial
MySQL partitions tutorialGiuseppe Maxia
 
Optimizing MySQL Queries
Optimizing MySQL QueriesOptimizing MySQL Queries
Optimizing MySQL QueriesAchievers Tech
 

La actualidad más candente (20)

Advanced MySQL Query and Schema Tuning
Advanced MySQL Query and Schema TuningAdvanced MySQL Query and Schema Tuning
Advanced MySQL Query and Schema Tuning
 
Advanced MySQL Query Tuning
Advanced MySQL Query TuningAdvanced MySQL Query Tuning
Advanced MySQL Query Tuning
 
Mysql Explain Explained
Mysql Explain ExplainedMysql Explain Explained
Mysql Explain Explained
 
MySQL Query tuning 101
MySQL Query tuning 101MySQL Query tuning 101
MySQL Query tuning 101
 
How to Design Indexes, Really
How to Design Indexes, ReallyHow to Design Indexes, Really
How to Design Indexes, Really
 
Optimizing queries MySQL
Optimizing queries MySQLOptimizing queries MySQL
Optimizing queries MySQL
 
Load Data Fast!
Load Data Fast!Load Data Fast!
Load Data Fast!
 
Optimizer Histograms: When they Help and When Do Not?
Optimizer Histograms: When they Help and When Do Not?Optimizer Histograms: When they Help and When Do Not?
Optimizer Histograms: When they Help and When Do Not?
 
Percona toolkit
Percona toolkitPercona toolkit
Percona toolkit
 
Introduction into MySQL Query Tuning for Dev[Op]s
Introduction into MySQL Query Tuning for Dev[Op]sIntroduction into MySQL Query Tuning for Dev[Op]s
Introduction into MySQL Query Tuning for Dev[Op]s
 
Efficient Pagination Using MySQL
Efficient Pagination Using MySQLEfficient Pagination Using MySQL
Efficient Pagination Using MySQL
 
New features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in actionNew features in Performance Schema 5.7 in action
New features in Performance Schema 5.7 in action
 
MySQL Index Cookbook
MySQL Index CookbookMySQL Index Cookbook
MySQL Index Cookbook
 
Powerful Explain in MySQL 5.6
Powerful Explain in MySQL 5.6Powerful Explain in MySQL 5.6
Powerful Explain in MySQL 5.6
 
Sql query patterns, optimized
Sql query patterns, optimizedSql query patterns, optimized
Sql query patterns, optimized
 
How to Use JSON in MySQL Wrong
How to Use JSON in MySQL WrongHow to Use JSON in MySQL Wrong
How to Use JSON in MySQL Wrong
 
MySQL partitions tutorial
MySQL partitions tutorialMySQL partitions tutorial
MySQL partitions tutorial
 
Optimizing MySQL Queries
Optimizing MySQL QueriesOptimizing MySQL Queries
Optimizing MySQL Queries
 
Recursive Query Throwdown
Recursive Query ThrowdownRecursive Query Throwdown
Recursive Query Throwdown
 
Mentor Your Indexes
Mentor Your IndexesMentor Your Indexes
Mentor Your Indexes
 

Destacado

Understanding query-execution806
Understanding query-execution806Understanding query-execution806
Understanding query-execution806yubao fu
 
Zurich2007 MySQL Query Optimization
Zurich2007 MySQL Query OptimizationZurich2007 MySQL Query Optimization
Zurich2007 MySQL Query OptimizationHiệp Lê Tuấn
 
Building High Performance MySql Query Systems And Analytic Applications
Building High Performance MySql Query Systems And Analytic ApplicationsBuilding High Performance MySql Query Systems And Analytic Applications
Building High Performance MySql Query Systems And Analytic Applicationsguest40cda0b
 
MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014
MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014
MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014Dave Stokes
 
MYSQL Query Anti-Patterns That Can Be Moved to Sphinx
MYSQL Query Anti-Patterns That Can Be Moved to SphinxMYSQL Query Anti-Patterns That Can Be Moved to Sphinx
MYSQL Query Anti-Patterns That Can Be Moved to SphinxPythian
 
Query Optimization with MySQL 5.6: Old and New Tricks
Query Optimization with MySQL 5.6: Old and New TricksQuery Optimization with MySQL 5.6: Old and New Tricks
Query Optimization with MySQL 5.6: Old and New TricksMYXPLAIN
 
Tunning sql query
Tunning sql queryTunning sql query
Tunning sql queryvuhaininh88
 
MySQL Query Optimization
MySQL Query OptimizationMySQL Query Optimization
MySQL Query OptimizationMorgan Tocker
 
Webinar 2013 advanced_query_tuning
Webinar 2013 advanced_query_tuningWebinar 2013 advanced_query_tuning
Webinar 2013 advanced_query_tuning晓 周
 
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricksQuery Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricksJaime Crespo
 
MySQL Query Optimization (Basics)
MySQL Query Optimization (Basics)MySQL Query Optimization (Basics)
MySQL Query Optimization (Basics)Karthik .P.R
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index TuningManikanda kumar
 
Percona Live 2012PPT: MySQL Query optimization
Percona Live 2012PPT: MySQL Query optimizationPercona Live 2012PPT: MySQL Query optimization
Percona Live 2012PPT: MySQL Query optimizationmysqlops
 
Using Optimizer Hints to Improve MySQL Query Performance
Using Optimizer Hints to Improve MySQL Query PerformanceUsing Optimizer Hints to Improve MySQL Query Performance
Using Optimizer Hints to Improve MySQL Query Performanceoysteing
 

Destacado (18)

Understanding query-execution806
Understanding query-execution806Understanding query-execution806
Understanding query-execution806
 
Zurich2007 MySQL Query Optimization
Zurich2007 MySQL Query OptimizationZurich2007 MySQL Query Optimization
Zurich2007 MySQL Query Optimization
 
Building High Performance MySql Query Systems And Analytic Applications
Building High Performance MySql Query Systems And Analytic ApplicationsBuilding High Performance MySql Query Systems And Analytic Applications
Building High Performance MySql Query Systems And Analytic Applications
 
MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014
MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014
MySQL Query Tuning for the Squeemish -- Fossetcon Orlando Sep 2014
 
MYSQL Query Anti-Patterns That Can Be Moved to Sphinx
MYSQL Query Anti-Patterns That Can Be Moved to SphinxMYSQL Query Anti-Patterns That Can Be Moved to Sphinx
MYSQL Query Anti-Patterns That Can Be Moved to Sphinx
 
Query Optimization with MySQL 5.6: Old and New Tricks
Query Optimization with MySQL 5.6: Old and New TricksQuery Optimization with MySQL 5.6: Old and New Tricks
Query Optimization with MySQL 5.6: Old and New Tricks
 
Tunning sql query
Tunning sql queryTunning sql query
Tunning sql query
 
MySQL Query Optimization
MySQL Query OptimizationMySQL Query Optimization
MySQL Query Optimization
 
My sql optimization
My sql optimizationMy sql optimization
My sql optimization
 
Webinar 2013 advanced_query_tuning
Webinar 2013 advanced_query_tuningWebinar 2013 advanced_query_tuning
Webinar 2013 advanced_query_tuning
 
MySQL Query Optimization.
MySQL Query Optimization.MySQL Query Optimization.
MySQL Query Optimization.
 
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricksQuery Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
Query Optimization with MySQL 5.7 and MariaDB 10: Even newer tricks
 
MySQL Query Optimization (Basics)
MySQL Query Optimization (Basics)MySQL Query Optimization (Basics)
MySQL Query Optimization (Basics)
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index Tuning
 
Percona Live 2012PPT: MySQL Query optimization
Percona Live 2012PPT: MySQL Query optimizationPercona Live 2012PPT: MySQL Query optimization
Percona Live 2012PPT: MySQL Query optimization
 
How to Design Indexes, Really
How to Design Indexes, ReallyHow to Design Indexes, Really
How to Design Indexes, Really
 
Mastering MySQL/Query
Mastering MySQL/QueryMastering MySQL/Query
Mastering MySQL/Query
 
Using Optimizer Hints to Improve MySQL Query Performance
Using Optimizer Hints to Improve MySQL Query PerformanceUsing Optimizer Hints to Improve MySQL Query Performance
Using Optimizer Hints to Improve MySQL Query Performance
 

Similar a 56 Query Optimization

What's New In MySQL 5.6
What's New In MySQL 5.6What's New In MySQL 5.6
What's New In MySQL 5.6Abdul Manaf
 
Indexierung mit MySQL
Indexierung mit MySQLIndexierung mit MySQL
Indexierung mit MySQLFromDual GmbH
 
Why Use EXPLAIN FORMAT=JSON?
 Why Use EXPLAIN FORMAT=JSON?  Why Use EXPLAIN FORMAT=JSON?
Why Use EXPLAIN FORMAT=JSON? Sveta Smirnova
 
Compare mysql5.1.50 mysql5.5.8
Compare mysql5.1.50 mysql5.5.8Compare mysql5.1.50 mysql5.5.8
Compare mysql5.1.50 mysql5.5.8Philip Zhong
 
2018 db-rainer schuettengruber-beating-oracles_optimizer_at_its_own_game-pres...
2018 db-rainer schuettengruber-beating-oracles_optimizer_at_its_own_game-pres...2018 db-rainer schuettengruber-beating-oracles_optimizer_at_its_own_game-pres...
2018 db-rainer schuettengruber-beating-oracles_optimizer_at_its_own_game-pres...Rainer Schuettengruber
 
MySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellMySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellEmily Ikuta
 
MySQL Performance Schema in 20 Minutes
 MySQL Performance Schema in 20 Minutes MySQL Performance Schema in 20 Minutes
MySQL Performance Schema in 20 MinutesSveta Smirnova
 
Scaling MySQL Strategies for Developers
Scaling MySQL Strategies for DevelopersScaling MySQL Strategies for Developers
Scaling MySQL Strategies for DevelopersJonathan Levin
 
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015Dave Stokes
 
MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015Dave Stokes
 
Preparse Query Rewrite Plugins
Preparse Query Rewrite PluginsPreparse Query Rewrite Plugins
Preparse Query Rewrite PluginsSveta Smirnova
 
Beginner guide to mysql command line
Beginner guide to mysql command lineBeginner guide to mysql command line
Beginner guide to mysql command linePriti Solanki
 
Performance Schema in Action: demo
Performance Schema in Action: demoPerformance Schema in Action: demo
Performance Schema in Action: demoSveta Smirnova
 
sveta smirnova - my sql performance schema in action
sveta smirnova - my sql performance schema in actionsveta smirnova - my sql performance schema in action
sveta smirnova - my sql performance schema in actionDariia Seimova
 
15 Ways to Kill Your Mysql Application Performance
15 Ways to Kill Your Mysql Application Performance15 Ways to Kill Your Mysql Application Performance
15 Ways to Kill Your Mysql Application Performanceguest9912e5
 
MySQL configuration - The most important Variables
MySQL configuration - The most important VariablesMySQL configuration - The most important Variables
MySQL configuration - The most important VariablesFromDual GmbH
 

Similar a 56 Query Optimization (20)

What's New In MySQL 5.6
What's New In MySQL 5.6What's New In MySQL 5.6
What's New In MySQL 5.6
 
Indexierung mit MySQL
Indexierung mit MySQLIndexierung mit MySQL
Indexierung mit MySQL
 
Why Use EXPLAIN FORMAT=JSON?
 Why Use EXPLAIN FORMAT=JSON?  Why Use EXPLAIN FORMAT=JSON?
Why Use EXPLAIN FORMAT=JSON?
 
Compare mysql5.1.50 mysql5.5.8
Compare mysql5.1.50 mysql5.5.8Compare mysql5.1.50 mysql5.5.8
Compare mysql5.1.50 mysql5.5.8
 
2018 db-rainer schuettengruber-beating-oracles_optimizer_at_its_own_game-pres...
2018 db-rainer schuettengruber-beating-oracles_optimizer_at_its_own_game-pres...2018 db-rainer schuettengruber-beating-oracles_optimizer_at_its_own_game-pres...
2018 db-rainer schuettengruber-beating-oracles_optimizer_at_its_own_game-pres...
 
Tek tutorial
Tek tutorialTek tutorial
Tek tutorial
 
MySQLinsanity
MySQLinsanityMySQLinsanity
MySQLinsanity
 
MySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellMySQL 5.7 in a Nutshell
MySQL 5.7 in a Nutshell
 
DPC Tutorial
DPC TutorialDPC Tutorial
DPC Tutorial
 
MySQL Performance Schema in 20 Minutes
 MySQL Performance Schema in 20 Minutes MySQL Performance Schema in 20 Minutes
MySQL Performance Schema in 20 Minutes
 
Scaling MySQL Strategies for Developers
Scaling MySQL Strategies for DevelopersScaling MySQL Strategies for Developers
Scaling MySQL Strategies for Developers
 
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
 
MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015
 
Preparse Query Rewrite Plugins
Preparse Query Rewrite PluginsPreparse Query Rewrite Plugins
Preparse Query Rewrite Plugins
 
Beginner guide to mysql command line
Beginner guide to mysql command lineBeginner guide to mysql command line
Beginner guide to mysql command line
 
Performance Schema in Action: demo
Performance Schema in Action: demoPerformance Schema in Action: demo
Performance Schema in Action: demo
 
sveta smirnova - my sql performance schema in action
sveta smirnova - my sql performance schema in actionsveta smirnova - my sql performance schema in action
sveta smirnova - my sql performance schema in action
 
15 Ways to Kill Your Mysql Application Performance
15 Ways to Kill Your Mysql Application Performance15 Ways to Kill Your Mysql Application Performance
15 Ways to Kill Your Mysql Application Performance
 
Optimizando MySQL
Optimizando MySQLOptimizando MySQL
Optimizando MySQL
 
MySQL configuration - The most important Variables
MySQL configuration - The most important VariablesMySQL configuration - The most important Variables
MySQL configuration - The most important Variables
 

Más de MYXPLAIN

Need for Speed: MySQL Indexing
Need for Speed: MySQL IndexingNeed for Speed: MySQL Indexing
Need for Speed: MySQL IndexingMYXPLAIN
 
Advanced Query Optimizer Tuning and Analysis
Advanced Query Optimizer Tuning and AnalysisAdvanced Query Optimizer Tuning and Analysis
Advanced Query Optimizer Tuning and AnalysisMYXPLAIN
 
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
 
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
 
Tools and Techniques for Index Design
Tools and Techniques for Index DesignTools and Techniques for Index Design
Tools and Techniques for Index DesignMYXPLAIN
 
The Power of MySQL Explain
The Power of MySQL ExplainThe Power of MySQL Explain
The Power of MySQL ExplainMYXPLAIN
 
Improving Performance with Better Indexes
Improving Performance with Better IndexesImproving Performance with Better Indexes
Improving Performance with Better IndexesMYXPLAIN
 
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
 

Más de MYXPLAIN (11)

Need for Speed: MySQL Indexing
Need for Speed: MySQL IndexingNeed for Speed: MySQL Indexing
Need for Speed: MySQL Indexing
 
Advanced Query Optimizer Tuning and Analysis
Advanced Query Optimizer Tuning and AnalysisAdvanced Query Optimizer Tuning and Analysis
Advanced Query Optimizer Tuning and Analysis
 
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
 
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
 
Tools and Techniques for Index Design
Tools and Techniques for Index DesignTools and Techniques for Index Design
Tools and Techniques for Index Design
 
The Power of MySQL Explain
The Power of MySQL ExplainThe Power of MySQL Explain
The Power of MySQL Explain
 
Improving Performance with Better Indexes
Improving Performance with Better IndexesImproving Performance with Better Indexes
Improving Performance with Better Indexes
 
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
 

Último

Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFMichael Gough
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfAarwolf Industries LLC
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 

Último (20)

Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDF
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdf
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 

56 Query Optimization

  • 1. Learn How MySQL 5.6 Makes Query Optimization Easier Jaime Crespo Percona Technical Webinars March 15, 2013
  • 2. About This Presentation • 5.6 from a pure technical view • Only query tuning, not other optimization or profiling features • Practical, simple examples but with real data (not “best cases”) • NOT benchmarks • Only response time/query strategy, not extra CPU/memory/locking • No comparisons with Percona Server or MariaDB • 5.6 optimizer has a lot of room for improvement, specially for query plan decision • Some features are poorly documented 2 www.percona.com
  • 3. Agenda • MySQL 5.6 Optimizer New Features • Filesort with short LIMIT • ICP • MRR • BKA • Index merge • Other Subquery and JOIN Optimizations • MySQL 5.6 Query Plan Information • EXPLAIN for DML • Structured EXPLAIN and Query Plan Profiler • Persistent Optimizer Statistics • Duplicate Key Check 3 www.percona.com
  • 4. Test Platform for Queries • We will compare official Oracle’s MySQL 5.5.30 vs 5.6.10 binary tarballs • Base platform: • CentOS 6.3 • 4 Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz • 32 GB RAM • Software RAID1 of SATA 6 GB/s HDD 7200 rpm • Standard options (not default) except otherwise noted • E.g. bigger transaction log and buffer pool, disabled P_S • Queries are executed several times between reboots • We will be using FORCE INDEX quite liberally • Not a good general practice 4 www.percona.com
  • 5. Original Test Schema CREATE TABLE `cast_info` ( CREATE TABLE `movie_info` ( `id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT, `person_id` int(11) NOT NULL, `movie_id` int(11) NOT NULL, `movie_id` int(11) NOT NULL, `info_type_id` int(11) NOT NULL, `person_role_id` int(11) DEFAULT NULL, `info` text NOT NULL, `note` text DEFAULT NULL, `note` text, `nr_order` int(11) DEFAULT NULL, PRIMARY KEY (`id`), `role_id` int(11) NOT NULL, ) ENGINE=InnoDB AUTO_INCREMENT=9748371 DEFAULT PRIMARY KEY (`id`), CHARSET=utf8; ) ENGINE=InnoDB AUTO_INCREMENT=22187769 DEFAULT CHARSET=utf8; CREATE TABLE `title` ( `id` int(11) NOT NULL AUTO_INCREMENT, CREATE TABLE `char_name` ( `title` text NOT NULL, `id` int(11) NOT NULL AUTO_INCREMENT, `imdb_index` varchar(12) DEFAULT NULL, `name` text NOT NULL, `kind_id` int(11) NOT NULL, `imdb_index` varchar(12) DEFAULT NULL, `production_year` int(11) DEFAULT NULL, `imdb_id` int(11) DEFAULT NULL, `imdb_id` int(11) DEFAULT NULL, `name_pcode_nf` varchar(5) DEFAULT NULL, `phonetic_code` varchar(5) DEFAULT NULL, `surname_pcode` varchar(5) DEFAULT NULL, `episode_of_id` int(11) DEFAULT NULL, PRIMARY KEY (`id`), `season_nr` int(11) DEFAULT NULL, ) ENGINE=InnoDB AUTO_INCREMENT=2406562 `episode_nr` int(11) DEFAULT NULL, DEFAULT CHARSET=utf8; `series_years` varchar(49) DEFAULT NULL, `title_crc32` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`id`), ) ENGINE=InnoDB AUTO_INCREMENT=1543721 DEFAULT CHARSET=utf8; 5 www.percona.com
  • 6. Learn How MySQL 5.6 Makes Query Optimization Easier OPTIMIZER NEW FEATURES 6 www.percona.com 5
  • 7. Filesort with Short LIMIT • Queries that require a filesort but only the first records are selected can benefit from this optimization: mysql> EXPLAIN select * from movie_info ORDER BY info LIMIT 100G ********************* 1. row ********************* id: 1 select_type: SIMPLE table: movie_info type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 6927988 Extra: Using filesort 1 row in set (0.00 sec) Note: Both EXPLAIN and the STATUS Handlers show the same outcome 7 www.percona.com 5
  • 8. Filesort with Short LIMIT (cont.) • SELECT * FROM movie_info ORDER BY info LIMIT 100; • MySQL 5.5: 20.06 sec • MySQL 5.6 (P_S on): 9.14 sec • MySQL 5.6 (P_S off): 8.51 sec • Over 2x faster. • Exact speed-up may depend on the original sort buffer size 8 www.percona.com 5
  • 9. Index Condition Pushdown • Let’s prepare a use case: UPDATE cast_info SET note = left(note, 250); ALTER TABLE cast_info MODIFY note varchar(250), ADD INDEX role_id_note (role_id, note); • We want to execute: SELECT * FROM cast_info WHERE role_id = 1 and note like '%Jaime%‘; 9 www.percona.com 5
  • 10. Without ICP (5.5) mysql> EXPLAIN SELECT * mysql> SHOW STATUS like 'Hand%'; FROM cast_info +----------------------------+---------+ | Variable_name | Value | WHERE role_id = 1 +----------------------------+---------+ and note like '%Jaime%'G | Handler_commit | 1 | | Handler_delete | 0 | ********** 1. row ********** | Handler_discover | 0 | id: 1 | Handler_prepare | 0 | | Handler_read_first | 0 | select_type: SIMPLE | Handler_read_key | 1 | table: cast_info | Handler_read_last | 0 | | Handler_read_next | 8346769 | type: ref | Handler_read_prev | 0 | possible_keys: role_id_note | Handler_read_rnd | 0 | | Handler_read_rnd_next | 0 | key: role_id_note | Handler_rollback | 0 | | Handler_savepoint | 0 | key_len: 4 | Handler_savepoint_rollback | 0 | ref: const | Handler_update | 0 | | Handler_write | 0 | rows: 11553718 +----------------------------+---------+ Extra: Using where 16 rows in set (0.00 sec) 1 row in set (0.01 sec) 10 www.percona.com 5
  • 11. With ICP (5.6) mysql> EXPLAIN SELECT * mysql> SHOW STATUS like 'Hand%'; FROM cast_info +----------------------------+-------+ | Variable_name | Value | WHERE role_id = 1 and note like +----------------------------+-------+ '%Jaime%'G | Handler_commit | 1 | ************ 1. row ************ | Handler_delete | 0 | id: 1 | Handler_discover | 0 | | Handler_external_lock | 2 | select_type: SIMPLE | Handler_mrr_init | 0 | table: cast_info | Handler_prepare | 0 | type: ref | Handler_read_first | 0 | possible_keys: role_id_note | Handler_read_key | 1 | | Handler_read_last | 0 | key: role_id_note | Handler_read_next | 266 | key_len: 4 | Handler_read_prev | 0 | ref: const | Handler_read_rnd | 0 | rows: 10259274 | Handler_read_rnd_next | 0 | | Handler_rollback | 0 | Extra: Using index | Handler_savepoint | 0 | condition | Handler_savepoint_rollback | 0 | 1 row in set (0.00 sec) | Handler_update | 0 | | Handler_write | 0 | +----------------------------+-------+ 18 rows in set (0.00 sec) 11 www.percona.com 5
  • 12. Comparison of ICP Execution • Execution time for this example: • MySQL 5.5: 5.76 sec • MySQL 5.6: 1.09 sec • Over 5x faster • In this example, it would not work with a prefix index (e.g. TEXT/BLOB), as it must search the whole field • Fun fact: if covering technique is tried, it actually runs slower than with ICP for this case/hardware (#68554) 12 www.percona.com 5
  • 13. ICP and Indexing • ICP will change the way we index our tables SELECT * FROM cast_info FORCE INDEX(person_role_id_role_id) WHERE person_role_id > 0 and person_role_id < 150000 and role_id > 1 and role_id < 7; • For example, a multiple column index can be, in some cases, efficiently used for a range condition on several columns: • Effectiveness is highly dependent on how selective is the second part of the index (an “index scan” is still done at engine level) 13 www.percona.com 13
  • 14. MySQL Option Change • For the next test cases, we will change the Buffer Pool size to: innodb_buffer_pool_size = 100M as the next optimizations depend on data being accessed mainly on disk 14 www.percona.com
  • 15. Multi-Range Read (MRR) • Reorders access to table data when using a secondary index on disk for sequential I/O • Like ICP, its efficiency is highly dependent on data distribution and memory contents • It also depends on hardware sequential access (e.g., InnoDB’s read ahead) • Not useful on SSDs • Not compatible with Using index • Only for range access and equi-joins 15 www.percona.com 5
  • 16. MRR Example • We want to execute: SELECT * FROM cast_info WHERE person_role_id > 0 and person_role_id < 150000; SELECT * FROM cast_info WHERE role_id = 3 and person_role_id > 0 and person_role_id < 500000 ; • We will use these indexes, respectively: ALTER TABLE cast_info ADD INDEX person_role_id (person_role_id); ALTER TABLE cast_info ADD INDEX person_role_id_role_id (person_role_id, role_id); 16 www.percona.com 5
  • 17. Without MRR (5.5) mysql> EXPLAIN SELECT * FROM mysql> SHOW STATUS like 'Hand%'; +----------------------------+---------+ cast_info FORCE | Variable_name | Value | INDEX(person_role_id) WHERE +----------------------------+---------+ | Handler_commit | 1 | person_role_id > 0 and | Handler_delete | 0 | person_role_id < 150000G | Handler_discover | 0 | | Handler_prepare | 0 | *********** 1. row *********** | Handler_read_first | 0 | id: 1 | Handler_read_key | 1 | | Handler_read_last | 0 | select_type: SIMPLE | Handler_read_next | 4654312 | table: cast_info | Handler_read_prev | 0 | type: range | Handler_read_rnd | 0 | | Handler_read_rnd_next | 0 | possible_keys: person_role_id | Handler_rollback | 0 | key: person_role_id | Handler_savepoint | 0 | key_len: 5 | Handler_savepoint_rollback | 0 | | Handler_update | 0 | ref: NULL | Handler_write | 0 | rows: 8966490 +----------------------------+---------+ 16 rows in set (0.00 sec) Extra: Using where 1 row in set (0.00 sec) 17 www.percona.com 5
  • 18. With MRR (5.6) mysql> EXPLAIN SELECT * FROM mysql> SHOW STATUS like 'Hand%'; +----------------------------+---------+ cast_info FORCE | Variable_name | Value | INDEX(person_role_id) WHERE +----------------------------+---------+ | Handler_commit | 1 | person_role_id > 0 and | Handler_delete | 0 | person_role_id < 150000G | Handler_discover | 0 | | Handler_external_lock | 4 | *********** 1. row *********** | Handler_mrr_init | 0 | id: 1 | Handler_prepare | 0 | | Handler_read_first | 0 | select_type: SIMPLE | Handler_read_key | 4654313 | table: cast_info | Handler_read_last | 0 | type: range | Handler_read_next | 4654312 | | Handler_read_prev | 0 | possible_keys: person_role_id | Handler_read_rnd | 4654312 | key: person_role_id | Handler_read_rnd_next | 0 | key_len: 5 | Handler_rollback | 0 | | Handler_savepoint | 0 | ref: NULL | Handler_savepoint_rollback | 0 | rows: 8966490 | Handler_update | 0 | | Handler_write | 0 | Extra: Using index +----------------------------+---------+ condition; Using MRR 18 rows in set (0.00 sec) 1 row in set (0.00 sec) 18 www.percona.com 5
  • 19. Comparison of MRR Execution • Execution time for this example: • MySQL 5.5: 4654312 rows in set (1 min 4.79 sec) • MySQL 5.6 (w/MRR, wo/ICP): 4654312 rows in set (48.64 sec) • Consistent 33% execution improvement for this test case • Difficult to see for smaller resultsets • What has changed? • 15% more “read_ahead”s, resulting in a 40% less data reads • Reordering has an overhead, can be tuned with read_rnd_buffer_size 19 www.percona.com 5
  • 20. What’s the Point for the ‘FORCE INDEX’? • For demonstration purposes (full table scan is better here) • Some features are not properly detected yet: SELECT * FROM cast_info FORCE INDEX(person_role_id_role_id) WHERE role_id = 3 and person_role_id > 0 and person_role_id < 500000; • Full table scan (any version): Empty set (8.08 sec) • MySQL 5.5: Empty set (1 min 16.88 sec) • MySQL 5.6 ICP+MRR*: Empty set (0.46 sec) *ICP is responsible for the dramatic change in execution time, not MRR 20 www.percona.com
  • 21. Batched Key Access (BKA) • It retrieves keys in batches and allows MRR usage for JOINs, as an alternative to standard Nested Loop Join execution • Not enabled by default SET optimizer_switch= 'mrr=on,mrr_cost_based=off,batched_key_access=on'; 21 www.percona.com
  • 22. Without BKA (5.5) - EXPLAIN mysql> EXPLAIN ... SELECT cast_info.note, char_name.name FROM cast_info FORCE index(person_role_id) ************* 2. row ************* JOIN char_name id: 1 ON cast_info.person_role_id = char_name.id WHERE cast_info.person_role_id > 0 and select_type: SIMPLE cast_info.person_role_id < 150000 table: cast_info ************ 1. row ************ type: ref id: 1 possible_keys: person_role_id select_type: SIMPLE key: person_role_id table: char_name key_len: 5 type: range ref: imdb.char_name.id possible_keys: PRIMARY rows: 4 key: PRIMARY Extra: NULL key_len: 4 2 rows in set (0.00 sec) ref: NULL rows: 313782 Extra: Using where ... 22 www.percona.com
  • 23. Without BKA (5.5) - Handlers mysql> SHOW STATUS like ‘Hand%’; +----------------------------+---------+ | Variable_name | Value | +----------------------------+---------+ | Handler_commit | 1 | | Handler_delete | 0 | | Handler_discover | 0 | | Handler_prepare | 0 | | Handler_read_first | 0 | | Handler_read_key | 150000 | | Handler_read_last | 0 | | Handler_read_next | 4804311 | | Handler_read_prev | 0 | | Handler_read_rnd | 0 | | Handler_read_rnd_next | 0 | | Handler_rollback | 0 | | Handler_savepoint | 0 | | Handler_savepoint_rollback | 0 | | Handler_update | 0 | | Handler_write | 0 | +----------------------------+---------+ 18 rows in set (0.00 sec) 23 www.percona.com
  • 24. With BKA (5.6) - EXPLAIN mysql> EXPLAIN ... SELECT cast_info.note, char_name.name FROM cast_info FORCE index(person_role_id) ************ 2. row ************ JOIN char_name ON cast_info.person_role_id id: 1 = char_name.id WHERE cast_info.person_role_id > 0 and select_type: SIMPLE cast_info.person_role_id < 150000G table: cast_info ************ 1. row ************ type: ref id: 1 possible_keys: person_role_id select_type: SIMPLE key: person_role_id table: char_name key_len: 5 type: range ref: imdb.char_name.id possible_keys: PRIMARY rows: 4 key: PRIMARY Extra: Using join buffer key_len: 4 (Batched Key Access) ref: NULL 2 rows in set (0.00 sec) rows: 313782 Extra: Using where ... 24 www.percona.com
  • 25. With BKA (5.6) - Handlers mysql> SHOW STATUS like ‘Hand%’; +----------------------------+---------+ | Variable_name | Value | +----------------------------+---------+ | Handler_commit | 1 | | Handler_delete | 0 | | Handler_discover | 0 | | Handler_external_lock | 6 | | Handler_mrr_init | 1 | | Handler_prepare | 0 | | Handler_read_first | 0 | | Handler_read_key | 4804312 | | Handler_read_last | 0 | | Handler_read_next | 4804311 | | Handler_read_prev | 0 | | Handler_read_rnd | 4654312 | | Handler_read_rnd_next | 0 | | Handler_rollback | 0 | | Handler_savepoint | 0 | | Handler_savepoint_rollback | 0 | | Handler_update | 0 | | Handler_write | 0 | +----------------------------+---------+ 18 rows in set (0.00 sec) 25 www.percona.com
  • 26. Comparison of BKA Execution • Execution time for this example: • MySQL 5.5: 4654312 rows in set (1 min 6.78 sec) • MySQL 5.6 (w/MRR, w/BKA): 4654312 rows in set (1 min 0.47 sec) • The results are consistent between executions, but the gain is not too big. But if we change the join_buffer_size… • MySQL 5.6 (w/MRR, w/BKA, join_buffer_size = 50M): 4654312 rows in set (19.54 sec) (join_buffer_size does not affect execution time in the 5.5 version) 26 www.percona.com 5
  • 27. Better Index Merge • In this example, it avoids a full table scan: mysql> EXPLAIN SELECT COUNT(*) FROM title WHERE (title = 'Pilot' OR production_year > 2010) AND kind_id < 4G ************************ 1. row ************************ id: 1 select_type: SIMPLE table: title type: index_merge possible_keys: title,production_year key: title,production_year key_len: 77,5 ref: NULL rows: 4434 Extra: Using sort_union(title,production_year); Using where 1 row in set (0.00 sec) (almost all titles have kind_id < 4) • MySQL 5.5: 0.79s – MySQL 5.6: 0.01s 27 www.percona.com 5
  • 28. Extended Secondary Keys • Implicit primary keys inside secondary keys can be used for filtering (ref, range, etc), not only for covering index or sorting. • Requires use_index_extensions=on (default) ALTER TABLE title add index (title(25)); SELECT COUNT(*) FROM title WHERE title = 'Pilot' AND id BETWEEN 1000 AND 1000000; 28 www.percona.com 5
  • 29. Extended Secondary Keys mysql> EXPLAIN SELECT COUNT(*) FROM title WHERE title = 'Pilot' AND id BETWEEN 1000 AND 1000000G ****************** 1. row ******************* id: 1 select_type: SIMPLE table: title type: range possible_keys: PRIMARY,title key: title key_len: 81 ref: NULL rows: 531 Extra: Using index condition; Using where 1 row in set (0.00 sec) 29 www.percona.com 5
  • 30. JOINs and Subqueries • Lazy Subquery Materialization • Useful for FROM subqueries if further filtering is done • Better detection of IN + non-dependent subqueries • Do not need to be converted to JOIN anymore for better execution • Join Order with Many Tables • Table order algorithm has been optimized, which leads to better query plans 30 www.percona.com 5
  • 31. Learn How MySQL 5.6 Makes Query Optimization Easier OPTIMIZER PROFILING AND TOOLS 31 www.percona.com 5
  • 32. EXPLAIN on DML • EXPLAIN is now available also for INSERT, UPDATE and DELETE mysql> EXPLAIN DELETE FROM title WHERE title = 'Pilot'G ********************* 1. row ********************* id: 1 select_type: SIMPLE table: title type: range possible_keys: PRIMARY,title key: title key_len: 77 ref: NULL rows: 1380 Extra: Using where 1 row in set (0.00 sec) 32 www.percona.com 5
  • 33. Structured EXPLAIN mysql> EXPLAIN FORMAT=JSON SELECT COUNT(*) FROM title WHERE (title = 'Pilot' OR production_year > 2010) AND kind_id < 4G *************************** 1. row *************************** EXPLAIN: { "query_block": { "select_id": 1, "table": { "table_name": "title", "access_type": "index_merge", "possible_keys": [ "title", "production_year" ], "key": "sort_union(title,production_year)", "key_length": "77,5", "rows": 4434, "filtered": 100, "attached_condition": "(((`imdb`.`title`.`title` = 'Pilot') or (`imdb`.`title`.`production_year` > 2010)) and (`imdb`.`title`.`kind_id` < 4))" } } } 33 www.percona.com 5
  • 34. Optimizer Trace • Allows profiling of MySQL query planner • It shows not only information about the final query plan (EXPLAIN), but also about other discarded strategies, and its “execution cost” • It can be accessed via the INFORMATION_SCHEMA database • It is off by default 34 www.percona.com 5
  • 35. Checking the Optimizer Trace • mysql> SET optimizer_trace="enabled=on"; • mysql> SELECT COUNT(*) FROM title WHERE (title = 'Pilot' OR production_year > 2010) AND kind_id < 4; +----------+ | COUNT(*) | +----------+ | 3050 | +----------+ 1 row in set (0.01 sec) • mysql> SELECT trace FROM information_schema.optimizer_trace; 35 www.percona.com 5
  • 36. Checking the Optimizer Trace (cont.) { "range_scan_alternatives": [ { "index": "production_year", "ranges": [ "2010 < production_year" ], "index_dives_for_eq_ranges": true, "rowid_ordered": false, "using_mrr": false, "index_only": true, "rows": 3054, "cost": 615.16, "chosen": true } ], "index_to_merge": "production_year", "cumulated_cost": 905.69 } ], "cost_of_reading_ranges": 905.69, "cost_sort_rowid_and_read_disk": 3672.8, "cost_duplicate_removal": 9467.6, "total_cost": 14046 } ], "chosen_range_access_summary": { "range_access_plan": { "type": "index_merge", "index_merge_of": [ 36 www.percona.com 5
  • 37. Persistent Optimizer Statistics • InnoDB index statistics are no longer discarded on server shutdown and recomputed the next time a table is accessed • Controlled by variable: innodb_stats_persistent = ON (default) • Remember that SHOW commands/accessing to I_S do not automatically regenerate statistics by default 37 www.percona.com 5
  • 38. Duplicated Key Check mysql> alter table title add index (production_year); Query OK, 0 rows affected (10.08 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> alter table title add index (production_year); Query OK, 0 rows affected, 1 warning (5.11 sec) Records: 0 Duplicates: 0 Warnings: 1 mysql> show warningsG ************************* 1. row ************************* Level: Note Code: 1831 Message: Duplicate index 'production_year_2' defined on the table 'imdb.title'. This is deprecated and will be disallowed in a future release. 1 row in set (0.00 sec) 38 www.percona.com 5
  • 39. Learn How MySQL 5.6 Makes Query Optimization Easier CONCLUSION 39 www.percona.com 5
  • 40. 5.6 is a Great Release • Many optimizer changes that can potentially improve query execution time • Some of them are transparent, some others require tuning and understanding • Some old tricks and indexing strategies become obsolete in 5.6 • pt-upgrade, from Percona Toolkit, and Percona Playback can be great tools to analyze improvements and regressions 40 www.percona.com
  • 41. Where to Learn More ? • More query and server optimization techniques in our training courses (http://www.percona.com/training): • Chicago, begins Monday, April 8, 2013 • London, begins Monday, April 8, 2013 • 15% discount for April training with coupon code W15 • Stay tuned for our new MySQL 5.6 course in May • http://www.mysqlperformanceblog.com 41 www.percona.com
  • 42. Percona Live Conference and Expo • Use Discount Code: “PerWebinar1” to receive 15% discount • For more information and to register: Visit: http://www.percona.com/live/mysql-conference-2013/
  • 43. Thank You! Jaime Crespo jaime.crespo@percona.com 43 www.percona.com www.percona.com