views:

131

answers:

1

I am trying to run a stored procedure with a while loop in it using Aqua Data Studio 6.5 and as soon as the SP starts Aqua Data starts consuming an increasing amount of my CPU's memory which makes absolutely no sense to me because everything should be off on the Sybase server I am working with. I have commented out and tested every piece of the SP and narrowed the issue down to the while loop. Can anyone explain to me what is going on?

create procedure sp_check_stuff as
begin

declare
    @counter numeric (9),
    @max_id numeric (9),
    @exists numeric (1),
    @rows numeric (1)

select @max_id = max(id) 
    from my_table      

set @counter = 0
set @exists = 0
set @rows = 0

while @count <= @max_id
    begin

     //More logic which doesn't affect memory usage based
     //on commenting it out and running the SP

    set @counter = @counter + 1
    set @exists = 0
    set @rows = 0

   end
end

return

+1  A: 

How many times does the while loop iterate? I suspect Aqua Data Studio is building up data structures as the query runs and for every iteration of the loop, a further block of memory is needed to catalogue the plan/stats of that iteration.

Daniel Renshaw
The max_id is ~32,000,000
Nathan
Well if, say, 1000 bytes were needed to store details about each iteration (and it could easly be much more than that!), Aqua Data Studio would need 32GB of memory! If you don't need to analyse the runtime of the SP, don' run in from Aqua Data Studio (or disable its monitoring features, if that's possible).
Daniel Renshaw