Presentation is loading. Please wait.

Presentation is loading. Please wait.

Kevin Kline Director of Engineering Services, SQL Sentry SQL Server MVP since 2003 Twitter, FB, LI: KEKline Blog:

Similar presentations


Presentation on theme: "Kevin Kline Director of Engineering Services, SQL Sentry SQL Server MVP since 2003 Twitter, FB, LI: KEKline Blog:"— Presentation transcript:

1 Kevin Kline Director of Engineering Services, SQL Sentry SQL Server MVP since 2003 Twitter, FB, LI: KEKline Blog: http://KevinEKline.com, http://ForITPros.comhttp://KevinEKline.comhttp://ForITPros.com

2 Tuning blog: http://www.sqlperformance.com/http://www.sqlperformance.com/ E-mail ebooks@sqlsentry.com for free copies of our e-books:ebooks@sqlsentry.com

3 ToolsTechniques Process, Patterns & Practices Happy & Helpful DBA!

4  DBAs:  Stodgy  Conservative  Slow  Control Freak  Dev’s say “Drats, thwarted again!”  The truth?  Our job is to act as the guardian of the true corporate IT assets.  Developers:  Cowboys  Reckless  Hasty  Chaotic  DBAs say “Blimey, my database is besmirched!”  The truth?  Our job is build products that are high quality, fast, and cheap (pick two).

5 Dev workstations are usually nothing like production: o Build representative data when you can. (Remember auto-update stats). o Build a stats-only database (a.k.a. db clone) for smaller dev environments o Ensure important settings are the same. o Simulate equivalent hardware: DBCC OPTIMIZER_WHATIF.

6 Warm caching or Cold caching? Measure: o Total elapsed time o Individual statement time o IO load Facilitates automation of execution plans Get to know the DMV sys.dm_exec_query_stats

7 The steps used by SQL Server to process a query are displayed in an execution plan. o Learn how to compare in SSMS. Better yet, use the free Plan Explorer product. o Learn how to watch in real-time with SQL Profiler or Extended Events. Comparative query performance might mislead: o Should evaluate on comparable data sizes. o Different CPU, disk, caching, etc. o Evaluate the query cost.

8 Red Flags Query Operators: Lookups, Scans, Spools, Parallelism Operations Other Red Flags: Dissimilar estimated versus actual row counts High physical reads Missing statistics alarms Large sort operations Implicit data type conversions

9 getord Plan Cache Memory finduser sp_1sp_4 16 16 7 2 2 3 3 0 2 7 1 5 6 4 0 1 14 15 13 12 What about buffer cache?

10 Expected: Because we request it: CREATE PROC … WITH RECOMPILE or EXEC myproc … WITH RECOMPILE SP_RECOMPILE foo Expected: Plan was aged out of memory Unexpected: Interleaved DDL and DML Unexpected: Big changes since last execution: Schema changes to objects in underlying code New/updated index statistics Sp_configure Execution Load metadata NO In Memory? compile optimize Execute YES ReComp Execute

11 CREATE PROC testddldml AS … ; CREATE TABLE #testdml;-- (DDL) INSERT INTO #testdml;-- (DML + RECOMPILE) ALTER TABLE #testdml;-- (DDL) INSERT INTO #testdml;-- (DML + RECOMPILE) DROP TABLE #testdml;-- (DDL)

12 Cursors are usually unnecessary, but when they are, use the right options. The defaults are heavy-handed and guaranteed to be slow. Blog post: http://bit.ly/AB-cursors http://bit.ly/AB-cursors

13 Leaf pages are the DATA. Non-leaf pages are POINTERS, but are also data. 8K pages. Not always self-healing. Make sure they’re on your important search arguments, a.k.a. “sargs”. Leaf Pages Root Page Level 0 Intermediate Pages Level 1 Level 2

14 Big differences between a SELECT and a DML statement that effects the same rows. Shouldn’t blindly create every index the Tuning Advisor or execution plan tells you to! Blog post - http://bit.ly/AB-BlindIndexhttp://bit.ly/AB-BlindIndex

15 SQL Server has to do a lot of extra work / scans when conversion operations are assumed by the SQL programmer. Happens all the time with data types you’d think wouldn’t need it, e.g. between date types and character types. Very useful data type conversion chart at http://bit.ly/15bDRRA.http://bit.ly/15bDRRA Data type precedence call also have an impact: http://bit.ly/13Zio1f.http://bit.ly/13Zio1f

16 Which are better, temp tables or temp variables? Temp TableTemp Variable Stored in?Tempdb Statistics?YesNo (1 row) Indexs/Keys?Yes1 UK / PK only Truncate?YesNo Recompiles?YesNo Parallelism?YesNo Metadata Overhead? LowLowest Lock Overhead?NormalLowest

17 Coding standards. Parameterization. Remember the power of specialized code. More details: http://bit.ly/ZpAxDD.http://bit.ly/ZpAxDD

18 Mimic production as best you can Test harness & testing Read execution plans Get to know the plan cache Avoid unwanted recompiles Use cursors appropriately Create useful and balanced indexes Write code that doesn’t break indexes Temp variables <> pure goodness Prevent cache bloat

19 PLEASE FILL OUT THE SESSION EVAL! Send questions to me at: kkline@sqlsentry.comkkline@sqlsentry.com Twitter, Facebook, LinkedIn at KEKline Slides at http://KevinEKline.com/Slides/ and now at Slideshare.Nethttp://KevinEKline.com/Slides/ IT leadership and soft skills content at http://ForITPros.comhttp://ForITPros.com THANK YOU!


Download ppt "Kevin Kline Director of Engineering Services, SQL Sentry SQL Server MVP since 2003 Twitter, FB, LI: KEKline Blog:"

Similar presentations


Ads by Google