Professional Documents
Culture Documents
When Good Design Goes Bad: March 2015
When Good Design Goes Bad: March 2015
Bob Duffy
Database Architect
Prodata SQL Centre of Excellence
Bob Duffy
• 20 years in database sector, 250+ projects
• Senior Consultant with Microsoft 2005-2008
• One of about 25 MCA for SQL Server globally (aka SQL Ranger)
• SQL MCM on SQL 2005 and 2008
• SQL Server MVP 2009+
• SSAS Maestro
• Database Architect at Prodata SQL Centre of Excellence
• http://blogs.prodata.ie/author/bob.aspx
• bob@Prodata.ie
@bob_duffy
What We Will Cover
Stored Procedures
Clustered Tables
Identity and Primary Keys
Indexes
Fragmentation
Naming Conventions
Partitioning
ORM
1. Stored Procedures
Why use Stored Procedures ?
The Dreaded Search Screen
http://www.sommarskog.se/dyn-search.html
The Chunky v Chatty Debate
Two Types of “Chunkiness”
Data Transferred per Call
Number of Calls
Network latency Important here
Stored Procedure Weigh In
PK CustomerID PK CustomerKey
DimCustomer
CustomerName CustomerID
CustomerAddress PK CustomerKeyKeyKeyKey
CustomerName
CustomerAddress
CustomerKeyKeyKey
CustomerKeyKey
CustomerKey
CustomerID
CustomerName
CustomerAddress
4. We Don’t Need no Indexes?
Best Practise. Add Indexes..
To Reduce IO on important Queries
Seek rather than scan. SELECT * WHERE CustomerID=2
Narrower Scan. SELECT SUM(Qty)
DWH
Bad “Tipping Points”
Staging Tables
Tables that we scan
When avoiding bad statistics is very hard
Data Analytics
Where we need guaranteed query performance for varied workloads.
Guaranteed Performance !!?!
We have a 1TB Table. Query SLA is 5 mins… Add indexes?
5 Stop Worrying about Fragmentation
Best Practise – Defragment the hell out of your database
Ordered Queries
Maintenance Operations Serial Queries
Parallel Queries Dynamic Parallel Queries
8 ORMs
Best Practise ? Hotly debated
Good For
Developer Agility
Code First, Database Second
Integrated Debugging
Domain Business Model
Cache Management
Key Management
Portable
Query Plan Nightmares
Source: http://www.scarydba.com/2014/12/19/pretty-plans-vs-performance/
When ORMs go Bad
Can write truly horrible TSQL and Plans
Naïve context
Parameterisation
The Disaster Scenario
Lazy/Eager Loading
Can be used as an excuse of lack of database expertise
Hard to Index for (lots of Select *)
Everything has good and bad Aspects
It Depends ;-)