SQL Server 2005 Query Statistics - sql-server

Where can I find some in-depth information on tuning statistics in SQL Server 2005?
I need to really delve in to what statistics are being used in a number of different queries, how they are interacting with indexes, how/when/where to use custom statistics (over and above what the database tuning advisor recommends), when/how to update the statistics for the best performance etc. etc.
Does anyone know of any good articles/webcasts/books around this subject?
Thanks in advance,
Tom

This book gives fairly detailed information on performance tuning Inside Microsoft® SQL Server(TM) 2005: Query Tuning and Optimization

I suggest you review the following comprehensive Microsoft TechNet reference.
Statistics Used by the Query Optimizer

I suggest you visit http://sqlserverpedia.com/ and look for blog/article/demo/screencast/podcast specific to your needs. SQLServerPedia is a free Premier Online SQL Server resource.
Or are you specifically asking these questions right now:
"Why is this query running slow? Is my
index getting used? Why does this
query run faster than this query?"
The book "Dissecting SQL Server Execution Plans" will help you on this regard. A free ebook version is available here.
;-)
MarlonRibunal

Related

optimize a read-only sql server database: new tricks with 2012?

For a new customer we created a read-only database with all his old data. This database will be about 80Gigs but very simply structured.
On my research I found this: tips for optimizing a read-only sql database
What I found there is exactly the answer I expected with my SQL Server 2008 experience... I just want to ask, if there are new approaches, hints, tricks with SQL 2012.
Thx!
You might want to read more about
Columnstore Indexes
Maybe the following article can help:
https://technet.microsoft.com/en-us/library/gg492088%28v=sql.110%29.aspx
Although they are claimed to speed up things up to 10x (by Microsoft) they come with some limitations such as:
[...] A table with a columnstore index cannot be updated [...] (although this is not entirely true as you can circumvent this problem with partitions).
https://technet.microsoft.com/en-us/library/gg492088%28v=sql.110%29.aspx#Restrictions
Just to mark this topic as finished I want to post the final solution:
"Normal" settings, DB on a SSD-Drive in the local hardware.
Works fast and reliable..

Alternative to SQL Server Tuning Advisor?

Are there any other tools out there that can analyze a SQL Profiler trace file and recommend indexes?
I highly recommend the free Qure Analyzer from DB Sophic:
http://www.dbsophic.com/qure-analyzer.html
Disclaimer: I work for SQL Sentry, who partners with DB Sophic on a paid version of their tools which work with our Performance Advisor product. This is not an attempt to up-sell, I am merely pointing you to a free tool that seems to meet your requirements.
You may also want to look at ClearTrace - it's not a one-for-one replacement for DTA, but it is quite useful if you're already collecting traces:
http://www.sqlmag.com/article/performance/cleartrace
If you are running SQL 2005 or higher you can use the Index Related DMVs. You can probably search Google for a handful of scripts using them.

Entity Framework and SQL Server Tuning Advisor

How do I use SQL Server Tuning Advisor to produce recommendations based on Entity Framework queries? Entity Framework uses sp_executesql 'query' instead of executing the query and Tuning Advisor does not recognize these queries. I could get the query text manually, but this will only work for very simple scenarious. How do I do it in an automatic way?
UPDATE
Would it help if I save the profiling information into a table and then run some application which will strip "sp_executesql" and only keep the query text and use this new data to run Tuning Advisor?
I know this topic is a little cold. But since I was having the same issue and found a better solution:
Changing events captured is one way to do it, but there is already a "template", which records everything needed by the SQL server tuning advisor.
If you select the template "tuning", it will effectively remove and add event capture quoted by Doug, but another too.
You can find more about template here
To activate this template, in the "New Trace" windows, select the corresponding template( I didn't create it, it was already there):
Once you did it, you can check the event selection, you have already what is needed:
I additionaly disabled the RPCCompleted, since I've no stored procedure
I hope it will help some people ;)
It looks like the problem is this. If you create a trace using SQL Profiler from the "Tuning" template it does not include the correct events. The Database Engine Tuning Advisor does not understand sp_executsql statements from the batch completed events. It report in the tuning log "Event does not reference any tables" with a category ID of "S008".
When capturing your trace you need to add the "SQL:StmtCompleted" event under the TSQL section as well.
Jeff Walker pointed me in the right direction - but his answer was incomplete (although I'm certain he knew the complete answer and just didn't fully explain it)
In the Event Selection for Sql Server Profiler:
Remove the logging of RPC:Completed under Stored Procedures - this is the item that does poorly with Entity Framework
Expand to all events and ADD SP:StmtCompleted under Stored Procedure in order to get the queries into the trace.
Seems to work for me.
Microsoft Entity Framework People (and profiler people) This is actually lame. It used to work.
Use SQL Profiler to capture a whole session of queries. When you're done you can save the profiler results and run the whole thing through SQL Server Tuning Advisor. In my experience this gives much better results than tuning based on individual queries and in many ways is easier and more realistic since you can use profiler to capture queries from real application usage.
EDIT:
Thanks for bringing more attention to the specific issue you're asking about. I didn't realize you were saying that the Tuning Advisor doesn't understand sp_executesql because that simply isn't true. You can run as many queries as you want through sp_executesql and capture them in a profile and then run that profile through Tuning Advisor and it will give you recommendations.
To be sure, I just did it with MS SQL Server 2008 R2. I created a table with no indexes, ran a bunch of queries through sp_executesql, captured them in SQL Profiler, and then ran the resulting trace through Tuning Advisor. Tuning Advisor gave appropriate recommendations for the queries embedded within sp_executesql.
The exact version of Database Engine Tuning Advisor is 10.50.1600.1, running against Microsoft SQL Server 2008 R2 (RTM) - 10.50.1617.0 (X64) Apr 22 2011 19:23:43 Copyright (c) Microsoft Corporation Developer Edition (64-bit) on Windows NT 6.1 (Build 7601: Service Pack 1).

Information regarding query profiler

Does anyone have an information about a good query profiler?? By query i mean about 5 page search query.The profiler should be such as which gives the bottleneck in the query.
thanks
Depends on the database engine you use.
If it's Sybase, then use set statistics (io, time) and set queryplan on.
In MySQL, you can do EXPLAIN <query>. More approaches are in this blog entry: "MySQL Performance Monitoring and Optimization Tools".
In MS SQL Server use SQL Server Profiler.
For MySQL, you can use SQLyog's Query Profiler feature... SQLyog is very simple and easy to use MySQL GUI tool with loads of powerfull features... Hope it helps...

looking for a good summary of SQL 2005 Partitioning

I'm looking at this as a baseline explanation of the SQL 2005 Enterprise partitioning. Is there a resource that goes deeper into fine points and considerations of this issue. Some more examples would be useful too.
My main scenario is a time based partition system. With one partition that has the most accessed last X days. This partition will have to somehow slide (at least periodically) to keep it refereeing to the same amount of days.
Here's an excellant white paper on "SQL Server 2005 Partitioned Tables and Indexes"
by Kimberly Tripp.
http://www.sqlskills.com/resources/Whitepapers/Partitioning%20in%20SQL%20Server%202005%20Beta%20II.htm
I've found the SQL Server 2005 Books Online normally has all the information I'm looking for.
I found a good resource in the 05 BOL on SQL Server 2005 Partitioning:
http://technet.microsoft.com/en-us/library/ms188706(SQL.90).aspx
This link goes over designing partitioned tables and indexes:
http://technet.microsoft.com/en-us/library/ms175533(SQL.90).aspx
Here is a blog post that explains the sliding window case you posted:
http://blogs.msdn.com/menzos/archive/2008/06/30/table-partitioning-sliding-window-case.aspx
What about this:
Partitioning Data for Query Performance - Where's the benefit?
I'm not sure if this will help you (how much data you are working with) but this whitepaper below speaks of how to use staging tables and the switch clause to alter partitions.
http://www.microsoft.com/technet/prodtechnol/sql/bestpractice/loading_bulk_data_partitioned_table.mspx
It's more about bulk loading data into partitions, but it might be worth a read. The example scenario as explained at the recent SQL Summit in Sydney, Australia used a date based partitioning scheme as the example, which might be similar to what your scenario is.
This site may help you:
http://highscalability.com/
specific tags:
http://highscalability.com/tags/shard
http://highscalability.com/tags/sharding

Resources