(IILFLHQW XVH RI ELQG YDULDEOHV FXUVRUBVKDULQJ DQG UHODWHG FXUVRU SDUDPHWHUV

$Q 2UDFOH :KLWH 3DSHU $XJXVW 

(IILFLHQW XVH RI ELQG YDULDEOHV FXUVRUBVKDULQJ DQG UHODWHG FXUVRU SDUDPHWHUV

29(59,(:   ,1752'8&7,21   64/ 352&(66,1* ,1 25$&/(   8VLQJ ELQG YDULDEOHV   6XSSRUW IRU DSSOLFDWLRQV XVLQJ OLWHUDOV   +DQGOLQJ RI FXUVRUV  5(68/76 $1' %(67 35$&7,&(6  %HVW SUDFWLFHV  63(&,$/ &216,'(5$7,216  &RQVLGHUDWLRQV IRU GHFLVLRQ VXSSRUW V\VWHPV  %LQG YDULDEOH SHHNLQJ LQ 2UDFOHL   &XUVRUBVKDULQJ LQ 2UDFOHL   &21&/86,21   $33(1',; 7(67 5(68/76  7HVWLQJ VHVVLRQBFDFKHGBFXUVRUV FXUVRUBVSDFHBIRUBWLPH DQG SURJUDPPLQJ PRGHO  7HVWLQJ FXUVRUBVKDULQJ IRU VWDWHPHQWV ZLWK VDIH OLWHUDOV  7HVWLQJ FXUVRUBVKDULQJ IRU VWDWHPHQWV ZLWK XQVDIH OLWHUDOV 

Efficient use of bind variables, cursor_sharing and related cursor parameters Page 2

(IILFLHQW XVH RI ELQG YDULDEOHV FXUVRUBVKDULQJ DQG UHODWHG FXUVRU SDUDPHWHUV

OVERVIEW

7KH 2UDFOH GDWDEDVH KDV EHHQ GHVLJQHG WR DOORZ GHYHORSHUV WR GHVLJQ DQG EXLOG DSSOLFDWLRQV WKDW ZLOO VFDOH WR WHQV RI WKRXVDQGV RI XVHUV 6SHFLILF IHDWXUHV LQ WKH 2UDFOH NHUQHO DOORZ VKDULQJ RI LQIRUPDWLRQ EHWZHHQ DOO WKHVH XVHUV LQ RUGHU WR UHGXFH ERWK PHPRU\ DQG &38 XVDJH VSHFLILFDOO\ LGHQWLFDO 64/ VWDWHPHQWV H[HFXWHG E\ PDQ\ XVHUV DUH VWRUHG RQO\ RQFH $ VHW RI 2UDFOH VWDUWXS SDUDPHWHUV FRQWURO WKH EHKDYLRU RI WKLV DQG DOVR DOORZLQJ VKDULQJ RI 64/ VWDWHPHQWV WKDW DUH QRW IXOO\ LGHQWLFDO
INTRODUCTION

$SSOLFDWLRQ GHYHORSHUV ZULWLQJ DSSOLFDWLRQV DJDLQVW UHODWLRQDO GDWDEDVHV OLNH 2UDFOH KDYH DOZD\V KDG UXOHV RQ KRZ WR LPSOHPHQW WKH DSSOLFDWLRQ LQ RUGHU WR DFKLHYH SHUIRUPDQFH DQG VFDODELOLW\ 7KH GDWDEDVH ZRUN WKDW QHHGV WR EH GRQH E\ WKH DSSOLFDWLRQ LV H[SUHVVHG XVLQJ WKH 64/ ODQJXDJH DQG ZULWLQJ DSSOLFDWLRQV FRUUHFWO\ WR PLQLPL]H ERWK WKH DFWXDO H[HFXWLRQ WLPH DQG WKH DVVRFLDWHG RYHUKHDG KDYH EHHQ NH\ WR ZHOO SHUIRUPLQJ DSSOLFDWLRQV 7KLV ZKLWH SDSHU IRFXVHV RQ VSHFLILF IHDWXUHV DYDLODEOH WR WKH DSSOLFDWLRQ SURJUDPPHU DQG WKH GDWDEDVH DGPLQLVWUDWRU WR FRQWURO WKLV VSHFLILFDOO\ WKH FRQFHSW RI ELQG YDULDEOHV DQG VRPH UHODWHG 2UDFOH VWDUWXS SDUDPHWHUV 0RVW DSSOLFDWLRQV LI QRW DOO KDYH D QHHG WR H[HFXWH WKH VDPH 64/ VWDWHPHQWV UHSHDWHGO\ DQG E\ PXOWLSOH XVHUV FRQFXUUHQWO\ DQG VKDULQJ RI VXFK 64/ VWDWHPHQWV LV LPSHUDWLYH IRU DSSOLFDWLRQV WR VFDOH WR WKRXVDQGV RU WHQV RI WKRXVDQGV RI XVHUV 2UDFOH LV DEOH WR VKDUH LGHQWLFDO 64/ VWDWHPHQWV H[HFXWHG E\ PDQ\ XVHUV FRQFXUUHQWO\ DQG WR NHHS WKHVH IRU VXEVHTXHQW H[HFXWLRQ LQ D FDFKH WKDW LV SDUW RI WKH GDWDEDVH VHUYHU ,QLWLDOO\ LQ 2UDFOHL UHOHDVH  DQG ZLWK IXUWKHU HQKDQFHPHQWV LQ 2UDFOHL D QHZ VWDUWXS SDUDPHWHU KDV EHHQ DGGHG WKDW DOORZ VKDULQJ RI 64/ VWDWHPHQWV WKDW DUH QRW FRPSOHWHO\ LGHQWLFDO 6SHFLILFDOO\ WKLV SDUDPHWHU PDNHV 2UDFOH VKDUH 64/ VWDWHPHQWV WKDW RQO\ GLIIHU LQ FRQVWDQWV VXFK DV VWULQJV DQG QXPEHUV 

%LQG YDULDEOHV DUH V\QWDFWLFDO SDUWV RI D 64/ VWDWHPHQW WKDW HQDEOH ELQGLQJ RI GDWD LQ DQ DSSOLFDWLRQ SURJUDP WR WKH 64/ VWDWHPHQW %LQG YDULDEOHV DUH DOVR NQRZQ DV SODFHKROGHUV

Efficient use of bind variables, cursor_sharing and related cursor parameters Page 3

SQL PROCESSING IN ORACLE

:KHQ 2UDFOH SURFHVVHV 64/ VWDWHPHQWV WKHUH DUH JHQHUDOO\ WKUHH RU IRXU VWHSV LQYROYHG GHSHQGLQJ RQ WKH W\SH RI 64/ VWDWHPHQW  $ SDUVH VWHS ZKHUH WKH 2UDFOH HQJLQH SDUVHV WKH 64/ VWDWHPHQW YHULILHV LWV V\QWDFWLFDO FRUUHFWQHVV DQG YHULILHV DFFHVV ULJKWV  $Q RSWLPL]DWLRQ VWHS ZKHUH 2UDFOH ILQGV WKH EHVW ZD\ WR SURFHVV WKH 64/ VWDWHPHQW XVLQJ LQIRUPDWLRQ DERXW WKH VL]H RI WKH YDULRXV REMHFWV WDEOHV LQGH[HV HWF  WKDW ZLOO EH DFFHVVHG  $Q H[HFXWLRQ VWHS ZKLFK XVHV WKH UHVXOW RI WKH RSWLPL]DWLRQ VWHS WR DFWXDOO\ DFFHVV GDWD  )RU TXHULHV LH VHOHFW VWDWHPHQWV  WKH H[HFXWLRQ LV IROORZHG E\ D IHWFK VWHS ZKLFK DFWXDOO\ UHWXUQV WKH URZV RI WKH TXHU\ WR WKH DSSOLFDWLRQ 7KH ILUVW WZR VWHSV ZKLFK PD\ WDNH FRQVLGHUDEOH WLPH DQG UHVRXUFHV DUH QRUPDOO\ FRQVLGHUHG RYHUKHDG DV QR DFWXDO SURFHVVLQJ RI XVHU GDWD WDNHV SODFH +HQFH DSSOLFDWLRQV VKRXOG EH ZULWWHQ WR PLQLPL]H WKH DPRXQW RI WLPH VSHQW GXULQJ WKHVH VWHSV 7KH PRVW HIILFLHQW ZD\ WR GR WKLV LV WR DYRLG WKH SDUVH DQG RSWLPL]DWLRQ VWHSV DV PXFK DV SRVVLEOH
Understanding of Oracle SQL processing allow application programmers writing fully scalable applications. In particular, avoiding hard and soft parses will greatly reduce CPU overhead and increase sharing of memory.

$V SDUW RI WKH VKDUHG SRRO LQ WKH V\VWHP JOREDO DUHD RI DQ 2UDFOH LQVWDQFH DOO FXUUHQWO\ H[HFXWLQJ 64/ VWDWHPHQWV DUH FDFKHG LQ WKH OLEUDU\ FDFKH 'XULQJ WKH SDUVH VWHS 2UDFOH ILUVW YHULILHV ZKHWKHU RU QRW WKH 64/ VWDWHPHQW LV LQ WKH OLEUDU\ FDFKH ,I LW LV RQO\ OLWWOH IXUWKHU SURFHVVLQJ LV QHFHVVDU\ VXFK DV YHULILFDWLRQ RI DFFHVV ULJKWV ,I QRW WKH VWDWHPHQW ZLOO QHHG WR EH SDUVHG FKHFNHG IRU V\QWD[ HUURUV FKHFNHG IRU FRUUHFWQHVV RI WDEOH DQG FROXPQDPHV HWF 7KH IRUPHU W\SH RI SDUVH LV FDOOHG D VRIW SDUVH DQG LV FRQVLGHUDEO\ IDVWHU WKDQ WKH ODWWHU D KDUG SDUVH +HQFH DSSOLFDWLRQV VKRXOG LQ SDUWLFXODU DYRLG KDUG SDUVHV 'XULQJ WKH ILUVW H[HFXWH RI D 64/ VWDWHPHQW WKH RSWLPL]DWLRQ WDNHV SODFH LH 2UDFOH ILQGV WKH EHVW SDWK WR DFFHVV GDWD 7KH DFFHVV SODQ DORQJ ZLWK WKH 64/ VWDWHPHQW DQG LWV SDUVH WUHH LV VWRUHG LQ WKH OLEUDU\ FDFKH )LQDOO\ WKH 64/ VWDWHPHQW LV H[HFXWHG DQG IRU TXHULHV WKH UHVXOWLQJ URZV DUH WKHQ IHWFKHG 2QFH D VWDWHPHQW LV SDUVHG DQG H[HFXWHG LW FDQ HIILFLHQWO\ EH H[HFXWHG DJDLQ FRPSOHWHO\ DYRLGLQJ WKH SDUVH DQG RSWLPL]DWLRQ VWHSV 7KH PHWKRG XVHG E\ 2UDFOH WR YHULI\ LI D 64/ VWDWHPHQW LV DOUHDG\ IRXQG LQ WKH OLEUDU\ FDFKH LV D KDVK ORRNXS IROORZHG E\ VLPSO\ GRLQJ D VWULQJ FRPSDULVRQ +HQFH RQO\ FRPSOHWHO\ LGHQWLFDO 64/ VWDWHPHQWV ZLOO EH FRQVLGHUHG LGHQWLFDO 

,Q VRPH FDVHV RSWLPL]DWLRQ PD\ WDNH SODFH GXULQJ SDUVLQJ EXW WKLV LV LUUHOHYDQW WR WKH GLVFXVVLRQV LQ WKLV ZKLWH SDSHU

Efficient use of bind variables, cursor_sharing and related cursor parameters Page 4

Using bind variables

$V LV H[SODLQHG LQ WKH SUHYLRXV VHFWLRQ RQO\ FRPSOHWHO\ LGHQWLFDO 64/ VWDWHPHQWV ZLOO EH UHFRJQL]HG DV VXFK ZKHQ WKH OLEUDU\ FDFKH LV FRQVXOWHG +HQFH WKH WZR VWDWHPHQWV select * from emp where empno=1234 DQG select * from emp where empno=5678 DUH FRQVLGHUHG GLIIHUHQW DQG H[HFXWLQJ WKHVH WZR ZLOO FDXVH WZR KDUG SDUVHV DQG WZR VHSDUDWH FXUVRUV LQ WKH OLEUDU\ FDFKH ,W LV WKHUHIRUH KLJKO\ UHFRPPHQGHG WR XVH ELQG YDULDEOHV LQ WKH 64/ VWDWHPHQW WKDW DUH ERXQG WR YDOXHV LQ WKH DSSOLFDWLRQ SURJUDP DQG ZKRVH DFWXDO YDOXH LV RQO\ ILOOHG LQ DW VWDWHPHQW H[HFXWH WLPH 7KH VWDWHPHQW DERYH ZRXOG WKHQ EH select * from emp where empno=:x ZKLFK FDQ EH H[HFXWHG PXOWLSOH WLPHV ZLWK GLIIHUHQW DFWXDO YDOXHV IRU WKH ELQG YDULDEOH [ $ ZHOO GHVLJQHG DSSOLFDWLRQ ZLOO GR D VLQJOH SDUVH RI WKLV VWDWHPHQW DQG UHSHDW WKH H[HFXWH DV RIWHQ DV QHFHVVDU\ ZLWK GLIIHUHQW DFWXDO YDOXHV IRU WKH ELQG YDULDEOH LQ WKH DSSOLFDWLRQ SURJUDP 7KLV DSSURDFK QRW RQO\ PDNHV D VLQJOH SURJUDP SHUIRUP EHWWHU LW DOVR HQVXUHV VFDODELOLW\ E\ KDYLQJ PXOWLSOH FRQFXUUHQWO\ UXQQLQJ SURJUDPV VKDUH WKH VDPH FRS\ RI WKH 64/ VWDWHPHQW 2UDFOH KDV DOZD\V UHFRPPHQGHG WKLV DSSURDFK WR DSSOLFDWLRQ SURJUDPPLQJ 6HH KRZHYHU EHORZ LQ WKH VHFWLRQ RQ VSHFLDO FRQVLGHUDWLRQV IRU UHFRPPHQGDWLRQV IRU GDWD ZDUHKRXVH W\SH DSSOLFDWLRQV 
Support for applications using literals

7KH YDOXHV  RU  LQ WKH WZR H[DPSOHV DERYH DUH FRQVWDQWV RU OLWHUDOV DQG XVLQJ WKHP LQ 64/ VWDWHPHQWV FDXVHV RYHUKHDG ZLWK SDUVLQJ DQG LPSO\ WKDW WKH 64/ VWDWHPHQWV DUH QRW VKDUHDEOH LQ WKH OLEUDU\ FDFKH 0DQ\ DSSOLFDWLRQV KDYH QRW KRZHYHU EHHQ GHYHORSHG ZLWK VXIILFLHQW DWWHQWLRQ WR WKLV DQG 2UDFOH KDV WKHUHIRUH LQWURGXFHG D PHWKRG WR UHGXFH WKH LPSDFW VXFK SURJUDPPLQJ LQ 2UDFOHL UHOHDVH  7KLV QHZ IHDWXUH ZLOO DOORZ VKDULQJ RI FXUVRU LQIRUPDWLRQ LQ WKH OLEUDU\ FDFKH IRU 64/ VWDWHPHQWV WKDW RQO\ GLIIHU LQ OLWHUDOV 7KLV LV FXUUHQWO\ LPSOHPHQWHG E\ GRLQJ D VLPSOH VFDQ RI WKH 64/ VWDWHPHQW ZKLFK ZLOO UHSODFH DQ\ OLWHUDOV IRXQG E\ D ELQG YDULDEOH )RU WKLV UHDVRQ FXUVRU VKDULQJ KDV DOVR EHHQ FDOOHG OLWHUDO UHSODFHPHQW 7KLV VFDQ LV GRQH EHIRUH WKH DFWXDO SDUVH VWHS DQG ZKHQ WKH VHUYHU LV DVNHG WR SDUVH WKH WZR VWDWHPHQWV DERYH WKH\ ZLOO WKHUHIRUH LQ ERWK FDVHV EH UHSODFHG E\ D VWDWHPHQW OLNH select * from emp where empno=:SYS_B_0 

$OWKRXJK FXUVRU VKDULQJ LV FXUUHQWO\ LPSOHPHQWHG E\ UHSODFLQJ OLWHUDOV ZLWK ELQG YDULDEOHV ODWHU UHOHDVHV RI 2UDFOH PD\ LPSOHPHQW FXUVRU VKDULQJ GLIIHUHQWO\

Efficient use of bind variables, cursor_sharing and related cursor parameters Page 5

The cursor sharing feature of Oracle allows sharing of SQL statements that differ only in values of constants. This reduces memory usage and parsing overhead.

,Q WKLV VWDWHPHQW WKH OLWHUDO KDV EHHQ UHSODFHG E\ WKH ELQG YDULDEOH DQG WKH VWDWHPHQW ZLOO EH VKDUHG DQG RQO\ LQFXU WKH RYHUKHDG RI D KDUG SDUVH RQFH 7KHUHIRUH HYHQ DSSOLFDWLRQV WKDW GR QRW WKHPVHOYHV XVH ELQG YDULDEOHV FDQ JHW WKH EHQHILW RI GRLQJ VR 7KLV LV FRQWUROOHG ZLWK WKH VWDUWXS LQLWRUD SDUDPHWHU FXUVRUBVKDULQJ ZKLFK FDQ EH VHW WR DQ\ RI WKUHH YDOXHV H[DFW IRUFH VLPLODU &DXVHV WKH EHKDYLRU RI SUHYLRXV UHOHDVHV LH QR FXUVRU VKDULQJ 7KLV LV WKH GHIDXOW YDOXH &DXVHV XQFRQGLWLRQDO VKDULQJ RI 64/ VWDWHPHQWV WKDW RQO\ GLIIHU HQ OLWHUDOV &DXVHV FXUVRU VKDULQJ WR WDNH SODFH ZKHQ WKLV LV NQRZQ QRW WR KDYH DQ\ LPSDFW RQ RSWLPL]DWLRQ 7KLV YDOXH LV QRW DYDLODEOH LQ 2UDFOHL

7KH SDUDPHWHU PD\ EH VHW JOREDOO\ HLWKHU LQ WKH VWDUWXS ILOH RU E\ DQ DOWHU V\VWHP FRPPDQG RU LW FDQ EH VHW IRU DQ LQGLYLGXDO VHVVLRQ ZLWK DQ DOWHU VHVVLRQ FRPPDQG 7KH GHIDXOW YDOXH LV H[DFW LQ 2UDFOH L UHOHDVH  DQG  DQG 2UDFOH L UHOHDVH  DOWKRXJK WKLV PD\ FKDQJH LQ D IXWXUH UHOHDVH RI 2UDFOH
Handling of cursors

$ FXUVRU LV D KDQGOH E\ ZKLFK DSSOLFDWLRQV H[HFXWH 64/ VWDWHPHQWV $Q DSSOLFDWLRQ PD\ RSHQ DV PDQ\ FXUVRUV DV QHFHVVDU\ ZLWKLQ OLPLWV RI PHPRU\ DQG WKH RSHQBFXUVRUV VWDUWXS SDUDPHWHU  DQG WKH FXUVRUV DUH VXEVHTXHQWO\ DVVRFLDWHG ZLWK 64/ VWDWHPHQWV )RU WKH PRVW HIILFLHQW H[HFXWLRQ RI 64/ VWDWHPHQWV DSSOLFDWLRQV VKRXOG RSHQ DV PDQ\ FXUVRUV DV LV QHFHVVDU\ VR WKDW IUHTXHQWO\ H[HFXWHG VWDWHPHQWV DUH DOZD\V UHDGLO\ DYDLODEOH IRU H[HFXWLRQ 7KH DSSOLFDWLRQ GRHV VR E\ RSHQLQJ PXOWLSOH FXUVRUV DQG SDUVLQJ WKHVH 64/ VWDWHPHQWV ZLWK ELQG YDULDEOHV 1H[W ZKHQ DFWXDO GDWD DUH DYDLODEOH RQO\ WKH H[HFXWH VWHS DQG IHWFK VWHS IRU TXHULHV QHHGV WR EH SHUIRUPHG (YHQ WKRXJK 2UDFOH KDV UHFRPPHQGHG WKLV DSSURDFK PDQ\ DSSOLFDWLRQV IDLO WR IROORZ WKLV RU RQO\ IROORZV WKLV UDUHO\ +HQFH DSSOLFDWLRQV ZRXOG HLWKHU RSHQ DQG FORVH FXUVRUV FRQWLQXRXVO\ RU WKH\ ZRXOG UHXVH D VLQJOH FXUVRU ZLWK GLIIHUHQW 64/ VWDWHPHQWV W\SLFDOO\ FDXVLQJ DW OHDVW D VRIW SDUVH LQ PDQ\ FDVHV D KDUG SDUVH 7KH 2UDFOH VWDUWXS SDUDPHWHU VHVVLRQBFDFKHGBFXUVRUV FDQ EH XVHG WR PRGLI\ WKLV EHKDYLRU 7KH SDUDPHWHU LV VHW WR DQ LQWHJHU YDOXH DQG VHWWLQJ LW ZLOO LPSO\ VRPH RI WKH VHUYHU VLGH FRQWH[W DVVRFLDWHG ZLWK 64/ VWDWHPHQWV ZLOO EH NHSW HYHQ ZKHQ WKH FOLHQW VLGH SHUIRUPV D FXUVRU FORVH RU UHXVHV D FXUVRU ZLWK D QHZ 64/ VWDWHPHQW 7KH YDOXH RI WKH SDUDPHWHU WHOOV KRZ PDQ\ 64/ VWDWHPHQWV SHU VHVVLRQ VKRXOG EH WUHDWHG OLNH WKLV 3OHDVH QRWH WKDW 2UDFOH )RUPV FORVHV DOO FXUVRUV ZKHQ D EORFN LV H[LWHG KHQFH W\SLFDO 2UDFOH )RUPV DSSOLFDWLRQV ZLOO EHQHILW IURP XVLQJ VHVVLRQBFDFKHGBFXUVRUV )RU ZHOO ZULWWHQ DSSOLFDWLRQV ZKHUH WKH H[HFXWH VWHS LV UHSHDWHG IRU RQH RU PRUH FXUVRUV WKDW DUH RSHQHG DQG KDYH 64/ VWDWHPHQWV SDUVHG RQO\ RQFH WKHUH LV VRPH SURFHVVLQJ WDNLQJ SODFH WR DOORFDWH UXQWLPH PHPRU\ LH PHPRU\ WKDW LV QHHGHG GXULQJ WKH H[HFXWH SKDVH RQO\ %\ VHWWLQJ WKH FXUVRUBVSDFHBIRUBWLPH SDUDPHWHU

Efficient use of bind variables, cursor_sharing and related cursor parameters Page 6

WR WUXH WKH GHIDXOW EHLQJ IDOVH  DOORFDWLRQ RI WKLV PHPRU\ LV GRQH RQO\ RQFH DW WKH ILUVW H[HFXWH ZKLFK LPSURYHV SHUIRUPDQFH DW WKH H[SHQVH RI XVLQJ PRUH PHPRU\ 'XH WR WKH RYHUKHDG LQ PHPRU\ XVDJH WKLV SDUDPHWHU VKRXOG RQO\ EH XVHG LI \RXU DSSOLFDWLRQ KDV D ZHOO FRQVWUDLQHG VHW RI 64/ WKDW ILWV LQ WKH VKDUHG SRRO
RESULTS AND BEST PRACTICES

,Q WKH FRQWH[W RI WKLV ZKLWH SDSHU DSSOLFDWLRQV WKDW IUHTXHQWO\ H[HFXWH VLPLODU 64/ VWDWHPHQWV LH 64/ VWDWHPHQWV WKDW DUH RQO\ GLIIHUHQW LQ OLWHUDOV DUH SXW LQWR WKH IRXU FDWHJRULHV  $SSOLFDWLRQV QRW XVLQJ ELQG YDULDEOHV 7KLV W\SH RI SURJUDPPLQJ LV IUHTXHQWO\ VHHQ ZKHQ DSSOLFDWLRQ GHYHORSHUV KDYH QRW EHHQ DZDUH RI WKH LPSRUWDQFH RI UHGXFLQJ WKH QXPEHU RI SDUVHV RU ZKHQ DSSOLFDWLRQV KDYH EHHQ PLJUDWHG IURP RWKHU HQYLURQPHQWV  $SSOLFDWLRQV GRLQJ DOO VWHSV FXUVRU RSHQ SDUVH ZLWK ELQG YDULDEOHV H[HFXWH IHWFK DQG FORVH IRU HDFK LQGLYLGXDO 64/ VWDWHPHQW 7KLV LV WKH EHKDYLRU 2UDFOH )RUPV ZKHQ EORFNV DUH HQWHUHG DQG H[LWHG DQG LQ QHZHU FRGH QDWLYH G\QDPLF 64/ RI WKH 3/64/ ODQJXDJH XVHV WKLV W\SH RI SURJUDPPLQJ 7KH EHQHILW RI XVLQJ ELQG YDULDEOHV LQ WKLV ZD\ KDV QRW EHHQ REYLRXV IRU 2&, DQG 3UHFRPSLOHU SURJUDPPHUV DQG LV UDUHO\ WKHUHIRUH VHHQ LQ WKHVH HQYLURQPHQW  $SSOLFDWLRQV RSHQLQJ FXUVRUV RQFH DQG UHSHDWHGO\ GRLQJ WKH VXEVHTXHQW VWHSV SDUVH ZLWK ELQG YDULDEOHV H[HFXWH DQG IHWFK IRU HDFK 64/ VWDWHPHQW 7KLV W\SH RI DSSOLFDWLRQ LV RIWHQ VHHQ ZKHQ XVLQJ WKH 2UDFOH 3UHFRPSLOHUV ZLWK WKH RSWLRQV +2/'B&85625 12 DQG 5(/($6(B&85625 12 ZKLFK LV WKH GHIDXOW RU ZKHQ XVLQJ WKH '%06B64/ SDFNDJH IURP 3/64/  $SSOLFDWLRQV RSHQLQJ D FXUVRU DQG SDUVLQJ ZLWK ELQG YDULDEOHV RQO\ RQFH IRU HDFK GLVWLQFW 64/ VWDWHPHQW IROORZHG E\ UHSHDWHG H[HFXWHV DQG IHWFKHV IRU TXHULHV  7KLV LV WKH PRVW HIILFLHQW ZD\ WR ZULWH DSSOLFDWLRQV UHSHDWHGO\ H[HFXWLQJ WKH VDPH 64/ VWDWHPHQWV DQG LW LV W\SLFDOO\ VHHQ LQ ZHOO GHVLJQHG DSSOLFDWLRQV XVLQJ 2UDFOH &DOO ,QWHUIDFH RU WKH 3UHFRPSLOHUV 6SHFLILFDOO\ IRU WKH 3UHFRPSLOHUV XVLQJ WKH RSWLRQV +2/'B&85625 <(6 5(/($6(B&85625 12 IRU VSHFLILF 64/ VWDWHPHQWV RU JHQHUDOO\ VHWWLQJ 0$;23(1&856256 VXIILFLHQWO\ KLJK FDXVHV WKLV EHKDYLRU IRU LPSOLFLW FXUVRUV 3/64/ XVLQJ FXUVRU IRU ORRSV RU H[SOLFLW FXUVRUV ZLWK VWDWLF 64/ DUH DOVR XVLQJ WKLV DSSURDFK $SSOLFDWLRQ SHUIRUPDQFH FDQ JHQHUDOO\ EH YLHZHG DV UHVSRQVH WLPH SHUIRUPDQFH LH WKH DFWXDO WLPH WDNHQ IRU HDFK H[HFXWLRQ RI D 64/ VWDWHPHQW DQG DV WKURXJKSXW SHUIRUPDQFH RU VFDODELOLW\ LH WKH DELOLW\ WR UXQ PXOWLSOH FRSLHV RI WKH DSSOLFDWLRQ FRQFXUUHQWO\ %RWK RI WKHVH SHUIRUPDQFH PHWULFV KDYH EHHQ WHVWHG ZLWK WKH GLIIHUHQW W\SH RI DSSOLFDWLRQ FDWHJRULHV DQG ZLWK GLIIHUHQW VFHQDULRV RI WKH FXUVRUBVKDULQJ DQG VHVVLRQBFDFKHGBFXUVRUV SDUDPHWHUV $GYLVHV IRU HDFK RI WKH IRXU FDWHJRULHV RI DSSOLFDWLRQV OLVWHG DERYH LQ FRPELQDWLRQ ZLWK WKH WKUHH VWDUWXS SDUDPHWHUV PHQWLRQHG DUH VKRZQ LQ WKH WDEOH EHORZ 7KH DSSHQGL[

Efficient use of bind variables, cursor_sharing and related cursor parameters Page 7

FRQWDLQV VRPH DFWXDO UHVXOWV RI WHVWV WKDW KDYH EHHQ GHVLJQHG VSHFLILFDOO\ WR GHPRQVWUDWH WKLV

Application category

General behavior

Cursor_sharing force or session_cached_ cursor_space_for_time similar cursors sufficiently high true 

1RW XVLQJ ELQG YDULDEOHV DW DOO

*HQHUDOO\ SRRU UHVSRQVH *RRG LPSURYHPHQW RI 1R H[WUD EHQHILW WLPH DQG VFDODELOLW\ ,V UHVSRQVH WLPH DQG KRZHYHU UHFRPPHQGHG VFDODELOLW\ DOWKRXJK QRW IRU '66 DSSOLFDWLRQV TXLWH DV JRRG DV ZULWLQJ DSSOLFDWLRQV XVLQJ WKDW KDYH OLWWOH RU QR FDWHJRU\  RU  UHSHWLWLRQ RI 64/ VWDWHPHQWV

QR HIIHFW 

&XUVRU RSHQ SDUVH 5HVSRQVH WLPH UHODWLYHO\ 1R H[WUD EHQHILW JRRG GXH WR FXUVRU ZLWK ELQG YDULDEOHV H[HFXWH IHWFK DQG FORVH VKDULQJ LQ OLEUDU\ FDFKH IRU HDFK 64/ VWDWHPHQW OLPLWHG VFDODELOLW\ GXH WR UHSHDWHG RSHQFORVH DQG VRIW SDUVH  &XUVRU RSHQ RQFH UHSHDWLQJ SDUVH ZLWK ELQG YDULDEOHV H[HFXWH IHWFK IRU HDFK 64/ VWDWHPHQW 5HVSRQVH WLPH UHODWLYHO\ 1R H[WUD EHQHILW JRRG EXW VFDODELOLW\ VWLOO OLPLWHG GXH WR VRIW SDUVH 6OLJKWO\ EHWWHU WKDQ FDWHJRU\  DV RSHQFORVH RI FXUVRU LV QRW UHSHDWHG 1R H[WUD EHQHILW

,PSURYHV UHVSRQVH WLPH QR HIIHFW DQG VFDODELOLW\ DV WKH VHUYHU NHHSV FXUVRUV FDFKHG

,PSURYHV UHVSRQVH WLPH QR HIIHFW DQG VFDODELOLW\ DV WKH VHUYHU NHHSV FXUVRUV FDFKHG

+LJKHVW SRVVLEOH  &XUVRU RSHQ DQG SDUVH ZLWK ELQG YDULDEOHV UHVSRQVH WLPH DQG RQFH UHSHDWHG H[HFXWHV VFDODELOLW\ IHWFK

1R H[WUD EHQHILW

$GGLWLRQDO LPSURYHPHQW WR VFDODELOLW\

Best practices

7KH WHVWV GHWDLOHG LQ DSSHQGL[ $ GHPRQVWUDWH WKDW WKH QHZ SDUDPHWHU FXUVRUBVKDULQJ WKDW LV LQWURGXFHG LQ 2UDFOHL UHOHDVH  KDV D JRRG SHUIRUPDQFH LPSDFW RQ DSSOLFDWLRQV ZULWWHQ ZLWKRXW ELQG YDULDEOHV ,Q SDUWLFXODU WKH UHVSRQVH WLPH RI DSSOLFDWLRQV WKDW IUHTXHQWO\ UHSHDW 64/ VWDWHPHQWV RQO\ GLIIHULQJ LQ OLWHUDOV FDQ KDYH D GUDPDWLF LQFUHDVH ,Q DGGLWLRQ WR WKH SHUIRUPDQFH LPSURYHPHQWV VKRZQ XVLQJ WKLV QHZ SDUDPHWHU DOVR GHFUHDVHV PHPRU\ XVDJH DV PRUH 64/ VWDWHPHQW VKDULQJ WDNHV SODFH +RZHYHU DV VRIW SDUVLQJ VWLOO WDNHV SODFH DSSOLFDWLRQV ZLWKRXW ELQG YDULDEOHV ZLOO VWLOO VHH VFDODELOLW\ SUREOHPV DOEHLW DW D KLJKHU OHYHO RI WKURXJKSXW $GGLWLRQDOO\ WKH WHVWV VKRZ WKDW VHWWLQJ WKH VHVVLRQBFDFKHGBFXUVRUV SDUDPHWHU WR DQ DSSURSULDWH YDOXH FDQ KDYH VRPH VFDODELOLW\ LPSURYHPHQWV RQ FHUWDLQ W\SHV RI DSSOLFDWLRQV LQ SDUWLFXODU WKRVH WKDW GR XVH ELQG YDULDEOHV EXW GR LW ZLWK D FXUVRU RSHQFORVH RU D VRIW SDUVH IRU HDFK 64/ VWDWHPHQW $SSURSULDWH YDOXHV IRU WKLV

Efficient use of bind variables, cursor_sharing and related cursor parameters Page 8

SDUDPHWHU LV W\SLFDOO\ EHWZHHQ WKH QXPEHU RI IUHTXHQWO\ H[HFXWHG 64/ VWDWHPHQWV SHU DSSOLFDWLRQ SURJUDP DQG WKH YDOXH RI WKH RSHQBFXUVRUV VWDUWXS SDUDPHWHU )RU ZHOO GHVLJQHG DSSOLFDWLRQV WKDW GR PXOWLSOH H[HFXWHV RI D SDUVHG 64/ VWDWHPHQW  VHWWLQJ FXUVRUBVSDFHBIRUBWLPH FDQ PDNH VRPH IXUWKHU LPSURYHPHQW WR VFDODELOLW\ DW WKH H[SHQVH RI VRPH PRUH PHPRU\ RYHUKHDG 7KH IROORZLQJ JHQHUDO UHFRPPHQGDWLRQV VKRXOG EH IROORZHG IRU DSSOLFDWLRQ SURJUDPPLQJ
The Oracle startup parameters cursor_sharing and session_cached_cursors allow application programmers some relaxation on the guidelines for proper application design. However, to fully get the scalability and performance of the Oracle database, applications should be designed according to the guidelines.

• 64/ VWDWHPHQWV WKDW DUH UHSHDWHGO\ H[HFXWHG ZLWKLQ WKH VDPH PRGXOH RI WKH DSSOLFDWLRQ VKRXOG EH DVVRFLDWHG ZLWK VSHFLILF FXUVRUV ZKLFK DUH RSHQHG RQFH KDYH WKH 64/ VWDWHPHQW ZLWK ELQG YDULDEOHV SDUVHG RQFH DQG DUH UHSHDWHGO\ H[HFXWHG 7KLV SURYLGHV WKH EHVW SRVVLEOH UHVSRQVH WLPH DQG VFDODELOLW\ 7KLV FDQ EH DFKLHYHG E\ XVLQJ H[SOLFLW FXUVRUV LQ 2UDFOH 3UHFRPSLOHU SURJUDPV DQG E\ SURSHUO\ XVLQJ VWDWHPHQW KDQGOHV LQ 2UDFOH &DOO ,QWHUIDFH SURJUDPV 2UDFOH 3UHFRPSLOHU SURJUDPV XVLQJ LPSOLFLW FXUVRUV VKRXOG UXQ ZLWK +2/'B&85625 <(6 5(/($6(B&85625 12 IRU VSHFLILF 64/ VWDWHPHQWV RU JHQHUDOO\ ZLWK 0$;23(1&856256 VHW WR D QXPEHU VXIILFLHQWO\ KLJK WR NHHS DOO IUHTXHQWO\ H[HFXWHG FXUVRUV RSHQ WKH GHIDXOW YDOXH RI  LV W\SLFDOO\ WRR ORZ 3/64/ FRGH KDV WKLV EHKDYLRU ZKHQ LW XVHV FXUVRU IRU ORRSV RU GHFODUH FXUVRUV ZLWK VWDWLF 64/ VWDWHPHQWV • 64/ VWDWHPHQWV WKDW DUH UHSHDWHGO\ H[HFXWHG IURP DQ\ZKHUH ZLWKLQ WKH DSSOLFDWLRQ DQG IRU ZKLFK WKH DERYH PHWKRG FDQQRW EH XVHG VKRXOG EH H[HFXWHG XVLQJ ELQG YDULDEOHV ,I WKLV LV QRW SRVVLEOH RU LI DQ DOUHDG\ ZULWWHQ DSSOLFDWLRQ QHHG WR XVH WKH EHQHILWV RI ELQG YDULDEOH WKH FXUVRUBVKDULQJ SDUDPHWHU FDQ EH VHW WR IRUFH RU VLPLODU 6HH KRZHYHU WKH FRPPHQW EHORZ RQ GHFLVLRQ VXSSRUW W\SH DSSOLFDWLRQV • )UHTXHQW VRIW SDUVLQJ RI 64/ VWDWHPHQWV RU RSHQFORVH RI FXUVRUV VKRXOG JHQHUDOO\ EH DYRLGHG )RU DSSOLFDWLRQV WKDW QHYHUWKHOHVV GR WKLV VHWWLQJ WKH VHVVLRQBFDFKHGBFXUVRUV SDUDPHWHU FDQ EULQJ VRPH EHQHILW WR VFDODELOLW\ EXW WKH SDUDPHWHU VKRXOG QRW EH XVHG DV D VXEVWLWXWH IRU SURSHU DSSOLFDWLRQ SURJUDPPLQJ • $SSOLFDWLRQV VKRXOG QRW VWRS XVLQJ ELQG YDULDEOHV DOWRJHWKHU DQG FRPSOHWHO\ UHO\ RQ XVLQJ WKH FXUVRUBVKDULQJ SDUDPHWHU 7KH PDMRU EHQHILW RI WKLV SDUDPHWHU LV WR LPSURYH SHUIRUPDQFH RI H[LVWLQJ DSSOLFDWLRQV WKDW ZHUH QRW XVLQJ ELQG YDULDEOHV E\ DYRLGLQJ WKH H[SHQVLYH KDUG SDUVH 1RWH WKDW VFDODELOLW\ SUREOHPV ZLWK 64/ SURFHVVLQJ DOVR FRPHV IURP WKH VRIW SDUVH DQG WKH VRIW SDUVH LV QRW DYRLGHG ZKHQ XVLQJ WKLV SDUDPHWHU $OVR QRWH WKDW DSSOLFDWLRQV WKDW GR QRW DFWXDOO\ KDYH DQ\ UHSHDWHG H[HFXWLRQ RI 64/ VWDWHPHQWV RQO\ GLIIHULQJ LQ OLWHUDOV RU DSSOLFDWLRQV WKDW GR QRW KDYH DFWXDO SUREOHPV ZLWK SDUVLQJ GR QRW EHQHILW IURP XVLQJ WKLV SDUDPHWHU • $V DQ H[FHSWLRQ 64/ VWDWHPHQWV LQ SDUWLFXODU FRPSOH[ 64/ VWDWHPHQWV WKDW DUH UDUHO\ H[HFXWHG PRUH WKDQ RQFH VKRXOG EH SDUVHG XVLQJ OLWHUDOV DQG QRW

Efficient use of bind variables, cursor_sharing and related cursor parameters Page 9

XVLQJ ELQG YDULDEOHV WR DOORZ WKH RSWLPL]HU WR JHW IXOO EHQHILW RI WKH DYDLODEOH VWDWLVWLFV 3OHDVH UHIHU WR WKH VSHFLDO FRQVLGHUDWLRQV VHFWLRQ EHORZ IRU GHWDLOV 1RWH WKDW LQ DGGLWLRQ WR WKH SHUIRUPDQFH EHQHILW RI XVLQJ WKH FXUVRUBVKDULQJ SDUDPHWHU WKH DFWXDO VKDULQJ RI 64/ VWDWHPHQWV WKDW ZRXOG RWKHUZLVH EH GLIIHUHQW GXH WR GLIIHUHQFHV LQ OLWHUDOV LPSOLHV D PHPRU\ VDYLQJ DV ZHOO $OVR QRWH WKDW VRPH DSSOLFDWLRQV RU VRPH SDUWV RI DQ DSSOLFDWLRQ XVLQJ OLWHUDOV PD\ QRW ZDQW WR UXQ ZLWK WKLV SDUDPHWHU VHW WR D YDOXH GLIIHUHQW IURP WKH GHIDXOW 7KLV LV LQ SDUWLFXODU WUXH LI \RXU DSSOLFDWLRQ XVHV 64/ VWDWHPHQWV ZLWK OLWHUDOV WKDW DFWXDOO\ GR QRW FKDQJH IURP RQH LQYRFDWLRQ WR WKH QH[W $Q H[DPSOH RI VXFK D 64/ VWDWHPHQW PD\ EH RQH ZLWK DQ ,1OLVW VXFK DV select * from elements where status in (1,4)
SPECIAL CONSIDERATIONS

7KH XVH RI ELQG YDULDEOHV LQ 64/ VWDWHPHQWV HLWKHU GLUHFWO\ FRGHG LQ WKH DSSOLFDWLRQ RU LQGLUHFWO\ YLD WKH FXUVRUBVKDULQJ SDUDPHWHU GRHV JHQHUDOO\ LPSURYH SHUIRUPDQFH +RZHYHU WKHUH DUH FDVHV ZKHUH XVLQJ LW HLWKHU GRHV QRW DFWXDOO\ KDYH DQ\ LPSDFW DW DOO RQ SHUIRUPDQFH RU PHPRU\ FRQVXPSWLRQ RU ZKHUH LWV XVH ZRXOG DFWXDOO\ KDYH D ULVN RI GHFUHDVLQJ SHUIRUPDQFH 7KLV VHFWLRQ GLVFXVVHV WKHVH LVVXHV DQG GLVFXVVHV KRZ WKH\ DUH VROYHG LQ 2UDFOHL
Considerations for decision support systems

'HFLVLRQ VXSSRUW V\VWHPV VXFK DV GDWD ZDUHKRXVH DSSOLFDWLRQV DUH FKDUDFWHUL]HG E\ VPDOO QXPEHUV RI XVHUV H[HFXWLQJ FRPSOH[ 64/ VWDWHPHQWV ZLWK OLWWOH RU QR UHSHWLWLRQ LQ ZKLFK FDVH WKHUH LV QR DFWXDO VKDULQJ LQ WKH OLEUDU\ FDFKH SRVVLEOH )RU VXFK FRPSOH[ 64/ VWDWHPHQWV LW LV DOVR LPSRUWDQW WKDW WKH RSWLPL]HU KDV DOO QHFHVVDU\ LQIRUPDWLRQ DYDLODEOH WR FKRRVH WKH ULJKW DFFHVV SODQ DQG LQ 2UDFOHL WKLV LV RQO\ SRVVLEOH LI ELQG YDULDEOHV DUH QRW EHLQJ XVHG ,Q 2UDFOHL XVLQJ D ELQG YDULDEOH KLGHV WKH DFWXDO YDOXH WR WKH RSWLPL]HU DQG LW ZLOO WKHUHIRUH XVH KHXULVWLFV WR JHQHUDWH WKH EHVW DFFHVV SODQ LQ VWHDG RI SRWHQWLDOO\ XVLQJ LQIRUPDWLRQ DERXW GDWD GLVWULEXWLRQ )RU WKLV W\SH RI DSSOLFDWLRQ WKH PDMRU DPRXQW RI UHVRXUFHV VSHQW LV QRW LQ WKH SDUVH RU RSWLPL]DWLRQ VWHS DQG KHQFH UHGXFLQJ WKHVH VWHSV KDYH OLWWOH LPSDFW RQ WKH RYHUDOO SHUIRUPDQFH 5DWKHU LW LV LPSRUWDQW WKDW WKH RSWLPL]DWLRQ VWHS LV GRQH ZLWK WKH EHVW SRVVLEOH GDWD DYDLODEOH LQ RUGHU IRU WKH VXEVHTXHQW H[HFXWH VWHS ZKLFK FDQ YHU\ ZHOO UXQ IRU PLQXWHV RU KRXUV WR EH DV HIILFLHQW DV SRVVLEOH 7KLV LV LQ SDUWLFXODU WUXH LI \RX KDYH FROOHFWHG FROXPQ VWDWLVWLFV WKDW PDNH GHWDLOHG LQIRUPDWLRQ DERXW WKH GDWD DYDLODEOH WR WKH RSWLPL]HU 

'DWD GLVWULEXWLRQ LV DVVXPHG WR EH OLQHDU DIWHU QRUPDO WDEOH RU LQGH[ VWDWLVWLFV KDYH EHHQ JHQHUDWHG ,I WDEOH VWDWLVWLFV DUH JHQHUDWHG RQ D FROXPQ EDVLV 2UDFOH VDYHV GHWDLOHG LQIRUPDWLRQ DERXW GDWD GLVWULEXWLRQ DV KLVWRJUDPV 3OHDVH UHIHU WR WKH '%06B67$76 SDFNDJH LQ WKH 2UDFOH 6XSSOLHG 3/64/ 3DFNDJHV 5HIHUHQFH GRFXPHQW

Efficient use of bind variables, cursor_sharing and related cursor parameters Page 10

7KHUHIRUH IRU WKLV W\SH RI DSSOLFDWLRQV UXQQLQJ ZLWK 2UDFOHL ELQG YDULDEOHV VKRXOG QRW EH XVHG DQG WKH FXUVRUBVKDULQJ SDUDPHWHU VKRXOG EH VHW WR H[DFW WR QRW KDYH WKH FXUVRU DQG WKHUHIRUH WKH H[HFXWLRQ SODQ VKDUHG
Bind variable peeking in Oracle9i

,Q 2UDFOHL WKH RSWLPL]HU LV HQKDQFHG WR SHHN DW DFWXDO YDOXHV RI ELQG YDULDEOHV LI WKHVH DUH DYDLODEOH %\ GRLQJ WKLV WKH RSWLPL]HU FDQ XVH JHQHUDWHG WDEOHLQGH[ RU FROXPQOHYHO VWDWLVWLFV ZKHQ ELQG YDULDEOHV DUH XVHG 7KLV ZLOO EHQHILW ERWK DSSOLFDWLRQV WKDW WKHPVHOYHV DUH ZULWWHQ WR XVH ELQG YDULDEOHV DQG DSSOLFDWLRQV WKDW KDYH KDG OLWHUDOV UHSODFHG E\ ELQG YDULDEOHV XVLQJ WKH FXUVRUBVKDULQJ SDUDPHWHU :KHQ XVHG ZLWK FXUVRUBVKDULQJ WKLV EHQHILWV FDVHV OLNH WKH RQH SUHYLRXVO\ PHQWLRQHG select * from elements where status in (1,4) ZKHUH WKH FXUVRUBVKDULQJ IRUFH ZLOO FDXVH WKH WZR OLWHUDOV WR EH UHSODFHG E\ ELQG YDULDEOHV EXW WKH RSWLPL]HU ZLOO VHH WKHLU YDOXHV DQG FXUVRU VKDULQJ FDQ VDIHO\ EH XVHG
Cursor_sharing in Oracle9i

,Q 2UDFOHL WKH FXUVRUBVKDULQJ SDUDPHWHU FDQ KDYH WKH YDOXH VLPLODU ZKLFK ZLOO FDXVH WKH FXUVRU VKDULQJ IDFLOLW\ WR KDQGOH GHFLVLRQ VXSSRUW TXHULHV ZHOO &RQVLGHU WKH WZR 64/ VWDWHPHQWV EHORZ DVVXPLQJ WKH HPS WDEOH KDV D SULPDU\ NH\ LQGH[ RQ WKH HPSQR FROXPQ DQG DQ RUGLQDU\ LQGH[ RQ WKH GHSWQR FROXPQV select * from emp where empno=1234 DQG select * from emp where deptno<400 ,Q WKH ILUVW FDVH ZLWK WKH SULPDU\ NH\ ORRNXS WKH GHFLVLRQV PDGH E\ WKH RSWLPL]HU ZRXOG QRW FKDQJH LI WKH OLWHUDO  LV UHSODFHG E\ DQRWKHU OLWHUDO VXFK DV  +HQFH FXUVRUV FDQ EH VDIHO\ VKDUHG ZLWKRXW DQ\ HIIHFW RQ EHVW RSWLPL]DWLRQ DQG OLWHUDOV OLNH WKHVH DUH FDOOHG VDIH OLWHUDOV ,Q WKH VHFRQG FDVH ZLWK WKH LQHTXDOLW\ FRQGLWLRQ KRZHYHU WKH RSWLPL]HU LV OLNHO\ WR JHQHUDWH D GLIIHUHQW H[HFXWLRQ SODQ LI WKH OLWHUDO  LV UHSODFHG E\ WKH OLWHUDO  +HQFH DOWKRXJK WKH WZR 64/ VWDWHPHQWV SDUVH LGHQWLFDO WKH\ VKRXOG QRW KDYH D VKDUHG H[HFXWLRQ SODQ DQG VXFK OLWHUDOV DUH FDOOHG XQVDIH OLWHUDOV ,Q 2UDFOHL VXFK GLVWLQFWLRQV LV GRQH E\ WKH FXUVRU VKDULQJ PHFKDQLVP ZKHQ WKH YDOXH RI WKH FXUVRUBVKDULQJ SDUDPHWHU LV VLPLODU 

,Q WKH FXUUHQW LPSOHPHQWDWLRQ RI WKH FXUVRU VKDULQJ IHDWXUH 2UDFOH ZLOO VKDUH WKH SDUHQW FXUVRUV ZKHQHYHU WKH FXUVRUBVKDULQJ SDUDPHWHU LV QRW H[DFW :KHQ WKH SDUDPHWHU LV VLPLODU DYDLODEOH LQ 2UDFOHL GLIIHUHQW FKLOG FXUVRUV ZLOO EH XVHG WR SURYLGH GLIIHUHQW H[HFXWLRQ SODQV IRU HDFK GLVWLQFW YDOXH RI D OLWHUDO LI WKH DFWXDO YDOXH RI WKDW OLWHUDO KDV LQIOXHQFH RQ WKH RSWLPL]DWLRQ ,I QRQH RI WKH DFWXDO YDOXHV RI WKH OLWHUDOV KDYH LQIOXHQFH WKH RSWLPL]DWLRQ RQO\ RQH FKLOG FXUVRU ZLOO EH XVHG :KHQ WKH

Efficient use of bind variables, cursor_sharing and related cursor parameters Page 11

8VLQJ WKH YDOXH VLPLODU IRU FXUVRUBVKDULQJ DOVR KDV WKH EHQHILW RI PDNLQJ FXUVRU VKDULQJ EHKDYH ZHOO ZKHQ 64/ VWDWHPHQWV DUH XVLQJ OLWHUDOV WKDW GR QRW DFWXDOO\ FKDQJH IURP RQH LQYRFDWLRQ WR DQRWKHU DV LQ WKH H[DPSOH ZLWK DQ ,1OLVW DERYH $GGLWLRQDOO\ 2UDFOHL DGGV D 64/ KLQW WKDW FDXVHV WKH FXUVRU VKDULQJ QRW WR WDNH SODFH 7KH KLQW FXUVRUBVKDULQJBH[DFW LV SXW LQ WKH XVXDO SODFH LQVLGH D FRPPHQW LPPHGLDWHO\ IROORZLQJ WKH 64/ NH\ZRUG VXFK DV VHOHFW select /*+cursor_sharing_exact*/ * from . . . ZLWK WKH LPSOLFDWLRQ WKDW QR FXUVRU VKDULQJ ZLOO EH XVHG HYHQ ZKHQ WKH FXUVRUBVKDULQJ SDUDPHWHU LV VHW WR WKH YDOXH VLPLODU RU WR IRUFH $OWKRXJK LW ZRXOG VHHP DWWUDFWLYH WR VHW FXUVRUBVKDULQJ WR VLPLODU LQ 2UDFOHL IRU ERWK 2/73 DQG GHFLVLRQ VXSSRUW V\VWHPV WKHUH DUH FDVHV ZKHUH WKLV ZRXOG QRW EH EHQHILFLDO :KHQ VLPLODU LV XVHG LQ FDVHV ZKHUH 64/ VWDWHPHQWV KDYH OLWHUDOV ZKRVH DFWXDO YDOXH GRHV LQIOXHQFH RSWLPL]DWLRQ DQG ZKRVH YDOXH GRHV FKDQJH ZLWK PRVW RU HDFK VWDWHPHQW WKH SHUIRUPDQFH ZLOO EH HTXLYDOHQW WR WKH SHUIRUPDQFH ZLWKRXW FXUVRU VKDULQJ LH WKH GHIDXOW YDOXH RI FXUVRUBVKDULQJ H[DFW  ZKLFK GRHV D KDUG SDUVH IRU HDFK VWDWHPHQW 7KHUHIRUH FXUVRU VKDULQJ VKRXOG QRW EH XVHG LQ VXFK FDVHV ,Q WKH FDVH ZKHUH WKH DFWXDO YDOXH RI OLWHUDOV RQO\ FKDQJH DPRQJ IHZ GLIIHUHQW RQHV FXUVRUBVKDULQJ VLPLODU FDQ KDYH WKH HIIHFW RI LQFUHDVLQJ VFDODELOLW\ DQG UHVSRQVH WLPH

SDUDPHWHU LV IRUFH RQO\ RQH FKLOG FXUVRU DQG RQH H[HFXWLRQ SODQ ZLOO EH XVHG WKLV SODQ ZLOO EH EDVHG RQ KHXULVWLFV LQ 2UDFOHL DQG RQ WKH ILUVW VHHQ YDOXHV RI OLWHUDOV LQ 2UDFOHL 7KH XVH RI SDUHQW DQG FKLOG FXUVRUV FDQ EH VHHQ LQ GHWDLO XVLQJ WKH Y VTOBSODQ IL[HG YLHZ ZKLFK H[LVWV LQ 2UDFOHL

Efficient use of bind variables, cursor_sharing and related cursor parameters Page 12

CONCLUSION
Oracle continues to support applications, that will scale to tens of thousands of users by providing best practices design recommendations. Additionally, new features are added and enhanced, that will support applications, that have been designed with less focus on scalability.

,Q WKH ,QWHUQHW DJH SUHGLFWLRQV RQ VL]HV RI GDWDEDVH DSSOLFDWLRQV DQG QXPEHU RI DSSOLFDWLRQ XVHUV DUH UDUHO\ SRVVLEOH 7KHUHIRUH GHVLJQHUV DQG GHYHORSHUV RI DSSOLFDWLRQV DUH UHTXLUHG WR XVH DOO SRVVLEOH PHWKRGV WR SODQ IRU JURZWK DQG D JRRG XQGHUVWDQGLQJ RI KRZ V\VWHP UHVRXUFHV VXFK DV WKH GDWDEDVH DUH ZRUNLQJ LV LPSHUDWLYH 7KH 2UDFOH GDWDEDVH KDV EHHQ GHVLJQHG WR IXOO\ VXSSRUW WKHVH QHHGV E\ DOORZLQJ WHQV RU KXQGUHV RI WKRXVDQGV RI FRQFXUUHQW XVHUV +RZHYHU FHUWDLQ DSSOLFDWLRQ GHVLJQ UXOHV QHHGV WR EH DGKHUHG WR 6SHFLILFDOO\ RQ WKH WRSLF RI VKDULQJ GDWD UHODWHG WR H[HFXWLRQ RI 64/ VWDWHPHQW WKLV SDSHU H[SODLQV • +RZ DSSOLFDWLRQV VKRXOG EH GHVLJQHG WR IXOO\ H[SORUH WKH SRVVLELOLWLHV RI WKH 2UDFOH GDWDEDVH HQJLQH • +RZ WKH GDWDEDVH HQJLQH FDQ EH DGMXVWHG WR KDQGOH DSSOLFDWLRQV WKDW KDYH EHHQ SURJUDPPHG ZLWK PRUH RU OHVV IRFXV RQ VFDODELOLW\ 7KH WKUHH SDUDPHWHUV WKDW KDYH EHHQ GLVFXVVHG LQ WKLV SDSHU VKRXOG EH XVHG DFFRUGLQJ WR WKHVH JXLGHOLQHV

FXUVRUBVKDULQJ

7KLV SDUDPHWHU ZLOO LPSURYH VFDODELOLW\ DQG SHUIRUPDQFH RI DSSOLFDWLRQV ZULWWHQ XVLQJ OLWHUDOV LQ VWHDG RI ELQG YDULDEOHV LQ 64/ VWDWHPHQWV 8VLQJ WKH YDOXH IRUFH FDQ JLYH JRRG LPSURYHPHQWV LQ WKURXJKSXW SHUIRUPDQFH DQG VRPH LPSURYH PHQWV LQ VFDODELOLW\ )RU GHFLVLRQ VXSSRUW DQG GDWD ZDUHKRXVH DSSOLFDWLRQV LW VKRXOG EH XVHG ZLWK FDUH RU QRW DW DOO LQ 2UDFOHL ,Q 2UDFOHL WKH YDOXH VLPLODU LV SRVVLEOH IRU WKLV SDUDPHWHU DQG WKLV YDOXH DOORZV FXUVRU VKDULQJ WR EH XVHG LQ PDQ\ FDVHV RI GHFLVLRQ VXSSRUW DQG GDWD ZDUHKRXVH DSSOLFDWLRQV 6HWWLQJ WKLV SDUDPHWHU LV W\SLFDOO\ GHFLGHG E\ WKH 'DWDEDVH $GPLQLVWUDWRU ZKHQ UHSHDWHG KDUG SDUVLQJ RI 64/ VWDWHPHQWV RQO\ GLIIHULQJ LQ OLWHUDOV LV WDNLQJ SODFH

VHVVLRQBFDFKHGBFXUVRUV

6HWWLQJ WKLV SDUDPHWHU WR D YDOXH EHWZHHQ WKH DFWXDO QXPEHU RI FXUVRUV XVHG DQG WKH YDOXH RI WKH RSHQBFXUVRUV SDUDPHWHU FDQ SURYLGH VRPH LPSURYHPHQW LQ VFDODELOLW\ DQG WKURXJKSXW SHUIRUPDQFH ([FHSW IRU VRPH PLQRU PHPRU\ RYHKHDG WKHUH LV QR QHJDWLYH LPSDFW E\ XVLQJ WKLV SDUDPHWHU 7KH 'DWDEDVH $GPLQLVWUDWRU ZRXOG W\SLFDOO\ GHFLGH WR VHW WKLV SDUDPHWHU ZKHQ WRR PXFK VRIW SDUVLQJ LV WDNLQJ SODFH

FXUVRUBVSDFHBIRUBWLPH

:HOO ZULWWHQ DSSOLFDWLRQ FDQ IXUWKHU LQFUHDVH VFDODELOLW\ DW WKH H[SHQVH RI XVLQJ PRUH PHPRU\ E\ VHWWLQJ WKLV SDUDPHWHU WR WUXH

Efficient use of bind variables, cursor_sharing and related cursor parameters Page 13

APPENDIX: TEST RESULTS

7KLV ZKLWH SDSHU GLVFXVVHV WKH HIIHFWV RI GRLQJ 64/ SURFHVVLQJ LQ GLIIHUHQW ZD\V ZLWK GLIIHUHQW SURJUDPPLQJ PRGHOV DQG ZLWK GLIIHUHQW 2UDFOH VWDUWXS SDUDPHWHUV 7HVWV KDYH EHHQ GHVLJQHG VSHFLILFDOO\ WR VHH WKH HIIHFWV RI WKLV DQG KDV EHHQ H[HFXWHG RQ D WHVW V\VWHP ZLWK  &38V 7KH FRUH RI HDFK WHVW LV D ORRS WKDW SHUIRUPV RQH WKRXVDQG H[HFXWLRQV RI D 64/ VWDWHPHQW DQG HDFK RI WKH WHVWV KDYH EHHQ H[HFXWHG UXQQLQJ DV D VLQJOH SURJUDP RU DV    RU  FRQFXUUHQWO\ H[HFXWLQJ FRSLHV ,Q DOO FDVHV WKH DYHUDJH YDOXH RI WKH VXP RI WKH &38 WLPH XVHG DQG WKH WLPH VSHQW ZDLWLQJ IRU ODWFKHV KDV EHHQ PHDVXUHG 7KH DEVROXWH YDOXH RI WKH UHVXOWV KDV QR VLJQLILFDQFH EXW UHVXOWV FDQ EH FRPSDUHG VKRZLQJ WKH EHQHILW RI VSHFLILF DSSOLFDWLRQ SURJUDPPLQJ PRGHOV RU 2UDFOH VWDUWXS SDUDPHWHUV 7KH ILUVW WHVW LV XVLQJ ELQG YDULDEOHV DV DGYLVHG E\ 2UDFOH IRU EHVW SHUIRUPDQFH RI 2/73 W\SH DSSOLFDWLRQV DQG LW GHPRQVWUDWHV WKH HIIHFW RI WKH SURJUDPPLQJ PRGHOV WKDW GR SDUVH DQG H[HFXWH IRU HDFK VWDWHPHQW RU RQO\ GR SDUVH RQFH DQG WKH HIIHFWV RI XVLQJ WKH VHVVLRQBFDFKHGBFXUVRUV DQG FXUVRUBVSDFHBIRUBWLPH VWDUWXS SDUDPHWHUV 7KH VHFRQG DQG WKLUG WHVW GHPRQVWUDWH WKH XVH RI WKH FXUVRUBVKDULQJ SDUDPHWHU 7KH VHFRQG WHVW LV D W\SLFDO 2/73 H[DPSOH ZLWK VDIH OLWHUDOV ZKHUH QR OLWHUDO YDOXH LQIOXHQFH WKH RSWLPL]DWLRQ DQG FXUVRUBVKDULQJ IRUFH LV XVHG 7KH WKLUG WHVW LV D FDVH ZLWK DQ XQVDIH OLWHUDO ZKRVH YDOXH GRHV LQIOXHQFH RSWLPL]DWLRQ DQG FXUVRUBVKDULQJ VLPLODU LV XVHG :LWKLQ HDFK RI WKH ILUVW WZR WHVWV DOO YDOXHV FDQ EH GLUHFWO\ FRPSDUHG DV WKH DFWXDOO\ H[HFXWHG 64/ VWDWHPHQW LV WKH VDPH +RZHYHU WKH SDUWV RI WKH WKLUG WHVW DOO XVH GLIIHUHQW 64/ VWDWHPHQWV DQG WKH UHVXOWV RI WKLV FDQ WKHUHIRU QRW EH FRPSDUHG DPRQJ HDFK RWKHU RU WR WKRVH RI WKH ILUVW DQG VHFRQG WHVW 

7KH &38 WLPH LV UHWULHYHG IURP WKH 2UDFOH VWDWLVWLFV ¶&38 XVHG E\ WKLV VHVVLRQ· DQG WKH WLPH ZDLWLQJ IRU ODWFKHV IURP WKH ¶ODWFK IUHH· HYHQW

Efficient use of bind variables, cursor_sharing and related cursor parameters Page 14

Testing session_cached_cursors, cursor_space_for_time and programming model

7HVW SURJUDP XVLQJ ELQG YDULDEOHV WR GR D VLPSOH SULPDU\ NH\ EDVHG ORRNXS ZLWK GLIIHUHQW FRPELQDWLRQV RI SURJUDPPLQJ PRGHO DQG VWDUWXS SDUDPHWHUV ,Q DOO WHVWV RSHQFORVH RI WKH FXUVRU LV RXWVLGH WKH ORRS  3URJUDP GRLQJ UHSHDWHG SDUVH DQG H[HFXWH DQG QRW XVLQJ VHVVLRQBFDFKHGBFXUVRUV 3URJUDP GRLQJ UHSHDWHG SDUVH DQG H[HFXWH DQG XVLQJ VHVVLRQBFDFKHGBFXUVRUV  3URJUDP GRLQJ SDUVH RQO\ RQFH UHSHDWLQJ H[HFXWH DQG QRW XVLQJ FXUVRUBVSDFHBIRUBWLPH 3URJUDP GRLQJ SDUVH RQO\ RQFH UHSHDWLQJ H[HFXWH DQG XVLQJ FXUVRUBVSDFHBIRUBWLPH WUXH                        

Testing cursor_sharing for statements with safe literals

7HVW SURJUDP GRLQJ D VLPSOH SULPDU\ NH\ EDVHG ORRNXS HIIHFWLYHO\ WKH VDPH DV LQ WKH ILUVW WHVWV EXW XVLQJ OLWHUDOV LQ VWHDG RI ELQG YDULDEOHV $OO WHVWV GR FXUVRU RSHQFORVH RQO\ RQFH RXWVLGH WKH ORRS 

7HVW XVLQJ VDIH OLWHUDO DQG FXUVRUBVKDULQJ H[DFW LH QR FXUVRU VKDULQJ 7HVW XVLQJ VDIH OLWHUDO DQG FXUVRUBVKDULQJ IRUFH  

 

 

 

     

Efficient use of bind variables, cursor_sharing and related cursor parameters Page 15

Testing cursor_sharing for statements with unsafe literals

7HVW SURJUDP GRLQJ D TXHU\ RQ DQ LQGH[HG FROXPQ RI D WDEOH ZLWK VNHZ GDWD GLVWULEXWLRQ DQG ZLWK FROXPQ VWDWLVWLFV JDWKHUHG +HQFH VRPH TXHULHV ZLOO XVH IXOO WDEOH VFDQ DQG VRPH ZLOO XVH LQGH[ ORRNXS 7KH WHVWV VKRZ WKH HIIHFW RI KDYLQJ XQVDIH OLWHUDOV WKDW FKDQJH PRUH RU OHVV UDSLGO\ EHWZHHQ LQYRFDWLRQV LQ FRPELQDWLRQ ZLWK FXUVRUBVKDULQJ VLPLODU $OO WHVWV ZHUH GRQH ZLWK FXUVRU RSHQFORVH RXWVLGH WKH ORRS DQG UHSHDWLQJ SDUVH DQG H[HFXWH RI 64/ VWDWHPHQWV $OVR DOO WHVWV DFWXDOO\ GR XVH WKH FRUUHFW DFFHVV SODQ IXOO WDEOH VFDQ RU LQGH[ ORRNXS  GLIIHUHQFHV DUH WKHUHIRUH QRW GXH WR LQFRUUHFW DFFHVV SODQV 1RWH WKDW UHVXOWV FDQ RQO\ EH FRPSDUHG ZLWKLQ HDFK VXEJURXS LH DPRQJ UHVXOWV VHSDUDWHG E\ D GRWWHG OLQH DV WKH DFWXDO WHVW H[HFXWHG LV GLIIHUHQW EHWZHHQ WKH GLIIHUHQW VXEJURXSV KDYLQJ GLIIHUHQW UDWHV RI FKDQJH RI WKH XQVDIH OLWHUDO 5HVXOWV FDQ DOVR QRW EH FRPSDUHG WR WKRVH RI WKH SUHYLRXV WZR WHVWV 

7HVW XVLQJ UDUHO\ FKDQJLQJ XQVDIH OLWHUDO DQG QR FXUVRUBVKDULQJ 7HVW XVLQJ UDUHO\ FKDQJLQJ XQVDIH OLWHUDO DQG FXUVRUBVKDULQJ VLPLODU 7HVW ZLWK XQVDIH OLWHUDO FKDQJLQJ HYHU\  FDOOV DQG QR FXUVRUBVKDULQJ 7HVW ZLWK XQVDIH OLWHUDO FKDQJLQJ HYHU\  FDOOV DQG FXUVRUBVKDULQJ VLPLODU 7HVW ZLWK XQVDIH OLWHUDO FKDQJLQJ HYHU\  FDOOV DQG QR FXUVRUBVKDULQJ 7HVW ZLWK XQVDIH OLWHUDO FKDQJLQJ HYHU\  FDOOO DQG FXUVRUBVKDULQJ VLPLODU 7HVW ZLWK FRQWLQXRXVO\ FKDQJLQJ XQVDIH OLWHUDO DQG QR FXUVRUBVKDULQJ 7HVW ZLWK FRQWLQXRXVO\ FKDQJLQJ XQVDIH OLWHUDO DQG FXUVRUBVKDULQJ VLPLODU         

        

        

        

       

Efficient use of bind variables, cursor_sharing and related cursor parameters Page 16

Efficient use of bind variables, cursor_sharing and related cursor parameters August 2001 Author: Bjørn Engsig Contributing Authors: Cecilia Gervasio, Sanjay Kaluskar, Lex de Haan, Graham Wood, Debu Chatterjee Oracle Corporation World Headquarters 500 Oracle Parkway Redwood Shores, CA 94065 U.S.A. Worldwide Inquiries: Phone: +1.650.506.7000 Fax: +1.650.506.7200 www.oracle.com Oracle Corporation provides the software that powers the internet. Oracle is a registered trademark of Oracle Corporation. Various product and service names referenced herein may be trademarks of Oracle Corporation. All other product and service names mentioned may be trademarks of their respective owners. Copyright © 2001 Oracle Corporation All rights reserved.

Sign up to vote on this title
UsefulNot useful