Home > Uncategorized > BULK COLLECT Performance

BULK COLLECT Performance

BULK COLLECT
Bu denememizde BULK COLLECT adlı bir yapıyla tanışmış oluyoruz. Bu yapı bize sorgu sonuçlarını bir cursora değil de bir array’e aktarmamızı sağlıyor. Normalde bir tablodaki her satıra ait bir colonu yazdırmak istesek bunu şu şekilde yaparız:

FOR REC IN ( SELECT NAME FROM EMP)
LOOP
DBMS_OUTPUT….
END LOOP;

İşte, BULK COLLECT kullanarak bir cursor içerisinde değil de bir array içerisinde dönmüş oluyor. Ve bu PLSQL Kodunun performansını arttırıyor.
Denememizi şu şekilde yapacağız. 2 procedurumuz var. Step_1 BULK COLLECT ile veri çekiyor. Step_2 ise bildiğimiz şekilde.
Step_1 Proceduru :
create or replace procedure step_1 is
TYPE array_type_id IS TABLE OF TEST_1.ID%TYPE;
TYPE array_type_name IS TABLE OF TEST_1.NAME%TYPE;

varIdArr array_type_id;
varNameArr array_type_name;
BEGIN
SELECT id,name bulk collect into varIdArr,varNameArr from test_1 WHERE ID < 10000;

for i in varIdArr.first..varIdArr.last
Loop
dbms_output.put_line(‘>ID :’ || varIdArr(i) || ‘ – NAME :’ || varNameArr(i) );
end loop;
end;

Step_2 Proceduru:

create or replace procedure step_2 is
BEGIN
FOR REC IN ( SELECT * FROM TEST_1 WHERE ID < 10000)
LOOP
DBMS_OUTPUT.put_line(‘>ID :’ || REC.ID || ‘ – NAME :’ || REC.NAME);
END LOOP;
END;

Testimizi Başlatmak için:

exec runstats_pkg.rs_start;
exec step_1;
exec runstats_pkg.rs_middle;
exec step_2;
exec runstats_pkg.rs_stop;

Test Sonuçları :
SQL> exec runstats_pkg.rs_stop;

Run1 ran in 1048 hsecs
Run2 ran in 1139 hsecs
run 1 ran in 92,01% of the time

Name Run1 Run2 Diff
LATCH.mostly latch-free SCN 4 3 -1
STAT…session cursor cache co 1 0 -1
STAT…recursive cpu usage 3 4 1
LATCH.library cache lock 28 27 -1
LATCH.object queue header oper 4 5 1
LATCH.library cache lock alloc 1 0 -1
LATCH.undo global data 17 18 1
STAT…redo entries 11 12 1
LATCH.Shared B-Tree 0 1 1
LATCH.active checkpoint queue 4 3 -1
LATCH.kwqbsn:qsga 0 1 1
LATCH.cache buffers lru chain 0 1 1
LATCH.lgwr LWN SCN 4 3 -1
STAT…free buffer requested 0 1 1
LATCH.KMG MMAN ready and start 3 4 1
LATCH.enqueues 164 162 -2
LATCH.resmgr:resource group CP 2 0 -2
LATCH.library cache pin 26,809 26,811 2
LATCH.enqueue hash chains 166 164 -2
STAT…bytes received via SQL* 1,105,839 1,105,837 -2
STAT…db block changes 36 33 -3
LATCH.redo allocation 22 19 -3
LATCH.redo writing 15 12 -3
STAT…heap block compress 7 4 -3
LATCH.qmn task queue latch 0 4 4
LATCH.messages 72 68 -4
STAT…active txn count during 11 15 4
STAT…cleanout – number of kt 11 15 4
STAT…consistent gets – exami 11 15 4
STAT…calls to kcmgcs 11 15 4
LATCH.shared pool 50 55 5
STAT…consistent changes 25 20 -5
STAT…db block gets 37 44 7
STAT…db block gets from cach 37 44 7
LATCH.channel operations paren 56 48 -8
STAT…parse time cpu 14 1 -13
STAT…CPU used by this sessio 60 47 -13
STAT…CPU used when call star 63 47 -16
LATCH.checkpoint queue latch 72 54 -18
STAT…parse time elapsed 30 2 -28
STAT…DB time 87 56 -31
STAT…workarea memory allocat 31 -2 -33
LATCH.SQL memory manager worka 274 207 -67
STAT…undo change vector size 2,180 2,248 68
STAT…Elapsed Time 1,056 1,140 84
LATCH.shared pool simulator 107 15 -92
LATCH.simulator lru latch 54 232 178
LATCH.simulator hash latch 54 232 178
STAT…redo size 2,972 3,216 244
STAT…no work – consistent re 777 4,109 3,332
STAT…table scan blocks gotte 777 4,109 3,332
STAT…consistent gets 800 4,136 3,336
STAT…consistent gets from ca 800 4,136 3,336
STAT…recursive calls 6 3,344 3,338
STAT…session logical reads 837 4,180 3,343
LATCH.cache buffers chains 1,778 8,426 6,648
STAT…session uga memory 196,392 0 -196,392
STAT…session pga memory 458,752 0 -458,752
STAT…table scan rows gotten 497,103 2,246,371 1,749,268

Run1 latches total versus runs — difference and pct
Run1 Run2 Diff Pct
80,153 86,968 6,815 92.16%

PL/SQL procedure successfully completed

SQL>

Bu Testte asıl dikkat etmemiz gereken birkaç nokta var. Bunlardan en önemlisi Tom Kyte’a göre Total Latches olayı. Görüldüğü gibi 2. Procedurumuzda bu daha fazla. Yani daha fazla gecikme meydana gelmiş. Diğer bakılabilecek önemli nokta ise elapsed time, yine aynı şekilde 1. Procedure 2.procedur’a göre daha performanslı elapsed time açısından.

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: