![]() |
|
|
By: Ray Barley | Read Comments (4) | Print Ray is a Principal Architect at RDA Corporation and a MSSQLTips.com BI Expert. Related Tips: More |
|
Problem
I have identified one production database in particular where the business users are constantly complaining about slow performance. I would like to focus strictly on identifying and mitigating issues related to query performance in that database. What's the best tool to analyze a workload and identify improvements?
Solution
The Database Engine Tuning Advisor (DTA) is a performance tuning tool that was first available with SQL Server 2005. DTA replaced the Index Tuning Wizard in previous versions of SQL Server. In a nutshell DTA analyzes a workload and makes recommendations that will enhance query performance; e.g.:
In addition to identifying all sorts of opportunities for improvement, DTA will create a T-SQL script that you can run to actually implement its recommendations.
There are several ways that you can launch DTA:
You typically create a workload by putting together a group of queries in a text file or by running SQL Server Profiler. The key point to consider is that the workload you pass to DTA for analysis should be representative of the typical workload. The recommendations are based on what DTA sees in the workload. If the workload is very limited the recommendations may not be optimal. Usually the best bet is to capture the workload by running SQL Server Profiler, save the trace to a file, and pass that file on to the DTA. I will demonstrate this approach.
Launch SQL Server Profiler from the Performance Tools folder of the SQL Server program group in the Start menu or from the Tools menu in SSMS. Create a new trace and fill in the dialog as shown below:
The following are the main points about the general properties of the new trace:
Click on the Events Selection tab to review the events and columns selected:
You may want to add a filter to the trace to limit the information that is collected. For instance you may want to collect trace information from a single database. To do that click the column filters button on the Events Selection dialog (not show in the above screen shot) and enter your filter(s). In my case I want to filter on the DatabaseId column as shown below (the AdventureWorksDW database that I'm using has a DatabaseId = 26):
Start the profiler trace by clicking the Run button on the Trace Properties dialog and let it run for a period where you will capture a representative workload. Stop the trace by selecting Stop trace from the File menu in SQL Server Profiler. Launch DTA from SQL Server Profiler by selecting Database Engine Tuning Advisor from the Tools menu; fill in the dialog as follows:
The following are the main points about the DTA General properties dialog:
Click the Tuning Options tab and fill in the dialog as follows:
The Tuning Options allow you to specify your choices for physical design structures, partitioning, and whether to keep the existing physical design structures. These options are mutually exclusive so you may want to run the analysis more than once if necessary to specify different options. If you have a limited amount of time that you want to allow DTA to run, click the Limit tuning time checkbox and specify a stop time. Click Start Analysis on the DTA top-level menu to begin the analysis. When DTA completes the analysis, you will be presented with recommendations and their estimated improvement percentage, as well as a number of reports that you can review. For the recommendations you can choose from the following options on the DTA Actions menu:
Saving the recommendations is probably your best bet. You should review them and apply them as you see fit. DTA creates the T-SQL commands to implement the recommendations. The following is a sample of the recommendations, showing creating a multi-column statistic, a nonclustered index, and an indexed view:
CREATE STATISTICS [_dta_stat_325576198_10_2]
ON [dbo].[FactResellerSales] (
[SalesOrderNumber]
, [OrderDateKey]
)
go
CREATE NONCLUSTERED INDEX [_dta_index_DimCustomer_8_37575172__K1_K20]
ON [dbo].[DimCustomer] (
[CustomerKey] ASC
, [EnglishOccupation] ASC
)
WITH (
SORT_IN_TEMPDB = OFF
, IGNORE_DUP_KEY = OFF
, DROP_EXISTING = OFF
, ONLINE = OFF
) ON [PRIMARY]
go
CREATE VIEW [dbo].[_dta_mv_530] WITH SCHEMABINDING
AS
SELECT
[dbo].[DimCustomer].[Phone] as _col_1
, count_big(*) as _col_2
FROM [dbo].[DimCustomer]
GROUP BY [dbo].[DimCustomer].[Phone]
go
CREATE UNIQUE CLUSTERED INDEX [_dta_index__dta_mv_530_c_8_1639676889__K1]
ON [dbo].[_dta_mv_530] (
[_col_1] ASC
)WITH (
SORT_IN_TEMPDB = OFF
, IGNORE_DUP_KEY = OFF
, DROP_EXISTING = OFF
, ONLINE = OFF
) ON [PRIMARY]
go
|
One of the things you probably want to change is the object names. DTA generates these in a generic way; you would be better off to follow your own naming conventions.
DTA generates a number of reports based on its analysis of your workload as shown below:
The following are some highlights of these reports:
Next Steps
| Share: | Share | Tweet |
|
![]() |
|
|
Free SQL Server Learning |
| Tuesday, November 03, 2009 - 7:51:19 AM - admin | Read The Tip |
|
Ray, With the recent tips you have written about performance tuning, which tool is your favorite? Same question to the community, which performance monitoring\tuning tool is your favorite? Thank you, |
|
| Wednesday, November 04, 2009 - 6:43:10 AM - raybarley | Read The Tip |
|
My favorite tool depends on where I am in the performance tuning process. My first step is usually to use SQLDIAG since it provides a wealth of information. SQLDIAG provides the initial information you need to figure out if your bottleneck is CPU, memory, or i/o. I use SQL Server Profiler to dig in to what's going on with the workloads. I like to use the Database Engine Tuning Advisor especially during the application development process to be able to implement its recommendations before deployment. |
|
| Tuesday, December 01, 2009 - 12:25:26 PM - allorah | Read The Tip |
|
Hi, We have a very complex query of which I've used DTA and I basically implemented its recommendations which include many indexes. The query is improved but my question is ...does it affect updates and inserts? I noticed a performance degradtion in the insert/update but I'm not sure if this is due to the many indexes or just simply due to the business logic put in place. Thanks.
|
|
| Tuesday, December 01, 2009 - 1:07:34 PM - raybarley | Read The Tip |
|
Unfortunately there is a performance hit with adding indexes. Every insert, update and delete potentially has to perform some updates to the indexes. The one thing that you can do is to make sure that your indexes are actually being used. To do that you can use the DMV sys.dm_db_index_usage_stats. If you find any indexes that aren't being used you could drop them. There's no sense in maintaining an index that isn't being used. Then you have to weigh whether the benefit of the index (how much better your queries execute) is enough to outweigh the cost of maintaining the index. |
|
|
privacy | disclaimer | copyright | advertise | about authors | contribute | feedback | giveaways | user groups Some names and products listed are the registered trademarks of their respective owners. Edgewood Solutions LLC | MSSharePointTips.com | MSSQLTips.com |