Download - You Can Tune Your Own SQL Code
![Page 1: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/1.jpg)
YOU CAN TUNE YOUR OWN CODESQL Saturday #33 Charlotte
![Page 2: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/2.jpg)
WHO IS MIKE?
10 years with SQL DBA roles of various sorts Blog: www.straightpathsql.com/ Syndicated at SQLServerPedia Full Time – Principal DBA at global insurance
company. “Spare” Time – Consult for SQL
Administration and Performance Issues President of new “Seacoast SQL” PASS
Chapter
![Page 3: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/3.jpg)
Who Are You?
![Page 4: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/4.jpg)
“Why is this so slow?!”
“It worked fine in dev!”
“The results came back fine… I’m done”
![Page 5: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/5.jpg)
What Aren’t We Covering?
![Page 6: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/6.jpg)
“Can’t you just make it
faster?!”
http://www.flickr.com/photos/irinaslutsky/4000761728/
![Page 7: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/7.jpg)
www.flickr.com/photos/no3rdw/170950846/
![Page 8: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/8.jpg)
www.flickr.com/photos/no3rdw/170950846/http://www.flickr.com/photos/dullhunk/359634390/
![Page 9: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/9.jpg)
AGENDA
Tips For Slow Queries The Right Mindset & Some Best Practices Indexes & Statistics (Building Blocks) Query Plans (Not So Scary) SQL Profiler (Don’t tell my DBA friends..) Put it all together and CLAP DBAs don’t mean to be so mean*
*Maybe we do…, but let’s work it out
![Page 10: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/10.jpg)
Goal 1
You will leave using the concepts we
discuss.
![Page 11: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/11.jpg)
Goal 2
You won’t ever say, “done” until you know your code
PERFORMS
![Page 12: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/12.jpg)
Goal 3
“Can’t we all just get
along??!”
![Page 13: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/13.jpg)
Tips For Making Queries Slow
![Page 14: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/14.jpg)
![Page 15: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/15.jpg)
Right Mindset
![Page 16: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/16.jpg)
RIGHT MINDSET
• SQL Is Declarative• Work With Sets• Watch Transaction Footprint• Join Where Necessary• Remember: Disk – Memory –
Query• Smaller Sets ASAP• Work with the columns you need
![Page 17: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/17.jpg)
“Should I split this up?”
“Should I use -that- view?”
“How Many Reads Am I
doing?”
“What will happen in 1
year?”
“How many rows are
affected by that operation?”
![Page 18: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/18.jpg)
HOW ARE YOU PROVING YOUR CODE?
• Working with representative volume?
• Testing various scenarios?• Before/After Testing?• Using Empirical Evidence?• Look and Feel with a Stop
Watch???
![Page 19: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/19.jpg)
Indexes
![Page 20: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/20.jpg)
What Are Indexes?
•Pointers To Data•B-Tree Structures•Sometimes – Hero Makers•Sometimes – Frustrations
![Page 21: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/21.jpg)
Clustered Indexes
•Leaf Level Is The Data•Narrower Is Better•Ever-Increasing•Order By•Not Changing
![Page 22: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/22.jpg)
Non-Clustered Indexes
•Leaf Level Has Index Data and Pointer Only•Joins•Common (and Selective) Search Criteria.
![Page 23: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/23.jpg)
ScanSeek
“Bookmark/RID/KEY Lookups”Covering
What Does It All Mean?
![Page 24: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/24.jpg)
Statistics
![Page 25: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/25.jpg)
SARGable Queries
![Page 26: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/26.jpg)
Search ARGuments
•Query That Can Use An Index
•(All Things Being Equal…)
•Generally: =, <, >, <=, =>,
BETWEEN, IN, LIKE (with exceptions).
•Some Rules but think of the
phonebook…
![Page 27: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/27.jpg)
Fun(?) With Phonebooks
![Page 28: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/28.jpg)
Some Tools
•IO Statistics
•Query Plans
•Profiler
![Page 29: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/29.jpg)
Put It Together
Care
Look
Act
Prove It Out
![Page 30: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/30.jpg)
http://www.flickr.com/photos/hikingartist/3515471358/
![Page 31: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/31.jpg)
Goal 3
“Can’t we all just get
along??!”
![Page 32: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/32.jpg)
Goal 1
You will leave using the concepts we
discuss.
![Page 33: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/33.jpg)
Goal 2
You won’t ever say, “done” until you know your code
PERFORMS
![Page 34: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/34.jpg)
You CAN Tune Your Own SQL Code
![Page 35: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/35.jpg)
RESOURCES
mike@StraightPathSQL.comwww.SQLServerCentral.comwww.SQLServerPedia.comsqlblog.comblogs.msdn.com/craigfr/default.aspxhttp://sqlinthewild.co.za/ http://scarydba.wordpress.com/ http://www.straightpathsql.com/
blogroll/
![Page 36: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/36.jpg)
![Page 37: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/37.jpg)
![Page 38: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/38.jpg)
![Page 39: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/39.jpg)
StraightPathSQL.com/ucandoit
![Page 40: You Can Tune Your Own SQL Code](https://reader035.vdocument.in/reader035/viewer/2022062319/5550988bb4c90590208b4723/html5/thumbnails/40.jpg)
Confused?Angry?Lost?