<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results matching tags 'Performance', 'indexes', and 'Query Tuning'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=Performance,indexes,Query+Tuning&amp;orTags=0</link><description>Search results matching tags 'Performance', 'indexes', and 'Query Tuning'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Automating dm_exec_query_stats and dm_db_index_usage_stats analysis</title><link>http://sqlblog.com/blogs/joe_chang/archive/2009/06/22/automating-dm-exec-query-stats-and-dm-db-index-usage-stats-analysis.aspx</link><pubDate>Mon, 22 Jun 2009 04:25:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:14815</guid><dc:creator>jchang</dc:creator><description>&lt;P&gt;Everyone should know by now how really useful the DMVs dm_exec_query_stats, and dm_db_index_usage_stats and the associated DMFs for obtaining the SQL and XML plan: dm_exec_sql_text, dm_exec_query_plan, and dm_exec_text_query_plan. Of course it has been explained that dm_exec_query_stats is not a replacement for SQL Server Profiler and SQL Trace. The DMV is only reliable if execution plans are not frequently evicted from the procedure cache and if SQL is not frequently recompiled. &lt;/P&gt;
&lt;P&gt;Still the DMV dm_exec_query_stats is popular because the results are available with a simple query. The complexity of setting up a trace, making sure it is not adversely impacting server performance, making sure space is available, and most of all, the effort of parsing the trace are all avoided.&lt;/P&gt;
&lt;P&gt;So what do we do next? From the top query statistics we can start looking at the SQL and the execution plans. One minor annoyance is that if we use CROSS APPLY to dm_exec_query_plan, each XML plan has to be saved individually. This can be annoying if one has to remote into to a PC in the server room and this connection is slow. &lt;BR&gt;There is much information in the XML plan that would be helpful if we could see it in a grid along with the execution statistics. &lt;/P&gt;
&lt;P&gt;From the index usage statistics, we can eliminate unused indexes. There might also be indexes that are infrequently used. Sometimes it is obvious that certain indexes can be consolidated. Other times, it is necessary to examine the execution plan to determine if another index is sufficient. The XML plan analysis cross-references in which plans each index is used. All of this is tedious work which can be automated. So this is the purpose of the SQLExecStats tool.&lt;/P&gt;
&lt;P&gt;A few people have tried it on production systems. There are still bugs, and feature requests, but hopefully I can turn this into something useful over time. &lt;/P&gt;
&lt;P&gt;lets use this url for the latest build rather than changing the url for each build&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.qdpma.com/tools/ExecStats.zip"&gt;http://www.qdpma.com/tools/ExecStats.zip&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The above build is now 20090628. The (poor excuse for) documention is also online &lt;A href="http://www.qdpma.com/SQLExecStats.html"&gt;http://www.qdpma.com/SQLExecStats.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Feedback is welcome, in particular, send me the output files so I can try to figure out if this is collecting the right information.&amp;nbsp;Support will be&amp;nbsp;based on&amp;nbsp;availability. &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Note&lt;/STRONG&gt;: SQL Server 2008 sp1 fix now correctly reports parallel execution plan total_worker_time (CPU). It is not fixed on SQL Server 2005 sp3, latest cu?&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Limitations: &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;European Localization &lt;/STRONG&gt;The XML plan is stored as a string, with numbers in US-en format. My program&amp;nbsp;extracts plan cost and estimated row numbers from the XML plan. The previous version did not specify any localization, but I think the default is the host environment. Hence the code double.Format(value) is interpreted as whatever the local environment is instead of US-en. The builds since 20090623&amp;nbsp;specifies the US-en format in most places. &lt;/P&gt;
&lt;P&gt;If some one with European number formats could run this program and send me the output, I would appreciate it.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Bug fixes, features etc&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;2009-06-22: The&amp;nbsp;password now should display *,&amp;nbsp;I don't do security work, and it shows. Some formatting was changed to right align, comma thousands separator, Very large numbers in&amp;nbsp;Excel&amp;nbsp;cannot be changed, 4 bytes integers are represented as numbers, larger numbers are represented as text.&lt;BR&gt;I will do more formatting changes later&lt;/P&gt;
&lt;DIV&gt;&lt;STRONG&gt;2009-06-28&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;The error described by Zen occurs with case sensitive collations. Apparently&amp;nbsp;one SQL query I issued from the executable was not a case correct with the columns I declared on the receiving side, and this is sufficient to cause the data table load to fail.&lt;/DIV&gt;
&lt;DIV&gt;The current build is really an intermediate build. I am adding the ability to collect table and index information for multiple databases and not everything is consistent yet.&lt;/DIV&gt;
&lt;DIV&gt;Be careful on trying to collect for too many databases, and too many execution plans, there are checks for over size yet.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;2009-07-09&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;I am still in the middle of changing the tool to have the option of collecting table and index info from all databases. So some of the UI is not entirely consistent. However, all bug fixes are in the new version.&lt;/DIV&gt;
&lt;DIV&gt;Previously there were SQL queries that were not case correct with client-side table definitions, and when the default collation is case sensitive, an error occurred. This should be corrected.&lt;/DIV&gt;
&lt;DIV&gt;Also, previously I issued DBCC SHOW_STATISTICS([schema.table],[stat]) &lt;/DIV&gt;
&lt;DIV&gt;which&amp;nbsp;can generate an error if there is a hyphen&amp;nbsp;'-'&amp;nbsp;in the table or schema. I changed this to&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;('schema.table',[stat])&lt;BR&gt;I am not sure if this is the most safe format, should it be: ('schema.table','stat')?&lt;BR&gt;anyways, go to the main url, &lt;A href="http://www.qdpma.com/"&gt;http://www.qdpma.com/&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV&gt;look for &lt;A href="http://www.qdpma.com/tools/ExecStats_20090709.zip"&gt;SQL Exec Stats Build 2009-07-09&lt;/A&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;A href="http://www.qdpma.com/tools/ExecStats_20090709.zip"&gt;http://www.qdpma.com/tools/ExecStats_20090709.zip&lt;/A&gt;&lt;/DIV&gt;</description></item></channel></rss>