Expert Performance Indexing in SQL Server 2019: Toward Faster Results and Lower Maintenance 3rd Edition Jason Strate 2024 Scribd Download
Expert Performance Indexing in SQL Server 2019: Toward Faster Results and Lower Maintenance 3rd Edition Jason Strate 2024 Scribd Download
com
https://textbookfull.com/product/expert-performance-
indexing-in-sql-server-2019-toward-faster-results-and-lower-
maintenance-3rd-edition-jason-strate/
OR CLICK BUTTON
DOWNLOAD NOW
https://textbookfull.com/product/high-performance-sql-server-the-go-
faster-book-1st-edition-benjamin-nevarez-auth/
textboxfull.com
https://textbookfull.com/product/expert-sql-server-in-memory-oltp-2nd-
edition-dmitri-korotkevitch/
textboxfull.com
Practical Maintenance Plans in SQL Server Automation for
the DBA Beard
https://textbookfull.com/product/practical-maintenance-plans-in-sql-
server-automation-for-the-dba-beard/
textboxfull.com
https://textbookfull.com/product/expert-scripting-and-automation-for-
sql-server-dbas-springerlink-online-service/
textboxfull.com
https://textbookfull.com/product/sql-server-execution-plans-for-sql-
server-2008-through-to-2017-and-azure-sql-database-3rd-edition-grant-
fritchey/
textboxfull.com
https://textbookfull.com/product/practical-maintenance-plans-in-sql-
server-automation-for-the-dba-1st-edition-bradley-beard/
textboxfull.com
https://textbookfull.com/product/expert-scripting-and-automation-for-
sql-server-dbas-1st-edition-peter-a-carter-auth/
textboxfull.com
Jason Strate
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.
Summary
As previously mentioned, data is important, and indexes provide the
way for you to get to that data. Through the chapters in this book, you
will become armed with what you need to know about the indexes in
your environment. You will also learn how to find the information you
need to improve the performance of your environment.
Table of Contents
Chapter 1:Index Fundamentals
Why Build Indexes?
Major Index Types
Heap Tables
Clustered Indexes
Nonclustered Indexes
Columnstore Indexes
Other Index Types
JSON and XML Indexes
Spatial Indexes
Hash and Range Indexes
Full-Text Search
Index Variations
Primary Key
Unique Index
Included Columns
Partitioned Indexes
Filtered Indexes
Compression and Indexing
Index Data Definition Language
Creating an Index
Altering an Index
Dropping an Index
Index Metadata
sys.indexes
sys.index_columns
sys.index_resumable_operations
sys.xml:indexes
sys.selective_xml:index_paths
sys.selective_xml:index_namespaces
sys.spatial_indexes
sys.spatial_index_tessellations
sys.column_store_dictionaries
sys.column_store_segments
sys.column_store_row_groups
sys.hash_indexes
sys.fulltext_catalogs
sys.fulltext_indexes
sys.fulltext_index_columns
Summary
Chapter 2:Index Storage Fundamentals
Storage Basics
Pages
Extents
Page Types
File Header Page
Boot Page
Page Free Space Page
Global Allocation Map Page
Shared Global Allocation Map Page
Differential Changed Map Page
Minimally Logged Page
Index Allocation Map Page
Data Page
Index Page
Large Object Page
Organizing Pages
Heap Structure
B-Tree Structure
Columnstore Structure
Examining Pages
Dynamic Management Functions
DBCC Commands
Page Fragmentation
Forwarded Records
Page Splits
Index Characteristics
Heap
Clustered Index
Nonclustered Index
Columnstore Index
Summary
Chapter 3:Index Metadata and Statistics
Column-Level Statistics
DBCC SHOW_STATISTICS
Catalog Views
STATS_DATE
sys.dm_db_stats_properties
sys.dm_db_stats_histogram
sys.dm_db_incremental_stats_properties
Statistics DDL
Colum-Level Statistics Summary
Index Usage Statistics
Header Columns
User Columns
System Columns
Index Usage Stats Summary
Index Operational Statistics
Header Columns
DML Activity
SELECT Activity
Locking Contention
Latch Contention
Page Allocation Cycle
Compression
LOB Access
Row Version
Index Operational Stats Summary
Index Physical Statistics
Header Columns
Row Statistics
Fragmentation Statistics
Index Physical Stats Summary
Columnstore Statistics
Columnstore Physical Stats
Columnstore Operational Stats
Summary
Chapter 4:XML Indexes
XML Data
Benefits
Cautions
XML Indexes
Primary/Secondary XML Indexes
Selective XML Indexes
Summary
Chapter 5:Spatial Indexing
How Spatial Data Is Indexed
Creating Spatial Indexes
Supporting Methods with Indexes
Understanding Statistics, Properties, and Information
The Views
The Procedures
Tuning Spatial Indexes
Restrictions on Spatial Indexes
Summary
Chapter 6:Indexing Memory-Optimized Tables
Memory-Optimized Tables Overview
Hash Indexes
Range Indexes
Summary
Chapter 7:Full-Text Indexing
Full-Text Indexing
Creating a Full-Text Example
Creating a Full-Text Catalog
Creating a Full-Text Index
Full-Text Search Index Catalog Views and Properties
Summary
Chapter 8:Indexing Myths and Best Practices
Index Myths
Myth 1:Databases Don’t Need Indexes
Myth 2:Primary Keys Are Always Clustered
Myth 3:Online Index Operations Don’t Block
Myth 4:Any Column Can Be Filtered in Multicolumn Indexes
Myth 5:Clustered Indexes Store Records in Physical Order
Myth 6:Indexes Always Output in the Same Order
Myth 7:Fill Factor Is Applied to Indexes During Inserts
Myth 8:Deleting from Heaps Results in Unrecoverable
Space
Myth 9:Every Table Should Have a Heap/Clustered Index
Index Best Practices
Index to Your Current Workload
Use Clustered Indexes on Primary Keys by Default
Specify Fill Factors
Index Foreign Key Columns
Balance Index Count
Summary
Chapter 9:Index Maintenance
Index Fragmentation
Fragmentation Operations
Fragmentation Variants
Fragmentation Issues
Defragmentation Options
Defragmentation Strategies
Preventing Fragmentation
Index Statistics Maintenance
Automatically Maintaining Statistics
Manually Maintaining Statistics
Summary
Chapter 10:Indexing Tools
Missing Indexes
Explaining the DMOs
Using the DMOs
Database Engine Tuning Advisor
Explaining the DTA
Using the DTA GUI
Using the DTA Utility
Summary
Chapter 11:Indexing Strategies
Heaps
Temporary Objects
Other Heap Scenarios
Clustered Indexes
Identity Sequence
Natural Key
Foreign Key
Multiple Column
Globally Unique Identifier
Nonclustered Indexes
Search Columns
Index Intersection
Multiple Column
Covering Index
Included Columns
Filtered Indexes
Foreign Keys
Columnstore Index
JSON Indexing
Index Storage Strategies
Row Compression
Page Compression
Indexed Views
Summary
Chapter 12:Query Strategies
LIKE Comparison
Concatenation
Computed Columns
Scalar Functions
Data Conversion
Summary
Chapter 13:Monitoring Indexes
Performance Counters
Dynamic Management Objects
Index Usage Stats
Index Operational Stats
Index Physical Stats
Wait Statistics
Data Cleanup
Event Tracing
SQL Trace
Extended Events
Query Store
Summary
Chapter 14:Index Analysis
Review of Server State
Performance Counters
Wait Statistics
Buffer Allocation
Schema Discovery
Identify Heaps
Duplicate Indexes
Overlapping Indexes
Unindexed Foreign Keys
Uncompressed Indexes
Database Engine Tuning Advisor
Unused Indexes
Index Plan Usage
Summary
Chapter 15:Indexing Methodology
The Indexing Method
Implement
Communication
Deployment Scripts
Execution
Repeat
Summary
Index
About the Author and About the Technical
Reviewer
1. Index Fundamentals
Jason Strate1
The goal of this book is to help you improve the performance of your
databases through the use of indexes. In order to accomplish this, you
must first understand what indexes are and why you need them. You
need to understand the differences between how data in a clustered
index, columnstore index, and heap table is stored. You also will look at
how nonclustered and other index types are built and how indexes
interact with other indexes. This chapter will provide the building
blocks for understanding the logical design of indexes.
Heap Tables
As mentioned in the library analogy, in a Little Free Library, the books
available change often; usually there are only one or two short shelves
of books. In these cases, the owner doesn’t spend time organizing the
books under the Dewey Decimal system. Instead, the books are placed
on the shelves as they are acquired. In this case, there is no order to
how the books are stored in the library. When SQL Server stores data in
a table in a similar fashion, when the data lacks an ordered structure, it
is referred to as a heap .
In a heap, the first row added to the index is the first record in the
table, the second row is the second record in the table, the third row is
the third record in the table, and so on. There is nothing in the data that
is used to specify the order in which the data has been added. The data
and records are in the table without any particular order.
When a table is first created, the initial storage structure is called a
heap. This is probably the simplest storage structure. Rows are inserted
into the table in the order in which they are added. A table uses a heap
until a clustered index or clustered columnstore index is created on the
table or the table is created as memory-optimized, discussed in Chapter
7. A table can be a heap only if there are no other index types that
define how the base data is stored on the table. Only a single heap
structure is allowed per table.
Clustered Indexes
In the library analogy, you reviewed how the Dewey Decimal system
defines how books are sorted and stored in the library. Regardless of
when the book is added to the library, with the Dewey Decimal system,
it is assigned a number based on its subject and placed on the shelf
between other books of the same subject. The subject of the book, not
when it is added, determines the location of the book. This structure is
the most direct method to find a book within the library. In the context
of a table, the index that provides this functionality in a database is
called a clustered index.
With a clustered index , one or more columns are selected as the key
columns for the index. Key columns are used to sort and determine
where to locate data in the table. Where a library places books on the
shelves based on their Dewey Decimal number, a clustered index
determines the location of records in the table based on the logical
order of the key columns of the index.
The columns used as the key columns for a clustered index are
selected based on the most frequently used method for accessing the
records in the table. For instance, in a table with states and provinces,
the most common method of finding a record in the table would
probably be through its abbreviation. In that situation, using the
abbreviation for the clustering key column would be best. With most
tables, the primary key or business key will serve as the clustered index
key columns.
As with heaps, clustered indexes determine where data is located in
a table. In a clustered index, the data outside the key columns is stored
alongside the key columns. This equates to the clustered index
determining the physical table itself, just as a heap defines the table.
Due to this, a table cannot have more than one clustered index.
Nonclustered Indexes
As was noted in my analogy, the Dewey Decimal system doesn’t account
for every way in which a person may need to search for a book. If the
author or title is known but not the subject, then the classification
doesn’t really provide any value. Libraries solve this problem with card
catalogs, which provide a place to cross-reference the classification
number of a book with the name of the author or the book title.
Databases are also able to solve this problem with nonclustered
indexes.
In a nonclustered index , columns are selected and sorted based on
their values. These columns contain a reference to the heap or clustered
index location of the data they are related to. This is nearly identical to
how a card catalog works in a library. The order of the books, or the
records in the tables, doesn’t change, but a shortcut to the data is
created based on the other search criteria.
Nonclustered indexes do not have the same restrictions as heaps
and clustered indexes. There can be many nonclustered indexes on a
table, in fact up to 999 nonclustered indexes. This allows alternative
routes to be created for users to get to the data they need without
having to traverse all records in a table. Just because a table can have
many indexes doesn’t mean that it should, as I’ll discuss later in this
book.
Columnstore Indexes
One of the problems with card catalogs in large libraries is that there
could be dozens or hundreds of index cards that match a title of a book.
Each of these index cards contains information such as the author,
subject, title, International Standard Book Number (ISBN), page count,
and publishing date, along with the Dewey Decimal number. In nearly
all cases, this additional information is not needed, but it’s there to help
filter out index cards when necessary.
Imagine if instead of dozens or hundreds of index cards to look at,
you had a few cards that had only the title and Dewey Decimal number
or only the subject and Dewey Decimal number. Basically, instead of
storing all attributes together, you stored them separately with an
identifier, like a Dewey Decimal number, included to link them back
together again. For each attribute, where you previously would have
had to look through dozens or hundreds of index cards, you instead are
left with a few consolidated index cards. This type of index would be
called a columnstore index .
Columnstore indexes were new to SQL Server 2012 and greatly
expanded in following SQL Server releases. Traditionally, indexes are
stored in row-based organization, also known as rowstore. This form of
storage is extremely efficient when one row or a small range is
requested. When a large range or all rows are returned, rowstores can
become inefficient, especially when there are aggregations or few
columns are required. The columnstore index favors the return of large
ranges of rows by storing data in column-wise organization.
When you create a columnstore index, you include all the columns
in a table. This ensures that all columns are included in the enhanced
performance benefits of the columnstore organization. In a
columnstore index, instead of storing all the columns for a record
together, each column is stored separately with all the other rows in an
index. The benefit of this type of index is that only the columns and
rows required for a query need to be read. In data warehousing
scenarios, often less than 15 percent of the columns in an index are
needed for the results of a query.1
Because of their structure, columnstore indexes provide significant
value for data warehousing. Consider first that the index accesses only
the columns required to execute the query. Additionally, compression is
greatly improved since data within a single column has a higher
likelihood for similarity. Between these two aspects, columnstore
indexes provide significant performance improvements. I’ll discuss
these in more depth in later chapters.
. . . . . .
The song goes on to tell the sad story of her death while her
“pitying comrades” were carrying her home to die, and ends:—
When I look back into the factory life of fifty or sixty years ago, I
do not see what is called “a class” of young men and women going
to and from their daily work, like so many ants that cannot be
distinguished one from another; I see them as individuals, with
personalities of their own. This one has about her the atmosphere of
her early home. That one is impelled by a strong and noble purpose.
The other,—what she is, has been an influence for good to me and
to all womankind.
Yet they were a class of factory operatives, and were spoken of
(as the same class is spoken of now) as a set of persons who earned
their daily bread, whose condition was fixed, and who must continue
to spin and to weave to the end of their natural existence. Nothing
but this was expected of them, and they were not supposed to be
capable of social or mental improvement. That they could be
educated and developed into something more than mere work-
people, was an idea that had not yet entered the public mind. So
little does one class of persons really know about the thoughts and
aspirations of another! It was the good fortune of these early mill-
girls to teach the people of that time that this sort of labor is not
degrading; that the operative is not only “capable of virtue,” but also
capable of self-cultivation.
At the time the Lowell cotton-mills were started, the factory girl
was the lowest among women. In England, and in France
particularly, great injustice had been done to her real character; she
was represented as subjected to influences that could not fail to
destroy her purity and self-respect. In the eyes of her overseer she
was but a brute, a slave, to be beaten, pinched, and pushed about.
It was to overcome this prejudice that such high wages had been
offered to women that they might be induced to become mill-girls, in
spite of the opprobrium that still clung to this “degrading
occupation.” At first only a few came; for, though tempted by the
high wages to be regularly paid in “cash,” there were many who still
preferred to go on working at some more genteel employment at
seventy-five cents a week and their board.
But in a short time the prejudice against factory labor wore away,
and the Lowell mills became filled with blooming and energetic New
England women. They were naturally intelligent, had mother-wit,
and fell easily into the ways of their new life. They soon began to
associate with those who formed the community in which they had
come to live, and were invited to their houses. They went to the
same church, and sometimes married into some of the best families.
Or if they returned to their secluded homes again, instead of being
looked down upon as “factory girls” by the squire’s or the lawyer’s
family, they were more often welcomed as coming from the
metropolis, bringing new fashions, new books, and new ideas with
them.
In 1831 Lowell was little more than a factory village. Several
corporations were started, and the cotton-mills belonging to them
were building. Help was in great demand; and stories were told all
over the country of the new factory town, and the high wages that
were offered to all classes of work-people,—stories that reached the
ears of mechanics’ and farmers’ sons, and gave new life to lonely
and dependent women in distant towns and farmhouses. Into this
Yankee El Dorado, these needy people began to pour by the various
modes of travel known to those slow old days. The stage-coach and
the canal-boat came every day, always filled with new recruits for
this army of useful people. The mechanic and machinist came, each
with his home-made chest of tools, and oftentimes his wife and little
ones. The widow came with her little flock and her scanty
housekeeping goods to open a boarding-house or variety store, and
so provided a home for her fatherless children. Many farmers’
daughters came to earn money to complete their wedding outfit, or
buy the bride’s share of housekeeping articles.
Women with past histories came, to hide their griefs and their
identity, and to earn an honest living in the “sweat of their brow.”
Single young men came, full of hope and life, to get money for an
education, or to lift the mortgage from the home-farm. Troops of
young girls came by stages and baggage-wagons, men often being
employed to go to other States and to Canada, to collect them at so
much a head, and deliver them at the factories.
A very curious sight these country girls presented to young eyes
accustomed to a more modern style of things. When the large
covered baggage-wagon arrived in front of a block on the
corporation, they would descend from it, dressed in various and
outlandish fashions, and with their arms brimful of bandboxes
containing all their worldly goods. On each of these was sewed a
card, on which one could read the old-fashioned New England name
of the owner. And sorrowful enough they looked, even to the fun-
loving child who has lived to tell the story; for they had all left their
pleasant country homes to try their fortunes in a great
manufacturing town, and they were homesick even before they
landed at the doors of their boarding-houses. Years after, this scene
dwelt in my memory; and whenever anyone said anything about
being homesick, there rose before me the picture of a young girl
with a sorrowful face and a big tear in each eye, clambering down
the steps at the rear of a great covered wagon, holding fast to a
cloth-covered bandbox, drawn up at the top with a string, on which
was sewed a paper bearing the name of Plumy Clay!
Some of these girls brought diminutive hair trunks covered with
the skin of calves, spotted in dun and white, even as when they did
skip and play in daisy-blooming meads. And when several of them
were set together in front of one of the blocks, they looked like their
living counterparts, reposing at noontide in the adjacent field. One of
this kind of trunks has been handed down to me as an heirloom.
The hair is worn off in patches; it cannot be invigorated, and it is
now become a hairless heirloom. Within its hide-bound sides are
safely stowed away the love-letters of a past generation,—love-
letters that agitated the hearts of the grandparents of to-day; and I
wonder that their resistless ardor has not long ago burst its wrinkled
sides. It is relegated to distant attics, with its ancient crony, “ye
bandbox,” to enjoy an honored and well-earned repose.
Ah me! when some of us, its contemporaries, are also past our
usefulness, gone clean out of fashion, may we also be as resigned,
yea, as willing, to be laid quietly on some attic shelf!
These country girls had queer names, which added to the
singularity of their appearance. Samantha, Triphena, Plumy, Kezia,
Aseneth, Elgardy, Leafy, Ruhamah, Lovey, Almaretta, Sarepta, and
Florilla were among them.
Their dialect was also very peculiar. On the broken English and
Scotch of their ancestors was ingrafted the nasal Yankee twang; so
that many of them, when they had just come daown, spoke a
language almost unintelligible. But the severe discipline and ridicule
which met them was as good as a school education, and they were
soon taught the “city way of speaking.”
Their dress was also peculiar, and was of the plainest of
homespun, cut in such an old-fashioned style that each young girl
looked as if she had borrowed her grandmother’s gown. Their only
head-covering was a shawl, which was pinned under the chin; but
after the first pay-day, a “shaker” (or “scooter”) sunbonnet usually
replaced this primitive head-gear of their rural life.
But the early factory girls were not all country girls. There were
others also, who had been taught that “work is no disgrace.” There
were some who came to Lowell solely on account of the social or
literary advantages to be found there. They lived in secluded parts of
New England, where books were scarce, and there was no cultivated
society. They had comfortable homes, and did not perhaps need the
money they would earn; but they longed to see this new “City of
Spindles,” of which they had heard so much from their neighbors
and friends, who had gone there to work.
And the fame of the circulating libraries, that were soon opened,
drew them and kept them there, when no other inducement would
have been sufficient.
The laws relating to women were such, that a husband could
claim his wife wherever he found her, and also the children she was
trying to shield from his influence; and I have seen more than one
poor woman skulk behind her loom or her frame when visitors were
approaching the end of the aisle where she worked. Some of these
were known under assumed names, to prevent their husbands from
trusteeing their wages. It was a very common thing for a male
person of a certain kind to do this, thus depriving his wife of all her
wages, perhaps, month after month. The wages of minor children
could be trusteed, unless the children (being fourteen years of age)
were given their time. Women’s wages were also trusteed for the
debts of their husbands, and children’s for the debts of their parents.
As an instance, my mother had some financial difficulties when I
was fifteen years old, and to save herself and me from annoyance,
she gave me my time. The document reads as follows:—
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com