"No one is harder on a talented person than the person themselves" - Linda Wilkinson ; "Trust your guts and don't follow the herd" ; "Validate direction not destination" ;

July 02, 2009

Basics SQL Performance Tuning - Queries and Tips

Basics of Performance Tuning

1. Check for Cost of Joins, Seek, Scans (Join Types listed in previous blog entries)
2. Seek is always better than scan, Look for possibilities where covering index can convert scans into seeks
3. When there is Key lookup for large number of data sets create a index, This is avoid lookup costs

DBCC FREEPROCCACHE --clears entire plan cache
DBCC DROPCLEANBUFFERS --clears all clean data cache pages
SET STATISTICS IO ON –- To see physical/logical read counts

--Tip #1
--• Checking the reads and writes generated by the query using


SET STATISTICS IO ON
--• Checking the running time of the query using
SET STATISTICS TIME ON
select * from employees
sp_spaceused employees
--Tip #2
--Query Execution Time
DECLARE @start_time DATETIME
SELECT @start_time = GETDATE()
--<>
SELECT 'Elapsed Time, sec' = DATEDIFF( second, @start_time, GETDATE() )
GO

--Tip #3

SET SHOWPLAN_TEXT ON


SET SHOWPLAN_ALL ON
select * from employees

--Tip #4
/*
Seeks go directly, or at least very quickly, to the needed records while scans read the whole object (either table, clustered index, or non-clustered index). Thus, scans usually consume lots more resources than seeks.
*/

--Tip #5

SET NOCOUNT ON



/*
Reduces the amount of information passed from the server to the client. Therefore, it helps to lower network traffic and improves the overall response time of your transactions
*/


More Reads
Notes - Updated

Happy Reading!!

No comments: