FIX: Regression: Compilation of Many UNIONs Takes Excessively Long Time

This article was previously published under Q274706
This article has been archived. It is offered "as is" and will no longer be updated.
BUG #: 57921 (SQLBUG_70)
Beginning with SQL Server 7.0 Service Pack 1 (build 699 and higher), the compilation of a SQL statement containing many UNIONs takes substantially longer than on the golden version (build 623).
Reduce the number of UNIONs. If possible, avoid having more than about 40 UNIONs in a single SQL statement.
Microsoft has confirmed this to be a problem in SQL Server 7.0. This problem has been corrected in U.S. Service Pack 3 for Microsoft SQL Server 7.0. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
274799 INF: How to Obtain Service Pack 3 for Microsoft SQL Server 7.0 and Microsoft Data Engine (MSDE) 1.0
For more information, contact your primary support provider.
In every version of SQL Server of course, the compilation time is proportional to the number of UNIONs in a query. However, in SQL Server 7.0 Service Pack 1 and Service Pack 2, the impact of a large number of UNIONs is dramatic. The chart below compares the time for parse and compile time (CPU) between build 623 and 699. Each subset of the UNION queries was "select * from authors".

No. of Unions204080160320
Build 623 (ms)6320362521567938
Build 699 (ms)7936019061257896156
slow aggregate view regression runtime query

Article ID: 274706 - Last Review: 02/28/2014 00:33:33 - Revision: 5.1

Microsoft SQL Server 7.0 Service Pack 1, Microsoft SQL Server 7.0 Service Pack 2

  • kbnosurvey kbarchive kbbug kbfix KB274706