Optimizing Procedural Code



Similar documents
SQL Server 200x Optimizing Stored Procedure Performance

SQL Server 2012 Extended Events. Bob Beauchemin SQLskills.com

Understanding SQL Server Execution Plans. Klaus Aschenbrenner Independent SQL Server Consultant SQLpassion.at

Karuana Gatimu, ECMp Business Solution SharePoint Overview. What, Why, When and Where The Basics

Indexing for Performance Index Defragmentation Best Practices

Offline Database Development and Unit Testing with SSDT. Andrey Zavadskiy

SQL Server 2016 Query Store

The Database is Slow

SharePoint for Digital Asset Management

SharePoint What's New, What's Not. Colin Phillips :: SharePoint MVP & Consultant :: itgroove

Scaling out a SharePoint Farm and Configuring Network Load Balancing on the Web Servers. Steve Smith Combined Knowledge MVP SharePoint Server

Dynamics NAV/SQL Server Configuration Recommendations

What s new for SharePoint 2016?

Capacity Planning for Microsoft SharePoint Technologies

WINDOWS AZURE SQL REPORTING

SQL Server 2012 Optimization, Performance Tuning and Troubleshooting

MONyog White Paper. Webyog

AV-005: Administering and Implementing a Data Warehouse with SQL Server 2014

How to move a SharePoint Server bit environment to a 64-bit environment on Windows Server 2008.

How To Create A Help Desk For A System Center System Manager

System Requirements for Microsoft Dynamics NAV 2009 SP1

SSRS Reporting Using Report Builder 3.0. By Laura Rogers Senior SharePoint Consultant Rackspace Hosting

Optimising SQL Server CPU performance

Intelligent Dashboards made Simple! Using Excel Services

Server Consolidation with SQL Server 2008

UBGP008: Maximizing SQL Server Performance with Microsoft Dynamics GP. John Lowther

System Requirements for Microsoft Dynamics SL 2015

SharePoint 2010 Performance and Capacity Planning Best Practices

Who is SharePoint Joel?

How To Improve Performance In A Database

SQL Server Performance Tuning and Optimization

$99.95 per user. SQL Server 2008/R2 Database Administration CourseId: 157 Skill level: Run Time: 47+ hours (272 videos)

Microsoft Azure Cloud for Solution Architects

SharePoint for Digital Asset Management

Building a Scale-Out SQL Server 2008 Reporting Services Farm

ONSITE TRAINING CATALOG

System Requirements for Microsoft Dynamics NAV 2009

SharePoint 2010 Monitoring and Troubleshooting. Andrew Lynes, Premier Field Engineer 30 August, 2011

READPAST & Furious: Transactions, Locking and Isolation

SharePoint 2010 Monitoring and Troubleshooting. Andrew Lynes, Premier Field Engineer

USERS, PROFILES, & MYSITES

Team Foundation Server 2013 Installation Guide

Introduction to: SQL Server Reporting Services. Architecture, Installation, and Administration

Microsoft SQL Server: MS Performance Tuning and Optimization Digital

Performance Tuning and Optimizing SQL Databases 2016

Power BI Performance. Tips and Techniques

Microsoft SQL Server performance tuning for Microsoft Dynamics NAV

MOC 20461C: Querying Microsoft SQL Server. Course Overview

Course ID#: W 35 Hrs. Course Content

Response Time Analysis

SQL Server 2012 Query. Performance Tuning. Grant Fritchey. Apress*

Online Transaction Processing in SQL Server 2008

Data Compression in Blackbaud CRM Databases

PRODUCT OVERVIEW SUITE DEALS. Combine our award-winning products for complete performance monitoring and optimization, and cost effective solutions.

System Requirements for Microsoft Dynamics SL 2015

Guerrilla Warfare? Guerrilla Tactics - Performance Testing MS SQL Server Applications

SQL Server Replication

Multi-Tenancy in SharePoint DD105 Spencer Harbar Enterprise Architect harbar.net

Protect SQL Server 2012 AlwaysOn Availability Group with Hitachi Application Protector

How to Scale out SharePoint Server 2007 from a single server farm to a 3 server farm with Microsoft Network Load Balancing on the Web servers.

MS SQL Server 2014 New Features and Database Administration

The 5-minute SQL Server Health Check

Scalable Internet Services and Load Balancing

Microsoft Dynamics NAV 2013 R2 Sizing Guidelines for On-Premises Single Tenant Deployments

BIGDATA GREENPLUM DBA INTRODUCTION COURSE OBJECTIVES COURSE SUMMARY HIGHLIGHTS OF GREENPLUM DBA AT IQ TECH

Microsoft Office Outlook 2013: Part 1

Querying Microsoft SQL Server

SQL Server Query Tuning

DATA AND LOG FILES FOR CENTRAL MANAGEMENT STORE

Query Performance Tuning: Start to Finish. Grant Fritchey

The first time through running an Ad Hoc query or Stored Procedure, SQL Server will go through each of the following steps.

Red Gate Books SQL Server DMV Starter Pack

Cloud Database Demystified to Deliver SaaS Customer Value

W I S E. SQL Server 2008/2008 R2 Advanced DBA Performance & WISE LTD.

Course Outline. SQL Server 2014 Performance Tuning and Optimization Course 55144: 5 days Instructor Led


In addition to their professional experience, students who attend this training should have technical knowledge in the following areas.

MOC 20467B: Designing Business Intelligence Solutions with Microsoft SQL Server 2012

Donabel Santos. DBA/Developer/Trainer, QueryWorks Instructor, British Columbia Institute of Technology (BCIT) tweets

There are four technologies or components in the database system that affect database performance:

Introduction to SQLIO & SQLIOSim & FIO. XLVIII Encontro da Comunidade SQLPort

SQL Server Query Tuning

System Requirements Table of contents

An Oracle White Paper May Guide for Developing High-Performance Database Applications

Understanding and Controlling Transaction Logs

The Ultimate Remote Database Administration Tool for Oracle, SQL Server and DB2 UDB

Developing Solutions for Microsoft Dynamics AX in a Shared AOS Development Environment

Response Time Analysis

SQL Server for Database Administrators Course Syllabus

Microsoft Office Outlook 2010: Level 1

Module 9: Implementing Stored Procedures

SQLintersection SQL123

Upgrading Your SQL Server 2000 Database Administration (DBA) Skills to SQL Server 2008 DBA Skills Course 6317A: Three days; Instructor-Led

Transcription:

.Net Rocks! Visual Studio 2012 Launch Road Trip Optimizing Procedural Code Kimberly L. Tripp Kimberly@SQLskills.com

Kimberly L. Tripp Consultant/Trainer/Speaker/Writer President/Founder, SYSolutions, Inc. e mail: Kimberly@SQLskills.com blog: /blogs/kimberly Twitter: @KimberlyLTripp Author/Instructor for SQL Server Immersion Events Instructor for multiple rotations of both the SQL MCM & Sharepoint MCM Author/Manager of SQL Server 2005 Launch Content, co author/manager for SQL Server 2008 Jumpstart Content, Author/Speaker at TechEd, SQL Connections, SQLPASS, ITForum, Conference Co chair for SQL Connections Author of several SQL Server Whitepapers on MSDN/TechNet: Partitioning, Snapshot Isolation, Manageability, SQLCLR for DBAs Author/Presenter for more than 25 online webcasts on MSDN and TechNet (two series and other individual webcasts) Co author MSPress Title: SQL Server 2008 Internals, the SQL Server MVP Project (1 & 2), and SQL Server 2000 High Availability Presenter/Technical Manager for SQL Server HOL DVDs I love this stuff feel free to ask questions! 2

SQLskills Team of world renowned SQL Server experts Paul S. Randal @PaulRandal Jonathan Kehayias @SQLPoolBoy Joseph Sack @JosephSack Glenn Berry @GlennAlanBerry Erin Stellato @ErinStellato Instructor led training Immersion Events Online training Pluralsight (http://pluralsight.com/) Consulting: health checks, hardware, performance Remote DBA Become a SQLskills Insider http://www.sqlskills.com/joincommunity.asp

Overview Back to the basics Never say never, never say always It depends! Problem area to highlight Parameter sniffing What is it? When/why does it become problematic? Recompilation in procedures What to recompile? How to effectively use statement level recompilation 4

Processing Stored Procedures Creation Execution (when a plan does not already exist in cache) Parsing Resolution Resolution* Optimization Compilation sniffing runtime params 5 A procedure's plan is NOT saved to disk; only metadata is saved at procedure creation Use sys.procedures, sp_ procs, functions and views to see metadata Compiled plan placed in unified plan cache Re used on subsequent executions parameter sniffing PROBLEMS

Procedure Caching Isn t That the Point? Reusing plans can be good When different parameters don t change the optimal plan, then saving and reusing is excellent! SQL Server saves time in compilation Reusing plans can be VERY bad When different parameters wildly change the size of the result set and the optimal plans vary, then reusing the plan can be horribly bad If indexes are added to base tables, existing plans may not leverage them Don t worry, there s a simple solution here: EXEC sp_recompile <tablename> 6

Recompilation Issues RECOMPILATION = OPTIMIZATION OPTIMIZATION = RECOMPILATION When do you want to recompile? What options do you have for recompilation and at what granularity? How do you know you need to recompile? Do you want to recompile the entire procedure or only part of it? Can you test it? 7

Options for Recompilation CREATE WITH RECOMPILE EXECUTE WITH RECOMPILE sp_recompile objname Statement level recompilation The 2000+ ways (still have benefits) Dynamic string execution (statement s plan not stored with procedure s plan) Modularized code (reduced sniffing problems with conditional logic/branching) Better way to change compilation/optimization 2005+: OPTION(RECOMPILE) 2005+: OPTION (OPTIMIZE FOR (@variable_name = constant,...) ) 2008+: OPTION (OPTIMIZE FOR UNKNOWN) 8

Statement Level Recompilation In 2005 and 2008: inline recompilation for statements OPTION (RECOMPILE) Excellent when parameters cause the execution plan to widely vary Bad because EVERY execution will recompile but only for the statements OPTION (OPTIMIZE FOR (@variable = literal,...)) Excellent when large majority of executions generate the same optimization time You don t care that the minority may run slower with a less than optimal plan? 2008 only: OPTION (OPTIMIZE FOR UNKNOWN) Use the all density (average) instead of the histogram 9

Demo Recompilation

Stored Procedure Resources Plan Caching in SQL Server 2008 http://msdn.microsoft.com/en us/library/ee343986.aspx Batch Compilation, Recompilation, and Plan Caching Issues in SQL Server 2005 http://www.microsoft.com/technet/prodtechnol/sql/2005/rec omp.mspx PSS SQL Server Engine Blog http://blogs.msdn.com/psssql/default.aspx KB 243586: Troubleshooting Stored Procedure Recompilation KB 308737: How to identify the cause of recompilation in an SP:Recompile event (SQL Server 2000 SP2+ has 6 subclass values, SQL Server 2005 has 11 subclass values and SQL Server 2008 RTM has 14 subclass values) KB 263889: Description of SQL Server blocking caused by compile locks 11

Plan Cache Pollution Resources Blog posts: Plan cache and optimizing for adhoc workloads Plan cache, adhoc workloads and clearing the singleuse plan cache bloat Clearing the cache are there other options? Statement execution and why you should use stored procedures Category: Optimizing Procedural Code http://www.sqlskills.com/blogs/kimberly/category/opti mizing Procedural Code.aspx MSDN Article: How Data Access Code Affects Database Performance, Bob Beauchemin http://msdn.microsoft.com/enus/magazine/ee236412.aspx 12