Share E-Book
Scan to open this page

Scan with your phone to open this page

AuthorGrant Fritchey

Troubleshoot slow-performing queries and make them run faster. Database administrators and SQL developers are constantly under pressure to provide more speed. This new edition has been redesigned and rewritten from scratch based on the last 15 years of learning, knowledge, and experience accumulated by the author. The book Includes expanded information on using extended events, automatic execution plan correction, and other advanced features now available in SQL Server. These modern features are covered while still providing the necessary fundamentals to better understand how statistics and indexes affect query performance. The book gives you knowledge and tools to help you identify poorly performing queries and understand the possible causes of that poor performance. The book also provides mechanisms for resolving the issues identified, whether on-premises, in containers, or on cloud platform providers. You’ll learn about key fundamentals, such as statistics, data distribution, cardinality, and parameter sniffing. You’ll learn to analyze and design your indexes and your queries using best practices that ward off performance problems before they occur. You’ll also learn to use important modern features, such as Query Store to manage and control execution plans, the automated performance tuning feature set, and memory-optimized OLTP tables and procedures. You will be able to troubleshoot in a systematic way. Query tuning doesn’t have to be difficult. This book helps you to make it much easier. What You Will Learn Use Query Store to understand and easily change query performance Recognize and eliminate bottlenecks leading to slow performance Tune queries whether on-premises, in containers, or on cloud platform providers Implement best practices in T-SQL to minimize performance risk Design in the performance that you need through careful query and index design Understand how built-in, automatic tuning can assist your performance enhancement efforts Protect query perf

AI Reading Assistant

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

AI guide
【One-Line Pitch】 A systematic, hands-on guide to diagnosing and fixing slow SQL Server queries, rewritten for SQL Server 2022 with modern tooling like Query Store and automatic tuning. Best for DBAs and T-SQL developers who already write queries and now need to make them fast. 【Book Arc】 - **Opening (~0%–15%)**: Frames query tuning as a repeatable process rather than a bag of tricks—defining "good enough," establishing baselines, and cataloging the usual suspects (weak indexes, stale statistics, bad T-SQL, problematic plans). Introduces the measurement toolkit: execution plans, SET STATISTICS TIME/IO, DMVs, Query Store, and Extended Events. - **Early (~15%–35%)**: Moves into the mechanics of plans and statistics—how to read an execution plan, how rowstore and nonindexed-column statistics are built and analyzed, and why cardinality estimates drive plan quality. This is the conceptual core that later chapters assume. - **Middle (~35%–60%)**: Covers recompilation control (plan forcing, query hints, plan guides, hint forcing) and index architecture, including rowstore vs. columnstore indexes, their benefits, and their overhead. Shifts from "why is it slow" toward "how do I design it right." - **Late (~60%–85%)**: Turns to concurrency and cost: reducing transaction cost via logging and locking, blocking and blocked processes (ACID, lock types, isolation levels, capturing blocking), deadlock causes and solutions, and cursor overhead with recommendations. - **Ending (~85%–100%)**: Modern features and consolidation—memory-optimized OLTP tables and natively compiled procedures, automatic index management, and a closing query tuning methodology spanning database design, constraints, index best practices, and configuration settings like memory and cost threshold for parallelism. 【Key Takeaways】 - **Tuning is a process, not a one-off fix** (Opening): the book opens by insisting on baselines, comparison points, and a definition of "good enough" before touching anything—without these you cannot tell improvement from noise. - **Statistics and cardinality estimates are the root of most plan problems** (Early): inaccurate or missing statistics and skewed data distribution mislead the optimizer, so understanding statistics headers and analysis is prerequisite to fixing plans. - **Measurement tooling has modernized** (Early): Extended Events, DMVs, Query Store, and execution-plan QueryTimeStats replace older Profiler-centric workflows; the book walks through creating sessions, targets, and causality tracking. - **Plan instability is controllable** (Middle): recompilation, parameter sniffing, plan forcing, query hints, and plan guides are presented as levers—each with trade-offs rather than as universal cures. - **Index design is where you prevent problems** (Middle): rowstore and columnstore indexes carry both benefit and overhead; the book treats index architecture as a design decision, not an afterthought. - **Concurrency costs are tunable** (Late): logging and locking overhead, blocking, isolation levels, and deadlocks are covered with capture techniques (T-SQL, Extended Events blocked_process_report, deadlock graphs) and concrete reduction recommendations. - **Cursors and row-by-row logic carry measurable overhead** (Late): the book weighs default result sets against cursors and offers recommendations rather than blanket bans. - **Modern SQL Server features can do part of the work** (Ending): memory-optimized OLTP tables, natively compiled procedures, and automatic index management are positioned as complements to—not replacements for—human tuning judgment. 【Reading Tips】 - Read the opening process chapter slowly; the baseline-and-measure discipline is what makes the rest of the book usable rather than a catalog of fixes. - Deep-read the statistics/cardinality and execution-plan chapters (Early); skim the tool-setup walkthroughs if you already use Extended Events and Query Store daily. - Treat the Middle chapters on hints, plan guides, and forcing as reference material—consult when a specific plan problem appears rather than memorizing syntax. - If you are primarily a developer, prioritize the design-oriented Ending methodology (constraints, index best practices, configuration settings) and the T-SQL best-practice guidance; DBAs should weight the blocking/deadlock chapters more heavily. - Keep the book beside a real slow query: each technique is far more memorable when applied to an actual plan you can capture and compare. 【Coverage Limits】 This guide is synthesized from the book's front matter, table of contents, and stratified excerpts; specific code samples, benchmark numbers, and chapter-level arguments beyond the listed topics are not covered here.
Excerpt 1
lement best practices in T-SQL to minimize performance risk Design in the performance that you need through careful query and index design Understand how bui...
View in text
Page 6
42 SET STATISTICS TIME/IO 43 QueryTimeStats in the Execution Plan 43 Trace Events (Profiler) 44 Dynamic Management Views 45 Actively Executing Queries 45 Pre...
View in text
Page 8
183 Plan Forcing 189 Table of ConTenTs
View in text
Page 5
302 Summary 303 Chapter 10: Index Behaviors 305 Covering Indexes 305 A Pseudoclustered Index 308 Recommendations 308 Index Intersection 308 Table of ConTenTs
View in text
Page 12
376 Automatic Maintenance 380 Summary 380 Chapter 13: Parameter-Sensitive Queries: Causes and Solutions 383 How Does Parameter Sniffing Work? 383 Identifying...
View in text
Page 14
497 Repeatable Read 499 Table of ConTenTs
View in text
Page 16
617 Table of ConTenTs
View in text
Page 19
rver (Apress), and Query Store for SQL Server 2019 (Apress). Grant presents live sessions, virtual sessions, and recorded content online, and in person, all...
View in text
Tags
AI categories
DatabaseSQLProgramming
ISBN: 1484288904
Publisher: Apress
Publish Year: 2022
Language: English
Pages: 731
File Format: PDF
File Size: 27.2 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…