Bind Variables are important because one of the design feature in Oracle is ability to reuse the optimizer plans whenever possible. whenever you submit any SQL or PL/SQL blocks to database, Oracle will look if the query is already parsed and optimized (Shared pool) if it finds then the execution plan can be reused. If it cannot find then Oracle Hard parses the query, performs security checks and optimizes the plan and so on..This not only consumes CPU but tends to lock the portion of the library cache for relatively long periods. The more people hard parsing the query increases then longer the wait.
BANNER
----------------------------------------------------------------
Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production
PL/SQL Release 9.2.0.8.0 - Production
CORE 9.2.0.8.0 Production
TNS for 32-bit Windows: Version 9.2.0.8.0 - Production
NLSRTL Version 9.2.0.8.0 - Production
2 FROM dba_tablespaces
3 where tablespace_name ='DATA1';
TABLESPACE_NAME SEGMEN
------------------------------ ------
DATA1 MANUAL
Elapsed: 00:00:00.04
create table t(x number,y number,z number) tablespace DATA1 storage(freelists 5);
create global temporary table temp_sess
on commit preserve rows
as
select *
from v$session_event where 1 = 0;
2 select * from v$session_event
3 where sid = (select sid from v$mystat where rownum = 1);
12 rows created.
Elapsed: 00:00:00.06
2 l_value number;
3 begin
4 for i in 1..100000
5 loop
6 l_value := dbms_random.value;
7 execute immediate ' insert into t (x,y,z) values ('||l_value||','||l_value||','||l_value||')';
8 end loop;
9 end;
10 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:52.95
2 (nvl(aft.time_waited,0) - nvl(bfr.time_waited,0)) as time_waited
3 FROM V$SESSION_EVENT aft,temp_sess bfr
4 WHERE aft.SID = (select sid from v$mystat where rownum = 1)
5 and aft.event = bfr.event(+)
6 and abs(aft.total_waits - nvl(bfr.total_waits,0)) > 0 ;
EVENT TOTAL_WAITS TIME_WAITED
---------------------------------------------------------------- ----------- -----------
latch free 226 30
enqueue 3 5
free buffer waits 1 67
buffer busy waits 33 0
log file switch completion 2 6
db file sequential read 8 4
row cache lock 15 31
SQL*Net message to client 8 0
SQL*Net message from client 7 11895
9 rows selected.
The Oracle wait interface are documented in Oracle 9i Reference manual.
This latch free is actually a latch in shared sql area.So how this can be reduced. one way by using Bind variables.
Now using Bind variables Latch Free has gone down.
scott@9iR2> declare
2 l_value number;
3 begin
4 for i in 1..100000
5 loop
6 l_value := dbms_random.value;
7 execute immediate ' insert into t (x,y,z) values (:x,:y,:z) ' using l_value,l_value,l_value;
8 end loop;
9 end;
10 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:19.29
scott@9iR2> SELECT aft.event,(nvl(aft.total_waits,0) - nvl(bfr.total_waits,0)) as total_waits,
2 (nvl(aft.time_waited,0) - nvl(bfr.time_waited,0)) as time_waited
3 FROM V$SESSION_EVENT aft,temp_sess bfr
4 WHERE aft.SID = (select sid from v$mystat where rownum = 1)
5 and aft.event = bfr.event(+)
6 and abs(aft.total_waits - nvl(bfr.total_waits,0)) > 0 ;
EVENT TOTAL_WAITS TIME_WAITED
---------------------------------------------------------------------------
latch free 123 8
buffer busy waits 1000 350
log file switch completion 3 9
db file sequential read 677 373
SQL*Net message to client 5 0
SQL*Net message from client 4 4538
6 rows selected.
Elapsed: 00:00:00.04
Another way to drop this considerably is static SQL's in Pl/SQL block.
scott@9iR2> declare
2 l_value number;
3 begin
4 for i in 1..100000
5 loop
6 l_value := dbms_random.value;
7 insert into t (x,y,z) values (l_value,l_value,l_value);
8 end loop;
9 end;
10 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:07.55
scott@9iR2> SELECT aft.event,(nvl(aft.total_waits,0) - nvl(bfr.total_waits,0)) as total_waits,
2 (nvl(aft.time_waited,0) - nvl(bfr.time_waited,0)) as time_waited
3 FROM V$SESSION_EVENT aft,temp_sess bfr
4 WHERE aft.SID = (select sid from v$mystat where rownum = 1)
5 and aft.event = bfr.event(+)
6 and abs(aft.total_waits - nvl(bfr.total_waits,0)) > 0 ;
EVENT TOTAL_WAITS TIME_WAITED
-----------------------------------------------------------------------
enqueue 9 0
free buffer waits 5 70
write complete waits 1 20
buffer busy waits 3 0
log buffer space 7 64
log file switch completion 2 18
db file sequential read 2 1
SQL*Net message to client 5 0
SQL*Net message from client 4 3020
9 rows selected.
Now when executing static sql's in Pl./Sql block ( PL/SQL will cache my cursor for me – that is one of the major advantages of PL/SQL. This insert will typically be soft parsed once per session for me if it was in a
procedure ) . The latching is totally gone.
The above demonstrates that using Bind variable is crucial to performance.
Those guidelines additionally worked to become a good way to recognize that other people online have the identical fervor like mine to grasp great deal more around this condition"Devops Training in Bangalore" .
ReplyDeleteNew informative about oracle.Thanks u made me know some additional term in oracle.Keep posting some more contents.Will be waiting for ur next blog.
ReplyDeletemotorola mobile service centre in chennai
moto g service center in chennai
Great post.Thanks to share lots of unique features about oracle.
ReplyDeletebest mobile service center in chennai
Hi, thank you very much for the new information, i learned something new. Very well written.it was so good to read and usefull to improve knowledge. Keep posting. If you are looking for any data science related information please visit our website data science course training bangalore
ReplyDeleteI am happy for sharing on this blog its awesome blog I really impressed. thanks for sharing. Great efforts.
ReplyDeleteBest Training Institute in Bangalore BTM. My Class Training Bangalore training center for certified course, learning on Software Training Course by expert faculties, also provides job placement for fresher, experience job seekers.
Software Training Institute in Bangalore
Such a great blog,
ReplyDeleteThanks for sharing with us,
We are again come on your website,
Thanks and good day,
If you need any logo then,
Please visit our site,
buylogo
ReplyDeleteSuch a great word which you use in your article and article is amazing knowledge. thank you for sharing it. DevOps Training | Certification in Chennai | DevOps Training | Certification in anna nagar | DevOps Training | Certification in omr | DevOps Training | Certification in porur | DevOps Training | Certification in tambaram | DevOps Training | Certification in velachery
Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts.
ReplyDeletejava training in chennai
java training in tambaram
aws training in chennai
aws training in tambaram
python training in chennai
python training in tambaram
selenium training in chennai
selenium training in tambaram
I have express a few of the articles on your website now, and I really like your style of blogging. I added it to my favorite’s blog site list and will be checking back soon…
ReplyDeleteangular js training in chennai
angular js training in velachery
full stack training in chennai
full stack training in velachery
php training in chennai
php training in velachery
photoshop training in chennai
photoshop training in velachery
New informative about oracle.Thanks u made me know some additional term in oracle.Keep posting some more contents.Will be waiting for ur next blog.
ReplyDeleteangular js training in chennai
angular js training in omr
full stack training in chennai
full stack training in omr
php training in chennai
php training in omr
photoshop training in chennai
photoshop training in omr
Wow its a very good post. The information provided by you is really very good and helpful for me. Keep sharing good information.
ReplyDeletedata science training in chennai
data science training in annanagar
android training in chennai
android training in annanagar
devops training in chennai
devops training in annanagar
artificial intelligence training in chennai
artificial intelligence training in annanagar
Excellent post, From this post i got more detailed information,
ReplyDeleteThanks to share with us,
Excellent post, From this post i got more detailed information,
Thanks to share with us,
java training in chennai
java training in porur
aws training in chennai
aws training in porur
python training in chennai
python training in porur
selenium training in chennai
selenium training in porur
This was a very informative article, indeed loved to read and clear my doubts. Keep us posted a lot more blogs. Also check out our blog pages too.
ReplyDeletedata science training in chennai
ccna training in chennai
iot training in chennai
cyber security training in chennai
ethical hacking training in chennai