ÍøÕ¾µ¼º½£ºÍøѧ Ô­´´ÂÛÎÄ Ô­´´×¨Ìâ ÍøÕ¾Éè¼Æ ×îÐÂϵͳ Ô­´´ÂÛÎÄ ÂÛÎĽµÖØ ·¢±íÂÛÎÄ ÂÛÎÄ·¢±í UIÉè¼Æ¶¨ÖÆ ÂÛÎÄ´ð±çPPT¸ñʽÅÅ°æ ÆÚ¿¯·¢±í ÂÛÎÄרÌâ
·µ»ØÍøѧÊ×Ò³
Íøѧԭ´´ÂÛÎÄ
×îÐÂÂÛÎÄ ÍƼöרÌâ ÈÈÃÅÂÛÎÄ ÂÛÎÄרÌâ
µ±Ç°Î»Ö㺠Íøѧ > ½»Ò×´úÂë > SQLÓï·¨ > ÕýÎÄ

sqlÐÔÄܵ÷Õû

ÂÛÎĽµÖØÐ޸ķþÎñ¡¢¸ñʽÅÅ°æµÈ »ñÈ¡ÂÛÎÄ ÂÛÎĽµÖؼ°ÅÅ°æ ÂÛÎÄ·¢±í Ïà¹Ø·þÎñ

    «e¨¥
    ¥»¤å.¥D­n¤¶.ÉOSQL.¾ã¦³.ªº.®e¡A.®e¯A¤Î¦h.¤è­±¡GSQL.¥y.¦æªº.µ{¡B
    ORACLEɬ¤Æ¾¹¡Aªí¤§.ªº..¡A¦p¦ó±o¨ìSQL.¦æ.¦E¡A¦p¦ó¤ÀªR.¦æ.¦Eµ¥.®e¡A.
    ¦Ó¥Ñ.¨ì²`ªº¤è¦¡¤F¸ÑSQLɬ¤Æªº.µ{¡A¨Ï¤j®a³v¨B¨B¤JSQL.¾ã¤§.¡AµM¦Z§A..
    .¡K¡K¡C
    
    .¤å.ªº¤£.¤§.¡A·q.«ü¥X¡A¥H«K.¤@¨B§ï¥¿¡C..¨ä.©¹§Úªº«H½c¡G
    xu_yu_jin2000@sina¡C
    
    ¦pªG¤Þ¥Î¥»¤åªº.®e¡A.µÛ¦W¥X.¡I
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    §@ªÌ¡G®}¥Éª÷
    MSN¡Gsunny_xyj@hotmial
    Email:xu_yu_jin2000@sina
    ¤é´Á¡G2005.12.12
    ¬¡.¤_:cnoug.orgSunnyXu
    ¥Ø.
    
    
    ²Ä1³¹©Ê¯à.¾ã.­z
    ²Ä2³¹¦³®Äªº.¥Î..
    ²Ä3³¹SQL.¥y.²zªº.µ{
    ²Ä4³¹ORACLEªºÉ¬¤Æ¾¹
    ²Ä5³¹ORACLEªº.¦æ.¦E
    ..¸ô.(¤èªk)--accesspath
    ªí¤§.ªº.±µ
    ¦p¦ó.¥Í.¦æ.¦E
    ¦p¦ó¤ÀªR.¦æ.¦E
    ¦p¦ó¤z..¦æ.¦E--¨Ï¥Îhints´£¥Ü
    ¨ãÊ^®×¨Ò¤ÀªR
    ²Ä6³¹¨ä¥¦ª`·N¨Æ.
    ªþ.
    
    
    ²Ä1³¹©Ê¯à.¾ã.­z
    Oracle.Õu.¬O°ª«×¥i.ªº.Õu..«~¡C¥»³¹´y­z.¾ãªº.µ{©M¨º¨Ç¤H..ÉOOracle
    ªA.¾¹ªº.¾ã¦³.¡A¥H¤ÎÉO.¾ã¬Û..ªº¾Þ§@¨t.µw¥ó©M.¥ó¡C¥»³¹¥]¬A¥H¤U¤è­±:
    .....¾ã¨t.?
    ..¤°¤\.­Ô.¾ã?
    ..«Ø¥ß¦³®Ä.¾ãªº¥Ø.
    ..¦b..©M...ªº.¾ã
    ...¾ã.«~¨t.
    ...±±.«~¨t.
    
    ...¾ã¨t.:
    .¤F¦³®Ä¦a.¾ã¨t.¡A­Y¤z.¤H.¥².¥æ.«H®§¦}.¯A¨ì¨t..¾ã¤¤¡A¨Ò¦p:
    ...¥Î..¤H.¥²....¥Î¨t.ªº..¡A¨Ï±o¨C.¤H³£²M·¡.¥Î¤¤ªº.Õu¬y..
    ...¥Î..¤H.¥²...¥L...ªº..µ¦²¤¡A¨Ï±o.¥y.¾ãªº.µ{¤¤¯à§Ö³t¡B®e©ö¦a.
    .¦³..ªº.¥Î¼Ò.©M¥iºÃªºSQL.¥y.
    ...Õu.ºÞ²z¤H.¥².¥J.¦a.±±¨t.¬¡.¦}´£¨Ñ¥¦.ªº.®Æ¡A¨Ï±oÉݱ`ªº¨t.©Ê¯à¥i³Q
    §Ö³t±o..©M.¥¿.
    ..µw¥ó/.¥óºÞ²z¤H.¥²...¨t.ªºµw¥ó¡B.¥ó°t¸m¦}´£¨Ñ¥¦.ªº.®Æ¡A¨Ï±o¬Û.¤H.
    ¯à¦³®Ä¦a..©MºÞ²z¨t.¡C
    
    .¦Ó¨¥¤§¡AÉO¨t.¯A¤Îªº¨C.¤H³£¦b.¾ã.µ{¤¤°_¬Y¨Ç§@¥Î¡A.¤W­±´£¤Îªº¨º¨Ç¤H..
    .¤F¨t.ªº¯S©Ê¦}´£¨Ñ¤F¥¦.ªº.®Æ¡A.¾ã´N¯à¬Û.ªº®e©ö©M§ó§Ö¤@¨Ç¡C
    ¤£©¯ªº¬O¡A¨Æ.¤Wªº.ªG¬O¡G.Õu.ºÞ²z...¾ã.¦³¥þ³¡©Î¥D­nªº.¥ô¡C¦ý¬O¡A.Õu
    .ºÞ²z.«Ü¤Ö¦³¦XÓ쪺¨t.¤è­±ªº.®Æ¡A¦Ó¥B¡A¦b«Ü¦h±¡.¤U¡A.Õu.ºÞ²z.©¹©¹¬O¦b.¬I
    .¬q¤~¤¶¤J.Õu.¡A.´N..¾ã¤u§@...¦h.­±ªº¼v.¡A¦].¦b...¬qªº¯Ê³´¬O¤£¯à³q
    .DBAªº.¾ã¦Ó±o¥H¸Ñ.¡A¦Ó...¬qªº¯Ê³´©¹©¹..Õu.©Ê¯à³y¦¨Ìå¤jªº¼v.¡C
    ¨ä.¡A¦b¯u¥¿¦¨¼ôªº...¹Ò¤U¡A..¤H.§@..¥N...¤H..¡A.©Ê¯àªº¼v.³Ì¤p¡A
    ¦¹.¤j³¡¤Àªº¤u§@.¥Ñ.¥Î..¤H.§¹¦¨¡A¦Ó¥B.Õu.ºÞ²z.©¹©¹¦b«e´Áªº»Ý¨DºÞ²z.¬q´N
    ¤¶¤J¡A...¤H.´£¨Ñ¥²­nªº§Þ.¤ä«ù¡C
    .¾ã¦}¤£¬O.Õu.ºÞ²z.ªº.§Q¡A¬Û¤Ï¤j³¡¤À..¬O..¤H.©M..¤H.ªº¤u§@¡A.´N
    »Ý­n..¤H.©M..¤H.¨ãÊ^¥²­nªº.Õu.ª¾.¡A..¤~¯à.¦¨¤@.°ª®Äªº..¡AµM¦Ó¨Æ.
    ¤W©¹©¹¦}«D¦p¦¹¡C
    
    ¤°¤\.­Ô§@.¾ã¡H
    ¦h.¤H...¥Î.·P.©Ê¯à®t.¤~.¦æ.¾ã¡A...¾ã.µ{¤¤¨Ï¥Î¬Y¨Ç³Ì¦³®Äªº.¾ãµ¦
    ²¤..©¹©¹¬O¤Ó.¤F¡C¦¹.¡A¦pªG§A¤£º@·N­«·s...¥Îªº.¡A§A¥u¯à³q.­«·s¤À°t.¦s(.
    ¾ãSGA)©M.¾ãI/Oªº.ªk©Î¦h©Î¤Ö¦a´£°ª©Ê¯à¡COracle´£¨Ñ¤F.¦h¯S©Ê¡A.¨Ç¯S©Ê¥u¦³.
    ¥Î¨ì¥¿Ú̦a..ªº¨t.¤¤.¤~¯à.«Ü¤j¦a´£°ª©Ê¯à¡C
    .¥Î..¤H.»Ý­n¦b...¬q.¸m.¥Îªº©Ê¯à´Á±æ­È¡CµM¦Z¦b..©M..´Á.¡A.¥Î.
    .¤H..¦Ò.­þ¨ÇOracle¯S©Ê¥i¥H.¨t.¦³¦n.¡A¦}¨Ï¥Î.¨Ç¯S©Ê¡C
    ³q.¨}¦nªº¨t...¡A§A´N¥i¥H¦b.¥Îªº¥Í©R©P´Á¤¤®ø°£©Ê¯à.¾ãªº¥Nɲ©M®À§é¡C.
    1-1.1-2.©ú¦b.¥Îªº¥Í©R©P´Á¤¤.¾ãªº¬Û.¥Nɲ©M¦¬¯q¡A¥¿¦p§A.¨ìªº¡A³Ì¦³®Äªº.¾ã
    ..¬O¦b...¬q¡C¦b..´Á.ªº.¾ã¯à¥H³Ì§Cªº¥Nɲ.§A³Ì¤jªº¦¬¯q¡C
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    .1-1¦b.¥Î¥Í©R©P´Á¤¤.¾ãªº¥Nɲ
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    .1-2¦b.¥Î¥Í©R©P´Á¤¤.¾ãªº¦¬¯q
    
    .µM¡A§Y¨Ï¦b..«Ü¦nªº¨t.¤¤¡A¤]¥i¯à¦³©Ê¯à­°§C¡C¦ý.¨Ç©Ê¯à­°§C..¬O¥i±±ªº©M
    ¥i¥H..ªº¡C
    
    .¾ã¥Ø.
    ¤£ºÞ§A¥¿¦b..©Î..¨t.¡A§A..«Ø¥ß..ªº©Ê¯à¥Ø.¡A¥¦¨Ï§Aª¾¹D¦ó.­n§@.¾ã¡C
    ¦pªG§A..­J.¦a§ï.ªì©l¤Æ..©ÎSQl.¥y¡A§A¥i¯à.®ö..¾ã¨t.ªº..¡A¦Ó¥B.¤°
    ¤\¤jªº¦¬¯q¡C.¾ã§Aªº¨t.ªº³Ì¦³®Ä¤èªk¦p¤U¡G
    .....¨t..¦Ò.©Ê¯à
    ...¾ã¾Þ§@¨t.ªºµw¥ó©M.¥ó
    ....©Ê¯à²~.
    ¤å¥»®Ø:COST
    ¤å¥»®Ø:Production
    ¤å¥»®Ø:Development
    ¤å¥»®Ø:Design
    ¤å¥»®Ø:TIME
    ¤å¥»®Ø:Production
    ¤å¥»®Ø:Development
    ¤å¥»®Ø:Design
    ¤å¥»®Ø:Time
    ¤å¥»®Ø:Benefit
    ..ÚÌ©w..ªº­ì¦]
    ..ªö¨ú.¥¿ªº.§@
    .§A..¨t..¡A¨î©w..ªº¥Ø.¡F¨Ò¦p¡A....¤p¤_¢²¬í¡C..¥Î¤£¯à.¨¬¦¹
    ¥Ø..¡A..³y¦¨.ºCªº²~.¡]¨Ò¦p¡AI/O..¡^¡AÚÌ©w­ì¦]¡Aªö¨ú.¥¿.§@¡C¦b..
    ´Á.¡A§A....¥Î¬ã¨s¡AÚÌ©w¦bªö¨ú.¥Î¤§«e¬O§_.¨¬..ªº©Ê¯à¥Ø.¡C
    .§A¥¿¦b..¥Í..¨t..¡A¦³¦hÏú§Ö³t¦³®Äªº¤èªk...©Ê¯à²~.¡C
    ¤£ºÞ«ç.¡A.¾ã³q±`¬O¤@¨t¦C..¡C¤@¥¹§A¤wÚÌ©w¤F²~.¡A§A¥i¯à­n.¬¹¤@¨Ç¨ä¥¦
    ¤è­±ªº«ü...¨ì©Ò­nªº.ªG¡C¨Ò¦p¡A¦pªGI/O¦³..¡A§A¥i¯à»Ý­n§ó¦h.¦s©ÎºÏ.¡C
    ¦pªG¤£¥i¯à.¡A§A¥i¯à­n­­¨î¨t.ªº¦}.©Ê¡A..¨ú©Ò»Ýªº©Ê¯à¡CµM¦Ó¡A¦pªG§A¤w.
    ©úÚ̦a©w.¤F©Ê¯àªº¥Ø.¡A¨º¥Î¤°¤\.¥æ.°ª©Ê¯àªº.µ¦´N.ªº«Ü®e©öªº¡A¦].§A¤w
    .ÚÌ©w¤F­þ¨Ç¤è­±¬O³Ì­«­nªº¡A¦p.§Úªº¥Ø..°ª©Ê¯à¡A¥i¯à.¬¹¤@¨ÇªÅ..·½¡C
    ...¥Îªº¶V.¶V.¤j¡Aµw¥ó©Ê¯àªº´£°ª¡A¥þ­±ªº.¾ã.¥Î³v..¦¨¥Nɲ°ª©ùªº¦æ
    .¡A¦b..±¡.¤U¡A­n¨ú±o³Ì¤jªº§ë¤J/®Ä²v¤§¤ñ¡A.¦nªº.ªk¬O.¾ã.¥Îªº..³¡¤À¡A
    ¨Ï¨ä.¨ì¤ñ.°ªªº©Ê¯à¡A....Ê^¤W..¡A¾ã.¨t.ªº©Ê¯à¤]¬O¤ñ.°ªªº¡C.¤]´N
    ¬O¦³¦Wªº20/80­ì.¡A.¾ã.¥Îªº20%(..³¡¤À)¡A¯à¸Ñ.80%ªº..¡C
    
    ¦b..©M..¨t..§@.¾ã
    ¨}¦n..ªº¨t.¥i¥H¨¾¤î¦b.¥Î¥Í©R©P´Á¤¤.¥Í©Ê¯à..¡C¨t...¤H.©M.¥Î
    ..¤H.¥².¤F¸ÑOracleªº¬d..²zÉó¨î¥H«K.¥X°ª®ÄªºSQL.¥y¡C¡§²Ä2³¹¦³®Ä
    ªº.¥Î..¡¨..¤F§Aªº¨t.¤¤¦UÏú¥i¥Îªº°t¸m¡A¥H¤Î¨CÏú°t¸m§óÓì¦X­þÏú.«¬ªº.
    ¥Î¡C¡§²Ä5³¹É¬¤Æ¾¹¡¨..¤FOracleªº¬d.ɬ¤Æ¾¹¡A¥H¤Î¦p¦ó..¥y¥H.¨ú³Ì§Öªº.
    ªG¡C
    ...§Aªº¨t..¡A¨Ï¥Î¤U¦Cɬ¤Æ©Ê¯àªº­ã.¡G
    ..®ø°£«È.Éó¡þªA.¾¹.¥Î¤¤¤£¥²­nªºÊI...¡C--¨Ï¥Î¦s..µ{¡C
    ..¨Ï¥ÎÓì¦X§A¨t.ªº¬Û.OracleªA.¾¹.¥ó¡]¨Ò¦p¡A¦}¦æ¬d.©Î¤À¥¬¦¡.Õu.¡^¡C
    ..°£«D§Aªº.¥Î¦³¯S®íªº»Ý­n¡A§_.¨Ï¥Î¯Ê¬ÙªºOracle.¡C
    ..§Q¥Î.Õu..¦í.¥Î¼Ò.¡A¥H«K§A¯à¥H¨C.¼Ò..°ò..°l.©Ê¯à¡C
    ....§Aªº.Õu.ªº³Ì¨Î¤j¤p¡C--­ì.¤W..¤j¤@¨Çªº©Ê¯à.¦n¡C
    ..¤À¥¬§Aªº.Õu¡A¨Ï±o¤@...¨Ï¥Îªº.Õu¥»¦a¦s.¦b...¤¤¡C
    
    .¾ã.«~¨t.
    ¥».´y­z..¥Î¨t.§Ö³t¡B®e©ö¦a§ä¥X©Ê¯à²~.¡A¦}.©w.¥¿.§@ªº¤èªk¡C.Ïú¤è
    ªk¨Ì.¤_.OracleªA.¾¹Ê^¨t.ÌÛ©M¯S©Êªº¤F¸Ñµ{«×¡C¦b...¾ã§Aªº¨t.«e¡A§A.¼ô±x
    Oracle.¾ãªº.®e¡C
    ..¾ã§A¤w¦³ªº¨t.¡A¿í.¤U¦C¨B.¡G
    ...¾ã¾Þ§@¨t.ªºµw¥ó©M.¥ó
    ..³q.¬d.V$SESSION_WAIT..¡A..©Ê¯àªº²~.¡A....©Ê¯à..¦C
    ¥X¤F³y¦¨..(session)µ¥«Ýªº¨Æ¥ó¡C
    ..³q.¤ÀªRV$SESSION_WAIT¤¤ªº.Õu¡A.©w²~.ªº­ì¦]¡C
    ...¥¿¦s¦bªº..¡C
    
    .±±.¥Î¨t.
    .¥D­n¬O³q..±±oracleªº.....§¹¦¨¡C
    ¦UÏú¦³¥Îªº....¡G¦pv$session_wait,v$session_eventµ¥¡C
    
    
    ²Ä2³¹¦³®Äªº.¥Î..
    §Ú.³q±`.³Ì±`¥Îªº.¥Î¤À.2Ïú.«¬¡G.Éó¨Æ..²z.«¬(OLTP)¡A.µ¦¤ä«ù¨t.
    (DSS)¡C
    
    .Éó¨Æ..²z(OLTP)
    ..«¬ªº.¥Î¬O°ª§]¦R¶q¡A´¡¤J¡B§ó·s¡B.°£¾Þ§@¤ñ.¦hªº¨t.¡A.¨Ç¨t.¥H¤£.¼W
    .ªº¤j®e¶q.Õu.¯S©º¡A¥¦.´£¨Ñ.¦¨¦Ê¥Î.¦P.¦s¨ú¡A¨å«¬ªºOLTP¨t.¬O.²¼¨t.¡A.
    ¦æªº..¨t.¡A..¨t.¡COTLPªº¥D­n¥Ø.¬O¥i¥Î©Ê¡B³t«×¡B¦}.©Ê©M¥i«ìÎ`©Ê¡C
    .....¨t..¡A¥².ÚÌ«O¤j¶qªº¦}.¥Î.¤£¯à¤zÊð¨t.ªº©Ê¯à¡C.»Ý­nÁקK¨Ï¥Î
    .¶qªº¯Á¤ÞÉOclusterªí¡A¦]..¨Ç.ÌÛ.¨Ï´¡¤J©M§ó·s¾Þ§@.ºC¡C
    
    .µ¦¤ä«ù(DSS)
    ..«¬ªº.¥Î.¤j¶q«H®§.¦æ´£¨ú§Î¦¨.§i¡A.§U.µ¦ªÌ§@¥X¥¿Ú̪º§P.¡C¨å«¬ªº±¡
    .¬O¡G.µ¦¤ä«ù¨t..OLTP.¥Î¦¬¶°ªº¤j¶q.Õu.¦æ¬d.¡C¨å«¬ªº.¥Î.«È.¦æ.¤ÀªR¨t
    .(¶W¥«¡A«O.µ¥)¡C
    .µ¦¤ä«ùªº..¥Ø.¬O³t«×¡BºëÚÌ©Ê©M¥i¥Î©Ê¡C
    .Ïú.«¬ªº..©¹©¹ÉOOLTP..ªº²z©À­I¹D¦Ó.¡A¤@¯ë«Ø.¨Ï¥Î.Õu¤¾§E¡B¤j¶q¯Á
    ¤Þ¡Bclustertable¡B¦}¦æ¬d.µ¥¡C
    ªñ¦~.¡A..«¬ªº.¥Î³v.ÉOOLAP¡B.Õu...±Kªº.¨t¦b¤@°_¡A§Î¦¨ªº¤@.·sªº
    .¥Î¤è¦V¡C
    
    
    ²Ä3³¹SQL.¥y.²zªº.µ{
    ¦b.¾ã¤§«e§Ú.»Ý­n¤F¸Ñ¤@¨Ç­I´ºª¾.¡A¥u¦³ª¾¹D.¨Ç­I´ºª¾.¡A§Ú.¤~¯à§ó¦nªº¥h.
    ¾ãsql.¥y¡C
    ¥».¤¶.¤FSQL.¥y.²zªº°ò¥».µ{¡A¥D­n¥]¬A¡G
    ¡E¬d..¥y.²z
    ¡EDML.¥y.²z(insert,update,delete)
    ¡EDDL.¥y.²z(create..,drop..,alter..,)
    ¡E¨Æ.±±¨î(commit,rollback)
    SQL.¥yªº.¦æ.µ{(SQLStatementExecution)
    .3-1·§­nªº¦C¥X¤F.²z©M.¦æ¤@.sql.¥yªº»Ý­n¦U.­«­n.¬q¡C¦b¬Y¨Ç±¡.¤U¡A
    Oracle.¦æsqlªº.µ{¥i¯àÉO¤U­±¦C¥Xªº¦U..¬qªº.§Ç¦³©Ò¤£¦P¡C¦pDEFINE.¬q¥i¯à
    ¦bFETCH.¬q¤§«e¡A.¥D­n¨Ì.§A¦p¦ó..¥N.¡C
    ..¦horacleªº¤u¨ã..¡A¨ä¤¤¬Y¨Ç.¬q.¦Û..¦æ¡C.¤j¦h.¥Î.¤£»Ý­n.¤ß¦U.
    .¬qªº....¡AµM¦Ó¡Aª¾¹D.¦æªº¦U..¬q.¬O¦³¥²­nªº¡A...§U§A.¥X§ó°ª®ÄªºSQL
    .¥y.¡A¦Ó¥B.¥i¥H.§A²q.¥X©Ê¯à®tªºSQL.¥y¥D­n¬O¥Ñ¤_­þ¤@..¬q³y¦¨ªº¡AµM¦Z§Ú
    .....¨ãÊ^ªº.¬q¡A§ä¥X¸Ñ.ªº.ªk¡C
    Textdescriptionofcncpt105.giffollows
    .3-1SQL.¥y.²zªº¦U..¬q
    
    DML.¥yªº.²z
    ¥»..¥X¤@.¨Ò¤l..©ú¦bDML.¥y.²zªº¦U..¬q¨ì©³.¥Í¤F¤°¤\¨Æ±¡¡C
    °².§A¨Ï¥ÎPro*Cµ{§Ç..«ü©w³¡.ªº©Ò¦³..¼W¥[¤u.¡Cµ{§Ç¤w..¨ì¥¿Ú̪º¥Î.¡A§A
    ¥i¥H¦b§Aªºµ{§Ç¤¤´O¤J¦p¤UªºSQL.¥y¡G
    EXECSQLUPDATEemployees
    SETsalary=1.10*salary
    WHEREdepartment_id=:var_department_id;
    var_department_id¬Oµ{§Ç.¶q¡A¨½­±¥]§t³¡..¡A§Ú.­n­×§ï.³¡.ªº..ªº¤u.¡C..
    .SQL.¥y.¦æ.¡A¨Ï¥Î..¶qªº­È¡C
    ¨CÏú.«¬ªº.¥y³£»Ý­n¦p¤U.¬q¡G
    ¡E²Ä1¨B:CreateaCursor.«Ø´å.
    ¡E²Ä2¨B:ParsetheStatement¤ÀªR.¥y
    ¡E²Ä5¨B:BindAnyVariables.©w.¶q
    ¡E²Ä7¨B:RuntheStatement.¦æ.¥y
    ¡E²Ä9¨B:ClosetheCursor..´å.
    ¦pªG¨Ï¥Î¤F¦}¦æ¥\¯à¡A..¥]§t¤U­±...¬q¡G
    ¡E²Ä6¨B:ParallelizetheStatement¦}¦æ.¦æ.¥y
    ¦pªG¬O¬d..¥y¡A.»Ý­n¥H¤U¤L..¥~ªº¨B.¡A¦p.3©Ò¥Ü¡G
    ¡E²Ä3¨B:DescribeResultsofaQuery´y­z¬d.ªº.ªG¶°
    ¡E²Ä4¨B:DefineOutputofaQuery©w.¬d.ªº.¥X.Õu
    ¡E²Ä8¨B:FetchRowsofaQuery¨ú¬d.¥X.ªº¦æ
    
    ¤U­±¨ãÊ^.¤@¤U¨C¤@¨B¤¤³£.¥Í¤F¤°¤\¨Æ±¡¡G.
    ²Ä1¨B:.«Ø´å.(CreateaCursor)
    ¥Ñµ{§Ç±µ¤f.¥Î.«Ø¤@.´å.¡]cursor¡^¡C¥ô¦óSQL.¥y³£..«Ø¥¦¡A¯S.¦b.¦æDML
    .¥y.¡A³£¬O¦Û..«Ø´å.ªº¡A¤£»Ý­n..¤H.¤z.¡C¦h..¥Î¤¤¡A´å.ªº.«Ø¬O¦Û.ªº¡C
    µM¦Ó¡A¦b...µ{§Ç(pro*c)¤¤´å.ªº.«Ø¡A¥i¯à¬O.§tªº¡A¤]¥i¯à.¦¡ªº.«Ø¡C¦b¦s..µ{
    ¤¤¤]¬O..ªº¡C
    ²Ä2¨B:¤ÀªR.¥y(ParsetheStatement)
    ¦b.ªk¤ÀªR´Á.¡ASQL.¥y.¥Î..µ{.°e¨ìOracle¡ASQL.¥y..ªk¤ÀªR¦Z¡ASQL
    .¥y¥»¨­ÉO¤ÀªRªº«H®§³£³Q.¤J¨ì¦@¨ÉSQL.¡C¦b..¬q¤¤¡A¥i¥H¸Ñ..¦h.«¬ªº..¡C
    
    .ªk¤ÀªR¤À..¦æ¤U¦C¾Þ§@¡G
    ..½.SQL.¥y¡A..¥¦¬O¦Xªkªº.¥y¡A§Y..¥¿ÚÌ
    .....Õu¦r¨åªº¬d§ä¡A¥H..¬O§_²Å¦Xªí©M¦Cªº©w.
    ..¦b©Ò­n¨Dªº.¶H¤W.¨ú.ªk¤ÀªR.¡A¨Ï±o¦b.¥yªº.ªk¤ÀªR.µ{¤¤¤£§ï..¨Ç.
    ¶Hªº©w.
    .....¦s¨ú©Ò¯A¤Îªº¼Ò¦¡.¶H©Ò»Ýªº.­­¬O§_.¨¬
    ...©w¦¹.¥y³Ì¨Îªº.¦æ.¦E
    ...¥¦.¤J¦@¨ÉSQL.
    ...¤À¥¬ªº.¥y..¡A§â.¥yªº¥þ³¡©Î³¡¤À¸ô¥Ñ¨ì¥]§t©Ò¯A¤Î.Õuªº.µ{..
    ¥H¤W¥ô¦ó¤@¨B¥X...¡A³£..­P.¥y..¡A¤¤¤î.¦æ¡C
    ¥u¦³¦b¦@¨É¦À¤¤¤£¦s¦bµ¥É²SQL.¥yªº±¡.¤U¡A¤~.SQL.¥y§@.ªk¤ÀªR¡C¦b.Ïú±¡
    .¤U¡A.Õu..®Ö­«·s...¥y¤À°t·sªº¦@¨ÉSQL.¡A¦}..¥y.¦æ.ªk¤ÀªR¡C.¦æ.ªk
    ¤ÀªR»Ý­n¯Ó..¦hªº.·½¡A©Ò¥H­n.¶qÁקK.¦æ.ªk¤ÀªR¡A.¬Oɬ¤Æªº§Þ¥©¤§¤@¡C
    .ªk¤ÀªR.¬q¥]§t¤F¤£ºÞ¦¹.¥y..¦æ¦h¤Ö¦¸¡A¦Ó¥u»Ý¤ÀªR¤@¦¸ªº.²z­n¨D¡COracle
    ¥u.¨C.SQL.¥y½.¤@¦¸¡A¦b¥H¦Z¦A¦¸.¦æ..¥y.¡A¥u­n..¥y.¦b¦@¨ÉSQL.¤¤¡A
    ´N¥i¥HÁקK...¥y­«·s.¦æ.ªk¤ÀªR¡A¤]´N¬O¦¹.¥i¥Hª½±µ¨Ï¥Î¨ä..ªº.¦æ.¦E..Õu
    .¦æ¦s¨ú¡C.¥D­n¬O³q..©w.¶q(bindvariable)..ªº¡A¤]´N¬O§Ú.±`.ªº¦@¨ÉSQL¡A¦Z
    ­±..¥X¦@¨ÉSQLªº·§©À¡C
    .µM.ªk¤ÀªR..¤FSQL.¥yªº¥¿ÚÌ©Ê¡A¦ý.ªk¤ÀªR¥u¯à..¦bSQL.¥y.¦æ¤§«e©Ò
    ¯à..ªº..(¦p....¡B.­­¤£¨¬µ¥)¡C¦]¦¹¡A¦³¨Ç..³q..ªk¤ÀªR¬O§ì¤£¨ìªº¡C¨Ò¦p¡A
    ¦b.Õu..¤¤ªº..©Î¦b.Õu¤¤ªº.¡]¦p¥ø.¦b¥D.¤¤´¡¤J­«Î`ªº­È¡^¥H¤Î¦º.µ¥§¡¬O¥u¦³
    ¦b.¥y.¦æ.¬q´Á.¤~¯à¹J¨ì©M.§iªº..©Î±¡.¡C
    ¬d..¥yªº.²z
    ¬d.ÉO¨ä¥¦.«¬ªºSQL.¥y¤£¦P¡A¦].¦b¦¨¥\.¦æ¦Z§@..ªG.ªð¦^.Õu¡C¨ä¥¦.¥y
    ¥u¬O..¦aªð¦^¦¨¥\©Î¥¢.¡A¦Ó¬d..¯àªð¦^¤@¦æ©Î.¦h¦æ.Õu¡C¬d.ªº.ªG§¡ªö¥Îªí®æ§Î
    ¦¡¡A.ªG¦æ³Q¤@¦¸¤@¦æ©ÎªÌ§å¶q¦a³Q.¯Á¥X.¡C..¨½§Ú.¥i¥H±oª¾§å¶qªºfetch.Õu¥i¥H
    ­°§CÊI...¡A©Ò¥H§å¶qªºfetch¤]¬Oɬ¤Æªº§Þ¥©¤§¤@¡C
    
    ¦³¨Ç..¥uÉO¬d..²z¬Û.¡A¬d.¤£..«üSELECT.¥y¡A¦P.¤]¥]¬A¦b¨ä¥¦SQL.
    ¥y¤¤ªº.§t¬d.¡C¨Ò¦p¡A¤U­±ªº¨C..¥y³£»Ý­n§â¬d.§@.¥¦.¦æªº¤@³¡¤À¡G
    INSERTINTOtableSELECT...
    UPDATEtableSETx=yWHERE...
    DELETEFROMtableWHERE...
    CREATEtableASSELECT...
    ¨ãÊ^..¡A¬d.
    ¡E­n¨D.¤@­P©Ê
    ¡E¥i¯à¨Ï¥Î¦^.¬q§@¤¤..²z
    ¡E¥i¯à­n¨DSQL.¥y.²z´y­z¡B©w.©M¨ú.Õu.¬q
    ²Ä3¨B:´y­z¬d..ªG(DescribeResultsofaQuery)
    ´y­z.¬q¥u¦³¦b¬d..ªGªº¦U.¦C¬O¥¼ª¾.¤~»Ý­n¡F¨Ò¦p¡A.¬d.¥Ñ¥Î.¥æ¤¬¦a.¤J
    »Ý­n.¥Xªº¦C¦W¡C¦b.Ïú±¡.­n¥Î´y­z.¬q..©w¬d..ªGªº¯S©º¡].Õu.«¬¡A.«×©M¦W¦r¡^¡C
    ²Ä4¨B:©w.¬d.ªº.¥X.Õu(DefineOutputofaQuery)
    ¦b¬d.ªº©w..¬q¡A§A«ü©wÉO¬d.¥Xªº¦C­È..ªº±µ¦¬.¶qªº¦ì¸m¡B¤j¤p©M.Õu.«¬¡A
    ..§Ú.³q.±µ¦¬.¶q´N¥i¥H±o¨ì¬d..ªG¡C¦pªG¥²­nªº.¡AOracle.¦Û....Õu.«¬
    ªº..¡C.¬O.±µ¦¬.¶qªº.«¬ÉO..ªº¦C.«¬¬Û¤ñ..©wªº¡C
    ²Ä5¨B:.©w.¶q(BindAnyVariables)
    ¦¹.¡AOracleª¾¹D¤FSQL.¥yªº·N«ä¡A¦ý¤´.¦³¨¬.ªº«H®§¥Î¤_.¦æ..¥y¡COracle
    »Ý­n±o¨ì¦b.¥y¤¤¦C¥Xªº©Ò¦³.¶qªº­È¡C¦b.¨Ò¤¤¡AOracle»Ý­n±o¨ì.department_id¦C
    .¦æ­­©wªº­È¡C±o¨ì..­Èªº.µ{´N¥s.©w.¶q(bindingvariables)
    ¦¹.µ{.¤§...¶q­È®¹...¡Cµ{§Ç¥².«ü¥X¥i¥H§ä¨ì..­Èªº.¶q¦W¡]..¶q³Q.
    .®¹..¶q¡A.¶q¦W..¤W¬O¤@..¦s¦a§}¡A¬Û.¤_«ü.¡^¡C.¥Îªº³Ì.¥Î.¥i¯à¦}.¦³.
    .¥L.¥¿¦b«ü©w®¹..¶q¡A¦].Oracleªºµ{§Ç¥i¯à¥u¬O..¦a«ü¥Ü¥L..¤J·sªº­È¡A¨ä.
    .¤@¤Á³£¦bµ{§Ç¤¤¦Û.°µ¤F¡C
    ¦].§A«ü©w¤F.¶q¦W¡A¦b§A¦A¦¸.¦æ¤§«e..­«·s®¹..¶q¡C§A¥i¥H§ï..©w.¶qªº­È¡A
    ¦ÓOracle¦b¨C¦¸.¦æ.¡A..¨Ï¥Î.¦s¦a§}.¬d§ä¦¹­È¡C
    ¦pªGOracle»Ý­n..¦Û..Õu.«¬..ªº.¡]°£«D¥¦.¬O.§tªº©Î¯Ê¬Ùªº¡^¡A§A.¥²
    ..¨C.­È«ü©w.Õu.«¬©M.«×¡C.¤_.¨Ç«H®§¥i¥H.¦Òoracleªº¬Û.¤å.¡A¦pOracleCall
    InterfaceProgrammer'sGuide
    ²Ä6¨B:¦}¦æ.¦æ.¥y(ParallelizetheStatement)
    ORACLE¥i¥H¦bSELECTs,INSERTs,UPDATEs,MERGEs,DELETEs.¥y¤¤.¦æ¬Û
    .¦}¦æ¬d.¾Þ§@¡A.¤_¬Y¨ÇDDL¾Þ§@¡A¦p.«Ø¯Á¤Þ¡B¥Î¤l¬d..«Øªí¡B¦b¤À.ªí¤Wªº¾Þ§@¡A
    ¤]¥i¥H.¦æ¦}¦æ¾Þ§@¡C¦}¦æ¤Æ¥i¥H.­P¦h.ªA.¾¹.µ{(oracleserverprocesses).¦P¤@.
    SQL.¥y¤u§@¡A¨Ï.SQL.¥y¥i¥H§Ö³t§¹¦¨¡A¦ý¬O.¯Ó.§ó¦hªº.·½¡A©Ò¥H°£«D«Ü¦³¥²­n¡A
    §_.¤£­n¨Ï¥Î¦}¦æ¬d.¡C
    ²Ä7¨B:.¦æ.¥y(RuntheStatement)
    ¨ì¤F.¦b...­Ô¡AOracle.¦³©Ò¦³»Ý­nªº«H®§ÉO.·½¡A¦]¦¹¥i¥H¯u¥¿.¦æSQL.¥y
    ¤F¡C¦pªG..¥y.SELECT¬d.©ÎINSERT.¥y¡A.¤£»Ý­n.©w¥ô¦ó¦æ¡A¦]..¦³.Õu»Ý
    ­n³Q§ï.¡CµM¦Ó¡A¦pªG.¥y.UPDATE©ÎDELETE.¥y¡A...¥y¼v.ªº©Ò¦³¦æ³£³Q.©w¡A
    ¨¾¤î.¥Î.´£¥æ©Î¦^.¤§«e¡A.ªº¥Î...¨Ç.Õu.¦æ­×§ï¡C.«O.¤F.Õuªº¤@­P©Ê¡C
    .¤_¬Y¨Ç.¥y¡A§A¥i¥H«ü©w.¦æªº¦¸.¡A...§å.²z(arrayprocessing)¡C«ü©w.¦æN
    ¦¸¡A..©w.¶qÉO©w..¶q³Q©w..¤j¤p.Nªº..ªº.©l¦ì¸m¡A.Ïú¤èªk¥i¥H.¤ÖÊI.
    ..¡A¤]¬Oɬ¤Æªº§Þ¥©¤§¤@¡C
    ²Ä8¨B:¨ú¥X¬d.ªº¦æ(FetchRowsofaQuery)
    ¦bfetch.¬q¡A¦æ.Õu³Q¨ú¥X.¡A¨C.¦Z.ªº¦s¨ú¾Þ§@.¯Á.ªG¶°¤¤ªº¤U¤@¦æ.Õu¡Aª½
    ¨ì³Ì¦Z¤@¦æ³Q¨ú¥X.¡C¤W­±´£¨ì.¡A§å¶qªºfetch¬Oɬ¤Æªº§Þ¥©¤§¤@¡C
    ²Ä9¨B:..´å.(ClosetheCursor)
    SQL.¥y.²zªº³Ì¦Z¤@..¬q´N¬O..´å.
    
    DDL.¥yªº.²z(DDLStatementProcessing)
    DDL.¥yªº.¦æ¤£¦PÉODML.¥y©M¬d..¥yªº.¦æ¡A.¬O¦].DDL.¥y.¦æ¦¨¥\¦Z
    »Ý­n..Õu¦r¨å.Õu.¦æ­×§ï¡C.¤_DDL.¥y¡A.¥yªº¤ÀªR.¬q..¤W¥]¬A¤ÀªR¡B¬d§ä.
    Õu¦r¨å«H®§©M.¦æ¡C
    ¨Æ.ºÞ²z.¥y¡B..ºÞ²z.¥y¡B¨t.ºÞ²z.¥y¥u¦³¤ÀªRÉO.¦æ.¬q¡A.¤F­«·s.¦æ..
    ¥y¡A.­«·s¤ÀªRÉO.¦æ..¥y¡C
    ¨Æ.±±¨î(ControlofTransactions)
    ¤@¯ë..¡A¥u¦³¨Ï¥ÎORACLE.µ{±µ¤fªº.¥Î..¤H.¤~.¤ß¾Þ§@ªº.«¬¡A¦}§â¬Û.
    ªº¾Þ§@..¦b¤@°_¡A§Î¦¨¤@.¨Æ.¡C¤@¯ë..¡A§Ú.¥².©w.¨Æ.¡A..¦b¤@....¤¸¤¤
    ªº©Ò¦³¤u§@¥i¥H¦P.³Q´£¥æ©Î¦^.¡A«O.¤F.Õuªº¤@­P©Ê¡C¤@.¨Æ...¥Ñ...¤¸¤¤ªº©Ò
    ¦³¥².³¡¤À.¦¨¡A¤£..¦h¤@.¡A¤]¤£..¤Ö¤@.¡C
    ¡E¦b¨Æ..©l©M.§ôªº.¬q...¡A©Ò¦³³Q¤Þ¥Îªí¤¤ªº.Õu³£..¦b¤@­Pªº..(©Î¥i¥H
    ³Q¦^·¹¨ì¤@­Pªº..)
    ¡E¨Æ...¥u¥]§t¥i¥H..Õu.¦æ¤@­P§ó§ï(oneconsistentchangetothedata)ªºSQL
    .¥y
    ¨Ò¦p¡A¦b....¤§.ªº..(.¬O¤@.¨Æ.©Î..¤u§@.¤¸)¡A..¥]§t.¤@...¤¤
    ­É.(¥Ñ¤@.SQL§¹¦¨)¡AµM¦Z.­Éªº.¦s¤J¥t¤@...(¥Ñ¥t¤@.SQL§¹¦¨)¡C.2.¾Þ§@
    §@.¤@....¤¸¡A..¦P.¦¨¥\©Î¦P.¥¢.¡C¨ä¥¦¤£¬Û.ªº¾Þ§@¡A¦p¦V¤@...¤¤¦s.¡A
    ¤£..¥]§t¦b....¨Æ.¤¤¡C
    ¦b...¥Î.¡A°£¤F»Ý­n.©w­þÏú.«¬ªº¾Þ§@.¦¨¤@.¨Æ.¥~¡A.»Ý­n.©w¨Ï¥Î
    BEGIN_DISCRETE_TRANSACTIO¦s..µ{¬O§_.´£°ª¤pªº¡B«D¤À¥¬¦¡ªº¨Æ.ªº©Ê¯à¦³§@
    ¥Î¡C
    
    
    ²Ä4³¹ORACLEªºÉ¬¤Æ¾¹
    
    É¬¤Æ¾¹¦³.¤]³Q..¬d.ɬ¤Æ¾¹¡A.¬O¦].¬d.¬O¼v..Õu.©Ê¯à³Ì¥D­nªº³¡¤À¡A¤£
    ­n¥H.¥u¦³SELECT.¥y¬O¬d.¡C..¤W¡A.¦³¥ô¦óWHERE.¥óªºDML(INSERT¡B
    UPDATE¡BDELETE).¥y¤¤³£¥]§t¬d.­n¨D¡A¦b¦Z­±ªº¤å³¹¤¤¡A..¨ì¬d..¡A¤£¤@©w¥u
    ¬O«üSELECT.¥y¡A¤]¦³¥i¯à«üDML.¥y¤¤ªº¬d.³¡¤À¡Cɬ¤Æ¾¹¬O©Ò¦³.¨t.Õu.¤ÞÀº¤¤
    ªº³Ì¯«¯µ¡B³Ì´I¬D.©Êªº³¡¥ó¤§¤@¡A.©Ê¯àªº¨¤«×¬Ý¤]¬O³Ì­«­nªº³¡¤À¡A¥¦©Ê¯àªº°ª§Cª½±µ
    .¨t¨ì.Õu.©Ê¯àªº¦n§¥¡C
    §Ú.ª¾¹D¡ASQL.¥y¦P¨ä¥¦.¨¥(¦pC.¨¥)ªº.¥y¤£¤@.¡A¥¦¬O«D.µ{¤Æ
    (non-procedural)ªº.¥y¡A§Y.§A­n¨ú.Õu.¡A¤£»Ý­n§i..Õu.³q.¦óÏú³~.¥h¨ú.Õu¡A
    ¦p¨ì©³¬O³q.¯Á¤Þ¨ú.Õu¡A.¬O...ªí¤¤ªº¨C¦æ.Õu³£¨ú¥X.¡AµM¦Z¦A³q.¤@¤@¤ñ.ªº¤è
    ¦¡¨ú.Õu(§Y¥þªí.´y)¡A.¬O¥Ñ.Õu.ªºÉ¬¤Æ¾¹.©wªº¡A.´N¬O«D.µ{¤Æªº§t.¡A¤]´N¬O.¡A
    ¦p¦ó¨ú.Õu¬O¥Ñɬ¤Æ¾¹.©w¡A¦Ó¤£¬O.¥Î..ªÌ³q..µ{.©w¡C¦b.²zSQLªºSELECT¡B
    UPDATE¡BINSERT©ÎDELETE.¥y.¡AOracle¥²....¥y©Ò¯A¤Îªº.Õu¡AOracleªºÉ¬
    ¤Æ¾¹³¡¤À¥Î..©w...Õuªº¦³®Ä¸ô.¡A¨Ï±o.¥y.¦æ©Ò»ÝªºI/O©M.²z..³Ì¤p¡C
    .¤F..¤@.¬d.¡A.®Ö¥²..¨C.¬d.©w¨î¤@.¬d.µ¦²¤¡A©Î.¨ú¥X²Å¦X.¥óªº.
    Õu¥Í¦¨¤@..¦æ.¦E(executionplan)¡C¨å«¬ªº¡A.¤_¦P¤@.¬d.¡A¥i¯à¦³¤L..¦æ.¦E³£
    ²Å¦X­n¨D¡A³£¯à±o¨ì²Å¦X.¥óªº.Õu¡C¨Ò¦p¡A.ÉO.±µªºªí¥i¥H¦³¦hÏú¤£¦Pªº.±µ¤èªk¡A.
    ¨ú.¤_.±µ.¥ó©Mɬ¤Æ¾¹ªö¥Îªº.±µ¤èªk¡C.¤F¦b¦h..¦æ.¦E¤¤..³Ìɬªº.¦æ.¦E¡Aɬ
    ¤Æ¾¹¥².¨Ï¥Î¤@¨Ç..ªº«ü..¿Å¶q¨C..¦æ.¦E¨Ï¥Îªº.·½(I/0¦¸.¡BCPUµ¥)¡A.¨Ç.
    ·½¤]´N¬O§Ú.©Ò.ªº¥Nɲ(cost)¡C¦pªG¤@..¦æ.¦E¨Ï¥Îªº.·½¦h¡A§Ú.´N.¨Ï¥Î.¦æ.¦E
    ªº¥Nɲ¤j¡C¥H.¦æ.¦Eªº¥Nɲ¤j¤p§@.¿Å¶q.­ã¡Aɬ¤Æ¾¹..¥Nɲ³Ì¤pªº.¦æ.¦E§@.¯u¥¿
    .¦æ.¬d.ªº.¦æ.¦E¡A¦}..¨ä¥¦ªº.¦æ.¦E¡C
    ¦bORACLEªº.®i.µ{¤¤¡A¤@¦@...2Ïú.«¬ªºÉ¬¤Æ¾¹¡G°ò¤_..ªºÉ¬¤Æ¾¹©M°ò¤_
    ¥NɲªºÉ¬¤Æ¾¹¡C.2Ïúɬ¤Æ¾¹ªº¤£¦P¤§...¦b¤_¡G¨ú±o¥Nɲªº¤èªkÉO¿Å¶q¥Nɲªº¤j¤p¤£
    ¦P¡C..¨CÏúɬ¤Æ¾¹°µ¤@¤U..ªº¤¶.¡G
    
    °ò¤_..ªºÉ¬¤Æ¾¹--RuleBased(Heuristic)Optimization(..RBO)¡G
    ¦bORACLE7¤§«e¡A¥D­n¬O¨Ï¥Î°ò¤_..ªºÉ¬¤Æ¾¹¡CORACLE¦b°ò¤_..ªºÉ¬¤Æ¾¹¤¤
    ªö¥Î..¦¡ªº¤èªk(HeuristicApproach)©Î..(Rules).¥Í¦¨.¦æ.¦E¡C¨Ò¦p¡A¦pªG¤@.¬d
    .ªºwhere.¥ó(whereclause)¥]§t¤@...(predicate¡A¨ä.´N¬O¤@.§P..¥ó¡A¦p¡¨=¡¨,
    ¡§>¡¨,¡¨<¡¨µ¥)¡A¦Ó¥B...¤W¤Þ¥Îªº¦C¤W¦³¦³®Ä¯Á¤Þ¡A¨º¤\ɬ¤Æ¾¹.¨Ï¥Î¯Á¤Þ....ªí¡A¦Ó
    ¤£¦Ò.¨ä¥¦¦]¯À¡A¦pªí¤¤.Õuªº¦h¤Ö¡Bªí¤¤.Õuªº©ö.©Ê¡B¯Á¤Þªº¥i..©Êµ¥¡C¦¹..Õu.
    ¤¤.¦³.¤_ªíÉO¯Á¤Þ.Õuªº..©Ê´y­z¡A¦pªí¤¤¦³¦h¤W¦æ¡A¨C¦æªº¥i..©Êµ¥¡Cɬ¤Æ¾¹¤]¤£
    ¦Ò..¨Ò..¡A¦pmultiblocki/o¡B¥i¥Î±Æ§Ç.¦sªº¤j¤pµ¥¡A©Ò¥Hɬ¤Æ¾¹¦³.´N..¤F¦¸É¬
    ¤Æªº.¦E§@.¯u¥¿ªº.¦æ.¦E¡A.­P¨t.©Ê¯à¤£°ª¡C
    ¦p¡A.¤_
    select*fromempwheredeptno=10;
    ..¬d...¡A¦pªG¬O¨Ï¥Î°ò¤_..ªºÉ¬¤Æ¾¹¡A¦Ó¥Bdeptno¦C¤W¦³¦³®Äªº¯Á¤Þ¡A.
    .³q.deptno¦C¤Wªº¯Á¤Þ...empªí¡C¦b.¤j¦h.±¡.¤U¡A.¬O¤ñ.°ª®Äªº¡A¦ý¬O¦b¤@
    ¨Ç¯S®í±¡.¤U¡A¨Ï¥Î¯Á¤Þ..¤]¦³¤ñ.§C®Äªº.­Ô¡A..¨Ò.©ú¡G
    1)empªí¤ñ.¤p¡A.ªíªº.Õu¥u¦s©ñ¦b¤L..Õu.¤¤¡C¦¹.¨Ï¥Î¥þªí.´y¤ñ¨Ï¥Î¯Á¤Þ
    ..empªí¤Ï¦Ó­n¦n¡C¦].ªí¤ñ.¤p¡AÌ妳¥i¯à.Õu¥þ¦b.¦s¤¤¡A©Ò¥H¦¹.°µ¥þªí.´y¬O
    ³Ì§Öªº¡C¦Ó¦pªG¨Ï¥Î¯Á¤Þ.´y¡A»Ý­n¥ý.¯Á¤Þ¤¤§ä¨ì²Å¦X.¥ó..ªºrowid¡AµM¦Z¦A¤@¤@®Ú
    Õu.¨Çrowid.emp¤¤..Õu¨ú¥X.¡A¦b.Ïú.¥ó¤U¡A®Ä²v´N.¤ñ¥þªí.´yªº®Ä²v­n®t¤@
    ¨Ç¡C
    2)empªí¤ñ.¤j.¡A¦Ó¥Bdeptno=10.¥ó¯à¬d.¥Xªí¤¤¤j³¡¤Àªº.Õu¦p(50%)¡C¦p
    .ªí¦@¦³4000ÉE¦æ.Õu¡A¦@©ñ¦b¦³500000..Õu.¤¤¡A¨C..Õu..8k¡A..ªí¦@¦³.
    4G¡A..¤\¦hªº.Õu¤£¥i¯à¥þ©ñ¦b.¦s¤¤¡A.¤j¦h.»Ý­n©ñ¦bµw.¤W¡C¦¹.¦pªG.¬d.³q
    .¯Á¤Þ¬d.¡A.¬O§A..ªº.©l¡Cdb_file_multiblock_read_count..ªº­È200¡C¦pªGªö¥Î
    ¥þªí.´y¡A.»Ý­n500000/db_file_multiblock_read_count=500000/200=2500¦¸I/O¡C¦ý¬O
    ¦pªGªö¥Î¯Á¤Þ.´y¡A°².deptno¦C¤Wªº¯Á¤Þ³£¤w.cache¨ì.¦s¤¤¡A©Ò¥H¥i¥H...¯Á¤Þ
    ªº..©¿²¤¤£.¡C¦].­n.¥X4000ÉEx50%=2000ÉE.Õu¡A°².¦b..2000ÉE.Õu.¡A
    ¦³99.9%ªº©R¤¤²v¡A..¬O»Ý­n20000¦¸I/O,¤ñ¤W­±ªº¥þªí.´y»Ý­nªº2500¦¸¦h¦h¤F¡A©Ò
    ¥H¦b.Ïú±¡.¤U¡A¥Î¯Á¤Þ.´y¤Ï¦Ó©Ê¯à.®t«Ü¦h¡C¦b..ªº±¡.¤U¡A¥Î¥þªí.´yªº..¬O©T
    ©wªº¡A¦ý¬O¥Î¯Á¤Þ.´yªº......¥X.Õuªº¼W¦h¨Ï¬d...¬Û.ªº©µ.¡C
    ¤W­±¬O¬\Àꪺ°²..Õu¡A.¦b¥H¨ãÊ^ªº.¨Ò.¤©..¡G
    .¹Ò:oracle817+linux+.¦CÏ@¡AªíSWD_BILLDETAIL¦³3200¦hÉE.Õu¡F
    ªíªºid¦C¡Bcn¦C¤W³£¦³¯Á¤Þ
    .¬d¬Ý.¦æ.¦E¡A...¦æselectcount(id)fromSWD_BILLDETAIL;¨Ï¥Î¥þªí.´y¡A
    .¦æ§¹¥Î¤F¤j.1.50¤À.(4¦¸.¦æ¨ú¥­§¡¡A¨C¦¸¤À..1.451.512.001.46)¡C¦Ó.¦æselect
    count(id)fromSWD_BILLDETAILwherecn<'6';.¥Î¤F2.¤p...¦³.¦æ§¹¡A.¤ÀªR.
    .¥y¨Ï¥Î¤Fcn¦C¤Wªº¯Á¤Þ¡AµM¦Z§Q¥Î¬d.¥Xªºrowid¦A.ªí¤¤¬d..Õu¡C§Ú.¤°¤\¤£¨Ï¥Î
    selectcount(cn)fromSWD_BILLDETAILwherecn<'6';©O¡H¦Z­±¦b¤ÀªR.¦æ¸ô.ªº¯Á¤Þ.
    ´y....¥X.©ú¡C
    ¤U­±´N¬O°ò¤_..ªºÉ¬¤Æ¾¹¨Ï¥Îªº.¦æ¸ô.ÉO¦U.¸ô...ªºµ¥.¡G
    RBOPath1:SingleRowbyRowid(µ¥.³Ì°ª)
    RBOPath2:SingleRowbyClusterJoin
    RBOPath3:SingleRowbyHashClusterKeywithUniqueorPrimaryKey
    RBOPath4:SingleRowbyUniqueorPrimaryKey
    RBOPath5:ClusteredJoin
    RBOPath6:HashClusterKey
    RBOPath7:IndexedClusterKey
    RBOPath8:CompositeIndex
    RBOPath9:Single-ColumnIndexes
    RBOPath10:BoundedRangeSearchonIndexedColumns
    RBOPath11:UnboundedRangeSearchonIndexedColumns
    RBOPath12:SortMergeJoin
    RBOPath13:MAXorMINofIndexedColumn
    RBOPath14:ORDERBYonIndexedColumn
    RBOPath15:FullTableScan(µ¥.³Ì§C)
    ¤W­±ªº.¦æ¸ô.¤¤¡ARBO..¶V©¹¤U.¦æªº¥Nɲ¶V¤j¡A§Yµ¥.¶V§C¡C¦bRBO¥Í¦¨.
    ¦æ.¦E.¡A¦pªG¥¦..¦³µ¥.°ªªº.¦æ¸ô.¥i¥Î¡A.ªÖ©w.¨Ï¥Îµ¥.°ªªº¸ô.¡A¦Ó¤£ºÞ¥ô¦ó
    ¨ä¥¦¼v.©Ê¯àªº¤¸¯À¡A§YRBO³q.¤W­±ªº¸ô.ªºµ¥..©w.¦æ¸ô.ªº¥Nɲ¡A.¦æ¸ô.ªºµ¥
    .¶V°ª¡A.¨Ï¥Î..¦æ¸ô.ªº¥Nɲ¶V¤p¡C¦p¤W­±2.¨Ò¤l©Ò­z¡A¦pªG¨Ï¥ÎRBO¡A.ªÖ©w¨Ï
    ¥Î¯Á¤Þ..ªí¡A¤]´N¬O..¤F¤ñ.®tªº.¦æ.¦E¡A.....Õu.©Ê¯à..«Ü¤jªº.­±¼v.¡C
    .¤F¸Ñ.....¡A.ORACLE7.©loracle¤Þ¤J¤F°ò¤_¥NɲªºÉ¬¤Æ¾¹¡A¤U­±.¥X¤F¤¶.¡C
    
    °ò¤_¥NɲªºÉ¬¤Æ¾¹--CostBasedOptimization(..CBO)
    Oracle§â¤@.¥Nɲ¤ÞÀº(CostEngine)¶°¦¨¨ì.Õu..®Ö¤¤¡A¥Î.¦ô.¨C..¦æ.¦E»Ý
    ­nªº¥Nɲ¡A.¥Nɲ.¨C..¦æ.¦E©Ò¯Ó.ªº.·½.¦æ¶q¤Æ¡A.¦ÓCBO¥i¥H®ÚÕu..¥Nɲ.
    .¥X³Ìɬªº.¦æ.¦E¡C¤@.¬d.¯Ó.ªº.·½¥i¥H³Q¤À¦¨3.°ò¥».¦¨³¡¤À¡GI/O¥Nɲ¡BCPU
    ¥Nɲ¡Bnetwork¥Nɲ¡CI/O¥Nɲ¬O..Õu.ºÏ..¤J.¦s©Ò»Ýªº¥Nɲ¡C...Õu¥]¬A..Õu
    ¤å¥ó¤¤.Õu.ªº.®e.¤J¨ìSGAªº.Õu°ª³t.¦s¤¤¡A¦b¤@¯ë±¡.¤U¡A.¥Nɲ¬O.²z¤@.¬d
    .©Ò»Ý­nªº³Ì¥D­n¥Nɲ¡A©Ò¥H§Ú.¦bɬ¤Æ.¡A¤@.°ò¥»­ì.´N¬O­°§C¬d.©Ò.¥ÍªºI/O.¦¸
    .¡CCPU¥Nɲ¬O.²z¦b.¦s¤¤.Õu©Ò»Ý­nªº¥Nɲ¡A¦p¤@¥¹.Õu³Q.¤J.¦s¡A.§Ú.¦b..
    ¥X§Ú.»Ý­nªº.Õu¦Z¡A¦b.¨Ç.Õu¤W.¦æ±Æ§Ç(sort)©Î.±µ(join)¾Þ§@¡A.»Ý­n¯Ó.CPU.
    ·½¡C
    .¤_»Ý­n..¸ó..(§Y³q±`.ªºªA.¾¹).Õu.¤W.Õuªº¬d...¡A¦s¦bnetwork¥N
    É²¡A¥Î.¶q¤Æ..¾Þ§@¯Ó.ªº.·½¡C¬d..µ{ªíªº¬d.©Î.¦æ¤À¥¬¦¡.±µªº¬d..¦b
    network¥Nɲ¤è­±ªá.¤ñ.¤j¡C
    ¦b¨Ï¥ÎCBO.¡A»Ý­n¦³ªí©M¯Á¤Þªº...Õu(¤ÀªR.Õu)§@.°ò..Õu¡A¦³¤F.¨Ç.Õu¡A
    CBO¤~¯à.¦U..¦æ.¦E.ºâ¥X¬Û.­ãÚ̪º¥Nɲ¡A.¦Ó¨ÏCBO..³Ì¨Îªº.¦æ.¦E¡C©Ò
    ¥H©w´Áªº.ªí¡B¯Á¤Þ.¦æ¤ÀªR¬O..¥²­nªº¡A..¤~¯à¨Ï...Õu¤Ï¬M.Õu.¤¤ªº¯u.±¡.¡C
    §_.´N.¨ÏCBO...®tªº.¦æ.¦E¡A¼v..Õu.ªº©Ê¯à¡C¤ÀªR¾Þ§@¤£¥²°µªº¤Ó.Ác¡A¤@
    ¯ë..¡A¨C¬P´Á¤@¦¸´N¨¬.¤F¡C¤Á.¦pªG·Q¨Ï¥ÎCBO¡A.¥².©w´Á.ªí©M¯Á¤Þ.¦æ¤ÀªR¡C
    .¤_¤ÀªR¥Îªº©R¥O¡A...Õu.ª©¥»ªº¤É.¡A¥Îªº©R¥O¤].¥Í¤F..¡A¦boracle8i
    ¥H«e¡A¥D­n¬O¥ÎANALYZE©R¥O¡C¦bORACLE8I¥H¦Z¡A¤S¤Þ¤J¤FDBMS_STATS¦s.¥].
    .¦æ¤ÀªR¡C©¯.ªº¬O.ORACLE10G¥H¦Z¡A¤ÀªR¤u§@.¦¨¦Û.ªº¤F¡A...ªºDBAªº.
    .¡A¤£.¦b¤@¨Ç¯S®í±¡.¤U¡A.»Ý­n¤@¨Ç¤â¤u¤ÀªR¡C
    ¦pªGªö¥Î¤FCBOɬ¤Æ¾¹¡A¦Ó.¦³.ªí©M¯Á¤Þ.¦æ¤ÀªR¡A.¦³...Õu¡A.ORACLE
    ¨Ï¥Î¯Ê¬Ùªº...Õu(¦Ü¤Ö¦bORACLE9I¤¤¬O..)¡A.¥i¥H.oracleªº¤å.¤W§ä¨ì¡C¨Ï¥Î
    ªº¯Ê¬Ù­ÈªÖ©wÉO¨t.ªº....­È¤£¤@­P¡A.¥i¯à..­Pɬ¤Æ¾¹....ªº.¦æ.¦E¡A¼v.
    .Õu.ªº©Ê¯à¡C
    ­nª`·Nªº¬O¡G.µMCBOªº¥\¯à..ORACLE·sª©¥»ªº±À¥X¡A¥\¯à¶V.¶V.¡A¦ý¥¦¤£
    ¬O¯à¥]ªv¦Ê¯fªº¯«.¡A§_.´N¤£¦A»Ý­nDBA¤F¡A¨º§Ú´N.¤F¡I¡I¡I..¤W¥ô¦ó¤@..¥y¡A.
    .µw¥ó.¹ÒÉO.¥Î.Õuªº¤£¦P¡A..¥yªº.¦æ.¦E¥i¯à»Ý­n.¤§.¥Í.¤Æ¡A..¤~¯à¨ú±o³Ì
    ¦nªº©Ê¯à¡C©Ò¥H¦³.­Ô¤£¦b¨ãÊ^ªº.¹Ò¤U¦Ó.¦æSQL©Ê¯à.¾ã¬O®{.ªº¡C
    ¦bORACLE8I±À¥Xªº.­Ô¡AORACLEÌå¤O«Ø.¤j®a¨Ï¥ÎCBO¡A.CBO¦³ÏúÏú¦n.¡A
    ¦ý¬O¦b¨º¬OORACLE..ªº.¥Î¨t..¬O¨Ï¥Î°ò¤_..ªºÉ¬¤Æ¾¹¡A..¥ó¨Æ¤W§Ú.¥i¥H±o
    ¥X..ªº..¡G1)¦pªG..ªº.Õu.¤ô¥­«Ü°ª¦Ó¥B³£¼ô±x.¥Î.Õuªº¯S.¡ARBO¤]¥i¥H¨ú
    ±o«Ü¦nªº©Ê¯à¡C2¡^CBO¤£¬O«Ü.©w¡A¦ý¬O¤@.¤ñ.¦³«e³~ªºÉ¬¤Æ¾¹¡AOracleÌå¤O«Ø.¤j
    ®a¥Î¬O.¤F.¤j®a.§Ö..¥¦ªºBUG¡A¥H«K.¤@¨B§ïµ½¡A¦ý¬OORACLE.¤F.¦Û¤v..ªº
    .¥Î¨t...¡A¥L..¬O¨Ï¥Î¤F¤ñ.¼ô±x¦Ó¥B¦¨¼ôªºRBO¡C...¨Æ±¡¤W.§Ú.ªº..´N
    ¬O¡G§Ú.¦b¥H¦Zªº..¤¤¡A...¶qªö¥Î§Ú.¼ô±x¦}¥B¦¨¼ôªº§Þ.¡A¦Ó¤£­n¤@¨ýªºªö¥Î·s§Þ
    .¡A¤@¨ýªö¥Î·s§Þ.¦}¤£¤@©w¯à..¥X¦nªº.«~¡C©¯.ªº¬O.ORACLE10G¦Z¡ACBO¤w
    .¨¬.ªº.¤jÉO´¼¯à¡A¤j®a¥i¥H©ñ¤ßªº¨Ï¥Î.§Þ.¡A¦].ORACLE10G¦Z¡AOracle¦Û¤v.
    .ªº.¥Î¨t.¤]¨Ï¥ÎCBOɬ¤Æ¾¹¤F¡C¦Ó¥BORACLE.©w¡A.ORACLE10G.©l¡A.©l
    ..RBOɬ¤Æ¾¹¡C.¥y.¦}¤£¬O«ü¦bORACLE10G¤¤¤£¯à¨Ï¥ÎRBO¡A¦Ó¬O.ORACLE
    10G.©l.©l¡A¤£¦A.RBOªºBUG´£¨Ñ­×.ªA.¡C
    ¦b¤W­±ªº²Ä2.¨Ò¤l¤¤¡A¦pªGªö¥ÎCBOɬ¤Æ¾¹¡A¥¦´N.¦Ò.empªíªº¦æ.¡Adeptno
    ¦Cªº...Õu¡A....¦C°µ¬d..¬d.¥X.¦hªº.Õu¡A¦}¥B¦Ò.
    db_file_multiblock_read_count..ªº.¸m¡A..¥Î¥þªí.´yªº¥Nɲ¤ñ¥Î¯Á¤Þ.´yªº¥Nɲ­n
    ¤p¡A.¦Ó¨Ï¥Î¥þªí.´y.¦Ó¨ú±o¨}¦nªº.¦æ©Ê¯à¡C
    
    §P..«e.Õu.¨Ï¥Î¦óÏúɬ¤Æ¾¹¡G
    ¥D­n¬O¥Ñoptimizer_modeªì©l¤Æ...©wªº¡C...¥i¯àªº¨ú­È.¡Gfirst_rows_[1|10
    |100|1000]|first_rows|all_rows|choose|rule¡C¨ãÊ^¸Ñ.¦p¤U¡G
    RULE.¨Ï¥ÎRBOɬ¤Æ¾¹¡C
    CHOOSE.¬O®ÚÕu..±¡.¡A¦pªG.Õu¦r¨å¤¤¥]§t³Q¤Þ¥Îªºªíªº...Õu¡A§Y¤Þ
    ¥Îªº.¶H¤w.³Q¤ÀªR¡A.´N¨Ï¥ÎCBOɬ¤Æ¾¹¡A§_..RBOɬ¤Æ¾¹¡C
    ALL_ROWS.CBOɬ¤Æ¾¹¨Ï¥Îªº²Ä¤@Ïú¨ãÊ^ªºÉ¬¤Æ¤èªk¡A¬O¥H.Õuªº§]¦R¶q.
    ¥D­n¥Ø.¡A¥H«K¥i¥H¨Ï¥Î³Ì¤Öªº.·½§¹¦¨.¥y¡C
    FIRST_ROWS.ɬ¤Æ¾¹¨Ï¥Îªº²Ä¤GÏú¨ãÊ^ªºÉ¬¤Æ¤èªk¡A¬O¥H.Õuªº.....
    ¥D­n¥Ø.¡A¥H«K§Ö³t¬d.¥X.©lªº¤L¦æ.Õu¡C
    FIRST_ROWS_[1|10|100|1000].ɬ¤Æ¾¹¨Ï¥Îªº²Ä¤TÏú¨ãÊ^ªºÉ¬¤Æ¤èªk¡A.
    É¬¤Æ¾¹..¤@.¯à.§â.....¨ì³Ì¤pªº¬d..¦æ.¦E¡A¥H¨³³t.¥Í¬d..ªG
    ªº«en¦æ¡C....ORACLE9I·s¤Þ¤Jªº¡C
    .ORACLEV7¥H.¡Aoptimizer_mode..ªº¯Ê¬Ù.¸m.¬O"choose"¡A§Y¦pªG.¤w¤À
    ªRªºªí¬d.ªº...CBO¡A§_...RBO¡C¦b¦¹Ïú.¸m¤¤¡A¦pªGªö¥Î¤FCBO¡A.¯Ê¬Ù.
    CBO¤¤ªºall_rows¼Ò¦¡¡C
    ª`·N¡G§Y¨Ï«ü©w.Õu.¨Ï¥ÎRBOɬ¤Æ¾¹¡A¦ý¦³.ORACLE.Õu..¬O.ªö¥ÎCBO
    É¬¤Æ¾¹¡A.¦}¤£¬OORACLEªºBUG¡A¥D­n¬O¥Ñ¤_.ORACLE8I¦Z¤Þ¤Jªº.¦h·s¯S©Ê³£¥²
    .¦bCBO¤U¤~¯à¨Ï¥Î¡A¦Ó§AªºSQL.¥y¥i¯à¥¿¦n¨Ï¥Î¤F.¨Ç·s¯S©Ê¡A¦¹..Õu..¦Û.
    ..¨Ï¥ÎCBOɬ¤Æ¾¹.¦æ.¨Ç.¥y¡C
    
    
    ¤°¤\¬Oɬ¤Æ
    É¬¤Æ¬O..³Ì¦³®Äªº.¦æ.¦E..¦æSQL.¥yªº.µ{¡A.¬O¦b.²z¥ô¦ó.Õuªº.¥y
    ¡]SELECT,INSERT,UPDATE©ÎDELETE¡^¤¤ªº¤@.­«­n¨B.¡C.Oracle..¡A.¦æ..
    ªº.¥y¦³.¦h¤£¦Pªº¤èªk¡AÄ´¦p.¡A...¥H¤°¤\.§Ç..­þ¨Çªí©Î¯Á¤Þªº¤£¦P¦Ó¤£¦P¡C©Ò
    ¨Ï¥Îªº.¦æ.¦E¥i¥H.©w.¥y¯à.¦æ±o¦³¦h§Ö¡COracle¤¤.¤§.ɬ¤Æ¾¹¡]Optimizer¡^ªº.
    ¥ó¥Î....Ïú¥¦..³Ì¦³®Äªº.¦æ.¦E¡C
    ¥Ñ¤_¤@¨t¦C¦]¯À³£..¼v..¥yªº.¦æ¡Aɬ¤Æ¾¹.¦X.¿Å¦U.¦]¯À¡A¦b.¦hªº.¦æ.
    ¦E¤¤....¬O³Ì¨Îªº.¦æ.¦E¡CµM¦Ó¡A.¥Î..¤H.³q±`¤ñɬ¤Æ¾¹§óª¾¹D.¤_¯S©w.¥Îªº
    .Õu¯S.¡C..ɬ¤Æ¾¹¦h¤\´¼¯à¡A¦b¬Y¨Ç±¡.¤U..¤H.¯à..¥X¤ñɬ¤Æ¾¹..ªº³Ìɬ.¦æ
    .¦E.­n¦nªº.¦æ.¦E¡C.¬O»Ý­n¤H¤u¤z..Õu.ɬ¤Æªº¥D­n­ì¦]¡C¨Æ.ªí©ú¡A¦b¬Y¨Ç±¡.
    ¤U¡AÚÌ.»Ý­nDBA.¬Y¨Ç.¥y.¦æ¤â¤uɬ¤Æ¡C
    ª`¡G.Oracleªº¤@.ª©¥»¨ì¥t¤@.ª©¥»¡Aɬ¤Æ¾¹¥i¯à.¦P¤@.¥y¥Í¦¨¤£¦Pªº.¦æ.¦E¡C
    ¦b..ªºOracleª©¥»¤¤¡Aɬ¤Æ¾¹¥i¯à.°ò¤_¥¦¥i¥H¥Îªº§ó¦n¡B§ó²z·Qªº«H®§¡A§@¥X§óɬªº
    .µ¦¡A.¦Ó.­P..¥y.¥Í§óɬªº.¦æ.¦E¡C
    
    
    ²Ä5³¹ORACLEªº.¦æ.¦E
    ­I´ºª¾.¡G
    .¤F§ó¦nªº.¦æ¤U­±ªº.®e§Ú.¥².¤F¸Ñ¤@¨Ç·§©À©Êªº..¡G
    ¦@¨Ésql.¥y
    .¤F¤£­«Î`¸ÑªR¬Û¦PªºSQL.¥y(¦].¸ÑªR¾Þ§@¤ñ...·½¡A..­P©Ê¯à¤U­°)¡A¦b²Ä
    ¤@¦¸¸ÑªR¤§¦Z¡AORACLE.SQL.¥y¤Î¸ÑªR¦Z±o¨ìªº.¦æ.¦E¦s©ñ¦b.¦s¤¤¡C..¦ì¤_¨t
    .¥þ§½.°ìSGA(systemglobalarea)ªº¦@¨É¦À(sharedbufferpool)¤¤ªº.¦s¥i¥H³Q©Ò¦³ªº
    .Õu.¥Î.¦@¨É¡C¦]¦¹¡A.§A.¦æ¤@.SQL.¥y(¦³.³Q..¤@.´å.).¡A¦pªG..¥y©M
    ¤§«eªº.¦æ.ªº¬Y¤@.¥y§¹¥þ¬Û¦P¡A¦}¥B¤§«e.¦æªº..¥yÉO¨ä.¦æ.¦E¤´µM¦b.¦s¤¤¦s
    ¦b¡A.ORACLE´N¤£»Ý­n¦A.¦æ¤ÀªR¡Aª½±µ±o¨ì..¥yªº.¦æ¸ô.¡CORACLEªº..¥\¯à
    ¤j¤j¦a´£°ª¤FSQLªº.¦æ©Ê¯à¦}¤j¤j.¬Ù¤F.¦sªº¨Ï¥Î¡C¨Ï¥Î..¥\¯àªº..¬O..¦æ.
    ªº.¥y.¥i¯à©ñ¨ì.¦s¤¤¡A©Ò¥H.­n¨D¦³¤jªº¦@¨É¦À(³q..¸msharedbufferpool..­È)
    ©M.¥i¯àªº¨Ï¥Î.©w.¶qªº¤èªk.¦æSQL.¥y¡C
    
    .§A¦VORACLE´£¥æ¤@.SQL.¥y¡AORACLE.­º¥ý¦b¦@¨É.¦s¤¤¬d§ä¬O§_¦³¬Û¦P
    ªº.¥y¡C.¨½»Ý­nª`©úªº¬O¡AORACLE..ªÌªö¨úªº¬O¤@Ïú.®æ¤Ç°t¡A­n.¦¨¦@¨É¡ASQL
    .¥y¥².§¹¥þ¬Û¦P(¥]¬AªÅ®æ,.¦æµ¥)¡C
    
    ¤U­±¬O§P.SQL.¥y¬O§_ÉO¦@¨É.¦s¤¤¬Y¤@SQL¬Û¦Pªº¨B.¡G
    1)..©Ò.¥X.¥yªº¤å¥»¦ê.¦æhashed¡C¦pªGhash­ÈÉO¤w¦b¦@¨É¦À¤¤SQL.¥yªº
    hash­È¬Û¦P¡A..¦æ²Ä2¨B¡G
    2).©Ò.¥X.¥yªº¤å¥»¦ê¡]¥]¬A¤j¤p.¡BªÅ¥Õ©Mª`.¡^ÉO¦b²Ä?¨B¤¤..ªº©Ò¦³
    ¤w¦s¦bªºSQL.¥y¬Û¤ñ.¡C
    ¨Ò¦p¡G
    SELECT*FROMempWHEREempno=1000;
    ©M¤U¦C¨C¤@.³£¤£¦P
    SELECT*fromempWHEREempno=1000;
    SELECT*FROMEMPWHEREempno=1000;
    SELECT*FROMempWHEREempno=2000;
    ¦b¤W­±ªº.¥y¤¤¦C­È³£¬Oª½±µSQL.¥y¤¤ªº¡A¤µ¦Z§Ú....sql¦¨.µw..SQL
    ©Î¦r­±­ÈSQL
    
    ¨Ï¥Î.©w.¶qªºSQL.¥y¤¤¥².¨Ï¥Î¬Û¦Pªº¦W¦rªº.©w.¶q(bindvariables)¡A
    ¨Ò¦p¡G
    a..2.sql.¥y³Q..¬Û¦P
    selectpin,namefrompeoplewherepin=:blk1.pin;
    selectpin,namefrompeoplewherepin=:blk1.pin;
    b..2.sql.¥y³Q..¤£¬Û¦P
    selectpin,namefrompeoplewherepin=:blk1.ot_ind;
    selectpin,namefrompeoplewherepin=:blk1.ov_ind;
    ¤µ¦Z§Ú..¤W­±ªº...¥y...©w.¶qSQL¡C
    
    3)..©Ò.¥X.¥y¤¤¯A¤Îªº.¶HÉO²Ä¢±¨B¤¤..ªº¤w¦s¦b.¥y©Ò¯A¤Î.¶H¬Û¤ñ.¡C
    ¨Ò¦p:
    ¦p¥Î.user1ÉO¥Î.user2¤U³£¦³EMPªí¡A.
    ¥Î.user1.¥Xªº.¥y¡GSELECT*FROMEMP;ÉO
    ¥Î.user2.¥Xªº.¥y¡GSELECT*FROMEMP;³Q..¬O¤£¬Û¦Pªº.¥y¡A
    ¦]....¥y¤¤¤Þ¥ÎªºEMP¤£¬O«ü¦P¤@.ªí¡C
    
    4).¦bSQL.¥y¤¤¨Ï¥Îªº®¹..¶qªº®¹..«¬¥².¤@­P¡C
    
    ¦pªG.¥yÉO.«e¦b¦@¨É¦À¤¤ªº¥t¤@..¥y¬Oµ¥¦Pªº.¡AOracle¦}¤£.¥¦.¦æ.ªk¤À
    ªR¡C¦Óª½±µ.¦æ..¥y¡A´£°ª¤F.¦æ®Ä²v¡A¦]..ªk¤ÀªR¤ñ.¯Ó..·½¡C
    
    ª`·Nªº¬O¡A.oracle8i.©l¡A·s¤Þ¤J¤F¤@.CURSOR_SHARING..¡A...ªº¥D­n
    ¥Øªº´N¬O.¤F¸Ñ.¦b.µ{.µ{¤¤¤w¤j¶q¨Ï¥Îªºµw..SQL..¡C¦].¦b....¤¤¡A«Ü¦hµ{
    §Ç¤H..¤F´£°ª..³t«×¡A¦Óªö¥Î.¦ü¤U­±ªº..¤èªk¡G
    str_sqlstring;
    int_empnoint;
    int_empno=2000;
    str_sql=¡¥SELECT*FROMempWHEREempno=¡¥+int_empno;
    ¡K¡K¡K¡K
    int_empno=1000;
    str_sql=¡¥SELECT*FROMempWHEREempno=¡¥+int_empno;
    ¤W­±ªº¥N...¤W¨Ï¥Î¤Fµw..SQL¡A¨Ï§Ú.¤£¯à¨Ï¥Î¦@¨ÉSQLªº¥\¯à¡A.ªG¬O.Õu
    .®Ä²v¤£°ª¡C¦ý¬O.¤W­±ªº2..¥y.¬Ý¡A.¥Íªºµw..SQL¥u¬O¦C­È¤£¦P¡A¨ä¥¦³¡¤À³£¬O
    ¬Û¦Pªº¡A¦pªG..¦].¦C­È¤£¦P¦Ó.­P.2..¥y¤£¯à¦@¨É¬O«Ü¥i±¤ªº¡A.¤F¸Ñ.....¡A
    ¤Þ¤J¤FCURSOR_SHARING..¡A¨Ï....¤]¥i¥H¨Ï¥Î¦@¨ÉSQL¡A.¦Ó¨Ï..ªº..¤]
    ¥i¥H§Q¥Î¦@¨ÉSQL¥\¯à¡C§v°_.¤£.¡AORACLE¯u.¥Î..·Q¡A¨Ï¥Î.¦b¤£§ï.¥N.ªº±¡
    .¤U.¥i¥H§Q¥Î¦@¨ÉSQLªº¥\¯à¡C¯uªº¦p¦¹.¡H¤Ñ¤W¤£....¬Gªº±¼¤@...ªº¡A
    ORACLE....ªº¨Ï¥Î°µ¤F.©ú¡A«Ø.¦b......¦Z¦A§ï...ªº­È(¯Ê¬Ù±¡.¤U¡A
    ...ªº­È.EXACT¡A.¥y§¹¥þ¤@­P¤~¨Ï¥Î¦@¨ÉSQL)¡C¦].¦³¥i¯à...­È¦Z¡A§Aªºµw.
    .SQL¬O¥i¥H¨Ï¥Î¦@¨ÉSQL¤F¡A¦ý.Õu.ªº©Ê¯à¤Ï¦Ó.¤U­°¡C§Ú¦b...¥Î¤¤¤w.¹J¨ì.
    Ïú±¡.¡C©Ò¥H«Ø...»Ý­n.©w.¦æµ{§Çªº..¤H.³Ì¦n.¬O¤@.©l´N¨Ï¥Î.©w.¶qªº
    SQL¡C
    
    Rowidªº·§©À¡G
    rowid¬O¤@..¦C¡A¬JµM¬O.¦C¡A¨º¤\..¦C´N¤£¬O¥Î.©w.¡A¦Ó¬O¨t.¦Û¤v.¥[¤Wªº¡C
    .¨C.ªí³£¦³¤@.rowidªº.¦C¡A¦ý¬Oªí¤¤¦}¤£ª«²z¦s.ROWID¦Cªº­È¡C¤£.§A¥i¥H¹³¨Ï
    ¥Î¨ä¥¦¦C¨º.¨Ï¥Î¥¦¡A¦ý¬O¤£¯à.°£§ï¦C¡A¤]¤£¯à..¦Cªº­È.¦æ­×§ï¡B´¡¤J¡C¤@¥¹¤@¦æ.
    Õu´¡¤J.Õu.¡A.rowid¦b.¦æªº¥Í©R©P´Á.¬O°ß¤@ªº¡A§Y§Y¨Ï.¦æ.¥Í¦æ.²¾¡A¦æªºrowid
    ¤]¤£.§ï.¡C
    
    .¤°¤\¨Ï¥ÎROWID
    rowid...¤@.ªí¤¤ªº.©wªº¦æ´£¨Ñ¤F³Ì§Öªº..¤èªk¡A³q.ROWID¥i¥Hª½±µ©w¦ì
    ¨ì¬Û.ªº.Õu.¤W¡AµM¦Z.¨ä.¨ì.¦s¡C§Ú..«Ø¤@.¯Á¤Þ.¡A.¯Á¤Þ¤£¦ý¦s.¯Á¤Þ¦Cªº­È¡A
    ¦Ó¥B¤]¦s.¯Á¤Þ­È©Ò..ªº¦æªºROWID¡A..§Ú.³q.¯Á¤Þ§Ö³t§ä¨ì¬Û.¦æªºROWID¦Z¡A
    ³q..ROWID¡A´N¥i¥H¨³³t..Õu¬d.¥X.¡C.¤]´N¬O§Ú.¨Ï¥Î¯Á¤Þ¬d..¡A³t«×¤ñ.§Ö
    ªº­ì¦]¡C
    ¦bORACLE8¥H«eªºª©¥»¤¤¡AROWID¥ÑFILE¡BBLOCK¡BROWNUMBERÌÛ¦¨¡C.
    .oracle8¤¤.¶H·§©Àªº.®i¡AROWID.¥Í¤F.¤Æ¡AROWID¥ÑOBJECT¡BFILE¡BBLOCK¡B
    ROWNUMBERÌÛ¦¨¡C§Q¥ÎDBMS_ROWID¥i¥H.rowid¤À¸Ñ¦¨¤W­zªº¦U³¡¤À¡A¤]¥i¥H.
    ¤W­zªº¦U³¡¤À.¦¨¤@.¦³®Äªºrowid¡C
    
    RecursiveSQL·§©À
    ¦³..¤F.¦æ¥Î..¥Xªº¤@.sql.¥y¡AOracle¥²..¦æ¤@¨Ç.¥~ªº.¥y¡A§Ú...
    ¨Ç.¥~ªº.¥y.¤§.'recursivecalls'©Î'recursiveSQLstatements'¡C¦p.¤@.DDL.¥y.¥X
    ¦Z¡AORACLE.¬O.§tªº.¥X¤@¨ÇrecursiveSQL.¥y¡A.­×§ï.Õu¦r¨å«H®§¡A¥H«K¥Î.
    ¥i¥H¦¨¥\ªº.¦æ.DDL.¥y¡C.»Ý­nªº.Õu¦r¨å«H®§.¦³¦b¦@¨É.¦s¤¤.¡A.±`..¥Í
    Recursivecalls¡A.¨ÇRecursivecalls...Õu¦r¨å«H®§.µw..¤J.¦s¤¤¡C¥Î.¤£¤ñ.¤ß
    .¨ÇrecursiveSQL.¥yªº.¦æ±¡.¡A¦b»Ý­nªº.­Ô¡AORACLE.¦Û.ªº¦b.³¡.¦æ.¨Ç
    .¥y¡C.µMDML.¥yÉOSELECT³£¥i¯à¤Þ°_recursiveSQL¡C..ªº.¡A§Ú.¥i¥H.àD.
    ¾¹..recursiveSQL¡C
    
    RowSource(¦æ·½)
    ¥Î¦b¬d.¤¤¡A¥Ñ¤W¤@¾Þ§@ªð¦^ªº²Å¦X.¥óªº¦æªº¶°¦X¡A§Y¥i¥H¬Oªíªº¥þ³¡¦æ.Õuªº¶°
    ¦X¡F¤]¥i¥H¬Oªíªº³¡¤À¦æ.Õuªº¶°¦X¡F¤]¥i¥H..¤W2.rowsource.¦æ.±µ¾Þ§@(¦pjoin
    .±µ)¦Z±o¨ìªº¦æ.Õu¶°¦X¡C
    
    Predicate(..)
    ¤@.¬d.¤¤ªºWHERE­­¨î.¥ó
    
    DrivingTable(..ªí)
    .ªí¤S..¥~.ªí(OUTERTABLE)¡C..·§©À¥Î¤_´O®MÉOHASH.±µ¤¤¡C¦pªG.row
    sourceªð¦^.¦hªº¦æ.Õu¡A..©Ò¦³ªº¦Z.¾Þ§@¦³.­±¼v.¡Cª`·N¦¹..µM½....ªí¡A
    ¦ý..¤W½....¦æ·½(drivingrowsource)§ó.Ṳ́Á¡C¤@¯ë..¡A¬O.¥Î¬d.ªº­­¨î.¥ó
    ¦Z¡Aªð¦^.¤Ö¦æ·½ªºªí§@...ªí¡A©Ò¥H¦pªG¤@.¤jªí¦bWHERE.¥ó¦³¦³­­¨î.¥ó(¦pµ¥
    ­È­­¨î)¡A..¤jªí§@...ªí¤]¬O¦XÓ쪺¡A©Ò¥H¦}¤£¬O¥u¦³.¤pªºªí¥i¥H§@...ªí¡A¥¿
    ÚÌ.ªk....¥Î¬d.ªº­­¨î.¥ó¦Z¡Aªð¦^.¤Ö¦æ·½ªºªí§@...ªí¡C¦b.¦æ.¦E¤¤¡A..
    .¾a¤Wªº¨º.rowsource¡A¦Z­±..¥X¨ãÊ^.©ú¡C¦b§Ú.¦Z­±ªº´y­z¤¤¡A¤@¯ë..ªí..
    .±µ¾Þ§@ªºrowsource1¡C
    
    ProbedTable(³Q±´¬dªí)
    .ªí¤S....ªí(INNERTABLE)¡C¦b§Ú....ªí¤¤±o¨ì¨ãÊ^¤@¦æªº.Õu¦Z¡A¦b.
    ªí¤¤.§ä²Å¦X.±µ.¥óªº¦æ¡C©Ò¥H.ªí...¤jªí(..¤W...ªð¦^.¤jrowsourceªºªí)
    ¥B¬Û.ªº¦C¤W..¦³¯Á¤Þ¡C¦b§Ú.¦Z­±ªº´y­z¤¤¡A¤@¯ë..ªí...±µ¾Þ§@ªºrowsource2¡C
    
    .¦X¯Á¤Þ(concatenatedindex)
    ¥Ñ¦h.¦CÌÛ¦¨ªº¯Á¤Þ¡A¦pcreateindexidx_emponemp(col1,col2,col3,¡K¡K)¡A.§Ú
    ..idx_emp¯Á¤Þ..¦X¯Á¤Þ¡C¦b.¦X¯Á¤Þ¤¤¦³¤@.­«­nªº·§©À¡G¤Þ.¦C(leadingcolumn)¡A
    ¦b¤W­±ªº¨Ò¤l¤¤¡Acol1¦C.¤Þ.¦C¡C.§Ú..¦æ¬d..¥i¥H¨Ï¥Î¡¨wherecol1=?¡¨¡A¤]¥i¥H
    ¨Ï¥Î¡¨wherecol1=?andcol2=?¡¨¡A..ªº­­¨î.¥ó³£.¨Ï¥Î¯Á¤Þ¡A¦ý¬O¡¨wherecol2=?¡¨
    ¬d.´N¤£.¨Ï¥Î.¯Á¤Þ¡C©Ò¥H­­¨î.¥ó¤¤¥]§t¥ý.¦C.¡A.­­¨î.¥ó¤~.¨Ï¥Î..¦X¯Á¤Þ¡C
    
    ¥i..©Ê(selectivity)¡G
    ¤ñ.¤@¤U¦C¤¤°ß¤@.ªº.¶q©Mªí¤¤ªº¦æ.¡A´N¥i¥H§P..¦Cªº¥i..©Ê¡C¦pªG.¦Cªº¡¨
    °ß¤@.ªº.¶q/ªí¤¤ªº¦æ.¡¨ªº¤ñ­È¶V±µªñ1¡A..¦Cªº¥i..©Ê¶V°ª¡A.¦C´N¶VÓì¦X.«Ø¯Á
    ¤Þ¡A¦P.¯Á¤Þªº¥i..©Ê¤]¶V°ª¡C¦b¥i..©Ê°ªªº¦C¤W.¦æ¬d..¡Aªð¦^ªº.Õu´N.¤Ö¡A¤ñ
    .Óì¦X¨Ï¥Î¯Á¤Þ¬d.¡C
    
    
    ¦³¤F.¨Ç­I´ºª¾.¦Z´N.©l¤¶..¦æ.¦E¡C.¤F.¦æ.¥y¡AOracle¥i¯à¥²....¦h
    ¨B.¡C.¨Ç¨B.¤¤ªº¨C¤@¨B¥i¯à¬O..Õu.¤¤ª«²z.¯Á.Õu¦æ¡A©ÎªÌ¥Î¬YÏú¤èªk­ã..Õu¦æ¡A
    ¨Ñ.¥X.¥yªº¥Î.¨Ï¥Î¡COracle¥Î..¦æ.¥yªº.¨Ç¨B.ªº.¦X³Q.¤§..¦æ.¦E¡C.¦æ
    .¦E¬OSQLɬ¤Æ¤¤³Ì.Î`.¤]¬O³Ì...ªº³¡¤À¡A¥u¦³ª¾¹D¤FORACLE¦b.³¡¨ì©³¬O¦p
    ¦ó.¦æ.SQL.¥y¦Z¡A§Ú.¤~¯àª¾¹Dɬ¤Æ¾¹..ªº.¦æ.¦E¬O§_.³Ìɬªº¡C.¦æ.¦E.¤_
    DBA..¡A´N¶H...ªí.¤_..¤H.¤@.­«­n¡C©Ò¥H§Ú.­±.ªº..¥D­n¬O¡G¦p¦ó±o¨ì
    .¦æ.¦E¡F¦p¦ó¤ÀªR.¦æ.¦E¡A.¦Ó§ä¥X¼v.©Ê¯àªº¥D­n..¡C¤U­±¥ý.¤ÀªR.«¬.¦æ.¦E
    .©l¤¶.¡AµM¦Z¤¶.¦p¦ó±o¨ì.¦æ.¦E¡A¦A¤¶.¦p¦ó¤ÀªR.¦æ.¦E¡C
    
    .¨Ò¡G
    ..¨Ò¤l.¥Ü.¤_¤U­±SQL.¥yªº.¦æ.¦E¡C
    SELECTename,job,sal,dname
    FROMemp,dept
    WHEREemp.deptno=derpt.deptno
    ANDNOTEXISTS
    (SELECT*
    FROMsalgrade
    WHEREemp.salBETWEENlosalANDhisal);
    ¦¹.¥y¬d.Á~¤ô¤£¦b¥ô¦ó«Ø.Á~¤ô­S..ªº©Ò¦³¶±.ªº¦W¦r¡A¤u§@¡AÁ~¤ô©M³¡.¦W¡C
    ¤U.5-1.¥Ü¤F¤@..¦æ.¦Eªº.§Îªí¥Ü¡G
    
    
    .¦æ.¦Eªº¨B.
    .¦æ.¦Eªº¨C¤@¨Bªð¦^¤@.¦æ¡A¥¦.©ÎªÌ.¤U¤@¨B©Ò¨Ï¥Î¡A©ÎªÌ¦b³Ì¦Z¤@¨B.ªð¦^.
    .¥XSQL.¥yªº¥Î.©Î.¥Î¡C¥Ñ¨C¤@¨Bªð¦^ªº¤@.¦æ¥s°µ¦æ·½(rowsource¡^¡C.5-1..
    ..¥Ü¤F.¤@¨B¨ì¥t¤@¨B¦æ.Õuªº¬y.±¡.¡C¨C¨Bªº..¤Ï¬M¤F¦b§A.¹î.¦æ.¦E.©Ò¥Ü¨B
    .ªº.§Ç¡]¦p¦ó.¹î.¦æ.¦E.³Q.µu¦a.©ú¡^¡C¤@¯ë...¦}¤£¬O¨C¤@¨B³Q.¦æªº¥ý¦Z.
    §Ç¡C.¦æ.¦Eªº¨C¤@¨B©ÎªÌ..Õu.¤¤.¯Á¦æ¡A©ÎªÌ±µ¦¬.¦Û¤@.©Î¦h.¦æ·½ªº¦æ.Õu§@.
    .¤J¡G
    ¥Ñ.¦â¦r®Ø«ü¥Xªº¨B...Õu.¤¤ªº.Õu¤å¥ó¤¤ª«²z.¯Á.Õu¡C.Ïú¨B.³Q.¤§.¦s¨ú
    ¸ô.¡A¦Z­±...¤¶.¦bOracle¥i¥H¨Ï¥Îªº¦s¨ú¸ô.¡G
    ..²Ä¢²¨B©M²Ä¢µ¨B¤À.ªº.EMPªí©MSALGRADEªí.©Ò¦³ªº¦æ¡C
    ..²Ä¢´¨B¦bPK_DEPTNO¯Á¤Þ¤¤¬d§ä¥Ñ¨B.¢²ªð¦^ªº¨C.DEPTNO­È¡C¥¦§ä¥XÉODEPT
    ªí¤¤¬Û..ªº¨º¨Ç¦æªºROWID¡C
    ..²Ä¢³¨B.DEPTªí¤¤.¯Á¥XROWID.²Ä¢´¨Bªð¦^ªº¨º¨Ç¦æ¡C
    ¥Ñ¶Â¦â¦r®Ø«ü¥Xªº¨B.¦b¦æ·½¤W¾Þ§@¡A¦p°µ2ªí¤§.ªº..¡A±Æ§Ç¡A©Î..µ¥¾Þ§@¡A
    ¦Z­±¤]..¥X..ªº¤¶.¡G
    ..²Ä¢±¨B..´O®Mªº´`.¾Þ§@(¬Û.¤_C.¥y¤¤ªº´O®M´`.)¡A±µ¦¬.²Ä¢²¨B©M²Ä¢³¨B.ªº
    ¦æ·½¡A§â.¦Û²Ä¢²¨B·½ªº¨C¤@¦æÉO¥¦²Ä¢³¨B¤¤¬Û.ªº¦æ.±µ¦b¤@°_¡Aªð¦^.ªG¦æ¨ì²Ä?
    ¤å¥»®Ø:5
    INDEX
    (UNIQUESCAN)
    pk_deptno
    ¤å¥»®Ø:4
    TABLEACCESS
    (BYROWID)
    dept
    ¤å¥»®Ø:3
    TABLEACCESS
    (FULL)
    emp
    ¤å¥»®Ø:6
    TABLEACCESS
    (FULL)
    salgrade
    ¤å¥»®Ø:2
    NESTEDLOOPS
    ¤å¥»®Ø:?
    FILTER
    ¨B¡C
    ..²Ä?¨B§¹¦¨¤@...¾¹¾Þ§@¡C¥¦±µ¦¬.¦Û²Ä¢±¨B©M²Ä¢µ¨Bªº¦æ·½¡A®ø°£±¼²Ä¢±¨B¤¤.ªº¡A
    ¦b²Ä¢µ¨B¦³¬Û.¦æªº¨º¨Ç¦æ¡A¦}..¦Û²Ä¢±¨Bªº³Ñ¤Uªº¦æªð¦^..¥X.¥yªº¥Î.©Î.
    ¥Î¡C
    
    ...¦æ.¦E¨B.ªº.§Ç
    .¦æ.¦E¤¤ªº¨B.¤£¬O«ö·Ó¥¦...ªº.§Ç...ªº¡GOracle­º¥ý...5-1..ÌÛ
    .§Î¨½§@..¤l¥X.ªº¨º¨Ç¨B.(¨Ò¦p¨B.3¡B5¡B6)¡C¥Ñ¨C¤@¨Bªð¦^ªº¦æ..¥¦¤U¤@¨B.ªº
    ¦æ·½¡CµM¦ZOracle..¤÷¨B.¡C
    .¨Ò..¡A.¤F.¦æ.5-1¤¤ªº.¥y¡AOracle¥H¤U¦C.§Ç...¨Ç¨B.¡G
    ..­º¥ý¡AOracle..¨B.¢²¡A¦}¤@¦æ¤@¦æ¦a..ªG¦æªð¦^.²Ä¢±¨B¡C
    ...²Ä¢²¨Bªð¦^ªº¨C¤@¦æ¡AOracle...¨Ç¨B.¡G
    --Oracle..¨B.¢´¡A¦}..ªGROWIDªð¦^.²Ä¢³¨B¡C
    --Oracle..¨B.¢³¡A¦}..ªG¦æªð¦^.²Ä¢±¨B¡C
    --Oracle..¨B.¢±¡A.±µ¨ü.¦Û²Ä¢²¨Bªº¤@¦æ©M.¦Û²Ä¢³¨Bªº¤@¦æ¡A¦}ªð¦^
    .²Ä?¨B¤@¦æ¡C
    --Oracle..¨B.¢µ¡A¦pªG¦³.ªG¦æªº.¡A.¥¦ªð¦^.²Ä?¨B¡C
    --Oracle..¨B.?¡A¦pªG.¨B.¢µªð¦^¦æ¡AOracle..¦Û²Ä¢±¨Bªº¦æªð¦^.
    .¥XSQL.¥yªº¥Î.¡C
    ª`·NOracle.¥Ñ²Ä¢²¨Bªð¦^ªº¨C¤@¦æ..¨B.¢´¡A¢³¡A¢±¡A¢µ¤@¦¸¡C.¦h¤÷¨B.¦b¥¦
    .¯à.¦æ¤§«e¥u»Ý­n.¦Û¥¦.¤l¨B.ªº.¤@¦æ¡C...ªº¤÷¨B...¡A¥u­n.¤l¨B.¤wªð¦^
    .¤@¦æ.¥ß§Y..¤÷¨B.¡]¥i¯à.¦³.¦æ.¦Eªº¨ä§E³¡¤À¡^¡C¦pªG.¤÷¨B.ªº¤÷¨B.¦P.¥i
    ¥H³q..¤@¦æªð¦^¿E¬¡ªº.¡A¨º¤\¥¦¤]¦P.³Q.¦æ¡C©Ò¥H¡A.¦æ¥i¥H¦b.¤W¦ê.¤W¥h¡A¥i¯à
    ¥]§t.¦æ.¦Eªº§E¤U³¡¤À¡C.¤_..ªº¾Þ§@¡A¥i¥H¨Ï¥Îfirst_rows§@.ɬ¤Æ¥Ø.¥H«K¤_..
    §Ö³t..¥Î.ªº.¨D¡C
    .¨C.¥Ñ¤l¨B.¨Ì¦¸.¯Á¥X.ªº¨C¤@¦æ¡AOracle´N..¤÷¨B.¤Î©Ò¦³¦ê.¦b¤@°_ªº¨B
    .¤@¦¸¡C.¥Ñ¤l¨B.ªð¦^ªº¨C¤@¦æ©ÒàD.ªº¤÷¨B.¥]¬Aªí¦s¨ú¡A¯Á¤Þ¦s¨ú¡A´O®Mªº´`..±µ
    ©M..¾¹¡C
    ¦³¨Ç¤÷¨B.¦b¥¦.³Q..¤§«e»Ý­n.¦Û¤l¨B.ªº©Ò¦³¦æ¡C...ªº¤÷¨B.¡Aª½¨ì©Ò¦³¦æ
    .¤l¨B.ªð¦^¤§«eOracle¤£¯à...¤÷¨B.¡C..ªº¤÷¨B.¥]¬A±Æ§Ç¡A±Æ§Ç¤@¦X¦}ªº.±µ¡A
    .¥\¯à©M..¡C.¤_..ªº¾Þ§@¡A¤£¯à¨Ï¥Îfirst_rows§@.ɬ¤Æ¥Ø.¡A¦Ó¥i¥H¥Îall_rows
    §@.ɬ¤Æ¥Ø.¡A¨Ï.¤¤.«¬ªº¾Þ§@¯Ó.ªº.·½³Ì¤Ö¡C
    ¦³..¥y.¦æ.¡A¦}¤£¬O¶H¤W­±.ªº¨º.¤@¨B¤@¨B¦³¥ý¦³¦Zªº.¦æ¡A¦Ó¬O¥i¯à¦}¦æ.¦æ¡A
    ¦p¦b...¹Ò¤¤¡A3¡B5¡B4¨B¥i¯à¦}¦æ.¦æ¡A¥H«K¨ú±o§ó¦nªº®Ä²v¡C.¤W­±ªº.«¬.¤W¡A¬O
    «Ü.¬Ý¥X¦U.¾Þ§@.¦æªº¥ý¦Z.§Ç¡A¦Ó³q.ORACLE¥Í¦¨ªº¥t¤@Ïú§Î¦¡ªº.¦æ.¦E¡A.¥i
    ¥H«Ü®e©öªº¬Ý¥X­þ.¾Þ§@¥ý.¦æ¡A­þ.¦Z.¦æ¡A..ªº.¦æ.¦E¬O§Ú.¯u¥¿»Ý­nªº¡A¦Z­±.
    .¥X...©ú¡C.¦b¥ý.¬Ý¤@¨Ç..ª¾.¡C
    
    ..¸ô.(¤èªk)--accesspath
    É¬¤Æ¾¹¦b§Î¦¨.¦æ.¦E.»Ý­n°µªº¤@.­«­n..¬O¦p¦ó..Õu.¬d.¥X»Ý­nªº.Õu¡C
    .¤_SQL.¥y¦s¨úªº¥ô¦óªí¤¤ªº¥ô¦ó¦æ¡A¥i¯à¦s¦b.¦h¦s¨ú¸ô.(¦s¨ú¤èªk)¡A³q.¥¦.¥i
    ¥H©w¦ì©M¬d.¥X»Ý­nªº.Õu¡Cɬ¤Æ¾¹..¨ä¤¤¦Û..¬O³Ìɬ¤Æªº¸ô.¡C
    ¦bª«²z.¡Aoracle.¨ú.Õu¡A¤@¦¸.¨úªº³Ì¤p.¦ì..Õu..(¥Ñ¦h...ªº¾Þ§@¨t.
    ..¦¨)¡A¤@¦¸.¨úªº³Ì¤j­È¥Ñ¾Þ§@¨t.¤@¦¸I/Oªº³Ì¤j­ÈÉOmultiblock..¦@¦P.©w¡A©Ò
    ¥H§Y¨Ï¥u»Ý­n¤@¦æ.Õu¡A¤]¬O..¦æ©Ò¦bªº.Õu...¤J.¦s¡C..¤W¡Aoracle¥Î¦p¤U¦s¨ú
    ¤èªk...Õu¡G
    1)¥þªí.´y¡]FullTableScans,FTS¡^
    ...¥þªí.´y¡AOracle.¨úªí¤¤©Ò¦³ªº¦æ¡A¦}.¬d¨C¤@¦æ¬O§_.¨¬.¥yªºWHERE
    ­­¨î.¥ó¡COracle.§Ç¦a.¨ú¤À°t.ªíªº¨C..Õu.¡Aª½¨ì.¨ìªíªº³Ì°ª¤ô..(highwater
    mark,HWM¡A..ªíªº³Ì¦Z¤@..Õu.)¡C¤@.¦h..¾Þ§@¥i¥H¨Ï¤@¦¸I/O¯à.¨ú¦h..Õu
    .(db_block_multiblock_read_count...©w)¡A¦Ó¤£¬O¥u.¨ú¤@..Õu.¡A.Ìå¤jªº.¤Ö
    ¤FI/O.¦¸.¡A´£°ª¤F¨t.ªº§]¦R¶q¡A©Ò¥H§Q¥Î¦h..ªº¤èªk¥i¥H¤Q¤À°ª®Ä¦a..¥þªí.´y¡A
    ¦Ó¥B¥u¦³¦b¥þªí.´yªº±¡.¤U¤~¯à¨Ï¥Î¦h..¾Þ§@¡C¦b.Ïú..¼Ò¦¡¤U¡A¨C..Õu.¥u³Q.
    ¤@¦¸¡C¥Ñ¤_HWM..³Ì¦Z¤@.³Q.¤Jªº.Õu¡A¦Ódelete¾Þ§@¤£¼v.HWM­È¡A©Ò¥H¤@.
    ªíªº©Ò¦³.Õu³Qdelete¦Z¡A¨ä¥þªí.´yªº..¤£.¦³§ïµ½¡A¤@¯ë§Ú.»Ý­n¨Ï¥Îtruncate©R
    ¥O.¨ÏHWM­È..0¡C©¯.ªº¬Ooracle10G¦Z¡A¥i¥H¤H¤u¦¬.HWMªº­È¡C
    ¥ÑFTS¼Ò¦¡.¤Jªº.Õu³Q©ñ¨ì°ª³t.¦sªºLeastRecentlyUsed(LRU)¦Cªíªº§À³¡¡A.
    .¥i¥H¨Ï¨ä§Ö³t¥æ.¥X.¦s¡A.¦Ó¤£¨Ï.¦s­«­nªº.Õu³Q¥æ.¥X.¦s¡C
    ¨Ï¥ÎFTSªº«e´£.¥ó¡G¦b.¤jªºªí¤W¤£«Ø.¨Ï¥Î¥þªí.´y¡A°£«D¨ú¥X.Õuªº¤ñ.¦h¡A
    ¶W..¶qªº5%--10%¡A©Î§A·Q¨Ï¥Î¦}¦æ¬d.¥\¯à.¡C
    ¨Ï¥Î¥þªí.´yªº¨Ò¤l¡G
    ~~~~~~~~~~~~~~~~~~~~~~~~
    SQL>explainplanforselect*fromdual;
    QueryPlan
    -----------------------------------------
    SELECTSTATEMENT[CHOOSE]Cost=
    TABLEACCESSFULLDUAL
    
    2)³q.ROWIDªºªí¦s¨ú¡]TableAccessbyROWID©Îrowidlookup¡^
    ¦æªºROWID«ü¥X¤F.¦æ©Ò¦bªº.Õu¤å¥ó¡B.Õu.¥H¤Î¦æ¦b..¤¤ªº¦ì¸m¡A©Ò¥H³q.
    ROWID.¦s¨ú.Õu¥i¥H§Ö³t©w¦ì¨ì¥Ø..Õu¤W¡A¬OOracle¦s¨ú.¦æ.Õuªº³Ì§Ö¤èªk¡C
    .¤F³q.ROWID¦s¨úªí¡AOracle­º¥ý­n.¨ú³Q..¦æªºROWID¡A©ÎªÌ..¥yªº
    WHERE¤l¥y¤¤±o¨ì¡A©ÎªÌ³q.ªíªº¤@.©Î¦h.¯Á¤Þªº¯Á¤Þ.´y±o¨ì¡COracleµM¦Z¥H±o¨ì
    ªºROWID.¨ÌÕu©w¦ì¨C.³Q..ªº¦æ¡C
    .Ïú¦s¨ú¤èªk¤£.¥Î¨ì¦h..¾Þ§@¡A¤@¦¸I/O¥u¯à.¨ú¤@..Õu.¡C§Ú...±`¦b.
    ¦æ.¦E¤¤¬Ý¨ì.¦s¨ú¤èªk¡A¦p³q.¯Á¤Þ¬d..Õu¡C
    ¨Ï¥ÎROWID¦s¨úªº¤èªk¡G
    SQL>explainplanforselect*fromdeptwhererowid='AAAAyGAADAAAAATAAF';
    QueryPlan
    ------------------------------------
    SELECTSTATEMENT[CHOOSE]Cost=1
    TABLEACCESSBYROWIDDEPT[ANALYZED]
    
    3¡^¯Á¤Þ.´y¡]IndexScan©Îindexlookup¡^
    §Ú.¥ý³q.index¬d§ä¨ì.Õu..ªºrowid­È(.¤_«D°ß¤@¯Á¤Þ¥i¯àªð¦^¦h.rowid­È)¡A
    µM¦Z®ÚÕurowidª½±µ.ªí¤¤±o¨ì¨ãÊ^ªº.Õu¡A.Ïú¬d§ä¤è¦¡..¯Á¤Þ.´y©Î¯Á¤Þ¬d§ä(index
    lookup)¡C¤@.rowid°ß¤@ªºªí¥Ü¤@¦æ.Õu¡A.¦æ..ªº.Õu.¬O³q.¤@¦¸i/o±o¨ìªº¡A¦b¦¹
    ±¡.¤U.¦¸i/o¥u..¨ú¤@..Õu..¡C
    ¦b¯Á¤Þ¤¤¡A°£¤F¦s.¨C.¯Á¤Þªº­È¥~¡A¯Á¤Þ.¦s.¨ã¦³¦¹­Èªº¦æ..ªºROWID­È¡C¯Á
    ¤Þ.´y¥i¥H¥Ñ2¨B.¦¨¡G(1).´y¯Á¤Þ±o¨ì..ªºrowid­È¡C(2)³q.§ä¨ìªºrowid.ªí¤¤
    .¥X¨ãÊ^ªº.Õu¡C¨C¨B³£¬O..ªº¤@¦¸I/O¡A¦ý¬O.¤_¯Á¤Þ¡A¥Ñ¤_.±`¨Ï¥Î¡A.¤j¦h.³£¤w
    .CACHE¨ì.¦s¤¤¡A©Ò¥H²Ä1¨BªºI/O.±`¬O..I/O¡A§Y.Õu¥i¥H..¦s¤¤±o¨ì¡C¦ý¬O
    .¤_²Ä2¨B..¡A¦pªGªí¤ñ.¤j¡A.¨ä.Õu¤£¥i¯à¥þ¦b.¦s¤¤¡A©Ò¥H¨äI/O«Ü¦³¥i¯à¬Oª«²z
    I/O¡A.¬O¤@.Éó±ñ¾Þ§@¡A¬Û...I/O..¡A¬OÌå¨ä...ªº¡C©Ò¥H¦pªG¦h¤jªí.¦æ¯Á¤Þ
    .´y¡A¨ú¥Xªº.Õu¦pªG¤j¤_.¶qªº5%--10%¡A¨Ï¥Î¯Á¤Þ.´y.®Ä²v¤U­°«Ü¦h¡C
    ¦p¤U¦C©Ò¥Ü¡G
    SQL>explainplanforselectempno,enamefromempwhereempno=10;
    QueryPlan
    ------------------------------------
    SELECTSTATEMENT[CHOOSE]Cost=1
    TABLEACCESSBYROWIDEMP[ANALYZED]
    INDEXUNIQUESCANEMP_I1
    ª`·NTABLEACCESSBYROWIDEMP³¡¤À¡A.ªí©ú.¤£¬O³q.FTS¦s¨ú¸ô...
    .Õu¡A¦Ó¬O³q.rowidlookup¦s¨ú¸ô....Õuªº¡C¦b¦¹¨Ò¤¤¡A©Ò»Ý­nªºrowid¬O¥Ñ¤_¦b¯Á
    ¤Þ¬d§äempno¦Cªº­È±o¨ìªº¡A.Ïú¤è¦¡¬OINDEXUNIQUESCAN¬d§ä¡A¦Z­±.¤©¤¶.¡A
    EMP_I1.¨Ï¥Îªº.¦æ¯Á¤Þ¬d§äªº¯Á¤Þ¦W¦r¡C
    
    ¦ý¬O¦pªG¬d.ªº.Õu¯à¥þ¦b¯Á¤Þ¤¤§ä¨ì¡A´N¥i¥HÁקK.¦æ²Ä2¨B¾Þ§@¡AÁקK¤F¤£¥²­n
    ªºI/O¡A¦¹.§Y¨Ï³q.¯Á¤Þ.´y¨ú¥Xªº.Õu¤ñ.¦h¡A®Ä²v.¬O«Ü°ªªº¡A¦]..¥u.¦b¯Á¤Þ¤¤
    .¨ú¡C©Ò¥H¤W­±§Ú¦b¤¶.°ò¤_..ªºÉ¬¤Æ¾¹.¡A¨Ï¥Î¤Fselectcount(id)from
    SWD_BILLDETAILwherecn<'6'¡A¦Ó.¦³¨Ï¥Îselectcount(cn)fromSWD_BILLDETAIL
    wherecn<'6'¡C¦].¦b..±¡.¤¤¡A¥u¬d.³Q¯Á¤Þ¦Cªº­Èªº±¡.Ìå.¤Ö¡A©Ò¥H¡A¦pªG§Ú¦b¬d
    .¤¤¨Ï¥Îcount(cn)¡A.¤£¨ã¦³¥Nªí©Ê¡C
    
    SQL>explainplanforselectempnofromempwhereempno=10;--¥u¬d.empno¦C­È
    QueryPlan
    ------------------------------------
    SELECTSTATEMENT[CHOOSE]Cost=1
    INDEXUNIQUESCANEMP_I1
    
    .¤@¨B.¡A¦pªGsql.¥y¤¤.¯Á¤Þ¦C.¦æ±Æ§Ç¡A¦].¯Á¤Þ¤w..¥ý±Æ§Ç¦n¤F¡A©Ò¥H¦b
    .¦æ.¦E¤¤¤£»Ý­n¦A.¯Á¤Þ¦C.¦æ±Æ§Ç
    SQL>explainplanforselectempno,enamefromemp
    whereempno>7876orderbyempno;
    QueryPlan
    --------------------------------------------------------------------------------
    SELECTSTATEMENT[CHOOSE]Cost=1
    TABLEACCESSBYROWIDEMP[ANALYZED]
    INDEXRANGESCANEMP_I1[ANALYZED]
    ...¨Ò¤l¤¤¥i¥H¬Ý¨ì¡G¦].¯Á¤Þ¬O¤w.±Æ§Ç¤Fªº¡A©Ò¥H.«ö·Ó¯Á¤Þªº.§Ç¬d.¥X²Å
    ¦X.¥óªº¦æ¡A¦]¦¹ÁקK¤F.¤@¨B±Æ§Ç¾Þ§@¡C
    
    ®ÚÕu¯Á¤Þªº.«¬ÉOwhere­­¨î.¥óªº¤£¦P¡A¦³4Ïú.«¬ªº¯Á¤Þ.´y¡G
    ¯Á¤Þ°ß¤@.´y(indexuniquescan)
    ¯Á¤Þ­S..´y(indexrangescan)
    ¯Á¤Þ¥þ.´y(indexfullscan)
    ¯Á¤Þ§Ö³t.´y(indexfastfullscan)
    
    (1)¯Á¤Þ°ß¤@.´y(indexuniquescan)
    ³q.°ß¤@¯Á¤Þ¬d§ä¤@..­È.±`ªð¦^..ROWID¡C¦pªG.°ß¤@¯Á¤Þ¦³¦h.¦C.¦¨
    (§Y.¦X¯Á¤Þ)¡A.¦Ü¤Ö­n¦³.¦X¯Á¤Þªº¤Þ.¦C.ÉO¨ì.¬d.¤¤¡A¦p.«Ø¤@.¯Á¤Þ¡Gcreate
    indexidx_testonemp(ename,deptno,loc)¡C.selectenamefromempwhere
    ename=¡¥JACK¡¦anddeptno=¡¥DEV¡¦.¥y¥i¥H¨Ï¥Î.¯Á¤Þ¡C¦pªG..¥y¥uªð¦^¤@¦æ¡A
    .¦s¨ú¤èªk..¯Á¤Þ°ß¤@.´y¡C¦Óselectenamefromempwheredeptno=¡¥DEV¡¦.
    ¥y.¤£.¨Ï¥Î.¯Á¤Þ¡A¦].where¤l¥yÏú.¦³¤Þ.¦C¡C¦pªG¦s¦bUNIQUE©Î
    PRIMARYKEY.§ô¡]¥¦«O.¤F.¥y¥u¦s¨ú.¦æ¡^ªº.¡AOracle.±`..°ß¤@©Ê.´y¡C
    ¨Ï¥Î°ß¤@©Ê.§ôªº¨Ò¤l¡G
    SQL>explainplanfor
    selectempno,enamefromempwhereempno=10;
    QueryPlan
    ------------------------------------
    SELECTSTATEMENT[CHOOSE]Cost=1
    TABLEACCESSBYROWIDEMP[ANALYZED]
    INDEXUNIQUESCANEMP_I1
    
    (2)¯Á¤Þ­S..´y(indexrangescan)
    ¨Ï¥Î¤@.¯Á¤Þ¦s¨ú¦h¦æ.Õu¡A¦P¤W­±¤@.¡A¦pªG¯Á¤Þ¬O.¦X¯Á¤Þ¡A¦p(1)©Ò¥Ü¡A¦Ó
    ¥Bselectenamefromempwhereename=¡¥JACK¡¦anddeptno=¡¥DEV¡¦.¥yªð¦^¦h¦æ
    .Õu¡A.µM..¥y.¬O¨Ï¥Î..¦X¯Á¤Þ.¦æ¬d.¡A¥i¦¹.ªº¦s¨ú¤èªk..¯Á¤Þ­S..
    ´y¡C¦b°ß¤@¯Á¤Þ¤W¨Ï¥Î¯Á¤Þ­S..´yªº¨å«¬±¡.¤U¬O¦b..(where­­¨î.¥ó)¤¤¨Ï¥Î
    ¤F­S.¾Þ§@²Å(¦p>¡B<¡B<>¡B>=¡B<=¡Bbetween)
    ¨Ï¥Î¯Á¤Þ­S..´yªº¨Ò¤l¡G
    SQL>explainplanforselectempno,enamefromemp
    whereempno>7876orderbyempno;
    QueryPlan
    --------------------------------------------------------------------------------
    SELECTSTATEMENT[CHOOSE]Cost=1
    TABLEACCESSBYROWIDEMP[ANALYZ, ED]
    INDEXRANGESCANEMP_I1[ANALYZED]
    
    ¦b«D°ß¤@¯Á¤Þ¤W¡A..col=5¥i¯àªð¦^¦h¦æ.Õu¡A©Ò¥H¦b«D°ß¤@¯Á¤Þ¤W³£¨Ï¥Î¯Á¤Þ­S
    ..´y¡C
    ¨Ï¥Îindexrangscanªº3Ïú±¡.¡G
    (a)¦b°ß¤@¯Á¤Þ¦C¤W¨Ï¥Î¤Frange¾Þ§@²Å(><<>>=<=between)
    (b)¦b.¦X¯Á¤Þ¤W¡A¥u¨Ï¥Î³¡¤À¦C.¦æ¬d.¡A.­P¬d.¥X¦h¦æ
    (c).«D°ß¤@¯Á¤Þ¦C¤W.¦æªº¥ô¦ó¬d.¡C
    
    (3)¯Á¤Þ¥þ.´y(indexfullscan)
    ÉO¥þªí.´y..¡A¤]¦³¬Û.ªº¥þ¯Á¤Þ.´y¡C¦b¬Y¨Ç±¡.¤U¡A¥i¯à.¦æ¥þ¯Á¤Þ.´y¦Ó
    ¤£¬O­S..´y¡A»Ý­nª`·Nªº¬O¥þ¯Á¤Þ.´y¥u¦bCBO¼Ò¦¡¤U¤~¦³®Ä¡CCBO®ÚÕu...
    ­È±oª¾.¦æ¥þ¯Á¤Þ.´y¤ñ.¦æ¥þªí.´y§ó¦³®Ä.¡A¤~.¦æ¥þ¯Á¤Þ.´y¡A¦Ó¥B¦¹.¬d.
    ¥Xªº.Õu³£¥²..¯Á¤Þ¤¤¥i¥Hª½±µ±o¨ì¡C
    ¥þ¯Á¤Þ.´yªº¨Ò¤l¡G
    AnIndexfullscanwillnotperformsingleblocki/o'sandsoitmayprovetobe
    inefficient.
    
    e.g.
    IndexBE_IXisaconcatenatedindexonbig_emp(empno,ename)
    
    SQL>explainplanforselectempno,enamefrombig_emporderbyempno,ename;
    QueryPlan
    --------------------------------------------------------------------------------
    SELECTSTATEMENT[CHOOSE]Cost=26
    INDEXFULLSCANBE_IX[ANALYZED]
    
    (4)¯Á¤Þ§Ö³t.´y(indexfastfullscan)
    .´y¯Á¤Þ¤¤ªº©Ò¦³ªº.Õu.¡AÉOindexfullscan«Ü.¦ü¡A¦ý¬O¤@..µÛªº..´N
    ¬O¥¦¤£.¬d.¥Xªº.Õu.¦æ±Æ§Ç¡A§Y.Õu¤£¬O¥H±Æ§Ç.§Ç³Qªð¦^¡C¦b.Ïú¦s¨ú¤èªk¤¤¡A
    ¥i¥H¨Ï¥Î¦h..¥\¯à¡A¤]¥i¥H¨Ï¥Î¦}¦æ.¤J¡A¥H«K.±o³Ì¤j§]¦R¶qÉO.µu.¦æ..¡C
    
    ¯Á¤Þ§Ö³t.´yªº¨Ò¤l¡G
    BE_IX¯Á¤Þ¬O¤@.¦h¦C¯Á¤Þ¡Gbig_emp(empno,ename)
    
    SQL>explainplanforselectempno,enamefrombig_emp;
    QueryPlan
    ------------------------------------------
    SELECTSTATEMENT[CHOOSE]Cost=1
    INDEXFASTFULLSCANBE_IX[ANALYZED]
    
    ¥u..¦h¦C¯Á¤Þªº²Ä2¦C¡G
    SQL>explainplanforselectenamefrombig_emp;
    QueryPlan
    ------------------------------------------
    SELECTSTATEMENT[CHOOSE]Cost=1
    INDEXFASTFULLSCANBE_IX[ANALYZED]
    
    
    ªí¤§.ªº.±µ
    Join¬O¤@Ïú.....ªí.¦X¦b¤@°_ªº..¡A¤@¦¸¥u¯à.±µ2.ªí¡Aªí.±µ¤]¥i¥H³Q
    ..ªí..¡C¦b¦Z­±ªº.­z¤¤¡A§Ú...¨Ï¥Î¡¨rowsource¡¨.¥N´À¡¨ªí¡¨¡A¦].¨Ï¥Îrowsource
    §ó..¤@¨Ç¡A¦}¥B..ÉO.±µªº2.rowsource¤À...rowsource1©Mrowsource2¡C
    Join.µ{ªº¦U.¨B..±`¬O¦ê¦æ¾Þ§@¡A§Y¨Ï¬Û.ªºrowsource¥i¥H³Q¦}¦æ..¡A§Y¥i¥H¦}
    ¦æªº.¨ú°µjoin.±µªº..rowsourceªº.Õu¡A¦ý¬O¦b.ªí¤¤²Å¦X­­¨î.¥óªº.Õu.¤J¨ì
    .¦s§Î¦¨rowsource¦Z¡Ajoinªº¨ä¥¦¨B.¤@¯ë¬O¦ê¦æªº¡C¦³¦hÏú¤èªk¥i¥H.2.ªí.±µ°_
    .¡A.µM¨CÏú¤èªk³£¦³¦Û¤vªºÉ¬¯Ê.¡A¨CÏú.±µ.«¬¥u¦³¦b¯S©wªº.¥ó¤U¤~...¥X¨ä³Ì¤j
    É¬.¡C
    
    rowsource(ªí)¤§.ªº.±µ.§Ç.¤_¬d.ªº®Ä²v¦³«D±`¤jªº¼v.¡C³q.­º¥ý¦s¨ú¯S©w
    ªºªí¡A§Y..ªí§@...ªí¡A..¥i¥H¥ý.¥Î¬Y¨Ç­­¨î.¥ó¡A.¦Ó±o¨ì¤@..¤pªºrow
    source¡A¨Ï.±µªº®Ä²v.°ª¡A.¤]´N¬O§Ú.±`.ªº­n¥ý.¦æ­­¨î.¥óªº­ì¦]¡C¤@¯ë¬O¦b.ªí
    .¤J.¦s.¡A.¥Îwhere¤l¥y¤¤..ªíªº­­¨î.¥ó¡C
    ®ÚÕu2.rowsourceªº.±µ.¥óªº¤¤¾Þ§@²Åªº¤£¦P¡A¥i¥H..±µ¤À.µ¥­È.±µ(¦p
    WHEREA.COL3=B.COL4)¡B«Dµ¥­È.±µ(WHEREA.COL3>B.COL4)¡B¥~.±µ(WHERE
    A.COL3=B.COL4(+))¡C¤W­±ªº¦U..±µªº.±µ­ì²z³£°ò¥»¤@.¡A©Ò¥H.¤F..´Á.¡A¤U­±
    ¥Hµ¥­È.±µ.¨Ò.¦æ¤¶.¡C¦b¦Z­±ªº¤¶.¤¤¡A³£¤w¡G
    SELECTA.COL1,B.COL2
    FROMA,B
    WHEREA.COL3=B.COL4;
    .¨Ò.¦æ.©ú¡A°².Aªí.RowSoruce1¡A.¨ä..ªº.±µ¾Þ§@..¦C.COL3¡FB
    ªí.RowSoruce2¡A.¨ä..ªº.±µ¾Þ§@..¦C.COL4¡F
    
    .±µ.«¬¡G
    ¥Ø«e.¤î¡A...±µ¾Þ§@²Å¦p¦ó¡A¨å«¬ªº.±µ.«¬¦@¦³3Ïú¡G
    ±Æ§Ç--¦X¦}.±µ(SortMergeJoin(SMJ))
    ´O®M´`.(NestedLoops(NL))
    «¢§Æ.±µ(HashJoin)
    
    ±Æ§Ç--¦X¦}.±µ(SortMergeJoin,SMJ)
    .³¡.±µ.µ{¡G
    1)­º¥ý¥Í¦¨rowsource1»Ý­nªº.Õu¡AµM¦Z..¨Ç.Õu«ö·Ó.±µ¾Þ§@..¦C(¦pA.col3)
    .¦æ±Æ§Ç¡C
    2).¦Z¥Í¦¨rowsource2»Ý­nªº.Õu¡AµM¦Z..¨Ç.Õu«ö·ÓÉOsortsource1..ªº.
    ±µ¾Þ§@..¦C(¦pB.col4).¦æ±Æ§Ç¡C
    3)³Ì¦Z..¤w±Æ§Çªº¦æ³Q©ñ¦b¤@°_.¦æ¦X¦}¾Þ§@¡A§Y.2.rowsource«ö·Ó.±µ.
    ¥ó.±µ°_.
    ¤U­±¬O.±µ¨B.ªº.§Îªí¥Ü¡G
    MERGE
    /\
    SORTSORT
    ||
    RowSource1RowSource2
    
    ¦pªGrowsource¤w.¦b.±µ..¦C¤W³Q±Æ§Ç¡A...±µ¾Þ§@´N¤£»Ý­n¦A.¦æsort
    ¾Þ§@¡A..¥i¥H¤j¤j´£°ª.Ïú.±µ¾Þ§@ªº.±µ³t«×¡A¦].±Æ§Ç¬O.Ìå¨ä..·½ªº¾Þ§@¡A
    ¯S.¬O.¤_.¤jªºªí¡C.¥ý±Æ§Çªºrowsource¥]¬A¤w.³Q¯Á¤Þªº¦C(¦pa.col3©Î
    b.col4¤W¦³¯Á¤Þ)©Îrowsource¤w.¦b«e­±ªº¨B.¤¤³Q±Æ§Ç¤F¡C.ºÞ¦X¦}..row
    sourceªº.µ{¬O¦ê¦æªº¡A¦ý¬O¥i¥H¦}¦æ.....rowsource(¦p¦}¦æ.¤J.Õu¡A¦}
    ¦æ±Æ§Ç).
    
    SMJ.±µªº¨Ò¤l¡G
    SQL>explainplanfor
    select/*+ordered*/e.deptno,d.deptno
    fromempe,deptd
    wheree.deptno=d.deptno
    orderbye.deptno,d.deptno;
    
    QueryPlan
    -------------------------------------
    SELECTSTATEMENT[CHOOSE]Cost=17
    MERGEJOIN
    SORTJOIN
    TABLEACCESSFULLEMP[ANALYZED]
    SORTJOIN
    TABLEACCESSFULLDEPT[ANALYZED]
    
    ±Æ§Ç¬O¤@...¡B..·½ªº¾Þ§@¡A¯S..¤_¤jªí¡C°ò¤_..­ì¦]¡ASMJ.±`¤£¬O
    ¤@.¯S.¦³®Äªº.±µ¤èªk¡A¦ý¬O¦pªG2.rowsource³£¤w..¥ý±Æ§Ç¡A..Ïú.±µ¤è
    ªkªº®Ä²v¤]¬O.°ªªº¡C
    
    ´O®M´`.(NestedLoops,NL)
    ...±µ¤èªk¦³..ªí(¥~³¡ªí)ªº·§©À¡C¨ä.¡A..±µ.µ{´N¬O¤@.2.´O®M´`
    .¡A©Ò¥H¥~.´`.ªº¦¸.¶V¤Ö¶V¦n¡A.¤]´N¬O§Ú..¤°¤\.¤pªí©Îªð¦^.¤prowsource
    ªºªí§@...ªí(¥Î¤_¥~.´`.)ªº²z.¨ÌÕu¡C¦ý¬O..²z.¥u¬O¤@¯ë«ü.­ì.¡A¦].
    ¿í´`..²z.¦}¤£¯à.«O.¨Ï.¥y.¥ÍªºI/O¦¸.³Ì¤Ö¡C¦³.¤£¿í¦u..²z.¨ÌÕu¡A
    ¤Ï¦Ó..±o§ó¦nªº®Ä²v¡C¦pªG¨Ï¥Î.Ïú¤èªk¡A.©w¨Ï¥Î­þ.ªí§@...ªí«Ü­«­n¡C¦³
    .¦pªG..ªí..¤£¥¿ÚÌ¡A...­P.¥yªº©Ê¯à«Ü®t¡B«Ü®t¡C
    
    .³¡.±µ.µ{¡G
    Rowsource1ªºRow1----------------Probe->Rowsource2
    Rowsource1ªºRow2----------------Probe->Rowsource2
    Rowsource1ªºRow3----------------Probe->Rowsource2
    ¡K¡K.
    Rowsource1ªºRown----------------Probe->Rowsource2
    ..³¡.±µ.µ{.¬Ý¡A»Ý­n¥Îrowsource1¤¤ªº¨C¤@¦æ¡A¥h¤Ç°trowsource2¤¤
    ªº©Ò¦³¦æ¡A©Ò¥H¦¹.«O«ùrowsource1.¥i¯àªº¤pÉO°ª®Äªº..rowsource2(¤@¯ë³q
    .¯Á¤Þ..)¬O¼v....±µ®Ä²vªº....¡C.¥u¬O²z.«ü.­ì.¡A¥Øªº¬O¨Ï¾ã..
    ±µ¾Þ§@.¥Í³Ì¤Öªºª«²zI/O¦¸.¡A¦Ó¥B¦pªG¿í¦u..­ì.¡A¤@¯ë¤].¨Ï.ªºª«²zI/O
    .³Ì¤Ö¡C¦ý¬O¦pªG¤£¿í...«ü.­ì.¡A¤Ï¦Ó¯à¥Î§ó¤Öªºª«²zI/O...±µ¾Þ§@¡A¨º
    .ºÞ.¤Ï«ü.­ì.§a¡I¦].³Ì¤Öªºª«²zI/O¦¸.¤~¬O§Ú...¿í.ªº¯u¥¿ªº«ü.­ì.¡A
    ¦b¦Z­±ªº¨ãÊ^®×¨Ò¤ÀªR¤¤´N.¥X..ªº¨Ò¤l¡C
    
    ¦b¤W­±ªº.±µ.µ{¤¤¡A§Ú..Rowsource1...ªí©Î¥~³¡ªí¡CRowSource2³Q
    ..³Q±´¬dªí©Î.³¡ªí¡C
    
    ¦bNESTEDLOOPS.±µ¤¤¡AOracle.¨úrowsource1¤¤ªº¨C¤@¦æ¡AµM¦Z¦brow
    sourc2¤¤.¬d¬O§_¦³¤Ç°tªº¦æ¡A©Ò¦³³Q¤Ç°tªº¦æ³£³Q©ñ¨ì.ªG¶°¤¤¡AµM¦Z.²zrow
    source1¤¤ªº¤U¤@¦æ¡C...µ{¤@ª½..¡Aª½¨ìrowsource1¤¤ªº©Ò¦³¦æ³£³Q.²z¡C
    .¬O..±µ¾Þ§@¤¤¥i¥H±o¨ì²Ä¤@.¤Ç°t¦æªº³Ì§Öªº¤èªk¤§¤@¡A.Ïú.«¬ªº.±µ¥i¥H¥Î
    ¦b»Ý­n§Ö³t..ªº.¥y¤¤¡A¥H..³t«×.¥D­n¥Ø.¡C
    
    ¦pªGdrivingrowsource(¥~³¡ªí)¤ñ.¤p¡A¦}¥B¦binnerrowsource(.³¡ªí)¤W¦³°ß
    ¤@¯Á¤Þ¡A©Î¦³°ª..©Ê«D°ß¤@¯Á¤Þ.¡A¨Ï¥Î.Ïú¤èªk¥i¥H±o¨ì.¦nªº®Ä²v¡CNESTED
    LOOPS¦³¨ä¥¦.±µ¤èªk.¦³ªºªº¤@.ɬ.¬O¡G¥i¥H¥ýªð¦^¤w..±µªº¦æ¡A¦Ó¤£¥²µ¥
    «Ý©Ò¦³ªº.±µ¾Þ§@.²z§¹¤~ªð¦^.Õu¡A.¥i¥H..§Ö³tªº....¡C
    
    ¦pªG¤£¨Ï¥Î¦}¦æ¾Þ§@¡A³Ì¦nªº..ªí¬O¨º¨Ç.¥Î¤Fwhere­­¨î.¥ó¦Z¡A¥i¥Hªð¦^
    .¤Ö¦æ.Õuªºªºªí¡A©Ò¥H¤jªí¤]¥i¯à....ªí¡A..¬Ý­­¨î.¥ó¡C.¤_¦}¦æ¬d.¡A
    §Ú..±`..¤jªí§@...ªí¡A¦].¤jªí¥i¥H¥R¤À§Q¥Î¦}¦æ¥\¯à¡C.µM¡A¦³..¬d.
    ¨Ï¥Î¦}¦æ¾Þ§@¦}¤£¤@©w.¤ñ¬d.¤£¨Ï¥Î¦}¦æ¾Þ§@®Ä²v°ª¡A¦].³Ì¦Z¥i¯à¨C.ªí¥u¦³«Ü
    ¤Öªº¦æ²Å¦X­­¨î.¥ó¡A¦Ó¥B.­n¬Ý§Aªºµw¥ó°t¸m¬O§_¥i¥H¤ä«ù¦}¦æ(¦p¬O§_¦³¦h.
    CPU¡A¦h.µw.±±¨î¾¹)¡A©Ò¥H­n¨ãÊ^..¨ãÊ^.«Ý¡C
    
    NL.±µªº¨Ò¤l¡G
    SQL>explainplanfor
    selecta.dname,b.sql
    fromdepta,empb
    wherea.deptno=b.deptno;
    
    QueryPlan
    -------------------------
    SELECTSTATEMENT[CHOOSE]Cost=5
    NESTEDLOOPS
    TABLEACCESSFULLDEPT[ANALYZED]
    TABLEACCESSFULLEMP[ANALYZED]
    
    «¢§Æ.±µ(HashJoin,HJ)
    .Ïú.±µ¬O¦boracle7.3¥H¦Z¤Þ¤Jªº¡A.²z.¤W..¤ñNLÉOSMJ§ó°ª®Ä¡A¦Ó¥B
    ¥u¥Î¦bCBOɬ¤Æ¾¹¤¤¡C
    .¤pªºrowsource³Q¥Î.ÌÛ«ØhashtableÉObitmap¡A²Ä2.rowsource³Q¥Î.
    ³Qhansed¡A¦}ÉO²Ä¤@.rowsource¥Í¦¨ªºhashtable.¦æ¤Ç°t¡A¥H«K.¦æ.¤@¨Bªº
    .±µ¡CBitmap³Q¥Î.§@.¤@Ïú¤ñ.§Öªº¬d§ä¤èªk¡A..¬d¦bhashtable¤¤¬O§_¦³¤Ç°t
    ªº¦æ¡C¯S.ªº¡A.hashtable¤ñ.¤j¦Ó¤£¯à¥þ³¡®e.¦b.¦s¤¤.¡A.Ïú¬d§ä¤èªk§ó.
    ¦³¥Î¡C.Ïú.±µ¤èªk¤]¦³NL.±µ¤¤©Ò.ªº..ªíªº·§©À¡A³QÌÛ«Ø.hashtableÉO
    bitmapªºªí...ªí¡A.³QÌ۫تºhashtableÉObitmap¯à³Q®e.¦b.¦s¤¤.¡A.Ïú
    .±µ¤è¦¡ªº®Ä²vÌå°ª¡C
    
    HASH.±µªº¨Ò¤l¡G
    SQL>explainplanfor
    select/*+use_hash(emp)*/empno
    fromemp,dept
    whereemp.deptno=dept.deptno;
    
    QueryPlan
    ----------------------------
    SELECTSTATEMENT[CHOOSE]Cost=3
    HASHJOIN
    TABLEACCESSFULLDEPT
    TABLEACCESSFULLEMP
    
    ­n¨Ï«¢§Æ.±µ¦³®Ä¡A»Ý­n.¸mHASH_JOIN_ENABLED=TRUE¡A¯Ê¬Ù±¡.¤U..
    ..TRUE¡A¥t¥~¡A¤£­n§Ñ¤F.­n.¸mhash_area_size..¡A¥H¨Ï«¢§Æ.±µ°ª®Ä.
    ¦æ¡A¦].«¢§Æ.±µ.¦b...«ü©w¤j¤pªº.¦s¤¤.¦æ¡A.¤pªº...¨Ï«¢§Æ.±µªº©Ê
    ¯à¤ñ¨ä¥L.±µ¤è¦¡.­n§C¡C
    
    ..¤@¤U¡A¦b­þÏú±¡.¤U¥Î­þÏú.±µ¤èªk¤ñ.¦n¡G
    ±Æ§Ç--¦X¦}.±µ(SortMergeJoin,SMJ)¡G
    a).¤_«Dµ¥­È.±µ¡A.Ïú.±µ¤è¦¡ªº®Ä²v¬O¤ñ.°ªªº¡C
    b)¦pªG¦b..ªº¦C¤W³£¦³¯Á¤Þ¡A®ÄªG§ó¦n¡C
    c).¤_.2..¤jªºrowsource°µ.±µ¡A..±µ¤èªk¤ñNL.±µ­n¦n¤@¨Ç¡C
    d)¦ý¬O¦pªGsortmergeªð¦^ªºrowsource.¤j¡A.¤S..­P¨Ï¥Î.¦hªºrowid
    ¦bªí¤¤¬d..Õu.¡A.Õu.©Ê¯à¤U­°¡A¦]..¦hªºI/O¡C
    ´O®M´`.(NestedLoops,NL)¡G
    a)¦pªGdrivingrowsource(¥~³¡ªí)¤ñ.¤p¡A¦}¥B¦binnerrowsource(.³¡ªí)¤W
    ¦³°ß¤@¯Á¤Þ¡A©Î¦³°ª..©Ê«D°ß¤@¯Á¤Þ.¡A¨Ï¥Î.Ïú¤èªk¥i¥H±o¨ì.¦nªº®Ä²v¡C
    b)NESTEDLOOPS¦³¨ä¥¦.±µ¤èªk.¦³ªºªº¤@.ɬ.¬O¡G¥i¥H¥ýªð¦^¤w.
    .±µªº¦æ¡A¦Ó¤£¥²µ¥«Ý©Ò¦³ªº.±µ¾Þ§@.²z§¹¤~ªð¦^.Õu¡A
    .¥i¥H..§Ö³tªº....¡C
    «¢§Æ.±µ(HashJoin,HJ)¡G
    a).Ïú¤èªk¬O¦boracle7¦Z.¤Þ¤Jªº¡A¨Ï¥Î¤F¤ñ.¥ý.ªº.±µ²z.¡A
    ¤@¯ë..¡A¨ä®Ä²v..¦n¤_¨ä¥¦2Ïú.±µ¡A¦ý¬O.Ïú.±µ¥u¯à¥Î¦b
    CBOɬ¤Æ¾¹¤¤¡A¦Ó¥B»Ý­n.¸m¦XÓ쪺hash_area_size..¡A
    ¤~¯à¨ú±o.¦nªº©Ê¯à¡C
    b)¦b2..¤jªºrowsource¤§..±µ..¨ú±o¬Û..¦nªº®Ä²v¡A¦b¤@.
    rowsource.¤p..¯à¨ú±o§ó¦nªº®Ä²v¡C
    c)¥u¯à¥Î¤_µ¥­È.±µ¤¤
    
    ²Ã¥d¤I­¼.(CartesianProduct)
    ...rowsource°µ.±µ¡A¦ý¬O¥¦.¤§..¦³...¥ó.¡A´N.¦b..rowsource
    ¤¤°µ²Ã¥d¤I­¼.¡A.³q±`¥Ñ..¥N.²¨º|³y¦¨(§Yµ{§Ç.§Ñ¤F....¥ó)¡C²Ã¥d.­¼
    .¬O¤@.ªíªº¨C¤@¦æ¨Ì¦¸ÉO¥t¤@.ªí¤¤ªº©Ò¦³¦æ¤Ç°t¡C¦b¯S®í±¡.¤U§Ú.¥i¥H¨Ï¥Î²Ã
    ¥d¤I­¼.¡A¦p¦b¬P§Î.±µ¤¤¡A°£¦¹¤§¥~¡A§Ú.­n.¶q¨Ï¥Î²Ã¥d¤I­¼.¡A§_.¡A¦Û¤v·Q
    .ªG¬O¤°¤\§a¡I
    
    ª`·N¦b¤U­±ªº.¥y¤¤¡A¦b2.ªí¤§..¦³.±µ¡C
    SQL>explainplanfor
    selectemp.deptno,dept,deptno
    fromemp,dept
    
    QueryPlan
    ------------------------------
    SLECTSTATEMENT[CHOOSE]Cost=5
    MERGEJOINCARTESIAN
    TABLEACCESSFULLDEPT
    SORTJOIN
    TABLEACCESSFULLEMP
    
    CARTESIAN..¦r«ü¥X¤F¦b2.ªí¤§.°µ²Ã¥d.­¼.¡C°²¦pªíemp¦³n¦æ¡Adept
    ªí¦³m¦æ¡A²Ã¥d.­¼.ªº.ªG´N¬O±o¨ìn*m¦æ.ªG¡C
    
    
    
    ¦p¦ó.¥Í.¦æ.¦E
    ­n.¤@..¥y¥Í¦¨.¦æ.¦E¡A¥i¥H¦³3Ïú¤èªk¡G
    1)¡D³Ì..ªº.ªk
    Sql>setautotraceon
    Sql>select*fromdual;
    .¦æ§¹.¥y¦Z¡A..¥ÜexplainplanÉO..«H®§¡C
    ...¥yªºÉ¬.´N¬O¥¦ªº¯Ê.¡A..¦b¥Î.¤èªk¬d¬Ý.¦æ....ªºsql.¥y.¡A»Ý­nµ¥«Ý
    ..¥y.¦æ¦¨¥\¦Z¡A¤~ªð¦^.¦æ.¦E¡A¨Ïɬ¤Æªº©P´Á¤j¤j¼W.¡C
    
    ¦pªG¤£·Q.¦æ.¥y¦Ó¥u¬O·Q±o¨ì.¦æ.¦E¥i¥Hªö¥Î¡G
    Sql>setautotracetraceonly
    ..¡A´N¥u.¦C¥X.¦æ.¦E¡A¦Ó¤£.¯u¥¿ªº.¦æ.¥y¡A¤j¤j.¤Ö¤Fɬ¤Æ..¡C.µM¤]¦C¥X¤F
    ..«H®§¡A¦ý¬O¦]..¦³.¦æ.¥y¡A©Ò¥H...«H®§.¦³¥Î.¡A
    
    
    ¦pªG.¦æ..¥y.¹J¨ì..¡A¸Ñ.¤èªk.¡G
    (1¡^¦b­n¤ÀªRªº¥Î.¤U¡G
    Sqlplus>@?\rdbms\admin\utlxplan.sql
    (2)¥Îsys¥Î.µn.
    Sqlplus>@?\sqlplus\admin\plustrce.sql
    Sqlplus>grantplustracetouser_name;--user_name¬O¤W­±©Ò.ªº¤ÀªR¥Î.
    
    2)¡D¥Îexplainplan©R¥O
    (1)sqlplus>@?\rdbms\admin\utlxplan.sql
    (2)sqlplus>explainplansetstatement_id=¡¦???¡¦forselect¡K¡K¡K¡K¡K¡K
    ª`·N¡A¥Î¦¹¤èªk.¡A¦}¤£.¦æsql.¥y¡A©Ò¥H¥u.¦C¥X.¦æ.¦E¡A¤£.¦C¥X..«H®§¡A¦}¥B
    .¦æ.¦E¥u¦s¦bplan_table¤¤¡C©Ò¥H..¥y¤ñ°_setautotracetraceonly¥i¥Î©Ê­n®t¡C»Ý­n
    ¥Î¤U­±ªº©R¥O®æ¦¡¤Æ.¥X¡A©Ò¥H.Ïú¤è¦¡§Ú¥Îªº¤£¦h¡G
    
    setlinesize150
    setpagesize500
    colPLANLINEfora120
    SELECTEXECORDEXEC_ORDER,PLANLINE
    FROM(SELECTPLANLINE,ROWNUMEXECORD,ID,RID
    FROM(SELECTPLANLINE,ID,RID,LEV
    FROM(SELECTlpad('',2*(LEVEL),rpad('',80,''))||
    OPERATION||''||--Operation
    DECODE(OPTIONS,NULL,'','('||OPTIONS||')')||--Options
    DECODE(OBJECT_OWNER,null,'','OF'''||OBJECT_OWNER||'.')||--
    Owner
    DECODE(OBJECT_NAME,null,'',OBJECT_NAME||'''')||--ObjectName
    DECODE(OBJECT_TYPE,null,'','('||OBJECT_TYPE||')')||--Object
    Type
    DECODE(ID,0,'OPT_MODE:')||--Optimizer
    DECODE(OPTIMIZER,null,'','ANALYZED','',OPTIMIZER)||
    DECODE(NVL(COST,0)+NVL(CARDINALITY,0)+NVL(BYTES,0),
    0,null,'(COST='||TO_CHAR(COST)||',CARD='||
    TO_CHAR(CARDINALITY)||',BYTES='||TO_CHAR(BYTES)||')')
    PLANLINE,ID,LEVELLEV,
    (SELECTMAX(ID)
    FROMPLAN_TABLEPL2
    CONNECTBYPRIORID=PARENT_ID
    ANDPRIORSTATEMENT_ID=STATEMENT_ID
    STARTWITHID=PL1.ID
    ANDSTATEMENT_ID=PL1.STATEMENT_ID)RID
    FROMPLAN_TABLEPL1
    CONNECTBYPRIORID=PARENT_ID
    ANDPRIORSTATEMENT_ID=STATEMENT_ID
    STARTWITHID=0
    ANDSTATEMENT_ID='aaa')
    ORDERBYRID,-LEV))
    ORDERBYID;
    
    ¤W­±.2Ïú¤èªk¥u¯à.¦b¥»..¤¤¥¿¦b.¦æªº.¥y.¥Í.¦æ.¦E¡A§Y§Ú.»Ý­n¤w.ª¾¹D¤F
    ­þ..¥y.¦æªº®Ä²v«Ü®t¡A§Ú.¬O¦³¥Øªº¥u...SQL.¥y¥hɬ¤Æ¡C¨ä.¡A¦b«Ü¦h±¡.¤U¡A
    §Ú.¥u.§v¤@.«È.©ê«è..¦b¨t..¦æ«ÜºC¡A¦Ó§Ú.¤£ª¾¹D¬O­þ.SQL¤Þ°_ªº¡C¦¹.¦³
    .¦h.¦¨ªº.¥y¥i¥H§ä¥X¯Ó..·½¤ñ.¦hªº.¥y¡A¦p¡G
    SELECTADDRESS,
    substr(SQL_TEXT,1,20)Text,
    buffer_gets,
    executions,
    buffer_gets/executionsAVG
    FROMv$sqlarea
    WHEREexecutions>0
    ANDbuffer_gets>100000
    ORDERBY5;
    .¦Ó.§ä¥Xªº.¥y.¦æ.¤@¨Bɬ¤Æ¡C.µM§Ú..¥i¥H.¤@.¥¿¦b.¦æªº..¤¤.¦æªº
    ©Ò¦³SQL.¥y¥Í¦¨.¦æ.¦E¡A.»Ý­n.....¦æ¸ò.¡A.¥Ítrace¤å¥ó¡AµM¦Z..¤å¥ó
    ¥Îtkprofµ{§Ç®æ¦¡¤Æ¤@¤U¡A.Ïú±o¨ì.¦æ.¦Eªº¤è¦¡«Ü¦³¥Î¡A¦].¥¦¥]§t¨ä¥¦.¥~«H®§¡A¦p
    SQL.¥y.¦æªº¨C..¬q(¦pParse¡BExecute¡BFetch)¤À.¯Ó.ªº¦U..·½±¡.(¦pCPU¡B
    DISK¡Belapsedµ¥)¡C
    
    3)¡D¥Îdbms_system¦s..µ{¥Í¦¨.¦æ.¦E
    ¦].¨Ï¥Îdbms_system¦s..µ{¥i¥H¸ò.¥t¤@....¥Xªºsql.¥y¡A¦}..©Ò¨Ï¥Î
    ªº.¦æ.¦E¡A¦Ó¥B.´£¨Ñ¨ä¥¦.©Ê¯à.¾ã¦³¥Îªº«H®§¡C¦]¨ä¨Ï¥Î¤è¦¡ÉO¤W­±2Ïú¤è¦¡¦³¨Ç
    ¤£¤Ó¤@.¡A©Ò¥H¦bªþ.¤¤..¤¶.¡C.Ïú¤èªk¬O.SQL.¦æ.¾ã¤ñ.¦³¥Îªº¤è¦¡¤§¤@¡A¦³
    ¨Ç±¡.¤U«D¥¦¤£¥i¡C¨ãÊ^.®e..ªþ.¡C
    
    ¦p¦ó¤ÀªR.¦æ.¦E
    
    ¨Ò1¡G
    °².LARGE_TABLE¬O¤@..¤jªºªí¡A¥Busername¦C¤W.¦³¯Á¤Þ¡A..¦æ¤U­±ªº.¥y¡G
    SQL>SELECT*FROMLARGE_TABLEwhereUSERNAME=¡¥TEST¡¦;
    QueryPlan
    -----------------------------------------
    SELECTSTATEMENTOptimizer=CHOOSE(Cost=1234Card=1Bytes=14)
    TABLEACCESSFULLLARGE_TABLE[:Q65001][ANALYZED]
    
    ¦b..¨Ò¤l¤¤¡ATABLEACCESSFULLLARGE_TABLE¬O²Ä¤@.¾Þ§@¡A·N«ä¬O¦b
    LARGE_TABLEªí¤W°µ¥þªí.´y¡C...¾Þ§@§¹¦¨¤§¦Z¡A.¥Íªºrowsource¤¤ªº.Õu³Q°e
    ©¹¤U¤@¨B..¦æ.²z¡A¦b¦¹¨Ò¤¤¡ASELECTSTATEMENT¾Þ§@¬O..¬d..¥yªº³Ì¦Z¤@¨B¡C
    
    Optimizer=CHOOSE«ü©ú..¬d.ªºoptimizer_mode¡A§Yoptimizer_modeªì©l¤Æ..«ü
    ©wªº­È¡A¥¦¦}¤£¬O«ü.¥y.¦æ.¯uªº¨Ï¥Î¤F.ɬ¤Æ¾¹¡C.©w..¥y¨Ï¥Î¦óÏúɬ¤Æ¾¹ªº°ß¤@¤è
    ªk¬O¬Ý¦Z­±ªºcost³¡¤À¡C¨Ò¦p¡A¦pªG.¥Xªº¬O¤U­±ªº§Î¦¡¡A.ªí©ú¨Ï¥Îªº¬OCBOɬ¤Æ¾¹¡A
    ¦¹.ªºcostªí¥Üɬ¤Æ¾¹....¦æ.¦Eªº¥Nɲ:
    SELECTSTATEMENTOptimizer=CHOOSE(Cost=1234Card=1Bytes=14)
    
    µM¦Ó°²¦p.¦æ.¦E¤¤.¥Xªº¬O.¦ü¤U­±ªº«H®§¡A.ªí©ú¬O¨Ï¥ÎRBOɬ¤Æ¾¹¡A¦].cost
    ³¡¤Àªº­È.ªÅ¡A©ÎªÌ.®Ú´N.¦³cost³¡¤À¡C
    SELECTSTATEMENTOptimizer=CHOOSECost=
    SELECTSTATEMENTOptimizer=CHOOSE
    ..§Ú..Optimizer¦Z­±ªº«H®§¤¤¥i¥H±o¥X.¦æ..¥y.¨ì©³¥Î¤F¤°¤\.ªºÉ¬¤Æ
    ¾¹¡C¯S.ªº¡A¦pªGOptimizer=ALL_ROWS|FIRST_ROWS|FIRST_ROWS_n¡A.¨Ï¥Îªº¬O
    CBOɬ¤Æ¾¹¡F¦pªGOptimizer=RULE¡A.¨Ï¥Îªº¬ORBOɬ¤Æ¾¹¡C
    
    cost.©Êªº­È¬O¤@.¦boracle.³¡¥Î.¤ñ.¦U..¦æ.¦E©Ò¯Ó.ªº¥Nɲªº­È¡A.¦Ó¨Ï
    É¬¤Æ¾¹¥i¥H..³Ì¦nªº.¦æ.¦E¡C¤£¦P.¥yªºcost­È¤£¨ã¦³¥i¤ñ©Ê¡A¥u¯à.¦P¤@..¥yªº
    ¤£¦P.¦æ.¦Eªºcost­È.¦æ¤ñ.¡C
    
    [:Q65001]ªí©ú.³¡¤À¬d.¬O¥H¦}¦æ¤è¦¡.¦æªº¡C¨½­±ªº.Õuªí¥Ü..¾Þ§@¬O¥Ñ¦}¦æ¬d.ªº
    ¤@.slave.µ{.²zªº¡A¥H«K.¾Þ§@¥i¥H..¤_¦ê¦æ.¦æªº¾Þ§@¡C
    
    [ANALYZED]ªí©ú¾Þ§@¤¤¤Þ¥Îªº.¶H³Q¤ÀªR.¤F¡A¦b.Õu¦r¨å¤¤¦³..¶Hªº..«H®§¥i¥H
    ¨ÑCBO¨Ï¥Î¡C
    
    ¨Ò2¡G
    °²©wA¡BB¡BC³£¬O¤£¬O¤pªí¡A¥B¦bAªí¤W¤@..¦X¯Á¤Þ¡GA(a.col1,a.col2)¡Aª`·Na.col1
    ¦C.¯Á¤Þªº¤Þ.¦C¡C
    ¦Ò.¤U­±ªº¬d.¡G
    selectA.col4
    fromA,B,C
    whereB.col3=10andA.col1=B.col1andA.col2=C.col2andC.col3=5
    ExecutionPlan
    ----------------------------------------------------------
    0SELECTSTATEMENTOptimizer=CHOOSE
    10MERGEJOIN
    21SORT(JOIN)
    32NESTEDLOOPS
    43TABLEACCESS(FULL)OF'B'
    53TABLEACCESS(BYINDEXROWID)OF'A'
    65INDEX(RANGESCAN)OF'INX_COL12A'(NON-UNIQUE)
    71SORT(JOIN)
    87TABLEACCESS(FULL)OF'C'
    
    Statistics
    ----------------------------------------------------------
    0recursivecalls
    8dbblockgets
    6consistentgets
    0physicalreads
    0redosize
    551bytessentviaSQL*Nettoclient
    430bytesreceivedviaSQL*Netfromclient
    2SQL*Netroundtripsto/fromclient
    2sorts(memory)
    0sorts(disk)
    6rowsprocessed
    
    ¦bªí°µ.±µ.¡A¥u¯à2.ªí¥ý°µ.±µ¡AµM¦Z..±µ¦Zªº.ªG§@.¤@.rowsource¡AÉO
    ³Ñ¤Uªºªí°µ.±µ¡A¦b¤W­±ªº¨Ò¤l¤¤¡A.±µ.§Ç.BÉOA¥ý.±µ¡AµM¦Z¦AÉOC.±µ¡G
    B<--->A<--->C
    col3=10col3=5
    
    ¦pªG.¦³.¦æ.¦E¡A¤ÀªR¤@¤U¡A¤W­±ªº3.ªí..®³­þ¤@.§@.²Ä¤@...ªí¡H.SQL
    .¥y¬Ý.¡A¥u¦³BªíÉOCªí¤W¦³­­¨î.¥ó¡A©Ò¥H²Ä¤@...ªí....2.ªí¤¤ªº¤@.¡A
    ¨ì©³¬O­þ¤@.©O¡H
    
    Bªí¦³..B.col3=10¡A..¦b.Bªí°µ¥þªí.´yªº.­Ô´N.where¤l¥y¤¤ªº­­¨î
    .¥ó(B.col3=10)¥Î¤W¡A.¦Ó±o¨ì¤@..¤pªºrowsource,©Ò¥HBªí..§@.²Ä¤@...ªí¡C
    ¦Ó¥B..ªº.¡A¦pªG¦AÉOAªí°µ..¡A¥i¥H¦³®Ä§Q¥ÎAªíªº¯Á¤Þ(¦].Aªíªºcol1¦C.leading
    column)¡C
    
    .µM¤W­±ªº¬d.¤¤Cªí¤W¤]¦³..(C.col3=5)¡A¦³¤H¥i¯à..Cªí§@.²Ä¤@...
    ªí¤]¯à.±o.¦nªº©Ê¯à¡C.§Ú.¦A.¤ÀªR¤@¤U¡G¦pªGCªí§@.²Ä¤@...ªí¡A.¯à«O..
    .ªí¥Í¦¨«Ü¤pªºrowsource¡A¦ý¬O¬Ý¬Ý.±µ.¥óA.col2=C.col2¡A¦¹.´N.¦³Éó.§Q¥ÎA
    ªíªº¯Á¤Þ¡A¦].Aªíªºcol2¦C¤£.leadingcolumn¡A..nestedloopªº®Ä²v«Ü®t¡A.¦Ó
    .­P¬d.ªº®Ä²v«Ü®t¡C©Ò¥H.¤_NL.±µ..¥¿Ú̪º..ªí«Ü­«­n¡C
    
    ¦]¦¹¤W­±¬d.¤ñ.¦nªº.±µ.§Ç.(B-->A)-->C¡C¦pªG.Õu.¬O°ò¤_¥NɲªºÉ¬¤Æ
    ¾¹¡A¥¦.§Q¥Î.ºâ¥Xªº¥Nɲ..©w¦XÓ쪺..ªíÉO¦XÓ쪺.±µ.§Ç¡C¤@¯ë..¡ACBO³£.
    ..¥¿Ú̪º.±µ.§Ç¡A¦pªGCBO..¤F¤ñ.®tªº.±µ.§Ç¡A§Ú..¥i¥H¨Ï¥ÎORACLE´£
    ¨Ñªºhints..CBOªö¥Î¥¿Ú̪º.±µ.§Ç¡C¦p¤U©Ò¥Ü¡G
    
    select/*+ordered*/A.col4
    fromB,A,C
    whereB.col3=10
    andA.col1=B.col1
    andA.col2=C.col2
    andC.col3=5
    
    ¬JµM..¥¿Ú̪º..ªí.¤\­«­n¡A¨º¤\.§Ú..¬Ý¤@¤U.¦æ.¦E¡A¨ì©³¦U.ªí¤§.¬O
    ¦p¦ó..ªº¡A.¦Ó±o¨ì.¦æ.¦E¤¤­þ.ªí.....ªí¡G
    ¦b.¦æ.¦E¤¤¡A»Ý­nª¾¹D­þ.¾Þ§@¬O¥ý.¦æªº¡A­þ.¾Þ§@¬O¦Z.¦æªº¡A..¤_§P.­þ
    .ªí...ªí¦³¥Î.¡C§P.¤§«e¡A¦pªG.ªíªº..¬O³q.rowid¡A¥B.rowidªº­È¬O.¯Á¤Þ
    .´y¤¤±o.±o¡A...¯Á¤Þ.´y¥ý..¦æ.¦E¤¤..¥h±¼¡CµM¦Z¦b.¦æ.¦E³Ñ¤Uªº³¡¤À¤¤¡A
    §P..¦æ.§Çªº«ü.­ì.´N¬O¡G³Ì¥k¡B³Ì¤Wªº¾Þ§@¥ý.¦æ¡C¨ãÊ^¸Ñ.¦p¤U¡G
    ±o¨ì¥h°£§«.§P.ªº¯Á¤Þ.´y¦Zªº.¦æ.¦E¡G
    ExecutionPlan
    ----------------------------------------------------------
    0SELECTSTATEMENTOptimizer=CHOOSE
    10MERGEJOIN
    21SORT(JOIN)
    32NESTEDLOOPS
    43TABLEACCESS(FULL)OF'B'
    53TABLEACCESS(BYINDEXROWID)OF'A'
    71SORT(JOIN)
    87TABLEACCESS(FULL)OF'C'
    ¬Ý.¦æ.¦Eªº²Ä3¦C¡A§Y¦r¥À³¡¤À¡A¨C¦C­Èªº¥ª­±¦³ªÅ®æ§@...¦r²Å¡C¦b.¦C­È¥ª
    .ªºªÅ®æ¶V¦h¡A.©ú.¦C­Èªº..¶V¦h¡A.¦C­È¤]¶V¾a¥k¡C¦p¤W­±ªº.¦æ.¦E©Ò¥Ü¡G²Ä¤@¦C
    ­È.6ªº¦æªº..³Ì¦h¡A§Y.¦æ³Ì¾a¥k¡F²Ä¤@¦C­È.4¡B5ªº¦æªº..¤@.¡A¨ä¾a¥kªºµ{«×
    ¤]¤@.¡A¦ý¬O²Ä¤@¦C­È.4ªº¦æ¤ñ²Ä¤@¦C­È.5ªº¦æ¾a¤W¡F..¤W¤U.¨t.¡A¥u...ªº¡B
    ..¤@­Pªº¦æ¦³®Ä¡C
    
    ....¤¤§Ú.¥i¥H¬Ý¨ì¡A.¤_NESTEDLOOPS³¡¤À¡A³Ì¥k¡B³Ì¤Wªº¾Þ§@¬OTABLE
    ACCESS(FULL)OF'B'¡A©Ò¥H.¤@¾Þ§@¥ý.¦æ¡A©Ò¥H.¾Þ§@..ªºBªí.²Ä¤@...ªí(¥~
    ³¡ªí)¡A¦ÛµM¡AAªí´N..³¡ªí¤F¡C..¤¤.¥i¥H¬Ý¥X¡ABÉOAªí°µ´O®M´`.¦Z¥Í¦¨¤F·sªº
    rowsource¡A..rowsource.¦æ.±Æ§Ç¦Z¡AÉOCªí..ªº±Æ§Ç¤Fªºrowsource(.¥Î¤F
    C.col3=5­­¨î.¥ó).¦æMSJ.±µ¾Þ§@¡C©Ò¥H.¤W­±¥i¥H±o¥X¦p¤U¨Æ.¡GBªí¥ýÉOAªí°µ
    ´O®M´`.¡AµM¦Z.¥Í¦¨ªºrowsourceÉOCªí°µ±Æ§Ç¡X¦X¦}.±µ¡C
    ³q.¤ÀªR¤W­±ªº.¦æ.¦E¡A§Ú.¤£¯à.Cªí¤@©w¦bB¡BAªí¤§¦Z¤~³Q.¨ú¡A¨Æ.¤W¡A
    Bªí¦³¥i¯àÉOCªí¦P.³Q.¤J.¦s¡A¦]..ªí¤¤ªº.Õu.¤J.¦sªº¾Þ§@¥i¯à.¦}¦æªº¡C¨Æ
    .¤W.¦h¾Þ§@¥i¯à.¥æ¤e.¦æªº¡A¦].ORACLE.¨ú.Õu.¡A¦pªG´N¬O»Ý­n¤@¦æ.Õu¤]¬O
    ..¦æ©Ò¦bªº¾ã..Õu..¤J.¦s¡A¦Ó¥B.¦³¥i¯à.¦h..¡C
    ¬Ý.¦æ.¦E.¡A§Ú.ªº..¤£¬O¬Ý­þ.¾Þ§@¥ý.¦æ¡A­þ.¾Þ§@¦Z.¦æ¡A¦Ó¬O..¬Ýªí
    ¤§..±µªº.§Ç(¦p±oª¾­þ....ªí¡A.»Ý­n.¾Þ§@ªº.§Ç.¦æ§P.)¡B¨Ï¥Î¤F¦óÏú.«¬ªº
    ..¤Î¨ãÊ^ªº¦s¨ú¸ô.(¦p§P.¬O§_§Q¥Î¤F¯Á¤Þ)
    
    ¦b..¦æ.¦E¤¤§P.¥X­þ.ªí...ªí¦Z¡A®ÚÕu§Ú.ªºª¾.§P..ªí§@...ªí(´N¹³
    ¤W­±§P.ABCªí¨º.)¬O§_¦XÓì¡A¦pªG¤£¦XÓì¡A.SQL.¥y.¦æ§ó§ï¡A¨Ïɬ¤Æ¾¹¥i¥H..
    ¥¿Ú̪º..ªí¡C
    
    .¤_RBOɬ¤Æ¾¹¡G
    ¦bORACLE¤å.¤W.¡G.¤_RBO..¡A¥Hfrom¤l¥y¤¤.¥k¨ì¥ªªº.§Ç....ªí¡A
    §Y³Ì¥k.ªºªí.²Ä¤@...ªí¡A.¬O¨ä­^¤å­ì¤å¡GAllthingsbeingequalRBOchoosesthe
    drivingorderbytakingthetablesintheFROMclauseRIGHTtoLEFT¡C¤£.¡A¦b§Ú°µªº.
    .¤¤¡A..¤].¦³....Ïú.ªk¬O¥¿Ú̪º¡C§Ú..¡A§Y¨Ï¦bRBO¤¤¡A¤]¬O¦³¤@®M...
    .©w¨Ï¥Î­þÏú.±µ.«¬©M­þ.ªí§@...ªí¡A¦b...ªÖ©w.¦Ò..«e¯Á¤Þªº±¡.¡A.¥i¯à
    .¦Ò.where¤¤ªº­­¨î.¥ó¡A¦ý¬OªÖ©w¬OÉOwhere¤¤­­¨î.¥óªº¦ì¸m..¡C
    
    ..¡G
    ¦pªG§Ú.«Ø3.ªí¡G
    createtableA(col1number(4,0),col2number(4,0),col4char(30));
    createtableB(col1number(4,0),col3number(4,0),name_bchar(30));
    createtableC(col2number(4,0),col3number(4,0),name_cchar(30));
    createindexinx_col12Aona(col1,col2);
    .¦æ¬d.¡G
    selectA.col4
    fromB,A,C
    whereB.col3=10
    andA.col1=B.col1
    andA.col2=C.col2
    andC.col3=5;
    ExecutionPlan
    ----------------------------------------------------------
    0SELECTSTATEMENTOptimizer=RULE
    10MERGEJOIN
    21SORT(JOIN)
    32NESTEDLOOPS
    43TABLEACCESS(FULL)OF'B'
    53TABLEACCESS(BYINDEXROWID)OF'A'
    65INDEX(RANGESCAN)OF'INX_COL12A'(NON-UNIQUE)
    71SORT(JOIN)
    87TABLEACCESS(FULL)OF'C'
    
    selectA.col4
    fromB,A,C
    whereA.col1=B.col1
    andA.col2=C.col2;
    ExecutionPlan
    ----------------------------------------------------------
    0SELECTSTATEMENTOptimizer=RULE
    10MERGEJOIN
    21SORT(JOIN)
    32NESTEDLOOPS
    43TABLEACCESS(FULL)OF'B'
    53TABLEACCESS(BYINDEXROWID)OF'A'
    65INDEX(RANGESCAN)OF'INX_COL12A'(NON-UNIQUE)
    71SORT(JOIN)
    87TABLEACCESS(FULL)OF'C'
    
    .Aªí¤Wªº¯Á¤Þinx_col12A.°£¦Z¡G
    selectA.col4
    fromB,A,C
    whereA.col1=B.col1
    andA.col2=C.col2;
    ExecutionPlan
    ----------------------------------------------------------
    0SELECTSTATEMENTOptimizer=RULE
    10MERGEJOIN
    21SORT(JOIN)
    32MERGEJOIN
    43SORT(JOIN)
    54TABLEACCESS(FULL)OF'C'
    63SORT(JOIN)
    76TABLEACCESS(FULL)OF'A'
    81SORT(JOIN)
    98TABLEACCESS(FULL)OF'B'
    
    ³q.¤W­±ªº.¨Ç¨Ò¤l¡A¨Ï§Ú.oracle¤å.¤Wªº¡¨AllthingsbeingequalRBOchooses
    thedrivingorderbytakingthetablesintheFROMclauseRIGHTtoLEFT¡¨.¥y.«ùÊäºÃ.
    «×¡C¦¹.¡A§Ú¤]¤£¯à¨Ï¥Îhints..¨îɬ¤Æ¾¹¨Ï¥Înestedloop¡A¦pªG¨Ï¥Î¤Fhints¡A..´N
    ¦Û.¨Ï¥ÎCBOɬ¤Æ¾¹¡A¦Ó¤£¬ORBOɬ¤Æ¾¹¤F¡C
    
    .¤_CBOɬ¤Æ¾¹¡G
    CBO®ÚÕu..«H®§....ªí¡A°²¦p.¦³..«H®§¡A.¦bfrom¤l¥y¤¤.¥ª¨ì¥kªº.
    §Ç....ªí¡C.ÉORBO..ªº.§Ç¥¿¦n¬Û¤Ï¡C.¬O­^¤å­ì¤å(CBOdeterminesjoinorder
    fromcostsderivedfromgatheredstatistics.IftherearenostatsthenCBOchoosesthe
    drivingorderoftablesfromLEFTtoRIGHTintheFROMclause.ThisisOPPOSITEto
    theRBO)¡C§Ú.¬O.ªk...¥y.ªº¥¿ÚÌ©Ê¡C¤£.....¡G¡§¦pªG¥Îordered´£¥Ü(¦¹.
    ªÖ©w¥ÎCBO)¡A.¥Hfrom¤l¥y¤¤«ö.¥ª¨ì¥kªº.§Ç....ªí¡¨.¥y.¬O¥¿Ú̪º¡C..¤W¦b
    CBO¤¤¡A¦pªG¦³...Õu(§Y.ªíÉO¯Á¤Þ.¦æ¤F¤ÀªR)¡A.ɬ¤Æ¾¹.¦Û.®ÚÕucost­È.©wªö
    ¥Î­þÏú.±µ.«¬¡A¦}..¦XÓ쪺..ªí¡A.ÉOwhere¤l¥y¤¤¦U.­­¨î.¥óªº¦ì¸m.¦³¥ô¦ó
    .¨t¡C¦pªG§Ú.­n§ï.ɬ¤Æ¾¹..ªº.±µ.«¬©Î..ªí¡A.´N»Ý­n¨Ï¥Îhints¤F¡A¨ãÊ^hints
    ªº¥Îªk¦b¦Z­±..¤©¤¶.¡C
    
    ..¡G
    ¦pªG§Ú.«Øªº3.ªí¡G
    createtableA(col1number(4,0),col2number(4,0),col4char(30));
    createtableB(col1number(4,0),col3number(4,0),name_bchar(30));
    createtableC(col2number(4,0),col3number(4,0),name_cchar(30));
    createindexinx_col12Aona(col1,col2);
    
    .¦æ¬d.¡G
    selectA.col4
    fromB,A,C
    whereB.col3=10
    andA.col1=B.col1
    andA.col2=C.col2
    andC.col3=5;
    ExecutionPlan
    ----------------------------------------------------------
    0SELECTSTATEMENTOptimizer=ALL_ROWS(Cost=3Card=1Bytes=110)
    10NESTEDLOOPS(Cost=3Card=1Bytes=110)
    21MERGEJOIN(CARTESIAN)(Cost=2Card=1Bytes=52)
    32TABLEACCESS(FULL)OF'B'(Cost=1Card=1Bytes=26)
    42SORT(JOIN)(Cost=1Card=1Bytes=26)
    54TABLEACCESS(FULL)OF'C'(Cost=1Card=1Bytes=26)
    61TABLEACCESS(FULL)OF'A'(Cost=1Card=82Bytes=4756)
    
    selectA.col4
    fromB,A,C
    whereA.col1=B.col1
    andA.col2=C.col2;
    ExecutionPlan
    ----------------------------------------------------------
    0SELECTSTATEMENTOptimizer=ALL_ROWS(Cost=5Card=55Bytes=4620)
    10HASHJOIN(Cost=5Card=55Bytes=4620)
    21HASHJOIN(Cost=3Card=67Bytes=4757)
    32TABLEACCESS(FULL)OF'B'(Cost=1Card=82Bytes=1066)
    42TABLEACCESS(FULL)OF'A'(Cost=1Card=82Bytes=4756)
    51TABLEACCESS(FULL)OF'C'(Cost=1Card=82Bytes=1066)
    
    .Aªí¤Wªº¯Á¤Þinx_col12A.°£¦Z¡G
    selectA.col4
    fromB,A,C
    whereA.col1=B.col1
    andA.col2=C.col2;
    ExecutionPlan
    ----------------------------------------------------------
    0SELECTSTATEMENTOptimizer=ALL_ROWS(Cost=5Card=55Bytes=4620)
    10HASHJOIN(Cost=5Card=55Bytes=4620)
    21HASHJOIN(Cost=3Card=67Bytes=4757)
    32TABLEACCESS(FULL)OF'B'(Cost=1Card=82Bytes=1066)
    42TABLEACCESS(FULL)OF'A'(Cost=1Card=82Bytes=4756)
    51TABLEACCESS(FULL)OF'C'(Cost=1Card=82Bytes=1066)
    
    select/*+ORDERED*/A.col4
    fromC,A,B
    whereB.col3=10
    andA.col1=B.col1
    andA.col2=C.col2
    andC.col3=5;
    ExecutionPlan
    ----------------------------------------------------------
    0SELECTSTATEMENTOptimizer=ALL_ROWS(Cost=3Card=1Bytes=110)
    10NESTEDLOOPS(Cost=3Card=1Bytes=110)
    21NESTEDLOOPS(Cost=2Card=1Bytes=84)
    32TABLEACCESS(FULL)OF'C'(Cost=1Card=1Bytes=26)
    42TABLEACCESS(FULL)OF'A'(Cost=1Card=82Bytes=4756)
    51TABLEACCESS(FULL)OF'B'(Cost=1Card=1Bytes=26)
    ..¬d...¤F³q.ORDERED´£¥Ü¥i¥H¥¿Ú̪º´£¥Üɬ¤Æ¾¹..­þ.ªí§@.ɬ¤Æ¾¹¡C
    
    
    ¦p¦ó¤z..¦æ.¦E--¨Ï¥Îhints´£¥Ü
    °ò¤_¥NɲªºÉ¬¤Æ¾¹¬O«Ü.©úªº¡A¦b.¤j¦h.±¡.¤U¥¦...¥¿Ú̪ºÉ¬¤Æ¾¹¡A..¤FDBA
    ªº..¡C¦ý¦³.¥¦¤].©ú¤Ï³Q.©ú.¡A..¤F«Ü®tªº.¦æ.¦E¡A¨Ï¬Y..¥yªº.¦æ.±o©_ºC
    .¤ñ¡C¦¹.´N»Ý­nDBA.¦æ¤H.ªº¤z.¡A§i.ɬ¤Æ¾¹¨Ï¥Î§Ú.«ü©wªº¦s¨ú¸ô.©Î.±µ.«¬
    ¥Í¦¨.¦æ.¦E¡A.¦Ó¨Ï.¥y°ª®Äªº.¦æ¡C¨Ò¦p¡A¦pªG§Ú....¤_¤@.¯S©wªº.¥y¡A.¦æ¥þ
    ªí.´y­n¤ñ.¦æ¯Á¤Þ.´y§ó¦³®Ä¡A.§Ú.´N¥i¥H«ü¥Üɬ¤Æ¾¹¨Ï¥Î¥þªí.´y¡C¦bORACLE¤¤¡A
    ¬O³q...¥y²K¥[hints(´£¥Ü)...¤z.ɬ¤Æ¾¹É¬¤Æªº¥Øªº¡C
    
    hints¬Ooracle´£¨Ñªº¤@ÏúÉó¨î¡A¥Î.§i.ɬ¤Æ¾¹«ö·Ó§Ú.ªº§i.¥¦ªº¤è¦¡¥Í¦¨.¦æ.
    ¦E¡C§Ú.¥i¥H¥Îhints...¡G
    1)¨Ï¥ÎªºÉ¬¤Æ¾¹ªº.«¬
    2)°ò¤_¥NɲªºÉ¬¤Æ¾¹ªºÉ¬¤Æ¥Ø.¡A¬Oall_rows.¬Ofirst_rows¡C
    3)ªíªº..¸ô.¡A¬O¥þªí.´y¡A.¬O¯Á¤Þ.´y¡A.¬Oª½±µ§Q¥Îrowid¡C
    4)ªí¤§.ªº.±µ.«¬
    5)ªí¤§.ªº.±µ.§Ç
    6).¥yªº¦}¦æµ{«×
    
    °£¤F¡¨RULE¡¨´£¥Ü¥~¡A¤@¥¹¨Ï¥Îªº.ªº´£¥Ü¡A.¥y´N.¦Û.ªº§ï.¨Ï¥ÎCBOɬ¤Æ¾¹¡A¦¹
    .¦pªG§Aªº.Õu¦r¨å¤¤.¦³...Õu¡A´N.¨Ï¥Î¯Ê¬Ùªº...Õu¡C©Ò¥H«Ø.¤j®a¦pªG¨Ï¥Î
    CBO©ÎHINTS´£¥Ü¡A.³Ì¦n.ªí©M¯Á¤Þ.¦æ©w´Áªº¤ÀªR¡C
    
    ¦p¦ó¨Ï¥Îhints:
    Hints¥u.¥Î¦b¥¦.©Ò¦bsql.¥y.(statementblock¡A¥Ñselect¡Bupdate¡Bdelete..
    ¦r..)¤W¡A.¨ä¥¦SQL.¥y©Î.¥yªº¨ä¥¦³¡¤À.¦³¼v.¡C¦p¡G.¤_¨Ï¥Îunion¾Þ§@ªº2.
    sql.¥y¡A¦pªG¥u¦b¤@.sql.¥y¤W¦³hints¡A..hints¤£.¼v.¥t¤@.sql.¥y¡C
    
    §Ú.¥i¥H¨Ï¥Îª`.(comment)..¤@..¥y²K¥[hints¡A¤@..¥y.¥u¯à¦³¤@.ª`.¡A
    ¦Ó¥Bª`.¥u¯à©ñ¦bSELECT,UPDATE,orDELETE..¦rªº¦Z­±
    
    ¨Ï¥Îhintsªº.ªk¡G
    {DELETE|INSERT|SELECT|UPDATE}/*+hint[text][hint[text]]...*/
    or
    {DELETE|INSERT|SELECT|UPDATE}--+hint[text][hint[text]]...
    ª`¸Ñ¡G
    1)DELETE¡BINSERT¡BSELECT©MUPDATE¬O..¤@..¥y..©lªº..¦r¡A¥]§t
    ´£¥Üªºª`.¥u¯à¥X.¦b.¨Ç..¦rªº¦Z­±¡A§_.´£¥Ü.®Ä¡C
    2)¡§+¡¨.ªí¥Ü.ª`.¬O¤@.hints¡A.¥[.¥².¥ß§Y¸ò¦b¡¨/*¡¨ªº¦Z­±¡A¤¤.¤£¯à¦³ªÅ®æ¡C
    3)hint¬O¤U­±¤¶.ªº¨ãÊ^´£¥Ü¤§¤@¡A¦pªG¥]§t¦h.´£¥Ü¡A.¨C.´£¥Ü¤§.»Ý­n¥Î¤@.
    ©Î¦h.ªÅ®æ¹j.¡C
    4)text¬O¨ä¥¦.©úhintªºª`.©Ê¤å¥»
    
    ¦pªG§A.¦³¥¿Ú̪º«ü©whints¡AOracle.©¿²¤.hints¡A¦}¥B¤£..¥X¥ô¦ó..¡C
    
    
    ¨Ï¥Î¥þ®Mªºhints¡G
    .¨Ï¥Îhints.¡A¦b¬Y¨Ç±¡.¤U¡A.¤FÚÌ«O.ɬ¤Æ¾¹.¥Í³Ìɬªº.¦æ.¦E¡A§Ú.¥i¯à«ü
    ©w¥þ®Mªºhints¡C¨Ò¦p¡A¦pªG¦³¤@.Î`.ªº¬d.¡A¥]§t¦h.ªí.±µ¡A¦pªG§A¥u.¬Y.ªí«ü©w
    ¤FINDEX´£¥Ü(«ü¥Ü¦s¨ú¸ô.¦b.ªí¤W¨Ï¥Î¯Á¤Þ)¡Aɬ¤Æ¾¹»Ý­n..©w¨ä¥¦..¨Ï¥Îªº..
    ¸ô.©M¬Û.ªº.±µ¤èªk¡C¦]¦¹¡A§Y¨Ï§A.¥X¤F¤@.INDEX´£¥Ü¡Aɬ¤Æ¾¹¥i¯à.±o.¦³¥²­n
    ¨Ï¥Î.´£¥Ü¡C.¬O¥Ñ¤_§Ú..ɬ¤Æ¾¹..¤F¨ä¥¦.±µ¤èªk©M¦s¨ú¸ô.¡A¦Ó°ò¤_.¨Ç.±µ¤èªk
    ©M¦s¨ú¸ô.¡Aɬ¤Æ¾¹..¥Î..¥XªºINDEX´£¥Ü.¥Î¡C.¤F¨¾¤î.Ïú±¡.¡A§Ú.­n¨Ï¥Î¥þ
    ®Mªºhints¡A¦p¡G¤£¦ý«ü©w­n¨Ï¥Îªº¯Á¤Þ¡A¦Ó¥B¤]«ü©w.±µªº¤èªkÉO.±µªº.§Çµ¥¡C
    
    ¤U­±¬O¤@.¨Ï¥Î¥þ®Mhintsªº¨Ò¤l¡AORDERED´£¥Ü«ü¥X¤F.±µªº.§Ç¡A¦Ó¥B.¤£¦Pªº
    ªí«ü©w¤F.±µ¤èªk¡G
    SELECT/*+ORDEREDINDEX(b,jl_br_balances_n1)USE_NL(jb)
    USE_NL(glccglf)USE_MERGE(gpgsb)*/
    b.application_id,b.set_of_books_id,
    b.personnel_id,p.vendor_idPersonnel,
    p.segment1PersonnelNumber,p.vendor_nameName
    FROMjl_br_journalsj,jl_br_balancesb,
    gl_code_combinationsglcc,fnd_flex_values_vlglf,
    gl_periodsgp,gl_sets_of_booksgsb,po_vendorsp
    WHERE...
    
    «ü¥Üɬ¤Æ¾¹ªº¤èªkÉO¥Ø.ªºhints¡G
    ALL_ROWS--°ò¤_¥NɲªºÉ¬¤Æ¾¹¡A¥H§]¦R¶q.¥Ø.
    FIRST_ROWS(n)--°ò¤_¥NɲªºÉ¬¤Æ¾¹¡A¥H.....¥Ø.
    CHOOSE--®ÚÕu¬O§_¦³..«H®§¡A..¤£¦PªºÉ¬¤Æ¾¹
    RULE--¨Ï¥Î°ò¤_..ªºÉ¬¤Æ¾¹
    
    ¨Ò¤l¡G
    SELECT/*+FIRST_ROWS(10)*/employee_id,last_name,salary,job_id
    FROMemployees
    WHEREdepartment_id=20;
    
    SELECT/*+CHOOSE*/employee_id,last_name,salary,job_id
    FROMemployees
    WHEREemployee_id=7566;
    
    SELECT/*+RULE*/employee_id,last_name,salary,job_id
    FROMemployees
    WHEREemployee_id=7566;
    
    «ü¥Ü¦s.¸ô.ªºhints¡G
    FULL/*+FULL(table)*/
    «ü©w.ªí¨Ï¥Î¥þªí.´y
    ROWID/*+ROWID(table)*/
    «ü©w..ªí¨Ï¥Îrowid¦s¨ú¤èªk¡A.´£¥Ü¥Îªº.¤Ö
    INDEX/*+INDEX(table[index])*/
    ¨Ï¥Î.ªí¤W«ü©wªº¯Á¤Þ.ªí.¦æ¯Á¤Þ.´y
    INDEX_FFS/*+INDEX_FFS(table[index])*/
    ¨Ï¥Î§Ö³t¥þªí.´y
    NO_INDEX/*+NO_INDEX(table[index])*/
    ¤£¨Ï¥Î.ªí¤W«ü©wªº¯Á¤Þ.¦æ¦s¨ú¡A¤´µM¥i¥H¨Ï¥Î¨ä¥¦ªº¯Á¤Þ.¦æ¯Á¤Þ.´y
    
    SELECT/*+FULL(e)*/employee_id,last_name
    FROMemployeese
    WHERElast_nameLIKE:b1;
    
    SELECT/*+ROWID(employees)*/*
    FROMemployees
    WHERErowid>'AAAAtkAABAAAFNTAAA'ANDemployee_id=155;
    
    SELECT/*+INDEX(Asex_index)usesex_indexbecausetherearefew
    malepatients*/A.name,A.height,A.weight
    FROMpatientsA
    WHEREA.sex=¡¦m¡¦;
    
    SELECT/*+NO_INDEX(employeesemp_empid)*/employee_id
    FROMemployees
    WHEREemployee_id>200;
    
    «ü¥Ü.±µ.§Çªºhints:
    ORDERED/*+ORDERED*/
    «öfrom¦r¥y¤¤ªíªº.§Ç.¥ª¨ì¥kªº.±µ
    STAR/*+STAR*/
    «ü¥Üɬ¤Æ¾¹¨Ï¥Î¬P«¬¬d.
    
    SELECT/*+ORDERED*/o.order_id,c.customer_id,l.unit_price*l.quantity
    FROMcustomersc,order_itemsl,orderso
    WHEREc.cust_last_name=:b1
    ANDo.customer_id=c.customer_id
    ANDo.order_id=l.order_id;
    
    /*+ORDEREDUSE_NL(FACTS)INDEX(factsfact_concat)*/
    
    «ü¥Ü.±µ.«¬ªºhints¡G
    USE_NL/*+USE_NL(table[,table,...])*/
    ¨Ï¥Î´O®M.±µ
    USE_MERGE/*+USE_MERGE(table[,table,...])*/
    ¨Ï¥Î±Æ§Ç--¦X¦}.±µ
    USE_HASH/*+USE_HASH(table[,table,...])*/
    ¨Ï¥ÎHASH.±µ
    ª`·N¡G¦pªGªí¦³alias(.¦W)¡A.¤W­±ªºtable«üªº¬Oªíªº.¦W¡A¦Ó¤£¬O¯u.ªºªí¦W
    
    ¨ãÊ^ªº...¨Ò¡G
    createtableA(col1number(4,0),col2number(4,0),col4char(30));
    createtableB(col1number(4,0),col3number(4,0),name_bchar(30));
    createtableC(col2number(4,0),col3number(4,0),name_cchar(30));
    
    selectA.col4
    fromC,A,B
    whereC.col3=5andA.col1=B.col1andA.col2=C.col2
    andB.col3=10;
    ExecutionPlan
    ----------------------------------------------------------
    0SELECTSTATEMENTOptimizer=CHOOSE
    10MERGEJOIN
    21SORT(JOIN)
    32MERGEJOIN
    43SORT(JOIN)
    54TABLEACCESS(FULL)OF'B'
    63SORT(JOIN)
    76TABLEACCESS(FULL)OF'A'
    81SORT(JOIN)
    98TABLEACCESS(FULL)OF'C'
    
    select/*+ORDERED*/A.col4
    fromC,A,B
    whereC.col3=5andA.col1=B.col1andA.col2=C.col2
    andB.col3=10;
    ExecutionPlan
    ----------------------------------------------------------
    0SELECTSTATEMENTOptimizer=CHOOSE(Cost=5Card=1Bytes=110)
    10HASHJOIN(Cost=5Card=1Bytes=110)
    21HASHJOIN(Cost=3Card=1Bytes=84)
    32TABLEACCESS(FULL)OF'C'(Cost=1Card=1Bytes=26)
    42TABLEACCESS(FULL)OF'A'(Cost=1Card=82Bytes=4756)
    51TABLEACCESS(FULL)OF'B'(Cost=1Card=1Bytes=26)
    
    select/*+ORDEREDUSE_NL(AC)*/A.col4
    fromC,A,B
    whereC.col3=5andA.col1=B.col1andA.col2=C.col2
    andB.col3=10;
    ExecutionPlan
    ----------------------------------------------------------
    0SELECTSTATEMENTOptimizer=CHOOSE(Cost=4Card=1Bytes=110)
    10HASHJOIN(Cost=4Card=1Bytes=110)
    21NESTEDLOOPS(Cost=2Card=1Bytes=84)
    32TABLEACCESS(FULL)OF'C'(Cost=1Card=1Bytes=26)
    42TABLEACCESS(FULL)OF'A'(Cost=1Card=82Bytes=4756)
    51TABLEACCESS(FULL)OF'B'(Cost=1Card=1Bytes=26)
    
    .«Ø¯Á¤Þ¡G
    createindexinx_col12Aona(col1,col2);
    selectA.col4
    fromC,A,B
    whereC.col3=5andA.col1=B.col1andA.col2=C.col2
    andB.col3=10;
    ExecutionPlan
    ----------------------------------------------------------
    0SELECTSTATEMENTOptimizer=CHOOSE
    10MERGEJOIN
    21SORT(JOIN)
    32NESTEDLOOPS
    43TABLEACCESS(FULL)OF'B'
    53TABLEACCESS(BYINDEXROWID)OF'A'
    65INDEX(RANGESCAN)OF'INX_COL12A'(NON-UNIQUE)
    71SORT(JOIN)
    87TABLEACCESS(FULL)OF'C'
    
    select/*+ORDERED*/A.col4
    fromC,A,B
    whereC.col3=5andA.col1=B.col1andA.col2=C.col2
    andB.col3=10;
    ExecutionPlan
    ----------------------------------------------------------
    0SELECTSTATEMENTOptimizer=CHOOSE(Cost=5Card=1Bytes=110)
    10HASHJOIN(Cost=5Card=1Bytes=110)
    21HASHJOIN(Cost=3Card=1Bytes=84)
    32TABLEACCESS(FULL)OF'C'(Cost=1Card=1Bytes=26)
    42TABLEACCESS(FULL)OF'A'(Cost=1Card=82Bytes=4756)
    51TABLEACCESS(FULL)OF'B'(Cost=1Card=1Bytes=26)
    
    select/*+ORDEREDUSE_NL(AC)*/A.col4
    fromC,A,B
    whereC.col3=5andA.col1=B.col1andA.col2=C.col2
    andB.col3=10;
    ExecutionPlan
    ----------------------------------------------------------
    0SELECTSTATEMENTOptimizer=CHOOSE(Cost=4Card=1Bytes=110)
    10HASHJOIN(Cost=4Card=1Bytes=110)
    21NESTEDLOOPS(Cost=2Card=1Bytes=84)
    32TABLEACCESS(FULL)OF'C'(Cost=1Card=1Bytes=26)
    42TABLEACCESS(FULL)OF'A'(Cost=1Card=82Bytes=4756)
    51TABLEACCESS(FULL)OF'B'(Cost=1Card=1Bytes=26)
    
    select/*+USE_NL(AC)*/A.col4
    fromC,A,B
    whereC.col3=5andA.col1=B.col1andA.col2=C.col2
    andB.col3=10;
    §Ú...¬d.ªº·N«ä¬O.A¡BCªí°µNL.±µ¡A¦}¥B.Aªí§@..ªí¡A¦ý¬O..¦æ.¦E.¬Ý¡A
    .¦³.¨ì§Ú.ªº¥Øªº¡C
    ExecutionPlan
    ----------------------------------------------------------
    0SELECTSTATEMENTOptimizer=CHOOSE(Cost=3Card=1Bytes=110)
    10NESTEDLOOPS(Cost=3Card=1Bytes=110)
    21MERGEJOIN(CARTESIAN)(Cost=2Card=1Bytes=52)
    32TABLEACCESS(FULL)OF'C'(Cost=1Card=1Bytes=26)
    42SORT(JOIN)(Cost=1Card=1Bytes=26)
    54TABLEACCESS(FULL)OF'B'(Cost=1Card=1Bytes=26)
    61TABLEACCESS(FULL)OF'A'(Cost=1Card=82Bytes=4756)
    
    ..¶H.¦æ¤ÀªR¦Z¡G
    analyzetableacomputestatistics;
    analyzetablebcomputestatistics;
    analyzetableccomputestatistics;
    analyzeindexinx_col12Acomputestatistics;
    selectA.col4
    fromC,A,B
    whereC.col3=5andA.col1=B.col1andA.col2=C.col2
    andB.col3=10;
    ExecutionPlan
    ----------------------------------------------------------
    0SELECTSTATEMENTOptimizer=CHOOSE(Cost=5Card=8Bytes=336)
    10HASHJOIN(Cost=5Card=8Bytes=336)
    21MERGEJOIN(CARTESIAN)(Cost=3Card=8Bytes=64)
    32TABLEACCESS(FULL)OF'B'(Cost=1Card=2Bytes=8)
    42SORT(JOIN)(Cost=2Card=4Bytes=16)
    54TABLEACCESS(FULL)OF'C'(Cost=1Card=4Bytes=16)
    61TABLEACCESS(FULL)OF'A'(Cost=1Card=30Bytes=1020)
    
    select/*+ORDERED*/A.col4
    fromC,A,B
    whereC.col3=5andA.col1=B.col1andA.col2=C.col2
    andB.col3=10;
    ExecutionPlan
    ----------------------------------------------------------
    0SELECTSTATEMENTOptimizer=CHOOSE(Cost=5Card=9Bytes=378)
    10HASHJOIN(Cost=5Card=9Bytes=378)
    21HASHJOIN(Cost=3Card=30Bytes=1140)
    32TABLEACCESS(FULL)OF'C'(Cost=1Card=4Bytes=16)
    42TABLEACCESS(FULL)OF'A'(Cost=1Card=30Bytes=1020)
    51TABLEACCESS(FULL)OF'B'(Cost=1Card=2Bytes=8)
    
    select/*+ORDEREDUSE_NL(AC)*/A.col4
    fromC,A,B
    whereC.col3=5andA.col1=B.col1andA.col2=C.col2
    andB.col3=10;
    ExecutionPlan
    ----------------------------------------------------------
    0SELECTSTATEMENTOptimizer=, CHOOSE(Cost=7Card=9Bytes=378)
    10HASHJOIN(Cost=7Card=9Bytes=378)
    21NESTEDLOOPS(Cost=5Card=30Bytes=1140)
    32TABLEACCESS(FULL)OF'C'(Cost=1Card=4Bytes=16)
    42TABLEACCESS(FULL)OF'A'(Cost=1Card=30Bytes=1020)
    51TABLEACCESS(FULL)OF'B'(Cost=1Card=2Bytes=8)
    
    select/*+USE_NL(AC)*/A.col4
    fromC,A,B
    whereC.col3=5andA.col1=B.col1andA.col2=C.col2
    andB.col3=10;
    ExecutionPlan
    ----------------------------------------------------------
    0SELECTSTATEMENTOptimizer=CHOOSE(Cost=7Card=9Bytes=378)
    10HASHJOIN(Cost=7Card=9Bytes=378)
    21NESTEDLOOPS(Cost=5Card=30Bytes=1140)
    32TABLEACCESS(FULL)OF'C'(Cost=1Card=4Bytes=16)
    42TABLEACCESS(FULL)OF'A'(Cost=1Card=30Bytes=1020)
    51TABLEACCESS(FULL)OF'B'(Cost=1Card=2Bytes=8)
    
    select/*+ORDEREDUSE_NL(ABC)*/A.col4
    fromC,A,B
    whereC.col3=5andA.col1=B.col1andA.col2=C.col2
    andB.col3=10;
    ExecutionPlan
    ----------------------------------------------------------
    0SELECTSTATEMENTOptimizer=CHOOSE(Cost=35Card=9Bytes=378)
    10NESTEDLOOPS(Cost=35Card=9Bytes=378)
    21NESTEDLOOPS(Cost=5Card=30Bytes=1140)
    32TABLEACCESS(FULL)OF'C'(Cost=1Card=4Bytes=16)
    42TABLEACCESS(FULL)OF'A'(Cost=1Card=30Bytes=1020)
    51TABLEACCESS(FULL)OF'B'(Cost=1Card=2Bytes=8)
    
    .¤_..¬d.§Ú..¦p¦ó¤].¦³±o¨ì.¦ü¤U­±..ªº.¦æ.¦E¡G
    ExecutionPlan
    ----------------------------------------------------------
    0SELECTSTATEMENTOptimizer=CHOOSE(Cost=35Card=9Bytes=378)
    10NESTEDLOOPS(Cost=35Card=9Bytes=378)
    21TABLEACCESS(FULL)OF'B'(Cost=1Card=2Bytes=8)
    31NESTEDLOOPS(Cost=5Card=30Bytes=1140)
    43TABLEACCESS(FULL)OF'C'(Cost=1Card=4Bytes=16)
    53TABLEACCESS(FULL)OF'A'(Cost=1Card=30Bytes=1020)
    
    .¤W­±ªº.¨Ç¨Ò¤l§Ú.¥i¥H¬Ý¥X¡G³q...¥y²K¥[HINTS¡A.¨ä«ö·Ó§Ú.ªº·Nº@.¦æ¡A
    ¦³.¬O¤@¥ó«Ü§x.ªº¨Æ±¡¡A»Ý­n¤£.ªº..¦UÏú¤£¦Pªºhints¡C.¤_USE_NLÉOUSE_HASH
    ´£¥Ü¡A«Ø.¦PORDERED´£¥Ü¤@°_¨Ï¥Î¡A§_.¤£®e©ö«ü©w¨º.ªí...ªí¡C
    
    ¨ãÊ^®×¨Ò¤ÀªR¡G
    
    .¹Ò¡Goracle817+linux+.¦CÏ@
    swd_billdetailªí5000ÉE..Õu
    SUPER_USERªí2800..Õu
    .±µ¦C¤W³£¦³¯Á¤Þ¡A¦Ó¥Bsuper_user¤¤ªº¤@...¤_swd_billdetailªí¤¤ªº«Ü¦h...
    ªíÉO¯Á¤Þ³£°µ¤F¤ÀªR¡C
    
    ...¥Îªº¬d..¡G
    selecta.CHANNEL,B.user_class
    fromswd_billdetailB,SUPER_USERA
    whereA=B;
    
    ..¦b¤ÀªR..­P¬d.¥Xªº.Õu.¦h¡A¤£¤è«K¡A©Ò¥H¥Î
    count(a.CHANNEL||B.user_class).¥N´À¡A¦Ó¥Bcount(a.CHANNEL||B.user_class)¾Þ§@¥»
    ¨­¦}¤£¥e¥Î.¦hªº..¡A©Ò¥H¥i¥H±µ¨ü¦¹Ïú´À¥N¡C
    
    §Q¥Î¯Á¤Þ¬d.¥XSWD_BILLDETAILªí¤¤©Ò¦³..ªº¤èªk
    SQL>selectcount(id)fromSWD_BILLDETAIL;
    COUNT(ID)
    ----------
    53923574
    Elapsed:00:02:166.00
    ExecutionPlan
    ----------------------------------------------------------
    0SELECTSTATEMENTOptimizer=CHOOSE(Cost=18051Card=1)
    10SORT(AGGREGATE)
    21INDEX(FASTFULLSCAN)OF'SYS_C001851'(UNIQUE)(Cost=18051Card=54863946)
    
    Statistics
    ----------------------------------------------------------
    0recursivecalls
    1952dbblockgets
    158776consistentgets
    158779physicalreads
    1004redosize
    295bytessentviaSQL*Nettoclient
    421bytesreceivedviaSQL*Netfromclient
    2SQL*Netroundtripsto/fromclient
    1sorts(memory)
    0sorts(disk)
    1rowsprocessed
    
    
    §Q¥Î¥þªí.´y.SWD_BILLDETAILªí¤¤¨ú¥X¥þ³¡.Õuªº¤èªk¡C
    SQL>selectcount(user_class)fromswd_billdetail;
    COUNT(USER_CLASS)
    -----------------
    53923574
    Elapsed:00:11:703.07
    ExecutionPlan
    ----------------------------------------------------------
    0SELECTSTATEMENTOptimizer=CHOOSE(Cost=165412Card=1Bytes=2)
    10SORT(AGGREGATE)
    21TABLEACCESS(FULL)OF'SWD_BILLDETAIL'(Cost=165412
    Card=54863946Bytes=109727892)
    
    Statistics
    ----------------------------------------------------------
    0recursivecalls
    8823dbblockgets
    1431070consistentgets
    1419520physicalreads
    0redosize
    303bytessentviaSQL*Nettoclient
    421bytesreceivedviaSQL*Netfromclient
    2SQL*Netroundtripsto/fromclient
    1sorts(memory)
    0sorts(disk)
    1rowsprocessed
    
    
    selectcount(a.CHANNEL||B.user_class)
    fromswd_billdetailB,SUPER_USERA
    whereA=B;
    EXEC_ORDERPLANLINE
    ---------------------------------------------------------------------------------------------------------------------
    6SELECTSTATEMENTOPT_MODE:CHOOSE
    (COST=108968,CARD=1,BYTES=21)
    5SORT(AGGREGATE)(COST=,CARD=1,BYTES=21)
    4NESTEDLOOPS
    (COST=108968,CARD=1213745,BYTES=25488645)
    1TABLEACCESS(FULL)OF'SWORD.SUPER_USER'
    (COST=2,CARD=2794,BYTES=27940)
    3TABLEACCESS(BYINDEXROWID)OF
    'SWORD.SWD_BILLDETAIL'(COST=39,CARD=54863946,BYTES=603503406)
    2INDEX(RANGESCAN)OF'SWORD.IDX_DETAIL_CN'
    (NON-UNIQUE)(COST=3,CARD=54863946,BYTES=)
    
    ..¬d.¯Ó.ªº..«Ü.¡A»Ý­n1.¦h¤p.¡C
    .¦æ¦Zªº«H®§¦p¤U¡G
    COUNT(A.CHANNEL||B.USER_CLASS)
    ------------------------------
    1186387
    
    Elapsed:01:107:6429.87
    
    ExecutionPlan
    ----------------------------------------------------------
    0SELECTSTATEMENTOptimizer=CHOOSE(Cost=108968Card=1Bytes=21)
    10SORT(AGGREGATE)
    21NESTEDLOOPS(Cost=108968Card=1213745Bytes=25488645)
    32TABLEACCESS(FULL)OF'SUPER_USER'(Cost=2
    Card=2794Bytes=27940)
    42TABLEACCESS(BYINDEXROWID)OF'SWD_BILLDETAIL'
    (Cost=39Card=54863946Bytes=603503406)
    54INDEX(RANGESCAN)OF'IDX_DETAIL_CN'(NON-UNIQUE)
    (Cost=3Card=54863946)
    
    Statistics
    ----------------------------------------------------------
    0recursivecalls
    4dbblockgets
    1196954consistentgets
    1165726physicalreads
    0redosize
    316bytessentviaSQL*Nettoclient
    421bytesreceivedviaSQL*Netfromclient
    2SQL*Netroundtripsto/fromclient
    2sorts(memory)
    0sorts(disk)
    1rowsprocessed
    
    ..¥y¤¤¥[¤Jhints¡A.oracleªºÉ¬¤Æ¾¹¨Ï¥Î´O®M´`.¡A¦}¥B¤jªí§@...ªí¡A¥Í¦¨·s
    ªº.¦æ.¦E¡G
    select/*+ORDEREDUSE_NL(A)*/count(a.CHANNEL||B.user_class)
    fromswd_billdetailB,SUPER_USERA
    whereA=B;
    
    EXEC_ORDERPLANLINE
    ---------------------------------------------------------------------------------------------------------------
    6SELECTSTATEMENTOPT_MODE:CHOOSE
    (COST=109893304,CARD=1,BYTES=21)
    5SORT(AGGREGATE)(COST=,CARD=1,BYTES=21)
    4NESTEDLOOPS
    (COST=109893304,CARD=1213745,BYTES=25488645)
    1TABLEACCESS(FULL)OF'SWORD.SWD_BILLDETAIL'
    (COST=165412,CARD=54863946,BYTES=603503406)
    3TABLEACCESS(BYINDEXROWID)OF
    'SWORD.SUPER_USER'(COST=2,CARD=2794,BYTES=27940)
    2INDEX(RANGESCAN)OF'SWORD.IDX_SUPER_USER_CN'
    (NON-UNIQUE)(COST=1,CARD=2794,BYTES=)
    
    ..¬d.¯Ó.ªº...µu¡A¤~20¤À.¡A©Ê¯à¤ñ.¦n¡C
    .¦æ¦Zªº«H®§¦p¤U¡G
    COUNT(A.CHANNEL||B.USER_CLASS)
    ------------------------------
    1186387
    
    Elapsed:00:20:1208.87
    
    ExecutionPlan
    ----------------------------------------------------------
    0SELECTSTATEMENTOptimizer=CHOOSE(Cost=109893304Card=1
    Bytes=21)
    10SORT(AGGREGATE)
    21NESTEDLOOPS(Cost=109893304Card=1213745Bytes=25488645)
    32TABLEACCESS(FULL)OF'SWD_BILLDETAIL'(Cost=165412
    Card=54863946Bytes=603503406)
    42TABLEACCESS(BYINDEXROWID)OF'SUPER_USER'
    (Cost=2Card=2794Bytes=27940)
    54INDEX(RANGESCAN)OF'IDX_SUPER_USER_CN'
    (NON-UNIQUE)(Cost=1Card=2794)
    
    Statistics
    ----------------------------------------------------------
    0recursivecalls
    8823dbblockgets
    56650250consistentgets
    1413250physicalreads
    0redosize
    316bytessentviaSQL*Nettoclient
    421bytesreceivedviaSQL*Netfromclient
    2SQL*Netroundtripsto/fromclient
    2sorts(memory)
    0sorts(disk)
    1rowsprocessed
    
    ..¡G
    ¦].¤W..¬d.³£¬Oªö¥Înestedloop´`.¡A..ªö¥Î­þ.ªí§@.drivingtable´N«Ü
    ­«­n¡C¦b²Ä¤@.sql¤¤¡A¤pªí(SUPER_USER)§@.drivingtable¡A²Å¦Xoracleɬ¤Æªº«Ø.¡A
    ¦ý¬O¥Ñ¤_SWD_BILLDETAILªí¤¤cn¦Cªº­È¦³«Ü¦h­«Î`ªº¡A...¤_SUPER_USER¤¤ªº
    ¨C¤@¦æ¡A³£.¦bSWD_BILLDETAIL¤¤¦³«Ü¦h¦æ¡A§Q¥Î¯Á¤Þ¬d.¥X.¨Ç¦æªºrowid«Ü§Ö¡A¦ý
    ¬O¦A§Q¥Î.¨Çrowid¥h¬d.SWD_BILLDETAILªí¤¤ªºuser_class¦Cªº­È¡A´N¤ñ.ºC¤F¡C­ì
    ¦]¬O.¨Çrowid¬O.É󪺡A¦Ó¥B.ªí¤ñ.¤j¡A¤£¥i¯à.¦s¨ì.¦s¡A©Ò¥H¤L¥G¨C¦¸«ö·Órowid
    ¬d.³£»Ý­n.ª«²zºÏ.¡A.´N¬O..¦æ.¦E¤ñ.ºCªº¯u¥¿­ì¦]¡C..ªG¥i¥H±o¨ì..¡G¬d.
    ¥X1186387¦æ¡A»Ý­n§Q¥Îrowid.SWD_BILLDETAILªí¤¤.¨ú1186387¦¸¡A¦Ó¥B¤j³¡¤À
    ..µw.¤W.¨ú¡C
    
    ¤Ï¨ä¹D¦Ó¦æ¤§¡A§Q¥Î¤jªí(SWD_BILLDETAIL)§@.drivingªí¡A..¤jªí¥u»Ý­n°µ¤@
    ¦¸¥þªí.´y(¦Ó¥B.¨Ï¥Î¦h..¥\¯à¡A¨C¦¸ª«²zI/O³£..¨ú¤L.oracle.Õu.¡A.¦Ó¤@¦¸
    .¨ú«Ü¦h¦æ¡A¥[§Ö¤F.¦æ®Ä²v)¡A.¤_.¥Xªº¨C¤@¦æ¡A³£ÉOSUPER_USER¤¤ªº¦æ.¦æ¤Ç°t¡A
    ¦].SUPER_USERªí«Ü¤p¡A©Ò¥H¥i¥H¥þ³¡©ñ¨ì.¦s¤¤¡A..¤Ç°t¾Þ§@´NÌå§Ö¡A©Ò¥H.sql
    .¦æªº..ÉOSWD_BILLDETAILªí¥þªí.´yªº..®t¤£¦h(SWD_BILLDETAIL¥þªí¥Î11
    ¤À.¡A¦Ó¦¹¬d.¥Î20¤À.)¡C
    
    ¥t¥~¡G¦pªGSWD_BILLDETAILªí¤¤cn¦Cªº­È°ß¤@¡A.²Ä¤@.sql.¦æ.¦E.¦æªº.
    ªG©Î.¤].¤£.¡C¦pªGSUPER_USERªí¤]«Ü¤j¡A¦p500ÉE¦æ¡A.²Ä2.sql.¦æ.¦E.
    ¦æªº.ªG¤Ï¦Ó¤S¥i¯à.®t¡C¨ä.¡A¦pªGSUPER_USERªí«Ü¤p¡A.²Ä2.sql.¥yªº.¦æ
    .¦E¦pªG¤£§Q¥ÎSUPER_USERªíªº¯Á¤Þ¡A¬d.©Î..§ó§Ö¤@¨Ç¡A§Ú.¦³.¦¹.¦æ..¡C
    
    ©Ò¥H¦b.¦æ©Ê¯à.¾ã.¡A¨ãÊ^..­n¨ãÊ^¤ÀªR¡A.¦³¤@..¤@ªº.­ã¡C
    
    ²Ä6³¹¨ä¥¦ª`·N¨Æ.
    
    1.¤£­n...optimizer_mode....rule¡A´N..©Ò¦³ªº.¥y³£¨Ï¥Î°ò¤_..ªºÉ¬¤Æ¾¹
    ¤£ºÞoptimizer_mode..¦p¦ó.¸m¡A¥u­n.¨¬¤U­±3..¥ó¡A´N¤@©w¨Ï¥ÎCBO¡C
    1)¦pªG¨Ï¥ÎIndexOnlyTables(IOTs),¦Û.¨Ï¥ÎCBO.
    2)Oracle7.3¥H¦Z¡A¦pªGªí¤WªºParalledegreeoption..>1¡A
    .¦Û.¨Ï¥ÎCBO,¦Ó¤£ºÞ¬O§_¥Îrulehints.
    3)°£rlue¥H¥~ªº¥ô¦óhints³£..­P¦Û.¨Ï¥ÎCBO..¦æ.¥y
    
    ..¤@¤U¡A¤@..¥y¦b.¦æ.¨ì©³¨Ï¥Î¦óÏúɬ¤Æ¾¹¥i¥H.¤U­±ªºªí®æ¤¤..¥X.¡A.¤W
    ¨ì¤U¬Ý§Aªº.¥y¨ì©³¬O§_.¨¬description¦C¤¤´y­zªº.¥ó¡G
    Description.¶H¬O§_³Q¤ÀªRɬ¤Æ¾¹ªº.«¬
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Non-RBOObject(Eg:IOT)n/a#1
    Parallelism>1n/a#1
    RULEhintn/aRULE
    ALL_ROWShintn/aALL_ROWS
    FIRST_ROWShintn/aFIRST_ROWS
    *OtherHintn/a#1
    OPTIMIZER_GOAL=RULEn/aRULE
    OPTIMIZER_GOAL=ALL_ROWSn/aALL_ROWS
    OPTIMIZER_GOAL=FIRST_ROWSn/aFIRST_ROWS
    OPTIMIZER_GOAL=CHOOSENORULE
    OPTIMIZER_GOAL=CHOOSEYESALL_ROWS
    
    #1ªí¥Ü°£«DOPTIMIZER_GOAL³Q.¸m.FIRST_ROWS¡A§_..¨Ï¥Î
    ALL_ROWS¡C¦bPL/SQL¤¤¡A.¤@ª½¬O¨Ï¥ÎALL_ROWS
    
    *OtherHintªí¥Ü¬O«ü°£RULE¡BALL_ROWS©MFIRST_ROWS¥H¥~ªº¨ä¥¦´£¥Ü
    
    2).CBO..¤F¤@.¦¸É¬¤Æªº.¦æ.¦E.,¤£­n¦PCBO.·N¤£¥h,¥ýªö¨ú¦p¤U±¹¬I:
    a).¬d¬O§_¦bªíÉO¯Á¤Þ¤W¤S³Ì·sªº...Õu
    b).©Ò¦³ªº.Õu.¦æ¤ÀªR¡A¦Ó¤£¬O¥u¤ÀªR¤@³¡¤À.Õu
    c).¬d¬O§_¤Þ¥Îªº.Õu¦r¨åªí¡A¦boracle10G¤§«e¡A¯Ê¬Ù±¡.¤U¬O¤£..Õu¦r¨åªí
    .¦æ¤ÀªRªº¡C
    d)..RBOɬ¤Æ¾¹¡A¬Ý.¥y.¦æªº®Ä²v¦p¦ó¡A¦³.RBO¯à¤ñCBO.¥Íªº§ó¦nªº.
    ¦æ.¦E
    e)¦pªG.¤£¦æ¡A¸ò...¥yªº.¦æ¡A¥Í¦¨trace«H®§¡AµM¦Z¥Îtkprof®æ¦¡¤Ætrace«H
    ®§¡A..¥i¥H±o¨ì¥þ­±ªº¨Ñɬ¤Æªº«H®§¡C
    
    3)°²¦p§Q¥Îªþ.ªº¤èªk.¥t¤@....¦ætrace¡A........¥Î.±µ
    
    4)¤£­n...©w.¶q(bindvariables)ªº¯Ê.¥u¦³..³Â.¡A¦Óɬ.¦h¦h¡A..¤W¨Ï¥Î.©w
    .¶q.µMÁקK¤F­«Î`parse¡A¦ý¬O¥¦.­Pɬ¤Æ¾¹¤£¯à¨Ï¥Î.Õu.¤¤ªº¦C..¡A.¦Ó..¤F.
    ®tªº.¦æ.¦E¡C¦Ó¨Ï¥Îµw..ªºSQL.¥i¥H¨Ï¥Î¦C..¡C.µM..CBO¥\¯àªº¶V.¶V.¡A
    .Ïú±¡..±o¨ì§ïµ½¡C¥Ø«e´N¤w...¤F¦b²Ä¤@¦¸.¦æ.©w.¶qªºsql.¥y.¡A¦Ò.¦C..¡C
    
    5)¦pªG¤@.rowsource¶W.10000¦æ.Õu¡A.¥i¥H³Q..¤jrowsource
    
    6)¦³(+)ªºªí¤£¬Odrivingtable¡Aª`·N¡G¦pªG¦³¥~.±µ¡A¦Ó¥Borderhint«ü©wªº.§ÇÉO¥~..
    .©wªº.§Ç.¬ð¡A.©¿²¤orderhint
    
    7)¼v.CBO..executionplanªºªì©l¤Æ..:
    .¨Ç...¼v.cost­È
    ALWAYS_ANTI_JOIN
    B_TREE_BITMAP_PLANS
    COMPLEX_VIEW_MERGING
    DB_FILE_MULTIBLOCK_READ_COUNT
    FAST_FULL_SCAN_ENABLED
    HASH_AREA_SIZE
    HASH_JOIN_ENABLED
    HASH_MULTIBLOCK_IO_COUNT
    OPTIMIZER_FEATURES_ENABLE
    OPTIMIZER_INDEX_CACHING
    OPTIMIZER_INDEX_COST_ADJ
    OPTIMIZER_MODE>/GOAL
    OPTIMIZER_PERCENT_PARALLEL
    OPTIMIZER_SEARCH_LIMIT
    PARTITION_VIEW_ENABLED
    PUSH_JOIN_PREDICATE
    SORT_AREA_SIZE
    SORT_DIRECT_WRITES
    SORT_WRITE_BUFFER_SIZE
    STAR_TRANSFORMATION_ENABLED
    V733_PLANS_ENABLED
    CURSOR_SHARING
    
    
    ªþ.¡G
    ¦p¦ó³q.¸ò.¤@.«È.ºÝµ{§Ç.¥Xªºsqlªº¤èªk.ɬ¤ÆSQL
    
    .­n..¡A¸ò.¤@.«È.µ{§Ç.¥XªºSQL¥D­n¤À¦¨¤U­±¤L¨B¡G
    1)..­n¸ò.ªº«È.ºÝµ{§Ç¨ì.Õu.ªº.±µ(¦Z­±³£¥Îsession¥N´À)¡A¥D­n§ä¥X¯à°ß¤@.
    .¤@.sessionªºsidÉOserial#.
    2).©w¬Û.ªº..¡A¦p¥´.....(¥i¥Hª¾¹D¤@.sql.¦æ¤F¦h...)¡A¦s©ñ¸ò..Õu
    ªº¤å¥óªº¦ì¸m¡B³Ì¤j­È¡C
    3)..¸ò.¥\¯à
    4).¨t..¦æ¤@¬q..¡A¥H«K¥i¥H¦¬¶°¨ì¸ò..Õu
    5)..¸ò.¥\¯à
    6)®æ¦¡¤Æ¸ò..Õu¡A±o¨ì§Ú.©ö¤_²z¸Ñªº¸ò..ªG¡C
    
    .¦b´N¨C¤@¨B¡A.¥X..ªº.©ú¡G
    1)..­n¸ò.ªº«È.ºÝµ{§Ç¨ì.Õu.ªº.Õu..±µ
    ¬d.session«H®§(¦bsql*plus¤¤.¦æ)¡G
    setlinesize190
    colmachineformata30wrap
    colprogramfora40
    colusernameformata15wrap
    setpagesize500
    selects.sidsid,s.SERIAL#"serial#",s.username,s.machine,s.program,
    p.spidServPID,s.server
    fromv$sessions,v$processp
    wherep.addr=s.paddr;
    
    ¦p±o¨ìªº¤@.¬d..ªG¦p¤U¡G
    SIDserial#USERNAMEMACHINEPROGRAMSERVPIDSERVER
    --------------------------------------------------------------------
    83SCOTTWORKGROUP\SUNNYXUSQLPLUS.EXE388DEDICATED
    
    LOGON_TIME
    ------------------
    2005.06.2818:50:11
    
    ¤W­±ªº.ªG¤¤¤ñ.¦³¥Îªº¦C.¡G
    sid,serial#:...­È.¦X°_.°ß¤@..¤@.session
    username:µ{§Ç.±µ.Õu.ªº¥Î.¦W
    machine:.±µ.Õu.ªºµ{§Ç©Ò¦bªºÉ󾹪ºÉ󾹦W¡A¥i¥Hhostname±o¨ì
    program:.±µ.Õu.ªºµ{§Ç¦W¡A©Ò¦³¥Îjavajdbcthinªºµ{§Çªº¦W¦r³£¤@.¡A
    servpid:ÉOµ{§Ç..ªºªA.¾¹ºÝªºªA.¾¹.µ{ªº.µ{.¡A¦bunix¤U¤ñ.¦³¥Î
    server:µ{§Ç.±µ.Õu.ªº¼Ò¦¡¡G.¥Î¼Ò¦¡(dedicaed)¡B¦@¨É¼Ò¦¡(shared)¡C
    ¥u¦³¦b.¥Î¼Ò¦¡¤Uªº.Õu..±µ¡A.¨ä.µ{¸ò.¤~¦³®Ä
    logon_time:µ{§Ç.±µ.Õu.ªºµn...
    
    ®ÚÕumachine,logon_time¥i¥H¤è«Kªº..¥X¤@..Õu..±µ..ªºsession¡A.¦Ó±o¨ì.
    sesionªº°ß¤@..sid,serial#,...session.¦æ¸ò.°µ¦n­ã.
    
    2).©w¬Û.ªº..
    ...©ú¡G
    timed_statistics:¦¬¶°¸ò.«H®§.¡A¬O§_.¦¬¶°..«H®§¡A¦pªG¦¬¶°¡A
    .¥i¥Hª¾¹D¤@.sqlªº¦U..¦æ.¬q¯Ó.ªº..±¡.
    user_dump_dest:¦s©ñ¸ò..Õuªº¤å¥óªº¦ì¸m
    max_dump_file_size:©ñ¸ò..Õuªº¤å¥óªº³Ì¤j­È¡A¨¾¤î¥Ñ¤_.·Nªº²¨©¿¡A
    ¨Ï¸ò..Õuªº¤å¥ó¥e¥Î¾ã.µw.¡A¼v.¨t.ªº¥¿±`.¦æ
    
    .¸mªº¤èªk¡G
    SQL>execsys.dbms_system.set_bool_param_in_session(-
    sid=>8,-
    serial#=>3,-
    parnam=>'timed_statistics',-
    bval=>true);
    
    SQL>altersystemsetuser_dump_dest='c:\temp';
    --ª`·N...¥y.§ï.¾ã.¨t.ªº¸ò.¤å¥ó¦s©ñªº¦ì¸m¡A©Ò¥H§Ú¤@¯ë¤£§ï....¡A¦Ó¥Î
    ¨t.ªº¯Ê¬Ù­È¡A­n¬d¬Ý.«e¨t.ªº...ªº­È¡A¥i¥H¥Îsystem¥Î.µn.¦Z¡G
    SQL>showparameteruser_dump_dest
    
    SQL>execsys.dbms_system.set_int_param_in_session(-
    sid=>8,-
    serial#=>3,-
    parnam=>'max_dump_file_size',-
    intval=>2147483647)
    
    3)..¸ò.¥\¯à
    SQL>execsys.dbms_system.set_sql_trace_in_session(8,3,true);
    ª`·N¡A¥u¦³¸ò.ªºsession¦A¦¸.¥Xsql.¥y¦Z¡A¤~..¥Ítrc¤å¥ó
    
    4).¨t..¦æ¤@¬q..¡A¥H«K¥i¥H¦¬¶°¨ì¸ò..Õu
    
    5)..¸ò.¥\¯à
    SQL>execsys.dbms_system.set_sql_trace_in_session(8,3,false);
    
    6)®æ¦¡¤Æ¸ò..Õu¡A±o¨ì§Ú.©ö¤_²z¸Ñªº¸ò..ªG¡C
    ..¥Íªºtrace¤å¥ó.¦æ®æ¦¡¤Æ¡G
    ¦b©R¥O´£¥Ü²Å¤U¡A.¦æ¤U­±ªº©R¥O
    tkprofdsdb2_ora_18468.trcdsdb2_trace.outSYS=NOEXPLAIN=SCOTT/TIGER
    ¨ä¥¦¨Ï¥Îtkprofªº¨Ò¤l¡G
    (a)tkproftracefile.trcsort_1.prfexplain=apps/your_apps_passwordprint=10
    sort='(prsqry,exeqry,fchqry,prscu,execu,fchcu)'
    (b)tkproftracefile.trcsort_2.prfexplain=apps/your_apps_passwordprint=10
    sort='(prsela,exeela,fchela)'
    (c)tkproftracefile.trcsort_3.prfexplain=apps/your_apps_passwordprint=10
    sort='(prscnt,execnt,fchcnt)'
    (d)tkproftracefile.trcnormal.prfexplain=apps/your_apps_password
    
    
    ..tkprofµ{§Ç°µ.¤@¨Bªº.©ú¡G
    ¦b¥´.¸ò.¥\¯à¦Z¡Aoracle.³Q¸ò.session¤¤¥¿¦b.¦æªºSQLªº©Ê¯à...Õu³£¦¬
    ¶°¨ì¤@.¸ò.¤å¥ó¤¤¡C..¸ò.¤å¥ó´£¨Ñ¤F.¦h¦³¥Îªº«H®§¡A¨Ò¦p¤@.sqlªº¸ÑªR¦¸.¡B.
    ¦æ¦¸.¡Bfetch¦¸.¡Bª«²z.¦¸.¡B...¦¸.¡BCPU¨Ï¥Î..µ¥¡A§Q¥Î.¨Ç«H®§¥i¥H..
    §Aªºsqlªº..¡A.¦Ó¥Î.ɬ¤Æ§Aªº¨t.¡C¤£©¯ªº¬O¡A¥Í¦¨ªº¸ò.¤å¥ó¤¤ªº.Õu¬O§Ú..¥H
    ²z¸Ñªº¡A©Ò¥H­n¥ÎTKPROF¤u¨ã.¨ä.¦æ..¡A..¦¨§Ú.©ö¤_²z¸Ñ®æ¦¡¡Ctkprof¬Ooracle
    ´£¨Ñªº.¥Î¤u¨ã¡A.¦ü¤_sql*plus¡A¦b¦w.§¹oracle«È.ºÝ¦Z´N¦Û.¦w.¨ì¨t.¤¤¡Aª½±µ¦b
    ©R¥O²Å¤U¥Î´N¥i¥H¤F¡C
    
    .¦b¥´.¸ò.¥\¯à..¥Í¤Frecursivecalls¡A.tkprof¤]..¥Í.¨Çrecursivecallsªº..
    «H®§¡A¦}²M·¡ªº¦b®æ¦¡¤Æ.¥X¤å¥ó¤¤.¦W¥¦..recursivecalls¡C
    ª`·N¡Grecursivecallsªº...Õu¬O¥]§t¦brecursivecalls¤Wªº¡A¦}¤£¥]§t¦b¤Þ°_.recursive
    calls.¥yªºsql.¥y¤W­±¡C©Ò¥H.ºâ¤@.sql.¥y¯Ó.ªº.·½.¡A¤]­n¦Ò..sql.¥y¤Þ°_
    recursivecalls.¥yªá.ªº.·½¡C³q..sys....no.¡A§Ú..¥i¥H¦b®æ¦¡¤Æªº.¥X
    ¤å¥ó¤¤«Ì½ª±¼.¨Çrecursivecalls«H®§¡C
    
    
    ¦p¦ó±o¨ìtkprofªº.§U«H®§¡G
    .¦ætkprof.¡A¤£.¥ô¦ó..¡A´N¥i¥H±o¨ì.¤u¨ãªº.§U«H®§¡C
    
    .¦æ.¦E¡G
    ---------------
    ¤@..¥yªº.¦æ.¦E¬Ooracle.¦æ..sql.¥yªº¤@¨t¦C«ü¥O¡C³q....¦æ.¦E¡A§A
    ¥i¥H§ó¦nªºª¾¹Doracle¦p¦ó.¦æ§Aªºsql.¥y¡A..«H®§¥i¥H.§U§A.©w¬O§_§A.ªºsql.
    ¥y¤w.¨Ï¥Î¤F¯Á¤Þ¡C
    ¦pªG¦btkprof¤¤«ü©w¤FEXPLAIN..¡Atkprof¨Ï¥ÎEXPLAINPLAN©R¥O..¨C.³Q¸ò.
    ªºsql.¥y.¥Í.¦æ.¦E¡C
    
    ¨Ï¥Î.©ú¡G
    TKPROF¤u¨ã±µ¨ü¤@.trace¤å¥ó§@..¤J¤å¥ó¡A§Q¥Î´£¨Ñ.©R¥Oªº¦h....trace¤å¥ó
    .¦æ¤ÀªR¡AµM¦Z.®æ¦¡¤Æ¦nªº.ªG©ñ¨ì¤@..¥X¤å¥ó¤¤¡C
    
    TKPROFªº¨Ï¥Î.ªk¡G
    ----------------
    TKPROFcommand::=
    >>--TKPROFtraced_fileformatted_file---------------------------------------------->
    ||
    +-SORT=---------------------------------+
    ||
    +--OPTION--+
    ||
    |+----,----+|
    |V||
    |__(OPTION)__|
    
    >----------------------------------------------------------------------------->
    ||||||
    +--PRINT=integer--++--INSERT=filname3--++--SYS=---------+
    ||
    +-YES-+
    ||
    +-NO--+
    
    >----------------------------------------------------------------------------->
    ||
    +----------------------------------------EXPLAIN=user/password------+
    ||
    +----TABLE=schema.table----+
    
    >----------------------------------------------------------------------------><
    ||
    +----RECORD=filname----+
    
    
    ¦U...ªº§t.¡G
    'traced_file'
    «ü©w.¤J¤å¥ó¡A§Yoracle.¥Íªºtrace¤å¥ó¡A.¤å¥ó¤¤¥i¥H¥u¥]§t¤@.
    sessionªº¸ò.«H®§¡A¤]¥i¥H¥]§t¨t.¤¤©Ò¦³sessionªº«H®§(¦¹.»Ý­n¦b
    ¨t...¦æ¸ò.)
    'formatted_file'
    «ü©w.¥X¤å¥ó¡A§Y§Ú.·Q±o¨ìªº©ö¤_²z¸Ñªº®æ¦¡¤Æ¤å¥ó¡A§Ú.§Q¥Î.¤å¥ó
    ....¦æªºsql.¦æ¤ÀªR¡C
    'EXPLAIN'
    §Q¥Î­þ.¥Î..trace¤å¥ó¤¤ªºsql.¦æ¤ÀªR¡A.¦Ó±o¨ì.sql.¥yªº
    .¦æ.¦E¡A.¤].©ú¦btracefile¤¤¦}.¦³¦U.sql.¥yªº.¦æ.¦E¡A¥u¬O¦b.
    ¦ætkprofµ{§Ç.¤~.tracefile¤å¥ó¤¤ªºsql.¥y¥Îexplian..«ü©wªº
    ¥Î..±µ¨ì.Õu.¡AµM¦Z.¥ÎEXPLAINPLAN©R¥O¥Í¦¨sqlªº.¦æ.¦E¡C
    ..¥Î.¤@¯ë¬O§Aªºµ{§Ç¤¤.±µ.Õu.ªº¥Î.
    'TABLE'
    ¦b.sql.¥y.¦æ¤ÀªR.¡A..¥Íªº.¦æ.¦E..¦s©ñ¨ì.ªí¤¤¡C
    ¤@¯ë¤£»Ý­n...¡A...ªí¤£¦s¦b.¡Atkprof.¦Û..«Ø¬Û.ªºªí¡A
    ¦}¦b¤ÀªR§¹¤§¦Z¡A..«Øªºªí¦Û..°£¡C¦pªG­n«ü©w¦Û©w.ªºªí¡A.ªíªº.ÌÛ
    ¥².ÉOutlxplan.sql¤å¥ó¤¤«ü©wªºªíªº.ÌÛ¤@.¡C
    §Ú¤@¯ë¤£.¸m....¡A.¨äªö¥ÎÀq.ªºªí¦W¡A¦}¦Û..«Ø¡B.°£
    'SYS'
    ¬O§_.sys¥Î..¦æªºsql.¥y©Î³Q¸ò.session.¥ÍªºrecursiveSQL
    ¤].¦æ¤ÀªR¡A¦}.¤ÀªR.ªG©ñ¨ì.¥X¤å¥ó¤¤¡C¯Ê¬Ù­È.YES¡C
    §Ú¤@¯ë..NO¡A...¥X¤å¥ó¤¤¥u¥]§t§Ú.¥Xªºsql.¥y¡A
    ¦Ó¤£¥]§t¨t..¥Íªºsql¡C
    SORT
    «ö·Ó«ü©wªº±Æ§Ç..(.¥ó).®æ¦¡¤Æ¦nªºsql.¥y.¦æ­°§Ç±Æ¦C¡AµM¦Z¦s©ñ
    ¨ì.¥X¤å¥ó¤¤¡C¥i¥H.¦h.±Æ§Ç...¦X°_.¡A¦pªG.¦³«ü©w±Æ§Ç..¡A
    .«ö·Ó¨Ï¥Îsqlªº¥ý¦Z.§Ç¡C
    ±Æ§Ç..¦³¡G
    prscntnumberoftimesparsewascalled
    prscpucputimeparsing
    prselaelapsedtimeparsing
    prsdsknumberofdiskreadsduringparse
    prsqrynumberofbuffersforconsistentreadduringparse
    prscunumberofbuffersforcurrentreadduringparse
    prsmisnumberofmissesinlibrarycacheduringparse
    execntnumberofexecutewascalled
    execpucputimespentexecuting
    exeelaelapsedtimeexecuting
    exedsknumberofdiskreadsduringexecute
    exeqrynumberofbuffersforconsistentreadduringexecute
    execunumberofbuffersforcurrentreadduringexecute
    exerownumberofrowsprocessedduringexecute
    exemisnumberoflibrarycachemissesduringexecute
    fchcntnumberoftimesfetchwascalled
    fchcpucputimespentfetching
    fchelaelapsedtimefetching
    fchdsknumberofdiskreadsduringfetch
    fchqrynumberofbuffersforconsistentreadduringfetch
    fchcunumberofbuffersforcurrentreadduringfetch
    fchrownumberofrowsfetched
    useriduseridofuserthatparsedthecursor
    
    PRINT
    ¥u¦C¥X«ü©w.¶qªº¤w±Æ§Çªºsql.¥y¡A±Æ§Çªº.¥ó..SORT..¡C
    ¦pªG©¿²¤¦¹..¡Atkprof.¸ò.¤å¥ó¤¤ªº©Ò¦³ªºsql.¥y¤Î¨ä¬Û.ªº
    ¤ÀªR.Õu¦s©ñ¨ì.¥X¤å¥ó¤¤¡C
    PrintÉOsort...¦X¦b¤@°_¡A¥i¥H..:
    §ä¥X¬Y¤@.¬q¯Ó.cpu³Ì¦hªº«en.sql
    §ä¥X¬Y¤@.¬q.µw.³Ì¦hªº«en.sqlµ¥µ¥¡C
    
    INSERT
    .«Ø¤@.sql.¥»¤å¥ó¡A¨½­±¥]§tcreatetableÉOinsert.¥y¡C
    §Q¥Î...¥»¤å¥ó.«Ø¤@.ªí¤Î´¡¤J.Õu¦Z¡A¥i¥H±o¨ì¸ò.¤å¥ó¤¤
    ©Ò¦³sql.¥y(¥]§trecursiveSQL)ªº..«H®§¡C¦p
    ,depth,user_id,
    parse_cnt,parse_cpu,parse_elap,parse_disk,
    parse_query,parse_current,parse_miss
    ,exe_count,exe_cpu,exe_elap,exe_disk,exe_query,
    exe_current,exe_miss,exe_rows
    ,fetch_count,fetch_cpu,fetch_elap,fetch_disk,
    fetch_query,fetch_current,fetch_rows,ticks
    ,sql_statement¡C
    §Q¥Î.¨Ç«H®§¡A¤]¥i¥H..¦³..ªºsql¡C§Y¬O®æ¦¡¤Æ¦nªº.¥X¤å¥ó¤¤
    ¦³.sql©Ê¯à«H®§.Õuªº.Õu.ªíªº§Î¦¡¡C
    §Ú¤@¯ë¤£¥Î...
    RECORD
    .«Ø¤@.¥]§t«È.ºÝµ{§Ç.¥Xªº©Ò¦³ªºsql.¥yªº.¥»¤å¥ó¡C
    ª`·N¡A¦}¤£¥]§trecursiveSQL¡C·Qª¾¹D¥¦ªº¥Î..¡H
    .¤F¥i¥H.±´.¤Hµ{§Ç¬O¦p¦ó...Õu.ªº¡A.¦Ó.¤F¸Ñµ{§Çªº..¬yµ{¡C
    ¦¹.¡A³Ì¦n¤£¥Îsort..¡A..´N¥i¥H«ö¥ý¦Z.¥Xªº.§Çªº¨ìsql.
    
    ¨Ò¤l1¡G
    .¸ò.¤å¥ó"dsdb2_ora_18468.trc".¦æ¤ÀªR¡A¦}.¨ä®æ¦¡ªº.ªG©ñ¨ì"dsdb2_trace.out"¤å¥ó
    ¤¤¡G
    TKPROFdsdb2_ora_18468.trcdsdb2_trace.outSYS=NOEXPLAIN=SCOTT/TIGER
    
    ¤W­±ªº¨Ò¤l¤¤¡G
    EXPLAIN...TKPROFµ{§Ç.±µ¨ìSCOTT¥Î.¡AµM¦Z¥ÎEXPLAINPLAN©R¥O.¸ò.
    ¤å¥ó¤¤ªºsql.¥y.¥Í.¦æ.¦E¡CSYS..ªº­È.NO¡A..TKPROF´N.©¿²¤.¸ò.¤å
    ¥ó¤¤ªºrecursiveSQL¡C
    
    ¨Ò¤l2¡G
    TKPROFDLSUN12_JANE_FG_SVRMGR_007.TRCOUTPUTA.PRF
    EXPLAIN=SCOTT/TIGERTABLE=SCOTT.TEMP_PLAN_TABLE_A
    INSERT=STOREA.SQLSYS=NOSORT=(EXECPU,FCHCPU)
    
    ª`·N¤W­±ªº©Ò¦³©R¦W..³£¦b¤@¦æ¤¤¡A§_.»Ý­n¦³.¦æ²Å¡C
    
    ¤W­±ªº¨Ò¤l¤¤¡G
    TABLE..¨ÏTKPROF¨Ï¥Îscott¥Î.¤UªºTEMP_PLAN_TABLE_Aªí§@...¦s©ñsql
    .¦æ.¦Eªºªí¡C
    INSERT..¨ÏTKPROF.¥Í¤@.¦W.STOREA.SQLªº.¥»¤å¥ó¡A¦s©ñ©Ò¦³³Q¸ò.ªºsql
    .¥yªº...Õu¡C
    SORT..¨ÏTKPROF¥ý«ö·Ósql.¥y¨Ï¥Îªºcpu.¦æ..ÉO..¥yfetch¾Þ§@¨Ï¥Îªºcpu
    ...¦æ±Æ§Ç¡AµM¦Z.¨ä.¨ì.¥X¤å¥ó¤¤¡C
    
    ¸Ñ.tkprofµ{§Ç.¥Íªº®æ¦¡¤Æ¤å¥ó¡G
    
    tkprofªº®æ¦¡¤Æ.¥X¤å¥ó¥D­n¥]§t.¤j³¡¤À¡G
    header
    body
    summary
    
    header¡G
    ¥D­n¥]¬A¤@¨Ç´y­z«H®§¡A¦pTKPROFªºª©¥»¡B.¦æ..¡A¦U....ªº´y­z¡C¦p¡G
    
    TKPROF:Release8.1.7.0.0-Productionon¬P´Á¥|6¤ë3013:10:592005
    (c)Copyright2000OracleCorporation.Allrightsreserved.
    Tracefile:D:\oracle\admin\xyj\udump\ORA01720.TRC
    Sortoptions:default
    
    ********************************************************************************
    count=numberoftimesOCIprocedurewasexecuted
    cpu=cputimeinsecondsexecuting
    elapsed=elapsedtimeinsecondsexecuting
    disk=numberofphysicalreadsofbuffersfromdisk
    query=numberofbuffersgottenforconsistentread
    current=numberofbuffersgottenincurrentmode(usuallyforupdate)
    rows=numberofrowsprocessedbythefetchorexecutecall
    ********************************************************************************
    
    body¡G
    ¬O§Ú.¥D­n.¤ßªº¦a¤è¡A¦³§Ú.·P.½ìªº«H®§¡C¦psql.¥y¡Bsql.¥yªº..«H®§¡Bsql.¥y
    ªº.¦æ.¦Eµ¥¡C¦p
    select*
    from
    emp
    
    callcountcpuelapseddiskquerycurrentrows
    ------------------------------------------------
    Parse30.000.001010
    Execute30.000.000000
    Fetch60.000.00161236
    ------------------------------------------------
    total120.000.00261336
    
    Missesinlibrarycacheduringparse:1
    Optimizergoal:CHOOSE
    Parsinguserid:19(SCOTT)
    
    RowsRowSourceOperation
    ----------------------------------------------------------
    12TABLEACCESSFULLEMP
    
    RowsExecutionPlan
    ----------------------------------------------------------
    0SELECTSTATEMENTGOAL:CHOOSE
    12TABLEACCESS(FULL)OF'EMP'
    
    
    DELETEFROMRM$HASH_ELMS
    callcountcpuelapseddiskquerycurrentrows
    --------------------------------------------------
    Parse20.000.000000
    Execute2912.0412.616786685310819
    Fetch00.000.000000
    --------------------------------------------------
    total3112.0412.616786685310819
    
    Missesinlibrarycacheduringparse:0
    Optimizerhint:CHOOSE
    Parsinguserid:9(DES12A)(recursivedepth:3)
    
    RowsExecutionPlan
    ----------------------------------------------------------
    0DELETESTATEMENTHINT:CHOOSE
    16TABLEACCESS(FULL)OF'RM$HASH_ELMS'
    
    summary¡G
    .©Ò¦³ªºsql.¥y¦U..¦æ.¬qªº...Õuªº..¡G
    
    OVERALLTOTALSFORALLNON-RECURSIVESTATEMENTS--.©ú¬O¥Î..¥Xªº
    sql.¥yªº...Õuªº..
    
    callcountcpuelapseddiskquerycurrentrows
    -----------------------------------------------------
    Parse70.000.00220120
    Execute70.000.001271
    Fetch100.000.002671652
    -----------------------------------------------------
    total240.000.0052702553
    
    Missesinlibrarycacheduringparse:5
    
    
    OVERALLTOTALSFORALLRECURSIVESTATEMENTS--.©ú¬O¨t..¥Xªºsql.¥y
    ªº...Õuªº..
    
    callcountcpuelapseddiskquerycurrentrows
    --------------------------------------------------
    Parse750.000.002320
    Execute810.000.001151
    Fetch1530.000.00213550110
    --------------------------------------------------
    total3090.000.00243597111
    
    Missesinlibrarycacheduringparse:29
    
    8userSQLstatementsinsession.
    74internalSQLstatementsinsession.
    82SQLstatementsinsession.
    5statementsEXPLAINedinthissession.
    *********************************************************************
    Tracefile:D:\oracle\admin\xyj\udump\ORA01720.TRC
    Tracefilecompatibility:8.00.04
    Sortoptions:default
    
    1sessionintracefile.
    8userSQLstatementsintracefile.
    74internalSQLstatementsintracefile.
    82SQLstatementsintracefile.
    34uniqueSQLstatementsintracefile.
    5SQLstatementsEXPLAINedusingschema:
    SCOTT.prof$plan_table
    Defaulttablewasused.
    Tablewascreated.
    Tablewasdropped.
    825linesintracefile.
    
    
    .¥u.body¤¤ªº¨C³¡¤À§@¥X...©ú¡G
    1)sql.¥yªº..«H®§
    §Ú.§âselect.¥yªº.¦æ.µ{¤À¦¨3..¬q(¤ÀªR...¦æ..¨ú.ªG)¡A§âDML.¥yªº
    .¦æ¤À¦¨2..¬q(¤ÀªR...¦æ)¡C®æ¦¡¤Æªº.¥X¤å¥ó¤¤¦C¥X¤Fsql.¥y.¦æªº¨C¤@.¬q©Ò¯Ó
    ..·½..«H®§¡A.¤_.¨Ç«H®§¡A¬O¥H¦æ¦Cªº¼Ò¦¡.¥Xªº¡C¨C¤@¦æ¥Nªí¨C.sql.¦æ¤¤ªº¨ã
    Ê^¬Y¤@.¬q©Ò¯Ó.ªº¬Û..·½¡C..³q.¤ÀªR¨C..¬q¯Ó.ªº.·½¡A¥i¥Hª¾¹D­þ.sql¦³.
    .¡A¦}.¤@¨Bª¾¹D.sql.¦æ.µ{¤¤­þ¤@.¬q¥X.¤F..¡A.¦Ó§Ö³t©w¦ì..¡A.¦Ó¨³³t¸Ñ
    ...¡C
    
    ¤U­±.¨C.¦C.¦æ.©ú¡G
    call:ªí¥Üsql.¥y.¦æªº¨C..¬q¡A¨C.sql.¥yªº¬¡.³Q¤À¦¨¥H¤U3³¡¤À¡G
    Parse:.¥y³Q¸ÑªRªº¦¸.¡A¥D­n¬O¥Í¦¨.¦æ.¦E¡C¥]§thardparseÉOsoftparse¡C
    »Ý­n°µªº¤u§@¡G.­­.¬d¡Aªí¡B¦C¡B¤Þ¥Îªºªíªº¦s¦b©Ê.¬d¡F
    ¤ñ..¦æ.¦E¡A.¥X³Ì¦nªº¤@.µ¥µ¥¡C
    Execute:¯u¥¿.¦æ.¥yªº..¡A.¤_DML.¥y¡A¦b¦¹.¬q¤¤­×§ï.Õu¡F
    .¤_select.¥y¡A.¨B¥u¬O..¥X¬d.¥Xªº¦æ¡C
    Fetch:¥u.select.¥y¦³®Ä¡ADML.¥yªº.¦æ¦}.¦³..¬q
    
    ¨ä¥¦¦Cªº­È³£¬OÉOsql.¦æ¤T..¬q¤¤©Ò¯Ó.ªº.·½ªº..­È
    COUNT
    ¤@..¥y³Qparsed¡Bexecuted¡Bfetchedªº¦¸.
    CPU
    .¦æ...¥yªº¨C..¬q¯Ó.ªºcpu..
    ELAPSED
    .¦æ...¥yªº¨C..¬q¯Ó.ªº...(¥]¬A¤W­±ªºcpu..ÉO¨ä¥¦..¡A¦p..Õu)
    DISK
    ¨C..¬q.µw.ªº¦¸.(¦³¥i¯à.filesystembuffer¤¤¨ú±o.Õu)
    .¤_...¡A§Ú.§Æ±æ.­È¶V¤p¶V¦n¡A¦pªG.­È«Ü¤j¡A.sql»Ý­n.¾ã¡A
    «Ø¥ß¬Û.¯Á¤Þ©Î¬Ý¬O§_¥¿Ú̪º¨Ï¥Î¤F¯Á¤Þ
    QUERY
    ¨C..¬q¥Hconsistentmode¤è¦¡..Õu.buffer¤¤¬d.ªºbuffers.¡C
    .¤_¬d.¡A¨äbuffer¤@¯ë³£¬O¥Hconsistentmode¼Ò¦¡³Q.¨ú
    CURRENT
    ¨C..¬q¥Hcurrentmode¤è¦¡..Õu.buffer¤¤¬d.ªºbuffers.¡CBuffersareoften
    .¤_DML.¥y¡A»Ý­nªºbuffer¬O¥Hcurrentmode¼Ò¦¡³Q.¨úªº¡C
    QUERY+CURRENTªº©M¬O.sql.¥y.ªº¦s¨úªºbuffer.¥Ø
    ROWS
    ..sql.¥y³Ì¦Z.²zªº¦æ.¡A¤£¥]¬A¤l¬d.¤¤¬d.¥X.ªº¦æ.¡C
    .¤_select.¥y¡A.­È.¥Í¤_fetch.¬q¡F.¤_dml.­È.¥Í¤_execute.¬q¡C
    
    ¦]...¯Ó.ªº...¡A³Ì¤pªº.¶q.¦ì.0.01¬í¡A©Ò¥H¦pªG±o¨ì¤@..¬q¤¤¯Ó.ªº
    ...0¡A¦}¤£ªí¥Ü...¬q.¦³¯Ó...¡A¦Ó¬OÌå¥i¯à.©ú...¬q¯Ó.ªº..¤p¤_0.01
    ¬í¡A¤p¤_.¶q.¦ì¡A.Õu..ªk..¡A¥u­n¥H0.00ªí¥Ü
    
    2)ÉO.¦æ.¦E¦³.ªº.®e
    Missesinlibrarycacheduringparse:1--.©úhardparseªº¦¸.
    Optimizergoal:CHOOSE--ªö¥ÎªºÉ¬¤Æ¾¹
    Parsinguserid:19(SCOTT)--¨º.¥Î..¦æªº.sql
    
    RowsRowSourceOperation
    ----------------------------------------------------------
    12TABLEACCESSFULLEMP
    
    RowsExecutionPlan--¤U­±¬O¯u¥¿ªº.¦æ.¦E
    ----------------------------------------------------------
    0SELECTSTATEMENTGOAL:CHOOSE
    12TABLEACCESS(FULL)OF'EMP'
    
    Missesinlibrarycacheduringparse:....­È¬O¤@.¤ñ.­«­nªº«ü.¡A¦pªG.­ÈÉO
    ..¥yªºparse..­È°ò¥»¬Ûµ¥¡A¦}¥B.­È¤ñ.¤j¡A¦Ó¥B.sqlªºparse.¬q¯Ó.ªº.·½
    ¤ñ.¦h¡A..©ú§Aªº.¥y..ªö¥Îbindvariable¼Ò¦¡¡C
    
    .¦æ.¦E³¡¤À¤]¤ñ.­«­n¡A¥¦¯à¬Ý¥X¬d.¬O§_¥Î¤F¯Á¤Þ¡A©M¦UÏú..¾Þ§@©Òªö¥Îªº¤èªk¡C
    
    «Ø.¥Îautotrace.¦æ¸ò.¦Ó¤£¬O¥Î¤W­±¤èªk.¦æ¸ò.ªº­ì¦]¡G
    .µM¤W­±ªº¤èªk.¥X¤Fsql.¥yªº.¦æ.¦E¡B...Õuµ¥«H®§¡A¦ý¬O¦].tkprofªº®æ¦¡
    ¤Æ.¥X¤£.¥X..ªºcostsÉOstatistics«H®§¡A.¨Ï§Ú.¦b§Q¥Î®æ¦¡¤Æ.¥X§P.¨t.¨ì©³¬O
    ¨Ï¥Î°ò¤_¥NɲªºÉ¬¤Æ¤èªk.¬O°ò¤_..ªºÉ¬¤Æ¤èªk.¡A·P¨ì«Ü°g¯í¡A§Ú.¤£¯à©úÚ̪ºª¾¹D¨ì
    ©³¨t.¦b¨Ï¥Î¨ºÏúɬ¤Æ¾¹¡C
    
    ¦ý¬O..¦]...­ì¦]´N¨Ï§Ú.©ñ.¤W­±¸ò.¤èªk¦Ó.¥Îautotrace¥\¯à¬O¤£.ªº¡A¦].¡G
    1)¨ì©³¨t.¬O¨Ï¥Î°ò¤_..ªº.¬O°ò¤_¥NɲªºÉ¬¤Æ¾¹§Ú.¥i¥H­É§UÉO¨ä¥¦«H®§...¡A¦Ó
    ¥B.10G¥H¦Z¡Aoracle´N«Å¥¬¤£¦A¨Ï¥Î°ò¤_..ªºÉ¬¤Æ¾¹¤F¡C
    2)¤W­±ªº¸ò..ªk¯à..autotrace¤£¯à§¹¦¨ªº¥\¯à¡A¦].autotrace¥u¯à¸ò.¥»..¡A¦Ó
    ¤£¯à¸ò.¨ä¥¦..¡A..°²¦p¦³¤@.¥¿¦b.¦æªºµ{§Ç¥X.¤F©Ê¯à..¡A§Ú.´N¤£¯à¨Ï¥Î
    autrace¥h¸ò.sqlªº.¦æ±¡.¡C
    
    
    ¤U­±¥H¤@.¨ãÊ^ªº¨Ò¤lªº.Õu.©ú¦p¦ó§Q¥Î®æ¦¡¤Æªº.¥X¤å¥ó.¦æsqlªº.¾ã¡G
    
    ²Ä¤@¨B¡G-.¬Ý®æ¦¡¤Æ.¥X¤å¥ó³Ì¦Z³¡¤À¡A§Y..³¡¤À
    ===========================================================
    OVERALLTOTALSFORALLNON-RECURSIVESTATEMENTS
    
    |call|count|cpu|elapsed|disk|query|current|rows|
    |---------|-------|------|---------|---------|--------|---------|--------|
    |Parse|[A]7|1.87|4.53|385|[G]553|22|0|
    |Execute|[E]7|0.03|0.11|[P]0|[C]0|[D]0|[F]0|
    |Fetch|[E]6|1.39|4.21|[P]182|[C]820|[D]3|[F]20|
    --------------------------------------------------------------------------
    
    Missesinlibrarycacheduringparse:5
    Missesinlibrarycacheduringexecute:1
    
    8userSQLstatementsinsession.
    12internalSQLstatementsinsession.
    [B]54SQLstatementsinsession.
    3statementsEXPLAINedinthissession.
    
    (1).³q.¤ñ.[A]ÉO[B]¡A§Ú.¥i¥H..¬O§_¦³.¶qªºparsing.¶H¡C¦b¤W­±ªº¨Ò¤l¤¤¡A§Ú
    .¥i¥H¬Ý¨ì¦bsession¤¤.¦æ¤F54..¥y¡A¦ý¬O¥u¦³7¦¸parses¡A©Ò¥H.¬O¤ñ.¥¿±`ªº¡A
    .¦³.¶qªºparse.¶H¡C
    
    (2).§Q¥Î[P],[C]&;[D]..©w.Õu.°ª³t.¦sªº©R¤¤²v..
    HitRatioislogicalreads/physicalreads:
    LogicalReads=ConsistentGets+DBBlockGets
    LogicalReads=query+current
    LogicalReads=Sum[C]+Sum[D]
    LogicalReads=0+820+0+3
    LogicalReads=820+3
    LogicalReads=823
    
    HitRatio=1-(PhysicalReads/LogicalReads)
    HitRatio=1-(Sum[P]/LogicalReads)
    HitRatio=1-(128/823)
    HitRatio=1-(0.16)
    HitRatio=0.84or84%
    
    (3).§Ú.§Æ±æfetchªº¦¸.­n¤ñrows¤p¡A§Y¤@¦¸fetch¥i¥H¨ú¦h¦æ.Õu(arrayfetching)¡A
    ¥i¥H§Ú.¥i¥H§ó°ª®Äªº¨ú±o¬d..Õu¡C
    .¥i¥H³q.¤ñ.[E]ÉO[F].
    
    [E]=6=NumberofFetches
    [F]=20=NumberofRows
    
    .¤W­±ªº«H®§¤¤§Ú.¥i¥H¬Ý¨ì¡A6¦¸fetch.¦@¨ú¤F20¦æ.Õu¡A.ªG¤£¬O«Ü§¥¡C¦pªG¨Ï¥Î
    ¤F..¨}¦n°t¸marrayfetching¡A.¥i¥H¥Î§ó¤Öªºfetch¦¸.¨ú¨ì¦P..¶qªº.Õu¡A©Ê¯à.§ó
    ¦n¡C
    
    (4).[G]ªí¥Ü.¤F..¥y.¦æ¤ÀªR¡A..Õu¦r¨å§i..¦sªº¦¸.
    -.....©Ê¯àªº¼v.¤£¤j¡A¤@¯ë¤£¥Î.¤ß¡C¦Ó¥B....­È¤@¯ë¤£¬O§Ú.¥i¥H±±¨î
    ªº¡C
    
    ²Ä¤G¨B¡V.¬d¯Ó.¤j¶q.·½ªº.¥y
    ===============================================
    update...
    where...
    
    |call|count|cpu|elapsed|disk|query|current|rows|
    |---------|-------|-----|---------|------|--------|---------|--------|
    |Parse|1|7|122|0|0|0|0|
    |Execute|1|75|461|5|[H]297|[I]3|[J]1|
    |Fetch|0|0|0|0|0|0|0|
    -----------------------------------------------------------------------
    
    [H]ªí©ú»Ý­n..297..Õu.¤~¯à§ä¨ì§Ú.»Ý­n­×§ïªº.Õu¡C
    [I]ªí©ú§Ú.ªº­×§ï¾Þ§@¤~­×§ï3..Õu.¤¤ªº.Õu
    [J]ªí©ú§Ú.¥u­×§ï¤F¤@¦æ.Õu(¨ä¥¦.Õu.ªº­×§ï..undo¡Bredo«H®§)
    
    .¤F­×§ï¤@¦æ.Õu¦Ó­n·j.297..Õu.¡C
    ¦Ò.¬O§_»Ý­n¦b¬d.ªº¦C¤W«Ø¤@.¯Á¤Þ¡I
    
    ²Ä¤T¨B¡V¬d¬Ý¬O§_¦³.¶qªºparse.¶H
    ==============================
    select...
    
    |call|count|cpu|elapsed|disk|query|current|rows|
    |---------|-------|---------|---------|------|--------|---------|-------|
    |Parse|[M]2|[N]221|329|0|45|0|0|
    |Execute|[O]3|[P]9|17|0|0|0|0|
    |Fetch|3|6|8|0|[L]4|0|[K]1|
    -------------------------------------------------------------------------
    
    Missesinlibrarycacheduringparse:2[Q]
    
    [K]ªí©ú..¬d.¥uªð¦^¤@¦æ.Õu
    [L]ªí©ú§Ú.»Ý­nfetch4¦¸¤~¯à±o¨ì.Õu¡A.¬O¥¿±`ªº¡A¦].»Ý­n.¥~ªºfetch¾Þ§@¥H«K.
    ¬d¬O§_fetch¨ìcursorªº³Ì¦Z¡A.µM.¥i¯à¦³¨ä¥¦fetch..¡C
    
    
    [M]ªí©ú§Ú..¦æ¤F.¦¸parse(¥]§thardparseÉOsoftparse)¡V.¬O§Ú.¤£·Q¬Ý¨ìªº¡A
    ¯S.¬O.parse.¬q¾Þ§@¯Ó.cpu.·½¤ñexecute.¬q¯Ó.ªºcpu.·½([O]&;[P])
    ¦h±o¦h±o.­Ô¡C[Q]ªí©ú...parse¾Þ§@³£¬Ohardparse¡C¦pªG[Q]ªº­È.1¡A
    ....¥y¦³¤@.hardparse¡AµM¦Z¸ò.¤@.softparse(.....¦s¤¤±o¨ì
    ¤W¦¸¤ÀªRªº«H®§¡A¤ñhardparse­n°ª®Äªº¦h)¡C
    
    .¤W­±ªº¨Ò¤l..¡A.ªG¦}¤£¬O¯S.ªº§¥¡A¦]...¥y¥u.¦æ2¦¸¡AµM¦Ó¦pªG.¤_.Ác.
    ¦æªºsql..¡A¦pªG¤L¥G¨C¦¸.¦æ³£»Ý­nhardparse¡A..ªG´N..ªº«Ü§¥¡A¦¹.§Ú...
    .¥y¦³.¶qªºparse.¶H(excessiveparsing)¡C
    
    o¸Ñ....ªº¤èªk¡G
    -¨Ï¥Îbindvariables
    -¨Ïsharedpool¨¬.¤j¡A.¦Ó¦b.¦s¤¤®e.§A.¦æ.ªº¨C¤@..¥y¡A
    ¥H«K¤U¤@¦¸¥i¥H­«¥Î..¥y¡C¦ý.Ïú¤èªkªv.¤£ªv¥»¡A¦bÁc¦£ªº¨t.¤¤¦³..¤Þ°_
    ora-04031:unabletoallocate%sbytesofsharedmemory(%s,%s,%s)
    ..¡C
    -¨Ï¥Î8i·s¤Þ¤Jªº..cursor_sharing¡A«Ø.¦b....¦Z¦A¨Ï¥Î...¡A¦].¦³.
    ¨Ï¥Î...¦Z.¤Þ°_¨t.©Ê¯à¤U­°
    
    ¦p¦ó­°§Cparse.¬q¨Ï¥Îªºcpu..
    1.Rewritetheapplicationsostatementsdonotcontinuallyreparse.
    2.ReduceparsingbyusingtheinitializationparameterSESSION_CACHED_CURSORS.
    3.Usebindvariablestoreduceparsing.
    
    
    ª`·N¡G
    .¦í¦pªGcursor.¦³³Q..¡A.¦btkprofªº.¥X¤å¥ó¤¤¬Ý¤£¨ì¥ô¦ó.sqlªº.¥X¡C.¸m
    SQL_TRACE=false¦}¤£¯à..PL/SQLªºchildcursors¡A©Ò¥H­n¦b¦Û¤vªº¦s..µ{¤¤
    .¦¨¤Î....¦¡cursorªº..¡C¥O§Ú.°ª.ªº¬O¡A¦bSQL*Plus¤¤¡A.¥y¤@¥¹.¦æ§¹.¡A
    ..¥y..ªºcursor¤]¦Û...¤F¡C
    
    
    
    
    
    
    
    .¦Ò«H®§¡G
   &, nbsp;1.METALINK
    
    
    
    
  • ÉÏһƪ×ÊѶ£º sqlÒâÒå
  • ÏÂһƪ×ÊѶ£º sqlÐÔÄܵ÷Õû(1)
  • ÉèΪÊ×Ò³ | ¼ÓÈëÊÕ²Ø | ÍøѧÊ×Ò³ | Ô­´´ÂÛÎÄ | ¼ÆËã»úÔ­´´
    °æȨËùÓÐ ÍøѧÍø [Myeducs.cn] ÄúµçÄԵķֱæÂÊÊÇ ÏñËØ
    Copyright 2008-2020 myeducs.Cn www.myeducs.Cn All Rights Reserved ÏæICP±¸09003080ºÅ ³£Äê·¨ÂɹËÎÊ£ºÍõÂÉʦ