SQL Server Performance Tuning Starter Kit Randolph West | Born SQL.

Slides:



Advertisements
Similar presentations
10 Things Not To Do With SQL SQLBits 7. Some things you shouldn’t do.
Advertisements

Database Optimization & Maintenance Tim Richard ECM Training Conference#dbwestECM Agenda SQL Configuration OnBase DB Planning Backups Integrity.
SharePoint and SQL Server integration Demo: SQL Server Optimizing Configurations SQL Server 2014 for SharePoint 2013 Avoiding ginormous transaction.
SQL Server Query Optimizer Cost Formulas Joe Chang
Troubleshooting SQL Server Enterprise Geodatabase Performance Issues
TEMPDB Capacity Planning. Indexing Advantages – Increases performance – SQL server do not have to search all the rows. – Performance, Concurrency, Required.
Ashwani Roy Understanding Graphical Execution Plans Level 200.
Parallel Execution Plans Joe Chang
Large Data Operations Joe Chang
Query Optimizer Execution Plan Cost Model Joe Chang
SQLintersection Putting the "Squeeze" on Large Tables Improve Performance and Save Space with Data Compression Justin Randall Tuesday,
MISSION CRITICAL COMPUTING Siebel Database Considerations.
TOP 10 Thinks you shouldn’t do with/in your database
October 15-18, 2013 Charlotte, NC Accelerating Database Performance Using Compression Joseph D’Antoni, Solutions Architect Anexinet.
Dave LinkedIn
How to kill SQL Server Performance Håkan Winther.
Scott Fallen Sales Engineer, SQL Sentry Blog: scottfallen.blogspot.com.
Diving into Query Execution Plans ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
SQL Server Magic Buttons! What are Trace Flags and why should I care? Steinar Andersen, SQL Service Nordic AB Thanks to Thomas Kejser for peer-reviewing.
Indexing strategies and good physical designs for performance tuning Kenneth Ureña /SpanishPASSVC.
Hitting the SQL Server “Go Faster” Button Rob Douglas #509 | Brisbane 2016.
Get the Most out of SQL Server Standard Edition
Query Optimization Techniques
What Is a Latch? …and Why Do I Care? Eddie Wuerch, mcm
Execution Planning for Success
SQL Server Performance Tuning
Hitting the SQL Server “Go Faster” Button
Query Tuning without Production Data
Very Large Databases in your future
Query Tuning without Production Data
Query Tuning without Production Data
Chapter Overview Understanding the Database Architecture
Hustle and Bustle of SQL Pages
Reading Execution Plans Successfully
The Top 5 SQL Server Mistakes
Introduction to Execution Plans
The Vocabulary of Performance Tuning
Hitting the SQL Server “Go Faster” Button
The Vocabulary of Performance Tuning
Configuring SQL Server
Performance Tuning for Mere Mortals Part II
What Is a Latch? …and Why Do I Care? Eddie Wuerch, mcm
Execution Plans Demystified
Welcome to SQL Saturday Denmark
Peter Shore SQL Saturday Cleveland 2016
Steve Hood SimpleSQLServer.com
Very large Databases in your future Eric Peterson.
Performance Tuning for Mere Mortals Part II
Reading Execution Plans Successfully
SQL Server Query Plans Journeyman and Beyond
Configuring SQL Server
Indexing For Optimal Performance
SQL Server Query Optimizer Cost Formulas
SQL Server Performance Tuning
The Vocabulary of Performance Tuning
Four Rules For Columnstore Query Performance
Transaction Log Internals and Performance David M Maxwell
Introduction to Execution Plans
Diving into Query Execution Plans
Are you following SQL Server Development Best Practices?
Transaction Log Performance Tuning
Jean Joseph DBA\DEVELOPER
Introduction to Execution Plans
Sourav Mukherjee Are you following SQL Server Development Best Practices? March 30, 2019 Cincinnati.
The Vocabulary of Performance Tuning
Reading execution plans successfully
Introduction to Execution Plans
Using wait stats to determine why my server is slow
All about Indexes Gail Shaw.
Hybrid Buffer Pool The Good, the Bad and the Ugly
Presentation transcript:

SQL Server Performance Tuning Starter Kit Randolph West | Born SQL

Please Support Our Sponsors SQL Saturday is made possible with the generous support of these sponsors. You can support them by opting-in and visiting them in the sponsor area.

Don’t forget to silence your phone

SQL Server Internals The Quick and Dirty Version for the Database Engine

Basic Internals  Transaction Log File (LDF)  Virtual Log Files  Data File (MDF, NDF)  Data Page (8KB in size)  Indexes (Clustered, Non-Clustered)  Statistics (Cardinality Estimator)  Buffer Pool

Basic Internals: Transaction Log Transaction Log File (LDF: Log Data File) Database File Group VLF Commit on Write

Basic Internals: Data File Transaction Log File (LDF: Log Data File) Data File (MDF: Main Data File) (NDF: Non-Primary Data File) Database File Group 8KB 8 x 8KB pages = 1 extent (64KB)

Basic Internals: Page Rows ID 1: … ID 2: … ID 3: … ID 4: … ID 6: … ID 5: … Page Header Slot Array Paul Randal (SQLskills.com): Anatomy of a Page

Basic Internals: Tables ColID | PageID 1 | 2 7 | 6 ColID | PageID 1 | 1 4 | 4 ColID | Province 1 | AB 2 | ON 3 | ON ColID | Province 4 | ON 5 | AB 6 | SK ColID | PageID 7 | 5 10 | 7 ColID | Province 7 | SK 8 | YT 9 | YT ColID | Province 10 | QC 11 | SK 12 | NU Page 5Page 4 Page 3 Page 2 Page 1 Page 6 Page 7 Clustered on ColID

Basic Internals: Indexes Province | PageID AB | 2 QC | 6 Province | PageID AB | 1 ON | 4 Province | ColID AB | 1 AB | 5 NU | 12 Province | ColID ON | 2 ON | 3 ON | 4 Province | PageID QC | 5 SK | 5 Province | ColID QC | 10 SK | 6 SK | 7 Province | ColID SK | 11 YT | 8 YT | 9 Page 5Page 4 Page 3 Page 2 Page 1 Page 6 Page 7 Indexed on Province

Basic Internals: Heap id | indid First IAM = indid 0 Extent | Bitmap 110 | | | | 1 Table Data xxxxx | xxxxx Table Data xxxxx | xxxxx Table Data xxxxx | xxxxx Table Data xxxxx | xxxxx Extent 112Extent 111 sys.sysindexes Index Allocation Map Extent 110 Extent 113

Basic Internals: Indexes (Contd.)  Heap  No B-tree, no links → all info stored in Index Allocation Map (IAM)  Clustered Index  B-tree, the index is the data, double-linked list  Non-Clustered Index (“a smaller table”)  Unique Indexes and Constraints  Filtered Index (WHERE clause → “an even smaller table”)  Indexed View (persisted data)  Fill Factor (it doesn’t always work the way you think it does)   Fragmented Indexes? Don’t bother rebuilding*.  Update statistics instead.

Basic Internals: Statistics  Query Magic Happens Here  Distribution of Data (up to 200 steps)  Density of Data (rows per step)  Tipping Point (selectivity of data)  Auto-updated after 20% plus 500 rows changed  SQL Server 2016 is more intelligent  All query plan costs are based on these values  SQL Server 2014 Cardinality Estimator  DBCC SHOW_STATISTICS  Read more by Gail Shaw, Kimberly L. Tripp and Joe Sack

How Do You Make SQL Server Go Faster? Hint: put it all in memory

CPU Cache (MB in size) RAM (GB in size) Disk (TB in size) Network ( ∞ in size) L1 cache (128KB) GB/s L4 cache (128MB) - 40 GB/s DDR3 – 12 GB/s Solid State – 600 MB/s 1 Gbps Ethernet – 125 MB/s Performance vs Storage 4x 20x 3x

Put Your Database in Memory Put your database in the Buffer Pool < $10k for 384 GB* * Canadian dollars

Where Do I Begin?

 Hardware Configuration  Operating System  SQL Server Configuration  Monitoring Tools

Hardware  CPU (SMP or NUMA?)  RAM (memory pressure?)  Storage (many options)  Network (SAN? TCP offloading?)

Operating System  Physical or Virtual  Version and Edition  Drive allocation  Also cluster size, partition alignment  Instant File Initialization  Power Saving  What else is running on the server?

SQL Server Configuration  Version, Edition, Build, and Licence  Part of a Cluster, Mirror or Availability Group?  Trace Flags (1118, 1117*, 3226, possibly 4199)  sp_configure  Cost Threshold for Parallelism? Appropriate to workload.  Max Degree of Parallelism (MAXDOP)? Cores in NUMA node.  Optimize for Ad-Hoc Queries? Turn it on.  Max Server Memory? Appropriate to environment.  Backup Compression? Turn it on.  Lightweight Pooling and Priority Boost? Turn it off.  Agent Jobs  Maintenance tasks  System Databases

User Databases  Number of Databases  Data and Transaction Log file allocation  File growth, free space, location, VLFs  I/O Performance  Latency < 10ms  Recovery Mode  Compatibility Level  SQL Server  Page Verify Option  Always be CHECKSUM  Auto-Update Statistics  Always be on

Monitoring Tools  DO YOU HAVE A BASELINE?  Dynamic Management Views  Missing Indexes:  sys.dm_db_missing_index_details  sys.dm_db_missing_index_groups  Wait Statistics: sys.dm_os_wait_stats  Sessions: sys.dm_exec_sessions  Free Tools  sp_WhoIsActive (Adam Machanic)  Diagnostic Scripts (Glenn Berry, SQLskills.com)  sp_Blitz, sp_BlitzIndex, sp_AskBrent (BrentOzar.com)

Tuning Process  TempDB performance  “The public toilet of SQL Server” - Brent Ozar  Indexes  Unique clustered indexes on all tables  Non-clustered covering indexes (avoid key lookups)  Included columns (2005+)  Filtered indexes (2008+) (WHERE clause)  Indexed views (materialized views)  Statistics  20% plus 500 rows changed (2016+ has changed)  Query Tuning (the last resort)

Query Tuning  Examine the longest running queries  Memory consumers  Sort, hash aggregate, hash join  Blocking operators  Sort, scalar aggregates, hash join, eager spool, any operation that can spill to disk (e.g. worktable)  Types of join  nested loop, merge, hash

Query Tuning (Contd.)  Examine the longest running queries  Key / Bookmark Lookups (try a covering index)  Cursors vs CROSS APPLY  Temp tables vs table variables  Collation  Implicit conversions  Craig Freedman:

Tips and Tricks  Stored procedures beat ad-hoc queries any day  Statistics are updated at 20% plus 500 rows  Avoid query hints at all costs  Parameterised dynamic T-SQL can be good  Tipping point (scans vs seeks)  Parameter sniffing can be bad  OPTIMIZE FOR UNKNOWN could be worse  Table Valued Function  It depends …

Contact Me  Blog: