SlideShare a Scribd company logo
1 of 31
www.dageop.com
All about
Storage
®
MS-03: All about Indexes
DR. SUBRAMANI
PARAMASIVAM
(MANI)
About
me
Dr. SubraMANI Paramasivam
PhD., MCT, MCSE, MCITP, MCP, MCTS, MCSA
CEO, Principal Consultant & Trainer
@ DAGEOP (UK)
Email: mani@dageop.com
Blog: http://dataap.org/blog
Follow
Us
https://www.facebook.com/pages/YOUR-SQL-MAN-LTD/
http://www.youtube.com/user/YourSQLMAN
https://twitter.com/dageop
https://uk.linkedin.com/in/dageop
Proud Sponsor
• SQLBits
• SQL Saturdays
• MCT Summit
• SQL Server Geeks
Summit
• Data Awareness
Programme
• Dageop’s Data Day
®
www.DataAP.org
SPEAKER
Contents
MS-03: All about Indexes
• Index types
• Indexing a View
• Managing Fragmentation
www.dageop.com
All About Storage
MS-03: ALL ABOUT INDEXES
www.dageop.com
All About Storage
Index types
• Clustered
• Non-Clustered
• Unique
• Columnstore (2012 onwards)
• Filtered
• Spatial
• XML
• Full-text
www.dageop.com
All About Storage
Clustered Vs Non-clustered indexes
• Clustered indexes sort and store the data rows in the table or view based on their
key values.
• There can be only one clustered index per table
• If table is not having clustered index then its data rows are stored in an unordered
structure called heap.
• Nonclustered index have a Separate structure from data rows. A nonclustered
index contains the nonclustered index key values and each key value entry has a
pointer to the data row that contains the key value.
• Both clustered and nonclustered indexes can be unique. This means no two rows
can have the same value for the index key.
www.dageop.com
All About Storage
Clustered Vs Non-clustered indexes
www.dageop.com
All About Storage
Credits: msdn
1-100 101-200 201-300 301-400
1
101
201
301
1
201
Data pages having actual
records
Stores pointer to
1. Index key for CL IX
2. Row ID for Heap tables
Clustered Vs Non-clustered indexes
www.dageop.com
All About Storage
CLUSTERED INDEX NON-CLUSTERED INDEX
Controls the physical order of the data
pages.
Data pages of Cl-IX always include all the
columns in the table
Key column affects how the pages are
stored in B-Tree index structure
Does not affect ordering and storing of
the data.
DEMO
www.dageop.com
All About Storage
Indexing a View
www.dageop.com
All About Storage
Indexing a View
VIEW
PROS
• Certain columns in a table
• Combination of 2 or more tables with filter by row & column
• Not stored in physical disk
• Effective for security
CONS
• Performance affected during complex joins
• Large number of records rendered
www.dageop.com
All About Storage
PROS
• Improves performance
• Use same B-Tree Structure similar to a table index.
• Indexed views work best when the underlying data is infrequently updated.
CONS
• Stored in physical drive and occupies space.
• Changes to underlying tables are restricted (Schemabinding option)
• The table must be in the same database
• Columns from tables only and not from another view.
• Must have the same ownership.
• Columns must be specified (* don’t work)
• Outer Join cannot be used in indexed view
• The maintenance of an indexed view > cost of maintaining a table index.
Possibility:
• Unique, Clustered and Non-clustered index.
Indexing a View
www.dageop.com
All About Storage
Indexing a View
• Create an indexed view, with schemabinding option in a regular view.
www.dageop.com
All About Storage
Indexing a View
• The first index should be an Unique index or Clustered Index
• Below index makes the view as indexed view.
www.dageop.com
All About Storage
DEMO
www.dageop.com
All About Storage
Managing Fragmentation
www.dageop.com
All About Storage
Managing Fragmentation
Storing data in different extents randomly on disk is known as fragmentation.
• Three types of fragmentation
• Internal Fragmentation
• Loads of free space in pages (eg., Fillfactor <= 50%)
• Random deletes
• Page splits due to inserts or updates
• Logical Fragmentation
• The disk drives have to jump around to different areas to read a table which is
stored in non-contiguous way.
• Heavy deletes can cause pages to be from off the page chain.
• Extent Fragmentation
• When Extent of a table or index are not contiguous. Extents are intermingled.
• It is a kind of internal fragmentation but instead of Pages this happens in extents.
www.dageop.com
All About Storage
Managing Fragmentation
How to detect?
Use sys.dm_db_index_physical_stats
www.dageop.com
All About Storage
Managing Fragmentation
Available Solutions:
Good way:
• Rebuild
• Reorganize
Bad way:
• Recreate the index by dropping existing (Not advisable)
• Create Clustered Index on the heap table and drop the index.
www.dageop.com
All About Storage
Managing Fragmentation
Page 1
Data Row 1
Data Row 2
Data Row 3
Data Row 4
Data Row 5
Page 2
Data Row 1
Data Row 2
Data Row 3
Data Row 4
Data Row 5
Statistics of Non Fragmented Pages
• Page Read Request : 2
• Extent Switches : 0
• Used Disk Space by table : 16KB
• Avg. Fragmentation in % : 0
Non Fragmented Pages
www.dageop.com
All About Storage
Managing Fragmentation
Fragmented Pages
Statistics of Non Fragmented Pages
• Page Read Request : 6
• Extent Switches : 5
• Used Disk Space by table : 48 KB
• Avg. Fragmentation in % : > 80
Data Row 1
Data Row 2
Page 6
Data Row 11
Data Row 12
Page 2
Data Row 3
Page 4
Data Row7
Data Row 8
Page 3
Data Row 5
Data Row 6
Page 5
Data Row 9
Data Row 10
Data Row 4
Page 1
Extent 1
Extent 2
Extent 3
www.dageop.com
All About Storage
Managing Fragmentation
Identifying Fragmentation
• We can get fragmentation information using the DMV : sys.dm_db_index_physical_stats
www.dageop.com
All About Storage
Managing Fragmentation
• There are two important column in the table with the other column
• Avg_Fragmentation_in_Percent • Avg_Page_Space _Used_In_Percent
• Values in %
• Represents internal
Fragmentation
• > Value Better
• < 75 % Corrective Action
Required
• Values in %
• Represents External
Fragmentation
• Extent Fragmentation
for Heap
• < Value Better
• > 10 % Corrective
Action Required
www.dageop.com
All About Storage
Managing Fragmentation
• Avg_Page_Space_Used_In_Percent
• This column represents
• average percentage use of pages
• internal fragmentation
• Higher the value, the better it is
• If the value is lower then 75% Corrective action is required
• Avg_Fragmentation_in_Percent
• This column will have percentage value that represent external fragmentation.
• For a clustered table and leaf level of index pages, this is logical fragmentation
• For heap this is extent fragmentation
• The lower the value , The better it is
• If the value is higher then 10% corrective action required.
www.dageop.com
All About Storage
Managing Fragmentation
Repairing Fragmentation
• Reducing Fragmentation in a Heap: Create a clustered index, to rearrange the
records in order, and the pages are placed contiguously on disk
• Reducing Fragmentation in a Index: Three ways to reduce fragmentation based on
the percentage of fragementation.
• If avg_fragementation_in_percent > 5 % and < 30%:
• use ALTER INDEX REORGANIZE: Replacement for DBCC INDEXDEFRAG
• Reorders the leaf level pages of the index in a logical order.
• This is an online operation and the index is available while the
statement is running.
www.dageop.com
All About Storage
• avg_fragmentation_in_percent > 30%,:
• use ALTER INDEX REBUILD: Replacement for DBCC
DBREINDEX
• Rebuild the index online or offline.
• Drop and re-create the clustered index: (NOT recommended)
• Re-creating a clustered index redistributes the data and results
in full data pages.
• FILLFACTOR option can be applied.
www.dageop.com
All About Storage
Managing Fragmentation
Managing Fragmentation
• Repairing Fragmentation
ALTER INDEX REORGANIZE
ALTER INDEX REBUILD
REDUCING FRAGMENTATION ON INDEX
ONLY IF
FRAGMENTATION
> 5 % & < 30%
ONLY IF
FRAGMENTATION
> 30%
www.dageop.com
All About Storage
www.dageop.com
All About Storage
DEMO
Review
Index Types
Types of Index
Requirement of Index
Impact of Index
Indexing a View
View
Creating Index on View
Performance Difference
Managing Fragmentation
Types of fragmentation
Correcting Fragementation
www.dageop.com
All About Storage
Q & A
www.dageop.com
All About Storage
®
www.dageop.com

More Related Content

Viewers also liked

Viewers also liked (10)

Pony Express Show Bill October 2011
Pony Express Show Bill October 2011Pony Express Show Bill October 2011
Pony Express Show Bill October 2011
 
Fidas premio un amico per la comunicazione 2011 a carmen lasorella
Fidas premio un amico per la comunicazione 2011 a carmen lasorellaFidas premio un amico per la comunicazione 2011 a carmen lasorella
Fidas premio un amico per la comunicazione 2011 a carmen lasorella
 
CV ME-FINAL-A0-2
CV  ME-FINAL-A0-2CV  ME-FINAL-A0-2
CV ME-FINAL-A0-2
 
Pressemitteilung Urlaubsregion Hannover.pdf
Pressemitteilung Urlaubsregion Hannover.pdfPressemitteilung Urlaubsregion Hannover.pdf
Pressemitteilung Urlaubsregion Hannover.pdf
 
Clin d’œil ext’ 27 mai 2016
Clin d’œil ext’ 27 mai 2016Clin d’œil ext’ 27 mai 2016
Clin d’œil ext’ 27 mai 2016
 
1EquityDaily.pdf
1EquityDaily.pdf1EquityDaily.pdf
1EquityDaily.pdf
 
EquityDaily.pdf
EquityDaily.pdfEquityDaily.pdf
EquityDaily.pdf
 
Proyecto comic
Proyecto comicProyecto comic
Proyecto comic
 
PM_WMF KULT pro.pdf
PM_WMF KULT pro.pdfPM_WMF KULT pro.pdf
PM_WMF KULT pro.pdf
 
Brennerplan de vp_zaehlung
Brennerplan de vp_zaehlungBrennerplan de vp_zaehlung
Brennerplan de vp_zaehlung
 

Similar to All about Storage - Series 3 - All about indexes

Postgres db performance improvements
Postgres db performance improvementsPostgres db performance improvements
Postgres db performance improvementsMahesh Chopker
 
Geek Sync | Top 5 Tips to Keep Always On Always Humming and Users Happy
Geek Sync | Top 5 Tips to Keep Always On Always Humming and Users HappyGeek Sync | Top 5 Tips to Keep Always On Always Humming and Users Happy
Geek Sync | Top 5 Tips to Keep Always On Always Humming and Users HappyIDERA Software
 
Best storage engine for MySQL
Best storage engine for MySQLBest storage engine for MySQL
Best storage engine for MySQLtomflemingh2
 
Storage talk
Storage talkStorage talk
Storage talkchristkv
 
Main MeMory Data Base
Main MeMory Data BaseMain MeMory Data Base
Main MeMory Data BaseSiva Rushi
 
confessions of a dba: worst and best things I've done in production - Open So...
confessions of a dba: worst and best things I've done in production - Open So...confessions of a dba: worst and best things I've done in production - Open So...
confessions of a dba: worst and best things I've done in production - Open So...emilyslocombe
 
How_To_Soup_Up_Your_Farm
How_To_Soup_Up_Your_FarmHow_To_Soup_Up_Your_Farm
How_To_Soup_Up_Your_FarmNigel Price
 
The dr overnight dba
The dr overnight dbaThe dr overnight dba
The dr overnight dbagdabate
 
Government and Education Webinar: SQL Server—Indexing for Performance
Government and Education Webinar: SQL Server—Indexing for PerformanceGovernment and Education Webinar: SQL Server—Indexing for Performance
Government and Education Webinar: SQL Server—Indexing for PerformanceSolarWinds
 
Rise of Column Oriented Database
Rise of Column Oriented DatabaseRise of Column Oriented Database
Rise of Column Oriented DatabaseSuvradeep Rudra
 
What SQL DBA's need to know about SharePoint-St. Louis 2013
What SQL DBA's need to know about SharePoint-St. Louis 2013What SQL DBA's need to know about SharePoint-St. Louis 2013
What SQL DBA's need to know about SharePoint-St. Louis 2013J.D. Wade
 
Managing Memory & Locks - Series 1 Memory Management
Managing  Memory & Locks - Series 1 Memory ManagementManaging  Memory & Locks - Series 1 Memory Management
Managing Memory & Locks - Series 1 Memory ManagementDAGEOP LTD
 
SPS Kansas City: What SharePoint Admin need to know about SQL
SPS Kansas City: What SharePoint Admin need to know about SQLSPS Kansas City: What SharePoint Admin need to know about SQL
SPS Kansas City: What SharePoint Admin need to know about SQLJ.D. Wade
 
What SharePoint Admins need to know about SQL-Cinncinati
What SharePoint Admins need to know about SQL-CinncinatiWhat SharePoint Admins need to know about SQL-Cinncinati
What SharePoint Admins need to know about SQL-CinncinatiJ.D. Wade
 
Query Optimization in SQL Server
Query Optimization in SQL ServerQuery Optimization in SQL Server
Query Optimization in SQL ServerRajesh Gunasundaram
 
Tech-Spark: Scaling Databases
Tech-Spark: Scaling DatabasesTech-Spark: Scaling Databases
Tech-Spark: Scaling DatabasesRalph Attard
 
MongoDB Aggregation Performance
MongoDB Aggregation PerformanceMongoDB Aggregation Performance
MongoDB Aggregation PerformanceMongoDB
 

Similar to All about Storage - Series 3 - All about indexes (20)

Postgres db performance improvements
Postgres db performance improvementsPostgres db performance improvements
Postgres db performance improvements
 
Geek Sync | Top 5 Tips to Keep Always On Always Humming and Users Happy
Geek Sync | Top 5 Tips to Keep Always On Always Humming and Users HappyGeek Sync | Top 5 Tips to Keep Always On Always Humming and Users Happy
Geek Sync | Top 5 Tips to Keep Always On Always Humming and Users Happy
 
Best storage engine for MySQL
Best storage engine for MySQLBest storage engine for MySQL
Best storage engine for MySQL
 
Storage talk
Storage talkStorage talk
Storage talk
 
Main MeMory Data Base
Main MeMory Data BaseMain MeMory Data Base
Main MeMory Data Base
 
confessions of a dba: worst and best things I've done in production - Open So...
confessions of a dba: worst and best things I've done in production - Open So...confessions of a dba: worst and best things I've done in production - Open So...
confessions of a dba: worst and best things I've done in production - Open So...
 
How_To_Soup_Up_Your_Farm
How_To_Soup_Up_Your_FarmHow_To_Soup_Up_Your_Farm
How_To_Soup_Up_Your_Farm
 
The dr overnight dba
The dr overnight dbaThe dr overnight dba
The dr overnight dba
 
Government and Education Webinar: SQL Server—Indexing for Performance
Government and Education Webinar: SQL Server—Indexing for PerformanceGovernment and Education Webinar: SQL Server—Indexing for Performance
Government and Education Webinar: SQL Server—Indexing for Performance
 
Rise of Column Oriented Database
Rise of Column Oriented DatabaseRise of Column Oriented Database
Rise of Column Oriented Database
 
What SQL DBA's need to know about SharePoint-St. Louis 2013
What SQL DBA's need to know about SharePoint-St. Louis 2013What SQL DBA's need to know about SharePoint-St. Louis 2013
What SQL DBA's need to know about SharePoint-St. Louis 2013
 
Managing Memory & Locks - Series 1 Memory Management
Managing  Memory & Locks - Series 1 Memory ManagementManaging  Memory & Locks - Series 1 Memory Management
Managing Memory & Locks - Series 1 Memory Management
 
SQLServer Database Structures
SQLServer Database Structures SQLServer Database Structures
SQLServer Database Structures
 
SPS Kansas City: What SharePoint Admin need to know about SQL
SPS Kansas City: What SharePoint Admin need to know about SQLSPS Kansas City: What SharePoint Admin need to know about SQL
SPS Kansas City: What SharePoint Admin need to know about SQL
 
What SharePoint Admins need to know about SQL-Cinncinati
What SharePoint Admins need to know about SQL-CinncinatiWhat SharePoint Admins need to know about SQL-Cinncinati
What SharePoint Admins need to know about SQL-Cinncinati
 
Query Optimization in SQL Server
Query Optimization in SQL ServerQuery Optimization in SQL Server
Query Optimization in SQL Server
 
Tech-Spark: Scaling Databases
Tech-Spark: Scaling DatabasesTech-Spark: Scaling Databases
Tech-Spark: Scaling Databases
 
Understanding indices
Understanding indicesUnderstanding indices
Understanding indices
 
MongoDB Aggregation Performance
MongoDB Aggregation PerformanceMongoDB Aggregation Performance
MongoDB Aggregation Performance
 
NoSql
NoSqlNoSql
NoSql
 

More from DAGEOP LTD

HIGH PERFORMANCE DATABASES
HIGH PERFORMANCE DATABASESHIGH PERFORMANCE DATABASES
HIGH PERFORMANCE DATABASESDAGEOP LTD
 
DBA – THINGS TO KNOW
DBA – THINGS TO KNOWDBA – THINGS TO KNOW
DBA – THINGS TO KNOWDAGEOP LTD
 
SQL Server Editions and Features
SQL Server Editions and Features SQL Server Editions and Features
SQL Server Editions and Features DAGEOP LTD
 
DATA & POWER VISUALIZATION
DATA & POWER VISUALIZATIONDATA & POWER VISUALIZATION
DATA & POWER VISUALIZATIONDAGEOP LTD
 
Microsoft Products
Microsoft ProductsMicrosoft Products
Microsoft ProductsDAGEOP LTD
 
Data, Education and Social awareness
Data, Education and Social awarenessData, Education and Social awareness
Data, Education and Social awarenessDAGEOP LTD
 
Data Modeling - Series 4 X-Events
Data Modeling - Series 4 X-EventsData Modeling - Series 4 X-Events
Data Modeling - Series 4 X-EventsDAGEOP LTD
 
Data Modeling - Series 1 Storing summarised data
Data Modeling - Series 1 Storing summarised dataData Modeling - Series 1 Storing summarised data
Data Modeling - Series 1 Storing summarised dataDAGEOP LTD
 
Optimising Queries - Series 4 Designing Effective Indexes
Optimising Queries - Series 4 Designing Effective IndexesOptimising Queries - Series 4 Designing Effective Indexes
Optimising Queries - Series 4 Designing Effective IndexesDAGEOP LTD
 
Optimising Queries - Series 3 Distinguishing among query types
Optimising Queries - Series 3 Distinguishing among query typesOptimising Queries - Series 3 Distinguishing among query types
Optimising Queries - Series 3 Distinguishing among query typesDAGEOP LTD
 
Optimising Queries - Series 1 Query Optimiser Architecture
Optimising Queries - Series 1 Query Optimiser ArchitectureOptimising Queries - Series 1 Query Optimiser Architecture
Optimising Queries - Series 1 Query Optimiser ArchitectureDAGEOP LTD
 
Managing Memory & Locks - Series 2 Transactions & Lock management
Managing  Memory & Locks - Series 2 Transactions & Lock managementManaging  Memory & Locks - Series 2 Transactions & Lock management
Managing Memory & Locks - Series 2 Transactions & Lock managementDAGEOP LTD
 
All about Storage - Series 2 Defining Data
All about Storage - Series 2 Defining DataAll about Storage - Series 2 Defining Data
All about Storage - Series 2 Defining DataDAGEOP LTD
 
Database Fundamental Concepts - Series 2 Monitoring plan
Database Fundamental Concepts - Series 2 Monitoring planDatabase Fundamental Concepts - Series 2 Monitoring plan
Database Fundamental Concepts - Series 2 Monitoring planDAGEOP LTD
 
Database Fundamental Concepts- Series 1 - Performance Analysis
Database Fundamental Concepts- Series 1 - Performance AnalysisDatabase Fundamental Concepts- Series 1 - Performance Analysis
Database Fundamental Concepts- Series 1 - Performance AnalysisDAGEOP LTD
 
Advanced SSRS Reporting Techniques
Advanced SSRS Reporting TechniquesAdvanced SSRS Reporting Techniques
Advanced SSRS Reporting TechniquesDAGEOP LTD
 
Perfect Performance Platter - SQL Server 2014
Perfect Performance Platter - SQL Server 2014 Perfect Performance Platter - SQL Server 2014
Perfect Performance Platter - SQL Server 2014 DAGEOP LTD
 

More from DAGEOP LTD (17)

HIGH PERFORMANCE DATABASES
HIGH PERFORMANCE DATABASESHIGH PERFORMANCE DATABASES
HIGH PERFORMANCE DATABASES
 
DBA – THINGS TO KNOW
DBA – THINGS TO KNOWDBA – THINGS TO KNOW
DBA – THINGS TO KNOW
 
SQL Server Editions and Features
SQL Server Editions and Features SQL Server Editions and Features
SQL Server Editions and Features
 
DATA & POWER VISUALIZATION
DATA & POWER VISUALIZATIONDATA & POWER VISUALIZATION
DATA & POWER VISUALIZATION
 
Microsoft Products
Microsoft ProductsMicrosoft Products
Microsoft Products
 
Data, Education and Social awareness
Data, Education and Social awarenessData, Education and Social awareness
Data, Education and Social awareness
 
Data Modeling - Series 4 X-Events
Data Modeling - Series 4 X-EventsData Modeling - Series 4 X-Events
Data Modeling - Series 4 X-Events
 
Data Modeling - Series 1 Storing summarised data
Data Modeling - Series 1 Storing summarised dataData Modeling - Series 1 Storing summarised data
Data Modeling - Series 1 Storing summarised data
 
Optimising Queries - Series 4 Designing Effective Indexes
Optimising Queries - Series 4 Designing Effective IndexesOptimising Queries - Series 4 Designing Effective Indexes
Optimising Queries - Series 4 Designing Effective Indexes
 
Optimising Queries - Series 3 Distinguishing among query types
Optimising Queries - Series 3 Distinguishing among query typesOptimising Queries - Series 3 Distinguishing among query types
Optimising Queries - Series 3 Distinguishing among query types
 
Optimising Queries - Series 1 Query Optimiser Architecture
Optimising Queries - Series 1 Query Optimiser ArchitectureOptimising Queries - Series 1 Query Optimiser Architecture
Optimising Queries - Series 1 Query Optimiser Architecture
 
Managing Memory & Locks - Series 2 Transactions & Lock management
Managing  Memory & Locks - Series 2 Transactions & Lock managementManaging  Memory & Locks - Series 2 Transactions & Lock management
Managing Memory & Locks - Series 2 Transactions & Lock management
 
All about Storage - Series 2 Defining Data
All about Storage - Series 2 Defining DataAll about Storage - Series 2 Defining Data
All about Storage - Series 2 Defining Data
 
Database Fundamental Concepts - Series 2 Monitoring plan
Database Fundamental Concepts - Series 2 Monitoring planDatabase Fundamental Concepts - Series 2 Monitoring plan
Database Fundamental Concepts - Series 2 Monitoring plan
 
Database Fundamental Concepts- Series 1 - Performance Analysis
Database Fundamental Concepts- Series 1 - Performance AnalysisDatabase Fundamental Concepts- Series 1 - Performance Analysis
Database Fundamental Concepts- Series 1 - Performance Analysis
 
Advanced SSRS Reporting Techniques
Advanced SSRS Reporting TechniquesAdvanced SSRS Reporting Techniques
Advanced SSRS Reporting Techniques
 
Perfect Performance Platter - SQL Server 2014
Perfect Performance Platter - SQL Server 2014 Perfect Performance Platter - SQL Server 2014
Perfect Performance Platter - SQL Server 2014
 

Recently uploaded

100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptxAnupama Kate
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Delhi Call girls
 
Zuja dropshipping via API with DroFx.pptx
Zuja dropshipping via API with DroFx.pptxZuja dropshipping via API with DroFx.pptx
Zuja dropshipping via API with DroFx.pptxolyaivanovalion
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxolyaivanovalion
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionfulawalesam
 
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Delhi Call girls
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfRachmat Ramadhan H
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxolyaivanovalion
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxolyaivanovalion
 
Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...shambhavirathore45
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfLars Albertsson
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusTimothy Spann
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightDelhi Call girls
 
Data-Analysis for Chicago Crime Data 2023
Data-Analysis for Chicago Crime Data  2023Data-Analysis for Chicago Crime Data  2023
Data-Analysis for Chicago Crime Data 2023ymrp368
 
BabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxBabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxolyaivanovalion
 
Capstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramCapstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramMoniSankarHazra
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfMarinCaroMartnezBerg
 
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...shivangimorya083
 

Recently uploaded (20)

100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
 
Zuja dropshipping via API with DroFx.pptx
Zuja dropshipping via API with DroFx.pptxZuja dropshipping via API with DroFx.pptx
Zuja dropshipping via API with DroFx.pptx
 
CebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptxCebaBaby dropshipping via API with DroFX.pptx
CebaBaby dropshipping via API with DroFX.pptx
 
Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interaction
 
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 
Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...Determinants of health, dimensions of health, positive health and spectrum of...
Determinants of health, dimensions of health, positive health and spectrum of...
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdf
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and Milvus
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 
Data-Analysis for Chicago Crime Data 2023
Data-Analysis for Chicago Crime Data  2023Data-Analysis for Chicago Crime Data  2023
Data-Analysis for Chicago Crime Data 2023
 
BabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxBabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptx
 
Capstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics ProgramCapstone Project on IBM Data Analytics Program
Capstone Project on IBM Data Analytics Program
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
 
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
 
Sampling (random) method and Non random.ppt
Sampling (random) method and Non random.pptSampling (random) method and Non random.ppt
Sampling (random) method and Non random.ppt
 

All about Storage - Series 3 - All about indexes

  • 1. www.dageop.com All about Storage ® MS-03: All about Indexes DR. SUBRAMANI PARAMASIVAM (MANI)
  • 2. About me Dr. SubraMANI Paramasivam PhD., MCT, MCSE, MCITP, MCP, MCTS, MCSA CEO, Principal Consultant & Trainer @ DAGEOP (UK) Email: mani@dageop.com Blog: http://dataap.org/blog Follow Us https://www.facebook.com/pages/YOUR-SQL-MAN-LTD/ http://www.youtube.com/user/YourSQLMAN https://twitter.com/dageop https://uk.linkedin.com/in/dageop Proud Sponsor • SQLBits • SQL Saturdays • MCT Summit • SQL Server Geeks Summit • Data Awareness Programme • Dageop’s Data Day ® www.DataAP.org SPEAKER
  • 3. Contents MS-03: All about Indexes • Index types • Indexing a View • Managing Fragmentation www.dageop.com All About Storage
  • 4. MS-03: ALL ABOUT INDEXES www.dageop.com All About Storage
  • 5. Index types • Clustered • Non-Clustered • Unique • Columnstore (2012 onwards) • Filtered • Spatial • XML • Full-text www.dageop.com All About Storage
  • 6. Clustered Vs Non-clustered indexes • Clustered indexes sort and store the data rows in the table or view based on their key values. • There can be only one clustered index per table • If table is not having clustered index then its data rows are stored in an unordered structure called heap. • Nonclustered index have a Separate structure from data rows. A nonclustered index contains the nonclustered index key values and each key value entry has a pointer to the data row that contains the key value. • Both clustered and nonclustered indexes can be unique. This means no two rows can have the same value for the index key. www.dageop.com All About Storage
  • 7. Clustered Vs Non-clustered indexes www.dageop.com All About Storage Credits: msdn 1-100 101-200 201-300 301-400 1 101 201 301 1 201 Data pages having actual records Stores pointer to 1. Index key for CL IX 2. Row ID for Heap tables
  • 8. Clustered Vs Non-clustered indexes www.dageop.com All About Storage CLUSTERED INDEX NON-CLUSTERED INDEX Controls the physical order of the data pages. Data pages of Cl-IX always include all the columns in the table Key column affects how the pages are stored in B-Tree index structure Does not affect ordering and storing of the data.
  • 11. Indexing a View VIEW PROS • Certain columns in a table • Combination of 2 or more tables with filter by row & column • Not stored in physical disk • Effective for security CONS • Performance affected during complex joins • Large number of records rendered www.dageop.com All About Storage
  • 12. PROS • Improves performance • Use same B-Tree Structure similar to a table index. • Indexed views work best when the underlying data is infrequently updated. CONS • Stored in physical drive and occupies space. • Changes to underlying tables are restricted (Schemabinding option) • The table must be in the same database • Columns from tables only and not from another view. • Must have the same ownership. • Columns must be specified (* don’t work) • Outer Join cannot be used in indexed view • The maintenance of an indexed view > cost of maintaining a table index. Possibility: • Unique, Clustered and Non-clustered index. Indexing a View www.dageop.com All About Storage
  • 13. Indexing a View • Create an indexed view, with schemabinding option in a regular view. www.dageop.com All About Storage
  • 14. Indexing a View • The first index should be an Unique index or Clustered Index • Below index makes the view as indexed view. www.dageop.com All About Storage
  • 17. Managing Fragmentation Storing data in different extents randomly on disk is known as fragmentation. • Three types of fragmentation • Internal Fragmentation • Loads of free space in pages (eg., Fillfactor <= 50%) • Random deletes • Page splits due to inserts or updates • Logical Fragmentation • The disk drives have to jump around to different areas to read a table which is stored in non-contiguous way. • Heavy deletes can cause pages to be from off the page chain. • Extent Fragmentation • When Extent of a table or index are not contiguous. Extents are intermingled. • It is a kind of internal fragmentation but instead of Pages this happens in extents. www.dageop.com All About Storage
  • 18. Managing Fragmentation How to detect? Use sys.dm_db_index_physical_stats www.dageop.com All About Storage
  • 19. Managing Fragmentation Available Solutions: Good way: • Rebuild • Reorganize Bad way: • Recreate the index by dropping existing (Not advisable) • Create Clustered Index on the heap table and drop the index. www.dageop.com All About Storage
  • 20. Managing Fragmentation Page 1 Data Row 1 Data Row 2 Data Row 3 Data Row 4 Data Row 5 Page 2 Data Row 1 Data Row 2 Data Row 3 Data Row 4 Data Row 5 Statistics of Non Fragmented Pages • Page Read Request : 2 • Extent Switches : 0 • Used Disk Space by table : 16KB • Avg. Fragmentation in % : 0 Non Fragmented Pages www.dageop.com All About Storage
  • 21. Managing Fragmentation Fragmented Pages Statistics of Non Fragmented Pages • Page Read Request : 6 • Extent Switches : 5 • Used Disk Space by table : 48 KB • Avg. Fragmentation in % : > 80 Data Row 1 Data Row 2 Page 6 Data Row 11 Data Row 12 Page 2 Data Row 3 Page 4 Data Row7 Data Row 8 Page 3 Data Row 5 Data Row 6 Page 5 Data Row 9 Data Row 10 Data Row 4 Page 1 Extent 1 Extent 2 Extent 3 www.dageop.com All About Storage
  • 22. Managing Fragmentation Identifying Fragmentation • We can get fragmentation information using the DMV : sys.dm_db_index_physical_stats www.dageop.com All About Storage
  • 23. Managing Fragmentation • There are two important column in the table with the other column • Avg_Fragmentation_in_Percent • Avg_Page_Space _Used_In_Percent • Values in % • Represents internal Fragmentation • > Value Better • < 75 % Corrective Action Required • Values in % • Represents External Fragmentation • Extent Fragmentation for Heap • < Value Better • > 10 % Corrective Action Required www.dageop.com All About Storage
  • 24. Managing Fragmentation • Avg_Page_Space_Used_In_Percent • This column represents • average percentage use of pages • internal fragmentation • Higher the value, the better it is • If the value is lower then 75% Corrective action is required • Avg_Fragmentation_in_Percent • This column will have percentage value that represent external fragmentation. • For a clustered table and leaf level of index pages, this is logical fragmentation • For heap this is extent fragmentation • The lower the value , The better it is • If the value is higher then 10% corrective action required. www.dageop.com All About Storage
  • 25. Managing Fragmentation Repairing Fragmentation • Reducing Fragmentation in a Heap: Create a clustered index, to rearrange the records in order, and the pages are placed contiguously on disk • Reducing Fragmentation in a Index: Three ways to reduce fragmentation based on the percentage of fragementation. • If avg_fragementation_in_percent > 5 % and < 30%: • use ALTER INDEX REORGANIZE: Replacement for DBCC INDEXDEFRAG • Reorders the leaf level pages of the index in a logical order. • This is an online operation and the index is available while the statement is running. www.dageop.com All About Storage
  • 26. • avg_fragmentation_in_percent > 30%,: • use ALTER INDEX REBUILD: Replacement for DBCC DBREINDEX • Rebuild the index online or offline. • Drop and re-create the clustered index: (NOT recommended) • Re-creating a clustered index redistributes the data and results in full data pages. • FILLFACTOR option can be applied. www.dageop.com All About Storage Managing Fragmentation
  • 27. Managing Fragmentation • Repairing Fragmentation ALTER INDEX REORGANIZE ALTER INDEX REBUILD REDUCING FRAGMENTATION ON INDEX ONLY IF FRAGMENTATION > 5 % & < 30% ONLY IF FRAGMENTATION > 30% www.dageop.com All About Storage
  • 29. Review Index Types Types of Index Requirement of Index Impact of Index Indexing a View View Creating Index on View Performance Difference Managing Fragmentation Types of fragmentation Correcting Fragementation www.dageop.com All About Storage
  • 30. Q & A www.dageop.com All About Storage