August 9, 2007 at 7:27 am
Hi,
has anyone ever encountered this problem where they have a stored procedure which runs perfectly fine the first time you run it(takes 14 seconds) but say if i try and run it again afterwards (i.e. 2 mins or 2 hours later) it seems to get stuck in a loop and i have to cancel the job and then start it again which basically means the job is useless.
The stored procedure its running is simply updating a view.
Any ideas?
kind regards
August 9, 2007 at 7:52 am
Does your stored procedure have parameters, and if so, are you passing different parameters in the second time? It's always helpful if you post your code, by the way.
John
August 9, 2007 at 7:58 am
Haven't seen that, but there are possibilities for what's wrong. WITH CHECK in the view definition, data changes, etc.
Can you post some code? Is there looping in the view?
August 9, 2007 at 8:10 am
The stored procedure itself simply updates a column with a corresponding column in the view ala...
UPDATE vw_CostPriceUpdate_Update
SET Cost =[UK Cost]
thats all the sp does.
the strange thing is that this works fine on another server with the only difference i can see so far is that under current activity in the locks/proccesses id the one which isn't working creates a new process an additional process to handle running the tempdb database however on the server that works it runs this tempdb database process within the same process as the update procedure is called.
And my first thought was that after the first instance it wasn't deleting all the locks it made after it finished but it is.
August 9, 2007 at 8:22 am
Also if iw as to just run a really basic stored procedure ala...
print 'hello'
or write to the events log
then this would work fine.
August 9, 2007 at 1:01 pm
it looks like you are actually updating a view, rather than directly accessing the underlying tables:
UPDATE vw_CostPriceUpdate_Update
SET Cost =[UK Cost]
if you do sp_helptext vw_CostPriceUpdate_Update, i bet the definition is a bit more complex, and is the cause of your problem.
if the statistics are outdated on the production box, but not on the other server as you noted, you'd probably see a performance hit, as the executaion plan might be outdated due to statistics.
you would problalby be able to directly update one of the underlying tables of the view to avoid the performance hit of the updatable view.
Lowell
August 9, 2007 at 2:30 pm
Good catch, Lowell...
I've seen it where the view totally recalculates for each individual update... kinda drags performance down a bit
--Jeff Moden
Change is inevitable... Change for the better is not.
August 10, 2007 at 2:14 am
this is the definition, not very complex.
CREATE VIEW dbo.vw_CostPriceUpdate_Update
AS
SELECT dbo.vw_CostPriceUpdate_UK.RECORD_NUMBER AS [UK Record Number], dbo.vw_CostPriceUpdate_UK.DEPOT AS [Depot UK],
dbo.vw_CostPriceUpdate_UK.PART AS [Part UK], dbo.vw_CostPriceUpdate_UK.COST AS [UK Cost],
dbo.vw_CostPriceUpdate_Non_UK.RECORD_NUMBER, dbo.vw_CostPriceUpdate_Non_UK.DEPOT, dbo.vw_CostPriceUpdate_Non_UK.PART,
dbo.vw_CostPriceUpdate_Non_UK.COST
FROM dbo.vw_CostPriceUpdate_Non_UK INNER JOIN
dbo.vw_CostPriceUpdate_UK ON dbo.vw_CostPriceUpdate_Non_UK.PART = dbo.vw_CostPriceUpdate_UK.PART
also that sounds right but would that be correct as it works fine the first time you run it but its the second time that it seems to get caught in a loop and never ends. the first time takes 15 seconds and i have left the second time running for over 21 hours so it's really annoying.
August 10, 2007 at 3:33 am
Additional notes:
Running SQL Server 2000 (SP4)
The view i'm calling the update on is on open query views of a linked server
August 10, 2007 at 6:42 am
I think the update is a little deeper, you name your views just like I do with "vw_" preceeding it,and that makes me think you need to take look a the update in profiler.
the update sets cost=[UK COST]; in your example, since there's no WHERE statement, it is going to affect every record. That's going to require a table scan on the underlying tables, right? If the tables are huge, and statistics are a bit out, then the execution plan might literally take forever as it goes down the wrong decision path.
The view you are updating is a view of another view. the sql statement is going to have to resolve vw_CostPriceUpdate_Non_UK.COST in order to update as well, which adds to the overhead.
if you update statistics , I believe the update would go through faster. I've had a similar performance hit with view-of-a-view for SELECT statements, but designwise I haven't tried very many updatable views.
CREATE VIEW dbo.vw_CostPriceUpdate_Update
AS
SELECT
dbo.vw_CostPriceUpdate_UK.RECORD_NUMBER AS [UK Record Number],
dbo.vw_CostPriceUpdate_UK.DEPOT AS [Depot UK],
dbo.vw_CostPriceUpdate_UK.PART AS [Part UK],
dbo.vw_CostPriceUpdate_UK.COST AS [UK Cost],
dbo.vw_CostPriceUpdate_Non_UK.RECORD_NUMBER,
dbo.vw_CostPriceUpdate_Non_UK.DEPOT,
dbo.vw_CostPriceUpdate_Non_UK.PART,
dbo.vw_CostPriceUpdate_Non_UK.COST
FROM dbo.vw_CostPriceUpdate_Non_UK
INNER JOIN dbo.vw_CostPriceUpdate_UK ON dbo.vw_CostPriceUpdate_Non_UK.PART = dbo.vw_CostPriceUpdate_UK.PART
Lowell
August 10, 2007 at 6:49 am
That seems valid but it's identical on another server and works fine there. Does it also explain why it works fine the first time but fails the second time.
Also an additional note, this server recently changed domain name and i've been through all permissions settings etc and they seem fine although is there anything in this that could affect it somewhere.
August 10, 2007 at 7:07 am
Seems to me it would have to be something in the data that is being used to do the update. What is different between the first and second time it is run?
August 10, 2007 at 7:12 am
Absolutely nothing is different it's really perplexing as to why it fails the second time you run it. Although looking at the processes the update processes status is set to sleeping and wait type as exchange if that has any bearing.
August 10, 2007 at 7:20 am
Yet when it works fine the status is Runnable and the wait type is OLEDB
August 10, 2007 at 9:30 am
In researching it could be linked to this problem with parallel processes as that's why am getting the Exchange (Wait-Type)
http://www.dbforums.com/t656327.html
http://www.dbforums.com/showthread.php?threadid=529043
Viewing 15 posts - 1 through 15 (of 21 total)
You must be logged in to reply to this topic. Login to reply