<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www2.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>Incorrect Results with Indexed Views</title><link>http://www2.sqlblog.com/blogs/paul_white/archive/2013/02/06/incorrect-results-with-indexed-views.aspx</link><description>Summary: If you use MERGE, indexed views and foreign keys, your queries can return incorrect results. Microsoft have released a fix for incorrect results returned when querying an indexed view. The problem applies to: SQL Server 2012 SQL Server 2008 R2</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>re: Incorrect Results with Indexed Views</title><link>http://www2.sqlblog.com/blogs/paul_white/archive/2013/02/06/incorrect-results-with-indexed-views.aspx#47501</link><pubDate>Tue, 05 Feb 2013 22:32:31 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47501</guid><dc:creator>jamiet</dc:creator><description>&lt;p&gt;Paul, you are on another planet. Awesome post - great detective work!&lt;/p&gt;
</description></item><item><title>re: Incorrect Results with Indexed Views</title><link>http://www2.sqlblog.com/blogs/paul_white/archive/2013/02/06/incorrect-results-with-indexed-views.aspx#47502</link><pubDate>Tue, 05 Feb 2013 22:35:24 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47502</guid><dc:creator>Rob Farley</dc:creator><description>&lt;p&gt;I keep meaning to find the time to update that Join Simplification post. It's been a lot of years since I wrote about it, and I don't even tend to give that talk any more either.&lt;/p&gt;
</description></item><item><title>re: Incorrect Results with Indexed Views</title><link>http://www2.sqlblog.com/blogs/paul_white/archive/2013/02/06/incorrect-results-with-indexed-views.aspx#47503</link><pubDate>Tue, 05 Feb 2013 22:41:24 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47503</guid><dc:creator>Paul White</dc:creator><description>&lt;p&gt;@Jamie You're welcome, thanks for tweeting about the problem - that got me interested!&lt;/p&gt;
&lt;p&gt;@Rob I always think of your post whenever this simplification thing comes up. One of my all-time favourites, as you know.&lt;/p&gt;
</description></item><item><title>re: Incorrect Results with Indexed Views</title><link>http://www2.sqlblog.com/blogs/paul_white/archive/2013/02/06/incorrect-results-with-indexed-views.aspx#47511</link><pubDate>Wed, 06 Feb 2013 05:34:17 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47511</guid><dc:creator>Boris Hristov</dc:creator><description>&lt;p&gt;Is it only me that can see this:&lt;/p&gt;
&lt;p&gt;&amp;quot;Updates the value column of parent row 1 from Apple to Kiwi Fruit&lt;/p&gt;
&lt;p&gt;Adds a new parent row 4 for Dragon Fruit&amp;quot;&lt;/p&gt;
&lt;p&gt;in the first screenshot of what data is inside the table dbo.Parents. I cannot see anywhere a record for Apple. &lt;/p&gt;
&lt;p&gt;Paul, am I correct?&lt;/p&gt;</description></item><item><title>re: Incorrect Results with Indexed Views</title><link>http://www2.sqlblog.com/blogs/paul_white/archive/2013/02/06/incorrect-results-with-indexed-views.aspx#47512</link><pubDate>Wed, 06 Feb 2013 06:31:07 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47512</guid><dc:creator>Paul White</dc:creator><description>&lt;p&gt;Hi Boris,&lt;/p&gt;
&lt;p&gt;No it wasn't just you. The T-SQL script was correct, but I must have pasted the wrong screenshot at some stage. Corrected now, thanks for pointing that out.&lt;/p&gt;
&lt;p&gt;Paul&lt;/p&gt;
</description></item><item><title>NOEXPAND query hint returns wrong results – CU fix now available</title><link>http://www2.sqlblog.com/blogs/paul_white/archive/2013/02/06/incorrect-results-with-indexed-views.aspx#47513</link><pubDate>Wed, 06 Feb 2013 09:01:18 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47513</guid><dc:creator>SSIS Junkie</dc:creator><description>&lt;p&gt;Three days ago at my current gig we stumbled across a problem where use of the NOEXPAND query hint was&lt;/p&gt;</description></item><item><title>re: Incorrect Results with Indexed Views</title><link>http://www2.sqlblog.com/blogs/paul_white/archive/2013/02/06/incorrect-results-with-indexed-views.aspx#47519</link><pubDate>Wed, 06 Feb 2013 21:53:22 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47519</guid><dc:creator>tobi</dc:creator><description>&lt;p&gt;The MERGE statement strikes again.&lt;/p&gt;</description></item><item><title>re: Incorrect Results with Indexed Views</title><link>http://www2.sqlblog.com/blogs/paul_white/archive/2013/02/06/incorrect-results-with-indexed-views.aspx#47537</link><pubDate>Thu, 07 Feb 2013 17:46:31 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47537</guid><dc:creator>AlexK</dc:creator><description>&lt;p&gt;This is awesome research, Paul!&lt;/p&gt;
&lt;p&gt;I guess you could do your research in a fraction of the time if the source code was available, so that you could just debug right through. If that were the case, we might have fixed this problem already. Peer reviews are very good for product quality.&lt;/p&gt;
&lt;p&gt;I'm using MERGE less and less. It has too many problems. I am not sure we know them all. This does not smell good. I do not want my users to discover yet another bug in MERGE, which will ruin their day and my weekend or vacation. In some cases a DELETE followed by an INSERT even performs better.&lt;/p&gt;</description></item><item><title>re: Incorrect Results with Indexed Views</title><link>http://www2.sqlblog.com/blogs/paul_white/archive/2013/02/06/incorrect-results-with-indexed-views.aspx#47540</link><pubDate>Thu, 07 Feb 2013 18:18:10 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47540</guid><dc:creator>Paul White</dc:creator><description>&lt;p&gt;Tobi and Alex,&lt;/p&gt;
&lt;p&gt;Yes, it's all rather sad. Every time I revisit MERGE and begin to warm to it, another problem comes up. Many of the past bugs have been edge cases that not too many people would encounter, but this one requires only foreign keys and an indexed view - not an uncommon combination at all!&lt;/p&gt;
&lt;p&gt;Paul&lt;/p&gt;</description></item><item><title>re: Incorrect Results with Indexed Views</title><link>http://www2.sqlblog.com/blogs/paul_white/archive/2013/02/06/incorrect-results-with-indexed-views.aspx#47575</link><pubDate>Thu, 07 Feb 2013 22:53:44 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47575</guid><dc:creator>AlexK</dc:creator><description>&lt;p&gt;Paul,&lt;/p&gt;
&lt;p&gt;I am not with you on the following assessment: &amp;quot;edge cases that not too many people would encounter&amp;quot;. These problems constitute a smell: they indicate that there might be something wrong with the overall quality of the feature. &lt;/p&gt;
&lt;p&gt;If we observed similar problems in an open source system, where we could access the code and automated tests, quite likely we would find that the full matrix of possible automated test cases is either missing altogether or incomplete. &lt;/p&gt;
&lt;p&gt;We could build a complete matrix of test cases, fix the exposed problems, and use the fixed feature with confidence.&lt;/p&gt;
&lt;p&gt;Beta testers that cannot read source code cannot ensure high quality, even if there are millions of them. For example, if the code does not work on the last day of a leap year, and we are beta-testing now, in 2013, we will not notice that defect no matter how many people test the black box. The bug would manifest itself on Dec 31st, 2016.&lt;/p&gt;
&lt;p&gt;On the other hand, developers can and do find such problems, and peer reviews can and do expose such things by just reading the code. In many cases this is just so very much more efficient than testing, or blindly trusting, a black box.&lt;/p&gt;</description></item><item><title>re: Incorrect Results with Indexed Views</title><link>http://www2.sqlblog.com/blogs/paul_white/archive/2013/02/06/incorrect-results-with-indexed-views.aspx#47596</link><pubDate>Fri, 08 Feb 2013 11:33:51 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47596</guid><dc:creator>Ian Yates</dc:creator><description>&lt;p&gt;Out of curiosity, if I have a corrupted table - and am unaware of it - and then apply this patch, does the corruption get fixed for me or do I still need to run the DBCC repair statement?&lt;/p&gt;</description></item><item><title>re: Incorrect Results with Indexed Views</title><link>http://www2.sqlblog.com/blogs/paul_white/archive/2013/02/06/incorrect-results-with-indexed-views.aspx#47601</link><pubDate>Fri, 08 Feb 2013 17:03:04 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47601</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;I don't think indexed views are very common. They're so limiting, and cause so many side issues, that I think they drive a lot of people away.&lt;/p&gt;
&lt;p&gt;That said, agreed wholeheartedly with Alex, this is an indicator that the entire feature was badly designed. And it really makes no sense from an outsider perspective. &lt;/p&gt;
&lt;p&gt;If you imagine how you might implement an index update, there would be some central method (overloaded, naturally), and all the updates would go through there. It would control things like subsequent updates to indexed views, etc. Enforcement of constraints, perhaps. There would be no way around these things, because it would all be centrally handled. There would be no choice.&lt;/p&gt;
&lt;p&gt;But that's clearly not how this feature has been implemented, and it's scary to imagine the spaghetti code that must exist in core parts of the engine. What other bugs are lying in wait?&lt;/p&gt;
</description></item><item><title>re: Incorrect Results with Indexed Views</title><link>http://www2.sqlblog.com/blogs/paul_white/archive/2013/02/06/incorrect-results-with-indexed-views.aspx#47602</link><pubDate>Fri, 08 Feb 2013 17:37:50 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47602</guid><dc:creator>Paul White</dc:creator><description>&lt;p&gt;Hi Ian,&lt;/p&gt;
&lt;p&gt;That's a great question! I haven't tried it myself, yet, but my expectation is that the fix only prevents future corruptions caused by an incorrect update plan. I would be amazed if it did more than that (but I have been wrong before). That's another detail missing from the KB :)&lt;/p&gt;
&lt;p&gt;The safest thing to do (it seems to me) is to test and apply the hotfix, and then either rebuild all indexed views manually or run DBCC CHECKDB with the EXTENDED_LOGICAL_CHECKS option - something which could take quite a long time, incidentally.&lt;/p&gt;
&lt;p&gt;Paul&lt;/p&gt;
</description></item><item><title>re: Incorrect Results with Indexed Views</title><link>http://www2.sqlblog.com/blogs/paul_white/archive/2013/02/06/incorrect-results-with-indexed-views.aspx#47617</link><pubDate>Sat, 09 Feb 2013 12:58:32 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47617</guid><dc:creator>tobi</dc:creator><description>&lt;p&gt;Adam,&lt;/p&gt;
&lt;p&gt;I wish indexed views had less limitations (like LEFT JOINs being unsupported) and could be stacked. That would be very powerful in OLTP. Joins without runtime cost, just disk, buffer pool and DML cost.&lt;/p&gt;</description></item><item><title>re: Incorrect Results with Indexed Views</title><link>http://www2.sqlblog.com/blogs/paul_white/archive/2013/02/06/incorrect-results-with-indexed-views.aspx#47628</link><pubDate>Sun, 10 Feb 2013 20:23:26 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47628</guid><dc:creator>Paul White</dc:creator><description>&lt;p&gt;I doubt we will ever see indexed views that can be stacked, or which allow outer joins, despite the fact that Microsoft Research have published papers showing that they have built code for this and tested it in SQL Server.&lt;/p&gt;
&lt;p&gt;There might be other reasons, but I suspect Microsoft see more general technologies like column-store (for DW) and Hekaton (for OLTP) as being better solutions, in that they are more general and perhaps easier to implement. There's a bit of text about Hekaton here: &lt;a rel="nofollow" target="_new" href="http://research.microsoft.com/en-us/news/features/hekaton-122012.aspx"&gt;http://research.microsoft.com/en-us/news/features/hekaton-122012.aspx&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Incorrect Results with Indexed Views</title><link>http://www2.sqlblog.com/blogs/paul_white/archive/2013/02/06/incorrect-results-with-indexed-views.aspx#47631</link><pubDate>Sun, 10 Feb 2013 22:21:16 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47631</guid><dc:creator>tobi</dc:creator><description>&lt;p&gt;The public link to the paper is broken. Here is an alternate one I discovered: &lt;a rel="nofollow" target="_new" href="http://research.microsoft.com/pubs/170384/bw-tree.pdf"&gt;http://research.microsoft.com/pubs/170384/bw-tree.pdf&lt;/a&gt;&lt;/p&gt;</description></item><item><title>re: Incorrect Results with Indexed Views</title><link>http://www2.sqlblog.com/blogs/paul_white/archive/2013/02/06/incorrect-results-with-indexed-views.aspx#47755</link><pubDate>Sat, 16 Feb 2013 09:46:13 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47755</guid><dc:creator>Paul White</dc:creator><description>&lt;p&gt;Thanks, Tobi!&lt;/p&gt;
</description></item></channel></rss>