Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Daniel Nichter

Rating No ratings yet

You'll find several books on basic or advanced MySQL performance, but nothing in between. That's because explaining MySQL performance without addressing its complexity is difficult. This practical book bridges the gap by teaching software engineers mid-level MySQL knowledge beyond the fundamentals, but well shy of deep-level internals required by database administrators (DBAs). Daniel Nichter shows you how to apply the best practices and techniques that directly affect MySQL performance. You'll learn how to improve performance by analyzing query execution, indexing for common SQL clauses and table joins, optimizing data access, and understanding the most important MySQL metrics. You'll also discover how replication, transactions, row locking, and the cloud influenceMySQL performance. Understand why query response time is the North Star of MySQL performance Learn query metrics in detail, including aggregation, reporting, and analysis See how to index effectively for common SQL clauses and table joins Explore the most important server metrics and what they reveal about performance Dive into transactions and row locking to gain deep, actionable insight Achieve remarkable MySQL performance at any scale

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
# Efficient MySQL Performance — Reading Guide ## 【One-Line Pitch】 A practical, mid-level guide for software engineers who know MySQL basics but need to move beyond them—teaching you how to analyze query performance, design effective indexes, and understand the metrics that actually matter, without diving into DBA-level internals. ## 【Book Arc】 - **Opening (~0%–9%)**: Establishes query response time as the "North Star" of MySQL performance and introduces the core query metrics—query time, lock time, query count, rows examined, and rows sent—along with the event hierarchy (transactions → statements → stages → waits) and the importance of metadata like EXPLAIN plans. - **Early (~16%–28%)**: Explains why indexes are the single most important factor in MySQL performance, using a simple example table to illustrate how InnoDB tables are really indexes, how the leftmost prefix requirement works, and how indexes optimize WHERE, GROUP BY, and ORDER BY clauses. - **Early-to-Middle (~28%–38%)**: Covers joins and index management—how MySQL joins tables in optimal order (not query order), why full joins are the worst thing a query can do, and the dangers of too many, duplicate, or unused indexes, plus tools like pt-duplicate-key-checker and the sys schema to find them. - **Middle (~38%–47%)**: Shifts to indirect query optimization—optimizing around the query rather than the query itself—covering data size, working set size and memory allocation (10% of total data as a starting point), why less data is better, and specific optimizations like ORDER BY…LIMIT. ## 【Key Takeaways】 - **Query response time is the North Star of MySQL performance** (Opening): All other metrics—lock time, rows examined, rows sent—are subordinate to response time. Lock time is included in query time, but beware: it's accurate only in the slow query log, not the Performance Schema. - **Query metrics alone are insufficient; you need metadata** (Opening): A complete query analysis requires at least the EXPLAIN plan and table structures. The "low and slow" combination (few executions, high response time) often signals a manually executed or programmatically generated query worth investigating. - **Indexes provide the greatest performance leverage** (Early): Hardware gives the least leverage, optimizations more, and indexes the most—without them, performance is limited to brute force. The book's example of a team buying faster cloud hardware until costs became stratospheric illustrates this perfectly. - **An InnoDB table is really an index** (Early): Understanding that tables are structured as indexes (primary key + secondary indexes) is fundamental. Scanning a secondary index in order doesn't guarantee sequential reads—primary key lookups are almost certainly random reads. - **The leftmost prefix requirement governs index usage** (Early): Indexes only help when queries use a leftmost prefix of the index columns. Violating this (e.g., WHERE on column b when the index is on a, b) forces MySQL to use temporary tables and lose the optimization. - **Filesort is usually not the root cause of slow queries** (Early): Despite its reputation, sorting rows is very fast. MySQL can optimize ORDER BY using an ordered index in three ways, and EXPLAIN ANALYZE (MySQL 8.0.18+) can measure the real-time penalty. - **Too many indexes hurt write performance** (Middle): Each index must be checked, updated, and potentially reorganized on every write. Use invisible indexes (MySQL 8.0+) to verify an index is truly unused before dropping it. - **Less data is better for everything** (Middle): Data size affects performance, management, and cost. Working set size—not total data size—determines memory needs; when it exceeds available memory, even indexes stop helping and sharding becomes necessary. ## 【Reading Tips】 - **Skim the opening chapter's event hierarchy** (~0%–9%): The transaction → statement → stage → wait hierarchy is useful context, but you don't need to memorize it. Focus instead on understanding what each query metric means and its limitations. - **Deep-read Chapter 2 on indexes** (~16%–38%): This is the heart of the book. Work through the table elem examples carefully—they build on each other. Pay special attention to the leftmost prefix requirement and how EXPLAIN output (rows is an estimate, not actual matches) can mislead. - **Use the join section as a reference** (~34%–38%): The key insight—MySQL joins tables in optimal order, not query order—is worth internalizing. The full join warning is critical: it's the single worst thing a query can do. - **Skim the data storage checklist** (~44%–47%): The "less data is better" principle and the 10% memory allocation guideline are practical heuristics worth remembering, but the storage audit details are less critical for everyday work. - **Take away the tooling** (throughout): pt-duplicate-key-checker, sys.schema_unused_indexes, SHOW WARNINGS, and invisible indexes are immediately actionable. Note these tools as you encounter them. ## 【Coverage Limits】 The excerpts cover roughly the first half of the book (through Chapter 3 on data). Later chapters on replication, transactions, row locking, and cloud performance are mentioned in the blurb but not covered in this guide. ##
Page 9
d me, taught me, and provided opportunities over the years: Peter Zaitsev, Baron Schwartz, Ryan Lowe, Bill Karwin, Emily Slocombe, Morgan Tocker, Shlomi Noac...
View in text
Excerpt 2
izations. Without indexes, performance is severely limited. To illustrate these points, think of MySQL as a fulcrum that leverages hardware, optimizations, a...
View in text
Excerpt 3
ns as usual, but these index columns also point back to the corresponding columns in the SELECT clause to signify that the values for these columns are read ...
View in text
Excerpt 4
query. Worst case: MySQL reads all rows because none match. But for this simple example, we can see that the first two rows (id values 8 and 9) will match th...
View in text
Excerpt 5
trait is quite simple, it’s important because knowing if an application is read-heavy or write-heavy quickly focuses your attention on relevant application c...
View in text
Excerpt 6
ns that are MySQL-compatible: TiDB and CockroachDB. Both of these solutions are exceptionally new for a data store: CockroachDB v1.0 GA released May 10, 2017...
View in text
Excerpt 7
l WHERE id=75 2022-03-01T00:06:51.165127Z 32 Close stmt Finally, the number of open prepared statements is limited to var.max_ pre pared_ stmt_count, wh...
View in text
Excerpt 8
pool). Start with the slowest queries in the query profile. If your query metric tool reports query load, fo
View in text
Tags
AI categories
DatabaseSQLBackend
ISBN: 1098105087
Publish Year: 2021
Language: English
Pages: 483
File Format: PDF
File Size: 4.8 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…