August 2, 2019 at 7:14 pm
Hi,
We have a stored procedure which is executing during a batch job and it is taking 7 seconds to complete and that batch job runs hours to complete. And I'm seeing this procedure called continuously during the batch job and each RPC:completed is taking 7 seconds and returing same rows
Started troubleshooting this procedure and I have noticed that this procedure has 2 views that are selected rows joining several tables.
So, is having views in stored procedures good idea? Should we make those views to permanent tables to improve the performance?
August 2, 2019 at 7:52 pm
A much better idea is to find out why the batch job is taking 7 hours. Is it actually because this stored procedure taking 7 seconds? While that may certainly appear to be the problem, I suspect that the batch job is a load of RBAR that needs to be fixed so that it doesn't have to call the stored procedure (I'm making a bit of an assumption here) once for every row or whatever in the overall batch job.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 6, 2019 at 1:25 pm
If the stored procedure is returning the same results each time, it might be worth amending it to store those results in a table that can be referred to whenever necessary. Then you only need to call the stored procedure once at the start of the job. That said, it doesn't sound as if the stored procedure and its views are the only problem (as Jeff suggested).
August 6, 2019 at 1:45 pm
There's nothing inherently wrong with views in stored procedures. However if the data from the view doesn't change during the entire batch process you might consider preloading the data into a staging table and using that in the SP instead of querying the view every time.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply