MySQL Performance Tuning - MySQL 8 Query Performance Tuning - A Systematic Method For Improving Execution Speeds
MySQL Performance Tuning - MySQL 8 Query Performance Tuning - A Systematic Method For Improving Execution Speeds
MySQL Performance Tuning - MySQL 8 Query Performance Tuning: A Systematic Method for Improving Execution Speeds
MySQL 8 Query Performance Tuning: A Systematic Method for Improving Execution Speeds
PREV NEXT
⏮ ⏭
Part I. Getting Started 2. Query Tuning Methodology
🔎
1. MySQL Performance
Tuning
1
Jesper Wisborg Krogh
Tip If you need a test instance, whether it is while reading this book or
for working on a problem at work, the cloud can be your friend. It allows
you to quickly spin up a test instance. If you just need a small instance, for
example, to explore examples in this book, you may even be able to use a
free instance, such as through Oracle Cloud’s free tier (registration and a
credit card is still required):
https://mysql.wisborg.dk/oracle_cloude_free_tier.
When an application needs the result of the query or needs to store data in
MySQL, it sends the request over the network to MySQL, and in order to
execute the request, MySQL interacts with the operating system and uses
host resources such as memory and disk. Once the result of the request is
ready, it is communicated back to the application through the network. This
is illustrated in Figure 1-1.
The pyramid is a very simplified picture which leaves out everything beyond
the application which may in turn communicate with a user and use its own
resources. Communicating over the network also involves both the host and
operating system.
This book focuses on MySQL and the aspects affecting queries, but do not
forget the rest of your system. That includes when you monitor your system.
https://learning.oreilly.com/library/view/mysql-8-query/9781484255841/html/484666_1_En_1_Chapter.xhtml 1/3
4/15/2020 1. MySQL Performance Tuning - MySQL 8 Query Performance Tuning: A Systematic Method for Improving Execution Speeds
If you take just one thing with you from reading this book, then let it be that
monitoring is critical to maintain a healthy system. Everything you do should
revolve around monitoring. In some cases, monitoring through a dedicated
monitoring solution provides all the data you need, and in other cases you
need to make ad hoc observations.
The slow query log which can record queries matching certain criteria
such as taking longer than a predefined threshold.
These sources of information are all discussed and used throughout this
book.
MySQL Server can be divided into two layers. There is the SQL layer which,
for example, handles the connections and prepares statements for execution.
The actual data is stored by storage engines which are implemented as
plugins which makes it relatively easy to implement different ways to handle
data. The main storage engine – and the only one that will be considered in
this book – is InnoDB which is fully transactional and has very good support
for high-concurrency workloads. An example of another storage engine is
NDBCluster which is also transactional and is used as part of MySQL NDB
Cluster.
When the application needs to execute a query, then the first thing is to
create a connection (this is not included in the figure as the connection may
be reused to execute more queries). When the query arrives, MySQL parses
it. This includes splitting the query into tokens, so the query type is known,
and there is a list of the tables and columns required by the query. This list is
needed during the next step where it is checked whether the user has the
necessary permissions to execute the query.
At this time, the query has reached the important step of determining how to
execute the query. This is the job of the optimizer and involves rewriting the
query as well as determining the order to access the tables and which
indexes to use.
The actual execution step includes requesting the data from the storage
engine layer. The storage engine may itself be complex. For InnoDB, it
includes a buffer pool used to cache data and indexes, redo and undo logs,
other buffers, as well as tablespace files. If the query returns rows, these are
sent back from the storage engine through the SQL layer to the application.
In query tuning, the most important steps are the optimizer and execution
steps including the storage engine. Most of the information in this book
relates to these three parts either directly or indirectly.
Summary
This chapter has scratched the surface of performance tuning and prepared
you for the journey of the rest of the book. The key takeaways are that you
need to consider the whole stack from the end user to the low-level details of
the host and operating system and monitoring is an absolute must in
performance tuning. Executing a query includes several steps, of which the
optimizer and execution steps are the ones that you will learn the most
about in this book.
The next chapter will look closer at a methodology that is useful for solving
performance issues.
Settings / Support / Sign Out Find answers on the fly, or master something new. Subscribe today. See pricing options.
© 2020 O'Reilly Media, Inc. Terms of Service / Privacy Policy
PREV NEXT
https://learning.oreilly.com/library/view/mysql-8-query/9781484255841/html/484666_1_En_1_Chapter.xhtml 2/3
4/15/2020 1. MySQL Performance Tuning - MySQL 8 Query Performance Tuning: A Systematic Method for Improving Execution Speeds
PREV NEXT
⏮ ⏭
Part I. Getting Started 2. Query Tuning Methodology
Find answers on the fly, or master something new. Subscribe today. See pricing options.
https://learning.oreilly.com/library/view/mysql-8-query/9781484255841/html/484666_1_En_1_Chapter.xhtml 3/3