oracle - Different queries or One? Which one is feasible? -


i have following queries want delete 3 employees in admin department.

delete employee_tbl emp_id = 123 , emp_dep = 'admin'; delete employee_tbl emp_id = 456 , emp_dep = 'admin'; delete employee_tbl emp_id = 789 , emp_dep = 'admin'; 

i thinking write single query like-

delete employee_tbl emp_id in (123, 456, 789) , emp_dep = 'admin'; 

is correct way write query in case of performance , all? confused.

any explanation appreciated.

both queries have pros , cons

1) multiple selects.

i rather rewrite query using bind variables.

delete employee_tbl emp_id = :l_emp_id , emp_dep = :l_emp_dep; 

and run multiple times.

this way, oracle don't hard parse query every time, , oracle re-uses explain plan reducing latch activity in shared global area(sga) minimizing cpu usage.

more details bind variables - key application performance

but 1 glitch here is, every execution of query actually, needs switch client sql engine process.(context switching, again costly process)

to override this, use bulk binding. not clients support this.

2) single query using in or temp tables/cte.

this query depends on db intelligence itself. no brainy developers. recent optimizers, handle them smartly, internally, using in-list iterators or temp tables if needed.

other advantage be, run query once, , operation needs 1 round trip database.

let database decide load.


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? -