Sybase SQL stored procedure consumes too much memory

1.1k views Asked by At

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

There are 1 answers

1
Daniel Renshaw On BEST ANSWER

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.