Performance may decrease when you run a query to retrieve rows from a view that is created by using a UNION operation (885715)
The information in this article applies to:
- Microsoft SQL Server 2000 (all editions)
SYMPTOMSWhen you run a query that includes the ORDER BY clause to retrieve rows from a view that is created by using a UNION operation on tables, performance may decrease. This problem occurs if a clustered index is defined on the column that you use in the ORDER BY clause.CAUSEThe query uses the merge union operation that always requests a sort operation on all the columns that are involved in a union. Therefore, a separate sort that is based on the ORDER BY clause in the query is not required. However, the query optimizer incorrectly selects an execution plan that performs an additional sort based on the ORDER BY clause. This plan is less efficient and causes the problem that is mentioned in the "Symptoms" section.WORKAROUNDTo work around this problem, you must define a unique clustered index instead of the clustered index that is defined on the ORDER BY column. Additionally, make sure that the following conditions are true: - The first column of the view must be the column where the unique clustered index is defined.
- The first column in the unique clustered index must be the ORDER BY column.
For more information about the CREATE UNIQUE CLUSTERED INDEX statement, visit the following Microsoft Web site:
Modification Type: | Major | Last Reviewed: | 10/21/2004 |
---|
Keywords: | kbprb kbPerformance kbView kbQuery kbtshoot KB885715 kbAudDeveloper |
---|
|