Название: SQL Server Execution Plans, Third Edition Автор: Grant Fritchey Издательство: Red Gate Books ISBN: 1910035246 Год: 2018 Страниц: 515 Язык: английский Формат: True PDF Размер: 23.64 MB
If a query is performing poorly, and you can't understand why, then that query's execution plan will tell you not only what data set is coming back, but also what SQL Server did, and in what order, to get that data. It will reveal how the data was retrieved, and from which tables and indexes, what types of joins were used, at what point filtering, sorting and aggregation occurred, and a whole lot more. These details will often highlight the likely source of any problem.
I wrote this book with the singular goal of teaching you how to read SQL Server Execution plans It will explain, among many other things, the following: How to capture execution plans using manual and automatic methods A documented method for reading and interpreting execution plans How common SQL Server objects, such as indexes, views, stored procedures, and so on, appear in execution plans How to control execution plans with hints and plan guides, and why this is a double-edged sword How the Query Store works with, and collects data on, execution plans
Frequently, a T-SQL query you wrote behaves in ways you don't expect, and causes slow response times for the application users, and resource contention on the server. Sometimes, you didn't write the offending query; it came from a third-party application, or was code generated by an improperly-used Object Relational Mapping layer. In any of these situations, and a thousand others, query tuning becomes quite difficult.
Often, it's very hard to tell, just by looking at the T-SQL code, why a query is running slowly. SQL is a declarative language, and a T-SQL query describes only the set of data that we want SQL Server to return. It does not tell SQL Server how to execute the query, to retrieve that data.
When we submit a query to SQL Server, several server processes kick into action whose collective job is to manage the querying or modification of the data. Specifically, a component of the relational database engine called the Query Optimizer has the job of examining the submitted query text and defining a strategy for executing it. The strategy takes the form of an execution plan, which contains a series of operators, each describing an action to perform on the data.
With this knowledge, you'll have everything you need to read the execution plan, for any query of your own, regardless of complexity, and understand what it does and what is causing the bad performance. It is still your job to work out how best to fix it, but your new understanding of execution plans will give a much better chance of success!