December 14, 2010 at 10:58 am
Typical questions on migration:
- did you perform post migration actions like:
-- DBCC CHECKDB (0) WITH ALL_ERRORMSGS, DATA_PURITY;
---- kb http://support.microsoft.com/kb/923247
-- rebuild all indexes
-- update all statistics
-- dbcc updateusage
- were you able to migrate the dblevel to 100 ?
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 and code to get the best help
- 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
December 14, 2010 at 12:36 pm
Yep, did all of that.
What's really perplexing is that a new database containing just one table with just 3500 rows, on a local sql server express instance, exhibits the same slow results when fetching a cursor. I know cursors aren't the most efficient, but this behavior seems crazy to me. Even if I don't "select" the result to the screen after each fetch, it still runs forever.
December 14, 2010 at 12:38 pm
And yes, was able to go to 100.
December 14, 2010 at 12:56 pm
Can you change your 2008 c.u.r.s.o.r. * cough* declaration to use TOP 1 so you have just on path and post the actual execution plan of it together with the complete table def including index definition?
Will surely help....
December 14, 2010 at 4:53 pm
Here are the files. I included the plan for the query without the top 1 to show how different the plan is than when top 1 is used. Isn't it strange that it does a table scan for each fetch?
Thanks so much for your help!
Breck.
December 14, 2010 at 4:57 pm
Also, remember there are only 3500 rows in this table. It takes 14 seconds to fetch the 207 rows for salesman 15. Running the select statement on it's own of course takes less than a second.
December 15, 2010 at 12:01 am
One of the things I've found is that 2K8 is a whole lot less tolerant of implicit data conversions than 2K or 2K5 was. Make sure that any joins or criteria precisely match datatypes with the datatypes in the table that you're joing to or looking up in.
--Jeff Moden
Change is inevitable... Change for the better is not.
December 15, 2010 at 12:16 am
your table is a heap, so rebuilding your indexes may not give you the result you aim for.
It isn't using the index [ixcustsalesman] your created for column [id_salesman].
Can you define a clustered index for that table ?
e.g. on column [tmst_created] because that's a datetime column that - gut feeling - is sequential .
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 and code to get the best help
- 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
December 15, 2010 at 1:25 am
Two more issues from my side:
#1: Can you post the code from inside the c.u.r.s.o.r. *cough*? In most cases such a loop can be replaced with a set based solution performing waaayyy better than RBAR.
#2: If you have to use a loop, make it at least STATIC or FAST_FORWARD (I would have expected the loop using a temp table for the fetch...).
Other than that I second Johan and Jeff.
December 15, 2010 at 5:03 am
There are a number of great articles on
- cursor avoidance:
-- http://www.sqlservercentral.com/articles/T-SQL/66097/
- RBAR avoidance:
--http://www.sqlservercentral.com/articles/Performance+Tuning/62278/
attached you'll find on one slide of the presentation I gave yesterday.
It was supported by the long story of what I learned from Barry and Jeff. 😉
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 and code to get the best help
- 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
December 15, 2010 at 7:45 am
The stored procedure where this problem initially came to lite has a much more involved declare, and performs about ten pages of logic for each record fetched. I realized that if I commented out all of the logic, the procedure was still dog slow and the explain showed the craziest operations on each fetch. I also of course executed the select statement from the declare on it's own and the plan looked correct and it was fast. This entire procedure runs on demand from a vb window on the sql2k instance and there has never been an issue.
I simplified it even further for posting here by declaring a single table cursor, fetching the results, and doing nothing else. 14 seconds to fetch the ~200 records and do nothing with the results. When I run this same query on the sql2k instance, it runs instantly.
Something is seriously crazy with the fetch...almost like it thinks it doesn't have enough memory to build the result set. That of course doesn't explain why it scans the table each time when an index exists on the column used in thh where clause. It uses the index (and returns the result immediately) if you execute the select statement from QA. Heck, with 3500 rows it should easily be able to scan the table 3500 times in 14 seconds, especially since there is plenty of memory and nothing else running.
December 15, 2010 at 7:57 am
There are certain cases where cursors make a lot of sense, but I would agree never for purposes of returning a single result or a result set. They are used in our applications for things like getting a list of part numbers that may need to be orderd from a vendor, then applying 1000 lines of code to each to see how how much and from where. The overhead of the cursor is miniscule compared to the amount of logic performed for each.
But at the end of the day, even if our applications were using cursors for "bad" reasons, I wasn't expecting to have to examine and potentially re-code and test over a thousand stored procedures just to upgrade to sql 2008. Something is broken with the environment when a brand new two processor box with 16G of memory takes 14 seconds to itterate 200 records. My guess is that whatever is causing this particular behavior is also what is causing most of the other procedures to perform poorly as well.
December 15, 2010 at 7:58 am
So I'll stop asking to replace the RBAR then 😉
Did you try to declare the cursors as STATIC or FAST_FORWARD like I mentionend earlier?
December 15, 2010 at 8:05 am
- did you prepare your migration using "Microsoft SQL Server 2008 Upgrade Advisor" http://www.microsoft.com/downloads/en/details.aspx?FamilyID=f5a6c5e9-4cd9-4e42-a21c-7291e7f0f852&displaylang=en
It may point you to potential issues.
- I didn't find a gap today to actually test your case, but my gut feeling for the replies says it might even be a configuration issue.
-- can you pull IO-stats for stalls, ... ?
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 and code to get the best help
- 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
December 15, 2010 at 8:30 am
Yes, I've tried all of the cursor options to no avail. If you write a simple cursor such as mine in your sql 2008 environment and fetch through it, do you see crazy operations on each fetch, or is the overhead as on the open (as it has been in every environment I've ever worked in from DB2 to Oracle to SQL2k)?
Viewing 15 posts - 1 through 15 (of 29 total)
You must be logged in to reply to this topic. Login to reply