SlideShare a Scribd company logo
1 of 18
SAG – Indexing and Query
Optimization
Vaibhav Jain
vjain44@csc.com
Ext : 706224
Indexing – A Refresher
• Introducing Indexes
 What are Indexes?
 What are the types of Indexes?
 What do these terms inside SQL Server mean?
– Pages, Extents
– Heap
– Clustered Indexes
– Non-Clustered Indexes
Page, Extents
• The fundamental unit of data storage in SQL Server is the PAGE
(8k)
 This means SQL Server databases have 128 pages per megabyte
 Each page begins with a 96-byte header
 Maximum amount of data contained in a single row on a page is 8,060
bytes
• Extents are a collection of eight physically contiguous pages
HEAP
• A heap is a table without a clustered index
• The data rows are not stored in any particular order
• Data pages are not linked in a linked list
Clustered Index
• The data rows are stored in order based on the clustered index key
• The clustered index is implemented as a B-tree index structure
• Data pages in the leaf level, are linked in a doubly-linked list
• Clustered indexes have one row in sys.partitions, with index_id = 1
Clustered Index B - Tree
Non-Clustered Index
• Nonclustered indexes have a B-tree index structure
similar to the one in clustered indexes
• The difference is that nonclustered indexes do not
affect the order of the data rows.
• Each index row contains the nonclustered key value, a
row locator and any included, or nonkey, columns
Query Optimization
Simple flow chart Real pie chart
Query Processing and Optimization
Parsing
Optimization
Execution
Query Processing and Optimization
• Cost Based Optimizer
• Disk IO Cost
• CPU Cost
• Memory Cost – Very insignificant
• Indexes
• Selects optimal indexes to be used
• Query Algorithms
• Converts Logical operation into physical operations
Execution Plan Operators
• When
• Good
• Bad
• Action Item
80% - 20% Rule
Table Scan
• When
Table without clustered index is accessed
• Good or Bad*
Can’t decide
• Action Item
Create Clustered Index
Clustered Index Scan
• When
Table with clustered index is accessed but query
doesn’t uses the clustered index key
• Good or Bad*
Bad unless large data with most columns and rows
retrieved
• Action Item
Evaluate Clustered Index Keys
Clustered Index Seek
• When
Table with clustered index is accessed and query
locates specific rows in B+ tree
• Good or Bad*
Good
• Action Item
Evaluate possibility of non-clustered index
Non-Clustered Index Scan
• When
Columns part of non-clustered index accessed in
query
• Good or Bad*
Bad unless large data with most columns and rows
retrieved
• Action Item
Create more refined non-clustered index
Non-Clustered Index Seek
• When
Columns part of non-clustered index accessed in
query and rows located in B+ tree
• Good or Bad*
Good
• Action Item
Further evaluate other operators
Lookups
• When
Query Optimizer uses non-clustered index to search
few column data and base table for other columns data
• Good or Bad*
Good
• Action Item
Included Index or Covered Index
Questions?
THANK YOU

More Related Content

What's hot

Introduction to Data Warehouse
Introduction to Data WarehouseIntroduction to Data Warehouse
Introduction to Data WarehouseTran Vi Duan
 
9. index and index organized table
9. index and index organized table9. index and index organized table
9. index and index organized tableAmrit Kaur
 
Text Mining & Sentiment Analysis with Power BI & Azure
Text Mining & Sentiment Analysis with Power BI & AzureText Mining & Sentiment Analysis with Power BI & Azure
Text Mining & Sentiment Analysis with Power BI & AzureSanil Mhatre
 
Why You Need to STOP Using Spreadsheets for Audit Analysis
Why You Need to STOP Using Spreadsheets for Audit AnalysisWhy You Need to STOP Using Spreadsheets for Audit Analysis
Why You Need to STOP Using Spreadsheets for Audit AnalysisCaseWare IDEA
 
How to find new ways to add value to your audits
How to find new ways to add value to your auditsHow to find new ways to add value to your audits
How to find new ways to add value to your auditsCaseWare IDEA
 
How to Design a Good Database for Your Application
How to Design a Good Database for Your ApplicationHow to Design a Good Database for Your Application
How to Design a Good Database for Your ApplicationNur Hidayat
 
Text Mining & Sentiment Analysis made easy, with Azure and Power BI
Text Mining & Sentiment Analysis made easy, with Azure and Power BIText Mining & Sentiment Analysis made easy, with Azure and Power BI
Text Mining & Sentiment Analysis made easy, with Azure and Power BISanil Mhatre
 

What's hot (8)

Introduction to Data Warehouse
Introduction to Data WarehouseIntroduction to Data Warehouse
Introduction to Data Warehouse
 
9. index and index organized table
9. index and index organized table9. index and index organized table
9. index and index organized table
 
Text Mining & Sentiment Analysis with Power BI & Azure
Text Mining & Sentiment Analysis with Power BI & AzureText Mining & Sentiment Analysis with Power BI & Azure
Text Mining & Sentiment Analysis with Power BI & Azure
 
Why You Need to STOP Using Spreadsheets for Audit Analysis
Why You Need to STOP Using Spreadsheets for Audit AnalysisWhy You Need to STOP Using Spreadsheets for Audit Analysis
Why You Need to STOP Using Spreadsheets for Audit Analysis
 
How to find new ways to add value to your audits
How to find new ways to add value to your auditsHow to find new ways to add value to your audits
How to find new ways to add value to your audits
 
How to Design a Good Database for Your Application
How to Design a Good Database for Your ApplicationHow to Design a Good Database for Your Application
How to Design a Good Database for Your Application
 
Text Mining & Sentiment Analysis made easy, with Azure and Power BI
Text Mining & Sentiment Analysis made easy, with Azure and Power BIText Mining & Sentiment Analysis made easy, with Azure and Power BI
Text Mining & Sentiment Analysis made easy, with Azure and Power BI
 
ADO.NET Introduction
ADO.NET IntroductionADO.NET Introduction
ADO.NET Introduction
 

Viewers also liked

Social Media Business Coach - Followers Strategy
Social Media Business Coach - Followers StrategySocial Media Business Coach - Followers Strategy
Social Media Business Coach - Followers StrategySocialMediaBusinessCoach
 
Sound Waves Explained
Sound Waves ExplainedSound Waves Explained
Sound Waves Explainedshikhak12
 
Konsep wilayah
Konsep wilayahKonsep wilayah
Konsep wilayahsalfarisi
 
Hadoop Distributed File System
Hadoop Distributed File SystemHadoop Distributed File System
Hadoop Distributed File SystemVaibhav Jain
 
2D wave interference
2D wave interference 2D wave interference
2D wave interference shikhak12
 
Michelson interferometer
Michelson interferometerMichelson interferometer
Michelson interferometercalvin_k
 

Viewers also liked (7)

Social Media Business Coach - Followers Strategy
Social Media Business Coach - Followers StrategySocial Media Business Coach - Followers Strategy
Social Media Business Coach - Followers Strategy
 
Sound Waves Explained
Sound Waves ExplainedSound Waves Explained
Sound Waves Explained
 
C.V
C.VC.V
C.V
 
Konsep wilayah
Konsep wilayahKonsep wilayah
Konsep wilayah
 
Hadoop Distributed File System
Hadoop Distributed File SystemHadoop Distributed File System
Hadoop Distributed File System
 
2D wave interference
2D wave interference 2D wave interference
2D wave interference
 
Michelson interferometer
Michelson interferometerMichelson interferometer
Michelson interferometer
 

Similar to SAG_Indexing and Query Optimization

Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysisRiteshkiit
 
Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysisRiteshkiit
 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server DatabasesColdFusionConference
 
SQLDay2013_Denny Cherry - Table indexing for the .NET Developer
SQLDay2013_Denny Cherry - Table indexing for the .NET DeveloperSQLDay2013_Denny Cherry - Table indexing for the .NET Developer
SQLDay2013_Denny Cherry - Table indexing for the .NET DeveloperPolish SQL Server User Group
 
Introduction to execution plan analysis
Introduction to execution plan analysisIntroduction to execution plan analysis
Introduction to execution plan analysisJohn Sterrett
 
MariaDB AX: Solución analítica con ColumnStore
MariaDB AX: Solución analítica con ColumnStoreMariaDB AX: Solución analítica con ColumnStore
MariaDB AX: Solución analítica con ColumnStoreMariaDB plc
 
MariaDB AX: Analytics with MariaDB ColumnStore
MariaDB AX: Analytics with MariaDB ColumnStoreMariaDB AX: Analytics with MariaDB ColumnStore
MariaDB AX: Analytics with MariaDB ColumnStoreMariaDB plc
 
Statistis, Row Counts, Execution Plans and Query Tuning
Statistis, Row Counts, Execution Plans and Query TuningStatistis, Row Counts, Execution Plans and Query Tuning
Statistis, Row Counts, Execution Plans and Query TuningGrant Fritchey
 
Introduction of sql server indexing
Introduction of sql server indexingIntroduction of sql server indexing
Introduction of sql server indexingMahabubur Rahaman
 
Query Optimization in SQL Server
Query Optimization in SQL ServerQuery Optimization in SQL Server
Query Optimization in SQL ServerRajesh Gunasundaram
 
Strategies for SQL Server Index Analysis
Strategies for SQL Server Index AnalysisStrategies for SQL Server Index Analysis
Strategies for SQL Server Index AnalysisJason Strate
 
Qualitem - Large List Support - SharePoint Saturday
Qualitem - Large List Support - SharePoint SaturdayQualitem - Large List Support - SharePoint Saturday
Qualitem - Large List Support - SharePoint SaturdayRick Rosato
 

Similar to SAG_Indexing and Query Optimization (20)

Statistics and Indexes Internals
Statistics and Indexes InternalsStatistics and Indexes Internals
Statistics and Indexes Internals
 
Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysis
 
Sql performance tuning
Sql performance tuningSql performance tuning
Sql performance tuning
 
Sql query performance analysis
Sql query performance analysisSql query performance analysis
Sql query performance analysis
 
Tunning overview
Tunning overviewTunning overview
Tunning overview
 
Building better SQL Server Databases
Building better SQL Server DatabasesBuilding better SQL Server Databases
Building better SQL Server Databases
 
SQLDay2013_Denny Cherry - Table indexing for the .NET Developer
SQLDay2013_Denny Cherry - Table indexing for the .NET DeveloperSQLDay2013_Denny Cherry - Table indexing for the .NET Developer
SQLDay2013_Denny Cherry - Table indexing for the .NET Developer
 
Introduction to execution plan analysis
Introduction to execution plan analysisIntroduction to execution plan analysis
Introduction to execution plan analysis
 
MariaDB AX: Solución analítica con ColumnStore
MariaDB AX: Solución analítica con ColumnStoreMariaDB AX: Solución analítica con ColumnStore
MariaDB AX: Solución analítica con ColumnStore
 
MariaDB AX: Analytics with MariaDB ColumnStore
MariaDB AX: Analytics with MariaDB ColumnStoreMariaDB AX: Analytics with MariaDB ColumnStore
MariaDB AX: Analytics with MariaDB ColumnStore
 
Statistis, Row Counts, Execution Plans and Query Tuning
Statistis, Row Counts, Execution Plans and Query TuningStatistis, Row Counts, Execution Plans and Query Tuning
Statistis, Row Counts, Execution Plans and Query Tuning
 
Introduction of sql server indexing
Introduction of sql server indexingIntroduction of sql server indexing
Introduction of sql server indexing
 
Query Optimization in SQL Server
Query Optimization in SQL ServerQuery Optimization in SQL Server
Query Optimization in SQL Server
 
Strategies for SQL Server Index Analysis
Strategies for SQL Server Index AnalysisStrategies for SQL Server Index Analysis
Strategies for SQL Server Index Analysis
 
Index
IndexIndex
Index
 
Data Warehouse
Data WarehouseData Warehouse
Data Warehouse
 
kalyani.ppt
kalyani.pptkalyani.ppt
kalyani.ppt
 
Data Warehouse
Data WarehouseData Warehouse
Data Warehouse
 
kalyani.ppt
kalyani.pptkalyani.ppt
kalyani.ppt
 
Qualitem - Large List Support - SharePoint Saturday
Qualitem - Large List Support - SharePoint SaturdayQualitem - Large List Support - SharePoint Saturday
Qualitem - Large List Support - SharePoint Saturday
 

SAG_Indexing and Query Optimization

  • 1. SAG – Indexing and Query Optimization Vaibhav Jain vjain44@csc.com Ext : 706224
  • 2. Indexing – A Refresher • Introducing Indexes  What are Indexes?  What are the types of Indexes?  What do these terms inside SQL Server mean? – Pages, Extents – Heap – Clustered Indexes – Non-Clustered Indexes
  • 3. Page, Extents • The fundamental unit of data storage in SQL Server is the PAGE (8k)  This means SQL Server databases have 128 pages per megabyte  Each page begins with a 96-byte header  Maximum amount of data contained in a single row on a page is 8,060 bytes • Extents are a collection of eight physically contiguous pages
  • 4. HEAP • A heap is a table without a clustered index • The data rows are not stored in any particular order • Data pages are not linked in a linked list
  • 5. Clustered Index • The data rows are stored in order based on the clustered index key • The clustered index is implemented as a B-tree index structure • Data pages in the leaf level, are linked in a doubly-linked list • Clustered indexes have one row in sys.partitions, with index_id = 1
  • 7. Non-Clustered Index • Nonclustered indexes have a B-tree index structure similar to the one in clustered indexes • The difference is that nonclustered indexes do not affect the order of the data rows. • Each index row contains the nonclustered key value, a row locator and any included, or nonkey, columns
  • 8. Query Optimization Simple flow chart Real pie chart
  • 9. Query Processing and Optimization Parsing Optimization Execution
  • 10. Query Processing and Optimization • Cost Based Optimizer • Disk IO Cost • CPU Cost • Memory Cost – Very insignificant • Indexes • Selects optimal indexes to be used • Query Algorithms • Converts Logical operation into physical operations
  • 11. Execution Plan Operators • When • Good • Bad • Action Item 80% - 20% Rule
  • 12. Table Scan • When Table without clustered index is accessed • Good or Bad* Can’t decide • Action Item Create Clustered Index
  • 13. Clustered Index Scan • When Table with clustered index is accessed but query doesn’t uses the clustered index key • Good or Bad* Bad unless large data with most columns and rows retrieved • Action Item Evaluate Clustered Index Keys
  • 14. Clustered Index Seek • When Table with clustered index is accessed and query locates specific rows in B+ tree • Good or Bad* Good • Action Item Evaluate possibility of non-clustered index
  • 15. Non-Clustered Index Scan • When Columns part of non-clustered index accessed in query • Good or Bad* Bad unless large data with most columns and rows retrieved • Action Item Create more refined non-clustered index
  • 16. Non-Clustered Index Seek • When Columns part of non-clustered index accessed in query and rows located in B+ tree • Good or Bad* Good • Action Item Further evaluate other operators
  • 17. Lookups • When Query Optimizer uses non-clustered index to search few column data and base table for other columns data • Good or Bad* Good • Action Item Included Index or Covered Index