|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Friday, April 26, 2013 2:31 AM
Points: 228,
Visits: 495
|
|
Comments posted to this topic are about the item Tips to optimize your SQL statements
Regards Brian Ellul ---------------------------------------------------------------------------------- Computers are incredibly fast, accurate, and stupid. Human beings are incredibly slow, inaccurate, and brilliant. Together they are powerful beyond imagination. - Albert Einstein -
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 11:05 AM
Points: 1,222,
Visits: 140
|
|
Thanks for the list, it's a great starting place!
Think great, be great!
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Yesterday @ 1:10 PM
Points: 2,673,
Visits: 2,418
|
|
| Great article. Lots of good things to be on the look out for. I am going to have to come back to this article a bunch of times. I wrote a query yesterday that could probably use a spin through the last half of this article. Thanks.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Monday, April 15, 2013 12:46 PM
Points: 2,
Visits: 57
|
|
| What perfect timing, the sp_updatestats stored procedure took a query that was taking 3 minutes to run down to 1 second.
|
|
|
|
|
Say Hey Kid
      
Group: General Forum Members
Last Login: Monday, May 20, 2013 12:28 PM
Points: 675,
Visits: 2,031
|
|
I didn't see a very important one: Pull up SQL Server Profiler, and watch the SQL:BatchCompleted and/or RPC:Completed numbers for CPU, Reads, Writes, and Duration. Know which is most important in your environment.
Then re-write the statement a few different ways against the full dataset (always more than once), and see, in your actual environment, how each works. Derived tables vs temp tables vs table variables vs CTE vs straight joins, one large statement vs smaller statements, etc. etc.
Know how much resources a given query "should" take; check if hints help, or hurt, and by how much, and decide if they're worth it or not. This is a reasonable way to find missing indexes or SQL Server generating bizzarely suboptimal query plans, by going "Hey! That's too much... why is that too much?"
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Thursday, January 24, 2013 12:02 PM
Points: 42,
Visits: 152
|
|
Make sure your where clause is SARG-able or indexes won't help: http://weblogs.sqlteam.com/dang/archive/2009/03/07/Low-Hanging-Fruit-of-Sargable-Expressions.aspx
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Wednesday, April 10, 2013 12:23 AM
Points: 20,
Visits: 153
|
|
Thanks for the great check list, but i also want to take some of your other advice that this doesn't substitute reading books and white papers on SQL Performance. Can you please recommend several of the books you've read that you believe would be most beneficial to read for another DBA?
e-mail is cameron.g.wells@gmail.com
Thanks,
Cameron
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Today @ 3:27 PM
Points: 2,692,
Visits: 1,075
|
|
Nadrek (7/29/2010) I didn't see a very important one: Pull up SQL Server Profiler, and watch the SQL:BatchCompleted and/or RPC:Completed numbers for CPU, Reads, Writes, and Duration. Know which is most important in your environment.
Then re-write the statement a few different ways against the full dataset (always more than once), and see, in your actual environment, how each works. Derived tables vs temp tables vs table variables vs CTE vs straight joins, one large statement vs smaller statements, etc. etc.
Know how much resources a given query "should" take; check if hints help, or hurt, and by how much, and decide if they're worth it or not. This is a reasonable way to find missing indexes or SQL Server generating bizzarely suboptimal query plans, by going "Hey! That's too much... why is that too much?"
Would have thought that this is part of an investigation/monitoring phase. Once you've identified a query that needs attention, you run though the great list provided by Brian.
It's amazing how often you don't need to worry about re-writing SQL when all that's needed is a new index, or updated statistics. If either of these two meet your needs, why go through the hassle of re-writing the query/procedure?
Hope this helps Phill Carter -------------------- Colt 45 - the original point and click interface 
Australian SQL Server User Groups - My profile Phills Philosophies Murrumbeena Cricket Club
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Friday, April 26, 2013 2:31 AM
Points: 228,
Visits: 495
|
|
Thanks to all for your feedback!
Regards Brian Ellul ---------------------------------------------------------------------------------- Computers are incredibly fast, accurate, and stupid. Human beings are incredibly slow, inaccurate, and brilliant. Together they are powerful beyond imagination. - Albert Einstein -
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Friday, April 26, 2013 2:31 AM
Points: 228,
Visits: 495
|
|
cameron.wells (7/29/2010) Thanks for the great check list, but i also want to take some of your other advice that this doesn't substitute reading books and white papers on SQL Performance. Can you please recommend several of the books you've read that you believe would be most beneficial to read for another DBA?
e-mail is cameron.g.wells@gmail.com
Thanks,
Cameron
Dissecting SQL Server Execution Plans (by Grant Fritchey) SQL Server 2008 Query Performance Tuning Distilled (by Grant Fritchey & Sajal Dam)
Regards Brian Ellul ---------------------------------------------------------------------------------- Computers are incredibly fast, accurate, and stupid. Human beings are incredibly slow, inaccurate, and brilliant. Together they are powerful beyond imagination. - Albert Einstein -
|
|
|
|