Sql Server Performance Siddhesh

14
SQL Server SQL Server Performance: Performance: Tips and Techniques Tips and Techniques Siddhesh Bhobe 14 th March 2002

description

Enabling high performance in your SQL Server

Transcript of Sql Server Performance Siddhesh

Page 1: Sql Server Performance Siddhesh

SQL Server Performance: SQL Server Performance: Tips and TechniquesTips and Techniques

Siddhesh Bhobe

14th March 2002

Page 2: Sql Server Performance Siddhesh

TopicsTopics

MotivationTips and Techniques

– Installation and Configuration– Database Schema Design– DDL and DML Statements– Indexing– Miscellaneous

References

Page 3: Sql Server Performance Siddhesh

MotivationMotivation

Simple tricks and tips can lead to a tremendous improvement in performance of your RDBMS engine

You do not have to be an “expert”! Although we will talk about SQL Server, most of

these techniques can be applied to all databases The purpose of this talk is to sensitize you towards

this topic… this is not a tutorial in “How to improve the performance of your database engine”

Page 4: Sql Server Performance Siddhesh

Installation and ConfigurationInstallation and Configuration

Don't install network libraries that are not  required

Don't install services you do not needTurn off the MS DTC if your applications 

do not  need itDo not run Screensavers or Terminal 

Services  on SQL Server machines

Page 5: Sql Server Performance Siddhesh

Installation and Config (2)Installation and Config (2)

Remove anti-virus softwareConsider setting ”min memory per query”Set min and max server memory optionsChoose appropriate sort order Consider changing default network packet

size

Page 6: Sql Server Performance Siddhesh

Database Schema DesignDatabase Schema Design

Do not use the same database for OLAP & OLTP Don't use FLOAT or REAL for Primary Keys Use UNICODE only if you require

internationalization Use CHAR datatype only when column is  non-

nullable. Else use VARCHAR Consider denormalization if you require more than

 4-5 joins in the queries

Page 7: Sql Server Performance Siddhesh

DDL and DML StatementsDDL and DML Statements

Avoid using DISTINCT clause if possible Use EXISTS instead of IN Use derived instead of temporary tables

– A derived table is the result of using a SELECT statement in the FROM clause of an existing SELECT statement.

Do not use Select *. Use column list Use TRUNCATE table instead of DELETE all

Page 8: Sql Server Performance Siddhesh

DDL and DML Statements (2)DDL and DML Statements (2)

Do not use Count(*) if you are ok with approximates

SELECT rows

FROM sysindexes

WHERE id = OBJECT_ID('<table_name>') AND indid < 2

Using SELECT DISTINCT after sampling to speed up operation

Use "SET NOCOUNT ON" in stored procedures

Page 9: Sql Server Performance Siddhesh

DDL and DML Statements (3)DDL and DML Statements (3)

Consider OUTPUT parameters instead of  SELECT statement for single row result sets

Give constraints precedence over triggers Use triggers for maintaining aggregate summary 

data Avoid using CURSORs. Use the new  TABLE 

datatype available in SQL Server  2000 Force small tables into buffer using the 

SP_TABLEOPTION PINTABLE option

Page 10: Sql Server Performance Siddhesh

DDL and DML Statements (4)DDL and DML Statements (4)

Avoiding bottlenecks with temporary tables– SELECTing data into a temp tables can block

the tempdb for the duration of the SELECT, creating a bottleneck. Ensure that the "create temporary table" part of the operation is committed as quickly as possible.

Page 11: Sql Server Performance Siddhesh

IndexingIndexing

Avoid using SQL functions in the Search Criteria– This can prevent indexes from being used

Every table in the database should have atleast a  clustered index defined on it

Add/Delete Indexes in OLTP applications, if  required

Use CHECKSUM instead of indexes on very wide columns

Use most selective columns to the left of the index key

Page 12: Sql Server Performance Siddhesh

Indexing (2)Indexing (2)

Consider creating covering indexes for repeated  queries if you have to use non-clustered indexes

Consider creating covering indexes for frequent  queries with aggregates

Schedule periodic reorganization on all indexes on all tables in the database

Create only UNIQUE clustered indexes Drop indexes and regenerate if you are importing 

data in batches

Page 13: Sql Server Performance Siddhesh

MiscellaneousMiscellaneous

Use OLE DB to access SQL Server over other mechanisms like ODBC

Use DSN-less connections in OLE DB

Page 14: Sql Server Performance Siddhesh

ReferencesReferences

Links– http://www.sql-server-performance.com– http://www.dbazine.com/ch_sql.html– http://www.sqlmag.com

Tools– http://www.quest.com/spotlight_sql