Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / DB Engine / SQL Server / March 2008

Tip: Looking for answers? Try searching our database.

Poor performance when using Transact SQL cursor

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ErikE - 14 Mar 2008 13:56 GMT
After a recent upgrade from SQL Server 2000 to SQL Server 2005, we get
problems with certain queries using a Transact SQL cursor.
I have noticed the following:
Table with a smaller number of rows.
declare cursor completes normally.
open cursor completes normally
fetch cursor retrieves the first row from the table.

Table with a larger number of rows.
declare cursor completes normally.
open cursor builds a temporary table with information about all the rows
matching the seek conditions. (This can take some time, depending on the
number of rows)
fetch cursor retrives a row from the table, based on values from the first
row in the temporary table.

This behaviour is undesirable because the application may cancel the current
query, do something else and start a new query on the same table. This
creates a lot of overhead.

I have done several tests, and I am sure that the change in behaviour is not
governed by the number of rows returned, but solely on the number of rows in
the table. Setting the conditions such that now rows will meet the conditions
will still show execute as described above.

Can anyone tell me why it has changed, and how I can get the "old" behaviour
back, or just point me to a place where it is described.

Thanks in advance.
Tom Moreau - 14 Mar 2008 14:42 GMT
Did you remember to update stats on all tables with FULLSCAN when you did
the migration?  Also, do you really need a cursor to do what you need?

Signature

  Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON   Canada
https://mvp.support.microsoft.com/profile/Tom.Moreau

After a recent upgrade from SQL Server 2000 to SQL Server 2005, we get
problems with certain queries using a Transact SQL cursor.
I have noticed the following:
Table with a smaller number of rows.
declare cursor completes normally.
open cursor completes normally
fetch cursor retrieves the first row from the table.

Table with a larger number of rows.
declare cursor completes normally.
open cursor builds a temporary table with information about all the rows
matching the seek conditions. (This can take some time, depending on the
number of rows)
fetch cursor retrives a row from the table, based on values from the first
row in the temporary table.

This behaviour is undesirable because the application may cancel the current
query, do something else and start a new query on the same table. This
creates a lot of overhead.

I have done several tests, and I am sure that the change in behaviour is not
governed by the number of rows returned, but solely on the number of rows in
the table. Setting the conditions such that now rows will meet the
conditions
will still show execute as described above.

Can anyone tell me why it has changed, and how I can get the "old" behaviour
back, or just point me to a place where it is described.

Thanks in advance.
ErikE - 17 Mar 2008 11:35 GMT
I have remembered to update stats. Cursors are only used in older
applications, so the problem is just to avoid spending time rewriting these
applications.

> Did you remember to update stats on all tables with FULLSCAN when you did
> the migration?  Also, do you really need a cursor to do what you need?
[quoted text clipped - 29 lines]
>
> Thanks in advance.
Linchi Shea - 15 Mar 2008 04:50 GMT
What kind of cursor did you declare?

Linchi

> After a recent upgrade from SQL Server 2000 to SQL Server 2005, we get
> problems with certain queries using a Transact SQL cursor.
[quoted text clipped - 25 lines]
>
> Thanks in advance.
Mahmoud Amin - 16 Mar 2008 11:04 GMT
I have the same problem,

i updated the statistics and nothing. it gives "Transaction ended by
trigger"

it works fine on SQL 2000 with no problem.

I am using Forward Only and Read Only Cursor.

> What kind of cursor did you declare?
>
[quoted text clipped - 35 lines]
>>
>> Thanks in advance.
ErikE - 17 Mar 2008 11:30 GMT
I tried the different types according to the transact-sql extended syntax,
all with the same result.

> What kind of cursor did you declare?
>
[quoted text clipped - 29 lines]
> >
> > Thanks in advance.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.