FIX: Cursor Overhead Higher on SQL Server 7.0 for Small Result Sets

ID: Q197800


The information in this article applies to:

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:

Q168678 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 version 6.5. This problem has been corrected in U.S. Service Pack for Microsoft SQL Server version 6.5. For information about downloading and installing the latest SQL Server Service Pack, see http://support.microsoft.com/support/sql/.

For more information, contact your primary support provider.

Microsoft has confirmed this to be a problem in SQL Server version 7.0. This problem has been corrected in U.S. Service Pack 1 for Microsoft SQL Server version 7.0. For information about downloading and installing the latest SQL Server Service Pack, see http://support.microsoft.com/support/sql/.

For more information, contact your primary support provider.

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


Keywords          : kbbug6.50 kbbug7.00 kbfix6.50.SP5 
Version           : winnt:6.5,7.0
Platform          : winnt 
Issue type        : kbbug 

Last Reviewed: June 7, 1999