Book Image

Advanced MySQL 8

By : Eric Vanier, Birju Shah, Tejaswi Malepati
Book Image

Advanced MySQL 8

By: Eric Vanier, Birju Shah, Tejaswi Malepati

Overview of this book

Advanced MySQL 8 teaches you to enhance your existing database infrastructure and build various tools to improve your enterprise applications and overall website performance. The book starts with the new and exciting MySQL 8.0 features and how to utilize them for maximum efficiency. As you make your way through the chapters, you will learn to optimize MySQL performance using indexes and advanced data query techniques for large queries. You will also discover MySQL Server 8.0 settings and work with the MySQL data dictionary to boost the performance of your database. In the concluding chapters, you will cover MySQL 8.0 Group Replication, which will enable you to create elastic, highly available, and fault-tolerant replication topologies. You will also explore backup and recovery techniques for your databases and understand important tips and tricks to help your critical data reach its full potential. By the end of this book, you’ll have learned about new MySQL 8.0 security features that allow a database administrator (DBA) to simplify user management and increase the security of their multi-user environments.
Table of Contents (13 chapters)
11
Advanced MySQL Performance Tips and Techniques

Case study 1 – an example of how to optimize a complex query

We will explore in this case study a complex step-by-step query such as the following:

  1. How to format a complex query
  2. Run and analyze an execution plan
  3. Optimize a complex query

When we have a query that runs in production and is complex, we need to format it so that we can have more clarity and can easily optimize it.

Here is our request (not formatted):

Here is our formatted query:

Here is the EXPLAIN plan:

Let's analyze the query together.

The first problem observed from the output of the execution plan is the following:

SUBQUERY DEPENDENT (NOT EXISTS ( SELECT 1 FROM employees_party WHERE fk_employees_id = employees.id AND Important_id BETWEEN 1 and 4 AND diff_value BETWEEN 1 and 3));

The solution is to rewrite the part of the SUBQUERY DEPENDENT as follows, in order to optimize our query:

SELECT E....