Foreword
Mark Callaghan, Software Engineer, Facebook
Ive been a fan of this book for years, and the third edition makes a great book even better. Not only do world-class experts share that expertise, but they have taken the time to update and add chapters with high-quality writing. While the book has many details on getting high performance from MySQL, the focus of the book is on the process of improvement rather than facts and trivia. This book will help you figure out how to make things better, regardless of changes in MySQLs behavior over time.
The authors are uniquely qualified to write this book, based on their experience, principled approach, focus on efficiency, and commitment to improvement. By experience , I mean that the authors have been working on MySQL performance from the days when it didnt scale and had no instrumentation to the current period where things are much better. By principled approach , I mean that they treat this like a science, first defining problems to be solved and then using reason and measurement to solve those problems.
I am most impressed by their focus on efficiency . As consultants, they dont have the luxury of time. Clients getting billed by the hour want problems solved quickly. So the authors have defined processes and built tools to get things done correctly and efficiently. They describe the processes in this book and publish source code for the tools.
Finally, they continue to get better at what they do. This includes a shift in concern from throughput to response time, a commitment to understanding the performance of MySQL on new hardware, and a pursuit of new skills like queueing theory that can be used to understand performance.
I believe this book augurs a bright future for MySQL. As MySQL has evolved to support demanding workloads, the authors have led a similar effort to improve the understanding of MySQL performance within the community. They have also contributed directly to that improvement via XtraDB and XtraBackup. I continue to learn from them and hope you take the time to do so as well.
Preface
We wrote this book to serve the needs of not just the MySQL application developer but also the MySQL database administrator. We assume that you are already relatively experienced with MySQL. We also assume some experience with general system administration, networking, and Unix-like operating systems.
The second edition of this book presented a lot of information to readers, but no book can provide complete coverage of a topic. Between the second and third editions, we took notes on literally thousands of interesting problems wed solved or seen others solve. When we started to outline the third edition, it became clear that not only would full coverage of these topics require three to five thousand pages, but the book still wouldnt be complete. After reflecting on this problem, we realized that the second editions emphasis on deep coverage was actually self-limiting, in the sense that it often didnt teach readers how to think about MySQL.
As a result, this third edition has a different focus from the second edition. We still convey a lot of information, and we still emphasize the same goals, such as reliability and correctness. But weve also tried to imbue the book with a deeper purpose: we want to teach the principles of why MySQL works as it does, not just the facts about how it works. Weve included more illustrative stories and case studies, which demonstrate the principles in action. We build on these to try to answer questions such as Given MySQLs internal architecture and operation, what practical effects arise in real usage? Why do those effects matter? How do they make MySQL well suited (or not well suited) for particular needs?
Ultimately, we hope that your knowledge of MySQLs internals will help you in situations beyond the scope of this book. And we hope that your newfound insight will help you to learn and practice a methodical approach to designing, maintaining, and troubleshooting systems that are built on MySQL.
How This Book Is Organized
We fit a lot of complicated topics into this book. Here, we explain how we put them together in an order that makes them easier to learn.
A Broad Overview
is dedicated to the basicsthings youll need to be familiar with before you dig in deeply. You need to understand how MySQL is organized before youll be able to use it effectively. This chapter explains MySQLs architecture and key facts about its storage engines. It helps you get up to speed if you arent familiar with some of the fundamentals of a relational database, including transactions. This chapter will also be useful if this book is your introduction to MySQL but youre already familiar with another database, such as Oracle. We also include a bit of historical context: the changes to MySQL over time, recent ownership changes, and where we think its headed.
Building a Solid Foundation
The early chapters cover material we hope youll reference over and over as you use MySQL.
discusses the basics of benchmarkingthat is, determining what sort of workload your server can handle, how fast it can perform certain tasks, and so on. Benchmarking is an essential skill for evaluating how the server behaves under load, but its also important to know when its not useful.
introduces you to the response timeoriented approach we take to troubleshooting and diagnosing server performance problems. This framework has proven essential to solving some of the most puzzling cases weve seen. Although you might choose to modify our approach (we developed it by modifying Cary Millsaps approach, after all), we hope youll avoid the pitfalls of not having any method at all.
In Chapters wraps the topics together by explaining how MySQL executes queries and how you can take advantage of its query optimizers strengths. This chapter also presents specific examples of many common classes of queries, illustrating where MySQL does a good job and how to transform queries into forms that use its strengths.
Up to this point, weve covered the basic topics that apply to any database: tables, indexes, data, and queries. goes beyond the basics and shows you how MySQLs advanced features work. We examine topics such as partitioning, stored procedures, triggers, and character sets. MySQLs implementation of these features is different from other databases, and a good understanding of them can open up new opportunities for performance gains that you might not have thought about otherwise.