SlideShare a Scribd company logo
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

PPT
TCC14 tour hague optimising workbooks
PPTX
Big Data Project using HIVE - college scorecard
PPTX
Topic sensitive page rank(review)
PDF
Analytics with R in SQL Server 2016
PPTX
Efficient & effective data management for research projects : ILRI's Data Ma...
PDF
Introduction to NOSQL quadrants
PPTX
Teaching Economics Students to become Data Professionals Using SAS
PPTX
IDEA 10.3 Launch Webinar
TCC14 tour hague optimising workbooks
Big Data Project using HIVE - college scorecard
Topic sensitive page rank(review)
Analytics with R in SQL Server 2016
Efficient & effective data management for research projects : ILRI's Data Ma...
Introduction to NOSQL quadrants
Teaching Economics Students to become Data Professionals Using SAS
IDEA 10.3 Launch Webinar

What's hot (8)

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

Viewers also liked (7)

PDF
Social Media Business Coach - Followers Strategy
PDF
Sound Waves Explained
DOCX
DOCX
Konsep wilayah
PPTX
Hadoop Distributed File System
PDF
2D wave interference
PPTX
Michelson interferometer
Social Media Business Coach - Followers Strategy
Sound Waves Explained
Konsep wilayah
Hadoop Distributed File System
2D wave interference
Michelson interferometer
Ad

Similar to SAG_Indexing and Query Optimization (20)

PPTX
JSSUG: SQL Sever Index Tuning
PPTX
dotnetMALAGA - Sql query tuning guidelines
PPTX
Introduction of sql server indexing
PPTX
We Don't Need Roads: A Developers Look Into SQL Server Indexes
PPTX
Indy pass writing efficient queries – part 1 - indexing
PPTX
Sql performance tuning
PPTX
Database Performance
PPTX
Geek Sync | Understand Indexes to Write Better Queries
PPTX
Sql server lesson6
DOCX
Indexes in ms sql server
PDF
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
PDF
Statistics and Indexes Internals
PPT
SQL Server 2000 Research Series - Performance Tuning
PPTX
SQL Server Index and Partition Strategy
PDF
Db performance optimization with indexing
PPTX
Sql query performance analysis
PDF
SQLDay2013_Denny Cherry - Table indexing for the .NET Developer
PPS
07 qmds2005 session10
PDF
Mysql query optimization
PPTX
Dev Sql Indexing Strategies
JSSUG: SQL Sever Index Tuning
dotnetMALAGA - Sql query tuning guidelines
Introduction of sql server indexing
We Don't Need Roads: A Developers Look Into SQL Server Indexes
Indy pass writing efficient queries – part 1 - indexing
Sql performance tuning
Database Performance
Geek Sync | Understand Indexes to Write Better Queries
Sql server lesson6
Indexes in ms sql server
"Using Indexes in SQL Server 2008" by Alexander Korotkiy, part 1
Statistics and Indexes Internals
SQL Server 2000 Research Series - Performance Tuning
SQL Server Index and Partition Strategy
Db performance optimization with indexing
Sql query performance analysis
SQLDay2013_Denny Cherry - Table indexing for the .NET Developer
07 qmds2005 session10
Mysql query optimization
Dev Sql Indexing Strategies

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