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

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

Optimizing Queries with EXPLAIN

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

OKC MySQL Users Group

Covering indexes. Stéphane Combaudon - SQLI

MariaDB Optimizer. Current state, comparison with other branches, development plans

Meet the Sergei Golubchik MariaDB Corporation

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

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

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

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

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

Indexes - What You Need to Know

Practical MySQL indexing guidelines

Query Optimization Percona, Inc. 1 / 74

Target Practice. A Workshop in Tuning MySQL Queries OSCON Jay Pipes Community Relations Manager, North America MySQL, Inc.

MySQL Query Optimization. Originally: Query Optimization from 0 to 10 by Jaime Crespo

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

Explaining the MySQL EXPLAIN

Advanced MySQL Query Tuning

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

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

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

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

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

MariaDB Developer UnConference April 9-10 th 2017 New York. MyRocks in MariaDB. Why and How. Sergei Petrunia

ORACLE DATA SHEET ORACLE PARTITIONING

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

Requirements for Improvements in PostgreSQL Database Partitioning

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

Distributing Queries the Citus Way Fast and Lazy. Marco Slot

Partitioning. Sheeri K. Cabral Database Administrator The Pythian Group, January 12, 2009

MySQL vs MariaDB. Where are we now?

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

Query Optimizer MySQL vs. PostgreSQL

Query Optimization, part 2: query plans in practice

CSE 530A. Inheritance and Partitioning. Washington University Fall 2013

FUN WITH ANALYTIC FUNCTIONS UTOUG TRAINING DAYS 2017

Writing Queries Using Microsoft SQL Server 2008 Transact-SQL. Overview

Advanced MySQL Query Tuning

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

Oracle Compare Two Database Tables Sql Query List All

CSE 530A. B+ Trees. Washington University Fall 2013

Lecture 19 Query Processing Part 1

IT Certification Exams Provider! Weofferfreeupdateserviceforoneyear! h ps://

IMPORTING DATA IN PYTHON I. Introduction to relational databases

How to Use JSON in MySQL Wrong

PostgreSQL to MySQL A DBA's Perspective. Patrick

Oracle 1Z Oracle Database 12c SQL. Download Full Version :

Chapter 3. Introduction to relational databases and MySQL. 2010, Mike Murach & Associates, Inc. Murach's PHP and MySQL, C3

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

CSED421 Database Systems Lab. Index

II. Structured Query Language (SQL)

Exam Name: Querying Microsoft SQL Server 2012

Aster Data SQL and MapReduce Class Outline

Major Features: Postgres 10

Pl Sql Copy Table From One Schema To Another

Class of 55 Room, Van Pelt Library - October 21, 2011

Manual Trigger Sql Server 2008 Inserted Table Examples Insert

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

MIS2502: Review for Exam 2. JaeHwuen Jung

Mastering the art of indexing

Practical Performance Tuning using Digested SQL Logs. Bob Burgess Salesforce Marketing Cloud

MySQL Performance Optimization

Oracle 11g Partitioning new features and ILM

What s New in MariaDB Server 10.3

MariaDB Crash Course. A Addison-Wesley. Ben Forta. Upper Saddle River, NJ Boston. Indianapolis. Singapore Mexico City. Cape Town Sydney.

Introduction to relational databases and MySQL

How to Use Full Pushdown Optimization in PowerCenter

CISC 7610 Lecture 2b The beginnings of NoSQL

MANAGING DATA(BASES) USING SQL (NON-PROCEDURAL SQL, X401.9)

Mysql Create Table With Multiple Index Example

MIS2502: Review for Exam 2. Jing Gong

SQL Joins and SQL Views

Aster Data Basics Class Outline

Microsoft Exam Querying Microsoft SQL Server 2012 Version: 13.0 [ Total Questions: 153 ]

Maximizing SQL reviews with pt-query-digest

MySQL 8.0: Common Table Expressions

Query Optimization With MySQL 8.0 and MariaDB 10.3: The Basics

What s New in MariaDB Server Max Mether VP Server

Open Source Database Ecosystem in Peter Zaitsev 3 October 2016

Databases (MariaDB/MySQL) CS401, Fall 2015

Middleware for Heterogeneous and Distributed Information Systems Sample Solution Exercise Sheet 5

Hyperion Interactive Reporting Reports & Dashboards Essentials

MyRocks in MariaDB. Sergei Petrunia MariaDB Tampere Meetup June 2018

Microsoft Access Illustrated. Unit B: Building and Using Queries

SQL Server 2012 Development Course

Course Outline. Querying Data with Transact-SQL Course 20761B: 5 days Instructor Led

Using SPIDER for sharding in production. Kentoku SHIBA Stephane Varoqui Kayoko Goto

Querying Data with Transact-SQL

Introduction to MySQL /MariaDB and SQL Basics. Read Chapter 3!

Still using. Windows 3.1? So why stick to -

MySQL 5.1 Past, Present and Future MySQL UC 2006 Santa Clara, CA

YourSQL: A High-Performance DBMS Leveraging In-Storage Computing

EXAM REF QUERYING DATA WITH TRANSACT-SQL BY ITZIK BEN-GAN

20761B: QUERYING DATA WITH TRANSACT-SQL

EXAM REF QUERYING DATA WITH TRANSACT-SQL BY ITZIK BEN-GAN

Exact Numeric Data Types

MyRocks Storage Engine Status Update. Sergei Petrunia MariaDB Meetup New York February, 2018

Transcription:

[Some of] New Query Optimizer features in MariaDB 10.3 Sergei Petrunia <sergey@mariadb.com> MariaDB Shenzhen Meetup November 2017

2 Plan MariaDB 10.2: Condition pushdown MariaDB 10.3: Condition pushdown through window functions MariaDB 10.3: GROUP BY splitting

3 Condition pushdown Just condition pushdown in 10.2 Pushdown through window functions in 10.3

4 Background derived table merge VIP customers and their big orders from October from vip_customer, ( order_date BETWEEN '2017-10-01' and '2017-10-31' ) as OCT_ORDERS OCT_ORDERS.amount > 1M and OCT_ORDERS.customer_id = customer.customer_id

Naive execution 1 compute oct_orders 5 from vip_customer, ( order_date BETWEEN '2017-10-01' and '2017-10-31' ) as OCT_ORDERS OCT_ORDERS.amount > 1M and OCT_ORDERS.customer_id = vip_customer vip_customer.customer_id orders 2- do join OCT_ORDERS amount > 1M

6 Derived table merge from vip_customer, ( order_date BETWEEN '2017-10-01' and '2017-10-31' ) as OCT_ORDERS OCT_ORDERS.amount > 1M and OCT_ORDERS.customer_id = vip_customer.customer_id from vip_customer, orders order_date BETWEEN '2017-10-01' and '2017-10-31' and orders.amount > 1M and orders.customer_id = vip_customer.customer_id

7 Execution after merge vip_customer Join orders Made in October amount > 1M from vip_customer, orders order_date BETWEEN '2017-10-01' and '2017-10-31' and orders.amount > 1M and orders.customer_id = vip_customer.customer_id Allows the optimizer to do customer->orders or orders customer Good for optimization

8 Another use case - grouping create view OCT_TOTALS as select customer_id, SUM(amount) as TOTAL_AMT order_date BETWEEN '2017-10-01' and '2017-10-31' group by customer_id from OCT_TOTALS customer_id=1 Can t merge due to GROUP BY in the child.

9 Execution is inefficient 1 compute all totals create view OCT_TOTALS as select customer_id, SUM(amount) as TOTAL_AMT order_date BETWEEN '2017-10-01' and '2017-10-31' group by customer_id orders Sum from OCT_TOTALS customer_id=1 OCT_TOTALS 2- get customer=1 customer_id=1

10 Condition pushdown create view OCT_TOTALS as select customer_id, SUM(amount) as TOTAL_AMT order_date BETWEEN '2017-10-01' and '2017-10-31' group by customer_id from OCT_TOTALS customer_id=1 Can push down conditions on GROUP BY columns to filter out rows that go into groups we dont care about

11 Condition pushdown 1 find customer_id=1 orders create view OCT_TOTALS as select customer_id, SUM(amount) as TOTAL_AMT order_date BETWEEN '2017-10-01' and '2017-10-31' group by customer_id Sum OCT_TOTALS, customer_id=1 customer_id=1 orders from OCT_TOTALS customer_id=1 Looking only at rows you re interested in is much more efficient

MariaDB 10.3: Pushdown through Window Functions Customer s biggest orders 12 create view top_three_orders as from ( select customer_id, amount, rank() over (partition by customer_id order by amount desc ) as order_rank ) as ordered_orders order_rank<3 +-------------+--------+------------+ customer_id amount order_rank +-------------+--------+------------+ 1 10000 1 1 9500 2 1 400 3 2 3200 1 2 1000 2 2 400 3... from top_three_orders customer_id=1

MariaDB 10.3: Pushdown through Window Functions 13 from top_three_orders customer_id=1 MariaDB 10.2, MySQL 8.0 Compute top_three_orders for all customers select rows with customer_id=1 MariaDB 10.3 (and e.g. PostgreSQL) Only compute top_three_orders for customer_id=1 This can be much faster! Can make use of index(customer_id)

14 Split grouping for derived create view OCT_TOTALS as select customer_id, SUM(amount) as TOTAL_AMT order_date BETWEEN '2017-10-01' and '2017-10-31' group by customer_id from customer, OCT_TOTALS customer.customer_id=oct_totals.customer_id and customer.customer_name IN ('Customer 1', 'Customer 2')

create view OCT_TOTALS as select customer_id, SUM(amount) as TOTAL_AMT order_date BETWEEN '2017-10-01' and '2017-10-31' group by customer_id from customer, OCT_TOTALS customer.customer_id= OCT_TOTALS.customer_id and customer.customer_name IN ('Customer 1', 'Customer 2') Inefficient, OCT_TOTALS is computed for *all* customers. Execution, the old way customer Customer 1 Customer 2 Sum OCT_TOTALS Customer 1 Customer 2 Customer 3 Customer 100 orders Customer 1 15 Customer 2 Customer 3 Customer 100

16 Split grouping execution Can be used when doing join from customer to orders Must have equalities for GROUP BY columns: OCT_TOTALS.customer_id=customer.customer_id This allows to select one group The underlying table (orders) must have an index on the GROUP BY column (customer_id) customer Customer 2 Customer 1 orders Customer 2 Customer 1 Customer 100 Sum Sum This allows to use ref access

17 Split grouping execution create view OCT_TOTALS as select customer_id, SUM(amount) as TOTAL_AMT order_date BETWEEN '2017-10-01' and '2017-10-31' group by customer_id from customer, OCT_TOTALS customer.customer_id= OCT_TOTALS.customer_id and customer.customer_name IN ('Customer 1', 'Customer 2') +------+-----------------+------------+------+---------------+-------------+---------+----------------------+------+-------------+ id select_type table type possible_keys key key_len ref rows Extra +------+-----------------+------------+------+---------------+-------------+---------+----------------------+------+-------------+ 1 PRIMARY customer ALL PRIMARY NULL NULL NULL 1000 1 PRIMARY <derived2> ref key0 key0 4 customer.customer_id 36 2 LATERAL DERIVED orders ref customer_id customer_id 4 customer.customer_id 365 Using +------+-----------------+------------+------+---------------+-------------+---------+----------------------+------+-------------+ EXPLAIN shows LATERAL DERIVED @@optimizer_switch flag: split_grouping_derived (ON by default) Not fully cost-based choice atm (check query plan, use if possible and certainly advantageous)

18 Summary MariaDB 10.2: Condition pushdown for derived tables optimization Push a condition into derived table Used when derived table cannot be merged Biggest effect is for subqueries with GROUP BY MariaDB 10.3: Condition Pushdown through Window functions MariaDB 10.3: Lateral derived optimization When doing a join, can t do condition pushdown So, lateral derived is used. It allows to only examine GROUP BY groups that match other tables. It needs index on grouped columns Work in progress (optimization process is very basic ATM)

19 Thanks! Discussion