About the Author |
|
xxiii | |
About the Technical Reviewer |
|
xxv | |
Acknowledgments |
|
xxvii | |
Introduction |
|
xxix | |
|
|
1 | (2) |
|
Chapter 1 MySQL Performance Tuning |
|
|
3 | (6) |
|
|
3 | (2) |
|
|
5 | (1) |
|
|
6 | (2) |
|
|
8 | (1) |
|
Chapter 2 Query Tuning Methodology |
|
|
9 | (10) |
|
|
9 | (2) |
|
|
11 | (1) |
|
|
11 | (1) |
|
|
12 | (1) |
|
|
13 | (2) |
|
|
15 | (1) |
|
|
16 | (3) |
|
Chapter 3 Benchmarking with Sysbench |
|
|
19 | (36) |
|
|
19 | (3) |
|
|
22 | (1) |
|
|
23 | (1) |
|
|
24 | (8) |
|
|
32 | (8) |
|
Creating Custom Benchmarks |
|
|
40 | (13) |
|
Overview of the Custom Script |
|
|
41 | (2) |
|
|
43 | (2) |
|
|
45 | (3) |
|
|
48 | (2) |
|
|
50 | (1) |
|
|
51 | (2) |
|
|
53 | (2) |
|
|
55 | (20) |
|
Downloading the Example Databases |
|
|
55 | (1) |
|
|
56 | (2) |
|
|
56 | (1) |
|
|
57 | (1) |
|
|
58 | (2) |
|
|
58 | (1) |
|
|
59 | (1) |
|
|
60 | (7) |
|
|
60 | (6) |
|
|
66 | (1) |
|
|
67 | (5) |
|
|
67 | (4) |
|
|
71 | (1) |
|
|
72 | (1) |
|
|
73 | (2) |
|
Part II Sources of Information |
|
|
75 | (2) |
|
Chapter 5 The Performance Schema |
|
|
77 | (24) |
|
|
77 | (1) |
|
|
78 | (5) |
|
|
83 | (2) |
|
|
85 | (2) |
|
|
87 | (7) |
|
|
88 | (1) |
|
|
89 | (1) |
|
|
90 | (2) |
|
|
92 | (2) |
|
|
94 | (1) |
|
|
94 | (2) |
|
|
96 | (1) |
|
|
97 | (2) |
|
|
99 | (2) |
|
|
101 | (10) |
|
|
101 | (4) |
|
|
105 | (2) |
|
|
107 | (2) |
|
Helper Functions and Procedures |
|
|
109 | (1) |
|
|
110 | (1) |
|
Chapter 7 The Information Schema |
|
|
111 | (22) |
|
What Is the Information Schema? |
|
|
111 | (1) |
|
|
112 | (1) |
|
|
113 | (15) |
|
|
113 | (2) |
|
|
115 | (6) |
|
|
121 | (5) |
|
|
126 | (2) |
|
Caching of Index Statistics Data |
|
|
128 | (3) |
|
|
131 | (2) |
|
Chapter 8 SHOW Statements |
|
|
133 | (20) |
|
Relationship to the Information Schema |
|
|
133 | (2) |
|
Relationship to the Performance Schema |
|
|
135 | (2) |
|
|
137 | (2) |
|
Replication and Binary Logs |
|
|
139 | (7) |
|
|
139 | (1) |
|
|
140 | (5) |
|
|
145 | (1) |
|
|
146 | (4) |
|
|
150 | (3) |
|
Chapter 9 The Slow Query Log |
|
|
153 | (12) |
|
|
154 | (4) |
|
|
158 | (2) |
|
|
160 | (4) |
|
|
164 | (1) |
|
|
165 | (108) |
|
Chapter 10 MySQL Enterprise Monitor |
|
|
167 | (32) |
|
|
167 | (3) |
|
|
170 | (12) |
|
|
170 | (5) |
|
|
175 | (7) |
|
Starting and Stopping the Service Manager |
|
|
182 | (4) |
|
|
183 | (1) |
|
|
184 | (2) |
|
|
186 | (3) |
|
The Graphical User Interface |
|
|
189 | (8) |
|
|
189 | (2) |
|
|
191 | (2) |
|
|
193 | (2) |
|
|
195 | (2) |
|
|
197 | (2) |
|
Chapter 11 MySQL Workbench |
|
|
199 | (28) |
|
|
199 | (17) |
|
|
200 | (7) |
|
|
207 | (5) |
|
|
212 | (4) |
|
|
216 | (2) |
|
|
218 | (5) |
|
|
218 | (2) |
|
|
220 | (1) |
|
|
221 | (1) |
|
|
222 | (1) |
|
|
223 | (3) |
|
|
226 | (1) |
|
|
227 | (46) |
|
|
227 | (9) |
|
|
228 | (1) |
|
|
228 | (1) |
|
|
229 | (3) |
|
|
232 | (1) |
|
|
233 | (2) |
|
|
235 | (1) |
|
|
236 | (9) |
|
|
236 | (3) |
|
|
239 | (3) |
|
Powerline and Awesome Fonts |
|
|
242 | (3) |
|
|
245 | (3) |
|
|
248 | (13) |
|
Report Information and Help |
|
|
249 | (1) |
|
|
250 | (2) |
|
|
252 | (9) |
|
|
261 | (9) |
|
|
270 | (3) |
|
Part IV Schema Considerations and the Query Optimizer |
|
|
273 | (266) |
|
|
275 | (22) |
|
|
275 | (5) |
|
|
276 | (2) |
|
|
278 | (1) |
|
|
278 | (1) |
|
|
279 | (1) |
|
|
280 | (1) |
|
|
280 | (13) |
|
|
281 | (2) |
|
|
283 | (1) |
|
String and Binary Data Types |
|
|
284 | (3) |
|
|
287 | (2) |
|
|
289 | (1) |
|
|
290 | (3) |
|
|
293 | (1) |
|
Which Data Type Should You Choose? |
|
|
293 | (3) |
|
|
296 | (1) |
|
|
297 | (50) |
|
|
297 | (1) |
|
|
298 | (5) |
|
|
299 | (1) |
|
|
299 | (1) |
|
|
300 | (1) |
|
|
301 | (1) |
|
|
301 | (1) |
|
|
302 | (1) |
|
|
303 | (1) |
|
|
304 | (5) |
|
Creating Tables with Indexes |
|
|
305 | (1) |
|
|
306 | (1) |
|
|
307 | (2) |
|
What Are the Drawbacks of Indexes? |
|
|
309 | (2) |
|
|
309 | (1) |
|
|
310 | (1) |
|
|
310 | (1) |
|
|
311 | (17) |
|
|
312 | (3) |
|
|
315 | (1) |
|
|
316 | (2) |
|
|
318 | (5) |
|
|
323 | (5) |
|
|
328 | (7) |
|
|
328 | (1) |
|
|
329 | (2) |
|
|
331 | (1) |
|
|
332 | (1) |
|
|
332 | (3) |
|
|
335 | (1) |
|
|
335 | (3) |
|
|
336 | (1) |
|
|
336 | (1) |
|
|
337 | (1) |
|
|
337 | (1) |
|
|
338 | (6) |
|
When Should You Add or Remove Indexes? |
|
|
338 | (2) |
|
Choice of the Primary Key |
|
|
340 | (1) |
|
|
341 | (1) |
|
|
342 | (1) |
|
|
343 | (1) |
|
|
344 | (3) |
|
Chapter 15 Index Statistics |
|
|
347 | (38) |
|
What Are Index Statistics? |
|
|
347 | (1) |
|
InnoDB and Index Statistics |
|
|
348 | (5) |
|
How Statistics Are Collected |
|
|
348 | (1) |
|
|
349 | (2) |
|
Transaction Isolation Level |
|
|
351 | (1) |
|
Configuring Statistics Type |
|
|
352 | (1) |
|
Persistent Index Statistics |
|
|
353 | (9) |
|
|
353 | (3) |
|
|
356 | (6) |
|
Transient Index Statistics |
|
|
362 | (1) |
|
|
363 | (14) |
|
Information Schema STATISTICS View |
|
|
363 | (3) |
|
|
366 | (4) |
|
The Information Schema INNODBJABLESTATS View |
|
|
370 | (2) |
|
The Information Schema TABLES View and SHOW TABLE STATUS |
|
|
372 | (5) |
|
|
377 | (7) |
|
|
377 | (1) |
|
The ANALYZE TABLE Statement |
|
|
378 | (2) |
|
|
380 | (4) |
|
|
384 | (1) |
|
|
385 | (32) |
|
|
385 | (1) |
|
When Should You Add Histograms? |
|
|
386 | (3) |
|
|
389 | (7) |
|
|
389 | (1) |
|
|
390 | (4) |
|
|
394 | (2) |
|
Adding and Maintaining Histograms |
|
|
396 | (5) |
|
Create and Update Histograms |
|
|
397 | (2) |
|
|
399 | (1) |
|
|
400 | (1) |
|
Inspecting Histogram Data |
|
|
401 | (2) |
|
Histogram Reporting Examples |
|
|
403 | (8) |
|
|
403 | (1) |
|
List All Information for a Single Histogram |
|
|
404 | (2) |
|
List Bucket Information for a Singleton Histogram |
|
|
406 | (3) |
|
List Bucket Information for an Equi-height Histogram |
|
|
409 | (2) |
|
|
411 | (4) |
|
|
415 | (2) |
|
Chapter 17 The Query Optimizer |
|
|
417 | (70) |
|
|
418 | (1) |
|
|
419 | (7) |
|
The Basics: Single Table SELECT |
|
|
419 | (2) |
|
|
421 | (1) |
|
Default Filtering Effects |
|
|
422 | (1) |
|
|
423 | (3) |
|
|
426 | (17) |
|
|
426 | (6) |
|
|
432 | (4) |
|
|
436 | (7) |
|
|
443 | (19) |
|
|
443 | (9) |
|
|
452 | (2) |
|
|
454 | (2) |
|
|
456 | (6) |
|
Configuring the Optimizer |
|
|
462 | (14) |
|
|
462 | (2) |
|
|
464 | (2) |
|
|
466 | (3) |
|
|
469 | (5) |
|
|
474 | (1) |
|
|
475 | (1) |
|
|
476 | (8) |
|
Retrieving Information About Resource Groups |
|
|
477 | (1) |
|
|
478 | (3) |
|
Assigning Resource Groups |
|
|
481 | (2) |
|
Performance Considerations |
|
|
483 | (1) |
|
|
484 | (3) |
|
Chapter 18 Locking Theory and Monitoring |
|
|
487 | (52) |
|
|
488 | (1) |
|
|
488 | (1) |
|
|
489 | (25) |
|
|
489 | (3) |
|
|
492 | (2) |
|
|
494 | (4) |
|
|
498 | (1) |
|
|
499 | (3) |
|
|
502 | (3) |
|
Gap Locks, Next-Key Locks, and Predicate Locks |
|
|
505 | (2) |
|
|
507 | (3) |
|
|
510 | (1) |
|
|
511 | (2) |
|
|
513 | (1) |
|
|
514 | (7) |
|
Metadata and Backup Lock Wait Timeouts |
|
|
515 | (1) |
|
InnoDB Lock Wait Timeouts |
|
|
516 | (1) |
|
|
517 | (4) |
|
|
521 | (7) |
|
|
521 | (1) |
|
|
522 | (2) |
|
|
524 | (1) |
|
Transaction Isolation Levels |
|
|
524 | (4) |
|
|
528 | (1) |
|
|
528 | (9) |
|
|
528 | (2) |
|
|
530 | (1) |
|
Status Counters and InnoDB Metrics |
|
|
531 | (1) |
|
InnoDB Lock Monitor and Deadlock Logging |
|
|
532 | (5) |
|
|
537 | (2) |
|
|
539 | (220) |
|
Chapter 19 Finding Candidate Queries for Optimization |
|
|
541 | (60) |
|
|
542 | (25) |
|
The Statement Event Tables |
|
|
542 | (9) |
|
Prepared Statements Summary |
|
|
551 | (4) |
|
|
555 | (6) |
|
|
561 | (4) |
|
|
565 | (2) |
|
|
567 | (16) |
|
|
568 | (3) |
|
|
571 | (2) |
|
|
573 | (3) |
|
Statement Performance Analyzer |
|
|
576 | (7) |
|
|
583 | (4) |
|
|
584 | (2) |
|
Client Connections Report |
|
|
586 | (1) |
|
|
587 | (10) |
|
|
587 | (5) |
|
|
592 | (2) |
|
|
594 | (3) |
|
|
597 | (2) |
|
|
599 | (2) |
|
Chapter 20 Analyzing Queries |
|
|
601 | (82) |
|
|
601 | (4) |
|
Usage for Explicit Queries |
|
|
602 | (1) |
|
|
603 | (1) |
|
|
604 | (1) |
|
|
605 | (20) |
|
|
607 | (3) |
|
|
610 | (4) |
|
|
614 | (5) |
|
|
619 | (6) |
|
|
625 | (18) |
|
|
626 | (4) |
|
|
630 | (2) |
|
|
632 | (7) |
|
|
639 | (4) |
|
|
643 | (11) |
|
|
643 | (1) |
|
Single Table, Index Access |
|
|
644 | (2) |
|
Two Tables and a Covering Index |
|
|
646 | (2) |
|
|
648 | (2) |
|
Two Tables with Subquery and Sorting |
|
|
650 | (4) |
|
|
654 | (4) |
|
Performance Schema Events Analysis |
|
|
658 | (22) |
|
Examining a Stored Procedure |
|
|
659 | (7) |
|
|
666 | (3) |
|
Analysis with the sys.ps_trace_thread() Procedure |
|
|
669 | (5) |
|
Analysis with the ps_trace_statement_digest() Procedure |
|
|
674 | (6) |
|
|
680 | (3) |
|
|
683 | (30) |
|
|
683 | (4) |
|
|
684 | (1) |
|
|
685 | (2) |
|
|
687 | (6) |
|
|
693 | (2) |
|
INNODBJVIETRICS and sys.metrics |
|
|
695 | (4) |
|
Performance Schema Transactions |
|
|
699 | (12) |
|
Transaction Events and Their Statements |
|
|
699 | (10) |
|
Transaction Summary Tables |
|
|
709 | (2) |
|
|
711 | (2) |
|
Chapter 22 Diagnosing Lock Contention |
|
|
713 | (46) |
|
|
714 | (9) |
|
|
714 | (1) |
|
|
715 | (1) |
|
|
716 | (1) |
|
|
716 | (5) |
|
|
721 | (1) |
|
|
722 | (1) |
|
Metadata and Schema Locks |
|
|
723 | (13) |
|
|
723 | (1) |
|
|
724 | (1) |
|
|
724 | (1) |
|
|
725 | (10) |
|
|
735 | (1) |
|
|
735 | (1) |
|
|
736 | (8) |
|
|
736 | (4) |
|
|
740 | (1) |
|
|
740 | (1) |
|
|
741 | (2) |
|
|
743 | (1) |
|
|
744 | (1) |
|
|
744 | (14) |
|
|
745 | (1) |
|
|
745 | (1) |
|
|
746 | (1) |
|
|
747 | (10) |
|
|
757 | (1) |
|
|
757 | (1) |
|
|
758 | (1) |
|
Part VI Improving the Queries |
|
|
759 | (188) |
|
|
761 | (32) |
|
|
761 | (5) |
|
|
766 | (2) |
|
|
768 | (11) |
|
|
770 | (3) |
|
|
773 | (1) |
|
|
773 | (1) |
|
|
774 | (3) |
|
|
777 | (2) |
|
|
779 | (6) |
|
|
780 | (1) |
|
|
781 | (4) |
|
|
785 | (1) |
|
|
786 | (1) |
|
Internal Temporary Tables |
|
|
787 | (4) |
|
|
791 | (2) |
|
Chapter 24 Change the Query Plan |
|
|
793 | (60) |
|
|
793 | (1) |
|
Symptoms of Excessive Full Table Scans |
|
|
794 | (2) |
|
|
796 | (3) |
|
|
799 | (14) |
|
Not a Left Prefix of Index |
|
|
800 | (4) |
|
|
804 | (5) |
|
|
809 | (4) |
|
|
813 | (15) |
|
|
813 | (2) |
|
|
815 | (11) |
|
Rewriting Complex Index Conditions |
|
|
826 | (2) |
|
Rewriting Complex Queries |
|
|
828 | (13) |
|
|
829 | (6) |
|
|
835 | (3) |
|
|
838 | (1) |
|
Splitting a Query Into Parts |
|
|
839 | (2) |
|
Queue System: SKIP LOCKED |
|
|
841 | (3) |
|
|
844 | (7) |
|
|
851 | (2) |
|
Chapter 25 DDL and Bulk Data Load |
|
|
853 | (36) |
|
|
853 | (4) |
|
|
854 | (2) |
|
|
856 | (1) |
|
Dropping or Truncating Tables |
|
|
857 | (1) |
|
General Data Load Considerations |
|
|
857 | (15) |
|
Insert in Primary Key Order |
|
|
872 | (6) |
|
Auto-increment Primary Key |
|
|
872 | (2) |
|
|
874 | (2) |
|
|
876 | (2) |
|
InnoDB Buffer Pool and Secondary Indexes |
|
|
878 | (2) |
|
|
880 | (3) |
|
Transactions and Load Method |
|
|
883 | (1) |
|
MySQL Shell Parallel Load Data |
|
|
883 | (4) |
|
|
887 | (2) |
|
|
889 | (28) |
|
|
890 | (2) |
|
|
892 | (11) |
|
|
894 | (3) |
|
|
897 | (4) |
|
|
901 | (1) |
|
|
902 | (1) |
|
|
903 | (4) |
|
|
903 | (1) |
|
|
904 | (1) |
|
|
905 | (1) |
|
|
906 | (1) |
|
|
907 | (6) |
|
|
907 | (3) |
|
|
910 | (1) |
|
|
911 | (1) |
|
|
912 | (1) |
|
Offloading Work to a Replica |
|
|
913 | (2) |
|
|
914 | (1) |
|
|
914 | (1) |
|
|
915 | (2) |
|
|
917 | (30) |
|
|
917 | (2) |
|
|
919 | (5) |
|
|
919 | (3) |
|
|
922 | (2) |
|
|
924 | (10) |
|
|
925 | (4) |
|
MySQL InnoDB Memcached Plugin |
|
|
929 | (5) |
|
|
934 | (10) |
|
|
944 | (1) |
|
|
944 | (3) |
Index |
|
947 | |