When and How to Take Advantage of New Optimizer Features in MySQL 5.6. Øystein Grøvlen Senior Principal Software Engineer, MySQL Oracle

Similar documents
Optimizer Standof. MySQL 5.6 vs MariaDB 5.5. Peter Zaitsev, Ovais Tariq Percona Inc April 18, 2012

Histogram Support in MySQL 8.0

TPC-H Benchmark Set. TPC-H Benchmark. DDL for TPC-H datasets

How to Analyze and Tune MySQL Queries for Better Performance

State of MariaDB. Igor Babaev Notice: MySQL is a registered trademark of Sun Microsystems, Inc.

MySQL Query Tuning 101. Sveta Smirnova, Alexander Rubin April, 16, 2015

High Volume In-Memory Data Unification

Technical Report - Distributed Database Victor FERNANDES - Université de Strasbourg /2000 TECHNICAL REPORT

Covering indexes. Stéphane Combaudon - SQLI

Comparison of Database Cloud Services

MySQL 8.0: Common Table Expressions

MySQL 8.0 What s New in the Optimizer

Tired of MySQL Making You Wait? Alexander Rubin, Principal Consultant, Percona Janis Griffin, Database Evangelist, SolarWinds

Query Optimization Percona, Inc. 1 / 74

Optimizing Queries with EXPLAIN

Indexes - What You Need to Know

Challenges in Query Optimization. Doug Inkster, Ingres Corp.

On-Disk Bitmap Index Performance in Bizgres 0.9

Orri Erling (Program Manager, OpenLink Virtuoso), Ivan Mikhailov (Lead Developer, OpenLink Virtuoso).

Midterm Review. March 27, 2017

CSC317/MCS9317. Database Performance Tuning. Class test

MySQL 5.6: Advantages in a Nutshell. Peter Zaitsev, CEO, Percona Percona Technical Webinars March 6, 2013

Practical MySQL indexing guidelines

Schema Tuning. Tuning Schemas : Overview

PostgreSQL to MySQL A DBA's Perspective. Patrick

1Z MySQL 5 Database Administrator Certified Professional Exam, Part II Exam.

<Insert Picture Here> Looking at Performance - What s new in MySQL Workbench 6.2

Comparison of Database Cloud Services

Avoiding Sorting and Grouping In Processing Queries

Whitepaper. Big Data implementation: Role of Memory and SSD in Microsoft SQL Server Environment

MySQL Performance Tuning

What is MariaDB 5.5? w: e: Daniel Bartholomew Oct 2012

How to Stop Hating MySQL: Fixing Common Mistakes and Myths

How to Analyze and Tune MySQL Queries for Better Performance

MySQL Indexing. Best Practices for MySQL 5.6. Peter Zaitsev CEO, Percona MySQL Connect Sep 22, 2013 San Francisco,CA

Tuning Relational Systems I

6.830 Problem Set 2 (2017)

Oracle Database In-Memory By Example

How to Analyze and Tune MySQL Queries for Better Performance

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

vsql: Verifying Arbitrary SQL Queries over Dynamic Outsourced Databases

How to Analyze and Tune MySQL Queries for Better Performance

Advanced MySQL Query Tuning

Troubleshooting Slow Queries. Sveta Smirnova Principal Support Engineer April, 28, 2016

Advanced MySQL Query Tuning

Querying Data with Transact SQL

Writing High Performance SQL Statements. Tim Sharp July 14, 2014

Copyright 2017, Oracle and/or its aff iliates. All rights reserved.

<Insert Picture Here> Boosting performance with MySQL partitions

Mastering the art of indexing

SQL QUERY EVALUATION. CS121: Relational Databases Fall 2017 Lecture 12

Vectorized Postgres (VOPS extension) Konstantin Knizhnik Postgres Professional

Parallelism Strategies In The DB2 Optimizer

Beyond EXPLAIN. Query Optimization From Theory To Code. Yuto Hayamizu Ryoji Kawamichi. 2016/5/20 PGCon Ottawa

Query Optimization, part 2: query plans in practice

GPU-Accelerated Analytics on your Data Lake.

Infrastructure at your Service. In-Memory-Pläne für den 12.2-Optimizer: Teuer oder billig?

Towards Comprehensive Testing Tools

MySQL Performance Optimization

The MariaDB/MySQL Query Executor In-depth. Presented by: Timour Katchaounov Optimizer team: Igor Babaev, Sergey Petrunia, Timour Katchaounov

DATABASE PERFORMANCE AND INDEXES. CS121: Relational Databases Fall 2017 Lecture 11

Oracle 1Z MySQL 5.6 Database Administrator. Download Full Version :

MySQL 5.7: What s New in the Optimizer?

Explaining the MySQL EXPLAIN

[Some of] New Query Optimizer features in MariaDB Sergei Petrunia MariaDB Shenzhen Meetup November 2017

<Insert Picture Here> Upcoming Changes in MySQL 5.7 Morgan Tocker, MySQL Community Manager

Part 1: IoT demo Part 2: MySQL, JSON and Flexible storage

Multiple query optimization in middleware using query teamwork

What's New in MySQL 5.7?

Lazy Maintenance of Materialized Views

Benchmark TPC-H 100.

Using MySQL, Hadoop and Spark for Data Analysis

WL#2474. refinements to Multi Range Read interface. Sergey Petrunia The World s Most Popular Open Source Database

MySQL Indexing. Best Practices. Peter Zaitsev, CEO Percona Inc August 15, 2012

<Insert Picture Here> MySQL Cluster What are we working on

Query Evaluation Overview, cont.

Efficiency Analysis of the access method with the cascading Bloom filter to the data warehouse on the parallel computing platform

After completing this course, participants will be able to:

Two-Phase Optimization for Selecting Materialized Views in a Data Warehouse

Efficient in-memory query execution using JIT compiling. Han-Gyu Park

InnoDB: What s new in 8.0

COURSE OUTLINE MOC 20461: QUERYING MICROSOFT SQL SERVER 2014

Meet the Sergei Golubchik MariaDB Corporation

Major Features: Postgres 9.5

InnoDB: Status, Architecture, and Latest Enhancements

T-SQL Training: T-SQL for SQL Server for Developers

Advanced query optimization techniques on large queries. Peter Boros Percona Webinar

Lecture 19 Query Processing Part 1

Oracle 11g Partitioning new features and ILM

Advanced Database Systems

External Sorting. Chapter 13. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1

MySQL Database Scalability

MySQL InnoDB Cluster. MySQL HA Made Easy! Miguel Araújo Senior Software Developer MySQL Middleware and Clients. FOSDEM 18 - February 04, 2018

Optimizing Queries Using Materialized Views

The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into

OKC MySQL Users Group

20461: Querying Microsoft SQL Server 2014 Databases

Tools and Techniques for Index Design. Bill Karwin, Percona Inc.

Copyright 2013, Oracle and/or its affiliates. All rights reserved.

Finding the Pitfalls in Query Performance

Transcription:

When and How to Take Advantage of New Optimizer Features in MySQL 5.6 Øystein Grøvlen Senior Principal Software Engineer, MySQL Oracle

Program Agenda Improvements for disk-bound queries Subquery improvements Index condition pushdown Misc. optimizer improvements 2

MySQL 5.6: Improvements for Disk-Bound Queries Main idea: Sort keys retrieved from index before accessing table Benefits: Read more rows from a page while it is still in buffer pool Increased benefits from prefetching pages into the buffer pool Sequential instead of random disk access? Range scan: Disk Sweep Multi-Range Read (DS-MRR) Index lookup (Ref access): Batched Key Access 3

MySQL 5.5: Data Access without DS-MRR Index Random access Table Index scan 4

MySQL 5.6: Data Access with DS-MRR InnoDB Example Index Collect PKs in buffer Sweepread rows Table Index scan Sort PKs in index order PKs in PK order 5

MySQL 5.5 vs MySQL 5.6: DBT-3 Queries using DS-MRR 100 % Query Execution Time Relative to MySQL 5.5 DBT-3, Scale 10 (23 GB) innodb_buffer_pool_size= 1 GB (disk-bound) read_rnd_buffer_size = 4 MB 80 % 60 % 40 % 20 % 0 % Q3 Q4 Q10 Q14 Q15 MySQL 5.5 MySQL 5.6 6

DS-MRR Usage Default: Cost-based choice for tables larger than innodb_buffer_pool_size Force MRR on: (Otherwise: off) set optimizer_switch = mrr_cost_based=off ; Force MRR off: set optimizer_switch = mrr=off ; Configurable size for buffer used to sort keys: read_rnd_buffer_size (Default: 256 kb) 7

DS-MRR EXPLAIN mysql> explain select l_suppkey, sum(l_extendedprice * (1 - l_discount)) from lineitem where l_shipdate >= '1996-07-01' and l_shipdate < date_add('1996-07-01', interval '90' day) group by l_suppkey\g *************************** 1. row *************************** id: 1 select_type: SIMPLE table: lineitem type: range possible_keys: i_l_shipdate key: i_l_shipdate key_len: 4 ref: NULL rows: 4354466 Extra: Using index condition; Using MRR; Using temporary; Using filesort 1 row in set (0.00 sec) 8

Query Time (Minutes) DS-MRR: Sort Buffer Size Matters DBT-3, Query 15 Scale 10 (23 GB) innodb_buffer_pool_size= 1 GB (disk-bound) Varying read_rnd_buffer_size 250 200 150 100 205 optimizer_switch settings: MRR Off: mrr=off MRR Cost-based: mrr=on,mrr_cost_based=on MRR Always on: mrr=on,mrr_cost_based=off 50 4 0 0,25 0,5 1 2 4 8 16 32 64 MRR Sort Buffer Size (MB) MRR Off MRR Cost-based MRR Always On 9

MySQL 5.6: Batched Key Access (BKA) DS-MRR Applied to Join Buffering Table1 Index Collect PKs in buffer Sweepread rows Table2 Sort Join buffer PKs in join buffer order PKs in PK order 10

MySQL 5.5 vs MySQL 5.6: Queries using BKA DBT-3, Scale 10 (23 GB) innodb_buffer_pool_size= 1 GB (disk-bound) join_buffer_size = 4 MB optimizer_switch = batched_key_access=on, mrr_cost_based=off 200 % 175 % 150 % 125 % 100 % 75 % 50 % 25 % 0 % Query Execution Time Relative to MySQL 5.5 Q2 Q5 Q8 Q9 Q11 Q13 Q17 Q19 Q20 Q21 MySQL 5.5 MySQL 5.6 11

Batched Key Access Usage Default: Off Force BKA on: set optimizer_switch = batched_key_access=on,mrr_cost_based=off ; Configurable size for buffering keys to sort: join_buffer_size (Default: 256 kb) 12

Batched Key Access EXPLAIN mysql> explain select sum(l_extendedprice* (1 - l_discount)) as revenue from lineitem, part where p_partkey = l_partkey and p_brand = 'Brand#22 and l_quantity >= 6 and p_size between 1 and 5; +----+-------------+----------+------+---------------------------------+-- id select_type table type possible_keys key key_len ref rows Extra +----+-------------+----------+------+---------------------------------+-- 1 SIMPLE part ALL PRIMARY NULL NULL NULL 200000 Using where 1 SIMPLE lineitem ref i_l_suppkey_partkey,i_l_partkey i_l_suppkey_partkey 5 dbt3.part.p_partkey 15 Using where; Using join buffer (Batched Key Access) +----+-------------+----------+------+---------------------------------+-- 2 rows in set (0.00 sec) 13

Query Time (Minutes) Batched Key Access: Buffer Size Matters DBT-3, Query 2 Scale 10 (23 GB) innodb_buffer_pool_size= 1 GB (disk-bound) Varying join_buffer_size optimizer_switch = batched_key_access=on, mrr_cost_based=off 70 60 59.6 50 40 30 20 10 0 1.4 16k 64k 256k 1M 4M 16M 64M Join Buffer Size (Bytes) BKA Off BKA On 14

MySQL 5.6: Subquery Improvements Optimize IN subqueries select o_orderdate, o_totalprice from orders where o_orderkey in (select l_orderkey from lineitem where l_quantity > 49); New optimizations in MySQL 5.6: Subquery Materialization Semi-join 15

Subquery Materialization 1. Execute subquery and store result in a temporary table with unique index (For quick look-up and duplicate removal.) 2. Execute outer query and check for matches in temporary table. select o_orderdate, o_totalprice from orders where o_orderkey in (select l_orderkey from lineitem group by l_orderkey Materialize having sum(l_quantity) > 313); 16

MySQL 5.5 vs MySQL 5.6: Subquery Materialization DBT-3, Scale 10 (23 GB) innodb_buffer_pool_size= 24 GB (CPU-bound) For Q20: optimizer_switch = semijoin=off; subquery_materialization_cost_ based=off 100 % 80 % 60 % 40 % 20 % Query Execution Time Relative to MySQL 5.5 87 % 0.000006 % 0 % Q16 Q18 Q20 Q18: MySQL 5.5: ~37 years? MySQL 5.5 MySQL 5.6 MySQL 5.6: 69 seconds 48 % 17

MySQL 5.6: Semi-join Convert subquery to inner join, BUT Need some way to remove duplicates Different strategies for duplicate removal: FirstMatch (equivalent to traditional subquery execution) LooseScan (index scan, skip duplicates) Materialization: MatLookup (like subquery materialization), MatScan (materialized table is first in join order) Duplicate WeedOut (insert result rows of semi-join query into temporary table with unique index; duplicate rows will be rejected. Any join order.) If duplicate removal is not necessary: Table pull-out 18

Semi-join, cont. Main advantage: Opens up for more optimal join orders. Example: select o_orderdate, o_totalprice from orders where o_orderkey in (select l_orderkey from lineitem where l_shipdate= 1996-09-30 ); Will process less rows if starting with lineitem instead of orders Restriction: Cannot use semi-join if subquery contains union or aggregation 19

Query Time (seconds) MySQL 5.6: Semi-join: Example 1 select o_totalprice from orders where o_orderkey in (select l_orderkey from lineitem where l_shipdate = '1996-09-30'); DBT-3, Scale 10 (23 GB) innodb_buffer_pool_size= 24 GB (CPU-bound) 70 60 50 40 30 20 10 0 57.83 10.84 0.06 0.07 Trad. Subquery Mat. LooseScan DupsWeedout 20

Query Time (seconds) MySQL 5.6: Semi-join: Example 2 select sum(l_quantity* l_extendedprice) from lineitem where l_orderkey in (select o_orderkey from orders where o_orderdate = '1996-09-30'); DBT-3, Scale 10 (23 GB) innodb_buffer_pool_size= 24 GB (CPU-bound) 80 70 67.02 60 50 40 30 27.61 20 10 0 0.03 Trad. Subquery Mat. Table Pullout 21

Query Time (seconds) MySQL 5.6: Semi-join: Example 3 select s_name, s_address from supplier where s_suppkey in (select ps_suppkey from partsupp, part where ps_partkey=p_partkey and p_name like 'grey% and ps_availqty > 9990); DBT-3, Scale 10 (23 GB) innodb_buffer_pool_size= 24 GB (CPU-bound) 14 12 10 8 6 4 2 0 12.74 12.53 12.49 0.89 0.89 Trad. Subquery Mat. MatLookup FirstMatch DupsWeedout 22

Semi-join Usage Default: All IN sub-queries that do not contain aggreation or union are converted to semi-join Disable semi-join conversion: set optimizer_switch = semijoin=off ; Disable individual semi-join strategies: set optimizer_switch = firstmatch=off ; set optimizer_switch = loosescan=off ; set optimizer_switch = materialization=off ; Force traditional IN-to-EXIST evaluation: set optimizer_switch = semijoin=off,materialization=off ; 23

MySQL 5.6: Index Condition Pushdown (ICP) DBT3 Query 6: Forecasting Revenue Change Query Need force index to get ICP for this query select sum(l_extendedprice * l_discount) as revenue from lineitem force index(j_l_shipdate_discount_quantity) where l_shipdate >= '1994-01-01' and l_shipdate < date_add('1994-01-01,interval '1' year) and l_discount between 0.09-0.01 and 0.09 + 0.01 and l_quantity < 24; Index range scan criteria Conditions evaluated during index scan 24

Query Time (seconds) MySQL 5.6: Index Condition Pushdown 30 DBT-3, Query 6 Scale 10 (23 GB) innodb_buffer_pool_size= 24 GB (CPU-bound) optimizer_switch settings: index_condition_pushdown = on/off 25 20 15 10 5 Table Scan Index Scan (ICP off) Index Scan (ICP on) 0 25

Index Condition Pushdown EXPLAIN mysql> explain select sum(l_extendedprice * l_discount) as revenue from lineitem force index (i_l_shipdate_discount_quantity) where l_shipdate >= '1994-01-01' and l_shipdate < date_add( '1994-01-01', interval '1' year) and l_discount between 0.09-0.01 and 0.09 + 0.01 and l_quantity < 2\G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: lineitem type: range possible_keys: i_l_shipdate_discount_quantity key: i_l_shipdate_discount_quantity key_len: 16 ref: NULL rows: 18940908 Extra: Using index condition 1 row in set (0.00 sec) 26

Index Condition Pushdown EXPLAIN FORMAT=JSON mysql> explain FORMAT=JSON select sum(l_extendedprice * l_discount) as revenue from lineitem force index (i_l_shipdate_discount_quantity) where l_shipdate >= '1994-01-01' and l_shipdate < date_add( '1994-01-01', interval '1' year) and l_discount between 0.09-0.01 and 0.09 + 0.01 and l_quantity < 24; { "query_block": { "select_id": 1, "table": { "table_name": "lineitem", "access_type": "range",... "filtered": 100, "index_condition": "((`dbt3`.`lineitem`.`l_shipdate` >= '1994-01-01') and (`dbt3`.`lineitem`.`l_shipdate` < ('1994-01-01' + interval '1' year)) and (`dbt3`.`lineitem`.`l_discount` between (0.09-0.01) and (0.09 + 0.01)) and (`dbt3`.`lineitem`.`l_quantity` < 24))" } 27

MySQL 5.6: More Optimizer Improvements ORDER BY with LIMIT optimization Delayed Materialization of Derived Tables Extended secondary keys (InnoDB) Reduced optimization time for large IN-lists Reduced optimization time for many-table joins Reduced space usage for large temporary tables with VARCHAR Speed-up of information schema queries EXPLAIN for INSERT, UPDATE, DELETE Structured EXPLAIN (JSON format) Optimizer trace 28

More information My blog: http://oysteing.blogspot.com/ Optimizer team blog: http://mysqloptimizerteam.blogspot.com/ What s new in MySQL 5.6: http://dev.mysql.com/tech-resources/articles/whats-new-in-mysql-5.6.html 29

The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle s products remains at the sole discretion of Oracle. 30

Q&A 31

32