0% found this document useful (0 votes)
138 views15 pages

SQ L Performance Tuning

This document provides an agenda for a presentation on SQL optimization and performance tuning. The agenda includes topics such as improving query speed through benchmarking and execution plans, using indexing strategies, deciding between common table expressions and temporary tables, optimizing stored procedures versus views, and using grouping sets. The presentation also provides an example optimization and discusses benefits of optimization including supporting application and database growth. It emphasizes the importance of commenting code and ongoing learning.

Uploaded by

Jeff Neima
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
138 views15 pages

SQ L Performance Tuning

This document provides an agenda for a presentation on SQL optimization and performance tuning. The agenda includes topics such as improving query speed through benchmarking and execution plans, using indexing strategies, deciding between common table expressions and temporary tables, optimizing stored procedures versus views, and using grouping sets. The presentation also provides an example optimization and discusses benefits of optimization including supporting application and database growth. It emphasizes the importance of commenting code and ongoing learning.

Uploaded by

Jeff Neima
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

DWYWD:

SQL Optimization and


Performance Tuning
May 22nd, 2018

Tips and Tricks During SQL Optimization


Steve Sax
Development Manager
Agenda
Let’s Tune

• Derby Cars
• Jump Right In
• Improving Speed
• Execution Plans
• Index Analysis
• CTEs vs. Temp Tables
• Procs vs. Views
• Data Type Matching
• Grouping Sets
• Commented Code
• Optimization Example
• Pay Offs
• Learning
• Questions

DWYWD: SQL Optimization and Performance Tuning


1
Derby Cars
Bare Minimum vs Effort

DWYWD: SQL Optimization and Performance Tuning


2
Improving Speed
Benchmarking and Initial States

• Is what you have the best solution?


• Must have tools:
• SQL Query Stress
• Execution Plans
• Index Analysis

DWYWD: SQL Optimization and Performance Tuning


3
Execution Plans
Use them!

• Always use the actual execution plan


• Looks for obvious improvements
• Table scans
• Key lookups
• Index Scans vs. Index Seeks
• Nested Loops
• Anything out of the ordinary

DWYWD: SQL Optimization and Performance Tuning


4
Index Analysis
Always have a map

• Always examine table indexes


• Run index analysis scripts
• Be aware of index impact

DWYWD: SQL Optimization and Performance Tuning


5
CTEs vs. Temp Tables
Depends on scenario

• CTEs are great for views


• Be wary of the impact of the CTE
• Temp tables can have indexes added
• Try both

DWYWD: SQL Optimization and Performance Tuning


6
Procs vs. Views
Both have their place

• Favor procedures
• Views when appropriate
• Limit view chaining
• Don’t forget naming schemes

DWYWD: SQL Optimization and Performance Tuning


7
Data Type Matching
Apples to Oranges

• Don’t make SQL Server do unnecessary work


• DateTime != Date
• Parameters & Variables

DateTime Date

DWYWD: SQL Optimization and Performance Tuning


8
Grouping Sets
Not always evident there are shortcuts

• Lots of aggregates
• Runs faster
• Prevents duplicate code

DWYWD: SQL Optimization and Performance Tuning


9
Commented Code
What the heck is happening here?

• Always, always, always add comments to your code


• You will forget too
• Prevents special cases from being reversed

DWYWD: SQL Optimization and Performance Tuning


10
Optimization Example
Let’s run through an example

• Security API User Search


• Indexing
• SQL Query Stress
• Optimization
• When do we stop?

SELECT * FROM…

DWYWD: SQL Optimization and Performance Tuning


11
Pay Offs
Long Term Results

• Application growth
• Database size and number of objects growth
• Two types of user comments
• Who would you rather have on your team?
• Two complementary sides to app development

DWYWD: SQL Optimization and Performance Tuning


12
Learning
Increase Your Value

• YouTube
• PluralSight
• Google

DWYWD: SQL Optimization and Performance Tuning


13
Questions
?s

• What questions do you have?

DWYWD: SQL Optimization and Performance Tuning


14

You might also like