June 28, 2006 at 1:07 pm
I have an sp that truncs a table and then inserts new rows. The sp takes over 2 minutes to insert about 80,000 rows while the same code in query analyzer takes just a few seconds. I cleared the proc cache (dbcc FreeProcCache) but this did not help. Does any one have any suggestions as to what the problem might be?
Thanks in advance.
June 28, 2006 at 1:17 pm
Not enough info.
What is the source of the inserted rows ? A join of 2 or more tables ? Are there input parameters to the stored prcoedure that are used to filter the rows being inserted ?
June 28, 2006 at 1:24 pm
the sql is very straight forward:
Truncate TableName
insert into TableName (FieldList)
Select Fields
From TableA a
Join TableB b on a.Acct_id = b.Acct_id
The sql being run in query analyzer is identical to that in the sp. There are no input parameters being passed, no additional filtering.
June 29, 2006 at 1:54 am
Do you run only SELECT in QA or INSERT?
How many indexes you have on the table being inserted?
What are the fill factors on them?
Is it used intensively for selects?
_____________
Code for TallyGenerator
June 29, 2006 at 3:38 am
Is the execution plan the same for both runs?
The truncate may cause a re-compilation of the SP.
June 29, 2006 at 6:06 am
wouldn't the sp need to be recompiled after the table is truncated, as the previous executtion plan would probably be invalid? i would think the proc is slow because of a bad execution plan.
i'd think that forcing a recompile on the proc would be desired:
create proc pr_procname with recompile as ....
i'd suggest calling a separate proc from within the stored proc instead:
create proc pr_innerproc as
insert into TableName (FieldList)
Select Fields
From TableA a
Join TableB b on a.Acct_id = b.Acct_id
GO
create proc pr_procname as
Truncate TableName
exec pr_innerproc
Lowell
June 29, 2006 at 8:24 am
All of the above are good suggestion. I would add to that:
Check the connection default settings; compare them with the QA connection settings.
June 29, 2006 at 9:31 am
very good suggestions- Thanks!
Question regarding recompilig the sp- sp_recomplile 'spName' will recopile any give sp. Creating the sp with "WITH recompile" causes the sp to be recompiled each time it is run. Does dbcc FreeProcCache cause all sp's to be recompiled the next time they are run?
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply