more sql performance tips

April 24, 2010 02:05 by Ryan Garaygay

As most of you know the general rule in performance tuning is .....

"measure, measure, measure" and "measure again"

But it doesn't hurt to give out some warning signs from time to time. And here goes two:

1) be careful in doing anything fancy on JOIN predicates (that is the condition in the "ON" section)

   most of the time anything more complex than comparing one columns from each of the tables being joined will have some performance impact.

   again measure, but in experience I find that even creating a common table expression, or a subquery to come up with the derived column and use it to join is faster than doing it in the JOIN predicate.

   also, the less columns involved in a JOIN the better.

2) always prefer set operations than row-by-row operations

    for the same reason that cursors should be avoided

    what many don't know however is that if you have a UDF (user-defined function) used in a SELECT query result set then that function will be called for every row and thus there will be an overheed. Again measure but for performance sensitive cases it will be significant.

     so if you have to squeeze out any performance gain you can have then get rid of the function if you and although redundant have the logic on the query itself.

     maintainability wise this is not advisable. so you have to feel the trade-off here

     For example:

     SELECT fullname = dbo.GetFullName(FirstName, LastName) FROM Employee (NOLOCK)

     regardless of the complexity of the GetFullName function's implementation would be slower than having it handled in the query directly. say

     SELECT fullname = FirstName + ' ' + LastName FROM Employee (NOLOCK)

Hope to share more soon. But again, don't forget, measure3x


Comments

April 24. 2010 19:15

rome sightseeing

The posts help visualize the issues described on this blog

rome sightseeing

April 25. 2010 01:57

Bennett Gentsy

I am not really sure if best practices have emerged around things like that, but I am sure that your great job is clearly identified. I was wondering if you offer any subscription to your RSS feeds as I would be very interested and can?t find any link to subscribe here.

Bennett Gentsy

April 26. 2010 19:17

Albert

I noticed a problem what I am facing with sql, as I am trying to add and implement more features on my sites, more problems appears, so I come only to one conclusion that the best solution is Keeping It Simple.

Albert

May 1. 2010 16:29

Gabriel Grosclaude

Intresting post, i really enjoyed reading it. Smile

Gabriel Grosclaude

May 3. 2010 12:54

ed hardy discount

Thank you for the information

ed hardy discount

May 4. 2010 19:49

hon ergonomic chairs

I am trying to learn SQL. I am a web developer. So it is necessary to learn this language. I use the tips given here. please give more tips.

hon ergonomic chairs

May 5. 2010 11:19

bellingham homes

Great blog post it could be interesting to see what other commenters write.

bellingham homes

May 6. 2010 15:00

Top Forex Brokers

A forex broker review will provide you with a lot of information about a particular broker or brokerage company, so you'll obviously want to choose one that has positive feedback from other clients.  The review will include information about whether or not the forex broker is registered, has good credentials, is experienced, and so forth. Take note of the positive forex broker reviews so that you'll know who you can trust with your money.  Likewise, avoid the brokers with negative reviews.

Top Forex Brokers

May 8. 2010 21:00

The patio

Really great information in your blog. Please write more so that we can get more updates in your blog. Thanks a lot!

The patio

May 8. 2010 21:43

razzak

We should thank you for giving such a wonderful blog. Your site happens to be not only informative but also very imaginative too. We find a limited number of experts who can think to write technical articles that creatively. All of us are on the lookout for information on something like this. I Myself have gone through several blogs to build up on knowledge about this.We look forward to the next posts !!

<a href="www.adnpost.com">Webmaster Forum</a>

<a href="www.freelinksoftware.com">Software Donload</a>

razzak

May 8. 2010 22:20

Airport Limo

Truly, marvelous article! Thank you for posting. I do have a couple questions for you, so I'll look for your email and email them directly if that's okay.

Airport Limo

May 12. 2010 03:18

shoes

This is a good article, I wanted to know if I could link to this post on my blog. let me know if its cool

shoes

May 14. 2010 22:32

Joomla Web Design

Yes it is true and this post  really help to solve the issue of the blog.

Joomla Web Design

May 17. 2010 22:30

Canadian Government Grants

I am impressed by your knowledge on this topic and i hope to learn a lot from you on this topic.

Canadian Government Grants

May 20. 2010 15:15

big boobs

Perfect post. Thanks!

big boobs

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading