Unix Technical Forum

SEO

vBulletin Search Engine Optimization


Go Back   Unix Technical Forum > Database Server Software > Sybase

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 06:18 PM
gucis
 
Posts: n/a
Default Any ideas regarding SQL procedure?

Hi, all.

Here's approximate design with which I have to work. At source I have:
create table source(some_id integer, iterations integer);

And I should make:
create table target(some_id integer, iteration_counter integer);

For example, if I have row (1, 5) in table source, I have to have rows
(1,1)
(1,2)
(1,3)
(1,4)
(1,5)
in target table.

OK this is not actual design, but this is essence of my task.

--------------------------------------------------------------------------------------------
One of my ideas - I make a cursor from source table and go through all
rows in it,
for each row calling procedure, which enters records in target table

FOR iteration AS iteration_cursor CURSOR FOR
select id, iterations
from source
DO
call enter_records(id, iterations);
END FOR;

enter_records procedure:

create procedure enter_records(p_id integer, p_iterations integer);
begin
declare v_iterations integer;
set v_iterations = p_iterations;

WHILE v_iterations>-1 LOOP
insert into target(id, iterations_counter) values (p_id, v_iterations);
set v_months_count=v_months_count-1;
END LOOP;
commit;
end;

--------------------------------------------------------------------------------------------

This works, but unacceptably slow, processing few records per second.


I improved performance by making Java procedure.

FOR iteration AS iteration_cursor CURSOR FOR
select id, iterations
from source
DO
WHILE v_iterations>-1 LOOP
call file_writer.main(id, iterations_counter);
set v_months_count=v_months_count-1;
END LOOP;
END FOR;

Java procedure file_writer.main writes id and iteration_counter to
text file, at end I make one big load, which inserts text file into
target table. Performance slightly improved, now it is about 1000 taget
records per minute, which still is very slow.

Currently I am out of ideas, how to improve performance. Cursor
processing seems to be the bottleneck. Any ideas how to avoid using
cursor? Or anything else, how to improve performance?

Thanks in advance!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 06:18 PM
Jochen Schug
 
Posts: n/a
Default Re: Any ideas regarding SQL procedure?

A potential approach:

- Prepare a table that has rows with all level of interations that you'll
ever need, e.g. rows with values from 1 to 1000. Let's call this table
t_it (interations int not null).

- Instead of looping n times over the source table, you could then simply
join against that prepared table:

insert into target (id, iterations_counter)
select (source.id, it.interation)
from source, it
where source.id = p_id and it.iteration between 1 and p_iterations

You'll need to do this for all p_id's from your source table.

Jochen
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 06:18 PM
gucis
 
Posts: n/a
Default Re: Any ideas regarding SQL procedure?

Thanks! It seems to be working!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:47 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145