FIX: Incorrect results when a complex update query uses the JOIN operator in an execution plan in SQL Server 2008 or in SQL Server 2008 R2

Applies to: SQL Server 2008 EnterpriseSQL Server 2008 DeveloperSQL Server 2008 Standard

Microsoft distributes Microsoft SQL Server 2008 or Microsoft SQL Server 2008 R2 fixes as one downloadable file. Because the fixes are cumulative, each new release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2008 or SQL Server 2008 R2 fix release.

Symptoms


When you run a complex update query that uses the JOIN operator in an execution plan in Microsoft SQL Server 2008 or in Microsoft SQL Server 2008 R2, you may receive incorrect results.

Note The update query might contain subqueries, aggregate functions, and the DISTINCT clause.

If you run the same query in Microsoft SQL Server 2008 or in Microsoft SQL Server 2008 R2 Parallel Data Warehouse, you may receive another set of incorrect results. For example, you might receive incorrect results when you run the following code:
UPDATE RB SET rb1 = (SELECT AVG(DISTINCT T2_1.C1) AS C1 FROM (SELECT DISTINCT T3_1.C3 AS C1, T3_1.C5 AS C2 FROM (SELECT T5_1.c2 AS C1, T5_1.c2 AS C2, T5_1.c3 AS C3, T5_1.c3 AS C4, T5_1.c2 AS C5 FROM DC AS T5_1 UNION SELECT T5_1.c2 AS C1, T5_1.c3 AS C2, T5_1.c2 AS C3, T5_1.c2 AS C4, T5_1.c3 AS C5 FROM DC AS T5_1) AS T3_1) AS T2_1 WHERE (T2_1.C1 = rb3)), rb2 = (SELECT COUNT_BIG(DISTINCT T2_1.C1) AS C1 FROM (SELECT DISTINCT T3_1.C1 AS C1 FROM (SELECT T5_1.rc2 AS C1 FROM RC AS T5_1 UNION ALL SELECT T5_1.c3 AS C1 FROM DC AS T5_1) AS T3_1) AS T2_1 WHERE (T2_1.C1 > rb1)), rb3 = (SELECT COUNT_BIG(*) AS C1 FROM (SELECT DISTINCT T3_1.C1 AS C1, T3_1.C2 AS C2, T3_1.C3 AS C3, T3_1.C4 AS C4, T3_1.C5 AS C5, T3_1.C6 AS C6, T3_1.C7 AS C7, T3_1.C8 AS C8, T3_1.C9 AS C9, T3_1.C10 AS C10 FROM (SELECT T5_1.b2 AS C1, T5_1.b1 AS C2, T5_1.b3 AS C3, T5_1.b2 AS C4, T5_1.b2 AS C5, T5_1.b2 AS C6, T5_1.b2 AS C7, T5_1.b1 AS C8, T5_1.b2 AS C9, T5_1.b3 AS C10 FROM DB AS T5_1 UNION SELECT T5_1.ra3 AS C1, T5_1.ra3 AS C2, T5_1.ra3 AS C3, T5_1.ra3 AS C4, T5_1.ra2 AS C5, T5_1.ra3 AS C6, T5_1.ra1 AS C7, T5_1.ra1 AS C8, T5_1.ra1 AS C9, T5_1.ra1 AS C10 FROM RA AS T5_1) AS T3_1) AS T2_1 WHERE (T2_1.C2 <= rb3)) WHERE rb1 IN (SELECT T2_1.C1 AS C1 FROM (SELECT T4_1.a2 AS C1, T4_1.a1 AS C2, T4_1.a1 AS C3, T4_1.a2 AS C4, T4_1.a1 AS C5, T4_1.a2 AS C6, T4_1.a3 AS C7, T4_1.a1 AS C8 FROM DA AS T4_1 WHERE (T4_1.a1 > (SELECT MIN(DISTINCT T5_1.b3) AS C1 FROM DB AS T5_1 WHERE (T5_1.b3 <= T4_1.a1))) UNION ALL SELECT T4_1.a2 AS C1, T4_1.a2 AS C2, T4_1.a1 AS C3, T4_1.a1 AS C4, T4_1.a1 AS C5, T4_1.a1 AS C6, T4_1.a1 AS C7, T4_1.a3 AS C8 FROM DA AS T4_1) AS T2_1);

Cause


This issue occurs because of an error in the SQL Server query optimizer.

Resolution


Cumulative update information

SQL Server 2008 Service Pack 2

The fix for this issue was first released in Cumulative Update 6 for SQL Server 2008 Service Pack 2. For more information about this cumulative update package, click the following article number to view the article in the Microsoft Knowledge Base:
2582285 Cumulative update package 6 for SQL Server 2008 Service Pack 2
Note Because the builds are cumulative, each new fix release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2008 fix release. Microsoft recommends that you consider applying the most recent fix release that contains this hotfix. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
2402659 The SQL Server 2008 builds that were released after SQL Server 2008 Service Pack 2 was released
Microsoft SQL Server 2008 hotfixes are created for specific SQL Server service packs. You must apply a SQL Server 2008 Service Pack 2 hotfix to an installation of SQL Server 2008 Service Pack 2. By default, any hotfix that is provided in a SQL Server service pack is included in the next SQL Server service pack.

SQL Server 2008 R2

The fix for this issue was first released in Cumulative Update 9. For more information about how to obtain this cumulative update package for SQL Server 2008 R2, click the following article number to view the article in the Microsoft Knowledge Base:
2567713 Cumulative Update package 9 for SQL Server 2008 R2
Note Because the builds are cumulative, each new fix release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2008 R2 fix release. We recommend that you consider applying the most recent fix release that contains this hotfix. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
981356 The SQL Server 2008 R2 builds that were released after SQL Server 2008 R2 was released

SQL Server 2008 R2 Service Pack 1

The fix for this issue was first released in Cumulative Update 2 for SQL Server 2008 R2 Service Pack 1. For more information about how to obtain this cumulative update package, click the following article number to view the article in the Microsoft Knowledge Base:
2567714 Cumulative Update package 2 for SQL Server 2008 R2 Service Pack 1
Note Because the builds are cumulative, each new fix release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2008 R2 fix release. We recommend that you consider applying the most recent fix release that contains this hotfix. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
2567616 The SQL Server 2008 R2 builds that were released after SQL Server 2008 R2 Service Pack 1 was released

SQL Server 2008 Service Pack 1

The fix for this issue was first released in Cumulative Update 15 for SQL Server 2008 Service Pack 1. For more information about this cumulative update package, click the following article number to view the article in the Microsoft Knowledge Base:
2555406 Cumulative update package 15 for SQL Server 2008 Service Pack 1
Note Because the builds are cumulative, each new fix release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2008 fix release. Microsoft recommends that you consider applying the most recent fix release that contains this hotfix. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
970365 The SQL Server 2008 builds that were released after SQL Server 2008 Service Pack 1 was released
Microsoft SQL Server 2008 hotfixes are created for specific SQL Server service packs. You must apply a SQL Server 2008 Service Pack 1 hotfix to an installation of SQL Server 2008 Service Pack 1. By default, any hotfix that is provided in a SQL Server service pack is included in the next SQL Server service pack.


Status


Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

References


For more information about Parallel Data Warehouse, visit the following Microsoft website:For more information about the Incremental Servicing Model for SQL Server, click the following article number to view the article in the Microsoft Knowledge Base:
935897 An Incremental Servicing Model is available from the SQL Server team to deliver hotfixes for reported problems
For more information about the naming schema for SQL Server updates, click the following article number to view the article in the Microsoft Knowledge Base:
822499 New naming schema for Microsoft SQL Server software update packages
For more information about software update terminology, click the following article number to view the article in the Microsoft Knowledge Base:
824684 Description of the standard terminology that is used to describe Microsoft software updates