SlideShare une entreprise Scribd logo
1  sur  51
1   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
MySQL Optimizer Overview
Olav Sandstå
MySQL Optimizer Team




2   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Program Agenda


        §  Introduction to MySQL optimizer
        §  Query transformations
        §  Selecting data access method
        §  Join optimizer
        §  Subquery optimizations



3   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Query Optimizer

        What does the optimizer do?


         SELECT a, b                                                                                                             JOIN
         FROM t1, t2, t3
         WHERE t1.a = t2.b
           AND t2.b = t3.c                                                          Optimizer                      JOIN
                                                                                                                                        Table
                                                                                                                                        scan
           AND t2.d > 20
           AND t2.d < 30;                                                                                  Range           Ref           t1
                                                                                                            scan          access


                                                                                                            t2              t3
                                                             Metadata:                    Statistics:
                                                             -  Index information         -  Table sizes
                                                             -  Uniqueness                -  Cardinality
                                                             -  Nullability

4   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
MySQL Architecture
                                                           SQL query                      Parser

                                                                                      Preprocessor:
                                                                               Semantic check,name resolution

                                                                                      Optimizer
                                                                                 Logical transformations

                                                                                 Cost-based optimizer:
                                                                               Join order and access methods

                                                                                     Plan refinement

                                                                                      Query execution
                                                                                           plan


                                                                Query result        Query execution

                                                                                     Storage Engine
                                                                                 InnoDB            MyISAM

5   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
MySQL Optimizer Characteristics


         §  Produce a query plan that uses least resources
                    –  IO and CPU                                                                        JOIN

         §  Optimizes a single query
                                                                                                                Table
                                                                                                 JOIN
                    –  No inter-query optimizations                                                             scan


         §  Produces left-deep linear query execution plan                                             Table    t4
                                                                                   JOIN                 scan


                                                                           Range           Ref           t3
                                                                            scan          access


                                                                            t1              t2

6   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Optimizer Overview
        Main phases:
                                                                                  Negation elimination
                                                Logical                    Equality and constant propagation
                                                transformations             Conversion of outer to inner joins
                                                                               Subquery transformations
                                                                           Evaluation of constant expressions

                                                                                  Ref access analysis
                                                Prepare for                  Estimation of condition fanout
                                                cost-based                       Const table detection
                                                optimization                       Range analysis


                                                Cost-based                     Access method selection
                                                optimization                       JOIN optimizer



                                                                               Table condition pushdown
                                                Plan                          Access method adjustments
                                                refinement                          Sort avoidance
                                                                               Index condition pushdown



7   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Logical Transformations




8   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Logical Transformations


         §  Logical transformations of query conditions:
                    –  Negation elimination
                    –  Equality propagations
                    –  Evaluate constant expressions
                    –  Remove trivial conditions
         §  Conversion of outer to inner join
         §  Subquery transformations



9   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Logical Transformations

         Example:
          SELECT * FROM t1, t2 WHERE
           t1.a = t2.a AND t2.a = 9 AND (NOT (t1.a > 10 OR t2.b > 3) OR (t1.b = t2.b + 7 AND t2.b = 5));
                                                                       Negation
                                                                      elimination
           t1.a = t2.a AND t2.a = 9 AND (t1.a <= 10 AND t2.b <= 3 OR (t1.b = t2.b + 7 AND t2.b = 5));
                                                Equality/const
                                                 propagation
           t1.a = 9 AND t2.a = 9 AND (9 <= 10 AND t2.b <= 3 OR (t1.b = 5 + 7 AND t2.b = 5));
                                                                                        Evaluate const
                                                                                         expressions
           t1.a = 9 AND t2.a = 9 AND (9 <= 10 AND t2.b <= 3 OR (t1.b = 12 AND t2.b = 5));
                                                          Trivial condition
                                          =TRUE               removal
           t1.a = 9 AND t2.a = 9 AND (t2.b <= 3 OR (t1.b = 12 AND t2.b = 5));

10   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Cost-based Optimization




11   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Cost-based Query Optimization

                                                                                                                            JOIN
          General idea:
          §  Assign cost to operations                                                                       JOIN
                                                                                                                                   Table
                                                                                                                                   scan
          §  Assign cost to partial or alternative plans
                                                                                                      Range           Ref           t3
          §  Search for plan with lowest cost                                                         scan          access


                                                                                                        t1             t2
          §  Cost-based optimizations:

                       Access method                                        Join order   Subquery strategy


12   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Optimizer Cost Model

         The ”cost” for executing a query
          §  Cost unit: read of a random data page
          §  Main cost factors:
                     –  IO cost:
                                  §  #pages read from table
                                  §  #pages read from index
                     –  CPU cost:
                                  §  Cost for evaluating query conditions
                                  §  Cost for comparing keys/records


13   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Input to Cost Model


          §  IO-cost:                                                      §  Statistics:
                     –  Estimates from storage engine                          –  Number of records in table
                        based on number of pages to                            –  Key distribution/Cardinality:
                        read
                                                                                    §  Average number of records
                     –  Both index and data pages                                    per key value
          §  Schema:                                                               §  Only for indexed columns
                     –  Length of records and keys                                  §  Maintained by storage engine
                     –  Uniqueness for indexes                                 –  Number of records in an index
                     –  Nullability                                               range

14   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Cost Model Example


          SELECT * FROM t1 WHERE a BETWEEN 20 and 30;


          Table scan:
          §  IO-cost: #pages in table
          §  CPU cost: #records * ROW_EVALUATE_COST



          Range scan (on secondary index):
          §  IO-cost: #pages to read from index + #records_in_range
          §  CPU cost: #records_in_range * ROW_EVALUATE_COST


15   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Selecting Access Method




16   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Selecting Access Method

         Finding the optimal method to read data from storage engine
          §  For each table, find the best access method:                  Main access methods:
                                                                            §  Table scan
          §  1. Check if the access method is useful                       §  Index scan
          §  2. Estimate cost of using access method                       §  Ref access
          §  3. Select the cheapest to be used                             §  Range scan
                                                                            §  Index merge
          §  Choice of access method is cost based                         §  Loose index scan



17   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Ref Access


          §  Read all records with a given key value using an index:
          §  Examples:
                     SELECT * FROM t1 WHERE t1.key = 7;
                     SELECT * FROM t1, t2 WHERE t1.key = t2.key;

          §  “eq_ref”:
                     –  Reading from a unique index, max one record returned
          §  “ref”:
                     –  Reading from a non-unique index or a prefix of an index, multiple records
                            returned

18   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Ref Access Analysis


          §  Determine which indexes that can be used for ref access in a join
                  SELECT City.Name AS Capital, Language FROM CountryLanguage, Country, City
                  WHERE City.CountryCode = Country.Code
                  AND City.ID = Country.Capital
                  AND CountryLanguage.Country = Country.Code

                                                                            CountryLanguage
                                                                                Country
                                 Country                                                         City
                                     Code                                                     CountryCode
                                   Capital                                                        ID

19   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Range Optimizer


          §  Goal: find the “minimal” ranges for each index that needs to be read
          §  Example:
                       SELECT * FROM t1 WHERE (key1 > 10 AND key1 < 20) AND key2 > 30
          §  Range scan using INDEX(key1):

                                           10                               20


          §  Range scan using INDEX(key2):

                                                                                 30

20   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Range Optimizer, cont.


          §  Range optimizer selects the “useful” parts of the WHERE condition:
                     –  Conditions comparing a column value with a constant:
                                   key > 3                                  key BETWEEN 4 AND 6      key IS NULL
                                                         key = 4              key IN (10,12,..)   key LIKE ”abc%”
                     –  Nested AND/OR conditions are supported
          §  Result: list of disjoint ranges that need to be read from index:


          §  Cost estimate based on number of records in each range:
                     –  Record estimate is found by asking the Storage Engine (“index dives”)

21   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Range Access for Multi-part Index

         Example table with multi-part index
          §  Table:
                                                                                             pk       a           b           c

          §  INDEX idx(a, b, c);


          §  Logical storage layout of index:

                    a                                  10                               11                    12                          13
                    b              1        2           3           4       5   1   2   3     4   5   1   2   3       4   5       1   2   3    4   5
                    c



22   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Range Access for Multi-part Index, cont


          §  Equality on 1st index part?
                      –  Can add condition on 2nd index part in range condition
          §  Example:
                      SELECT * from t1 WHERE a IN (10,11,13) AND (b=2 OR b=4)
                  a                                  10                                 11                   12                   13
                  b              1        2           3           4         5   1   2   3    4   5   1   2   3    4   5   1   2   3    4   5
                  c



          §  Resulting range scan:
                                          2                       4                 2        4                                2        4

23   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Range Access for Multi-part Index, cont


          §  Non-Equality on 1st index part:
                      –  Can NOT add condition on 2nd index part in range condition
          §  Example:
                      SELECT * from t1 WHERE a > 10 AND a < 13 AND (b=2 OR b=4)
                  a                                  10                                 11                      12                   13
                  b              1        2           3           4         5   1   2   3     4   5   1   2     3    4   5   1   2   3    4   5
                  c



          §  Resulting range scan:
                                                                                             a >10 AND a < 13

24   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Index Merge


          §  Uses multiple indexes on the same table
          §  Implemented index merge strategies:
                     –  Index Merge Union
                                  §  OR-ed conditions between different indexes
                     –  Index Merge Intersect
                                  §  AND conditions between different indexes
                     –  Index Merge Sort-Union
                                  §  OR-ed conditions where condition is a range


25   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Index Merge Union


          §  Single index cannot handle ORed conditions on different columns
          §  Example:
                     SELECT * FROM t1 WHERE a=10 OR b=10
          §  Index Merge Union:
                    INDEX(a)                                                10

                    INDEX(b)                                                                10


                                                                                 Union


                  Result:                                                    a=10 OR b=10
26   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Loose Index Scan


          §  Optimization for GROUP BY and DISTINCT:
                     SELECT a, b FROM t1 GROUP BY a, b;
                     SELECT DISTINCT a, b FROM t1;
                     SELECT a, MIN(b) FROM t1 GROUP BY a;
         §  GROUP BY/DISTINCT must be on the prefix of the index


                 a                                  10                                  11                   12                   13
                 b              1        2           3           4          5   1   2   3    4   5   1   2   3    4   5   1   2   3    4   5
                 c



27   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Join Optimizer




28   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Join Optimizer

         ”Greedy search strategy”
          §  Goal: Given a JOIN of N tables, find the best JOIN ordering
          §  Strategy:
                     –  Start with all 1-table plans
                                                                                            t1        t2        t3    t4
                     –  Expand each plan with remaining tables
                                  §  Depth-first                                t2         t3             t4

                     –  If “cost of partial plan” > “cost of best plan”:
                                                                            t3    t4   t2        t4        t2    t3
                                  §  “prune” plan
                                                                            t4    t3   t4        t2        t3    t2




29   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
JOIN Optimizer Illustrated
               SELECT City.Name, Language FROM Language, Country, City
               WHERE City.CountryCode = Country.Code
                 AND City.ID = Country.Capital
                 AND City.Population >= 1000000
                 AND Language.Country = Country.Code;
                                                        start

                                                   Language                            Country                City
                                                                                                             cost=862

                         Country                            City             Language            City    Language       Country
                                                                                             cost=1245

                            City                         Country              City           Language    Country        Language

                      cost=26568                        cost=32568          cost=627




30   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Complexity and Cost of Join Optimizer

         Join of N tables: N! possible plans to evaluate
          Heuristics to reduce the number of plans to
          evaluate:
          §  Use optimizer_search_depth to limit the
              number of tables to consider
          §  Pre-sort tables on size and key
              dependency order (Improved in MySQL
              5.6)
          §  When adding the next table to a partial
              plan, add all tables that it has an equality
              reference to (New in MySQL 5.6)
31   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Plan Refinements




32   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Finalizing Query Plan

         Main optimizations:
          §  Assigning conditions to tables
                     –  Evaluate conditions as early as possible in join order
          §  ORDER BY optimization: avoid sorting
                     –  Change to different index
                     –  Read in descending order
          §  Change to a cheaper access method
                     –  Example: Use range scan instead of table scan or ref access
          §  Index Condition Pushdown (New in MySQL 5.6)


33   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Index Condition Pushdown                                                        New




          §  Pushes conditions that can be evaluated on the                      MySQL server

                index down to storage engine                                  Query
                                                                            conditions
                     –  Works only on indexed columns
          §  Goal: evaluate conditions without having to
                access the actual record
                     –  Reduces number of disk/block accesses                 Index

                     –  Reduces CPU usage                                   Table data
                                                                                  Storage engine
         §  Both conditions on a single index and
                    conditions on earlier tables in a JOIN can be
                    pushed down
34   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Index Condition Pushdown

         How it works

          Without ICP:                                                                MySQL server     With ICP:
                                                                                 Optimizer
          Storage Engine:                                                                              Storage Engine:
          1. Reads index                                                         Execution    4.       1. Reads index and
          2. Reads record                                                                                 evaluates pushed index
          3. Returns record                                                                               condition
                                                                                              3.       2. Reads record
          Server:                                                           1.                         3. Returns record
                                                                                   Index
          4. Evaluates condition                                            2.
                                                                                 Table data
                                                                                      Storage engine
                                                                                                       Server:
                                                                                                       4. Evaluates rest of condition

35   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Index Condition Pushdown Example


          CREATE TABLE person (
             name VARCHAR(..),
             height INTEGER,
             postalcode INTEGER,
             age INTEGER,
             INDEX (postalcode, age)
          );                                                                                       Evaluated by server

          SELECT name FROM person
          WHERE postalcode BETWEEN 5000 AND 5500 AND age BETWEEN 21 AND 22 AND height>180;

                                                                            Pushed to storage engine
                                                                            Evaluated on index entries

36   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Subqueries




37   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Overview of Subquery Optimizations
         Subquery category:                                                 Strategy:              New

          §  IN (SELECT …)                                                  •  Semi-Join
                                                                             •  Materialization
                                                                             •  IN ➜ EXISTS
          §  NOT IN (SELECT …)


          §  FROM (SELECT …)                                                •  Derived table

          §  <CompOp> ALL/ANY (SELECT ..)                                   •  MAX/MIN re-write

          §  EXISTS/other                                                   •  Execute subquery
38   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Optimization of IN subqueries
                                                                                                                         New
         A. Semi-join Transformation
          1.             Transform IN (and =ANY) subquery to semi-join:
                          SELECT * FROM t1
                          WHERE query_where AND outer_expr IN (SELECT inner_expr FROM t2 WHERE cond2)


                            SELECT * FROM t1 SEMIJOIN t2 ON outer_expr = inner_expr
                            WHERE query_where AND cond2

          2.             Apply transformations/strategies for avoiding/removing duplicates:
                                                                                   Duplicate
                                   Table pullout                                   Weedout                 First Match
                                                                                                 Semi-join
                                                                            LooseScan          materialization
          3.             Optimize using cost-based JOIN optimizer
39   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Optimization of IN Subqueries, cont.
                                                                                                         New
         B. Subquery Materialization
          §  Only for non-correlated subqueries
          §  Execute subquery once
                     –  store result in temporary table with unique index (removes duplicates)
          §  Outer query does lookup in temporary table




                                                                                                  Temporary
                SELECT title FROM film




                                                                                          Index

                                                                                                    table
                                                                            Lookup
                WHERE film_id IN
                  (SELECT film_id FROM actor WHERE name=“Bullock”)
                                                                            Materialize



40   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Optimization of IN Subqueries, cont.

         C. IN è EXISTS transformation
          §  Convert IN subquery to EXISTS subquery by “push-down” IN-equality
                to subquery:
                               SELECT title FROM film
                               WHERE film_id IN (SELECT film_id FROM actor WHERE name=“Bullock”)



                               SELECT title FROM film
                               WHERE EXISTS (SELECT 1 FROM actor
                                               WHERE name=“Bullock” AND film.film_id = actor.film_id)

          §  Benefit: subquery will evaluate fewer records
          §  Note: special handling if pushed down expressions can be NULL
41   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Query Execution Plan




42   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Understanding the Query Plan

         EXPLAIN
          §  Use EXPLAIN to print the final query plan:

          EXPLAIN SELECT * FROM t1 JOIN t2 ON t1.a = t2.a WHERE b > 10 AND c > 10;
          +----+-------------+-------+-------+---------------+-----+---------+------+------+-----------------------+
          | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra                   |
          +----+-------------+-------+-------+---------------+-----+---------+------+------+-----------------------+
          | 1 | SIMPLE       | t1    | range | PRIMARY,idx   | idx | 4       | NULL |   12 | Using index condition |
          | 2 | SIMPLE       | t2    | ref   | key1          | key1| 4       | t1.a |    1 | NULL                  |
          +----+-------------+-------+-------+---------------+-----+---------+------+------+-----------------------+


          §  Structured EXPLAIN (New in MySQL 5.6)
                     –  JSON format
                     –  Includes more information about query (eg. pushed index conditions)


43   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Understanding the Query Plan

         Structured Explain Example:
                  EXPLAIN FORMAT=JSON SELECT * FROM t1 WHERE b > 10 AND c > 10 AND d > 10;
                  EXPLAIN
                  {
                    "query_block": {
                      "select_id": 1,
                      "table": {
                        "table_name": "t1",
                        "access_type": "range",
                        "possible_keys": [
                           ”idx"
                        ],
                        "key": ”idx",
                        "key_length": "4",
                        "rows": 12,
                        "filtered": 100,
                        "index_condition": "((`test`.`t1`.`b` > 10) and (`test`.`t1`.`c` > 10))",
                        "attached_condition": "(`test`.`t1`.`d` > 10)"
                      }
                    }
                  }
44   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Optimizer Traces                                                   "table": "`t1`",
                                                                            "range_analysis": {
         (New in MySQL 5.6)                                                    "table_scan": {
                                                                                  "rows": 54,
         Understand HOW a query gets optimized                                 },
                                                                                  "cost": 13.9

                                                                               "best_covering_index_scan": {
          §  Tracing of the main steps and decisions                             "index": ”idx",
                                                                                  "cost": 11.903,
                done by the optimizer                                             "chosen": true
                                                                               },
                                                                               "analyzing_range_alternatives": {
                                                                                  "range_scan_alternatives": [
          §  Example:                                                            {
                                                                                    "index": ”idx",
                                                                                    "ranges": [
                                                                                       "10 < a"
                SET optimizer_trace=”enabled=on”;                                   ],
                SELECT * FROM t1 WHERE a > 10;                                      "rowid_ordered": false,
                SELECT * FROM                                                       "using_mrr": false,
                                                                                    "index_only": true,
                     INFORMATION_SCHEMA.OPTIMIZER_TRACE;                            "rows": 12,
                                                                                    "cost": 3.4314,
                                                                                    "chosen": true
                                                                                  }


45   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Influencing the Optimizer

         When the optimizer does not do what you want:
          §  Add indexes
          §  Force use of specific indexes:
                     –  USE INDEX, FORCE INDEX, IGNORE INDEX
          §  Force specific join order:
                     –  STRAIGHT_JOIN
          §  Adjust optimizer_switch flags:
                     –  set optimizer_switch=“index_merge=off”
          §  Ask question in the MySQL optimizer forum


46   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Query Execution




47   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Nested Loops Join

         Execution strategy for joins
            SELECT City.Name, Language FROM Language, Country, City WHERE …..

           QEP:                                                             Execution:
                                                                                                                                        Result
           City                                                 Range scan
                                                                                             Ref                     Table
           range access                                                                                              scan




                                                                                                                             Language
                                                                                                           Country
                                                                              Index




                                                                                                   Index
                                                                                      City
           Country
           ref access



            City
            table scan


48   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Presentations by the MySQL Optimizer Team


          Sessions:
          §  Overview of New Optimizer Features in MySQL 5.6
          §  Query Performance Comparison of MySQL 5.5 and MySQL 5.6
          §  Powerful EXPLAIN in MySQL 5.6


          BOF:
          §  Query Optimizations: What Is New and What Is Coming?



49   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Summary


        §  Query transformations
        §  Selecting data access method
        §  Join optimizer
        §  Subquery optimizations
        §  Plan refinements


                                                                            Questions?
50   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
Graphic Section Divider




51   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.

Contenu connexe

Tendances

How to analyze and tune sql queries for better performance webinar
How to analyze and tune sql queries for better performance webinarHow to analyze and tune sql queries for better performance webinar
How to analyze and tune sql queries for better performance webinaroysteing
 
How to analyze and tune sql queries for better performance vts2016
How to analyze and tune sql queries for better performance vts2016How to analyze and tune sql queries for better performance vts2016
How to analyze and tune sql queries for better performance vts2016oysteing
 
Optimizing MySQL Queries
Optimizing MySQL QueriesOptimizing MySQL Queries
Optimizing MySQL QueriesAchievers Tech
 
MySQL 8.0: Common Table Expressions
MySQL 8.0: Common Table ExpressionsMySQL 8.0: Common Table Expressions
MySQL 8.0: Common Table Expressionsoysteing
 
MySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZE
MySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZEMySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZE
MySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZENorvald Ryeng
 
How to Take Advantage of Optimizer Improvements in MySQL 8.0
How to Take Advantage of Optimizer Improvements in MySQL 8.0How to Take Advantage of Optimizer Improvements in MySQL 8.0
How to Take Advantage of Optimizer Improvements in MySQL 8.0Norvald Ryeng
 
How to analyze and tune sql queries for better performance
How to analyze and tune sql queries for better performanceHow to analyze and tune sql queries for better performance
How to analyze and tune sql queries for better performanceoysteing
 
Query optimizer vivek sharma
Query optimizer vivek sharmaQuery optimizer vivek sharma
Query optimizer vivek sharmaaioughydchapter
 
Don't optimize my queries, organize my data!
Don't optimize my queries, organize my data!Don't optimize my queries, organize my data!
Don't optimize my queries, organize my data!Julian Hyde
 
MySQL Optimizer: What’s New in 8.0
MySQL Optimizer: What’s New in 8.0MySQL Optimizer: What’s New in 8.0
MySQL Optimizer: What’s New in 8.0oysteing
 
MySQL: Indexing for Better Performance
MySQL: Indexing for Better PerformanceMySQL: Indexing for Better Performance
MySQL: Indexing for Better Performancejkeriaki
 
Explaining the explain_plan
Explaining the explain_planExplaining the explain_plan
Explaining the explain_planarief12H
 
MySQL 8.0: Common Table Expressions
MySQL 8.0: Common Table Expressions MySQL 8.0: Common Table Expressions
MySQL 8.0: Common Table Expressions oysteing
 
MySQL 8.0: What Is New in Optimizer and Executor?
MySQL 8.0: What Is New in Optimizer and Executor?MySQL 8.0: What Is New in Optimizer and Executor?
MySQL 8.0: What Is New in Optimizer and Executor?Norvald Ryeng
 
MySQL Indexing : Improving Query Performance Using Index (Covering Index)
MySQL Indexing : Improving Query Performance Using Index (Covering Index)MySQL Indexing : Improving Query Performance Using Index (Covering Index)
MySQL Indexing : Improving Query Performance Using Index (Covering Index)Hemant Kumar Singh
 
Oracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic FunctionsOracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic FunctionsZohar Elkayam
 

Tendances (20)

How to analyze and tune sql queries for better performance webinar
How to analyze and tune sql queries for better performance webinarHow to analyze and tune sql queries for better performance webinar
How to analyze and tune sql queries for better performance webinar
 
How to analyze and tune sql queries for better performance vts2016
How to analyze and tune sql queries for better performance vts2016How to analyze and tune sql queries for better performance vts2016
How to analyze and tune sql queries for better performance vts2016
 
Optimizing MySQL Queries
Optimizing MySQL QueriesOptimizing MySQL Queries
Optimizing MySQL Queries
 
MySQL 8.0: Common Table Expressions
MySQL 8.0: Common Table ExpressionsMySQL 8.0: Common Table Expressions
MySQL 8.0: Common Table Expressions
 
Explain that explain
Explain that explainExplain that explain
Explain that explain
 
MySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZE
MySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZEMySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZE
MySQL 8.0.18 latest updates: Hash join and EXPLAIN ANALYZE
 
How to Take Advantage of Optimizer Improvements in MySQL 8.0
How to Take Advantage of Optimizer Improvements in MySQL 8.0How to Take Advantage of Optimizer Improvements in MySQL 8.0
How to Take Advantage of Optimizer Improvements in MySQL 8.0
 
Query compiler
Query compilerQuery compiler
Query compiler
 
How to analyze and tune sql queries for better performance
How to analyze and tune sql queries for better performanceHow to analyze and tune sql queries for better performance
How to analyze and tune sql queries for better performance
 
Query optimizer vivek sharma
Query optimizer vivek sharmaQuery optimizer vivek sharma
Query optimizer vivek sharma
 
Don't optimize my queries, organize my data!
Don't optimize my queries, organize my data!Don't optimize my queries, organize my data!
Don't optimize my queries, organize my data!
 
MySQL Optimizer: What’s New in 8.0
MySQL Optimizer: What’s New in 8.0MySQL Optimizer: What’s New in 8.0
MySQL Optimizer: What’s New in 8.0
 
Etl2
Etl2Etl2
Etl2
 
Advanced Relevancy Ranking
Advanced Relevancy RankingAdvanced Relevancy Ranking
Advanced Relevancy Ranking
 
MySQL: Indexing for Better Performance
MySQL: Indexing for Better PerformanceMySQL: Indexing for Better Performance
MySQL: Indexing for Better Performance
 
Explaining the explain_plan
Explaining the explain_planExplaining the explain_plan
Explaining the explain_plan
 
MySQL 8.0: Common Table Expressions
MySQL 8.0: Common Table Expressions MySQL 8.0: Common Table Expressions
MySQL 8.0: Common Table Expressions
 
MySQL 8.0: What Is New in Optimizer and Executor?
MySQL 8.0: What Is New in Optimizer and Executor?MySQL 8.0: What Is New in Optimizer and Executor?
MySQL 8.0: What Is New in Optimizer and Executor?
 
MySQL Indexing : Improving Query Performance Using Index (Covering Index)
MySQL Indexing : Improving Query Performance Using Index (Covering Index)MySQL Indexing : Improving Query Performance Using Index (Covering Index)
MySQL Indexing : Improving Query Performance Using Index (Covering Index)
 
Oracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic FunctionsOracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic Functions
 

En vedette

Performance e Tunning - Boas práticas em desenvolvimento
Performance e Tunning - Boas práticas em desenvolvimentoPerformance e Tunning - Boas práticas em desenvolvimento
Performance e Tunning - Boas práticas em desenvolvimentoMarcelo Raposo
 
Apache Tajo: Query Optimization Techniques and JIT-based Vectorized Engine
Apache Tajo: Query Optimization Techniques and JIT-based Vectorized EngineApache Tajo: Query Optimization Techniques and JIT-based Vectorized Engine
Apache Tajo: Query Optimization Techniques and JIT-based Vectorized EngineDataWorks Summit
 
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ OracleUnderstanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ OracleGuatemala User Group
 
MySQL/MariaDB query optimizer tuning tutorial from Percona Live 2013
MySQL/MariaDB query optimizer tuning tutorial from Percona Live 2013MySQL/MariaDB query optimizer tuning tutorial from Percona Live 2013
MySQL/MariaDB query optimizer tuning tutorial from Percona Live 2013Sergey Petrunya
 
MySQL Query Optimization (Basics)
MySQL Query Optimization (Basics)MySQL Query Optimization (Basics)
MySQL Query Optimization (Basics)Karthik .P.R
 
Database , 8 Query Optimization
Database , 8 Query OptimizationDatabase , 8 Query Optimization
Database , 8 Query OptimizationAli Usman
 
SQL Joins and Query Optimization
SQL Joins and Query OptimizationSQL Joins and Query Optimization
SQL Joins and Query OptimizationBrian Gallagher
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index TuningManikanda kumar
 

En vedette (11)

Cost-Based query optimization
Cost-Based query optimizationCost-Based query optimization
Cost-Based query optimization
 
Performance e Tunning - Boas práticas em desenvolvimento
Performance e Tunning - Boas práticas em desenvolvimentoPerformance e Tunning - Boas práticas em desenvolvimento
Performance e Tunning - Boas práticas em desenvolvimento
 
Apache Tajo: Query Optimization Techniques and JIT-based Vectorized Engine
Apache Tajo: Query Optimization Techniques and JIT-based Vectorized EngineApache Tajo: Query Optimization Techniques and JIT-based Vectorized Engine
Apache Tajo: Query Optimization Techniques and JIT-based Vectorized Engine
 
Mysql Optimization
Mysql OptimizationMysql Optimization
Mysql Optimization
 
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ OracleUnderstanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
 
MySQL/MariaDB query optimizer tuning tutorial from Percona Live 2013
MySQL/MariaDB query optimizer tuning tutorial from Percona Live 2013MySQL/MariaDB query optimizer tuning tutorial from Percona Live 2013
MySQL/MariaDB query optimizer tuning tutorial from Percona Live 2013
 
MySQL Query Optimization (Basics)
MySQL Query Optimization (Basics)MySQL Query Optimization (Basics)
MySQL Query Optimization (Basics)
 
Database , 8 Query Optimization
Database , 8 Query OptimizationDatabase , 8 Query Optimization
Database , 8 Query Optimization
 
SQL Joins and Query Optimization
SQL Joins and Query OptimizationSQL Joins and Query Optimization
SQL Joins and Query Optimization
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index Tuning
 
Otimização MySQL
Otimização MySQLOtimização MySQL
Otimização MySQL
 

Similaire à MySQL Optimizer Overview

Sql Performance Tuning For Developers
Sql Performance Tuning For DevelopersSql Performance Tuning For Developers
Sql Performance Tuning For Developerssqlserver.co.il
 
Exadata and the Oracle Optimizer: The Untold Story
Exadata and the Oracle Optimizer: The Untold StoryExadata and the Oracle Optimizer: The Untold Story
Exadata and the Oracle Optimizer: The Untold StoryEnkitec
 
Hybrid system architecture overview
Hybrid system architecture overviewHybrid system architecture overview
Hybrid system architecture overviewJesse Wang
 
Improving Performance with Better Indexes
Improving Performance with Better IndexesImproving Performance with Better Indexes
Improving Performance with Better IndexesMYXPLAIN
 
Introduction of e-Journal Local Hosting and Services - Dr. Kwang Young Kim
Introduction of e-Journal Local Hosting and Services - Dr. Kwang Young KimIntroduction of e-Journal Local Hosting and Services - Dr. Kwang Young Kim
Introduction of e-Journal Local Hosting and Services - Dr. Kwang Young Kimtulipbiru64
 
Исмаил Сенгор Алтинговде «Проблемы эффективности поисковых систем»
Исмаил Сенгор Алтинговде «Проблемы эффективности поисковых систем»Исмаил Сенгор Алтинговде «Проблемы эффективности поисковых систем»
Исмаил Сенгор Алтинговде «Проблемы эффективности поисковых систем»Yandex
 
LECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptx
LECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptxLECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptx
LECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptxAthosBeatus
 
Solving performance problems in MySQL without denormalization
Solving performance problems in MySQL without denormalizationSolving performance problems in MySQL without denormalization
Solving performance problems in MySQL without denormalizationdmcfarlane
 
Akiban Technologies: Renormalize
Akiban Technologies: RenormalizeAkiban Technologies: Renormalize
Akiban Technologies: RenormalizeAriel Weil
 
Akiban Technologies: Renormalize
Akiban Technologies: RenormalizeAkiban Technologies: Renormalize
Akiban Technologies: RenormalizeAriel Weil
 
IT Discovery: Automated Global Assessment
IT Discovery: Automated Global AssessmentIT Discovery: Automated Global Assessment
IT Discovery: Automated Global AssessmentHaim Ben Zagmi
 
Emulex and the Evaluator Group Present Why I/O is Strategic for Big Data
Emulex and the Evaluator Group Present Why I/O is Strategic for Big Data Emulex and the Evaluator Group Present Why I/O is Strategic for Big Data
Emulex and the Evaluator Group Present Why I/O is Strategic for Big Data Emulex Corporation
 
(ATS4-PLAT05) Accelrys Catalog: A Search Index for AEP
(ATS4-PLAT05) Accelrys Catalog: A Search Index for AEP(ATS4-PLAT05) Accelrys Catalog: A Search Index for AEP
(ATS4-PLAT05) Accelrys Catalog: A Search Index for AEPBIOVIA
 
Mining single dimensional boolean association rules from transactional
Mining single dimensional boolean association rules from transactionalMining single dimensional boolean association rules from transactional
Mining single dimensional boolean association rules from transactionalramya marichamy
 
Discovering the Plan Cache (#SQLSat 206)
Discovering the Plan Cache (#SQLSat 206)Discovering the Plan Cache (#SQLSat 206)
Discovering the Plan Cache (#SQLSat 206)Jason Strate
 
It symposium 2011-ods821_data_replication_04-11-2011
It symposium 2011-ods821_data_replication_04-11-2011It symposium 2011-ods821_data_replication_04-11-2011
It symposium 2011-ods821_data_replication_04-11-2011Greg Turmel
 
Presentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cPresentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cRonald Francisco Vargas Quesada
 

Similaire à MySQL Optimizer Overview (20)

Sql Performance Tuning For Developers
Sql Performance Tuning For DevelopersSql Performance Tuning For Developers
Sql Performance Tuning For Developers
 
Exadata and the Oracle Optimizer: The Untold Story
Exadata and the Oracle Optimizer: The Untold StoryExadata and the Oracle Optimizer: The Untold Story
Exadata and the Oracle Optimizer: The Untold Story
 
Hybrid system architecture overview
Hybrid system architecture overviewHybrid system architecture overview
Hybrid system architecture overview
 
Improving Performance with Better Indexes
Improving Performance with Better IndexesImproving Performance with Better Indexes
Improving Performance with Better Indexes
 
Introduction of e-Journal Local Hosting and Services - Dr. Kwang Young Kim
Introduction of e-Journal Local Hosting and Services - Dr. Kwang Young KimIntroduction of e-Journal Local Hosting and Services - Dr. Kwang Young Kim
Introduction of e-Journal Local Hosting and Services - Dr. Kwang Young Kim
 
Исмаил Сенгор Алтинговде «Проблемы эффективности поисковых систем»
Исмаил Сенгор Алтинговде «Проблемы эффективности поисковых систем»Исмаил Сенгор Алтинговде «Проблемы эффективности поисковых систем»
Исмаил Сенгор Алтинговде «Проблемы эффективности поисковых систем»
 
LECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptx
LECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptxLECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptx
LECTURE_06_DATABASE PROCESSING & OPTIMAZATION.pptx
 
Solving performance problems in MySQL without denormalization
Solving performance problems in MySQL without denormalizationSolving performance problems in MySQL without denormalization
Solving performance problems in MySQL without denormalization
 
Akiban Technologies: Renormalize
Akiban Technologies: RenormalizeAkiban Technologies: Renormalize
Akiban Technologies: Renormalize
 
Akiban Technologies: Renormalize
Akiban Technologies: RenormalizeAkiban Technologies: Renormalize
Akiban Technologies: Renormalize
 
Gic2011 aula3-ingles
Gic2011 aula3-inglesGic2011 aula3-ingles
Gic2011 aula3-ingles
 
Gic2011 aula3-ingles
Gic2011 aula3-inglesGic2011 aula3-ingles
Gic2011 aula3-ingles
 
IT Discovery: Automated Global Assessment
IT Discovery: Automated Global AssessmentIT Discovery: Automated Global Assessment
IT Discovery: Automated Global Assessment
 
Emulex and the Evaluator Group Present Why I/O is Strategic for Big Data
Emulex and the Evaluator Group Present Why I/O is Strategic for Big Data Emulex and the Evaluator Group Present Why I/O is Strategic for Big Data
Emulex and the Evaluator Group Present Why I/O is Strategic for Big Data
 
(ATS4-PLAT05) Accelrys Catalog: A Search Index for AEP
(ATS4-PLAT05) Accelrys Catalog: A Search Index for AEP(ATS4-PLAT05) Accelrys Catalog: A Search Index for AEP
(ATS4-PLAT05) Accelrys Catalog: A Search Index for AEP
 
Mining single dimensional boolean association rules from transactional
Mining single dimensional boolean association rules from transactionalMining single dimensional boolean association rules from transactional
Mining single dimensional boolean association rules from transactional
 
Discovering the Plan Cache (#SQLSat 206)
Discovering the Plan Cache (#SQLSat 206)Discovering the Plan Cache (#SQLSat 206)
Discovering the Plan Cache (#SQLSat 206)
 
Tunning overview
Tunning overviewTunning overview
Tunning overview
 
It symposium 2011-ods821_data_replication_04-11-2011
It symposium 2011-ods821_data_replication_04-11-2011It symposium 2011-ods821_data_replication_04-11-2011
It symposium 2011-ods821_data_replication_04-11-2011
 
Presentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cPresentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12c
 

Plus de MYXPLAIN

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
 
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
 
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
 
Advanced query optimization
Advanced query optimizationAdvanced query optimization
Advanced query optimizationMYXPLAIN
 

Plus de MYXPLAIN (17)

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
 
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
 
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
 
Advanced query optimization
Advanced query optimizationAdvanced query optimization
Advanced query optimization
 

Dernier

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
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
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
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
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
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
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 
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
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
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
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
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
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
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
 

Dernier (20)

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
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
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
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
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
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
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
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
 
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
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
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
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
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
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 

MySQL Optimizer Overview

  • 1. 1 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 2. MySQL Optimizer Overview Olav Sandstå MySQL Optimizer Team 2 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 3. Program Agenda §  Introduction to MySQL optimizer §  Query transformations §  Selecting data access method §  Join optimizer §  Subquery optimizations 3 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 4. Query Optimizer What does the optimizer do? SELECT a, b JOIN FROM t1, t2, t3 WHERE t1.a = t2.b AND t2.b = t3.c Optimizer JOIN Table scan AND t2.d > 20 AND t2.d < 30; Range Ref t1 scan access t2 t3 Metadata: Statistics: -  Index information -  Table sizes -  Uniqueness -  Cardinality -  Nullability 4 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 5. MySQL Architecture SQL query Parser Preprocessor: Semantic check,name resolution Optimizer Logical transformations Cost-based optimizer: Join order and access methods Plan refinement Query execution plan Query result Query execution Storage Engine InnoDB MyISAM 5 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 6. MySQL Optimizer Characteristics §  Produce a query plan that uses least resources –  IO and CPU JOIN §  Optimizes a single query Table JOIN –  No inter-query optimizations scan §  Produces left-deep linear query execution plan Table t4 JOIN scan Range Ref t3 scan access t1 t2 6 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 7. Optimizer Overview Main phases: Negation elimination Logical Equality and constant propagation transformations Conversion of outer to inner joins Subquery transformations Evaluation of constant expressions Ref access analysis Prepare for Estimation of condition fanout cost-based Const table detection optimization Range analysis Cost-based Access method selection optimization JOIN optimizer Table condition pushdown Plan Access method adjustments refinement Sort avoidance Index condition pushdown 7 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 8. Logical Transformations 8 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 9. Logical Transformations §  Logical transformations of query conditions: –  Negation elimination –  Equality propagations –  Evaluate constant expressions –  Remove trivial conditions §  Conversion of outer to inner join §  Subquery transformations 9 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 10. Logical Transformations Example: SELECT * FROM t1, t2 WHERE t1.a = t2.a AND t2.a = 9 AND (NOT (t1.a > 10 OR t2.b > 3) OR (t1.b = t2.b + 7 AND t2.b = 5)); Negation elimination t1.a = t2.a AND t2.a = 9 AND (t1.a <= 10 AND t2.b <= 3 OR (t1.b = t2.b + 7 AND t2.b = 5)); Equality/const propagation t1.a = 9 AND t2.a = 9 AND (9 <= 10 AND t2.b <= 3 OR (t1.b = 5 + 7 AND t2.b = 5)); Evaluate const expressions t1.a = 9 AND t2.a = 9 AND (9 <= 10 AND t2.b <= 3 OR (t1.b = 12 AND t2.b = 5)); Trivial condition =TRUE removal t1.a = 9 AND t2.a = 9 AND (t2.b <= 3 OR (t1.b = 12 AND t2.b = 5)); 10 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 11. Cost-based Optimization 11 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 12. Cost-based Query Optimization JOIN General idea: §  Assign cost to operations JOIN Table scan §  Assign cost to partial or alternative plans Range Ref t3 §  Search for plan with lowest cost scan access t1 t2 §  Cost-based optimizations: Access method Join order Subquery strategy 12 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 13. Optimizer Cost Model The ”cost” for executing a query §  Cost unit: read of a random data page §  Main cost factors: –  IO cost: §  #pages read from table §  #pages read from index –  CPU cost: §  Cost for evaluating query conditions §  Cost for comparing keys/records 13 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 14. Input to Cost Model §  IO-cost: §  Statistics: –  Estimates from storage engine –  Number of records in table based on number of pages to –  Key distribution/Cardinality: read §  Average number of records –  Both index and data pages per key value §  Schema: §  Only for indexed columns –  Length of records and keys §  Maintained by storage engine –  Uniqueness for indexes –  Number of records in an index –  Nullability range 14 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 15. Cost Model Example SELECT * FROM t1 WHERE a BETWEEN 20 and 30; Table scan: §  IO-cost: #pages in table §  CPU cost: #records * ROW_EVALUATE_COST Range scan (on secondary index): §  IO-cost: #pages to read from index + #records_in_range §  CPU cost: #records_in_range * ROW_EVALUATE_COST 15 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 16. Selecting Access Method 16 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 17. Selecting Access Method Finding the optimal method to read data from storage engine §  For each table, find the best access method: Main access methods: §  Table scan §  1. Check if the access method is useful §  Index scan §  2. Estimate cost of using access method §  Ref access §  3. Select the cheapest to be used §  Range scan §  Index merge §  Choice of access method is cost based §  Loose index scan 17 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 18. Ref Access §  Read all records with a given key value using an index: §  Examples: SELECT * FROM t1 WHERE t1.key = 7; SELECT * FROM t1, t2 WHERE t1.key = t2.key; §  “eq_ref”: –  Reading from a unique index, max one record returned §  “ref”: –  Reading from a non-unique index or a prefix of an index, multiple records returned 18 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 19. Ref Access Analysis §  Determine which indexes that can be used for ref access in a join SELECT City.Name AS Capital, Language FROM CountryLanguage, Country, City WHERE City.CountryCode = Country.Code AND City.ID = Country.Capital AND CountryLanguage.Country = Country.Code CountryLanguage Country Country City Code CountryCode Capital ID 19 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 20. Range Optimizer §  Goal: find the “minimal” ranges for each index that needs to be read §  Example: SELECT * FROM t1 WHERE (key1 > 10 AND key1 < 20) AND key2 > 30 §  Range scan using INDEX(key1): 10 20 §  Range scan using INDEX(key2): 30 20 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 21. Range Optimizer, cont. §  Range optimizer selects the “useful” parts of the WHERE condition: –  Conditions comparing a column value with a constant: key > 3 key BETWEEN 4 AND 6 key IS NULL key = 4 key IN (10,12,..) key LIKE ”abc%” –  Nested AND/OR conditions are supported §  Result: list of disjoint ranges that need to be read from index: §  Cost estimate based on number of records in each range: –  Record estimate is found by asking the Storage Engine (“index dives”) 21 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 22. Range Access for Multi-part Index Example table with multi-part index §  Table: pk a b c §  INDEX idx(a, b, c); §  Logical storage layout of index: a 10 11 12 13 b 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 c 22 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 23. Range Access for Multi-part Index, cont §  Equality on 1st index part? –  Can add condition on 2nd index part in range condition §  Example: SELECT * from t1 WHERE a IN (10,11,13) AND (b=2 OR b=4) a 10 11 12 13 b 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 c §  Resulting range scan: 2 4 2 4 2 4 23 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 24. Range Access for Multi-part Index, cont §  Non-Equality on 1st index part: –  Can NOT add condition on 2nd index part in range condition §  Example: SELECT * from t1 WHERE a > 10 AND a < 13 AND (b=2 OR b=4) a 10 11 12 13 b 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 c §  Resulting range scan: a >10 AND a < 13 24 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 25. Index Merge §  Uses multiple indexes on the same table §  Implemented index merge strategies: –  Index Merge Union §  OR-ed conditions between different indexes –  Index Merge Intersect §  AND conditions between different indexes –  Index Merge Sort-Union §  OR-ed conditions where condition is a range 25 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 26. Index Merge Union §  Single index cannot handle ORed conditions on different columns §  Example: SELECT * FROM t1 WHERE a=10 OR b=10 §  Index Merge Union: INDEX(a) 10 INDEX(b) 10 Union Result: a=10 OR b=10 26 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 27. Loose Index Scan §  Optimization for GROUP BY and DISTINCT: SELECT a, b FROM t1 GROUP BY a, b; SELECT DISTINCT a, b FROM t1; SELECT a, MIN(b) FROM t1 GROUP BY a; §  GROUP BY/DISTINCT must be on the prefix of the index a 10 11 12 13 b 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 c 27 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 28. Join Optimizer 28 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 29. Join Optimizer ”Greedy search strategy” §  Goal: Given a JOIN of N tables, find the best JOIN ordering §  Strategy: –  Start with all 1-table plans t1 t2 t3 t4 –  Expand each plan with remaining tables §  Depth-first t2 t3 t4 –  If “cost of partial plan” > “cost of best plan”: t3 t4 t2 t4 t2 t3 §  “prune” plan t4 t3 t4 t2 t3 t2 29 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 30. JOIN Optimizer Illustrated SELECT City.Name, Language FROM Language, Country, City WHERE City.CountryCode = Country.Code AND City.ID = Country.Capital AND City.Population >= 1000000 AND Language.Country = Country.Code; start Language Country City cost=862 Country City Language City Language Country cost=1245 City Country City Language Country Language cost=26568 cost=32568 cost=627 30 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 31. Complexity and Cost of Join Optimizer Join of N tables: N! possible plans to evaluate Heuristics to reduce the number of plans to evaluate: §  Use optimizer_search_depth to limit the number of tables to consider §  Pre-sort tables on size and key dependency order (Improved in MySQL 5.6) §  When adding the next table to a partial plan, add all tables that it has an equality reference to (New in MySQL 5.6) 31 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 32. Plan Refinements 32 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 33. Finalizing Query Plan Main optimizations: §  Assigning conditions to tables –  Evaluate conditions as early as possible in join order §  ORDER BY optimization: avoid sorting –  Change to different index –  Read in descending order §  Change to a cheaper access method –  Example: Use range scan instead of table scan or ref access §  Index Condition Pushdown (New in MySQL 5.6) 33 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 34. Index Condition Pushdown New §  Pushes conditions that can be evaluated on the MySQL server index down to storage engine Query conditions –  Works only on indexed columns §  Goal: evaluate conditions without having to access the actual record –  Reduces number of disk/block accesses Index –  Reduces CPU usage Table data Storage engine §  Both conditions on a single index and conditions on earlier tables in a JOIN can be pushed down 34 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 35. Index Condition Pushdown How it works Without ICP: MySQL server With ICP: Optimizer Storage Engine: Storage Engine: 1. Reads index Execution 4. 1. Reads index and 2. Reads record evaluates pushed index 3. Returns record condition 3. 2. Reads record Server: 1. 3. Returns record Index 4. Evaluates condition 2. Table data Storage engine Server: 4. Evaluates rest of condition 35 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 36. Index Condition Pushdown Example CREATE TABLE person ( name VARCHAR(..), height INTEGER, postalcode INTEGER, age INTEGER, INDEX (postalcode, age) ); Evaluated by server SELECT name FROM person WHERE postalcode BETWEEN 5000 AND 5500 AND age BETWEEN 21 AND 22 AND height>180; Pushed to storage engine Evaluated on index entries 36 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 37. Subqueries 37 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 38. Overview of Subquery Optimizations Subquery category: Strategy: New §  IN (SELECT …) •  Semi-Join •  Materialization •  IN ➜ EXISTS §  NOT IN (SELECT …) §  FROM (SELECT …) •  Derived table §  <CompOp> ALL/ANY (SELECT ..) •  MAX/MIN re-write §  EXISTS/other •  Execute subquery 38 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 39. Optimization of IN subqueries New A. Semi-join Transformation 1.  Transform IN (and =ANY) subquery to semi-join: SELECT * FROM t1 WHERE query_where AND outer_expr IN (SELECT inner_expr FROM t2 WHERE cond2) SELECT * FROM t1 SEMIJOIN t2 ON outer_expr = inner_expr WHERE query_where AND cond2 2.  Apply transformations/strategies for avoiding/removing duplicates: Duplicate Table pullout Weedout First Match Semi-join LooseScan materialization 3.  Optimize using cost-based JOIN optimizer 39 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 40. Optimization of IN Subqueries, cont. New B. Subquery Materialization §  Only for non-correlated subqueries §  Execute subquery once –  store result in temporary table with unique index (removes duplicates) §  Outer query does lookup in temporary table Temporary SELECT title FROM film Index table Lookup WHERE film_id IN (SELECT film_id FROM actor WHERE name=“Bullock”) Materialize 40 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 41. Optimization of IN Subqueries, cont. C. IN è EXISTS transformation §  Convert IN subquery to EXISTS subquery by “push-down” IN-equality to subquery: SELECT title FROM film WHERE film_id IN (SELECT film_id FROM actor WHERE name=“Bullock”) SELECT title FROM film WHERE EXISTS (SELECT 1 FROM actor WHERE name=“Bullock” AND film.film_id = actor.film_id) §  Benefit: subquery will evaluate fewer records §  Note: special handling if pushed down expressions can be NULL 41 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 42. Query Execution Plan 42 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 43. Understanding the Query Plan EXPLAIN §  Use EXPLAIN to print the final query plan: EXPLAIN SELECT * FROM t1 JOIN t2 ON t1.a = t2.a WHERE b > 10 AND c > 10; +----+-------------+-------+-------+---------------+-----+---------+------+------+-----------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+-------+---------------+-----+---------+------+------+-----------------------+ | 1 | SIMPLE | t1 | range | PRIMARY,idx | idx | 4 | NULL | 12 | Using index condition | | 2 | SIMPLE | t2 | ref | key1 | key1| 4 | t1.a | 1 | NULL | +----+-------------+-------+-------+---------------+-----+---------+------+------+-----------------------+ §  Structured EXPLAIN (New in MySQL 5.6) –  JSON format –  Includes more information about query (eg. pushed index conditions) 43 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 44. Understanding the Query Plan Structured Explain Example: EXPLAIN FORMAT=JSON SELECT * FROM t1 WHERE b > 10 AND c > 10 AND d > 10; EXPLAIN { "query_block": { "select_id": 1, "table": { "table_name": "t1", "access_type": "range", "possible_keys": [ ”idx" ], "key": ”idx", "key_length": "4", "rows": 12, "filtered": 100, "index_condition": "((`test`.`t1`.`b` > 10) and (`test`.`t1`.`c` > 10))", "attached_condition": "(`test`.`t1`.`d` > 10)" } } } 44 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 45. Optimizer Traces "table": "`t1`", "range_analysis": { (New in MySQL 5.6) "table_scan": { "rows": 54, Understand HOW a query gets optimized }, "cost": 13.9 "best_covering_index_scan": { §  Tracing of the main steps and decisions "index": ”idx", "cost": 11.903, done by the optimizer "chosen": true }, "analyzing_range_alternatives": { "range_scan_alternatives": [ §  Example: { "index": ”idx", "ranges": [ "10 < a" SET optimizer_trace=”enabled=on”; ], SELECT * FROM t1 WHERE a > 10; "rowid_ordered": false, SELECT * FROM "using_mrr": false, "index_only": true, INFORMATION_SCHEMA.OPTIMIZER_TRACE; "rows": 12, "cost": 3.4314, "chosen": true } 45 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 46. Influencing the Optimizer When the optimizer does not do what you want: §  Add indexes §  Force use of specific indexes: –  USE INDEX, FORCE INDEX, IGNORE INDEX §  Force specific join order: –  STRAIGHT_JOIN §  Adjust optimizer_switch flags: –  set optimizer_switch=“index_merge=off” §  Ask question in the MySQL optimizer forum 46 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 47. Query Execution 47 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 48. Nested Loops Join Execution strategy for joins SELECT City.Name, Language FROM Language, Country, City WHERE ….. QEP: Execution: Result City Range scan Ref Table range access scan Language Country Index Index City Country ref access City table scan 48 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 49. Presentations by the MySQL Optimizer Team Sessions: §  Overview of New Optimizer Features in MySQL 5.6 §  Query Performance Comparison of MySQL 5.5 and MySQL 5.6 §  Powerful EXPLAIN in MySQL 5.6 BOF: §  Query Optimizations: What Is New and What Is Coming? 49 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 50. Summary §  Query transformations §  Selecting data access method §  Join optimizer §  Subquery optimizations §  Plan refinements Questions? 50 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.
  • 51. Graphic Section Divider 51 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.