Jason Strate
Hugo, MN, USA
Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the books product page, located at www.apress.com/9781484254639 . For more detailed information, please visit http://www.apress.com/source-code .
ISBN 978-1-4842-5463-9 e-ISBN 978-1-4842-5464-6
https://doi.org/10.1007/978-1-4842-5464-6
Jason Strate 2019
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.
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.
Introduction
Todays world is all about the data. From the applications to manage our lives to the analytics we use to guide our decisions, data is everywhere. Behind data, databases provide the engine to get to our data, but without the right indexes we lack the fuel to access our data efficiently.
When it comes to indexes, no single structure aids in retrieving data from a database more than an index. New features in SQL Server provide new and unique ways to leverage and access your data, but without going back to the basics and ensuring that the data is properly indexed, youll find that even the new features fail to live up to expectations.
Indexes represent both how data is stored and the access paths by which data can be retrieved from your database. Without indexes, a database is an unordered mess minus the roadmap to find the information you want.
Throughout my experience working on data platforms, one of the most common resolutions that I provide for performance tuning and application outages is to provide the right indexes for the underlying databases. Often, the effort of adding an index or two to the most accessed tables within a database provides significant performance improvementsmuch more so than tuning the database at a per SQL statement level. This is because an index affects many SQL statements that are being run against the database lifting performance across the workload.
Managing indexes may seem like an easy task. Unfortunately, their seeming simplicity is often the key to why they are overlooked. Often, there is an assumption from developers that the database administrators will take care of indexing. Or there is an assumption by the database administrators that the developers are building the necessary indexes as they develop features in their applications. While these are primarily cases of miscommunication, people need to know how to determine what indexes are necessary and the value of those indexes. This book provides that information.
Outside of the aforementioned scenarios is the fact that applications and the data they use change over time. Features created and used to tune the database may not be as useful as expected, or a small feature change may lead to a big change in how the application and underlying databases are used. All of this change affects the database and what needs to be accessed. As time goes on, databases and their indexes need to be reviewed to determine if the current indexing is accurate for the new load. This book also provides information in this regard.
Whats in This Book?
From beginning to end, this book provides information that helps build your skills from a novice at indexing to an expert. The chapters are laid out such that you can start at any place to fill in the gaps in your knowledge and build out from there. Whether you can barely spell index, need to understand the fundamentals, or need to build an indexing methodology, the information is available here.
Chaptercovers index fundamentals. It lays the groundwork for all of the following chapters. This chapter provides information regarding the types of indexes available in SQL Server. It covers some of the Primary index types and defines what these are and how to build them. The chapter also explores the options available that can change the structure of indexes. From fill factor to included columns, the available attributes are defined and explained.
Chapterpicks up where the previous chapter left off. Going beyond defining the indexes available, the chapter looks at the physical and logical structure of indexes and the components that make up indexes. This internal understanding of indexes provides the basis for grasping why indexes behave in certain ways in certain situations. As you examine the structures of indexes, youll become familiar with the tools you can use to begin digging into these structures on your own.
Armed with an understanding of the indexes available and how they are built, Chapterexplores the statistics that are stored on the indexes and how to use this information; these statistics provide insight into how SQL Server is utilizing indexes. The chapter also provides information necessary to decipher why an index may not be selected and why it is behaving in a certain way. You will gain a deeper understanding of how this information is collected by SQL Server through dynamic management views and what data is worthwhile to review.
Not every index type is fully discussed in the first chapter; the types not discussed are covered in Chapters.Beyond the rowstore and columnstore index structures, there are a few other index types which are Extensible Markup Language (XML), spatial, full-text, and semantic search. These indexes are applicable to specific situations. In these chapters, youll look into these other index types to understand what they have to offer. Youll also look at situations where they should be implemented.