March 30, 2004 at 3:48 pm
A developer's proc is bottlenecking in production. The statement that seems to hang for 30 seconds is a DECLARE CURSOR on a temp (#) table. The #table is 63 rows, and the query is SELECT DISTINCT (integer_col) FROM #table ORDER BY integer_col.
Are there any special gotchas about DECLARE CURSOR?
I intend to see if there is other contention going on, but it should not be locks as it is his own session #table. Perhaps a tempdb issue...
Thanks,
Larry
Larry
March 30, 2004 at 11:56 pm
replace the "distinct" with a "group by" if you can, it might get index-only access, whilest distinct is an extra passthroug of the resultset .
- http://www.sql-server-performance.com/cursors.asp
- http://www.sql-server-performance.com/dp_no_cursors.asp
- http://www.sqlservercentral.com/articles/articlesexternal.asp?articleid=477
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
March 31, 2004 at 1:50 am
Even better....STAY AWAY from cursors....good performance and cursors rarely go in the same statement.
99.99% of database actions can be done without cursors.
Cursors really are only needed when a calculation on 1 row affects the calculation for the next in the same dataset.....like generating sequence numbers...(and even that can have a non-cursor solution)
An analogy i've seen before to describe cursors....is that they are like using tweezers to put grains of sugar into a cup of tea...instead of using a spoon. The task is achieveable, but horrible!
Post the code....sample table structures, sampel data and a description of what is being attempted to be achieved and 90%+ chance there is a better non-cursors solution available.
April 5, 2004 at 7:33 am
Cursors are bad business. You can select into a temp table and then run a While .... Begin ..... End statement with far superior results.
April 9, 2004 at 6:54 am
Huh?
I thought you could only loop through a table with a cursur. Could you post some sample code?
Bob
SuccessWare Software
April 9, 2004 at 7:17 am
http://www.sql-server-performance.com/dp_no_cursors.asp
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
April 9, 2004 at 7:54 am
Thank you very much!!!
Bob
SuccessWare Software
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply