 




<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SQL Server with Mr. Denny &#187; Statistics</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/sql-server/tag/statistics/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/sql-server</link>
	<description></description>
	<lastBuildDate>Fri, 17 May 2013 17:04:01 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>New SQL 2008 R2 SP1 trace flag adjusts autostats threshold</title>
		<link>http://itknowledgeexchange.techtarget.com/sql-server/new-sql-2008-r2-sp1-trace-flag-adjusts-autostats-threshold/</link>
		<comments>http://itknowledgeexchange.techtarget.com/sql-server/new-sql-2008-r2-sp1-trace-flag-adjusts-autostats-threshold/#comments</comments>
		<pubDate>Tue, 04 Oct 2011 19:58:56 +0000</pubDate>
		<dc:creator>Denny Cherry</dc:creator>
				<category><![CDATA[auto-stats]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server 2008 R2]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[Statistics]]></category>
		<category><![CDATA[Trace Flag]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/sql-server/new-sql-2008-r2-sp1-trace-flag-adjusts-autostats-threshold/</guid>
		<description><![CDATA[I recently learned about a new trace flag which has been introduced in SQL Server 2008 R2 SP1 (and SQL Server &#8220;Denali&#8221;).  This trace flag, number 2371, changes the way that the SQL Server figures out when auto-stats should kick in. Up until now auto-stats was fixed to kick in every time that the column [...]]]></description>
				<content:encoded><![CDATA[<p>I recently learned about a new trace flag which has been introduced in SQL Server 2008 R2 SP1 (and SQL Server &#8220;Denali&#8221;).  This trace flag, number 2371, changes the way that the SQL Server figures out when auto-stats should kick in.</p>
<p>Up until now auto-stats was fixed to kick in every time that the column (or table in the older versions) had 20% + 500 rows change.  With the new flag turned on auto stats now stats static at the old value up until the row has 25,000 rows in it.  At this point the percentage of rows that need to change before auto-stats kicks in gets smaller and smaller as the table grows.<a href="http://cdn.ttgtmedia.com/ITKE/uploads/blogs.dir/20/files/2011/10/3480clip_image002_7e4cb1b3.png"><img class="alignleft size-thumbnail wp-image-1784" style="border: 0pt none;margin: 2px 4px" src="http://cdn.ttgtmedia.com/ITKE/uploads/blogs.dir/20/files/2011/10/3480clip_image002_7e4cb1b3.png" alt="Click To Enlarge" width="271" height="163" /></a> As you can see from the included graph as the number of rows in the table gets higher the percentage of rows that needs to changes gets very small with tables in the 100M row range needing only 0.31% of the rows to change (310,000 rows).  Because of this the odds of a large table having auto stats kick in is much greater than before, in the range of 20 to 60 times greater according to the <a href="http://blogs.msdn.com/b/saponsqlserver/archive/2011/09/07/changes-to-automatic-update-statistics-in-sql-server-traceflag-2371.aspx">SAP on SQL Server</a> blog (the same place I stole the graph from).  As Microsoft points out in their blog post by updating stats this much more frequently new stats could be generated in just a couple of days instead of waiting for weeks or months for new stats to be generated.</p>
<p>Like everything in SQL Server, nothing is free.  Keep in mind that when auto-stats kicks in for a column or table all the execution plans for that table or column will be invalidated and new plans will be generated.  If auto-stats were to kick in, in the middle of the day this could cause performance problems while the new plans are being generated which would be seen as slow query run times and increased CPU load on the SQL Server as well as increased IO load when you aren&#8217;t expecting it as update stats goes through reading the data in the table.</p>
<p>This trace flag was specifically designed for the &#8220;stupid large&#8221; databases in the world that are running OLTP workloads such as when running SAP on SQL Server which can generate some insanely large OLTP tables.</p>
<p>Microsoft currently doesn&#8217;t have an recommendations on when to turn on this trace flag, as finding companies with &#8220;stupid large&#8221; databases to test stuff on is tricky at best.</p>
<p>If you have one of these &#8220;stupidly large&#8221; databases and you find yourself having to manually update stats (probably via a scheduled job unless you really hate yourself) and you have SQL Server 2008 R2 SP1 installed then you might want to check out this trace flag and see if it helps you out.  Personally I&#8217;ve got a system I&#8217;d love to try this out on, and I&#8217;ll be getting that system upgraded to SP1 shortly so I can give it a try.</p>
<p>I wouldn&#8217;t expect this trace flag to be back ported down to SQL Server 2008 or SQL Server 2005.</p>
<p>Denny</p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/sql-server/new-sql-2008-r2-sp1-trace-flag-adjusts-autostats-threshold/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>What a difference a temp table makes over a table variable</title>
		<link>http://itknowledgeexchange.techtarget.com/sql-server/what-a-difference-a-temp-table-makes-over-a-table-variable/</link>
		<comments>http://itknowledgeexchange.techtarget.com/sql-server/what-a-difference-a-temp-table-makes-over-a-table-variable/#comments</comments>
		<pubDate>Mon, 01 Nov 2010 11:00:27 +0000</pubDate>
		<dc:creator>Denny Cherry</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Statistics]]></category>
		<category><![CDATA[Table Variables]]></category>
		<category><![CDATA[Temp Tables]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/sql-server/?p=1073</guid>
		<description><![CDATA[I was working on performance tuning the data deletion process that I use to remove data from our database.  We delete massive amounts of data on a daily basis, so our data deletion process is pretty important to us.  As we&#8217;ve grown our customer base the amount of data to be deleted every day has [...]]]></description>
				<content:encoded><![CDATA[<p>I was working on performance tuning the data deletion process that I use to remove data from our database.  We delete massive amounts of data on a daily basis, so our data deletion process is pretty important to us.  As we&#8217;ve grown our customer base the amount of data to be deleted every day has also grown, and the amount of time to delete that data has gone up as well.</p>
<p>We it has started to take stupid amounts of time to delete the data, so I started digging into the data deletion procedures.</p>
<p>The first thing I looked at was the actual delete statements.  These seams ok, the actual deletes were happening very quickly (we process deletes in batches of 1000 records per batch to minimize locking of data).  So next I looked at the part of the code where we select the records to be deleted.  Looking at the execution plan, everything looked ok.</p>
<p><a href="http://cdn.ttgtmedia.com/ITKE/uploads/blogs.dir/20/files/2010/04/bad_plan.jpg"><img class="alignnone size-medium wp-image-1070" src="http://cdn.ttgtmedia.com/ITKE/uploads/blogs.dir/20/files/2010/04/bad_plan.jpg" alt="" width="636" height="245" /></a></p>
<p>But this little chunk of code took about 50 minutes to run.  Pretty bad when only returning 1000 numbers back from the database.</p>
<pre class="brush: sql; title: ; notranslate">SELECT TOP (@BatchSize) a.PolicyIncidentId
FROM PolicyIncident a WITH (NOLOCK)
JOIN #ComputersToProcess ComputersToProcess ON a.ComputerId = ComputersToProcess.ComputerId
WHERE CaptureTimestamp &amp;lt; ComputersToProcess.StartDeleteAt
</pre>
<p>The first thing that I did was put a primary key on the @ComputersToProcess table variable.  That turned the table scan into a Clustered Index Scan, but didn&#8217;t do anything for performance.</p>
<p>The next thing I did was switch the table variable to a temp table (without a primary key).  This really didn&#8217;t do anything to speed up the process as there is still no statistics on the data.  However this time the execution plan actually shows you that there&#8217;s no statistic on the temp table.</p>
<p><a href="http://cdn.ttgtmedia.com/ITKE/uploads/blogs.dir/20/files/2010/04/table_var_no_stat.jpg"><img class="alignnone size-medium wp-image-1071" src="http://cdn.ttgtmedia.com/ITKE/uploads/blogs.dir/20/files/2010/04/table_var_no_stat.jpg" alt="" width="662" height="233" /></a></p>
<p>Now, I didn&#8217;t want to put at non-clustered index on the table keeping the table as a heap, and a clustered index that wasn&#8217;t a primary key wasn&#8217;t going be any more effective than a primary key, so I put a primary key on the table.  While the query cost percentage went up from 2% to 7% the actual run time went down from 50 minutes to just 1 second.</p>
<p><a href="http://cdn.ttgtmedia.com/ITKE/uploads/blogs.dir/20/files/2010/04/with_pk.jpg"><img class="alignnone size-medium wp-image-1072" src="http://cdn.ttgtmedia.com/ITKE/uploads/blogs.dir/20/files/2010/04/with_pk.jpg" alt="" width="633" height="213" /></a></p>
<p>Now I didn&#8217;t make any other code changes to the procedures, just changing from the table variable to the temp table, and adding a primary key and this one little three line query went from an hour to a second.  Its amazing how much such a small change can make things run smoother.</p>
<p>Now obviously this isn&#8217;t going to fix every problem.  But in my case I&#8217;m putting a little over 190k rows into the table variable (now temp table) and this is just to much for the table variable to take.  Keep in mind that with table variables the SQL Server has statistics, but it assumes only a single row per temp table, no matter how much data is actually in the table variable.</p>
<p>Denny</p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/sql-server/what-a-difference-a-temp-table-makes-over-a-table-variable/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Whitepaper on why database maintenance is important</title>
		<link>http://itknowledgeexchange.techtarget.com/sql-server/whitepaper-on-why-database-maintenance-is-important/</link>
		<comments>http://itknowledgeexchange.techtarget.com/sql-server/whitepaper-on-why-database-maintenance-is-important/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 01:55:08 +0000</pubDate>
		<dc:creator>Denny Cherry</dc:creator>
				<category><![CDATA[Index Performance]]></category>
		<category><![CDATA[Performance Problems]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server 2000]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[Statistics]]></category>
		<category><![CDATA[White Paper]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/sql-server/whitepaper-on-why-database-maintenance-is-important/</guid>
		<description><![CDATA[Today I&#8217;m publishing a white paper which I wrote for our Customer Service department to give to our customers. It explains why database maintenance is so important in keeping your database happy and healthy. The white paper is entitled &#8220;Database Maintenance Best Practices&#8221;. The paper doesn&#8217;t go into detail as to what commands to run, [...]]]></description>
				<content:encoded><![CDATA[<p>Today I&#8217;m publishing a white paper which I wrote for our Customer Service department to give to our customers.  It explains why database maintenance is so important in keeping your database happy and healthy.<span id="more-715"></span></p>
<p>The white paper is entitled &#8220;Database Maintenance Best Practices&#8221;.  The paper doesn&#8217;t go into detail as to what commands to run, but gives a good high level overview (with some technical details) as to what needs to be done, and more importantly why.</p>
<p>The white paper is available free of charge to anyone who want to <a href="http://www.securityfightclub.com/downloads/Database%20Maintenance%20Best%20Practices.pdf" target="_blank">download</a> it.</p>
<p>Denny</p>
<p>PS. This is the same white paper which I published on <a href="http://www.securityfightclub.com" target="_blank">www.securityfightclub.com</a>.</p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/sql-server/whitepaper-on-why-database-maintenance-is-important/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>New tip published: Update SQL Server table statistics for performance kick</title>
		<link>http://itknowledgeexchange.techtarget.com/sql-server/new-tip-published-update-sql-server-table-statistics-for-performance-kick/</link>
		<comments>http://itknowledgeexchange.techtarget.com/sql-server/new-tip-published-update-sql-server-table-statistics-for-performance-kick/#comments</comments>
		<pubDate>Thu, 15 Nov 2007 19:23:06 +0000</pubDate>
		<dc:creator>Denny Cherry</dc:creator>
				<category><![CDATA[Article]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Statistics]]></category>
		<category><![CDATA[T/SQL]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/sql-server/new-tip-published-update-sql-server-table-statistics-for-performance-kick/</guid>
		<description><![CDATA[A new tip has been published over at SearchSQLServer.com entitled Update SQL Server table statistics for performance kick.]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve published a new tip over at <a target="_blank" href="http://www.searchsqlserver.com" title="SearchSQLServer.com">SearchSQLServer.com</a> entitled <a target="_blank" href="http://searchsqlserver.techtarget.com/tip/0,289483,sid87_gci1278729,00.html" title="Tip">Update SQL Server table statistics for performance kick</a>.</p>
<p> Denny</p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/sql-server/new-tip-published-update-sql-server-table-statistics-for-performance-kick/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New tip published about table statistics</title>
		<link>http://itknowledgeexchange.techtarget.com/sql-server/new-tip-published-about-table-statistics/</link>
		<comments>http://itknowledgeexchange.techtarget.com/sql-server/new-tip-published-about-table-statistics/#comments</comments>
		<pubDate>Thu, 25 Oct 2007 18:03:42 +0000</pubDate>
		<dc:creator>Denny Cherry</dc:creator>
				<category><![CDATA[Article]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Statistics]]></category>
		<category><![CDATA[T/SQL]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/sql-server/new-tip-published-about-table-statistics/</guid>
		<description><![CDATA[My next tip on SQL Server Statistics has been published on SearchSQLServer.com entitled Update SQL Server table statistics for performance kick.]]></description>
				<content:encoded><![CDATA[<p>My next tip on SQL Server Statistics has been published on <a target="_blank" href="http://www.searchsqlserver.com">SearchSQLServer.com</a> entitled <a target="_blank" href="http://searchsqlserver.techtarget.com/tip/0,289483,sid87_gci1278729,00.html" title="Update SQL Server table statistics for performance kick">Update SQL Server table statistics for performance kick</a>.</p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/sql-server/new-tip-published-about-table-statistics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
