• Tidak ada hasil yang ditemukan

A Systematic Method for Improving Execution Speeds

N/A
N/A
Andy Mkj

Academic year: 2024

Membagikan " A Systematic Method for Improving Execution Speeds"

Copied!
974
0
0

Teks penuh

(1)

MySQL 8 Query Performance

Tuning

A Systematic Method for Improving Execution Speeds

— Jesper Wisborg Krogh

(2)

MySQL 8 Query Performance Tuning

A Systematic Method for Improving Execution Speeds

Jesper Wisborg Krogh

www.allitebooks.com

(3)

Speeds

ISBN-13 (pbk): 978-1-4842-5583-4 ISBN-13 (electronic): 978-1-4842-5584-1 https://doi.org/10.1007/978-1-4842-5584-1

Copyright © 2020 by Jesper Wisborg Krogh

This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.

Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.

The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights.

While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein.

Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: Jonathan Gennick

Development Editor: Laura Berendson Coordinating Editor: Jill Balzano

Cover image designed by Freepik (www.freepik.com)

Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer- sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.

For information on translations, please e-mail [email protected], or visit http://www.apress.com/

rights-permissions.

Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales.

Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the book's product page, located at www.apress.com/9781484255834. For more detailed information, please visit http://www.apress.com/source-code.

Printed on acid-free paper Jesper Wisborg Krogh Hornsby, NSW, Australia

(4)

To the MySQL Support team, it has been a pleasure to work with you all.

www.allitebooks.com

(5)

v

Part I: Getting Started ������������������������������������������������������������������������������������� 1 Chapter 1: MySQL Performance Tuning �������������������������������������������������������������������� 3

Consider the Whole Stack ������������������������������������������������������������������������������������������������������������� 3 Monitoring ������������������������������������������������������������������������������������������������������������������������������������� 5 The Lifecycle of a Query���������������������������������������������������������������������������������������������������������������� 6 Summary��������������������������������������������������������������������������������������������������������������������������������������� 8

Chapter 2: Query Tuning Methodology���������������������������������������������������������������������� 9

Overview ��������������������������������������������������������������������������������������������������������������������������������������� 9 Verify the Problem ����������������������������������������������������������������������������������������������������������������������� 11 Determine the Cause ������������������������������������������������������������������������������������������������������������������ 11 Determine the Solution ��������������������������������������������������������������������������������������������������������������� 12 Implement the Solution ��������������������������������������������������������������������������������������������������������������� 13 Work Proactively ������������������������������������������������������������������������������������������������������������������������� 15 Summary������������������������������������������������������������������������������������������������������������������������������������� 16

Chapter 3: Benchmarking with Sysbench �������������������������������������������������������������� 19

Best Practices ����������������������������������������������������������������������������������������������������������������������������� 19 Standard TPC Benchmarks ��������������������������������������������������������������������������������������������������������� 22 Common Benchmarks Tools �������������������������������������������������������������������������������������������������������� 23 Sysbench Installation ������������������������������������������������������������������������������������������������������������������ 24 Executing Benchmarks ��������������������������������������������������������������������������������������������������������������� 32

Table of Contents

About the Author ��������������������������������������������������������������������������������������������������xxiii

About the Technical Reviewer �������������������������������������������������������������������������������xxv

Acknowledgments �����������������������������������������������������������������������������������������������xxvii

Introduction ����������������������������������������������������������������������������������������������������������xxix

(6)

vi

Creating Custom Benchmarks ���������������������������������������������������������������������������������������������������� 40 Overview of the Custom Script ���������������������������������������������������������������������������������������������� 41 Defining the Options �������������������������������������������������������������������������������������������������������������� 43 The run Command ����������������������������������������������������������������������������������������������������������������� 45 The prepare Command ���������������������������������������������������������������������������������������������������������� 48 The cleanup Command ���������������������������������������������������������������������������������������������������������� 50 Registering Commands ��������������������������������������������������������������������������������������������������������� 51 Summary������������������������������������������������������������������������������������������������������������������������������������� 53

Chapter 4: Test Data ����������������������������������������������������������������������������������������������� 55

Downloading the Example Databases ����������������������������������������������������������������������������������������� 55 The world Database �������������������������������������������������������������������������������������������������������������������� 56 Schema���������������������������������������������������������������������������������������������������������������������������������� 56 Installation ����������������������������������������������������������������������������������������������������������������������������� 57 The world_x Database ���������������������������������������������������������������������������������������������������������������� 58 Schema���������������������������������������������������������������������������������������������������������������������������������� 58 Installation ����������������������������������������������������������������������������������������������������������������������������� 59 The sakila Database �������������������������������������������������������������������������������������������������������������������� 60 Schema���������������������������������������������������������������������������������������������������������������������������������� 60 Installation ����������������������������������������������������������������������������������������������������������������������������� 66 The employees Database ������������������������������������������������������������������������������������������������������������ 67 Schema���������������������������������������������������������������������������������������������������������������������������������� 67 Installation ����������������������������������������������������������������������������������������������������������������������������� 71 Other Databases ������������������������������������������������������������������������������������������������������������������������� 72 Summary������������������������������������������������������������������������������������������������������������������������������������� 73

Part II: Sources of Information ��������������������������������������������������������������������� 75

Chapter 5: The Performance Schema ��������������������������������������������������������������������� 77

Terminology �������������������������������������������������������������������������������������������������������������������������������� 77 Threads ��������������������������������������������������������������������������������������������������������������������������������������� 78 Instruments ��������������������������������������������������������������������������������������������������������������������������������� 83 Consumers ���������������������������������������������������������������������������������������������������������������������������������� 85 Table of ConTenTs
(7)

Events ����������������������������������������������������������������������������������������������������������������������������������������� 87 Event Types ���������������������������������������������������������������������������������������������������������������������������� 88 Event Scopes ������������������������������������������������������������������������������������������������������������������������� 89 Event Nesting ������������������������������������������������������������������������������������������������������������������������ 90 Event Properties �������������������������������������������������������������������������������������������������������������������� 92 Actors and Objects ���������������������������������������������������������������������������������������������������������������������� 94 Digests ���������������������������������������������������������������������������������������������������������������������������������������� 94 Table Types ���������������������������������������������������������������������������������������������������������������������������������� 96 Dynamic Configuration ���������������������������������������������������������������������������������������������������������������� 97 Summary������������������������������������������������������������������������������������������������������������������������������������� 99

Chapter 6: The sys Schema ���������������������������������������������������������������������������������� 101

sys Schema Configuration �������������������������������������������������������������������������������������������������������� 101 Formatting Functions ���������������������������������������������������������������������������������������������������������������� 105 The Views ���������������������������������������������������������������������������������������������������������������������������������� 107 Helper Functions and Procedures ��������������������������������������������������������������������������������������������� 109 Summary����������������������������������������������������������������������������������������������������������������������������������� 110

Chapter 7: The Information Schema ��������������������������������������������������������������������� 111

What Is the Information Schema? ��������������������������������������������������������������������������������������������� 111 Privileges ���������������������������������������������������������������������������������������������������������������������������������� 112 Views ���������������������������������������������������������������������������������������������������������������������������������������� 113 System Information ������������������������������������������������������������������������������������������������������������� 113 Schema Information ������������������������������������������������������������������������������������������������������������ 115 Performance Information ���������������������������������������������������������������������������������������������������� 121 Privilege Information ����������������������������������������������������������������������������������������������������������� 126 Caching of Index Statistics Data ����������������������������������������������������������������������������������������������� 128 Summary����������������������������������������������������������������������������������������������������������������������������������� 131

Chapter 8: SHOW Statements ������������������������������������������������������������������������������� 133

Relationship to the Information Schema ����������������������������������������������������������������������������������� 133 Relationship to the Performance Schema��������������������������������������������������������������������������������� 135 Engine Status ���������������������������������������������������������������������������������������������������������������������������� 137
(8)

viii

Replication and Binary Logs ����������������������������������������������������������������������������������������������������� 139 Listing Binary Logs �������������������������������������������������������������������������������������������������������������� 139 Viewing Log Events ������������������������������������������������������������������������������������������������������������� 140 Show Connected Replicas ��������������������������������������������������������������������������������������������������� 145 Miscellaneous Statements �������������������������������������������������������������������������������������������������������� 146 Summary����������������������������������������������������������������������������������������������������������������������������������� 150

Chapter 9: The Slow Query Log����������������������������������������������������������������������������� 153

Configuration����������������������������������������������������������������������������������������������������������������������������� 154 Log Events��������������������������������������������������������������������������������������������������������������������������������� 158 Aggregation ������������������������������������������������������������������������������������������������������������������������������� 160 Summary����������������������������������������������������������������������������������������������������������������������������������� 164

Part III: Tools ����������������������������������������������������������������������������������������������� 165

Chapter 10 MySQL Enterprise Monitor ����������������������������������������������������������������� 167

Overview ����������������������������������������������������������������������������������������������������������������������������������� 167 Installation �������������������������������������������������������������������������������������������������������������������������������� 170 Download ����������������������������������������������������������������������������������������������������������������������������� 170 Installation Process ������������������������������������������������������������������������������������������������������������� 175 Starting and Stopping the Service Manager ����������������������������������������������������������������������������� 182 Microsoft Windows �������������������������������������������������������������������������������������������������������������� 183 Linux ������������������������������������������������������������������������������������������������������������������������������������ 184 Adding MySQL Instances ���������������������������������������������������������������������������������������������������������� 186 The Graphical User Interface����������������������������������������������������������������������������������������������������� 189 General Navigation �������������������������������������������������������������������������������������������������������������� 189 Advisors ������������������������������������������������������������������������������������������������������������������������������� 191 Timeseries Graphs ���������������������������������������������������

Gambar

Figure 1-2.  The basic query lifecycle
Figure 2-1 shows an example of how the performance tuning lifecycle can be  described
Figure 2-2.  Workflow to implement solution
Figure 2-3 shows how you can categorize your tasks into how urgent and how  important they are
+7

Referensi

Dokumen terkait

This study aims to improve students’ achievement in writing recount text by using Student Teams Achievement Division (STAD) method.. This Study was conducted by using classroom

The objective of this study was to investigate whether the application of Skimming Method improve the students’ achievement in Reading Comprehension.. This study

Related to the background mentioned, the researcher formulated a research question as follows: Does Prosody Pyramid method improve the students’ ability in pronunciation in terms of

The data that were obtained qualitatively and quantitatively show that Jolly Phonics Method could improve: (l) the students’ ability in remembering the letter that represent

Conclusion The Student Team Achievement Division STAD method can be an alternative method of guidance and counseling to improve student social interaction, it can be concluded that

Infusion phlebitis assessment method used in paediatric setting: a systematic review of literature ABSTRACT Introduction: Phlebitis may localise to the insertion site or travel

Thus, by considering the importance of students' grammar skills in learning English for university students, research needs to be done which analyzes how the Jigsaw Method can improve

57.9% of the students agreed that this method was effective, and 63.2% of the students were interested in using this method to improve their essay writing skill.. The findings on