Query Optimizer MySQL vs. PostgreSQL

Similar documents
Query Optimizer MySQL vs. PostgreSQL

Bloom Filters DOAG Webinar, 12 August 2016 Christian Antognini Senior Principal Consultant

Identifying Performance Problems in a Multitenant Environment

Adaptive

Oracle Database 18c New Performance Features

Designing for Performance: Database Related Worst Practices ITOUG Tech Day, 11 November 2016, Milano (I) Christian Antognini

Oracle Database New Performance Features

Oracle In-Memory & Data Warehouse: The Perfect Combination?

Die Wundertüte DBMS_STATS: Überraschungen in der Praxis

Pitfalls & Surprises with DBMS_STATS: How to Solve Them


Online Operations in Oracle 12.2

Data Vault Partitioning Strategies. Dani Schnider, Trivadis AG DOAG Conference, 23 November 2017

How Well Do Relational Database Engines Support

Application Containers an Introduction

Application Containers an Introduction

Get Groovy with ODI Trivadis

Domain Services Clusters Centralized Management & Storage for an Oracle Cluster Environment Markus Flechtner

Advanced Oracle Performance Troubleshooting. Query Transformations Randolf Geist

Independent consultant. Oracle ACE Director. Member of OakTable Network. Available for consulting In-house workshops. Performance Troubleshooting

Independent consultant. Oracle ACE Director. Member of OakTable Network. Available for consulting In-house workshops. Performance Troubleshooting

Pimping up Industry Devices with Rasperry Pi, Vert.x und Java 8

ORACLE TRAINING CURRICULUM. Relational Databases and Relational Database Management Systems

Application Containers an Introduction

Analytic Views: Use Cases in Data Warehouse. Dani Schnider, Trivadis AG DOAG Conference, 21 November 2017

Recovery without Backup. All Data Lost?

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

7. Query Processing and Optimization

Database Sharding with Oracle RDBMS

Delegates must have a working knowledge of MariaDB or MySQL Database Administration.

Introduction to MySQL NDB Cluster. Yves Trudeau Ph. D. Percona Live DC/January 2012

How Autonomous is the Oracle Autonomous Data Warehouse?

Edition-Based Redefinition

MySQL for Developers Ed 3

Querying Data with Transact SQL

MySQL for Developers Ed 3

Partitionierungsstrategien für Data Vault. Dani Schnider, Trivadis AG DOAG Konferenz, 23. November 2017

WELCOME. Unterstützung von Tuning- Maßnahmen mit Hilfe von Capacity Management. DOAG SIG Database

Interpreting Explain Plan Output. John Mullins

Backup Methods from Practice

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

Empfehlungen vom BigData Admin

PostgreSQL Introduction for Oracle DBAs

Oracle Database: Introduction to SQL Ed 2

Object-Relational Mapping Tools let s talk to each other!

20461: Querying Microsoft SQL Server 2014 Databases

Oracle Database 11gR2 Optimizer Insights

Oracle Developer Track Course Contents. Mr. Sandeep M Shinde. Oracle Application Techno-Functional Consultant

Migrating to 12c: 300 DBs in 300 days.

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

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Administrivia. Administrivia. Faloutsos/Pavlo CMU /615

Cloud Acceleration. Performance comparison of Cloud vendors. Tobias Deml DOAG2017

Service discovery in Kubernetes with Fabric8

Answer: Reduce the amount of work Oracle needs to do to return the desired result.

Scripting OBIEE Is UDML and XML all you need?

CSE 530A. Query Planning. Washington University Fall 2013

Oracle SQL & PL SQL Course

DB2 SQL Tuning Tips for z/os Developers

20761 Querying Data with Transact SQL

Data Replication With Oracle GoldenGate Looking Behind The Scenes Robert Bialek Principal Consultant Partner

Relational Database Index Design and the Optimizers

Querying Data with Transact-SQL

Microservices with Kafka Ecosystem. Guido Schmutz

Find All Tables Containing Column With Specified Name Oracle

Advanced Oracle SQL Tuning v3.0 by Tanel Poder

When should an index be used?

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

Oracle Syllabus Course code-r10605 SQL

Course Modules for MCSA: SQL Server 2016 Database Development Training & Certification Course:

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

Querying Microsoft SQL Server 2008/2012

COURSE OUTLINE: Querying Microsoft SQL Server

Troubleshooting Oracle Performance

Oracle Compare Two Database Tables Sql Query Join

MySQL Database Administrator Training NIIT, Gurgaon India 31 August-10 September 2015

REALTIME WEB APPLICATIONS WITH ORACLE APEX

DB2 UDB: Application Programming

SQL Server 2014 Highlights der wichtigsten Neuerungen In-Memory OLTP (Hekaton)

Querying Microsoft SQL Server (461)

MySQL for Beginners Ed 3

The Microsoft Big Data architecture approach

Oracle Database 11g: SQL Tuning Workshop

Mysql Create Table With Multiple Index Example

Does Exadata Need Performance Tuning? Jože Senegačnik, Oracle ACE Director, Member of OakTable DbProf d.o.o. Ljubljana, Slovenia

CSE 544 Principles of Database Management Systems. Magdalena Balazinska Fall 2007 Lecture 9 - Query optimization

Relational Database Index Design and the Optimizers

Cost Based Optimizer CBO: Configuration Roadmap

COURSE OUTLINE MOC 20461: QUERYING MICROSOFT SQL SERVER 2014

Course Details Duration: 3 days Starting time: 9.00 am Finishing time: 4.30 pm Lunch and refreshments are provided.

1 Writing Basic SQL SELECT Statements 2 Restricting and Sorting Data

PostgreSQL to MySQL A DBA's Perspective. Patrick

Querying Microsoft SQL Server 2012/2014

AVANTUS TRAINING PTE LTD

Querying Data with Transact-SQL

pgconf.de 2018 Berlin, Germany Magnus Hagander

MySQL 8.0 What s New in the Optimizer

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

Database Rolling Upgrade with Transient Logical Standby Database DOAG Day High Availability Robert Bialek Principal Consultant

Outline. Database Management and Tuning. Outline. Join Strategies Running Example. Index Tuning. Johann Gamper. Unit 6 April 12, 2012

Transcription:

Percona Live, Santa Clara (USA), 24 April 2018 Christian Antognini @ChrisAntognini antognini.ch/blog BASEL BERN BRUGG DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. GENEVA HAMBURG COPENHAGEN LAUSANNE MUNICH STUTTGART VIENNA ZURICH

@ChrisAntognini Senior principal consultant, trainer and partner at Trivadis christian.antognini@trivadis.com http://antognini.ch Focus: get the most out of database engines Logical and physical database design Query optimizer Application performance management Author of Troubleshooting Oracle Performance (Apress, 2008/14) OakTable Network, Oracle ACE Director 2 2018-04-24

Agenda 1. Introduction 2. Configuration 3. Statistics about Data 4. Data Dictionary Metadata 5. Single-Table Access Paths 6. Joins and Sub-queries 7. Conclusion 8. References 3 2018-04-24

Introduction 4 2018-04-24

Compared Products MySQL Community Server 8.0.11 Release date: 19 April 2018 PostgreSQL 10.3 Release date: 1 March 2018 Only the InnoDB engine is covered 5 2018-04-24

Terminology In PostgreSQL the query optimizer is called planner 6 2018-04-24

Disclaimer No performance tests were performed No comparison between the execution plans generated by the two query optimizers were performed To compare and to evaluate the two query optimizers only the availability of key features and the ability of the query optimizer to correctly recognize common data patterns was considered 7 2018-04-24

Aim of the Query Optimizer SQL is a declarative language SQL doesn t specify how to access data, only which data to process B The strategy used to access data is delegated to the query optimizer The aim of the query optimizer is to find out the optimal way to execute a given SQL statement A 8 2018-04-24

Inputs Considered to Produce an Execution Plan SQL statement Configuration Metadata Object statistics Query Optimizer Others? Execution plan 9 2018-04-24

How Is Data in Tables Stored? InnoDB uses a B-tree index Heap table 10 2018-04-24

Controlling the Query Optimizer 11 2018-04-24

Configuration Three system variables control the behavior of the query optimizer Limit the number of evaluated plans (2) Control specific features (1 parameter for 20 features) The default (system) values can be overwritten at session level and at the statement level Two dozen of parameters control the behavior of the query optimizer Limit the number of evaluated plans (2) Control specific features (15) Control the genetic optimizer (7) The default (system) values can be overwritten at session level 12 2018-04-24

Configuration Cost Model A cost model database contains cost estimate information for a number of operations (8) The default values can be changed at the system level only A number of parameters provide cost estimate information for a number of operations (11) The default (system) values can be overwritten at session level 13 2018-04-24

Hints hints_modifiers.sql hints_index.sql hints_optimizer.sql SELECT statement modifiers (4) Impact statement syntax (Available in EDB Advanced Server) Index hints (3) Impact statement syntax Cause error when index missing Optimizer hints (21) Similar to Oracle Database hints Global, query block and object-level Cause warning when syntax is wrong 14 2018-04-24

Statistics about Data 15 2018-04-24

Gathering Statistics The ANALYZE statement gathers and, by default, stores statistics in the data dictionary By default, an asynchronous automatic statistics recalculation takes place The ANALYZE statement gathers and stores statistics in the data dictionary By default, the autovacuum daemon recalculate statistics of modified tables Persistent (default) as well as nonpersistent statistics exist 16 2018-04-24

Table Statistics statistics.sql Clustered index size (pages) Number of rows Table size (pages) Number of rows Number of pages marked all-visible 17 2018-04-24

Column Statistics statistics.sql Data distribution (optional) Including fraction of entries that are null Fraction of values that are null Average column width (bytes) Number of distinct values Statistical correlation between physical and logical row ordering Data distribution (optional) Most common values and their frequency (optional) 18 2018-04-24

Cross-Column Statistics statistics.sql Functional dependencies (optional) Number of distinct values (optional) 19 2018-04-24

Index Statistics statistics.sql Index size (pages) Number of leaf pages Index size (pages) Number of indexed rows Number of distinct keys Several values are stored E.g. for index a,b,c a, a,b, a,b,c, a,b,c,pk 20 2018-04-24

Data Dictionary Metadata 21 2018-04-24

Constraints Primary Key and Unique Key constraints_pk_uk.sql Because of the clustered index, PK has precedence over other indexes Predicates based on UK take precedence over other indexes Equality predicates based on PK/UK are probed No particular precedence is given to predicates based on PK/UK Statistical correlation between physical and logical row ordering determines which index is used 22 2018-04-24

Constraints Foreign Key constraints_fk.sql No evidence about the usage of FK to avoid unnecessary loss-less joins has been observed No evidence about the usage of FK to avoid unnecessary loss-less joins has been observed 23 2018-04-24

Constraints NOT NULL constraints_not_null.sql NOT NULL constraints are used to verify the validity of predicates By default the usage of NOT NULL constraints to verify the validity of predicates is enabled for specific cases only constraint_exclusion = partition Statistics are used instead 24 2018-04-24

Constraints CHECK constraints_check.sql No evidence about the usage of CHECK constraints to verify the validity of predicates has been observed Statistics are used instead By default the usage of CHECK constraints to verify the validity of predicates is enabled for specific cases only constraint_exclusion = partition Statistics are used instead 25 2018-04-24

Single-Table Access Paths 26 2018-04-24

Available Index Types Supported index types B-tree (default) R-tree (for spatial indexes) For string columns, indexes can be created on the leading part of column values B-tree indexes store NULL values Supported index types B-tree (default) indexes_expression.sql indexes_partial.sql indexes_invisible.sql indexes_prefix.sql indexes_nulls.sql Hash, GiST, SP-GiST, GIN, BRIN Indexes can be created on expressions as well as on a subset of the rows B-tree indexes store NULL values Support for invisible indexes 27 2018-04-24

Optimization of ORDER BY, MIN and MAX indexes_order_by.sql indexes_min_max.sql B-tree indexes can be used to optimize ORDER BY, MIN and MAX Index scans can be performed in both directions Keys are stored according to the specified order No NULLS FIRST/LAST support B-tree indexes can be used to optimize ORDER BY, MIN and MAX Index scans can be performed in both directions Keys are stored according to the specified order NULLS FIRST/LAST supported 28 2018-04-24

Merging Indexes indexes_merge.sql Two or more B-tree indexes can be merged at runtime to evaluate multiple predicates combined with AND or OR When appropriate, B-tree indexes are dynamically converted to bitmaps in memory One utilization of this feature is to merge indexes to evaluate multiple predicates combined with AND or OR 29 2018-04-24

(Declarative) Partitioning partitioning_range.sql partitioning_list.sql partitioning_hash.sql Available methods: Multi-column range and list Single-column hash Sub-partitioning by hash Only local indexes (PK/UK must contain partition key) FK not supported Partition pruning Available methods: Multi-column range Single-column list Sub-partitioning Only local indexes (no PK/UK) FK not supported Partition exclusion (pruning) 30 2018-04-24

Joins and Sub-queries 31 2018-04-24

Available Kind of Joins joins_methods.sql joins_syntax.sql joins_bushy.sql Available join methods Nested loops join (Hash join available in MariaDB) Bushy plans are considered only when no other possibility exists Full outer joins are not supported Available join methods Nested loops join Hash join Merge join Bushy plans are considered Full outer joins are supported and optimized with hash/merge joins 32 2018-04-24

Sub-queries in WHERE Clause joins_subqueries.sql Simple sub-queries that are not correctly optimized were observed For optimal performance a rewrite might be necessary Problematic cases observed Correlated NOT IN Correlated (NOT) EXISTS Simple sub-queries that are not correctly optimized were observed For optimal performance a rewrite might be necessary Problematic case observed Correlated (NOT) IN Uncorrelated NOT IN 33 2018-04-24

Conclusion 34 2018-04-24

Summary Good configuration capabilities Hints available Fairly good object statistics Metadata only partially used Good indexing capabilities, average partition capabilities Limited join capabilities Good configuration capabilities Hints missing Very good object statistics Metadata only partially used Good indexing capabilities, average partition capabilities Good join capabilities 35 2018-04-24

Core Messages The query optimizer of PostgreSQL is more advanced than the one of MySQL In general, the query optimizer of MySQL can only do a good job with transactional loads; the one of PostgreSQL is also suitable for analytical loads 36 2018-04-24

Rate My Session 37 2018-04-24

References 38 2018-04-24

References (1) MySQL 8.0 Reference Manual The Unofficial MySQL 8.0 Optimizer Guide MySQL Internals PostgreSQL 10.1 Documentation Planner source code readme PostgreSQL Wiki MySQL Server Blog 39 2018-04-24

References (2) The verification scripts I wrote are available on GitHub How Well a Query Optimizer Handles Subqueries? 40 2018-04-24

Q&A 41 2018-04-24