SlideShare a Scribd company logo
Writing Efficient Queries – Part 1Using SQL Server Internals to Improve Data AccessEddie WuerchMCT, MCITPPrincipal, Data ManagementExactTargeteddie@indydba.com
Disk I/O – Key PointsDisk I/O (reads and writes) is usually the slowest component of a systemCompare: Memory and CPU speeds are reported in GHz: billions of actions per secondDisk I/O rates are simply measured in IOPS: Input/output Operations Per SecondFast disks on mostly sequential workloads can get 100-150 IOPSBecause of disk access rates, our first tuning goal is to reduce overall I/O…so let’s look at those data pages, then examine how to process less of them
Disk I/O – Key Points - IISQL Server is not a black boxMost data is in structured storageThere are many ways to access the data, some ways are significantly faster – and cause less impact on other processes - than othersUnderstanding SQL Server data storage internals will guide you to the faster ways
Data Storage in SQL ServerThe base unit of SQL Server data storage is the pageAll data – system and user – is stored in pagesEach page is 8KB (8192 bytes)Pages are allocated from files in 64KB (8-page) extents
Page ProcessingPages are read from disk and processed in memory as an entire 8KB unitExtents are often read in from disk as a single block to reduce I/OAll data is processed in memory, pulled from disk first (processing put on hold) if data is not in memory
Page TypesSystem Page TypesSpace Management: File Header, PFS, GAM, SGAMChange Management: DCM, BCMData Page TypesIn-row data Index LOB data and Row-overflow dataAll pages are 8KB
In-Row Data Pages96-byte Page HeaderPage HeaderRow Data
Rows written serially
Starts at 97th byteRow 1…Row 2…Row 3…Row 4…Row-offset table
Starts at end of page, moves backwards
Records first-byte offset of each row4… 3… 2… 1…
Disk Access MethodsThink of a phone book, with each entry as a recordOrdered by Last Name, First Name, MITwo ways to find a record:Use Last Name, First Name to find a number (Index Seek)Look through the entire phone book, one page at a time, scanning each row for data (Table Scan)
Clustered IndexRepresents the table itselfIndex specifies the physical ordering of that dataOnly 1 allowed per tableMay be unique, does not have to be the primary keyNon-clustered indexAdditional index of dataOver 200 allowedMay be uniqueIndex Types
The phone book exampleIf a table has a clustered index, the pointer to each row in the table is the clustered index keyThe leaf level of the nonclustered index contains the nonclustered keys and the clustered index keysNonclustered indexes may also include additional non-indexed columns, will be stored at the leaf level of the index
Index PagesA-K : Page 4L-U : Page 5V-Z : Page 6 456A : Page 22B : Page 23C : Page 24 D….Baa : Page 276Baba : Page 277Base : Page 278Ba…222324252627274275276277278279280281282283
Index Lookups
Index Lookups - revistedNonclustered indexSeparate trip through the clustered index for each ncl entry!Clustered index (table)
Operational Join TypesMerge JoinsHash JoinsLoop Joins
Join Type ComparisonLoopMergeHashWhen the other two can’t be used
One trip through one table
One trip through the other table for each entry in the first table
Generally the slowest of the three typesOne trip through each tableRequires indexes on both sides, at least one of them must be uniqueUsually the fastest join typeWorks well for very large joinsBuilds join data in tempdb
Join and Indexing TipsWhen defining an index, if the data is unique, then declare the index as uniqueJoin on keysProvide arguments in WHERE clauses to match available indexesCluster tables on range scansLook for covering indexes
So How Do I Know?SET STATISTICS IO ON

More Related Content

What's hot

MS Sql Server: Introduction To Database Concepts
MS Sql Server: Introduction To Database ConceptsMS Sql Server: Introduction To Database Concepts
MS Sql Server: Introduction To Database Concepts
DataminingTools Inc
 
Structure of the page table
Structure of the page tableStructure of the page table
Structure of the page table
duvvuru madhuri
 
File organization
File organizationFile organization
File organization
RituBhargava7
 
Data indexing presentation
Data indexing presentationData indexing presentation
Data indexing presentation
gmbmanikandan
 
Inverted page tables basic
Inverted page tables basicInverted page tables basic
Inverted page tables basic
Sanoj Kumar
 
Operating System- Multilevel Paging, Inverted Page Table
Operating System- Multilevel Paging, Inverted Page TableOperating System- Multilevel Paging, Inverted Page Table
Operating System- Multilevel Paging, Inverted Page Table
Zishan Mohsin
 
Concept of computer files
Concept of computer filesConcept of computer files
Concept of computer files
Samuel Igbanogu
 
Performance Improvements
Performance ImprovementsPerformance Improvements
Performance Improvements
Alexandro Colorado
 
File organisation
File organisationFile organisation
File organisation
Mukund Trivedi
 
Data Organization in InnoDB
Data Organization in InnoDBData Organization in InnoDB
Data Organization in InnoDB
Zhaoyang Wang
 
Falando de MySQL
Falando de MySQLFalando de MySQL
Falando de MySQL
Márcio Junior
 
File organisation
File organisationFile organisation
File organisation
Suneel Dogra
 
File organization continued
File organization continuedFile organization continued
File organization continued
chesterking12
 
File structures
File structuresFile structures
File structures
Shyam Kumar
 
[Www.pkbulk.blogspot.com]dbms12
[Www.pkbulk.blogspot.com]dbms12[Www.pkbulk.blogspot.com]dbms12
[Www.pkbulk.blogspot.com]dbms12
AnusAhmad
 
Sql server basics
Sql server basicsSql server basics
Sql server basics
Dilfaroz Khan
 
Lecture storage-buffer
Lecture storage-bufferLecture storage-buffer
Lecture storage-buffer
Klaas Krona
 
Fundamental File Processing Operations
Fundamental File Processing OperationsFundamental File Processing Operations
Fundamental File Processing Operations
Rico
 
Hardware implementation of page table
Hardware implementation of page table Hardware implementation of page table
Hardware implementation of page table
Sukhraj Singh
 
Indexing and hashing
Indexing and hashingIndexing and hashing
Indexing and hashing
Jeet Poria
 

What's hot (20)

MS Sql Server: Introduction To Database Concepts
MS Sql Server: Introduction To Database ConceptsMS Sql Server: Introduction To Database Concepts
MS Sql Server: Introduction To Database Concepts
 
Structure of the page table
Structure of the page tableStructure of the page table
Structure of the page table
 
File organization
File organizationFile organization
File organization
 
Data indexing presentation
Data indexing presentationData indexing presentation
Data indexing presentation
 
Inverted page tables basic
Inverted page tables basicInverted page tables basic
Inverted page tables basic
 
Operating System- Multilevel Paging, Inverted Page Table
Operating System- Multilevel Paging, Inverted Page TableOperating System- Multilevel Paging, Inverted Page Table
Operating System- Multilevel Paging, Inverted Page Table
 
Concept of computer files
Concept of computer filesConcept of computer files
Concept of computer files
 
Performance Improvements
Performance ImprovementsPerformance Improvements
Performance Improvements
 
File organisation
File organisationFile organisation
File organisation
 
Data Organization in InnoDB
Data Organization in InnoDBData Organization in InnoDB
Data Organization in InnoDB
 
Falando de MySQL
Falando de MySQLFalando de MySQL
Falando de MySQL
 
File organisation
File organisationFile organisation
File organisation
 
File organization continued
File organization continuedFile organization continued
File organization continued
 
File structures
File structuresFile structures
File structures
 
[Www.pkbulk.blogspot.com]dbms12
[Www.pkbulk.blogspot.com]dbms12[Www.pkbulk.blogspot.com]dbms12
[Www.pkbulk.blogspot.com]dbms12
 
Sql server basics
Sql server basicsSql server basics
Sql server basics
 
Lecture storage-buffer
Lecture storage-bufferLecture storage-buffer
Lecture storage-buffer
 
Fundamental File Processing Operations
Fundamental File Processing OperationsFundamental File Processing Operations
Fundamental File Processing Operations
 
Hardware implementation of page table
Hardware implementation of page table Hardware implementation of page table
Hardware implementation of page table
 
Indexing and hashing
Indexing and hashingIndexing and hashing
Indexing and hashing
 

Viewers also liked

Presentation New
Presentation NewPresentation New
Presentation New
adamsutherland8
 
3 Kodu
3 Kodu3 Kodu
3 Kodu
llangit
 
1 Win7 For Devs Fund Search
1 Win7 For Devs Fund Search1 Win7 For Devs Fund Search
1 Win7 For Devs Fund Search
llangit
 
3 App Compat Win7
3 App Compat Win73 App Compat Win7
3 App Compat Win7
llangit
 
SQL Programming
SQL ProgrammingSQL Programming
4 Making Movies
4 Making Movies4 Making Movies
4 Making Movies
llangit
 
MS SQL SERVER: Programming sql server data mining
MS SQL SERVER: Programming sql server data miningMS SQL SERVER: Programming sql server data mining
MS SQL SERVER: Programming sql server data mining
DataminingTools Inc
 

Viewers also liked (7)

Presentation New
Presentation NewPresentation New
Presentation New
 
3 Kodu
3 Kodu3 Kodu
3 Kodu
 
1 Win7 For Devs Fund Search
1 Win7 For Devs Fund Search1 Win7 For Devs Fund Search
1 Win7 For Devs Fund Search
 
3 App Compat Win7
3 App Compat Win73 App Compat Win7
3 App Compat Win7
 
SQL Programming
SQL ProgrammingSQL Programming
SQL Programming
 
4 Making Movies
4 Making Movies4 Making Movies
4 Making Movies
 
MS SQL SERVER: Programming sql server data mining
MS SQL SERVER: Programming sql server data miningMS SQL SERVER: Programming sql server data mining
MS SQL SERVER: Programming sql server data mining
 

Similar to Indy pass writing efficient queries – part 1 - indexing

Mysql For Developers
Mysql For DevelopersMysql For Developers
Mysql For Developers
Carol McDonald
 
Database Performance
Database PerformanceDatabase Performance
Database Performance
Boris Hristov
 
SQLServer Database Structures
SQLServer Database Structures SQLServer Database Structures
SQLServer Database Structures
Antonios Chatzipavlis
 
15 Ways to Kill Your Mysql Application Performance
15 Ways to Kill Your Mysql Application Performance15 Ways to Kill Your Mysql Application Performance
15 Ways to Kill Your Mysql Application Performance
guest9912e5
 
Myth busters - performance tuning 103 2008
Myth busters - performance tuning 103 2008Myth busters - performance tuning 103 2008
Myth busters - performance tuning 103 2008
paulguerin
 
Types of Databases
Types of DatabasesTypes of Databases
Types of Databases
kedar2310
 
Data storage and indexing
Data storage and indexingData storage and indexing
Data storage and indexing
pradeepa velmurugan
 
The thinking persons guide to data warehouse design
The thinking persons guide to data warehouse designThe thinking persons guide to data warehouse design
The thinking persons guide to data warehouse design
Calpont
 
Implementing the Databese Server session 02
Implementing the Databese Server session 02Implementing the Databese Server session 02
Implementing the Databese Server session 02
Guillermo Julca
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
guest9d79e073
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
Mark Ginnebaugh
 
Inside SQL Server In-Memory OLTP
Inside SQL Server In-Memory OLTPInside SQL Server In-Memory OLTP
Inside SQL Server In-Memory OLTP
Bob Ward
 
database.pdf
database.pdfdatabase.pdf
database.pdf
stirlingvwriters
 
CS 542 Putting it all together -- Storage Management
CS 542 Putting it all together -- Storage ManagementCS 542 Putting it all together -- Storage Management
CS 542 Putting it all together -- Storage Management
J Singh
 
Storage struct
Storage structStorage struct
Storage struct
durgaprasad1407
 
Pandi
PandiPandi
Pandi
Pandi C
 
Sql Server Performance Tuning
Sql Server Performance TuningSql Server Performance Tuning
Sql Server Performance Tuning
Bala Subra
 
Ch 7 Physical D B Design
Ch 7  Physical D B  DesignCh 7  Physical D B  Design
Ch 7 Physical D B Design
guest8fdbdd
 
Mass storage systemsos
Mass storage systemsosMass storage systemsos
Mass storage systemsos
Gokila Manickam
 
Sql server performance tuning and optimization
Sql server performance tuning and optimizationSql server performance tuning and optimization
Sql server performance tuning and optimization
Manish Rawat
 

Similar to Indy pass writing efficient queries – part 1 - indexing (20)

Mysql For Developers
Mysql For DevelopersMysql For Developers
Mysql For Developers
 
Database Performance
Database PerformanceDatabase Performance
Database Performance
 
SQLServer Database Structures
SQLServer Database Structures SQLServer Database Structures
SQLServer Database Structures
 
15 Ways to Kill Your Mysql Application Performance
15 Ways to Kill Your Mysql Application Performance15 Ways to Kill Your Mysql Application Performance
15 Ways to Kill Your Mysql Application Performance
 
Myth busters - performance tuning 103 2008
Myth busters - performance tuning 103 2008Myth busters - performance tuning 103 2008
Myth busters - performance tuning 103 2008
 
Types of Databases
Types of DatabasesTypes of Databases
Types of Databases
 
Data storage and indexing
Data storage and indexingData storage and indexing
Data storage and indexing
 
The thinking persons guide to data warehouse design
The thinking persons guide to data warehouse designThe thinking persons guide to data warehouse design
The thinking persons guide to data warehouse design
 
Implementing the Databese Server session 02
Implementing the Databese Server session 02Implementing the Databese Server session 02
Implementing the Databese Server session 02
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
 
Inside SQL Server In-Memory OLTP
Inside SQL Server In-Memory OLTPInside SQL Server In-Memory OLTP
Inside SQL Server In-Memory OLTP
 
database.pdf
database.pdfdatabase.pdf
database.pdf
 
CS 542 Putting it all together -- Storage Management
CS 542 Putting it all together -- Storage ManagementCS 542 Putting it all together -- Storage Management
CS 542 Putting it all together -- Storage Management
 
Storage struct
Storage structStorage struct
Storage struct
 
Pandi
PandiPandi
Pandi
 
Sql Server Performance Tuning
Sql Server Performance TuningSql Server Performance Tuning
Sql Server Performance Tuning
 
Ch 7 Physical D B Design
Ch 7  Physical D B  DesignCh 7  Physical D B  Design
Ch 7 Physical D B Design
 
Mass storage systemsos
Mass storage systemsosMass storage systemsos
Mass storage systemsos
 
Sql server performance tuning and optimization
Sql server performance tuning and optimizationSql server performance tuning and optimization
Sql server performance tuning and optimization
 

Recently uploaded

Mule Experience Hub and Release Channel with Java 17
Mule Experience Hub and Release Channel with Java 17Mule Experience Hub and Release Channel with Java 17
Mule Experience Hub and Release Channel with Java 17
Bhajan Mehta
 
NVIDIA at Breakthrough Discuss for Space Exploration
NVIDIA at Breakthrough Discuss for Space ExplorationNVIDIA at Breakthrough Discuss for Space Exploration
NVIDIA at Breakthrough Discuss for Space Exploration
Alison B. Lowndes
 
FIDO Munich Seminar Introduction to FIDO.pptx
FIDO Munich Seminar Introduction to FIDO.pptxFIDO Munich Seminar Introduction to FIDO.pptx
FIDO Munich Seminar Introduction to FIDO.pptx
FIDO Alliance
 
FIDO Munich Seminar Workforce Authentication Case Study.pptx
FIDO Munich Seminar Workforce Authentication Case Study.pptxFIDO Munich Seminar Workforce Authentication Case Study.pptx
FIDO Munich Seminar Workforce Authentication Case Study.pptx
FIDO Alliance
 
Demystifying Neural Networks And Building Cybersecurity Applications
Demystifying Neural Networks And Building Cybersecurity ApplicationsDemystifying Neural Networks And Building Cybersecurity Applications
Demystifying Neural Networks And Building Cybersecurity Applications
Priyanka Aash
 
Camunda Chapter NY Meetup July 2024.pptx
Camunda Chapter NY Meetup July 2024.pptxCamunda Chapter NY Meetup July 2024.pptx
Camunda Chapter NY Meetup July 2024.pptx
ZachWylie3
 
TrustArc Webinar - Innovating with TRUSTe Responsible AI Certification
TrustArc Webinar - Innovating with TRUSTe Responsible AI CertificationTrustArc Webinar - Innovating with TRUSTe Responsible AI Certification
TrustArc Webinar - Innovating with TRUSTe Responsible AI Certification
TrustArc
 
FIDO Munich Seminar: Biometrics and Passkeys for In-Vehicle Apps.pptx
FIDO Munich Seminar: Biometrics and Passkeys for In-Vehicle Apps.pptxFIDO Munich Seminar: Biometrics and Passkeys for In-Vehicle Apps.pptx
FIDO Munich Seminar: Biometrics and Passkeys for In-Vehicle Apps.pptx
FIDO Alliance
 
Mastering Board Best Practices: Essential Skills for Effective Non-profit Lea...
Mastering Board Best Practices: Essential Skills for Effective Non-profit Lea...Mastering Board Best Practices: Essential Skills for Effective Non-profit Lea...
Mastering Board Best Practices: Essential Skills for Effective Non-profit Lea...
OnBoard
 
FIDO Munich Seminar: FIDO Tech Principles.pptx
FIDO Munich Seminar: FIDO Tech Principles.pptxFIDO Munich Seminar: FIDO Tech Principles.pptx
FIDO Munich Seminar: FIDO Tech Principles.pptx
FIDO Alliance
 
Top 12 AI Technology Trends For 2024.pdf
Top 12 AI Technology Trends For 2024.pdfTop 12 AI Technology Trends For 2024.pdf
Top 12 AI Technology Trends For 2024.pdf
Marrie Morris
 
What's New in Copilot for Microsoft 365 June 2024.pptx
What's New in Copilot for Microsoft 365 June 2024.pptxWhat's New in Copilot for Microsoft 365 June 2024.pptx
What's New in Copilot for Microsoft 365 June 2024.pptx
Stephanie Beckett
 
Generative AI technology is a fascinating field that focuses on creating comp...
Generative AI technology is a fascinating field that focuses on creating comp...Generative AI technology is a fascinating field that focuses on creating comp...
Generative AI technology is a fascinating field that focuses on creating comp...
Nohoax Kanont
 
History and Introduction for Generative AI ( GenAI )
History and Introduction for Generative AI ( GenAI )History and Introduction for Generative AI ( GenAI )
History and Introduction for Generative AI ( GenAI )
Badri_Bady
 
Increase Quality with User Access Policies - July 2024
Increase Quality with User Access Policies - July 2024Increase Quality with User Access Policies - July 2024
Increase Quality with User Access Policies - July 2024
Peter Caitens
 
FIDO Munich Seminar: Strong Workforce Authn Push & Pull Factors.pptx
FIDO Munich Seminar: Strong Workforce Authn Push & Pull Factors.pptxFIDO Munich Seminar: Strong Workforce Authn Push & Pull Factors.pptx
FIDO Munich Seminar: Strong Workforce Authn Push & Pull Factors.pptx
FIDO Alliance
 
How UiPath Discovery Suite supports identification of Agentic Process Automat...
How UiPath Discovery Suite supports identification of Agentic Process Automat...How UiPath Discovery Suite supports identification of Agentic Process Automat...
How UiPath Discovery Suite supports identification of Agentic Process Automat...
DianaGray10
 
Scaling Vector Search: How Milvus Handles Billions+
Scaling Vector Search: How Milvus Handles Billions+Scaling Vector Search: How Milvus Handles Billions+
Scaling Vector Search: How Milvus Handles Billions+
Zilliz
 
Choosing the Best Outlook OST to PST Converter: Key Features and Considerations
Choosing the Best Outlook OST to PST Converter: Key Features and ConsiderationsChoosing the Best Outlook OST to PST Converter: Key Features and Considerations
Choosing the Best Outlook OST to PST Converter: Key Features and Considerations
webbyacad software
 
Redefining Cybersecurity with AI Capabilities
Redefining Cybersecurity with AI CapabilitiesRedefining Cybersecurity with AI Capabilities
Redefining Cybersecurity with AI Capabilities
Priyanka Aash
 

Recently uploaded (20)

Mule Experience Hub and Release Channel with Java 17
Mule Experience Hub and Release Channel with Java 17Mule Experience Hub and Release Channel with Java 17
Mule Experience Hub and Release Channel with Java 17
 
NVIDIA at Breakthrough Discuss for Space Exploration
NVIDIA at Breakthrough Discuss for Space ExplorationNVIDIA at Breakthrough Discuss for Space Exploration
NVIDIA at Breakthrough Discuss for Space Exploration
 
FIDO Munich Seminar Introduction to FIDO.pptx
FIDO Munich Seminar Introduction to FIDO.pptxFIDO Munich Seminar Introduction to FIDO.pptx
FIDO Munich Seminar Introduction to FIDO.pptx
 
FIDO Munich Seminar Workforce Authentication Case Study.pptx
FIDO Munich Seminar Workforce Authentication Case Study.pptxFIDO Munich Seminar Workforce Authentication Case Study.pptx
FIDO Munich Seminar Workforce Authentication Case Study.pptx
 
Demystifying Neural Networks And Building Cybersecurity Applications
Demystifying Neural Networks And Building Cybersecurity ApplicationsDemystifying Neural Networks And Building Cybersecurity Applications
Demystifying Neural Networks And Building Cybersecurity Applications
 
Camunda Chapter NY Meetup July 2024.pptx
Camunda Chapter NY Meetup July 2024.pptxCamunda Chapter NY Meetup July 2024.pptx
Camunda Chapter NY Meetup July 2024.pptx
 
TrustArc Webinar - Innovating with TRUSTe Responsible AI Certification
TrustArc Webinar - Innovating with TRUSTe Responsible AI CertificationTrustArc Webinar - Innovating with TRUSTe Responsible AI Certification
TrustArc Webinar - Innovating with TRUSTe Responsible AI Certification
 
FIDO Munich Seminar: Biometrics and Passkeys for In-Vehicle Apps.pptx
FIDO Munich Seminar: Biometrics and Passkeys for In-Vehicle Apps.pptxFIDO Munich Seminar: Biometrics and Passkeys for In-Vehicle Apps.pptx
FIDO Munich Seminar: Biometrics and Passkeys for In-Vehicle Apps.pptx
 
Mastering Board Best Practices: Essential Skills for Effective Non-profit Lea...
Mastering Board Best Practices: Essential Skills for Effective Non-profit Lea...Mastering Board Best Practices: Essential Skills for Effective Non-profit Lea...
Mastering Board Best Practices: Essential Skills for Effective Non-profit Lea...
 
FIDO Munich Seminar: FIDO Tech Principles.pptx
FIDO Munich Seminar: FIDO Tech Principles.pptxFIDO Munich Seminar: FIDO Tech Principles.pptx
FIDO Munich Seminar: FIDO Tech Principles.pptx
 
Top 12 AI Technology Trends For 2024.pdf
Top 12 AI Technology Trends For 2024.pdfTop 12 AI Technology Trends For 2024.pdf
Top 12 AI Technology Trends For 2024.pdf
 
What's New in Copilot for Microsoft 365 June 2024.pptx
What's New in Copilot for Microsoft 365 June 2024.pptxWhat's New in Copilot for Microsoft 365 June 2024.pptx
What's New in Copilot for Microsoft 365 June 2024.pptx
 
Generative AI technology is a fascinating field that focuses on creating comp...
Generative AI technology is a fascinating field that focuses on creating comp...Generative AI technology is a fascinating field that focuses on creating comp...
Generative AI technology is a fascinating field that focuses on creating comp...
 
History and Introduction for Generative AI ( GenAI )
History and Introduction for Generative AI ( GenAI )History and Introduction for Generative AI ( GenAI )
History and Introduction for Generative AI ( GenAI )
 
Increase Quality with User Access Policies - July 2024
Increase Quality with User Access Policies - July 2024Increase Quality with User Access Policies - July 2024
Increase Quality with User Access Policies - July 2024
 
FIDO Munich Seminar: Strong Workforce Authn Push & Pull Factors.pptx
FIDO Munich Seminar: Strong Workforce Authn Push & Pull Factors.pptxFIDO Munich Seminar: Strong Workforce Authn Push & Pull Factors.pptx
FIDO Munich Seminar: Strong Workforce Authn Push & Pull Factors.pptx
 
How UiPath Discovery Suite supports identification of Agentic Process Automat...
How UiPath Discovery Suite supports identification of Agentic Process Automat...How UiPath Discovery Suite supports identification of Agentic Process Automat...
How UiPath Discovery Suite supports identification of Agentic Process Automat...
 
Scaling Vector Search: How Milvus Handles Billions+
Scaling Vector Search: How Milvus Handles Billions+Scaling Vector Search: How Milvus Handles Billions+
Scaling Vector Search: How Milvus Handles Billions+
 
Choosing the Best Outlook OST to PST Converter: Key Features and Considerations
Choosing the Best Outlook OST to PST Converter: Key Features and ConsiderationsChoosing the Best Outlook OST to PST Converter: Key Features and Considerations
Choosing the Best Outlook OST to PST Converter: Key Features and Considerations
 
Redefining Cybersecurity with AI Capabilities
Redefining Cybersecurity with AI CapabilitiesRedefining Cybersecurity with AI Capabilities
Redefining Cybersecurity with AI Capabilities
 

Indy pass writing efficient queries – part 1 - indexing

  • 1. Writing Efficient Queries – Part 1Using SQL Server Internals to Improve Data AccessEddie WuerchMCT, MCITPPrincipal, Data ManagementExactTargeteddie@indydba.com
  • 2. Disk I/O – Key PointsDisk I/O (reads and writes) is usually the slowest component of a systemCompare: Memory and CPU speeds are reported in GHz: billions of actions per secondDisk I/O rates are simply measured in IOPS: Input/output Operations Per SecondFast disks on mostly sequential workloads can get 100-150 IOPSBecause of disk access rates, our first tuning goal is to reduce overall I/O…so let’s look at those data pages, then examine how to process less of them
  • 3. Disk I/O – Key Points - IISQL Server is not a black boxMost data is in structured storageThere are many ways to access the data, some ways are significantly faster – and cause less impact on other processes - than othersUnderstanding SQL Server data storage internals will guide you to the faster ways
  • 4. Data Storage in SQL ServerThe base unit of SQL Server data storage is the pageAll data – system and user – is stored in pagesEach page is 8KB (8192 bytes)Pages are allocated from files in 64KB (8-page) extents
  • 5. Page ProcessingPages are read from disk and processed in memory as an entire 8KB unitExtents are often read in from disk as a single block to reduce I/OAll data is processed in memory, pulled from disk first (processing put on hold) if data is not in memory
  • 6. Page TypesSystem Page TypesSpace Management: File Header, PFS, GAM, SGAMChange Management: DCM, BCMData Page TypesIn-row data Index LOB data and Row-overflow dataAll pages are 8KB
  • 7. In-Row Data Pages96-byte Page HeaderPage HeaderRow Data
  • 9. Starts at 97th byteRow 1…Row 2…Row 3…Row 4…Row-offset table
  • 10. Starts at end of page, moves backwards
  • 11. Records first-byte offset of each row4… 3… 2… 1…
  • 12. Disk Access MethodsThink of a phone book, with each entry as a recordOrdered by Last Name, First Name, MITwo ways to find a record:Use Last Name, First Name to find a number (Index Seek)Look through the entire phone book, one page at a time, scanning each row for data (Table Scan)
  • 13. Clustered IndexRepresents the table itselfIndex specifies the physical ordering of that dataOnly 1 allowed per tableMay be unique, does not have to be the primary keyNon-clustered indexAdditional index of dataOver 200 allowedMay be uniqueIndex Types
  • 14. The phone book exampleIf a table has a clustered index, the pointer to each row in the table is the clustered index keyThe leaf level of the nonclustered index contains the nonclustered keys and the clustered index keysNonclustered indexes may also include additional non-indexed columns, will be stored at the leaf level of the index
  • 15. Index PagesA-K : Page 4L-U : Page 5V-Z : Page 6 456A : Page 22B : Page 23C : Page 24 D….Baa : Page 276Baba : Page 277Base : Page 278Ba…222324252627274275276277278279280281282283
  • 17. Index Lookups - revistedNonclustered indexSeparate trip through the clustered index for each ncl entry!Clustered index (table)
  • 18. Operational Join TypesMerge JoinsHash JoinsLoop Joins
  • 19. Join Type ComparisonLoopMergeHashWhen the other two can’t be used
  • 20. One trip through one table
  • 21. One trip through the other table for each entry in the first table
  • 22. Generally the slowest of the three typesOne trip through each tableRequires indexes on both sides, at least one of them must be uniqueUsually the fastest join typeWorks well for very large joinsBuilds join data in tempdb
  • 23. Join and Indexing TipsWhen defining an index, if the data is unique, then declare the index as uniqueJoin on keysProvide arguments in WHERE clauses to match available indexesCluster tables on range scansLook for covering indexes
  • 24. So How Do I Know?SET STATISTICS IO ON
  • 25. So How Do I Know?
  • 26. So How Do I Know?sys.dm_db_index_usage_statsUser_seeksUser_scansUser_lookupsUser_updatesSys.dm_db_missing_index_*Not magic, has limitationsMany similar index entries with different INCLUDE statements may indicate a need to revisit the clustered index design
  • 27. So How Do I Know?Scan-indicating waitsLots of PAGEIOLATCH_SH and PAGEIOLATCH_EX waits are generated by tables scans that read from diskCX_PACKET waits – related to parallellism often caused by scanning large tables (don’t reduce MAXDOP: fix the scan!)Other processes with SOS_SCHEDULER_YIELD or high signal wait times may be mitigated by reducing CPU load of scans
  • 28. So How Do I Know?TempDB activity in instances without much use of temp tables or table variablesSELECT * FROM sys.dm_io_virtual_file_stats(DB_ID(‘TempDB’), NULL)Must track over time, perform time-slice analysisMay indicate additional worktable sort and hash-match activityTracking this for all of your databases shows the amount of I/O your systems are performing, and if the disk systems are keeping up
  • 29. ResourcesMicrosoft White PapersSQL Server 2000 I/O Basics (http://technet.microsoft.com/en-us/library/cc966500.aspx)SQL Server I/O Basics, Chapter 2 (http://technet.microsoft.com/en-us/library/cc917726.aspx)SQL Server Waits and Queues (download) (http://technet.microsoft.com/en-us/library/cc966413.aspx)The Waits and Queues document is highly recommended tuning or analyzing workloads
  • 30. ResourcesInside SQL Server Book SeriesSQL 2005The Storage Engine (Kalen Delaney)Query Tuning and Optimization (Delany, et. al.)T-SQL Querying (Ben-Gan, Kollar, Sarka)SQL 2008Microsoft SQL Server 2008 Internals (Delaney, Randal, Tripp, Cunningham)T-SQL Querying (Ben-Gan, Kollar, Sarka)