SqlShare.com Logo
 
Skip Navigation Links
Home
Video List
Events
Classes
About Us
Login / Register
Subscribe RSS Feed 

Idera SQL Check

Performance Tuning Quiz #2 - Part 2

In Part 2 we see how adding a single compound index dramatically reduces the number of reads, eliminating a table scan in the process. We also modify the query to use NOT EXISTS, but find for the single example the savings isn't huge.

Duration:
4 mins 27 secs
Skill Level:
100
Rating:
4.55 out of 5
Publish Date:
May 17, 2010
Performance Tuning Quiz #2 - Part 2 You must be logged in to view this video.  
Bookmark and Share
 
1=Poor, 3=Good, 5=Excellent

About the Author

Image of Andy Warren
Andy Warren is a software trainer focusing on SQL Server, a member of the PASS Board of Directors, and a principal in this site - SQLShare.com.

References

There are no downloads or recommended reading links for this video

Comments
Shashank Banerjea on 5/19/2010
Deja Vu! I have gone through this exercise as a consultant, where finding missing indexes and applied really helped. The flip side of adding indexes is on the write side when the indexes are updated based on the new row. My question is - how is that cost of updating the index actually reflected in the profiler, if at all? The idea would be easily figure out point of diminishing returns on adding indexes.

Slavius on 5/20/2010
Ok, how I solved this: I've created a non-clustered index on firstname/lastname + using page level compression. This gave me sum of 5 reads in case of insert and 2 in case of duplicate found with the original SP. Then I rewrote the SP. As far as the original SP does not care about the result I've decided to rely on exception. I tried to create UNIQUE nonclustered index on FirstName_LastName but there were some duplicates in the table from AdwentureWorks so I replaced the original index with UNIQUE NONCLUSTERED INDEX on FirstName, LastName, EmailAddress. Then I rewrote the SP like this: ALTER proc [dbo].[AddContact] @FirstName varchar(50), @LastName varchar(50) as BEGIN TRY insert into dbo.Contacts ( FirstName, LastName) values ( @Firstname, @LastName) END TRY BEGIN CATCH END CATCH This gives me 3 reads per SP in case of insert and 4 in case of duplicate present.

Ed Svastits on 5/20/2010
You opened up a can of worms by re-introducing us to EXISTS. Does SQL Server use the other operators like ANY and IN any more efficiently than their more manual counterparts? Perhaps some fodder for Part 3?

Robert Djabarov on 5/20/2010
too primitive in respect to significance of Reads and impact of the presence of an index on INSERT.

Jamshid Nouri on 5/20/2010
excellent demo!!!

Douglas Kemp on 5/20/2010
I like seeing your overall optimization process.

Pradeep on 5/20/2010
It was very interesting. Please consider to continue with more videos on performance tuning. Thanks!

Matt on 5/20/2010
I have really enjoyed the performance videos, hope you can do more. Thanks again.

Dennis Allen on 5/20/2010
-- Tuning is a great subject, I would like to see more -- of these. -- -- another optional syntax, which ever is clearer to the -- folks who will be maintaining the procedure would -- take precedents... insert into dbo.Contacts ( FirstName, LastName ) select @FirstName, @LastName where not exists ( select 1 from dbo.Contacts where FirstName = @FirstName and LastName = @LastName )

Mike Byrd on 5/20/2010
Let's see part 3 (and 4 and 5 and...)

Rubens on 5/20/2010
Found these to be very informative, would love to see a part 3 as performance tuning is always an area I am looking to improve. Thanks.

Shane on 5/20/2010
Great instruction! Please include a part three. Performance tuning is an art, and I need all the help I can get. Thanks!

Leonard Peoples on 5/20/2010
Great tip. I'm going to use this.

Kevin on 5/20/2010
Thanks for the information. I really enjoyed the pointers on what to look for when performance tuning.

Munna Bhai on 5/20/2010
Pros know the best. Excellent video Andy. Thanks once again for sharing and keep up the good work.

Slavius' approach with the try/catch and unique index on firt and last would solve the problem if the data supported it. As described though with the email added to establish uniqueness, you can add duplicate first and last name, provided you give different emails, which is not what was requested. But I think the example is a little wierd, in that existing data already fails the logic trying to be implemented.

srinivas on 5/24/2010
It's very informative. Look forward for part3

Cecil Small on 5/28/2010
I think it was great. Would appreciate a part 3. Thanks andy

mark brito on 5/29/2010
What about statistics? How can those influence query optimization?:

vinodkumar myakala on 6/15/2010
Excellent

vikram on 7/31/2010
can you show what are the settings of the profiler that are being used in this case.



Must Be Logged In
 

How Do I Become a Video Author? |  Newsletter History

Copyright © Fourdeuce, Inc., 2005-2009. All Rights Reserved | Privacy Policy | Terms & Conditions