Download presentation
Presentation is loading. Please wait.
Published byAbraham Hamilton Modified over 9 years ago
1
Connect with life www.connectwithlife.co.in Nauzad Kapadia Quartz Systems www.quartzsystems.com nauzadk@quartzsystems.com
2
Session Objectives And Key Takeaways Session Objectives: Dive into the query performance and tuning capabilities in SQL Server Demonstrate common tuning and troubleshooting techniques using SQL Server Disclaimer: Query Tuning is a deep & broad topic – won’t cover everything Key Takeaways: SQL Server 2005+ has wealth of capabilities Get a refresher on certain fundamental concepts Common pitfalls to avoid and optimization techniques
3
Factors Affecting Performance? Application Design 3 tier architecture facilitates caching, connection pooling. Partitioning tables and databases Not mixing logs and database on the same disk Database Design Normalization of database structure, choosing indexes. Microsoft SQL Server Setup. Affinity mask, lightweight pooling, max worker threads and degree of parallelism. Hardware
4
Indexes Scan and Seek * Clustered and non-clustered indexes Seekable Predicates * Single column Indexes Multi Column Indexes Covered Columns A Clustered index covers all columns A non-clustered index covers only key columns A non-clustered index on a table with a clustered index covers the clustered index key
5
Example : Covered Columns CREATE TABLE T_heap (a int, b int, c int, d int, e int, f int) CREATE INDEX T_heap_a ON T_heap (a) CREATE INDEX T_heap_bc ON T_heap (b, c) CREATE INDEX T_heap_d ON T_heap (d) INCLUDE (e) CREATE UNIQUE INDEX T_heap_f ON T_heap (f) CREATE TABLE T_clu (a int, b int, c int, d int, e int, f int) CREATE UNIQUE CLUSTERED INDEX T_clu_a ON T_clu (a) CREATE INDEX T_clu_b ON T_clu (b) CREATE INDEX T_clu_ac ON T_clu (a, c) CREATE INDEX T_clu_d ON T_clu (d) INCLUDE (e) CREATE UNIQUE INDEX T_clu_f ON T_clu (f)
6
Indexing Bookmark Lookups * Bookmark lookups are expensive Index Cost * Only one clustered index allowed per table A Clustered index is always unique even if it is not explicitly specified so. Create a PRIMARY KEY by adding a NONCLUSTERED keyword. Make non-clustered indexes highly selectable.
7
Indexing – cont’d Index small fields. Avoid creating indexes on large string columns ALTER TABLE titles ADD hash_title AS CHECKSUM(title) CREATE INDEX hash_index ON titles(hash_title) SELECT * FROM titles WHERE title = 'Cooking with Computers: Surreptitious Balance Sheets' AND hash_title = CHECKSUM('Cooking with Computers: Surreptitious Balance Sheets')
8
Indexing – cont’d Pay attention to column order Drop or create indexes as needed
9
Plan Caching Adhoc plan caching * Autoparameterization * Forced Parameterization ALTER DATABASE SET PARAMETERIZATION FORCED; Use Prepared statements *
10
Stored Procedures Execution Plan Usage Keep them small Recompiles Causes Avoiding Analysis
11
Stored Procedure Recompile recommendations Avoid interleaving DDL and DML operations Fully qualify all references to SP Use KEEP PLAN/KEEP FIXEDPLAN option To avoid recompile, execute statements by using either of these Sub-procedures EXECUTE/sp_executesql Use table variable instead of temp table (New in Microsoft SQL Server 2000)
12
Transactions Keep them short Avoid external work inside the transaction such as email Take care to avoid deadlocks Use a appropriate isolation level.
13
Best Practices LEARN T-SQL Avoid Cursors as far as possible Do you have missing indexes – Take the help of DTA Avoid joining tables on different data types For frequent computations create a calculated column It helps in column statistics which SQL Server can use in optimizing the query. Don’t use unqualified object names
14
© 2006 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.