sql - FORALL vs FOR bulk update -


this asked in interview. question is, 1 faster, forall on 5000 or using on 500 records? well, think indeed forall faster far processing speed concerned still depends on number of rows processed, in case of above question. please share thoughts.

it depends.

first, how test set up? in normal code, for loop runs query , if you're measuring performance of loop, you're combining time required run query, fetch results, , results.

for x in (<<some select statement>>) loop   <<do x>> end loop; 

a forall on other hand, implies you've done work of fetching data need process local collection.

forall in 1..l_collection.count   <<do something>> 

a performance comparison includes time required run query , fetch results in 1 case , excludes time other case not fair comparison. you'd either need include cost of populating collection in forall case or need for loop iterate on populated collection comparison fair one. approach use may have dramatic affect on result.

a forall eliminates context shifts between sql , pl/sql engines, that's it. can useful if substantial fraction of program's runtime spent on context shifts. more expensive thing you're doing data (and more expensive fetching data if you're including time), smaller fraction of time spent on context shifts must be. if you're excluding time required fetch data , guts of loop trivial operation, for loop solution may spending more 90% of time doing context shifts forall solution may 10 times faster. if you're including time required fetch data, time large fraction of overall runtime, , guts of loop expensive operation, for loop solution spending small fraction of time doing context shifts going forall won't 10x improvement.

things more complicated if including time required populate collection since there many ways potentially write that have different performance characteristics depending upon whether you're using implicit or explicit cursors , oracle version. that's discussed in more detail in this question on performance of bulk collect.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -