SlideShare a Scribd company logo
1   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
Powerful EXPLAIN in
MySQL 5.6
Evgeny Potemkin
MySQL Optimizer team




2   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
Program Agenda


         Introduction
         Optimizer trace
         EXPLAIN in JSON format
         Explaining INSERT, UPDATE, DELETE




3   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
Graphic Section Divider




4   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
Optimizer Trace




5   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
Optimizer trace: quick start
mysql> SET optimizer_trace= “enabled=on“,
             end_markers_in_json=on;
mysql> SELECT * FROM orders WHERE customer_id <> 6;
mysql> SELECT trace FROM
   information_schema.OPTIMIZER_TRACE;
mysql> SET optimizer_trace="enabled=off";
    QUERY                                                                                                         SELECT * FROM orders WHERE customer_id <> 6
    TRACE                                                                                                          “steps”: [ { "join_preparation": { "select#": 1,… } … } …]
    MISSING_BYTES_BEYOND_MAX_MEM_SIZE                                                                              0
    INSUFFICIENT_PRIVILEGES                                                                                        0


6    Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
Optimizer trace: what’s inside
 Steps
         – Join preparation
                       Modifications to subquery
                       Expanded query
         – Join optimization
                       Range optimizer info
                       Plan generation process
                       Condition optimization
                       Processing of ORDER/GROUP BY
         – Join execution
                       Tmp tables related info
7   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
Optimizer trace: example
mysql> SET optimizer_trace="enabled=on";
mysql> SELECT * FROM t1,t2 WHERE f1=1 AND f1=f2 AND f2>0;
mysql> SELECT trace FROM information_schema.optimizer_trace;
mysql> SET optimizer_trace="enabled=off";




8   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
Optimizer trace: example
    join_optimization / steps / condition_processing
    "condition": "WHERE",
    "original_condition": "((`t1`.`f1` = 1) and (`t1`.`f1` = `t2`.`f2`) and (`t2`.`f2` > 0))",
    "steps": [
     {
         "transformation": "equality_propagation",
         "resulting_condition": "((`t2`.`f2` > 0) and multiple equal(1, `t1`.`f1`, `t2`.`f2`))"
     }, {
         "transformation": "constant_propagation",
         "resulting_condition": "((1 > 0) and multiple equal(1, `t1`.`f1`, `t2`.`f2`))"
     }, {
         "transformation": "trivial_condition_removal",
         "resulting_condition": "multiple equal(1, `t1`.`f1`, `t2`.`f2`)"
     }
    ] /* steps */


9    Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
Optimizer trace: example
     join_optimization / row_estimation / table : t1, range_analysis
     "table_scan": {                                                                                                             "analyzing_range_alternatives": {
      "rows": 5,                                                                                                                    "range_scan_alternatives": [ {
      "cost": 5.1085                                                                                                                      "index": "f1",
     } /* table_scan */,                                                                                                                  "ranges": [ "1 <= f1 <= 1“ ] /* ranges */,
     "potential_range_indices": [ {                                                                                                       "index_dives_for_eq_ranges": true,
        "index": "f1",                  "usable": true,                                                                                   "rows": 2, "cost": 3.41,
        "key_parts": [ "f1“ ] /* key_parts */ }                                                                                           "chosen": false,
     ] /* potential_range_indices */,                                                                                                     "cause": "cost"
     "best_covering_index_scan": {                                                                                                    }
      "index": "f1", "cost": 2.093, "chosen": true                                                                                  ] /* range_scan_alternatives */,
     } /* best_covering_index_scan */,                                                                                              "analyzing_roworder_intersect": {
     "group_index_range": {                                                                                                           "usable": false, "cause": "too_few_roworder_scans"
      "chosen": false, "cause": "not_single_table"                                                                                  } /* analyzing_roworder_intersect */
     } /* group_index_range */,                                                                                                  } /* analyzing_range_alternatives */


10    Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
Optimizer trace: example
     join_optimization / considered_execution_plan
     "plan_prefix": [ ] /* plan_prefix */,                                                                                        "plan_prefix": [ "`t2`“ ] /* plan_prefix */,
     "table": "`t2`",                                                                                                                 "table": "`t1`",
     "best_access_path": {                                                                                                            "best_access_path": {
      "considered_access_paths": [ {                                                                                                     "considered_access_paths": [ {
          "access_type": "scan", "rows": 3,                                                                                                      "access_type": "ref", "index": "f1",
          "cost": 2.6051, "chosen": true                                                                                                         "rows": 2, "cost": 3.4698, "chosen": true
      } ] /* considered_access_paths */                                                                                                    }, {
     } /* best_access_path */,                                                                                                                   "access_type": "scan", "using_join_cache": true,
     "cost_for_plan": 2.6051,                                                                                                                    "rows": 2, "cost": 3.8087,
     "rows_for_plan": 3,                                                                                                                         "chosen": true
     "rest_of_plan": [ {                                                                                                              } ] } /* best_access_path */,
     … next iteration … =>                                                                                                            "cost_for_plan": 6.4138,
     } ] /* rest_of_plan */                                                                                                           "rows_for_plan": 6,
                                                                                                                                      "chosen": true


11    Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
Optimizer trace: example
     join_optimization / plan refinement
     {                                                                                                                               {
            "attaching_conditions_to_tables": {                                                                                          "refine_plan": [
            "original_condition":                                                                                                         {
              "((`t1`.`f1` = 1) and (`t2`.`f2` = 1))",                                                                                        "table": "`t1`"
             "attached_conditions_summary": [ {                                                                                           },
                  "table": "`t1`", "attached": null                                                                                       {
              }, {                                                                                                                            "table": "`t2`",
                  "table": "`t2`", "attached": "(`t2`.`f2` = 1)"                                                                              "access_type": "table_scan"
              }                                                                                                                           }
            ] /* attached_conditions_summary */                                                                                          ] /* refine_plan */
         } /* attaching_conditions_to_tables */                                                                                      }
     },




12        Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
Optimizer trace: controls
  optimizer-trace
  optimizer-trace-features
          – greedy_search
          – range_optimizer
          – dynamic_range
          – repeated_subselect
  optimizer-trace-limit
  optimizer-trace-offset
  optimizer-trace-max-mem-size
  end-markers-in-json

13   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
Optimizer trace: exploring
  mysql> pager less
  SELECT TRACE INTO DUMPFILE <filename> FROM
   INFORMATION_SCHEMA.OPTIMIZER_TRACE;
  JSONView for Firefox
  Pretty JSON for Chrome
  A registry patch for IE




14   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAIN in JSON format




15   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
Traditional EXPLAIN
id select type table                                            type              possible                       key                             key len ref        rows   extra
                                                                                  keys
     1 PRIMARY                        cust                       index            cust_id,                        cust_name                      40      const      10    Using where; Start
                                                                                  cust_name                                                                               materialize; Scan
     1 PRIMARY                        orders                     ref              order_id                        order_id                       8       ordid      32    Using where; End
                                                                                                                                                                          materialize; Using join
                                                                                                                                                                          buffer (Block Nested
                                                                                                                                                                          Loop)
     1 PRIMARY                        <derived2> ref                               <auto_key0> <auto_key0>                                       23      vc1        100   Using index
     2 DERIVED                        flights    ALL                               NULL        NULL                                              NULL    NULL       10000 Using where; Start
                                                                                                                                                                          materialize; Scan
     2 DERIVED                        storage                    eq_ref            PRIMARY                        PRIMARY                        8       fl_store   1     Using where; End
                                                                                                                                                                          materialize; Using join
                                                                                                                                                                          buffer (Block Nested
                                                                                                                                                                          Loop)
     4 SUBQUERY buzz                                             range             buzzez                         buzzez                         11      NULL       42    Using index; Using
                                                                                                                                                                          where
     6 SUBQUERY shortage                                         index             shrt_idx                       shrt_idx                       100     NULL       243   Using index; Using
                                                                                                                                                                          where

16    Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
Traditional EXPLAIN: Cons
  Hard to read in complex cases
  Unclear/non-obvious query structure in complex cases
          – Could take quite some time to see what’s going on
  Limited information about query plan
          – How conditions are split? When a subquery is evaluated?
  Hard to impossible to extend
          – Indication of a feature being used usually is limited to “Using <something>”




17   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAIN in JSON: Basics
 mysql> EXPLAIN SELECT * FROM t1;
     id          select type                            table                   type            possible keys                               key     key len   ref    rows   extra
     1            SIMPLE                                 t1                     index           NULL                                         i      5         NULL   3      NULL




18       Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAIN in JSON: Basics
                                                                                                                                          EXPLAIN
                                                                                                                                                "query_block": {
                                                                                                                                                 "select_id": 1,
                                                                                                                                                 "table": {
                                                                                                                                                  "table_name": "t1",
 mysql> EXPLAIN FORMAT=JSON                                                                                                                       "access_type": "index",
 SELECT * FROM t1;                                                                                                                                "key": "i",
                                                                                                                                                  "key_length": "5",
                                                                                                                                                  "rows": 3,
                                                                                                                                                  "filtered": 100,
                                                                                                                                                  "using_index": true
                                                                                                                                                 } /* table */
                                                                                                                                                } /* query_block */




19   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAIN in JSON: Basics
 mysql> set end_markers_in_json = on;
     end_markers_in_json = off                                                                                                  end_markers_in_json = on
                                              }                                                                                                             } /* table */
                                          }                                                                                                               } /* query_block */
                                      }                                                                                                               }
                                  ]                                                                                                                 ] /* query_specifications */
                              }                                                                                                                    } /* union_result */
                          }                                                                                                                       } /* query_block */
                      }                                                                                                                          } /* materialized_from_subquery */
                  }                                                                                                                        } /* table */
              }                                                                                                                          } /* grouping_operation */
          }                                                                                                                           } /* ordering_operation */
      }                                                                                                                             } /* query_block */



20    Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAIN in JSON: Basics
 mysql> EXPLAIN SELECT * FROM t1 WHERE str IS NULL AND id > 0;
     id          select type                            table                   type             possible keys                               key     key len   ref     rows   extra
     1            SIMPLE                                 t1                     ref              str                                          str    11        const   1      Using index
                                                                                                                                                                              condition;
                                                                                                                                                                              Using where




21       Copyright © 2012, Oracle and/or its affiliates. All rights reserved.    Insert Information Protection Policy Classification from Slide 12
EXPLAIN in JSON: Basics
                                                                                                                                          EXPLAIN
                                                                                                                                            "query_block": {
                                                                                                                                                 "select_id": 1,
                                                                                                                                                 "table": {
                                                                                                                                                  "table_name": "t1",
 mysql> EXPLAIN FORMAT=JSON                                                                                                                       "access_type": "ref",
 SELECT * FROM t1 WHERE str IS                                                                                                                    "possible_keys": [ "str“ ],
                                                                                                                                                  "key": "str", "key_length": "11",
 NULL AND id > 0;
                                                                                                                                                  "ref": [ "const"],
                                                                                                                                                  "rows": 1, "filtered": 100,
                                                                                                                                                  "index_condition": "isnull(`test`.`t1`.`str`)“
                                                                                                                                                  "attached_condition": "(`test`.`t1`.`id` > 0)"
                                                                                                                                                 } /* table */
                                                                                                                                                } /* query_block */



22   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAIN in JSON: Basics
 mysql> EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a
 BETWEEN '0000-00-00' AND '1001-01-01';
                                                                                                                             possible                     key
     id          select type                      partitions                          table               type                                      key         ref    rows   extra
                                                                                                                             keys                         len
     1            SIMPLE                           pNULL,                             t1                  index              a                      a     4     NULL   6      Using where;
                                                   p0001-01-01,                                                                                                               Using index
                                                   p1001-01-01




23       Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAIN in JSON: Basics
                                                                                                                                          EXPLAIN
                                                                                                                                            "query_block": {
                                                                                                                                                "select_id": 1,
                                                                                                                                                "table": {
                                                                                                                                                 "table_name": "t1",
 mysql> EXPLAIN FORMAT=JSON                                                                                                                      "partitions": [ "pNULL", "p0001-01-01",
 SELECT * FROM t1 WHERE a                                                                                                                            "p1001-01-01"],
                                                                                                                                                 "access_type": "index",
 BETWEEN '0000-00-00' AND '1001-
                                                                                                                                                 "possible_keys": [ "a" ],
 01-01';                                                                                                                                         "key": "a", "key_length": "4",
                                                                                                                                                 "rows": 6, "filtered": 33.333,
                                                                                                                                                 "using_index": true,
                                                                                                                                                 "attached_condition": "(`test`.`t1`.`a` between
                                                                                                                                                     '0000-00-00' and '1001-01-01')"
                                                                                                                                                }}


24   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAIN in JSON: Basics
 mysql> EXPLAIN SELECT * FROM t1 JOIN t2 USING(i);
                                                                                              possible                                         key
     id          select type                          table                type                                           key                         ref    rows   extra
                                                                                              keys                                             len
     1            SIMPLE                               t2                  ALL                NULL                         NULL                NULL   NULL   3      NULL

     1            SIMPLE                               t1                  index              i                            i                   5      NULL   3      Using where; Using
                                                                                                                                                                    index; Using join
                                                                                                                                                                    buffer (Block Nested
                                                                                                                                                                    Loop)




25       Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAIN in JSON: Basics
     EXPLAIN
     {                                                                                                                               {
         "query_block": {                                                                                                                  "table": {
           "select_id": 1,                                                                                                                   "table_name": "t1",
           "nested_loop": [                                                                                                                  "access_type": "index",
             {                                                                                                                               "possible_keys": [ "i" ],
                 "table": {                                                                                                                  "key": "i", "key_length": "5",
                   "table_name": "t2",                                                                                                       "rows": 3, "filtered": 100,
                   "access_type": "ALL",                                                                                                     "using_index": true,
                   "rows": 3,                                                                                                                "using_join_buffer": "Block Nested Loop",
                   "filtered": 100                                                                                                           "attached_condition":
                 } /* table */                                                                                                                      "(`test`.`t1`.`i` = `test`.`t2`.`i`)"
             },                                                                                                                            } /* table */
            … next table … =>                                                                                                        }
         ] } /* nested_loop */ } /* query_block */


26       Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAIN in JSON: Basics
         MySQL Workbench 5.2




 SELECT * FROM t1 JOIN t2 USING(i);




27   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAIN in JSON: more complex queries
 mysql> EXPLAIN FORMAT=JSON SELECT t1.a, MIN(t2.b)
 FROM t1 LEFT JOIN t2 ON t1.a=t2.a GROUP BY t1.a ORDER BY t1.b;

     id         select type                       table              type             possible keys                         key                     key len          ref   rows   extra
     1           SIMPLE                            t1                 ALL             NULL                                   NULL                   NULL      NULL         3      Using temporary;
                                                                                                                                                                                  Using filesort
     1           SIMPLE                            t2                 ref             PRIMARY                                PRIMARY                4         test.t1.a    1      Using index




28       Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAIN in JSON: more complex queries
                                                                                                                                          EXPLAIN
                                                                                                                                            "query_block": {
 mysql> EXPLAIN FORMAT=JSON                                                                                                                      "select_id": 1,

 SELECT t1.a, MIN(t2.b)                                                                                                                          "ordering_operation": {
                                                                                                                                                  "using_temporary_table": true,
 FROM t1 LEFT JOIN t2                                                                                                                             "using_filesort": true,
                                                                                                                                                  "grouping_operation": {
  ON t1.a=t2.a
                                                                                                                                                    "using_filesort": true,
 GROUP BY t1.a ORDER BY t1.b;                                                                                                                       "nested_loop": [
                                                                                                                                                      { “table” : {…} },
                                                                                                                                                      { “table” : {…} } ] /* nested_loop */
                                                                                                                                                  } /* grouping_operation */
                                                                                                                                                 } /* ordering_operation */
                                                                                                                                                } /* query_block */



29   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAIN in JSON: more complex queries
         MySQL Workbench 5.2

 SELECT t1.a, MIN(t2.b)
 FROM t1 LEFT JOIN t2
  ON t1.a=t2.a
 GROUP BY t1.a ORDER BY t1.b;




30   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAIN in JSON: more complex queries
 mysql> EXPLAIN SELECT a, b FROM
 (SELECT 1 AS a, 2 AS b UNION ALL SELECT 1 AS a, 2 AS b) t1
 GROUP BY a ORDER BY b DESC;
                                                                                                          possible                                  key
     id                  select type                      table                         type                                       key                     ref    rows   extra
                                                                                                          keys                                      len
     1                   PRIMARY                          <derived2>                     ALL               NULL                     NULL            NULL   NULL   2      Using temporary;
                                                                                                                                                                         Using filesort
     2                   DERIVED                          NULL                           NULL              NULL                     NULL            NULL   NULL   NULL   No tables used
     3                   UNION                            NULL                           NULL              NULL                     NULL            NULL   NULL   NULL   No tables used
     NULL                UNION                            <union2,3>                     ALL               NULL                     NULL            NULL   NULL   NULL   Using temporary
                         RESULT




31       Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAIN in JSON: more complex queries
     EXPLAIN
     "query_block": {                                                                                                              "union_result": {
          "ordering_operation": {                                                                                                        "using_temporary_table": true,
          "using_filesort": true,                                                                                                        "table_name": "<union2,3>",
          "grouping_operation": {                                                                                                        "query_specifications": [ {
             "using_temporary_table": true,                                                                                                 "query_block": {
             "using_filesort": false,                                                                                                            "table": {
             "table": {                                                                                                                           "message": "No tables used"
                "table_name": "t1",                                                                                                               } } }, {
                "materialized_from_subquery": {                                                                                             "query_block": {
                  "using_temporary_table": true,                                                                                                 "table": {
                  "query_block": {                                                                                                                "message": "No tables used"
                     … here goes union_result… =>                                                                                                } } } ] } /* union_result */
                  }}}}}}



32    Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAIN in JSON: more complex queries
         MySQL Workbench 5.2


 SELECT a, b FROM
 (SELECT 1 AS a, 2 AS b UNION ALL
 SELECT 1 AS a, 2 AS b) t1
 GROUP BY a ORDER BY b DESC;




33   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAIN in JSON: subqueries
 mysql> EXPLAIN FORMAT=JSON SELECT derived.vc
 FROM (SELECT * FROM t1) AS derived WHERE
 derived.vc IN (SELECT t2.vc1 FROM t2 JOIN t3 ON t2.vc2=t3.vc);
               select                                                                       possible                                                 key
     id                                       table                             type                                          key                           ref      rows   extra
               type                                                                         keys                                                     len
     1          PRIMARY                        t2                               ALL          NULL                             NULL                   NULL   NULL     2      Using where;
                                                                                                                                                                            Start materialize;
                                                                                                                                                                            Scan
     1          PRIMARY                        t3                               ALL          NULL                             NULL                   NULL   NULL     3      Using where; End
                                                                                                                                                                            materialize; Using
                                                                                                                                                                            join buffer (Block
                                                                                                                                                                            Nested Loop)
     1          PRIMARY                        <derived2>                       ref          <auto_key0>                      <auto_key0>            23     t2.vc1   2      NULL
     2          DERIVED                        t1                               ALL          NULL                             NULL                   NULL   NULL     2      NULL


34       Copyright © 2012, Oracle and/or its affiliates. All rights reserved.    Insert Information Protection Policy Classification from Slide 12
EXPLAIN in JSON: subqueries
     EXPLAIN
     "query_block": {                                                                                                             "table": {
        "select_id": 1,                                                                                                                          "table_name": "derived",
        "nested_loop": [                                                                                                                         "materialized_from_subquery": {
          { "table": {                                                                                                                            "using_temporary_table": true,
                "table_name": "<subquery3>",                                                                                                      "query_block": {
                "materialized_from_subquery": {                                                                                                    "select_id": 2,
                "query_block": {                                                                                                                   "table": {
                     "nested_loop": [                                                                                                                  "table_name": "t1“,
                        { "table": { "table_name": "t2“ } },                                                                                           …
                        { "table": { "table_name": "t3“ } }                                                                                        }
                     ] } /* query_block */ } } /* table */                                                                                        } /* query_block */
          }, { … next table goes here … => }                                                                                                     } /* materialized_from_subquery */
        ] /* nested_loop */ } /* query_block */                                                                                              } /* table */



35    Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAIN in JSON: subqueries
         MySQL Workbench 5.2


 SELECT derived.vc
 FROM (SELECT * FROM t1) AS
 derived WHERE
 derived.vc IN (SELECT t2.vc1 FROM
 t2 JOIN t3 ON t2.vc2=t3.vc);




36   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAIN in JSON: subqueries
 mysql> EXPLAIN SELECT * FROM t1, t2 WHERE t2.a IN (SELECT a
 FROM t1 WHERE t1.b <> 30) AND t1.b=t2.a GROUP BY t1.a;
                select                                                            possible
     id                                        table            type                                        key            key len                  ref         rows    extra
                type                                                              keys
     1          SIMPLE                         t2               index             a                         a               5                       NULL        4       Using where; Using index;
                                                                                                                                                                        Using temporary; Using filesort
     1          SIMPLE                         t1               ref               a                         a               5                       test.t2.a   101     Using where; Using index; Start
                                                                                                                                                                        temporary; End temporary


     1          SIMPLE                         t1               index             NULL                      a               10                      NULL        10004   Using where; Using index;
                                                                                                                                                                        Using join buffer (Block Nested
                                                                                                                                                                        Loop)




37       Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAIN in JSON: subqueries
     EXPLAIN
     "query_block": {                                                                                                             {
        "select_id": 1,                                                                                                               "duplicates_removal": {
        "grouping_operation": {                                                                                                           "using_temporary_table": true,
          "using_temporary_table": true,                                                                                                  "table": {
          "nested_loop": [                                                                                                                   "table_name": "t1",
             {                                                                                                                               "attached_condition": "(`test`.`t1`.`b` <> 30)"
                 "table": {                                                                                                               } /* table */
                  "table_name": "t2",                                                                                                   } /* duplicates_removal */
                  "attached_condition": "(`test`.`t2`.`a` is not null)"                                                               }, {
                 } /* table */                                                                                                          "table": {
             },                                                                                                                           "table_name": "t1",
             … next 2 tables => …                                                                                                         "attached_condition": "(`test`.`t1`.`b` = `test`.`t2`.`a`)"
          ] /* nested_loop */ } /* grouping_operation */                                                                                  } /* table */
     } /* query_block */                                                                                                              }


38    Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAIN in JSON: subqueries
         MySQL Workbench 5.2



 SELECT * FROM t1, t2 WHERE t2.a
 IN (SELECT a FROM t1 WHERE t1.b
 <> 30) AND t1.b=t2.a GROUP BY t1.a;




39   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAIN in JSON: subqueries
     EXPLAIN
     "query_block": {                                                                                                              "query_block": {
        "select_id": 1,                                                                                                               "select_id": 1,
        "nested_loop": [                                                                                                              "nested_loop": [
          {                                                                                                                              {
              "table": {                                                                                                                     "table": {
                "table_name": "t2",                                                                                                              "table_name": "t1",
              } /* table */                                                                                                                      "access_type": "range", "loosescan": true,
          }, {                                                                                                                               } /* table */
              "table": {                                                                                                                 }, {
                "table_name": "t1",                                                                                                          "table": {
                "first_match": "t2",                                                                                                             "table_name": "t2",
                "attached_condition": "(`test`.`t1`.`b` <> 30)"                                                                              } /* table */
              } /* table */                                                                                                              }
     } ] /* nested_loop */ } /* query_block */                                                                                        ] /* nested_loop */ } /* query_block */


40    Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAIN
         for non-select queries




41   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAINing non-select queries
  INSERT/REPLACE and INSERT/REPLACE SELECT
  Single- and multi-table UPDATE
  Single- and multi-table DELETE




42   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAINing non-select queries
 mysql> EXPLAIN UPDATE t1 SET a = 10 WHERE a < 10;
     id          select type                            table                   type            possible keys                               key     key len   ref    rows   extra
     1            SIMPLE                                 t1                     range           a,a_2                                        a      5         NULL   2      Using where;
                                                                                                                                                                            Using
                                                                                                                                                                            temporary




43       Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAINing non-select queries
                                                                                                                                          EXPLAIN
                                                                                                                                            "query_block": {
                                                                                                                                                 "select_id": 1,
                                                                                                                                                 "table": {
                                                                                                                                                  "update": true,
 mysql> EXPLAIN FORMAT=JSON                                                                                                                       "table_name": "t1",
                                                                                                                                                  "access_type": "range",
 UPDATE t1 SET a = 10 WHERE
                                                                                                                                                  "possible_keys": [ "a", "a_2" ],
 a < 10;                                                                                                                                          "key": "a", "key_length": "5",
                                                                                                                                                  "rows": 2, "filtered": 100,
                                                                                                                                                  "using_temporary_table": "for update",
                                                                                                                                                  "attached_condition": "(`test`.`t1`.`a` < 10)"
                                                                                                                                                 } /* table */
                                                                                                                                                } /* query_block */



44   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAINing non-select queries
                                                                                                                                          EXPLAIN
                                                                                                                                            "query_block": {
                                                                                                                                                 "select_id": 1,
                                                                                                                                                 "table": {
                                                                                                                                                  "delete": true,
 mysql> EXPLAIN FORMAT=JSON                                                                                                                       "table_name": "t1",
                                                                                                                                                  "access_type": "range",
 DELETE FROM t1 WHERE a < 10;
                                                                                                                                                  "possible_keys": [ "a", "a_2“ ],
                                                                                                                                                  "key": "a", "key_length": "5",
                                                                                                                                                  "rows": 2, "filtered": 100,
                                                                                                                                                  "attached_condition": "(`test`.`t1`.`a` < 10)"
                                                                                                                                                 } /* table */
                                                                                                                                                } /* query_block */




45   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAINing non-select queries
 mysql> EXPLAIN UPDATE t1 t11, (SELECT * FROM t2) t12 SET t11.a =10
 WHERE t11.a = 1;
                select                                                                         possible
     id                                        table                            type                                      key                key len   ref     rows   extra
                type                                                                           keys
     1          PRIMARY                        t11                              ref             a,a_2                      a                  5        const   1      NULL

     1          PRIMARY                        <derived2>                       ALL             NULL                       NULL               NULL     NULL    3      Using join buffer (Block
                                                                                                                                                                      Nested Loop)
     2          DERIVED                        t2                               ALL             NULL                       NULL               NULL     NULL    3      NULL




46       Copyright © 2012, Oracle and/or its affiliates. All rights reserved.    Insert Information Protection Policy Classification from Slide 12
EXPLAINing non-select queries
     EXPLAIN
      "query_block": {                                                                                                                   {
        "select_id": 1,                                                                                                                      "table": {
        "nested_loop": [ {                                                                                                                       "table_name": "t12",
             "table": {                                                                                                                          "access_type": "ALL",
                "update": true,                                                                                                                  "rows": 3, "filtered": 100,
                "table_name": "t11",                                                                                                             "using_join_buffer": "Block Nested Loop",
                "access_type": "ref",                                                                                                            "materialized_from_subquery": {
                "possible_keys": [ "a", "a_2“ ],                                                                                                  "using_temporary_table": true,
                "key": "a", "key_length": "5",                                                                                                    "query_block": {
                "ref": ["const"] /* ref */,                                                                                                        "select_id": 2,
                "rows": 1, "filtered": 100                                                                                                         "table": { … } /* table */
             } /* table */ },                                                                                                                     } /* query_block */
          … here goes                  2nd    table…=>                                                                                           } /* materialized_from_subquery */
        ] /* nested_loop */ } /* query_block */                                                                                              } /* table */ }


47    Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAINing non-select queries
 mysql> EXPLAIN UPDATE t1 SET a = 10 WHERE a IN
 (SELECT a FROM t2);
     id                  select type                         table              type              possible keys                         key         key len          ref   rows   extra
     1                   PRIMARY                              t1                ALL                a,a_2                                 NULL       NULL      NULL         3      NULL

     1                   DEPENDENT                            t2                ALL                NULL                                  NULL       NULL      NULL         3      Using where
                         SUBQUERY




48       Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
EXPLAINing non-select queries
     EXPLAIN
     "query_block": {                                                                                                              [{
        "select_id": 1,                                                                                                                          "dependent": true, "cacheable": false,
        "table": {                                                                                                                               "query_block": {
          "update": true,                                                                                                                         "select_id": 2,
          "table_name": "t1",                                                                                                                     "table": {
          "possible_keys": [ "a", "a_2“ ],                                                                                                         "table_name": "t2",
          "attached_condition":                                                                                                                    "access_type": "ALL",
             "<in_optimizer>(`test`.`t1`.`a`,                                                                                                      "rows": 3, "filtered": 100,
              <exists>(select 1 from `test`.`t2` where                                                                                             "attached_condition":
                                (<cache>(`test`.`t1`.`a`) =                                                                                          "(<cache>(`test`.`t1`.`a`) = `test`.`t2`.`b`)"
                                  `test`.`t1`.`a`)))",                                                                                            } /* table */
            "attached_subqueries": [ … => …]                                                                                                     } /* query_block */
         } /* table */                                                                                                                  }]
      } /* query_block */


49    Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12
50   Copyright © 2012, Oracle and/or its affiliates. All rights reserved.   Insert Information Protection Policy Classification from Slide 12

More Related Content

What's hot

Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007paulguerin
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index TuningManikanda kumar
 
Best sql plsql material
Best sql plsql materialBest sql plsql material
Best sql plsql material
pitchaiah yechuri
 
Troubleshooting MySQL Performance add-ons
Troubleshooting MySQL Performance add-onsTroubleshooting MySQL Performance add-ons
Troubleshooting MySQL Performance add-ons
Sveta Smirnova
 
Understanding Query Execution
Understanding Query ExecutionUnderstanding Query Execution
Understanding Query Executionwebhostingguy
 
56 Query Optimization
56 Query Optimization56 Query Optimization
56 Query OptimizationMYXPLAIN
 
Nested Queries Lecture
Nested Queries LectureNested Queries Lecture
Nested Queries Lecture
Felipe Costa
 
Database development coding standards
Database development coding standardsDatabase development coding standards
Database development coding standardsAlessandro Baratella
 
Lab1 select statement
Lab1 select statementLab1 select statement
Lab1 select statement
Balqees Al.Mubarak
 
View & index in SQL
View & index in SQLView & index in SQL
View & index in SQL
Swapnali Pawar
 
MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Replication Evolution -- Confoo Montreal 2017MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Replication Evolution -- Confoo Montreal 2017
Dave Stokes
 
SQLAlchemy Core: An Introduction
SQLAlchemy Core: An IntroductionSQLAlchemy Core: An Introduction
SQLAlchemy Core: An Introduction
Jason Myers
 
Optimizing Queries with Explain
Optimizing Queries with ExplainOptimizing Queries with Explain
Optimizing Queries with ExplainMYXPLAIN
 
An introduction to SQLAlchemy
An introduction to SQLAlchemyAn introduction to SQLAlchemy
An introduction to SQLAlchemy
mengukagan
 
DBMS lab manual
DBMS lab manualDBMS lab manual
DBMS lab manualmaha tce
 
PL/SQL User-Defined Functions in the Read World
PL/SQL User-Defined Functions in the Read WorldPL/SQL User-Defined Functions in the Read World
PL/SQL User-Defined Functions in the Read World
Michael Rosenblum
 
Recursive Query Throwdown
Recursive Query ThrowdownRecursive Query Throwdown
Recursive Query Throwdown
Karwin Software Solutions LLC
 

What's hot (19)

Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007
 
MySQL Query And Index Tuning
MySQL Query And Index TuningMySQL Query And Index Tuning
MySQL Query And Index Tuning
 
Best sql plsql material
Best sql plsql materialBest sql plsql material
Best sql plsql material
 
Troubleshooting MySQL Performance add-ons
Troubleshooting MySQL Performance add-onsTroubleshooting MySQL Performance add-ons
Troubleshooting MySQL Performance add-ons
 
Understanding Query Execution
Understanding Query ExecutionUnderstanding Query Execution
Understanding Query Execution
 
56 Query Optimization
56 Query Optimization56 Query Optimization
56 Query Optimization
 
Nested Queries Lecture
Nested Queries LectureNested Queries Lecture
Nested Queries Lecture
 
Database development coding standards
Database development coding standardsDatabase development coding standards
Database development coding standards
 
Mysql cheatsheet
Mysql cheatsheetMysql cheatsheet
Mysql cheatsheet
 
Lab1 select statement
Lab1 select statementLab1 select statement
Lab1 select statement
 
View & index in SQL
View & index in SQLView & index in SQL
View & index in SQL
 
Php 26
Php 26Php 26
Php 26
 
MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Replication Evolution -- Confoo Montreal 2017MySQL Replication Evolution -- Confoo Montreal 2017
MySQL Replication Evolution -- Confoo Montreal 2017
 
SQLAlchemy Core: An Introduction
SQLAlchemy Core: An IntroductionSQLAlchemy Core: An Introduction
SQLAlchemy Core: An Introduction
 
Optimizing Queries with Explain
Optimizing Queries with ExplainOptimizing Queries with Explain
Optimizing Queries with Explain
 
An introduction to SQLAlchemy
An introduction to SQLAlchemyAn introduction to SQLAlchemy
An introduction to SQLAlchemy
 
DBMS lab manual
DBMS lab manualDBMS lab manual
DBMS lab manual
 
PL/SQL User-Defined Functions in the Read World
PL/SQL User-Defined Functions in the Read WorldPL/SQL User-Defined Functions in the Read World
PL/SQL User-Defined Functions in the Read World
 
Recursive Query Throwdown
Recursive Query ThrowdownRecursive Query Throwdown
Recursive Query Throwdown
 

Viewers also liked

Inno db internals innodb file formats and source code structure
Inno db internals innodb file formats and source code structureInno db internals innodb file formats and source code structure
Inno db internals innodb file formats and source code structure
zhaolinjnu
 
The nightmare of locking, blocking and isolation levels!
The nightmare of locking, blocking and isolation levels!The nightmare of locking, blocking and isolation levels!
The nightmare of locking, blocking and isolation levels!
Boris Hristov
 
MySQL 5.7: Focus on InnoDB
MySQL 5.7: Focus on InnoDBMySQL 5.7: Focus on InnoDB
MySQL 5.7: Focus on InnoDB
Mario Beck
 
Mvcc Unmasked (Bruce Momjian)
Mvcc Unmasked (Bruce Momjian)Mvcc Unmasked (Bruce Momjian)
Mvcc Unmasked (Bruce Momjian)Ontico
 
Mysql For Developers
Mysql For DevelopersMysql For Developers
Mysql For Developers
Carol McDonald
 
The Power of MySQL Explain
The Power of MySQL ExplainThe Power of MySQL Explain
The Power of MySQL ExplainMYXPLAIN
 
Mv unmasked.w.code.march.2013
Mv unmasked.w.code.march.2013Mv unmasked.w.code.march.2013
Mv unmasked.w.code.march.2013EDB
 
Como migrar una base de datos de mysql a power designer
Como migrar una base de datos de mysql a power designerComo migrar una base de datos de mysql a power designer
Como migrar una base de datos de mysql a power designer
Alex Bernal
 
Explain
ExplainExplain
A brief introduction to PostgreSQL
A brief introduction to PostgreSQLA brief introduction to PostgreSQL
A brief introduction to PostgreSQL
Vu Hung Nguyen
 
Postgres MVCC - A Developer Centric View of Multi Version Concurrency Control
Postgres MVCC - A Developer Centric View of Multi Version Concurrency ControlPostgres MVCC - A Developer Centric View of Multi Version Concurrency Control
Postgres MVCC - A Developer Centric View of Multi Version Concurrency Control
Reactive.IO
 
InnoDB Internal
InnoDB InternalInnoDB Internal
InnoDB Internal
mysqlops
 
MySQL EXPLAIN Explained-Norvald H. Ryeng
MySQL EXPLAIN Explained-Norvald H. RyengMySQL EXPLAIN Explained-Norvald H. Ryeng
MySQL EXPLAIN Explained-Norvald H. Ryeng
郁萍 王
 
SQL Transactions - What they are good for and how they work
SQL Transactions - What they are good for and how they workSQL Transactions - What they are good for and how they work
SQL Transactions - What they are good for and how they work
Markus Winand
 
Best practices for MySQL High Availability
Best practices for MySQL High AvailabilityBest practices for MySQL High Availability
Best practices for MySQL High Availability
Colin Charles
 
Introduction to MySQL
Introduction to MySQLIntroduction to MySQL
Introduction to MySQL
Giuseppe Maxia
 
MySQL High Availability Solutions - Feb 2015 webinar
MySQL High Availability Solutions - Feb 2015 webinarMySQL High Availability Solutions - Feb 2015 webinar
MySQL High Availability Solutions - Feb 2015 webinar
Andrew Morgan
 
Introduction to Mysql
Introduction to MysqlIntroduction to Mysql
Introduction to Mysql
Tushar Chauhan
 
i.materialise
i.materialisei.materialise
i.materialise
i.materialise
 
Kenneth Smith Resume 2015
Kenneth Smith Resume 2015Kenneth Smith Resume 2015
Kenneth Smith Resume 2015Kenneth Smith
 

Viewers also liked (20)

Inno db internals innodb file formats and source code structure
Inno db internals innodb file formats and source code structureInno db internals innodb file formats and source code structure
Inno db internals innodb file formats and source code structure
 
The nightmare of locking, blocking and isolation levels!
The nightmare of locking, blocking and isolation levels!The nightmare of locking, blocking and isolation levels!
The nightmare of locking, blocking and isolation levels!
 
MySQL 5.7: Focus on InnoDB
MySQL 5.7: Focus on InnoDBMySQL 5.7: Focus on InnoDB
MySQL 5.7: Focus on InnoDB
 
Mvcc Unmasked (Bruce Momjian)
Mvcc Unmasked (Bruce Momjian)Mvcc Unmasked (Bruce Momjian)
Mvcc Unmasked (Bruce Momjian)
 
Mysql For Developers
Mysql For DevelopersMysql For Developers
Mysql For Developers
 
The Power of MySQL Explain
The Power of MySQL ExplainThe Power of MySQL Explain
The Power of MySQL Explain
 
Mv unmasked.w.code.march.2013
Mv unmasked.w.code.march.2013Mv unmasked.w.code.march.2013
Mv unmasked.w.code.march.2013
 
Como migrar una base de datos de mysql a power designer
Como migrar una base de datos de mysql a power designerComo migrar una base de datos de mysql a power designer
Como migrar una base de datos de mysql a power designer
 
Explain
ExplainExplain
Explain
 
A brief introduction to PostgreSQL
A brief introduction to PostgreSQLA brief introduction to PostgreSQL
A brief introduction to PostgreSQL
 
Postgres MVCC - A Developer Centric View of Multi Version Concurrency Control
Postgres MVCC - A Developer Centric View of Multi Version Concurrency ControlPostgres MVCC - A Developer Centric View of Multi Version Concurrency Control
Postgres MVCC - A Developer Centric View of Multi Version Concurrency Control
 
InnoDB Internal
InnoDB InternalInnoDB Internal
InnoDB Internal
 
MySQL EXPLAIN Explained-Norvald H. Ryeng
MySQL EXPLAIN Explained-Norvald H. RyengMySQL EXPLAIN Explained-Norvald H. Ryeng
MySQL EXPLAIN Explained-Norvald H. Ryeng
 
SQL Transactions - What they are good for and how they work
SQL Transactions - What they are good for and how they workSQL Transactions - What they are good for and how they work
SQL Transactions - What they are good for and how they work
 
Best practices for MySQL High Availability
Best practices for MySQL High AvailabilityBest practices for MySQL High Availability
Best practices for MySQL High Availability
 
Introduction to MySQL
Introduction to MySQLIntroduction to MySQL
Introduction to MySQL
 
MySQL High Availability Solutions - Feb 2015 webinar
MySQL High Availability Solutions - Feb 2015 webinarMySQL High Availability Solutions - Feb 2015 webinar
MySQL High Availability Solutions - Feb 2015 webinar
 
Introduction to Mysql
Introduction to MysqlIntroduction to Mysql
Introduction to Mysql
 
i.materialise
i.materialisei.materialise
i.materialise
 
Kenneth Smith Resume 2015
Kenneth Smith Resume 2015Kenneth Smith Resume 2015
Kenneth Smith Resume 2015
 

Similar to Powerful Explain in MySQL 5.6

Mastering Spring Boot's Actuator with Madhura Bhave
Mastering Spring Boot's Actuator with Madhura BhaveMastering Spring Boot's Actuator with Madhura Bhave
Mastering Spring Boot's Actuator with Madhura Bhave
VMware Tanzu
 
MongoDB and RDBMS
MongoDB and RDBMSMongoDB and RDBMS
MongoDB and RDBMS
francescapasha
 
Es part 2 pdf no build
Es part 2 pdf no buildEs part 2 pdf no build
Es part 2 pdf no buildErik Rose
 
JSON array indexes in MySQL
JSON array indexes in MySQLJSON array indexes in MySQL
JSON array indexes in MySQL
Dag H. Wanvik
 
Couchbase N1QL: Index Advisor
Couchbase N1QL: Index AdvisorCouchbase N1QL: Index Advisor
Couchbase N1QL: Index Advisor
Keshav Murthy
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance TuningMongoDB
 
Specs2
Specs2Specs2
Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013
Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013
Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013
Amazon Web Services
 
Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)
Postman
 
Services Drupalcamp Stockholm 2009
Services Drupalcamp Stockholm 2009Services Drupalcamp Stockholm 2009
Services Drupalcamp Stockholm 2009
hugowetterberg
 
ELK Stack - Turn boring logfiles into sexy dashboard
ELK Stack - Turn boring logfiles into sexy dashboardELK Stack - Turn boring logfiles into sexy dashboard
ELK Stack - Turn boring logfiles into sexy dashboard
Georg Sorst
 
Full-Text Search Explained - Philipp Krenn - Codemotion Rome 2017
Full-Text Search Explained - Philipp Krenn - Codemotion Rome 2017Full-Text Search Explained - Philipp Krenn - Codemotion Rome 2017
Full-Text Search Explained - Philipp Krenn - Codemotion Rome 2017
Codemotion
 
Creating Alloy Widgets
Creating Alloy WidgetsCreating Alloy Widgets
Creating Alloy Widgets
Mobile Data Systems Ltd.
 
Integrating SAP the Java EE Way - JBoss One Day talk 2012
Integrating SAP the Java EE Way - JBoss One Day talk 2012Integrating SAP the Java EE Way - JBoss One Day talk 2012
Integrating SAP the Java EE Way - JBoss One Day talk 2012
hwilming
 
Optimizer Trace Walkthrough
Optimizer Trace WalkthroughOptimizer Trace Walkthrough
Optimizer Trace Walkthrough
Sergey Petrunya
 
Using Spark to Load Oracle Data into Cassandra (Jim Hatcher, IHS Markit) | C*...
Using Spark to Load Oracle Data into Cassandra (Jim Hatcher, IHS Markit) | C*...Using Spark to Load Oracle Data into Cassandra (Jim Hatcher, IHS Markit) | C*...
Using Spark to Load Oracle Data into Cassandra (Jim Hatcher, IHS Markit) | C*...
DataStax
 
Using Spark to Load Oracle Data into Cassandra
Using Spark to Load Oracle Data into CassandraUsing Spark to Load Oracle Data into Cassandra
Using Spark to Load Oracle Data into Cassandra
Jim Hatcher
 
Mug17 gurgaon
Mug17 gurgaonMug17 gurgaon
Mug17 gurgaon
Ankur Raina
 
Service discovery and configuration provisioning
Service discovery and configuration provisioningService discovery and configuration provisioning
Service discovery and configuration provisioning
Source Ministry
 
First Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven DevelopmentFirst Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven Development
Nuvole
 

Similar to Powerful Explain in MySQL 5.6 (20)

Mastering Spring Boot's Actuator with Madhura Bhave
Mastering Spring Boot's Actuator with Madhura BhaveMastering Spring Boot's Actuator with Madhura Bhave
Mastering Spring Boot's Actuator with Madhura Bhave
 
MongoDB and RDBMS
MongoDB and RDBMSMongoDB and RDBMS
MongoDB and RDBMS
 
Es part 2 pdf no build
Es part 2 pdf no buildEs part 2 pdf no build
Es part 2 pdf no build
 
JSON array indexes in MySQL
JSON array indexes in MySQLJSON array indexes in MySQL
JSON array indexes in MySQL
 
Couchbase N1QL: Index Advisor
Couchbase N1QL: Index AdvisorCouchbase N1QL: Index Advisor
Couchbase N1QL: Index Advisor
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance Tuning
 
Specs2
Specs2Specs2
Specs2
 
Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013
Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013
Zero to Sixty: AWS CloudFormation (DMG201) | AWS re:Invent 2013
 
Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)Postman Collection Format v2.0 (pre-draft)
Postman Collection Format v2.0 (pre-draft)
 
Services Drupalcamp Stockholm 2009
Services Drupalcamp Stockholm 2009Services Drupalcamp Stockholm 2009
Services Drupalcamp Stockholm 2009
 
ELK Stack - Turn boring logfiles into sexy dashboard
ELK Stack - Turn boring logfiles into sexy dashboardELK Stack - Turn boring logfiles into sexy dashboard
ELK Stack - Turn boring logfiles into sexy dashboard
 
Full-Text Search Explained - Philipp Krenn - Codemotion Rome 2017
Full-Text Search Explained - Philipp Krenn - Codemotion Rome 2017Full-Text Search Explained - Philipp Krenn - Codemotion Rome 2017
Full-Text Search Explained - Philipp Krenn - Codemotion Rome 2017
 
Creating Alloy Widgets
Creating Alloy WidgetsCreating Alloy Widgets
Creating Alloy Widgets
 
Integrating SAP the Java EE Way - JBoss One Day talk 2012
Integrating SAP the Java EE Way - JBoss One Day talk 2012Integrating SAP the Java EE Way - JBoss One Day talk 2012
Integrating SAP the Java EE Way - JBoss One Day talk 2012
 
Optimizer Trace Walkthrough
Optimizer Trace WalkthroughOptimizer Trace Walkthrough
Optimizer Trace Walkthrough
 
Using Spark to Load Oracle Data into Cassandra (Jim Hatcher, IHS Markit) | C*...
Using Spark to Load Oracle Data into Cassandra (Jim Hatcher, IHS Markit) | C*...Using Spark to Load Oracle Data into Cassandra (Jim Hatcher, IHS Markit) | C*...
Using Spark to Load Oracle Data into Cassandra (Jim Hatcher, IHS Markit) | C*...
 
Using Spark to Load Oracle Data into Cassandra
Using Spark to Load Oracle Data into CassandraUsing Spark to Load Oracle Data into Cassandra
Using Spark to Load Oracle Data into Cassandra
 
Mug17 gurgaon
Mug17 gurgaonMug17 gurgaon
Mug17 gurgaon
 
Service discovery and configuration provisioning
Service discovery and configuration provisioningService discovery and configuration provisioning
Service discovery and configuration provisioning
 
First Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven DevelopmentFirst Steps in Drupal Code Driven Development
First Steps in Drupal Code Driven Development
 

More from 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 Tricks
MYXPLAIN
 
Need for Speed: MySQL Indexing
Need for Speed: MySQL IndexingNeed for Speed: MySQL Indexing
Need for Speed: MySQL Indexing
MYXPLAIN
 
Advanced Query Optimizer Tuning and Analysis
Advanced Query Optimizer Tuning and AnalysisAdvanced Query Optimizer Tuning and Analysis
Advanced Query Optimizer Tuning and Analysis
MYXPLAIN
 
MySQL Index Cookbook
MySQL Index CookbookMySQL Index Cookbook
MySQL Index Cookbook
MYXPLAIN
 
Advanced MySQL Query and Schema Tuning
Advanced MySQL Query and Schema TuningAdvanced MySQL Query and Schema Tuning
Advanced MySQL Query and Schema Tuning
MYXPLAIN
 
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
 
Tools and Techniques for Index Design
Tools and Techniques for Index DesignTools and Techniques for Index Design
Tools and Techniques for Index DesignMYXPLAIN
 
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
 

More from MYXPLAIN (14)

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
 
Tools and Techniques for Index Design
Tools and Techniques for Index DesignTools and Techniques for Index Design
Tools and Techniques for Index Design
 
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
 

Recently uploaded

FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 

Powerful Explain in MySQL 5.6

  • 1. 1 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 2. Powerful EXPLAIN in MySQL 5.6 Evgeny Potemkin MySQL Optimizer team 2 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 3. Program Agenda  Introduction  Optimizer trace  EXPLAIN in JSON format  Explaining INSERT, UPDATE, DELETE 3 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 4. Graphic Section Divider 4 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 5. Optimizer Trace 5 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 6. Optimizer trace: quick start mysql> SET optimizer_trace= “enabled=on“, end_markers_in_json=on; mysql> SELECT * FROM orders WHERE customer_id <> 6; mysql> SELECT trace FROM information_schema.OPTIMIZER_TRACE; mysql> SET optimizer_trace="enabled=off"; QUERY SELECT * FROM orders WHERE customer_id <> 6 TRACE “steps”: [ { "join_preparation": { "select#": 1,… } … } …] MISSING_BYTES_BEYOND_MAX_MEM_SIZE 0 INSUFFICIENT_PRIVILEGES 0 6 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 7. Optimizer trace: what’s inside  Steps – Join preparation  Modifications to subquery  Expanded query – Join optimization  Range optimizer info  Plan generation process  Condition optimization  Processing of ORDER/GROUP BY – Join execution  Tmp tables related info 7 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 8. Optimizer trace: example mysql> SET optimizer_trace="enabled=on"; mysql> SELECT * FROM t1,t2 WHERE f1=1 AND f1=f2 AND f2>0; mysql> SELECT trace FROM information_schema.optimizer_trace; mysql> SET optimizer_trace="enabled=off"; 8 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 9. Optimizer trace: example join_optimization / steps / condition_processing "condition": "WHERE", "original_condition": "((`t1`.`f1` = 1) and (`t1`.`f1` = `t2`.`f2`) and (`t2`.`f2` > 0))", "steps": [ { "transformation": "equality_propagation", "resulting_condition": "((`t2`.`f2` > 0) and multiple equal(1, `t1`.`f1`, `t2`.`f2`))" }, { "transformation": "constant_propagation", "resulting_condition": "((1 > 0) and multiple equal(1, `t1`.`f1`, `t2`.`f2`))" }, { "transformation": "trivial_condition_removal", "resulting_condition": "multiple equal(1, `t1`.`f1`, `t2`.`f2`)" } ] /* steps */ 9 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 10. Optimizer trace: example join_optimization / row_estimation / table : t1, range_analysis "table_scan": { "analyzing_range_alternatives": { "rows": 5, "range_scan_alternatives": [ { "cost": 5.1085 "index": "f1", } /* table_scan */, "ranges": [ "1 <= f1 <= 1“ ] /* ranges */, "potential_range_indices": [ { "index_dives_for_eq_ranges": true, "index": "f1", "usable": true, "rows": 2, "cost": 3.41, "key_parts": [ "f1“ ] /* key_parts */ } "chosen": false, ] /* potential_range_indices */, "cause": "cost" "best_covering_index_scan": { } "index": "f1", "cost": 2.093, "chosen": true ] /* range_scan_alternatives */, } /* best_covering_index_scan */, "analyzing_roworder_intersect": { "group_index_range": { "usable": false, "cause": "too_few_roworder_scans" "chosen": false, "cause": "not_single_table" } /* analyzing_roworder_intersect */ } /* group_index_range */, } /* analyzing_range_alternatives */ 10 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 11. Optimizer trace: example join_optimization / considered_execution_plan "plan_prefix": [ ] /* plan_prefix */, "plan_prefix": [ "`t2`“ ] /* plan_prefix */, "table": "`t2`", "table": "`t1`", "best_access_path": { "best_access_path": { "considered_access_paths": [ { "considered_access_paths": [ { "access_type": "scan", "rows": 3, "access_type": "ref", "index": "f1", "cost": 2.6051, "chosen": true "rows": 2, "cost": 3.4698, "chosen": true } ] /* considered_access_paths */ }, { } /* best_access_path */, "access_type": "scan", "using_join_cache": true, "cost_for_plan": 2.6051, "rows": 2, "cost": 3.8087, "rows_for_plan": 3, "chosen": true "rest_of_plan": [ { } ] } /* best_access_path */, … next iteration … => "cost_for_plan": 6.4138, } ] /* rest_of_plan */ "rows_for_plan": 6, "chosen": true 11 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 12. Optimizer trace: example join_optimization / plan refinement { { "attaching_conditions_to_tables": { "refine_plan": [ "original_condition": { "((`t1`.`f1` = 1) and (`t2`.`f2` = 1))", "table": "`t1`" "attached_conditions_summary": [ { }, "table": "`t1`", "attached": null { }, { "table": "`t2`", "table": "`t2`", "attached": "(`t2`.`f2` = 1)" "access_type": "table_scan" } } ] /* attached_conditions_summary */ ] /* refine_plan */ } /* attaching_conditions_to_tables */ } }, 12 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 13. Optimizer trace: controls  optimizer-trace  optimizer-trace-features – greedy_search – range_optimizer – dynamic_range – repeated_subselect  optimizer-trace-limit  optimizer-trace-offset  optimizer-trace-max-mem-size  end-markers-in-json 13 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 14. Optimizer trace: exploring  mysql> pager less  SELECT TRACE INTO DUMPFILE <filename> FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE;  JSONView for Firefox  Pretty JSON for Chrome  A registry patch for IE 14 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 15. EXPLAIN in JSON format 15 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 16. Traditional EXPLAIN id select type table type possible key key len ref rows extra keys 1 PRIMARY cust index cust_id, cust_name 40 const 10 Using where; Start cust_name materialize; Scan 1 PRIMARY orders ref order_id order_id 8 ordid 32 Using where; End materialize; Using join buffer (Block Nested Loop) 1 PRIMARY <derived2> ref <auto_key0> <auto_key0> 23 vc1 100 Using index 2 DERIVED flights ALL NULL NULL NULL NULL 10000 Using where; Start materialize; Scan 2 DERIVED storage eq_ref PRIMARY PRIMARY 8 fl_store 1 Using where; End materialize; Using join buffer (Block Nested Loop) 4 SUBQUERY buzz range buzzez buzzez 11 NULL 42 Using index; Using where 6 SUBQUERY shortage index shrt_idx shrt_idx 100 NULL 243 Using index; Using where 16 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 17. Traditional EXPLAIN: Cons  Hard to read in complex cases  Unclear/non-obvious query structure in complex cases – Could take quite some time to see what’s going on  Limited information about query plan – How conditions are split? When a subquery is evaluated?  Hard to impossible to extend – Indication of a feature being used usually is limited to “Using <something>” 17 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 18. EXPLAIN in JSON: Basics mysql> EXPLAIN SELECT * FROM t1; id select type table type possible keys key key len ref rows extra 1 SIMPLE t1 index NULL i 5 NULL 3 NULL 18 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 19. EXPLAIN in JSON: Basics EXPLAIN "query_block": { "select_id": 1, "table": { "table_name": "t1", mysql> EXPLAIN FORMAT=JSON "access_type": "index", SELECT * FROM t1; "key": "i", "key_length": "5", "rows": 3, "filtered": 100, "using_index": true } /* table */ } /* query_block */ 19 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 20. EXPLAIN in JSON: Basics mysql> set end_markers_in_json = on; end_markers_in_json = off end_markers_in_json = on } } /* table */ } } /* query_block */ } } ] ] /* query_specifications */ } } /* union_result */ } } /* query_block */ } } /* materialized_from_subquery */ } } /* table */ } } /* grouping_operation */ } } /* ordering_operation */ } } /* query_block */ 20 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 21. EXPLAIN in JSON: Basics mysql> EXPLAIN SELECT * FROM t1 WHERE str IS NULL AND id > 0; id select type table type possible keys key key len ref rows extra 1 SIMPLE t1 ref str str 11 const 1 Using index condition; Using where 21 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 22. EXPLAIN in JSON: Basics EXPLAIN "query_block": { "select_id": 1, "table": { "table_name": "t1", mysql> EXPLAIN FORMAT=JSON "access_type": "ref", SELECT * FROM t1 WHERE str IS "possible_keys": [ "str“ ], "key": "str", "key_length": "11", NULL AND id > 0; "ref": [ "const"], "rows": 1, "filtered": 100, "index_condition": "isnull(`test`.`t1`.`str`)“ "attached_condition": "(`test`.`t1`.`id` > 0)" } /* table */ } /* query_block */ 22 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 23. EXPLAIN in JSON: Basics mysql> EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a BETWEEN '0000-00-00' AND '1001-01-01'; possible key id select type partitions table type key ref rows extra keys len 1 SIMPLE pNULL, t1 index a a 4 NULL 6 Using where; p0001-01-01, Using index p1001-01-01 23 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 24. EXPLAIN in JSON: Basics EXPLAIN "query_block": { "select_id": 1, "table": { "table_name": "t1", mysql> EXPLAIN FORMAT=JSON "partitions": [ "pNULL", "p0001-01-01", SELECT * FROM t1 WHERE a "p1001-01-01"], "access_type": "index", BETWEEN '0000-00-00' AND '1001- "possible_keys": [ "a" ], 01-01'; "key": "a", "key_length": "4", "rows": 6, "filtered": 33.333, "using_index": true, "attached_condition": "(`test`.`t1`.`a` between '0000-00-00' and '1001-01-01')" }} 24 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 25. EXPLAIN in JSON: Basics mysql> EXPLAIN SELECT * FROM t1 JOIN t2 USING(i); possible key id select type table type key ref rows extra keys len 1 SIMPLE t2 ALL NULL NULL NULL NULL 3 NULL 1 SIMPLE t1 index i i 5 NULL 3 Using where; Using index; Using join buffer (Block Nested Loop) 25 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 26. EXPLAIN in JSON: Basics EXPLAIN { { "query_block": { "table": { "select_id": 1, "table_name": "t1", "nested_loop": [ "access_type": "index", { "possible_keys": [ "i" ], "table": { "key": "i", "key_length": "5", "table_name": "t2", "rows": 3, "filtered": 100, "access_type": "ALL", "using_index": true, "rows": 3, "using_join_buffer": "Block Nested Loop", "filtered": 100 "attached_condition": } /* table */ "(`test`.`t1`.`i` = `test`.`t2`.`i`)" }, } /* table */ … next table … => } ] } /* nested_loop */ } /* query_block */ 26 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 27. EXPLAIN in JSON: Basics MySQL Workbench 5.2 SELECT * FROM t1 JOIN t2 USING(i); 27 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 28. EXPLAIN in JSON: more complex queries mysql> EXPLAIN FORMAT=JSON SELECT t1.a, MIN(t2.b) FROM t1 LEFT JOIN t2 ON t1.a=t2.a GROUP BY t1.a ORDER BY t1.b; id select type table type possible keys key key len ref rows extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using temporary; Using filesort 1 SIMPLE t2 ref PRIMARY PRIMARY 4 test.t1.a 1 Using index 28 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 29. EXPLAIN in JSON: more complex queries EXPLAIN "query_block": { mysql> EXPLAIN FORMAT=JSON "select_id": 1, SELECT t1.a, MIN(t2.b) "ordering_operation": { "using_temporary_table": true, FROM t1 LEFT JOIN t2 "using_filesort": true, "grouping_operation": { ON t1.a=t2.a "using_filesort": true, GROUP BY t1.a ORDER BY t1.b; "nested_loop": [ { “table” : {…} }, { “table” : {…} } ] /* nested_loop */ } /* grouping_operation */ } /* ordering_operation */ } /* query_block */ 29 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 30. EXPLAIN in JSON: more complex queries MySQL Workbench 5.2 SELECT t1.a, MIN(t2.b) FROM t1 LEFT JOIN t2 ON t1.a=t2.a GROUP BY t1.a ORDER BY t1.b; 30 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 31. EXPLAIN in JSON: more complex queries mysql> EXPLAIN SELECT a, b FROM (SELECT 1 AS a, 2 AS b UNION ALL SELECT 1 AS a, 2 AS b) t1 GROUP BY a ORDER BY b DESC; possible key id select type table type key ref rows extra keys len 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 Using temporary; Using filesort 2 DERIVED NULL NULL NULL NULL NULL NULL NULL No tables used 3 UNION NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION <union2,3> ALL NULL NULL NULL NULL NULL Using temporary RESULT 31 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 32. EXPLAIN in JSON: more complex queries EXPLAIN "query_block": { "union_result": { "ordering_operation": { "using_temporary_table": true, "using_filesort": true, "table_name": "<union2,3>", "grouping_operation": { "query_specifications": [ { "using_temporary_table": true, "query_block": { "using_filesort": false, "table": { "table": { "message": "No tables used" "table_name": "t1", } } }, { "materialized_from_subquery": { "query_block": { "using_temporary_table": true, "table": { "query_block": { "message": "No tables used" … here goes union_result… => } } } ] } /* union_result */ }}}}}} 32 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 33. EXPLAIN in JSON: more complex queries MySQL Workbench 5.2 SELECT a, b FROM (SELECT 1 AS a, 2 AS b UNION ALL SELECT 1 AS a, 2 AS b) t1 GROUP BY a ORDER BY b DESC; 33 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 34. EXPLAIN in JSON: subqueries mysql> EXPLAIN FORMAT=JSON SELECT derived.vc FROM (SELECT * FROM t1) AS derived WHERE derived.vc IN (SELECT t2.vc1 FROM t2 JOIN t3 ON t2.vc2=t3.vc); select possible key id table type key ref rows extra type keys len 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Start materialize; Scan 1 PRIMARY t3 ALL NULL NULL NULL NULL 3 Using where; End materialize; Using join buffer (Block Nested Loop) 1 PRIMARY <derived2> ref <auto_key0> <auto_key0> 23 t2.vc1 2 NULL 2 DERIVED t1 ALL NULL NULL NULL NULL 2 NULL 34 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 35. EXPLAIN in JSON: subqueries EXPLAIN "query_block": { "table": { "select_id": 1, "table_name": "derived", "nested_loop": [ "materialized_from_subquery": { { "table": { "using_temporary_table": true, "table_name": "<subquery3>", "query_block": { "materialized_from_subquery": { "select_id": 2, "query_block": { "table": { "nested_loop": [ "table_name": "t1“, { "table": { "table_name": "t2“ } }, … { "table": { "table_name": "t3“ } } } ] } /* query_block */ } } /* table */ } /* query_block */ }, { … next table goes here … => } } /* materialized_from_subquery */ ] /* nested_loop */ } /* query_block */ } /* table */ 35 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 36. EXPLAIN in JSON: subqueries MySQL Workbench 5.2 SELECT derived.vc FROM (SELECT * FROM t1) AS derived WHERE derived.vc IN (SELECT t2.vc1 FROM t2 JOIN t3 ON t2.vc2=t3.vc); 36 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 37. EXPLAIN in JSON: subqueries mysql> EXPLAIN SELECT * FROM t1, t2 WHERE t2.a IN (SELECT a FROM t1 WHERE t1.b <> 30) AND t1.b=t2.a GROUP BY t1.a; select possible id table type key key len ref rows extra type keys 1 SIMPLE t2 index a a 5 NULL 4 Using where; Using index; Using temporary; Using filesort 1 SIMPLE t1 ref a a 5 test.t2.a 101 Using where; Using index; Start temporary; End temporary 1 SIMPLE t1 index NULL a 10 NULL 10004 Using where; Using index; Using join buffer (Block Nested Loop) 37 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 38. EXPLAIN in JSON: subqueries EXPLAIN "query_block": { { "select_id": 1, "duplicates_removal": { "grouping_operation": { "using_temporary_table": true, "using_temporary_table": true, "table": { "nested_loop": [ "table_name": "t1", { "attached_condition": "(`test`.`t1`.`b` <> 30)" "table": { } /* table */ "table_name": "t2", } /* duplicates_removal */ "attached_condition": "(`test`.`t2`.`a` is not null)" }, { } /* table */ "table": { }, "table_name": "t1", … next 2 tables => … "attached_condition": "(`test`.`t1`.`b` = `test`.`t2`.`a`)" ] /* nested_loop */ } /* grouping_operation */ } /* table */ } /* query_block */ } 38 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 39. EXPLAIN in JSON: subqueries MySQL Workbench 5.2 SELECT * FROM t1, t2 WHERE t2.a IN (SELECT a FROM t1 WHERE t1.b <> 30) AND t1.b=t2.a GROUP BY t1.a; 39 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 40. EXPLAIN in JSON: subqueries EXPLAIN "query_block": { "query_block": { "select_id": 1, "select_id": 1, "nested_loop": [ "nested_loop": [ { { "table": { "table": { "table_name": "t2", "table_name": "t1", } /* table */ "access_type": "range", "loosescan": true, }, { } /* table */ "table": { }, { "table_name": "t1", "table": { "first_match": "t2", "table_name": "t2", "attached_condition": "(`test`.`t1`.`b` <> 30)" } /* table */ } /* table */ } } ] /* nested_loop */ } /* query_block */ ] /* nested_loop */ } /* query_block */ 40 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 41. EXPLAIN for non-select queries 41 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 42. EXPLAINing non-select queries  INSERT/REPLACE and INSERT/REPLACE SELECT  Single- and multi-table UPDATE  Single- and multi-table DELETE 42 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 43. EXPLAINing non-select queries mysql> EXPLAIN UPDATE t1 SET a = 10 WHERE a < 10; id select type table type possible keys key key len ref rows extra 1 SIMPLE t1 range a,a_2 a 5 NULL 2 Using where; Using temporary 43 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 44. EXPLAINing non-select queries EXPLAIN "query_block": { "select_id": 1, "table": { "update": true, mysql> EXPLAIN FORMAT=JSON "table_name": "t1", "access_type": "range", UPDATE t1 SET a = 10 WHERE "possible_keys": [ "a", "a_2" ], a < 10; "key": "a", "key_length": "5", "rows": 2, "filtered": 100, "using_temporary_table": "for update", "attached_condition": "(`test`.`t1`.`a` < 10)" } /* table */ } /* query_block */ 44 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 45. EXPLAINing non-select queries EXPLAIN "query_block": { "select_id": 1, "table": { "delete": true, mysql> EXPLAIN FORMAT=JSON "table_name": "t1", "access_type": "range", DELETE FROM t1 WHERE a < 10; "possible_keys": [ "a", "a_2“ ], "key": "a", "key_length": "5", "rows": 2, "filtered": 100, "attached_condition": "(`test`.`t1`.`a` < 10)" } /* table */ } /* query_block */ 45 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 46. EXPLAINing non-select queries mysql> EXPLAIN UPDATE t1 t11, (SELECT * FROM t2) t12 SET t11.a =10 WHERE t11.a = 1; select possible id table type key key len ref rows extra type keys 1 PRIMARY t11 ref a,a_2 a 5 const 1 NULL 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 Using join buffer (Block Nested Loop) 2 DERIVED t2 ALL NULL NULL NULL NULL 3 NULL 46 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 47. EXPLAINing non-select queries EXPLAIN "query_block": { { "select_id": 1, "table": { "nested_loop": [ { "table_name": "t12", "table": { "access_type": "ALL", "update": true, "rows": 3, "filtered": 100, "table_name": "t11", "using_join_buffer": "Block Nested Loop", "access_type": "ref", "materialized_from_subquery": { "possible_keys": [ "a", "a_2“ ], "using_temporary_table": true, "key": "a", "key_length": "5", "query_block": { "ref": ["const"] /* ref */, "select_id": 2, "rows": 1, "filtered": 100 "table": { … } /* table */ } /* table */ }, } /* query_block */ … here goes 2nd table…=> } /* materialized_from_subquery */ ] /* nested_loop */ } /* query_block */ } /* table */ } 47 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 48. EXPLAINing non-select queries mysql> EXPLAIN UPDATE t1 SET a = 10 WHERE a IN (SELECT a FROM t2); id select type table type possible keys key key len ref rows extra 1 PRIMARY t1 ALL a,a_2 NULL NULL NULL 3 NULL 1 DEPENDENT t2 ALL NULL NULL NULL NULL 3 Using where SUBQUERY 48 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 49. EXPLAINing non-select queries EXPLAIN "query_block": { [{ "select_id": 1, "dependent": true, "cacheable": false, "table": { "query_block": { "update": true, "select_id": 2, "table_name": "t1", "table": { "possible_keys": [ "a", "a_2“ ], "table_name": "t2", "attached_condition": "access_type": "ALL", "<in_optimizer>(`test`.`t1`.`a`, "rows": 3, "filtered": 100, <exists>(select 1 from `test`.`t2` where "attached_condition": (<cache>(`test`.`t1`.`a`) = "(<cache>(`test`.`t1`.`a`) = `test`.`t2`.`b`)" `test`.`t1`.`a`)))", } /* table */ "attached_subqueries": [ … => …] } /* query_block */ } /* table */ }] } /* query_block */ 49 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12
  • 50. 50 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12