Indexes
-
Upload
randy-riness-south-puget-sound-community-college -
Category
Education
-
view
434 -
download
1
description
Transcript of Indexes
IndexesCIS282
IndexesHelp to select and find recordsServe as a “cross-reference”Can be based on one or more fields
Types of IndexesClustered: How table is physically ordered
Only one per tableNon-Clustered: Index is maintained
separately from table (data)Can be stored in a separate file group to speed
access (find pointers using one drive, find records on a second drive)
Index OrganizationData in SQL Server is organized by ‘pages’When an index entry is inserted in a full page
the data is split between two pagesBy default each page is filled to allow two
additions
Fill FactorAllows you to specify how much ‘room’ to
leave open on each pageSpecify the percentage of each page that is
used initially to store dataImpacts how often page splits occur
OLTP should have low percentageOLAP should have high percentage
“Good Index” CharacteristicsLow maintenance columns
Values don’t change frequentlyIncludes columns used frequently in Where
clauseDon’t have to go out to table for data
Covered indexes include multiple columns where related data is commonly used
Help search for ranges of records
“Poor Index” CharacteristicsColumns not used in queries (where clause)Index doesn’t return one or few rows
(selectivity)Exception: indexing foreign keys can speed up
joins significantlyMany columns in indexFew records in table
Unique Constraint v. Unique IndexNo significant differences between creating a
unique constraint and a unique indexData validation occurs in the same mannerQuery optimizer does not differentiate
between a unique index created by a constraint or created manually
Unique Constraint or Unique Index?A unique index makes sense when
uniqueness is a characteristic of the dataKnow that will always have a different
valueIf uniqueness must be enforced to ensure
data integrity, create a unique constraintNeed to ensure that have a different
valueUnique constraint allows null
Null treated as a value so can only occur once