SlideShare a Scribd company logo
Using indexes
Index architecture
clustered
nonclustered
CREATE INDEX (T-SQL)
Useful tips
Index options
Spatial indexes

1
Index architecture

2
Index architecture

3
Index architecture (clustered)

4
Index architecture (nonclustered)

5
CREATE INDEX (T-SQL)
CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX
index_name
ON <object> ( column [ ASC | DESC ] [ ,...n ] )
[ INCLUDE ( column_name [ ,...n ] ) ]
[ WHERE <filter_predicate> ]
[ WITH ( <relational_index_option> [ ,...n ] ) ]
[ ON { partition_scheme_name ( column_name )
| filegroup_name
| default
}
]
[ FILESTREAM_ON { filestream_filegroup_name |
partition_scheme_name | "NULL" } ]

!
[;]

6
CREATE INDEX (T-SQL)
<relational_index_option> ::=
{
PAD_INDEX = { ON | OFF }
| FILLFACTOR = fillfactor
| SORT_IN_TEMPDB = { ON | OFF }
| IGNORE_DUP_KEY = { ON | OFF }
| STATISTICS_NORECOMPUTE = { ON | OFF }
| DROP_EXISTING = { ON | OFF }
| ONLINE = { ON | OFF }
| ALLOW_ROW_LOCKS = { ON | OFF }
| ALLOW_PAGE_LOCKS = { ON | OFF }
| MAXDOP = max_degree_of_parallelism
| DATA_COMPRESSION = { NONE | ROW | PAGE}
[ ON PARTITIONS ( { <partition_number_expression> | <range> }
[ , ...n ] ) ]
}
7
Useful tips
Consider using a clustered index for queries that do the following:

!
•
•
•
•

Return a range of values by using operators such as BETWEEN, >, >=, <, and <=.
Return large result sets.
Use JOIN clauses; typically these are foreign key columns.
Use ORDER BY, or GROUP BY clauses.

•
•
•
•

Are unique or contain many distinct values
Are accessed sequentially
Defined as IDENTITY because the column is guaranteed to be unique within the table.
Used frequently to sort the data retrieved from a table.

•
•

Columns that undergo frequent changes
Wide keys

!
Consider columns that have one or more of the following attributes:
!

!
Clustered indexes are not a good choice for the following attributes:
!

8
Useful tips
Consider the characteristics of the database when designing nonclustered indexes.

!

• Databases or tables with low update requirements, but large volumes of data can benefit
from many nonclustered indexes to improve query performance. Consider creating filtered
indexes for well-defined subsets of data to improve query performance, reduce index storage
costs, and reduce index maintenance costs compared with full-table nonclustered indexes.
• Online Transaction Processing applications and databases that contain heavily updated
tables should avoid over-indexing. Additionally, indexes should be narrow, that is, with as few
columns as possible.

!
Consider using a nonclustered index for queries that have the following attributes:
!

• Use JOIN or GROUP BY clauses.
• Queries that do not return large result sets.
• Contain columns frequently involved in search conditions of a query, such as WHERE clause,
that return exact matches.

!
Consider columns that have one or more of these attributes:
!

• Cover the query.
• Lots of distinct values, such as a combination of last name and first name, if a clustered index
is used for other columns.

9
Useful tips
Query in which the
column predicate is
one of these
Exact match to a specific
value

Query description and example

Index to consider

Searches for an exact match in which the query uses the WHERE
Nonclustered or
clause to specify a column entry with a specific value. For example: clustered index on the
Id column.

! Id, [Login], Email FROM Users WHERE Id = 202
SELECT

Searches for an exact match to a value in a specified list of values.
Exact match to a value in an For example:
IN (x,y,z) list

! Id, [Login], Email FROM Users WHERE Id IN (603, 658, 1371)
SELECT

Nonclustered or
clustered index on the
Id column.

Searches for a range of values in which the query specifies any entry
that has a value between two values. For example:

Range of values

! Id, UserId, CreateDate, Content FROM Posts WHERE CreateDate
SELECT
>= '2013-03-01 12:00' AND CreateDate <= '2013-03-01 12:30‘
!
Or
! Id, UserId, CreateDate, Content FROM Posts WHERE CreateDate
SELECT

Clustered or
nonclustered index on
the CreateDate column.

BETWEEN '2013-03-01 12:00' AND '2013-03-01 12:30'

Join between tables

Searches for rows in a table that match a row in another table based
Nonclustered or
on a join predicate. For example:
clustered index on the
Id and UserId columns.
SELECT u.Id, u.[Login], p.Content

!

FROM Users u JOIN Posts p ON u.Id = p.UserId WHERE u.Id = 202

10
Useful tips
Query in which the
column predicate is
one of these
LIKE comparison

Sorted or aggregated

PRIMARY KEY or UNIQUE
constraint

Query description and example
Searches for matching rows that start with a specific character
string such as 'abc%'. For example:

! Id, [Login], Email FROM Users WHERE [Login] LIKE 'ma%'
SELECT

Nonclustered or
clustered index on the
Login column.

Nonclustered or
Requires an implicit or explicit sort order or an aggregation (GROUP clustered index on the
BY). For example:
sorted or aggregated
column.
SELECT p.Id, p.UserId, u.[Login], p.Content
For sort columns,
FROM Posts p JOIN Users u ON p.UserId = u.Id
consider specifying the
ORDER BY p.UserId, p.CreateDate
ASC or DESC order of
Searches for duplicates of new index key values in insert and update Clustered or
operations, to enforce PRIMARY KEY and UNIQUE constraints. For
nonclustered index on
example:
the column or columns

!

! Users ([Login], [Password], Email)
INSERT

VALUES ('xdfyht', 'dh4G57hn1', 'xdfyht@gmail.com')

UPDATE or DELETE operation Searches for rows in an update or delete operation in which the
in a PRIMARY KEY/FOREIGN column participates in a PRIMARY KEY/FOREIGN KEY relationship,
KEY relationship
with or without the CASCADE option.
Contains one or more columns in the select list that are not used for
searching and lookups. For example:
Column is in the select list
but not in the predicate.

Index to consider

! UserId, CreateDate, Content FROM Posts
SELECT

WHERE UserId = 202 ORDER BY CreateDate DESC

defined in the
constraint.
Nonclustered or
clustered index on the
foreign key column.
Nonclustered index with
Content specified in the
INCLUDE clause.

11
Index options (fill factor)

12
Index options (included columns)

13
Index options (filtered)
Views vs. Filtered Indexes
Allowed in expressions

Views

Filtered indexes

Computed columns

Yes

No

Joins

Yes

No

Multiple tables

Yes

No

Simple comparison logic in a predicate

Yes

Yes

Complex logic in a predicate

Yes

No

14
Spatial indexes

15
Spatial indexes

16
Spatial indexes

17
Spatial indexes

18
Spatial indexes (conditions)
•
•
•
•
•
•
•
•

geometry1.STContains(geometry2) = 1
geometry1.STDistance(geometry2) < @r
geometry1.STDistance(geometry2) <= @r
geometry1.STEquals(geometry2) = 1
geometry1.STIntersects(geometry2) = 1
geometry1.STOverlaps(geometry2) = 1
geometry1.STTouches(geometry2) = 1
geometry1.STWithin(geometry2) = 1

•
•
•
•

geography1.STEquals(geography2) = 1
geography1.STDistance(geography2) < @r
geography1.STDistance(geography2) <= @r
geography1.STIntersects(geography2) = 1
19
about:me
http://
unknowntransfer.blogspot.com
akor@ciklum.com
Skype: unknowntransfer

20

More Related Content

What's hot

Database index by Reema Gajjar
Database index by Reema GajjarDatabase index by Reema Gajjar
Database index by Reema Gajjar
Reema Gajjar
 
Indexes: The Second Pillar of Database Wisdom
Indexes: The Second Pillar of Database WisdomIndexes: The Second Pillar of Database Wisdom
Indexes: The Second Pillar of Database Wisdom
gisborne
 
Database indexing framework
Database indexing frameworkDatabase indexing framework
Database indexing framework
Nitin Pande
 
Columnstore indexes in sql server 2014
Columnstore indexes in sql server 2014Columnstore indexes in sql server 2014
Columnstore indexes in sql server 2014
Antonios Chatzipavlis
 
Sql server ___________session_17(indexes)
Sql server  ___________session_17(indexes)Sql server  ___________session_17(indexes)
Sql server ___________session_17(indexes)
Ehtisham Ali
 
dotnetMALAGA - Sql query tuning guidelines
dotnetMALAGA - Sql query tuning guidelinesdotnetMALAGA - Sql query tuning guidelines
dotnetMALAGA - Sql query tuning guidelines
Javier García Magna
 
Sql server lesson6
Sql server lesson6Sql server lesson6
Sql server lesson6
Ala Qunaibi
 
Database indexing techniques
Database indexing techniquesDatabase indexing techniques
Database indexing techniques
ahmadmughal0312
 
9. index and index organized table
9. index and index organized table9. index and index organized table
9. index and index organized table
Amrit Kaur
 
Dynamic Data Validation Lists
Dynamic Data Validation ListsDynamic Data Validation Lists
Dynamic Data Validation Lists
Marc Rivait, PMP
 
Effective Use of Excel
Effective Use of ExcelEffective Use of Excel
Effective Use of Excel
Sanjay Visanji Chheda
 
MySQL: Indexing for Better Performance
MySQL: Indexing for Better PerformanceMySQL: Indexing for Better Performance
MySQL: Indexing for Better Performance
jkeriaki
 
New slides access
New slides accessNew slides access
New slides access
jooomalaga
 
Sql server 2014 x velocity – updateable columnstore indexes
Sql server 2014 x velocity – updateable columnstore indexesSql server 2014 x velocity – updateable columnstore indexes
Sql server 2014 x velocity – updateable columnstore indexes
Pat Sheehan
 
Tunning sql query
Tunning sql queryTunning sql query
Tunning sql query
vuhaininh88
 
Advance microsoft excel institute in delhi
Advance microsoft excel institute in delhiAdvance microsoft excel institute in delhi
Advance microsoft excel institute in delhi
Vidya Topa Institute of Professional Studies
 
Dynamic Publishing with Arbortext Data Merge
Dynamic Publishing with Arbortext Data MergeDynamic Publishing with Arbortext Data Merge
Dynamic Publishing with Arbortext Data Merge
Clay Helberg
 

What's hot (20)

Database index by Reema Gajjar
Database index by Reema GajjarDatabase index by Reema Gajjar
Database index by Reema Gajjar
 
Indexes: The Second Pillar of Database Wisdom
Indexes: The Second Pillar of Database WisdomIndexes: The Second Pillar of Database Wisdom
Indexes: The Second Pillar of Database Wisdom
 
Database indexing framework
Database indexing frameworkDatabase indexing framework
Database indexing framework
 
Columnstore indexes in sql server 2014
Columnstore indexes in sql server 2014Columnstore indexes in sql server 2014
Columnstore indexes in sql server 2014
 
Sql server ___________session_17(indexes)
Sql server  ___________session_17(indexes)Sql server  ___________session_17(indexes)
Sql server ___________session_17(indexes)
 
dotnetMALAGA - Sql query tuning guidelines
dotnetMALAGA - Sql query tuning guidelinesdotnetMALAGA - Sql query tuning guidelines
dotnetMALAGA - Sql query tuning guidelines
 
Sql server lesson6
Sql server lesson6Sql server lesson6
Sql server lesson6
 
Index Tuning
Index TuningIndex Tuning
Index Tuning
 
Database indexing techniques
Database indexing techniquesDatabase indexing techniques
Database indexing techniques
 
9. index and index organized table
9. index and index organized table9. index and index organized table
9. index and index organized table
 
SQL_Part1
SQL_Part1SQL_Part1
SQL_Part1
 
Dynamic Data Validation Lists
Dynamic Data Validation ListsDynamic Data Validation Lists
Dynamic Data Validation Lists
 
Effective Use of Excel
Effective Use of ExcelEffective Use of Excel
Effective Use of Excel
 
MySQL: Indexing for Better Performance
MySQL: Indexing for Better PerformanceMySQL: Indexing for Better Performance
MySQL: Indexing for Better Performance
 
New slides access
New slides accessNew slides access
New slides access
 
Sql server 2014 x velocity – updateable columnstore indexes
Sql server 2014 x velocity – updateable columnstore indexesSql server 2014 x velocity – updateable columnstore indexes
Sql server 2014 x velocity – updateable columnstore indexes
 
Tunning sql query
Tunning sql queryTunning sql query
Tunning sql query
 
Advance microsoft excel institute in delhi
Advance microsoft excel institute in delhiAdvance microsoft excel institute in delhi
Advance microsoft excel institute in delhi
 
Dynamic Publishing with Arbortext Data Merge
Dynamic Publishing with Arbortext Data MergeDynamic Publishing with Arbortext Data Merge
Dynamic Publishing with Arbortext Data Merge
 
Select Queries
Select QueriesSelect Queries
Select Queries
 

Viewers also liked

Scaling the Content Repository with Elasticsearch
Scaling the Content Repository with ElasticsearchScaling the Content Repository with Elasticsearch
Scaling the Content Repository with Elasticsearch
Nuxeo
 
Elasticsearch and Symfony Integration - Debarko De
Elasticsearch and Symfony Integration - Debarko DeElasticsearch and Symfony Integration - Debarko De
Elasticsearch and Symfony Integration - Debarko De
Debarko De
 
Index in sql server
Index in sql serverIndex in sql server
Index in sql server
Durgaprasad Yadav
 
Before you optimize: Understanding Execution Plans
Before you optimize: Understanding Execution PlansBefore you optimize: Understanding Execution Plans
Before you optimize: Understanding Execution Plans
Timothy Corey
 
Discovering ElasticSearch
Discovering ElasticSearchDiscovering ElasticSearch
Discovering ElasticSearch
Ben Corlett
 
Strategies for SQL Server Index Analysis
Strategies for SQL Server Index AnalysisStrategies for SQL Server Index Analysis
Strategies for SQL Server Index Analysis
Jason Strate
 
Presentation interpreting execution plans for sql statements
Presentation    interpreting execution plans for sql statementsPresentation    interpreting execution plans for sql statements
Presentation interpreting execution plans for sql statements
xKinAnx
 
Consultas en MS SQL Server 2012
Consultas en MS SQL Server 2012Consultas en MS SQL Server 2012
Consultas en MS SQL Server 2012
CarlosFloresRoman
 
MS SQL SERVER: Creating Views
MS SQL SERVER: Creating ViewsMS SQL SERVER: Creating Views
MS SQL SERVER: Creating Views
sqlserver content
 
Sql db optimization
Sql db optimizationSql db optimization
Sql db optimization
Nikhildas P C
 
Using grouping sets in sql server 2008 tech republic
Using grouping sets in sql server 2008   tech republicUsing grouping sets in sql server 2008   tech republic
Using grouping sets in sql server 2008 tech republicKaing Menglieng
 
Sql tuning guideline
Sql tuning guidelineSql tuning guideline
Sql tuning guidelineSidney Chen
 
e computer notes - Subqueries
e computer notes - Subqueriese computer notes - Subqueries
e computer notes - Subqueriesecomputernotes
 
Sub-queries,Groupby and having in SQL
Sub-queries,Groupby and having in SQLSub-queries,Groupby and having in SQL
Sub-queries,Groupby and having in SQL
Vikash Sharma
 
Overview of query evaluation
Overview of query evaluationOverview of query evaluation
Overview of query evaluationavniS
 

Viewers also liked (20)

Scaling the Content Repository with Elasticsearch
Scaling the Content Repository with ElasticsearchScaling the Content Repository with Elasticsearch
Scaling the Content Repository with Elasticsearch
 
Elasticsearch and Symfony Integration - Debarko De
Elasticsearch and Symfony Integration - Debarko DeElasticsearch and Symfony Integration - Debarko De
Elasticsearch and Symfony Integration - Debarko De
 
Index in sql server
Index in sql serverIndex in sql server
Index in sql server
 
Before you optimize: Understanding Execution Plans
Before you optimize: Understanding Execution PlansBefore you optimize: Understanding Execution Plans
Before you optimize: Understanding Execution Plans
 
Discovering ElasticSearch
Discovering ElasticSearchDiscovering ElasticSearch
Discovering ElasticSearch
 
Strategies for SQL Server Index Analysis
Strategies for SQL Server Index AnalysisStrategies for SQL Server Index Analysis
Strategies for SQL Server Index Analysis
 
Presentation interpreting execution plans for sql statements
Presentation    interpreting execution plans for sql statementsPresentation    interpreting execution plans for sql statements
Presentation interpreting execution plans for sql statements
 
Consultas en MS SQL Server 2012
Consultas en MS SQL Server 2012Consultas en MS SQL Server 2012
Consultas en MS SQL Server 2012
 
MS SQL SERVER: Creating Views
MS SQL SERVER: Creating ViewsMS SQL SERVER: Creating Views
MS SQL SERVER: Creating Views
 
Sql db optimization
Sql db optimizationSql db optimization
Sql db optimization
 
Joins SQL Server
Joins SQL ServerJoins SQL Server
Joins SQL Server
 
Using grouping sets in sql server 2008 tech republic
Using grouping sets in sql server 2008   tech republicUsing grouping sets in sql server 2008   tech republic
Using grouping sets in sql server 2008 tech republic
 
Sql tuning guideline
Sql tuning guidelineSql tuning guideline
Sql tuning guideline
 
Sql xp 04
Sql xp 04Sql xp 04
Sql xp 04
 
Statistics
StatisticsStatistics
Statistics
 
e computer notes - Subqueries
e computer notes - Subqueriese computer notes - Subqueries
e computer notes - Subqueries
 
Sub-queries,Groupby and having in SQL
Sub-queries,Groupby and having in SQLSub-queries,Groupby and having in SQL
Sub-queries,Groupby and having in SQL
 
Locking in SQL Server
Locking in SQL ServerLocking in SQL Server
Locking in SQL Server
 
Overview of query evaluation
Overview of query evaluationOverview of query evaluation
Overview of query evaluation
 
Review of SQL
Review of SQLReview of SQL
Review of SQL
 

Similar to "Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1

MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
Md. Mahedee Hasan
 
ms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptxms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptx
YashaswiniSrinivasan1
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
Md.Mojibul Hoque
 
Module 3
Module 3Module 3
Module 3
cs19club
 
Physical Design and Development
Physical Design and DevelopmentPhysical Design and Development
Physical Design and Development
Er. Nawaraj Bhandari
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good know
PavithSingh
 
Filtered Indexes In Sql 2008
Filtered Indexes In Sql 2008Filtered Indexes In Sql 2008
Filtered Indexes In Sql 2008
wharrislv
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007paulguerin
 
Intro to tsql unit 7
Intro to tsql   unit 7Intro to tsql   unit 7
Intro to tsql unit 7Syed Asrarali
 
BIS06 Physical Database Models
BIS06 Physical Database ModelsBIS06 Physical Database Models
BIS06 Physical Database Models
Prithwis Mukerjee
 
BIS06 Physical Database Models
BIS06 Physical Database ModelsBIS06 Physical Database Models
BIS06 Physical Database Models
Prithwis Mukerjee
 
Sydney Oracle Meetup - indexes
Sydney Oracle Meetup - indexesSydney Oracle Meetup - indexes
Sydney Oracle Meetup - indexespaulguerin
 
02 database oprimization - improving sql performance - ent-db
02  database oprimization - improving sql performance - ent-db02  database oprimization - improving sql performance - ent-db
02 database oprimization - improving sql performance - ent-db
uncleRhyme
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic Concepts
Tony Wong
 
Ms sql server ii
Ms sql server  iiMs sql server  ii
Ms sql server iiIblesoft
 
Relational Database Management System
Relational Database Management SystemRelational Database Management System
Relational Database Management System
sweetysweety8
 

Similar to "Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1 (20)

Module08
Module08Module08
Module08
 
MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
 
ms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptxms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptx
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
 
Module 3
Module 3Module 3
Module 3
 
Physical Design and Development
Physical Design and DevelopmentPhysical Design and Development
Physical Design and Development
 
SQL.pptx for the begineers and good know
SQL.pptx for the begineers and good knowSQL.pptx for the begineers and good know
SQL.pptx for the begineers and good know
 
Filtered Indexes In Sql 2008
Filtered Indexes In Sql 2008Filtered Indexes In Sql 2008
Filtered Indexes In Sql 2008
 
Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007Myth busters - performance tuning 101 2007
Myth busters - performance tuning 101 2007
 
MySQL Indexes
MySQL IndexesMySQL Indexes
MySQL Indexes
 
Indexing
IndexingIndexing
Indexing
 
Intro to tsql unit 7
Intro to tsql   unit 7Intro to tsql   unit 7
Intro to tsql unit 7
 
BIS06 Physical Database Models
BIS06 Physical Database ModelsBIS06 Physical Database Models
BIS06 Physical Database Models
 
BIS06 Physical Database Models
BIS06 Physical Database ModelsBIS06 Physical Database Models
BIS06 Physical Database Models
 
Sydney Oracle Meetup - indexes
Sydney Oracle Meetup - indexesSydney Oracle Meetup - indexes
Sydney Oracle Meetup - indexes
 
02 database oprimization - improving sql performance - ent-db
02  database oprimization - improving sql performance - ent-db02  database oprimization - improving sql performance - ent-db
02 database oprimization - improving sql performance - ent-db
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic Concepts
 
Ms sql server ii
Ms sql server  iiMs sql server  ii
Ms sql server ii
 
Relational Database Management System
Relational Database Management SystemRelational Database Management System
Relational Database Management System
 
V25 sql index
V25 sql indexV25 sql index
V25 sql index
 

Recently uploaded

FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 

"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1

  • 1. Using indexes Index architecture clustered nonclustered CREATE INDEX (T-SQL) Useful tips Index options Spatial indexes 1
  • 6. CREATE INDEX (T-SQL) CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name ON <object> ( column [ ASC | DESC ] [ ,...n ] ) [ INCLUDE ( column_name [ ,...n ] ) ] [ WHERE <filter_predicate> ] [ WITH ( <relational_index_option> [ ,...n ] ) ] [ ON { partition_scheme_name ( column_name ) | filegroup_name | default } ] [ FILESTREAM_ON { filestream_filegroup_name | partition_scheme_name | "NULL" } ] ! [;] 6
  • 7. CREATE INDEX (T-SQL) <relational_index_option> ::= { PAD_INDEX = { ON | OFF } | FILLFACTOR = fillfactor | SORT_IN_TEMPDB = { ON | OFF } | IGNORE_DUP_KEY = { ON | OFF } | STATISTICS_NORECOMPUTE = { ON | OFF } | DROP_EXISTING = { ON | OFF } | ONLINE = { ON | OFF } | ALLOW_ROW_LOCKS = { ON | OFF } | ALLOW_PAGE_LOCKS = { ON | OFF } | MAXDOP = max_degree_of_parallelism | DATA_COMPRESSION = { NONE | ROW | PAGE} [ ON PARTITIONS ( { <partition_number_expression> | <range> } [ , ...n ] ) ] } 7
  • 8. Useful tips Consider using a clustered index for queries that do the following: ! • • • • Return a range of values by using operators such as BETWEEN, >, >=, <, and <=. Return large result sets. Use JOIN clauses; typically these are foreign key columns. Use ORDER BY, or GROUP BY clauses. • • • • Are unique or contain many distinct values Are accessed sequentially Defined as IDENTITY because the column is guaranteed to be unique within the table. Used frequently to sort the data retrieved from a table. • • Columns that undergo frequent changes Wide keys ! Consider columns that have one or more of the following attributes: ! ! Clustered indexes are not a good choice for the following attributes: ! 8
  • 9. Useful tips Consider the characteristics of the database when designing nonclustered indexes. ! • Databases or tables with low update requirements, but large volumes of data can benefit from many nonclustered indexes to improve query performance. Consider creating filtered indexes for well-defined subsets of data to improve query performance, reduce index storage costs, and reduce index maintenance costs compared with full-table nonclustered indexes. • Online Transaction Processing applications and databases that contain heavily updated tables should avoid over-indexing. Additionally, indexes should be narrow, that is, with as few columns as possible. ! Consider using a nonclustered index for queries that have the following attributes: ! • Use JOIN or GROUP BY clauses. • Queries that do not return large result sets. • Contain columns frequently involved in search conditions of a query, such as WHERE clause, that return exact matches. ! Consider columns that have one or more of these attributes: ! • Cover the query. • Lots of distinct values, such as a combination of last name and first name, if a clustered index is used for other columns. 9
  • 10. Useful tips Query in which the column predicate is one of these Exact match to a specific value Query description and example Index to consider Searches for an exact match in which the query uses the WHERE Nonclustered or clause to specify a column entry with a specific value. For example: clustered index on the Id column. ! Id, [Login], Email FROM Users WHERE Id = 202 SELECT Searches for an exact match to a value in a specified list of values. Exact match to a value in an For example: IN (x,y,z) list ! Id, [Login], Email FROM Users WHERE Id IN (603, 658, 1371) SELECT Nonclustered or clustered index on the Id column. Searches for a range of values in which the query specifies any entry that has a value between two values. For example: Range of values ! Id, UserId, CreateDate, Content FROM Posts WHERE CreateDate SELECT >= '2013-03-01 12:00' AND CreateDate <= '2013-03-01 12:30‘ ! Or ! Id, UserId, CreateDate, Content FROM Posts WHERE CreateDate SELECT Clustered or nonclustered index on the CreateDate column. BETWEEN '2013-03-01 12:00' AND '2013-03-01 12:30' Join between tables Searches for rows in a table that match a row in another table based Nonclustered or on a join predicate. For example: clustered index on the Id and UserId columns. SELECT u.Id, u.[Login], p.Content ! FROM Users u JOIN Posts p ON u.Id = p.UserId WHERE u.Id = 202 10
  • 11. Useful tips Query in which the column predicate is one of these LIKE comparison Sorted or aggregated PRIMARY KEY or UNIQUE constraint Query description and example Searches for matching rows that start with a specific character string such as 'abc%'. For example: ! Id, [Login], Email FROM Users WHERE [Login] LIKE 'ma%' SELECT Nonclustered or clustered index on the Login column. Nonclustered or Requires an implicit or explicit sort order or an aggregation (GROUP clustered index on the BY). For example: sorted or aggregated column. SELECT p.Id, p.UserId, u.[Login], p.Content For sort columns, FROM Posts p JOIN Users u ON p.UserId = u.Id consider specifying the ORDER BY p.UserId, p.CreateDate ASC or DESC order of Searches for duplicates of new index key values in insert and update Clustered or operations, to enforce PRIMARY KEY and UNIQUE constraints. For nonclustered index on example: the column or columns ! ! Users ([Login], [Password], Email) INSERT VALUES ('xdfyht', 'dh4G57hn1', 'xdfyht@gmail.com') UPDATE or DELETE operation Searches for rows in an update or delete operation in which the in a PRIMARY KEY/FOREIGN column participates in a PRIMARY KEY/FOREIGN KEY relationship, KEY relationship with or without the CASCADE option. Contains one or more columns in the select list that are not used for searching and lookups. For example: Column is in the select list but not in the predicate. Index to consider ! UserId, CreateDate, Content FROM Posts SELECT WHERE UserId = 202 ORDER BY CreateDate DESC defined in the constraint. Nonclustered or clustered index on the foreign key column. Nonclustered index with Content specified in the INCLUDE clause. 11
  • 12. Index options (fill factor) 12
  • 13. Index options (included columns) 13
  • 14. Index options (filtered) Views vs. Filtered Indexes Allowed in expressions Views Filtered indexes Computed columns Yes No Joins Yes No Multiple tables Yes No Simple comparison logic in a predicate Yes Yes Complex logic in a predicate Yes No 14
  • 19. Spatial indexes (conditions) • • • • • • • • geometry1.STContains(geometry2) = 1 geometry1.STDistance(geometry2) < @r geometry1.STDistance(geometry2) <= @r geometry1.STEquals(geometry2) = 1 geometry1.STIntersects(geometry2) = 1 geometry1.STOverlaps(geometry2) = 1 geometry1.STTouches(geometry2) = 1 geometry1.STWithin(geometry2) = 1 • • • • geography1.STEquals(geography2) = 1 geography1.STDistance(geography2) < @r geography1.STDistance(geography2) <= @r geography1.STIntersects(geography2) = 1 19