You Can Tune Your Own Code<br />SQL Saturday #33 Charlotte<br />
Who Is Mike?<br />10 years with SQL<br />DBA roles of various sorts<br />Blog: www.straightpathsql.com/<br />Syndicated at...
Who Are You?<br />
“Why is this so slow?!”<br />“It worked fine in dev!” <br />“The results came back fine… I’m done”<br />
What Aren’t We Covering?<br />
“Can’t you  <br />   just make it<br />faster?!”<br />http://www.flickr.com/photos/irinaslutsky/4000761728/<br />
www.flickr.com/photos/no3rdw/170950846/<br />
http://www.flickr.com/photos/dullhunk/359634390/<br />www.flickr.com/photos/no3rdw/170950846/<br />
Agenda<br /><ul><li>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*</li></ul>*Maybe we do…, but let’s work it out<br />
Goal 1<br />You will leave using the concepts we discuss.<br />
Goal 2<br />You won’t ever say, “done” until you know your code<br />PERFORMS<br />
Goal 3<br />“Can’t we all just get along??!”<br />
Tips For Making Queries Slow<br />
Right Mindset<br />
Right Mindset<br /><ul><li>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</li></li></ul><li>“Should I split this up?”<br />“Should I use -that- view?” <br />“How Man...
How Are You Proving Your Code?<br /><ul><li>Working with representative volume?
Testing various scenarios?
Before/After Testing?
Using Empirical Evidence?
Look and Feel with a Stop Watch???</li></li></ul><li>Indexes<br />
What Are Indexes?<br /><ul><li>Pointers To Data
B-Tree Structures
Sometimes – Hero Makers
Sometimes – Frustrations</li></li></ul><li>Clustered Indexes<br /><ul><li>Leaf Level Is The Data
Narrower Is Better
Ever-Increasing
Order By
Upcoming SlideShare
Loading in...5
×

You Can Tune Your Own SQL Code

1,275

Published on

Slide deck from a talk first delivered at SQL Saturday 34 in Waltham, MA. Mike Walsh talks about how you can tune your own SQL Server code. Walk through indexes, Query Plans, IO Statistics and Profiler. The goal was to show developers how painless it is to gauge performance and make changes as a result.

Updated to v1.5 as presented in Charlotte to SQLSat33

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,275
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
30
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

You Can Tune Your Own SQL Code

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

    Clipping is a handy way to collect important slides you want to go back to later.

×