Knowledge Base

FIX: Cursor overhead higher in SQL Server 7.0 than in SQL Server 6.x for small result sets

Article ID: 197800

Article Last Modified on 10/27/2006


APPLIES TO


This article was previously published under Q197800
BUG #: 52979 (SQLBUG_70)

SYMPTOMS

In some cases, execution times for repetitive cursor activity on very small result sets in SQL Server 7.0 may be higher than in SQL Server 6.x.

CAUSE

The overhead of cursor operations on small result sets may be larger in SQL Server 7.0 than in SQL Server 6.x, due to query compilation times and the method used to create and manipulate the internal worktables used by the cursors. By default, cursor queries are not eligible for auto-parameterization, so each execution of a cursor opened on an ad-hoc query must incur the costs compiling the query. For additional information about cursor worktables, please see the following article in the Microsoft Knowledge Base:

168678 INF: Understanding Worktables Used by Server Side Cursors

WORKAROUND

To work around this problem, use SQLPrepare, sp_sqlexecute, or create a stored procedure for the query the cursor is being opened on. This will eliminate the compilation time for subsequent executions of the cursor and may increase performance. Please note that when using SQLPrepare, SQL Server 7.0 supports the prepare execute model directly, while SQL Server 6.x uses temporary stored procedures. For more information, see the "Preparing SQL Statements" and "Prepared Execution" topics in the SQL Server 7.0 Books Online.

From a design standpoint, if an application is repetitively opening, fetching, and closing cursors based on small result sets, consider the following:

STATUS

Microsoft has confirmed this to be a problem in SQL Server 6.5. This problem has been corrected in U.S. Service Pack for Microsoft SQL Server 6.5. For information about how to download and install the latest SQL Server Service Pack, see the following Microsoft Web site: For more information, contact your primary support provider.

Microsoft has confirmed this to be a problem in SQL Server 7.0. This problem has been corrected in U.S. Service Pack 1 for Microsoft SQL Server 7.0. For information about how to download and install the latest SQL Server Service Pack, see the following Microsoft Web site: For more information, contact your primary support provider.

Additional query words: ODBC OLEDB application slower worse upgrade resultset resultsets work table tables

Keywords: kbbug kbfix kbqfe KB197800