<?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 tag 'Indexed Views'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=Indexed+Views&amp;orTags=0</link><description>Search results matching tag 'Indexed Views'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>NOEXPAND query hint returns wrong results – CU fix now available</title><link>http://sqlblog.com/blogs/jamie_thomson/archive/2013/02/04/noexpand-query-hint-returns-wrong-results-cu-fix-now-available.aspx</link><pubDate>Mon, 04 Feb 2013 10:24:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47466</guid><dc:creator>jamiet</dc:creator><description>&lt;p&gt;Three days ago at my current gig we stumbled across a problem where use of the &lt;a href="http://msdn.microsoft.com/en-gb/library/ms181714.aspx" target="_blank"&gt;NOEXPAND query hint&lt;/a&gt; was causing different results compared to the same query &lt;em&gt;without&lt;/em&gt; NOEXPAND. For those that do not know (which, until three days ago, included me) NOEXPAND governs the use of indexed views:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;The indexed view is not expanded only if the view is directly referenced in the SELECT part of the query and WITH (NOEXPAND) or WITH (NOEXPAND, INDEX(index_value [ &lt;strong&gt;,&lt;/strong&gt;...n ] ) ) is specified.        &lt;br&gt;&lt;/em&gt;&lt;a title="http://msdn.microsoft.com/en-gb/library/ms181714.aspx" href="http://msdn.microsoft.com/en-gb/library/ms181714.aspx"&gt;&lt;em&gt;http://msdn.microsoft.com/en-gb/library/ms181714.aspx&lt;/em&gt;&lt;/a&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;This screenshot demonstrates the problem:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://sqlblog.com/blogs/jamie_thomson/image_09EE107F.png"&gt;&lt;img style="border:0px currentColor;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/jamie_thomson/image_thumb_5645A420.png" width="936" height="225"&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Clearly this isn’t good. &lt;a href="https://twitter.com/jamiet/status/297384398972657664" target="_blank"&gt;I put a comment out on Twitter&lt;/a&gt; hoping someone knew something about it and thankfully &lt;a href="https://twitter.com/gonsalu"&gt;Gonçalo Ferreira&lt;/a&gt; was reading. He &lt;a href="https://twitter.com/gonsalu/status/298140026796138496" target="_blank"&gt;pointed me&lt;/a&gt; toward a Knowledge Base article entitled &lt;a href="http://support.microsoft.com/kb/2756471" target="_blank"&gt;FIX: Incorrect result is returned when you query an indexed view by using the NOEXPAND hint in SQL Server 2008, in SQL Server 2008 R2 or in SQL Server 2012&lt;/a&gt; that confirmed this as being a bug in SQL Server. The article is dated 24th January 2013 (that is only 11 days ago folks) and describes the bug rearing its head under these circumstances:&lt;/p&gt;  &lt;blockquote&gt;   &lt;ul&gt;     &lt;li&gt;&lt;font color="#c0504d"&gt;You create an indexed view for two tables that have a foreign key reference in Microsoft SQL Server 2008, in Microsoft SQL Server 2012 or in Microsoft SQL Server 2008 R2. &lt;/font&gt;&lt;/li&gt;      &lt;li&gt;&lt;font color="#c0504d"&gt;You update the base tables of the indexed view. &lt;/font&gt;&lt;/li&gt;      &lt;li&gt;&lt;font color="#c0504d"&gt;You run a query against the indexed view that uses the NOEXPAND hint.&lt;/font&gt;&lt;/li&gt;   &lt;/ul&gt;   &lt;font color="#c0504d"&gt;In this scenario, you receive an incorrect result.&lt;/font&gt;&lt;/blockquote&gt;  &lt;p&gt;I don’t know about you but I read that as “If you’re using Indexed Views with NOEXPAND, they’re most likely giving you the wrong answer”. The latest cumulative update (CU) for:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;SQL Server 2012&lt;/li&gt;    &lt;li&gt;SQL Server 2012 SP1&lt;/li&gt;    &lt;li&gt;SQL Server 2008 R2 SP2&lt;/li&gt;    &lt;li&gt;SQL Server 2008 R2 SP1&lt;/li&gt;    &lt;li&gt;SQL Server 2008 SP3&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;fixes the problem. If you’re using indexed views you may want to install the CU, sharpish!&lt;/p&gt;  &lt;p&gt;&lt;a href="http://twitter.com/jamiet" target="_blank"&gt;@Jamiet&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;float:none;white-space:normal;orphans:2;widows:2;font-size-adjust:none;font-stretch:normal;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;"&gt;UPDATE. Paul White has posted a fantastic blog post where he explains how to reproduce the problem: &lt;a href="http://sqlblog.com/blogs/paul_white/archive/2013/02/06/incorrect-results-with-indexed-views.aspx" target="_blank"&gt;Incorrect Results with Indexed Views&lt;/a&gt;&amp;nbsp;(N.B. It occurs if you are using the MERGE statement) and Aaron Bertrand has followed with&amp;nbsp;the equally readable &lt;a href="http://www.sqlperformance.com/2013/02/t-sql-queries/another-merge-bug" target="_blank"&gt;If you are using indexed views and MERGE, please read this!&lt;/a&gt; where he offers some considered opinions and advice surrounding the issue. I highly recommend reading both.&lt;/span&gt;&lt;/p&gt;</description></item><item><title>Connect Digest : 2011-06-27</title><link>http://sqlblog.com/blogs/aaron_bertrand/archive/2011/06/27/connect-digest-2011-06-27.aspx</link><pubDate>Mon, 27 Jun 2011 17:35:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:35785</guid><dc:creator>AaronBertrand</dc:creator><description>&lt;p&gt;Sorry I have fallen off the Connect Digest wagon for the past few weeks; been a little swamped since returning from SQLCruise Alaska. Not sure I'll be able to assemble a digest every week, but I'll certainly try to keep a steady pace.&lt;br&gt;&lt;/p&gt;&lt;p&gt;This week I wanted to highlight a few suggestions around indexed views. With the coming of SQL Server code-named "Denali" we will be pushed toward the new columnstore index as an alternative to indexed views. But this won't be for all cases, and it likely won't be available to all editions, either. So I hope that these requests don't start to get discarded with the simple workaround of upgrading to Denali, possibly upgrading to Enterprise Edition, and converting to the read-only columnstore index.&lt;/p&gt;&lt;p&gt;==================== &lt;br&gt;&lt;/p&gt;&lt;p&gt;Ralf Dietrich suggests relaxing some of the restrictions on indexed view
 creation; for example, the fact that an index can't be created on a 
view with non-deterministic functions. He doesn't want it to just 
suddenly start working, but to require a hint to make work. &lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/577305/indexed-view-improvements" title="http://connect.microsoft.com/SQLServer/feedback/details/577305/indexed-view-improvements" target="_blank"&gt;#577305 : indexed view improvements&lt;br&gt;&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;==================== &lt;br&gt;
&lt;/p&gt;&lt;p&gt;Razvan Socol has a similar suggestion, that views with one or more unions could be indexed. His specific use case is not just for performance but also that he'd like to define a foreign key against the view.&lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/125968/indexes-on-views-that-contain-union-s" title="http://connect.microsoft.com/SQLServer/feedback/details/125968/indexes-on-views-that-contain-union-s" target="_blank"&gt;#125968 : Indexes on views that contain UNION-s&lt;/a&gt;&lt;br&gt;

&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;==================== &lt;br&gt;
&lt;/p&gt;&lt;p&gt;xor88 is asking for stacked (or "nested") indexed views. Essentially he wants to be able to create an index on a view that references another indexed view, in order to support persist aggregations over existing persisted aggregations. &lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/641364" title="http://connect.microsoft.com/SQLServer/feedback/details/641364" target="_blank"&gt;#641364 : stacked indexed views&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;==================== &lt;br&gt;
&lt;/p&gt;&lt;p&gt;Back in 2007, I asked for more aggregation support in indexed views - in addition to counts, for example, it would be helpful to have min/max support. More work for the engine, of course, but it could dramatically&lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/267516/expand-aggregate-support-in-indexed-views-min-max" title="http://connect.microsoft.com/SQLServer/feedback/details/267516/expand-aggregate-support-in-indexed-views-min-max" target="_blank"&gt;#267516 : Expand aggregate support in indexed views (MIN/MAX)&lt;/a&gt;&lt;br&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;==================== &lt;br&gt;
&lt;/p&gt;&lt;p&gt;Adam Machanic (&lt;a href="http://twitter.com/AdamMachanic" title="http://twitter.com/AdamMachanic" target="_blank"&gt;@AdamMachanic&lt;/a&gt;) filed this bug, concerning the fact that indexed view creation takes a schema modification lock on the base table (resulting in blocking both readers and writers), when it would be possible to take only a schema stability and shared table lock (blocking only writers).&lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/581056/indexed-view-creation-causes-queries-on-the-base-table-to-block" title="http://connect.microsoft.com/SQLServer/feedback/details/581056/indexed-view-creation-causes-queries-on-the-base-table-to-block" target="_blank"&gt;#581056 : Indexed view creation causes queries on the base table to block&lt;/a&gt; &lt;br&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;==================== &lt;br&gt;
&lt;/p&gt;A comment on the above item from Paul White (&lt;a href="http://twitter.com/SQL_Kiwi" title="http://twitter.com/SQL_Kiwi" target="_blank"&gt;@SQL_Kiwi&lt;/a&gt;) made me think of this suggestion, to delay index creation so that it could be done in the background and have less impact on real-time operations:&lt;br&gt;&lt;blockquote&gt;&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/593032/indexed-views-option-for-delayed-seperate-index-creation-process-akin-to-full-text-indexing" title="http://connect.microsoft.com/SQLServer/feedback/details/593032/indexed-views-option-for-delayed-seperate-index-creation-process-akin-to-full-text-indexing" target="_blank"&gt;#593032 : Indexed Views - Option for Delayed Seperate Index creation Process - Akin to Full Text Indexing&lt;/a&gt;&lt;br&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;==================== &lt;/p&gt;&lt;p&gt;That's it for this week's digest. Please let me know if you have suggestions for future focus areas! &lt;br&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &lt;br&gt;&lt;/p&gt;</description></item><item><title>Connect Digest : 2011-05-23</title><link>http://sqlblog.com/blogs/aaron_bertrand/archive/2011/05/23/connect-digest-2011-05-23.aspx</link><pubDate>Mon, 23 May 2011 12:28:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:35396</guid><dc:creator>AaronBertrand</dc:creator><description>&lt;p&gt;Next week I'll be up in Alaska for &lt;a href="http://www.sqlcruise.com/" title="http://www.sqlcruise.com/" target="_blank"&gt;SQL Cruise&lt;/a&gt;, so I'll be skipping at least one digest. This week I gathered a few engine-related issues, two involving what the engine does while an index is being created. The most important one, though, at least IMHO, is the first one listed, involving a hashing algorithm fix that is in SQL Server 2008 R2 - but with no plans to fix it for SQL Server 2008. I wonder if someone should file a separate, 2008-specific bug?&lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/458091/change-lock-resource-hashing-algorithm-to-reduce-likelihood-of-collisions" title="http://connect.microsoft.com/SQLServer/feedback/details/458091/change-lock-resource-hashing-algorithm-to-reduce-likelihood-of-collisions" target="_blank"&gt;#458091 : Change Lock Resource Hashing Algorithm to Reduce Likelihood of Collisions&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/581056/indexed-view-creation-causes-queries-on-the-base-table-to-block" title="http://connect.microsoft.com/SQLServer/feedback/details/581056/indexed-view-creation-causes-queries-on-the-base-table-to-block" target="_blank"&gt;#581056 : Indexed view creation causes queries on the base table to block&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/478568/ssms-gets-blocked-and-locks-up-during-index-creation" title="http://connect.microsoft.com/SQLServer/feedback/details/478568/ssms-gets-blocked-and-locks-up-during-index-creation" target="_blank"&gt;#478568 : SSMS Gets Blocked and Locks Up During Index Creation&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/125549/poor-execution-plan-with-cte" title="http://connect.microsoft.com/SQLServer/feedback/details/125549/poor-execution-plan-with-cte" target="_blank"&gt;#125549 : Poor execution plan with CTE&lt;/a&gt; &lt;br&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;And finally, this issue ("&lt;span&gt;high degrees of parallelism cause incorrect results to be observed more frequently" according to &lt;a href="http://support.microsoft.com/kb/981502" title="http://support.microsoft.com/kb/981502" target="_blank"&gt;KB #981502&lt;/a&gt;)&lt;/span&gt; is one that has been fixed in SP1 for SQL Server 2008 R2, but it requires a trace flag (in Denali, it will be on by default, so you won't need a trace flag). I'm not telling you about this so you'll go and vote for this issue, but rather just to make you aware of it. The KB article states that the fix is in various CUs for 2005, 2008 and 2008 R2, but as the Connect item implies, the fix may not actually work in all cases, and requires the trace flag for others.&lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/642790" title="http://connect.microsoft.com/SQLServer/feedback/details/642790" target="_blank"&gt;#642790 : Parallel query plan returns different results every time that you run the query&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &lt;br&gt;&lt;/p&gt;&lt;/blockquote&gt;</description></item><item><title>Connect Digest : 2011-05-16</title><link>http://sqlblog.com/blogs/aaron_bertrand/archive/2011/05/16/connect-digest-2011-05-16.aspx</link><pubDate>Mon, 16 May 2011 11:19:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:35372</guid><dc:creator>AaronBertrand</dc:creator><description>&lt;p&gt;This week we're going to take a look at issues with filtered indexes. This feature was a very welcome addition in SQL Server 2008 and has enjoyed widespread usage if conversations on twitter and forums are any indication. But their implementation is not perfect - bugs in SSMS and numerous restrictions on their use have certainly reduced their impact, or at least made much more work for folks using them.&lt;br&gt;&lt;/p&gt;&lt;br&gt;&lt;b&gt;SSMS failures&lt;/b&gt;&lt;br&gt;&lt;blockquote&gt;&lt;p&gt;Several people have reported various cases where Management Studio trips over filtered index functionality. I would only expect these bugs to be fixed in either 2008 R2 SSMS or Denali (in some cases both) - don't hold out for your 2005 or even 2008 versions of SSMS to be fixed for filtered index or other "new feature" issues.&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/526911/ssms-table-designer-fails-to-correctly-script-filtered-index" title="http://connect.microsoft.com/SQLServer/feedback/details/526911/ssms-table-designer-fails-to-correctly-script-filtered-index" target="_blank"&gt;#526911 : Table designer fails to correctly script filtered index&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/462053/the-filter-expression-of-a-filtered-index-is-lost-when-a-table-is-modified-by-the-table-designer" title="http://connect.microsoft.com/SQLServer/feedback/details/462053/the-filter-expression-of-a-filtered-index-is-lost-when-a-table-is-modified-by-the-table-designer" target="_blank"&gt;#462053 : The filter expression of a filtered index is lost when a table is modified by the Table Designer&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/362699/2008-rtm-ssms-engine-table-designer-doesnt-script-where-clause-in-filtered-indexes" title="http://connect.microsoft.com/SQLServer/feedback/details/362699/2008-rtm-ssms-engine-table-designer-doesnt-script-where-clause-in-filtered-indexes" target="_blank"&gt;#362699 : Table designer doesn't script WHERE clause in filtered indexes&lt;/a&gt;&lt;br&gt;&amp;nbsp;
&lt;br&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/330238/msft-bicoe-csat-there-is-no-way-of-creating-filtered-index-from-ssms-while-designing-a-new-table" title="http://connect.microsoft.com/SQLServer/feedback/details/330238/msft-bicoe-csat-there-is-no-way-of-creating-filtered-index-from-ssms-while-designing-a-new-table" target="_blank"&gt;#330238 : There is no way of creating filtered index from SSMS while designing a new table&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/521333/view-dependencies-fails-with-transact-sql-error-515" title="http://connect.microsoft.com/SQLServer/feedback/details/521333/view-dependencies-fails-with-transact-sql-error-515" target="_blank"&gt;#521333 : View Dependencies fails with Transact-SQL Error 515&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;br&gt;&lt;b&gt;Engine failures&lt;/b&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Well, there is only one of these outstanding at this time, at least that I could find. I suspect this has to do with the testing matrix - they added both filtered indexes and MERGE in SQL Server 2008, but did not thoroughly test them *together.* There is a &lt;a href="http://social.technet.microsoft.com/Forums/en-US/transactsql/thread/32727b47-fd03-4033-8140-510876ccada2" title="http://social.technet.microsoft.com/Forums/en-US/transactsql/thread/32727b47-fd03-4033-8140-510876ccada2" target="_blank"&gt;discussion thread on the MSDN forums&lt;/a&gt; about this specific issue:&lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/596086/merge-statement-bug-when-insert-delete-used-and-filtered-index" title="http://connect.microsoft.com/SQLServer/feedback/details/596086/merge-statement-bug-when-insert-delete-used-and-filtered-index" target="_blank"&gt;#596086 : MERGE statement bug when INSERT/DELETE used and filtered index&lt;/a&gt;&lt;br&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;br&gt;&lt;b&gt;Missing functionality&lt;/b&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Some of these items are categorized as bugs, but I believe they simply represent scope creep. One of the items actually says something along the lines of, "It's not a bug; it's a known gap in functionality." Personally I think they got the bare minimum into SQL Server 2008 (supporting unique constraints the ANSI standard way, where more than one row can be NULL), and had no intention of supporting all of the other things that could make filtered indexes even more useful. If you find any of these suggestions valuable, please comment and vote - hopefully we can convince them to invest some time into this feature area for the next version after Denali! &lt;/p&gt;&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/454744/filtered-index-not-used-and-key-lookup-with-no-output" title="http://connect.microsoft.com/SQLServer/feedback/details/454744/filtered-index-not-used-and-key-lookup-with-no-output" target="_blank"&gt;#454744 : Filtered index not used and key lookup with no output&lt;/a&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/341891/filtered-index-creation-failed-with-not-in-clause" title="http://connect.microsoft.com/SQLServer/feedback/details/341891/filtered-index-creation-failed-with-not-in-clause" target="_blank"&gt;&lt;br&gt;&lt;br&gt;#341891 : Filtered index creation failed with NOT IN clause&lt;/a&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/341737/filtered-index-does-not-allow-filters-on-disjunctions%20" title="http://connect.microsoft.com/SQLServer/feedback/details/341737/filtered-index-does-not-allow-filters-on-disjunctions " target="_blank"&gt;&lt;br&gt;&lt;br&gt;#341737 : Filtered index does not allow filters on disjunctions&lt;/a&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/648551/" title="http://connect.microsoft.com/SQLServer/feedback/details/648551/" target="_blank"&gt;&lt;br&gt;&lt;br&gt;#648551 : filtered index on indexed view&lt;/a&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/666238/support-for-more-complex-where-clause-in-filtered-indexes" title="http://connect.microsoft.com/SQLServer/feedback/details/666238/support-for-more-complex-where-clause-in-filtered-indexes" target="_blank"&gt;&lt;br&gt;&lt;br&gt;#666238 : Support for more complex WHERE clause in filtered indexes&lt;/a&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/518328/should-be-possible-to-create-a-filtered-index-on-a-deterministic-persisted-computed-column" title="http://connect.microsoft.com/SQLServer/feedback/details/518328/should-be-possible-to-create-a-filtered-index-on-a-deterministic-persisted-computed-column" target="_blank"&gt;&lt;br&gt;&lt;br&gt;#518328 : Should be possible to create a filtered index on a deterministic persisted computed column&lt;/a&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/498009/allow-filtered-unique-index-to-be-a-canditate-key-for-a-foreign-key" title="http://connect.microsoft.com/SQLServer/feedback/details/498009/allow-filtered-unique-index-to-be-a-canditate-key-for-a-foreign-key" target="_blank"&gt;&lt;br&gt;&lt;br&gt;#498009 : Allow filtered unique index to be a canditate key for a foreign key&lt;/a&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/329805/enhancements-to-the-missing-indexes-dmvs-for-filtered-indexes" title="http://connect.microsoft.com/SQLServer/feedback/details/329805/enhancements-to-the-missing-indexes-dmvs-for-filtered-indexes" target="_blank"&gt;&lt;br&gt;&lt;br&gt;#329805 : Enhancements to the missing indexes DMV's for filtered indexes&lt;/a&gt;&lt;br&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;br&gt;&amp;nbsp;&lt;br&gt;</description></item><item><title>Mixing OLTP and reporting using indexed views</title><link>http://sqlblog.com/blogs/aaron_bertrand/archive/2009/12/29/mixing-oltp-and-reporting-using-indexed-views.aspx</link><pubDate>Tue, 29 Dec 2009 14:40:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:20314</guid><dc:creator>AaronBertrand</dc:creator><description>&lt;p&gt;I'm not a big fan of denormalizing, nor of repeating redundant &lt;strike&gt;redundant&lt;/strike&gt; information in a database when those facts can already be derived from other information.&amp;nbsp; A classic example of the latter is when I see questions on newsgroups, forums or StackOverflow that ask how they can update a table's rank column to reflect the current rank based on some other criteria in the table.&amp;nbsp; The problem with this is that you have to run the update every time any DML operation touches any row in the table, and if you can calculate that rank in an UPDATE query, you can also calculate that rank in a SELECT query, so why not just figure it out in real time?&amp;nbsp; An example of the former is when we want to maintain a second table with aggregates from another table.&amp;nbsp; This is where I want to spend my time today.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;In reality, many of us deal with OLTP systems that must also serve as the reporting source, so it's not always feasible to calculate aggregates in real time against a constantly moving target.&amp;nbsp; In several of these scenarios I've used indexed views, where we have tables that are inserted often, read often for statistics, but rarely or never updated... sure, you pay a little hit up front on the insert, but the benefit achieved during real-time reporting was worth it.&amp;nbsp; Let me give you an idea of what I was dealing with initially, and how I have fixed it over time to perform even better.&lt;/p&gt;

&lt;p&gt;One of our systems is an SaaS e-mail platform, where we offer the ability for our customers to distribute messaging to their customers (mostly via e-mail, but we also support fax, SMS, widgets/gadgets, and social media).&amp;nbsp; For brevity, let's call these people "recipients."&amp;nbsp; If you stripped the schema down to the bare essentials for metadata, you'd see this (I'm going to leave out the foreign key and other constraints, as they are either obvious or irrelevant):&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;CREATE&amp;nbsp;TABLE&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.Domains&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;DomainID&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&amp;nbsp;PRIMARY&amp;nbsp;KEY&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;DomainName&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;VARCHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;255&lt;/font&gt;&lt;font color="gray"&gt;)&lt;/font&gt;&lt;font color="blue"&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;);&lt;br&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;CREATE&amp;nbsp;TABLE&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.Recipients&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;RecipientID&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&amp;nbsp;PRIMARY&amp;nbsp;KEY&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;DomainID&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;LocalPart&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;VARCHAR&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;64&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="green"&gt;/*&amp;nbsp;,&amp;nbsp;...&amp;nbsp;other&amp;nbsp;columns&amp;nbsp;...&amp;nbsp;*/&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;);&amp;nbsp;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;Obviously we store many other details about recipients, such as demographic information, preferences, opt-in status, subscriptions, etc.&amp;nbsp; But for this discussion, the above is sufficient.&amp;nbsp; Notice that for space savings we don't actually store the e-mail address of the recipient, though it is required and is enforced to be unique via a constraint on (DomainID, LocalPart); this information can easily be derived using a view (you can even make this an indexed view if you want quicker access to e-mail addresses, but I'll leave that for another day): &lt;br&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;CREATE&amp;nbsp;VIEW&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.vRecipientDetails&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;AS&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SELECT&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;r.RecipientID&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;EmailAddress = &lt;/font&gt;&lt;font color="blue"&gt;&lt;/font&gt;&lt;font color="black"&gt;r.LocalPart&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;+&amp;nbsp;&lt;/font&gt;&lt;font color="red"&gt;'@'&amp;nbsp;&lt;/font&gt;&lt;font color="gray"&gt;+&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;d.DomainName&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;FROM&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.Recipients&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;AS&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;r&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INNER&amp;nbsp;JOIN&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.Domains&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;AS&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;d&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;ON&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;r.DomainID&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;d.DomainID&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;RecipientID is the primary key because it is used in a lot of related tables, most importantly, stats tables.&amp;nbsp; We record every single transaction for a recipient: when a message is attempted to be sent to them; when a successful delivery occurs; when a bounce occurs; when the recipient opens the message or clicks on a link in the message; when the recipient changes their preferences; or, when the user declines to receive further communications from our customer.&amp;nbsp; The thought of storing LocalPart + DomainID (or the fully composed e-mail address) in all of these other tables that would grow and grow over time made a surrogate representation a very easy choice for the primary key.&amp;nbsp; I didn't want to make the discussion revolve around this, but I've seen several raised eyebrows in the past about surrogate primary keys and wanted to assure you that, in this system, I think it is the best choice.&amp;nbsp; (If you want to debate that, let's have a different discussion, as long as it doesn't turn religious.)&lt;br&gt;&lt;/p&gt;


&lt;p&gt;Okay, so I mentioned this is an OLTP system, and I mentioned that we record all of the individual transactions for a recipient in various stats tables.&amp;nbsp; Let's take a quick look at how one of these stats tables looked for the first, oh, 5 years of their existence: &lt;br&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;CREATE&amp;nbsp;TABLE&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.Deliveries&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;MessageID&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;,&amp;nbsp;&lt;/font&gt;&lt;font color="green"&gt;--&amp;nbsp;references&amp;nbsp;a&amp;nbsp;table&amp;nbsp;dbo.Messages&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;RecipientID&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;EventDate &lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;SMALLDATETIME&lt;/font&gt;&lt;/font&gt;&lt;font color="black"&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="green"&gt;/*&amp;nbsp;,&amp;nbsp;...&amp;nbsp;other&amp;nbsp;columns...&amp;nbsp;*/&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;);&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;So a customer would send out a message targeted to, say, 50,000 recipients.&amp;nbsp; During the next few hours we would fill up this table with successful deliveries (and other similar tables with bounces, opens, clicks, etc).&amp;nbsp; Soon after inception of the system, we found that our customers wanted to pull real-time statistics on how the messages were going... mostly on the lookout for high bounce rates (well, low delivery rates too, I guess).&amp;nbsp; Of course this was very contentious if they pulled reports while the tables were loading.&amp;nbsp; So in order to give a much more satisfactory experience to the user pulling reports in our web UI, we created indexed views that would automatically maintain the number of deliveries, bounces, etc.:&lt;br&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;CREATE&amp;nbsp;VIEW&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.vMessageDeliveries&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;WITH SCHEMABINDING&lt;/font&gt;&lt;font color="black"&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;AS&lt;br&gt;&amp;nbsp;&amp;nbsp;SELECT&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;MessageID&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;c = &lt;font color="magenta"&gt;COUNT_BIG&lt;/font&gt;&lt;/font&gt;&lt;font color="gray"&gt;(*)&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;FROM&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.Deliveries&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;GROUP&amp;nbsp;BY&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;MessageID&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font color="black"&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;CREATE&amp;nbsp;UNIQUE&amp;nbsp;CLUSTERED&amp;nbsp;INDEX&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;m&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;ON&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.vMessageDeliveries&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;MessageID&lt;/font&gt;&lt;font color="gray"&gt;);&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;So now the inserts were a little more expensive but, as mentioned above, this was much better for overall system performance (at least perceived performance) and, more importantly, customer happiness.&lt;/p&gt;


&lt;p&gt;Then customers wanted more details on their statistics.&amp;nbsp; They wanted to see how their messages were getting into, say, Hotmail compared to AOL.&amp;nbsp; We have this information, but it was quite expensive to retrieve.&amp;nbsp; Remember earlier I noted that we don't typically store redundant information, but this means that in cases like this, we need to do a lot of joins.&amp;nbsp; So for example, to provide a responsive report that showed real-time message status per domain, we created indexed views like this: &lt;br&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;CREATE&amp;nbsp;VIEW&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.vMessageDomainDeliveries&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;WITH SCHEMABINDING&lt;/font&gt;&lt;font color="black"&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;AS&lt;br&gt;&amp;nbsp;&amp;nbsp;SELECT&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;d.MessageID&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;r.DomainID&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;c = &lt;font color="magenta"&gt;COUNT_BIG&lt;/font&gt;&lt;/font&gt;&lt;font color="gray"&gt;(*)&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;FROM&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.Deliveries&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;AS&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;d&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INNER&amp;nbsp;JOIN&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.Recipients&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;AS&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;r&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;ON&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;r.RecipientID&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;=&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;d.RecipientID&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;GROUP&amp;nbsp;BY&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;d.MessageID&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;r.DomainID&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font color="black"&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;CREATE&amp;nbsp;UNIQUE&amp;nbsp;CLUSTERED&amp;nbsp;INDEX&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;md&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;ON&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.vMessageDomainDeliveries&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;MessageID&lt;/font&gt;&lt;font color="gray"&gt;,&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;DomainID&lt;/font&gt;&lt;font color="gray"&gt;);&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;Of course this again added more strain to the insert process on the deliveries table, since it now had to maintain two indexed views.&amp;nbsp; In isolation, this still yielded better overall performance than essentially expanding that view and trying to get at the domain aggregates in real time.&amp;nbsp; But it introduced a new problem to the system: severe blocking.&amp;nbsp; Picture the case where deliveries are being recorded while a recipient is trying to update their preferences or change their e-mail address.&amp;nbsp; Since both processes need to lock and potentially update the index on the indexed view, one has to wait for the other.&amp;nbsp; This can lead to a sad face on an end user.&lt;/p&gt;

&lt;p&gt;What I ended up doing was to recant my disdain for storing redundant information, and store the domain information in the deliveries table.&amp;nbsp; Yes, this was an extra 4 bytes, but as we were moving the whole system to a new 2008 cluster with a much faster I/O subsystem, we would get much more than that back with page compression.&amp;nbsp; So starting over, we still have the same Domains and Recipients tables, but now domain-based reports are driven from objects that look like these:&lt;/p&gt;

&lt;blockquote&gt;
&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;pre style="padding:10px 20px;-moz-background-clip:border;-moz-background-origin:padding;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;CREATE&amp;nbsp;TABLE&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.Deliveries&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;(&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;MessageID&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;RecipientID&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;DomainID&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;INT&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;EventDate &lt;/font&gt;&lt;font color="blue"&gt;SMALLDATETIME&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="green"&gt;/*&amp;nbsp;,&amp;nbsp;...&amp;nbsp;other&amp;nbsp;columns&amp;nbsp;...&amp;nbsp;*/&lt;br&gt;&lt;/font&gt;&lt;font color="gray"&gt;);&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;GO&lt;br&gt;&lt;br&gt;CREATE&amp;nbsp;VIEW&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.vMessageDomainDeliveries&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;WITH SCHEMABINDING&lt;/font&gt;&lt;font color="black"&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;AS&lt;br&gt;&amp;nbsp;&amp;nbsp;SELECT&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;MessageID&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;DomainID&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;c = &lt;font color="magenta"&gt;COUNT_BIG&lt;/font&gt;&lt;/font&gt;&lt;font color="gray"&gt;(*)&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;FROM&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.Deliveries&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;GROUP&amp;nbsp;BY&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;MessageID&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;DomainID&lt;/font&gt;&lt;font color="gray"&gt;;&lt;br&gt;&lt;/font&gt;&lt;font&gt;&lt;font&gt;&lt;font&gt;&lt;font color="blue"&gt;GO&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;br&gt;&lt;font color="black"&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;CREATE&amp;nbsp;UNIQUE&amp;nbsp;CLUSTERED&amp;nbsp;INDEX&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;md&lt;br&gt;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="blue"&gt;ON&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;dbo.vMessageDomainDeliveries&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;MessageID&lt;/font&gt;&lt;font color="gray"&gt;,&amp;nbsp;&lt;/font&gt;&lt;font color="black"&gt;DomainID&lt;/font&gt;&lt;font color="gray"&gt;);&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;The up-front cost of calculating the domain of each recipient during insert is likely very equivalent to the system doing the same lookup while maintaining the indexed view (except we can use snapshot isolation in our query, but can't really enforce the same during clustered index updates).&amp;nbsp; And in addition to no longer causing blocking on updates to the recipients table, we also get a much more accurate representation of history: the delivery is marked with the domain the recipient had on that day, since their e-mail address could have changed 20 times since then.&amp;nbsp; All in all it has turned out that storing the domain information multiple times has helped contribute to making a very busy system suddenly seem almost idle.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;The primary lesson learned here: indexed views can be a very helpful tool in your arsenal, but they can bring you down if you try to over-use them.&amp;nbsp; Another lesson learned: do not assume that redundancy is the devil.&amp;nbsp; It can help out in many scenarios, even if it feels a little dirty.&lt;br&gt;&lt;/p&gt;</description></item><item><title>Connect Digest : 2009-10-30</title><link>http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/30/connect-digest-2009-10-30.aspx</link><pubDate>Fri, 30 Oct 2009 15:50:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:18245</guid><dc:creator>AaronBertrand</dc:creator><description>&lt;p&gt;Light helping this week.&amp;nbsp; I am busy closing out a few projects (or at least chapters within projects) in preparation for PASS next week.&lt;/p&gt;&lt;p&gt;&lt;br&gt;========================================&lt;br&gt;

&lt;br&gt;
&lt;a href="http://connect.microsoft.com/SQL/feedback/ViewFeedback.aspx?FeedbackID=506453" title="http://connect.microsoft.com/SQL/feedback/ViewFeedback.aspx?FeedbackID=506453" target="_blank"&gt;#506453 : Lock escalation no longer kicks in for INSERTs in SQL Server 2008&lt;/a&gt; &lt;/p&gt;&lt;p&gt;Adam
found a nasty lock escalation bug in SQL Server 2008.&amp;nbsp; This one is
actually serious enough that it has me really hesitant about my plans
for moving to the new version in production, as we process a lot of data in bulk operations like this (loading millions of rows into staging tables, then inserting/updating existing tables). &lt;br&gt;&lt;br&gt;&lt;/p&gt;
&lt;p&gt;========================================&lt;br&gt;&lt;br&gt;&lt;a href="http://connect.microsoft.com/SQL/feedback/ViewFeedback.aspx?FeedbackID=503207" title="http://connect.microsoft.com/SQL/feedback/ViewFeedback.aspx?FeedbackID=503207" target="_blank"&gt;#503207 : Bad query plan leads to wrong results (incorrectly uses indexed view)&lt;/a&gt; &lt;/p&gt;&lt;p&gt;In this one there is an indexed view matching problem which can produce incorrect results.&amp;nbsp; The fix is in SP1 CU1, so this isn't a "go vote for this issue" mention, but rather encouragement to get up to SP1 + the latest CU (which was &lt;a href="http://support.microsoft.com/default.aspx/kb/973602" title="http://support.microsoft.com/default.aspx/kb/973602" target="_blank"&gt;Cumulative Update 4&lt;/a&gt; at the time of writing) if you're currently sitting at SP1 or lower.&lt;/p&gt;&lt;p&gt;&lt;br&gt;
========================================&lt;br&gt;
&lt;br&gt;&lt;a href="http://connect.microsoft.com/SQL/feedback/ViewFeedback.aspx?FeedbackID=504631" title="http://connect.microsoft.com/SQL/feedback/ViewFeedback.aspx?FeedbackID=504631" target="_blank"&gt;#504631 : add RAISE syntax for propagating exceptions&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQL/feedback/ViewFeedback.aspx?FeedbackID=127228" title="http://connect.microsoft.com/SQL/feedback/ViewFeedback.aspx?FeedbackID=127228" target="_blank"&gt;#127228 : Rethrow last error&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQL/feedback/ViewFeedback.aspx?FeedbackID=125719" title="http://connect.microsoft.com/SQL/feedback/ViewFeedback.aspx?FeedbackID=125719" target="_blank"&gt;#125719 : Support Reraising Of Original Error In Catch In T-SQL&lt;/a&gt;&lt;/p&gt;&lt;p&gt;A lot of people want RERAISE() and/or RETHROW() among other enhancements to error
handling.&amp;nbsp; They are definitely looking at these changes for future
versions of SQL Server, so have your opinion heard!&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Connect digest : 2009-07-04</title><link>http://sqlblog.com/blogs/aaron_bertrand/archive/2009/07/04/connect-digest-2009-07-04.aspx</link><pubDate>Sat, 04 Jul 2009 14:07:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15084</guid><dc:creator>AaronBertrand</dc:creator><description>&lt;p&gt;I know most readers are out polishing their grills, buying hamburger buns and preparing potato and macaroni salads.&amp;nbsp; I am recovering from a pre-4th party, so here I am, groggy and online, finally not the host of Independence Day madness.&amp;nbsp; :-) &lt;/p&gt;&lt;p&gt;This week I only have a few entries for the Connect digest:&lt;/p&gt;&lt;p&gt;=================================&lt;/p&gt;&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=471201" title="http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=471201" target="_blank"&gt;#471201 : Incorrect query results with Enterprise edition indexed view substitution and NULL usage.&lt;br&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt;This is a new one filed this past week, which Microsoft believes they have fixed, in spite of the fact that several other people, myself included, have confirmed that it still exists in current builds.&amp;nbsp; It is also an issue in SQL Server 2005, which they fail to acknowledge.&lt;/p&gt;&lt;p&gt;=================================&lt;/p&gt;&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=472439" title="http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=472439" target="_blank"&gt;#472439 : Indexed View create via CREATE SCHEMA statement can produce error 8646 during updates&lt;/a&gt; &lt;br&gt;&lt;/p&gt;&lt;p&gt;Another indexed view issue filed yesterday, and also involving NULLs, in this item the submitter shows how a simple indexed view with two rows can succumb to the 8646 error (unable to find index entry) and the ominous:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;font face="courier new,courier"&gt;Msg 0, Level 20, State 0, Line 0&lt;br&gt;A severe error occurred on the current command. The results, if any, should be discarded. &lt;br&gt;&lt;/font&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;=================================&lt;/p&gt;&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=257502%20" title="http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=257502 " target="_blank"&gt;#257502 : Deprecation of sysprocesses - DMV's doesn't fully replace all columns&lt;/a&gt;&lt;/p&gt;&lt;p&gt;This is one that many of us have been complaining about since 2005 was released : because sys.dm_exec_requests only shows *active* sessions, and it is the primary place to obtain database context, it is very cumbersome to get database context for sessions that are not currently performing work.&amp;nbsp; You also can't easily get the open transaction count from the new DMVs.&amp;nbsp; This information was readily available in sysprocesses, of course, though we have been told that we should stop using this system table (actually now a backward-compatibility view) in favor of the new views.&amp;nbsp; But Microsoft simply can't deprecate sysprocesses until they duplicate its functionality elsewhere.&lt;br&gt;&lt;/p&gt;&lt;p&gt;=================================&lt;/p&gt;
&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=472266" title="http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=472266" target="_blank"&gt;#472266 : Install fails when choosing a path for tempdb two folders deep&lt;/a&gt; &lt;br&gt;&lt;/p&gt;&lt;p&gt;This was an interesting one filed this week, where installation of SQL Server 2008 fails if you specify a folder for tempdb that contains the name "tempdb" (which is certainly a valid approach).&amp;nbsp; The submitter did not get the symptom right; they think it has something to do with the number of folders in the path, but it is still an issue that Microsoft should look at.&lt;br&gt;&lt;/p&gt;&lt;p&gt;=================================&lt;/p&gt;

&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=472518" title="http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=472518" target="_blank"&gt;SQL Management Studio 2008 - enter Data Type of datetimeoffset(0) reverts to datetimeoffset(7)&lt;/a&gt;&lt;/p&gt;&lt;p&gt;More issues with the table designer... it's like a never-ending stream of scenarios that weren't tested or were deemed "good enough."&amp;nbsp; This time someone noticed that when you tab out of a DATETIMEOFFSET column's data type, after having changed the precision to 0, it reverts to 7.&amp;nbsp; Some related Connect items: &lt;/p&gt;&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=333445" title="http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=333445" target="_blank"&gt;#333445 : SSMS 2005 - Bug Table Designer substitues its own length , loses user input on changing data types &lt;/a&gt;&lt;/p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=366117" title="http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=366117" target="_blank"&gt;#366117 : RTM, SSMS: changing precision on datetime2 from default in table designer reverts back to 7 &lt;/a&gt;&lt;br&gt;&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=124872%20" title="http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=124872 " target="_blank"&gt;#124872 : Table Designer does not support newSequentialId()&lt;/a&gt;&lt;/p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=362699" title="http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=362699" target="_blank"&gt;#362699 : 2008 RTM, SSMS/Engine: Table designer doesn't script WHERE clause in filtered indexes&lt;/a&gt;&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=124658" title="http://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=124658" target="_blank"&gt;#124658 : SSMS Table Designer adds unwanted default to uniqueidentifier column&lt;br&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt;=================================&lt;/p&gt;&lt;p&gt;Sorry I couldn't collate more this week, but as New England is seeing the sun for the first time in weeks, I really feel the need to go out and enjoy the holiday!&lt;br&gt;&lt;/p&gt;</description></item></channel></rss>