INSERT-SELECT (Oracle PL/SQL) - Performance Issue -


i have many select statements toghether 1 insert (maybe hundreds of them) , system giving bad performance.

i explain in general words happening , i'm searching for:

considering following 2 pseudo-codes in oracle pl/sql, of them give best performance?

option a:

insert mytable   fields (      select field1, field2, ..., fieldn tablea join tablew .... <condition1>      union      select field1, field2, ..., fieldn tableb join tablex .... <condition2>      union      select field1, field2, ..., fieldn tablec join tableb .... <condition3>      ....      union      ....      select field1, field2, ..., fieldn tablezzz join tableb .... <conditionn> 

option b:

begin   insert mytable select field1, field2, ..., fieldn tablea join tablez .... <condition1>   insert mytable select field1, field2, ..., fieldn tableb join tablew .... <condition2>   insert mytable select field1, field2, ..., fieldn tablec join tableh .... <condition3>   ...   insert mytable select field1, field2, ..., fieldn tablezzzz join tablex .... <conditionn> end 

i didn't put real table names, know: if change current option option b, present me better performance? mean, idea replace union many insert statements in case?

context switches , performance

almost every program pl/sql developers write includes both pl/sql , sql statements. pl/sql statements run pl/sql statement executor; sql statements run sql statement executor. when pl/sql runtime engine encounters sql statement, stops , passes sql statement on sql engine. sql engine executes sql statement , returns information pl/sql engine (see figure 1). transfer of control called context switch, , each 1 of these switches incurs overhead slows down overall performance of programs.

so, use third way:

create view myview select field1, field2, ..., fieldn tablea join tableb .... <condition1>  declare   p_array_size pls_integer := 100;   type         array table of myview%rowtype;   l_data       array;   cursor c select * myview;     begin     open c;     loop     fetch c bulk collect l_data limit p_array_size;      forall in 1..l_data.count     insert mytable values l_data(i);      exit when c%notfound;     end loop;     close c; end; 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -