Indexing strategies and good physical
designs for performance tuning
Kenneth Ureña
http://www.sqlcr.com
@sqlcr
/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 ó 1 + 0
- Commit, backup log
trigger I/O
- Random Access
- Multiple datafiles Active
- Recommended Raid 1/1+0
5+0 / 5
- Checkpoint, backup, load /
unload Cache
Full Empty Full Empty
Empty Full Empty Full
PERFORMANCE DEGRADATION
FACTORS
Hardware Software
DB Performance Degradation life cycle
Overload
Degraded PerformanceCPU / 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
http://www.cloudbyte.com/docs/Whitepaper_CloudByte_Measuring-Storage-Performance.pdf
• 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
= (3.4 + 3.9) / 2 = 3.65 ms
• IOPS Estimated = 1 / ((seek time / 1000) + (latency / 1000))
= 1 / ((3.65/1000) + (2.0 / 1000)
= 176.9911 ~ 175 IOPS
SAS - 600GB 15K - Seagate
Reference
http://www.seagate.com/www/en-us/products/enterprise-hard-drives/cheetah-15k#tTabContentSpecifications
Raids
• Raid 0
• Raid 1
• Raid 5
• Raid 1 + 0
Raid 0 (Stripping)
 Logical Drive Characteristics
 IOPS = #Disk * IOPS Estimated
 Size = #Disks * Size disk
 Pros
 High performance
 Low cost
 Cons
 Fault tolerance
2
4
6
1
2
3
4
5
6
1
3
5
Raid 0
(Striping)
Disk1 Disk2
Logical
Drive
Raid 1 (Mirroring)
 Logical Drive Characteristics
 IOPS = (#Disk / 2) * IOPS Estimated
 Size = (#Disk / 2) * Size disk
 Pros
 Fault tolerance
 Cons
 Higher cost
1
2
3
4
5
6
Raid 1
(Mirror)
Disk1 Disk2
Logical
Drive
1
2
3
4
5
6
1
2
3
4
5
6
Raid 5
 Logical Drive Characteristics
 IOPS = (#Disk - 1) * IOPS Estimated
 Size = (#Disk - 1) * Size disk
 Pros
 Fault tolerance
 Cost Effective
 Cons
 Recalculation on raid failure
 Parity calculation
1
2
3
4
5
6
Disk2
Logical
Drive
Disk1
1
3
P
2
P
5
P
4
6
Raid 5
Disk3
2
4
6
1
2
3
4
5
6
Disk3
Logical
Drive
2
4
6
Disk4
Raid 1Raid 1
Raid 0
1
3
5
Disk2
1
3
5
Disk1
Raid 1 + 0
 Logical Drive Characteristics
 IOPS = (#Disk /2) * IOPS Estimated
 Size = (#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
Scenario #1 (Proposal 2)
Raid 1+0 Drive
SAS
TempDB UserDB
Raid 1+0 Drive
SAS
Raid 1+0 Drive
SAS
Scenario #1 (Proposal 3)
TempDB UserDB
Raid 1+0 Drive
SSD
Raid 1+0 Drive
SAS
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
UserDBN
Raid 1+0 Drive
SAS
Raid 1 Drive
SSD
UserDB1
INDEXING
Indexes and OrganizationTable structure
Image from
SQL server 2008 books online
Indexes and OrganizationHeap Table
Image from:
SQL server 2008 books online
Indexes and OrganizationClustered Table
Image from:
SQL server 2008 books online
Clustered (example)
Image from:
http://www.sqlservercentral.com/images/4695.jpg
Indexes and OrganizationNonClustered
Index
Image from:
SQL server 2008 books online
Column Index
Image from
http://magenic.com/
Data access patters
 Seek
 Scan
 Bookmark Lookup
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
http://www.sqlcr.com
@sqlcr
/SpanishPASSVC

Sqlcr indexing strategies and good physical designs for performance tuning

Editor's Notes

  • #3 This is what we are going to cover on this session, - Essentials of Raid Arrays configuration The basic that what happen under the seen during a transaction How can the data and log files been organized in order to
  • #7 Usually Hardware issues cause performance degradation in the software Changes on the software usually create hardware bottleneck and get reflected in performance degradation And that is the base of the problem, here is where you see DBA’s fighting Developers or DBA’s fighting San Administrators