OracleʹÓõÄhintsµ÷Õû»úÖÆ
10gÊý¾Ý¿â½éÉÜ£º¿ÉÒÔʹÓøü¶àеÄoptimizer hintsÀ´¿ØÖÆÓÅ»¯ÐÐΪ¡£ÏÖÔÚÈÃÎÒÃÇ¿ìËÙ½âÎöÒ»ÏÂÕâЩǿ´óµÄÐÂhints:
spread_min_analysis
ʹÓÃÕâÒ»hint£¬Äã¿ÉÒÔºöÂÔһЩ¹ØÓÚÈçÏêϸµÄ¹ØϵÒÀÀµÍ¼·ÖÎöµÈµç×Ó±í¸ñµÄ±àÒëʱ¼äÓÅ»¯¹æÔò¡£ÆäËûµÄһЩÓÅ»¯£¬Èç´´½¨¹ýÂËÒÔÓÐÑ¡ÔñÐԵĶ¨Î»µç×Ó±í¸ñ·ÃÎʽṹ²¢ÏÞÖÆÐÞ¶©¹æÔòµÈ£¬µÃµ½Á˼ÌÐøʹÓá£
ÓÉÓÚÔÚ¹æÔòÊý·Ç³£´óµÄÇé¿öÏ£¬µç×Ó±í¸ñ·ÖÎö»áºÜ³¤¡£ÕâÒ»Ìáʾ¿ÉÒÔ°ïÖúÎÒÃǼõÉÙÓɴ˲úÉúµÄÊýÒÔ°ÙСʱ¼ÆµÄ±àÒëʱ¼ä¡£
Àý:
SELECT /*+ SPREAD_MIN_ANALYSIS */ ...
spread_no_analysis
ͨ¹ýÕâÒ»hint£¬¿ÉÒÔʹÎÞµç×Ó±í¸ñ·ÖÎö³ÉΪ¿ÉÄÜ¡£Í¬Ñù£¬Ê¹ÓÃÕâÒ»hint¿ÉÒÔºöÂÔÐÞ¶©¹æÔòºÍ¹ýÂ˲úÉú¡£Èç¹û´æÔÚÒ»µç×Ó±í¸ñ·ÖÎö£¬±àÒëʱ¼ä¿ÉÒÔ±»¼õÉÙµ½×îµÍ³Ì¶È¡£
Àý:
SELECT /*+ SPREAD_NO_ANALYSIS */ ...
use_nl_with_index
ÕâÏîhintʹCBOͨ¹ýǶÌ×Ñ»·°ÑÌض¨µÄ±í¸ñ¼ÓÈëµ½ÁíÒ»ÔʼÐС£Ö»ÓÐÔÚÒÔÏÂÇé¿ö
ÖУ¬Ëü²ÅʹÓÃÌض¨±í¸ñ×÷ΪÄÚ²¿±í¸ñ:Èç¹ûûÓÐÖ¸¶¨±êÇ©£¬CBO±ØÐë¿ÉÒÔʹÓÃһЩ±êÇ©£¬ÇÒÕâЩ±êÇ©ÖÁÉÙÓÐÒ»¸ö×÷ΪË÷Òý¼üÖµ¼ÓÈëÅжÏ;·´Ö®£¬CBO±ØÐëÄܹ»Ê¹
ÓÃÖÁÉÙÓÐÒ»¸ö×÷ΪË÷Òý¼üÖµ¼ÓÈëÅжϵıêÇ©¡£
Àý:
SELECT /*+ USE_NL_WITH_INDEX (polrecpolrind) */ ...
CARDINALITY
´Ëhint¶¨ÒåÁ˶ÔÓɲéѯ»ò²éѯ²¿·Ö·µ»ØµÄ»ùÊýµÄÆÀ¼Û¡£×¢ÒâÈç¹ûûÓж¨Òå±í¸ñ£¬»ùÊýÊÇÓÉÕû¸ö²éѯËù·µ»ØµÄ×ÜÐÐÊý¡£
Àý:
SELECT /*+ CARDINALITY ( [tablespec] card ) */
SELECTIVITY
´Ëhint¶¨ÒåÁ˶Բéѯ»ò²éѯ²¿·ÖÑ¡ÔñÐÔµÄÆÀ¼Û¡£Èç¹ûÖ»¶¨ÒåÁËÒ»¸ö±í¸ñ£¬Ñ¡ÔñÐÔÊÇÔÚËù¶¨Òå±í¸ñÀïÂú×ãËùÓе¥Ò»±í¸ñÅжϵÄÐв¿·Ö¡£Èç¹û¶¨ÒåÁËһϵÁбí¸ñ£¬Ñ¡ÔñÐÔÊÇÖ¸Ôںϲ¢ÒÔÈκÎ˳ÐòÂú×ãËùÓпÉÓÃÅжϵÄÈ«²¿±í¸ñºó£¬ËùµÃ½á¹ûÖеÄÐв¿·Ö¡£
Àý:
SELECT /*+ SELECTIVITY ( [tablespec] sel ) */
È»¶ø£¬×¢ÒâÈç¹ûhints CARDINALITY ºÍ SELECTIVITY¶¼¶¨ÒåÔÚͬÑùµÄÒ»Åú±í¸ñ£¬¶þÕ߶¼»á±»ºöÂÔ¡£
no_use_nl
Hint no_use_nlʹCBOÖ´ÐÐÑ»·Ç¶Ì×£¬Í¨¹ý°ÑÖ¸¶¨±í¸ñ×÷ΪÄÚ²¿±í¸ñ£¬°Ñÿ¸öÖ¸¶¨±í¸ñÁ¬½Óµ½ÁíÒ»ÔʼÐС£Í¨¹ýÕâÒ»hint£¬Ö»ÓÐhash joinºÍsort-merge joins»áΪָ¶¨±í¸ñËù¿¼ÂÇ¡£
Àý:
SELECT /*+ NO_USE_NL ( employees ) */ ...
no_use_merge
´ËhintʹCBOͨ¹ý°ÑÖ¸¶¨±í¸ñ×÷ΪÄÚ²¿±í¸ñµÄ·½Ê½£¬¾Ü¾øsort-merge°Ñÿ¸öÖ¸¶¨±í¸ñ¼ÓÈëµ½ÁíÒ»ÔʼÐС£
Àý:
SELECT /*+ NO_USE_MERGE ( em
Ïà¹ØÎĵµ£º
1.¸ü¸Ä¹éµµÂ·¾¶
ÔÚORACLE10GÖУ¬Ä¬ÈϵĹ鵵·¾¶Îª$ORACLE_BASE/flash_recovery_area¡£¶ÔÓÚÕâ¸ö·¾¶£¬
ORACLEÓÐÒ»¸öÏÞÖÆ£¬¾ÍÊÇĬÈÏÖ»ÄÜÓÐ2GµÄ¿Õ¼ä¸ø¹éµµÈÕ־ʹÓ㬿ÉÒÔʹÓÃÏÂÃæÁ½¸öSQLÓï¾äÈ¥²é¿´ËüµÄÏÞÖÆ
1. select * from v$recovery_file_dest;
sql >show parameter db_recovery_file_dest(Õâ¸ö¸üÓѺÃÖ±¹ÛһЩ)
µ± ......
˵µ½Èí½âÎö£¨soft prase£©ºÍÓ²½âÎö£¨hard prase£©£¬¾Í²»Äܲ»ËµÒ»ÏÂOracle¶ÔsqlµÄ´¦Àí¹ý³Ì¡£µ±Äã·¢³öÒ»ÌõsqlÓï¾ä½»¸¶Oracle£¬ÔÚÖ´ÐкͻñÈ¡½á¹ûÇ°£¬Oracle¶Ô´Ësql½«½øÐм¸¸ö²½ÖèµÄ´¦Àí¹ý³Ì£º
1¡¢Óï·¨¼ì²é£¨syntax check£©
¼ì²é´ËsqlµÄƴдÊÇ·ñÓï ......
declare
begin
--SQLÓï¾ä
--Ö±½ÓдµÄSQLÓï¾ä(DML/TCL)
--¼ä½Óдexecute immediate <DDL/DCLÃüÁî×Ö·û´®>
--select Óï¾ä
<1>±ØÐë´øÓÐinto×Ó¾ä
&n ......
ÓкܶàÓ¦ÓÃÏîÄ¿, ¸ÕÆð²½µÄʱºòÓÃMYSQLÊý¾Ý¿â»ù±¾ÉÏÄÜʵÏÖ¸÷ÖÖ¹¦ÄÜÐèÇó£¬Ëæ×ÅÓ¦ÓÃÓû§µÄÔö¶à£¬Êý¾ÝÁ¿µÄÔö¼Ó£¬MYSQL½¥½¥µØ³öÏÖ²»¿°ÖظºµÄÇé¿ö£ºÁ¬½ÓºÜÂýÉõÖÁå´»ú£¬ÓÚÊǾÍÓаÑÊý¾Ý´ÓMYSQLǨµ½ORACLEµÄÐèÇó£¬Ó¦ÓóÌÐòÒ²ÒªÏàÓ¦×öһЩÐ޸ġ£±¾ÈË×ܽá³öÒÔϼ¸µã×¢ÒâÊÂÏϣÍû¶Ô´ó¼ÒÓÐËù°ïÖú¡£
1£® ×Ô¶¯Ôö³¤µÄÊý¾ ......
oracleÖÐconnect by priorʵÏֵݹé²éѯ
ÊÕ¼¯µÄ¼¸ÌõÔÚoracleÖÐͨ¹ýconnect by priorÀ´ÊµÏֵݹé²éѯ
Start with...Connect By×Ó¾äµÝ¹é²éѯһ°ãÓÃÓÚÒ»¸ö±íά»¤Ê÷ÐνṹµÄÓ¦Óá£
´´½¨Ê¾Àý±í£º
CREATE TABLE TBL_TEST
(
ID NUMBER,
NAME VARCHAR2(100 BYTE),
PID NUMBER &nbs ......