Indexing strategies and good physical designs for performance tuning Kenneth Ureña /SpanishPASSVC
Agenda The journey of a transaction Performance degradation factors Physical Designs Indexing Coding best practices
THE JOURNEY OF A TRANSACTION
Actual empty Virtual Log File Truncated -Sequential Access -Just 1 file Active -Recommended Raid 1 ó Commit, backup log trigger I/O Log File -Random Access -Multiple datafiles Active -Recommended Raid 1/ / 5 -Checkpoint, backup, load / unload Cache FullEmpty FullEmpty Full EmptyFull Data Files Cache fail Loads page Update page Commit Lazy Writter / Checkpoint
PERFORMANCE DEGRADATION FACTORS
HardwareSoftware DB Performance Degradation life cycle Overload Degraded Performance CPU / Memory Storage Peripheral Database Data Algorithm
Sata, SAS, SSD (Types of Hard Drives) Big performance difference between Sequential IO vs Random IO IOPS (In Out Per Second) IOPS Estimated = 1 / ((seek time / 1000) + (latency / 1000)) Storage Reference
Average read seek time: 3.4 ms Average write seek time: 3.9 ms Average latency: 2.0 ms Seek time = ( Average read seek time + Average write seek time) / 2 = ( ) / 2 = 3.65 ms IOPS Estimated = 1 / ((seek time / 1000) + (latency / 1000)) = 1 / ((3.65/1000) + (2.0 / 1000) = ~ 175 IOPS SAS - 600GB 15K - Seagate Reference
Raids Raid 0 Raid 1 Raid 5 Raid 1 + 0
Raid 0 (Stripping) Logical Drive Characteristics IOPS = #Disk * IOPS Estimated S ize = #Disks * Size disk Pros High performance Low cost Cons Fault tolerance
Raid 1 (Mirroring) Logical Drive Characteristics IOPS = (#Disk / 2) * IOPS Estimated S ize = (#Disk / 2) * Size disk Pros Fault tolerance Cons Higher cost
Raid 5 Logical Drive Characteristics IOPS = (#Disk - 1) * IOPS Estimated S ize = (#Disk - 1) * Size disk Pros Fault tolerance Cost Effective Cons Recalculation on raid failure Parity calculation
Raid Logical Drive Characteristics IOPS = (#Disk /2) * IOPS Estimated S ize = (#Disk / 2) * Size disk Pros Fault tolerance Cons Cost
Database Files Random Access Multiple Actives Data File Sequential Access One Active Log File
PHYSICAL DESIGNS
Physical Designs Choosing the right Raid for the Database File Split the files in order to get the expected Access behavior
Scenario #1 1 User Database High OLTP Traffic High TempDB consumption 16 Cores Server
Scenario #1 (Proposal 1) Raid 1+0 Drive SAS TempDB UserDB Raid 5 Drive SAS Raid 1+0 Drive SAS LOG File Data File
Scenario #1 (Proposal 2) Raid 1+0 Drive SAS TempDB UserDB Raid 1+0 Drive SAS Raid 1+0 Drive SAS LOG File Data File
Scenario #1 (Proposal 3) TempDB UserDB Raid 1+0 Drive SSD Raid 1+0 Drive SAS LOG, Data File LOG File Data File
Scenario #2 multiple User Database High OLTP Traffic High TempDB consumption multiple Cores Server
Scenario #2 (Proposal 1) Raid 1+0 Drive SAS TempDB Raid 1+0 Drive SAS Raid 1+0 Drive SAS LOG File Data File UserDBN Raid 1+0 Drive SAS Data File Raid 1 Drive SSD UserDB1 LOG File
INDEXING
Indexes and Organization Table structure Image from SQL server 2008 books online
Indexes and Organization Heap Table Image from: SQL server 2008 books online
Indexes and Organization Clustered Table Image from: SQL server 2008 books online
Clustered (example) Image from:
Indexes and Organization NonClustered Index Image from: SQL server 2008 books online
Column Index Image from
Data access patters Seek Scan Bookmark Lookup
Data access patters DEMO
CODING BEST PRACTICES
Coding Best Practices Maximize coverage Avoid conversions (implicit/explicit) Avoid row by row access (cursor pattern) Avoid unnecessary sorting Choose the right index for the expected data pattern access method
Q&A Thank you Kenneth Ureña /SpanishPASSVC