Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Oracle 10g SQL ÓÅ»¯ÔÙѧϰ

´Ó8iµ½10g£¬Oracle²»¶Ï½ø»¯×Ô¼ºµÄSQL TuningÖÇÄÜ£¬Ò»Ð©Ãؼ®¼¶µÄÓÅ»¯¿Ú¾÷ÒѾ­Ê§Ð§¡£
   µ«ÎÒϲ»¶Ê§Ð§£¬²»Óüǿھ÷£¬²Ù¸öToad for Oracle Xpert
 £¬°´ÕÕ´ó·½ÏòÊæÊæ·þ·þµÄ
µ÷ÓŲÅÊÇ°®×öµÄÊÂÇé¡£
1.Excution Plan
     Excution
PlanÊÇ×î»ù±¾µÄµ÷ÓŸÅÄ²»¹ÜÄãµÄµ÷ÓÅ´µµÃÈçºÎÌ컨ÂҶ飬½á¹û»¹ÊÇÒªÓÉExcution planÀ´ÏÔʾOracle
×îÖÕÓÃʲôË÷Òý¡¢°´Ê²Ã´Ë³ÐòÁ¬½Ó¸÷±í£¬Full Table Scan»¹ÊÇAccess by Rowid
Index£¬Æ¿¾±ÔÚʲôµØ·½¡£Èç¹ûûÓÐËüµÄÖ¸µ¼£¬Ò»Çе÷ÓŶ¼ÊÇÃɵġ£
2.Toad for Oracle
Xpert
    ÓÃËüÀ´µ÷ÓÅÔÚÕæµÄºÃÊæ·þ¡£Quest
ÍÌ
²¢ÁËLeccoºó£¬½«ËüÕûºÏµ½ÁËToad µÄSQL
TunningÀïÃ棺×îÇåÎúµÄÖ´Ðмƻ®ÏÔʾ£¬×Ô¶¯Éú³ÉNÌõµÈ¼ÛSQL¡¢¸ø³öÓÅ»¯½¨Ò飬²»Í¬SQLÖ´Ðмƻ®µÄ¶Ô±È£¬»¹ÓÐʵ¼ÊÖ´ÐеÄÂß¼­¶Á¡¢ÎïÀí¶ÁÊý¾ÝµÈµÈÒ»
Ä¿ÁËÈ»¡£
3.Ë÷Òý
   ´ó²¿·ÖµÄÐÔÄÜÎÊÌâÆäʵ¶¼ÊÇË÷ÒýÓ¦ÓõÄÎÊÌ⣬Where×Ӿ䡢
Order By¡¢Group By ¶¼ÒªÓõ½Ë÷Òý¡£
   Ò»°ã¿ª·¢ÈËÔ±ÈÏΪ½«Ë÷Òý½¨È«Á˾ͿÉÒÔÏ°à»Ø¼ÒÁË£¬ÊµÔò»¹ÓÐÆĶàµÄ˼Á¿ºÍÏÝÚå¡£
3.1
Ë÷ÒýÁÐÉϲ»Òª½øÐмÆËã
      ÕâÊÇ×î×îÆÕ±éµÄʧЧÏÝÚ壬±ÈÈçwhere
trunc(order_date)=trunc(sysdate),
i+2>4¡£Ë÷ÒýʧЧµÄÔ­ÒòÒ²¼òµ¥£¬Ë÷ÒýÊÇÕë¶ÔÔ­Öµ½¨µÄ¶þ²æÊ÷£¬Ä㽫ÁÐÖµ*3/4+2ÕÛÌÚÒ»·¬ºó£¬Ô­À´µÄ¶þ²æÊ÷µ±È»¾ÍÓò»ÉÏÁË¡£½â¾öµÄ·½·¨:
¡¡
1.¡¡»»³ÉµÈ¼ÛÓï·¨£¬±ÈÈçtrunc(order_date) »»³É
where order_date
>
trunc(sysdate)
-
1
 
and
 order_date
<
trunc(sysdate)
+
1
¡¡ 2.    ÌرðΪ¼ÆË㽨Á¢º¯ÊýË÷Òý
create
 
index
 £É_XXXX 
on
 shop_order(trunc(order_date))
    3.    ½«¼ÆËã´ÓµÈºÅ×ó±ßÒƵ½ÓÒ±ß
¡¡ÕâÊÇÕë¶ÔijЩÎÞÐÄ֮ʧµÄ¾ÀÕý£¬°Ña*2>4¡¡¸ÄΪa>4/2£»°Ñ
TO_CHAR(zip) = '94002' ¸ÄΪzip = TO_NUMBER('94002');
3.2
CBOÓëË÷ÒýÑ¡ÔñÐÔ
     ½¨ÁËË÷ÒýÒ²²»Ò»¶¨»á±»OracleÓõģ¬¾ÍÏñ¸öÌôʳµÄº¢×Ó¡£»ùÓڳɱ¾µÄÓÅ»¯Æ÷(CBO,
Cost-Based Optimizer)£¬»áÏÈ¿´¿´±íµÄ´óС£¬»¹ÓÐË÷ÒýµÄÖظ´¶È£¬ÔÙ¾ö¶¨Óû¹ÊDz»ÓᣱíÖÐÓÐ100 Ìõ¼Ç¼¶øÆäÖÐÓÐ80
¸ö²»Öظ´µÄË÷Òý¼üÖµ. Õâ¸öË÷ÒýµÄÑ¡ÔñÐÔ¾ÍÊÇ80/100 =
0.8£¬ÁôÒâToadÀïÏÔʾË÷ÒýµÄSelectiveº


Ïà¹ØÎĵµ£º

ÄÚÁª SQL PL(Inline SQL PL)

----start
    Í¨³£SQL PLÖ»ÄÜʹÓÃÔÚ´æ´¢¹ý³Ì¡¢´¥·¢Æ÷¡¢Óû§×Ô¶¨Ò庯ÊýÖУ¬µ«ÊÇÓÐÒ»²¿·ÖSQL PLÒ²¿ÉÒÔÖ±½ÓÔÚÃüÁîÐб༭Æ÷»ò½Å±¾ÖÐʹÓã¬ËüÃÇÊÇ£º
DECLARE <variable>
SET
CASE
FOR
GET DIAGNOSTICS
GOTO
IF
RETURN
SIGNAL
WHILE
ITERATE
LEAVE 
ÒÔÏÂSQL PL²»ÄÜÖ±½ÓÔÚÃüÁîÐб༭Æ÷»ò ......

SQLµÄÈýÖÖ·ÖÒ³·½·¨

±íÖÐÖ÷¼ü±ØÐëΪ±êʶÁУ¬[ID] int IDENTITY (1,1)
1.·ÖÒ³·½°¸Ò»£º(ÀûÓÃNot InºÍSELECT TOP·ÖÒ³)
Óï¾äÐÎʽ£º 
SELECT TOP Ò³¼Ç¼ÊýÁ¿ *
from ±íÃû
WHERE (ID NOT IN
  (SELECT TOP (ÿҳÐÐÊý*(Ò³Êý-1)) ID
  from ±íÃû
  ORDER BY ID))
  ORDER BY ID
//×Ô¼º»¹¿ÉÒÔ¼ÓÉÏһЩ²éѯ ......

JSPʵÏÖ¼òÒ×µÄSQL±¨±í

ÊäÈë: select ID as ±àºÅ, NAME as ÐÕÃû, AGE as ÄêÁä from XXX
Êä³ö:
񅧏
ÐÕÃû
ÄêÁä
 
 
 
ÒªÇóÊÇÈç¹ûSQL±ä¶¯, ÈÔȻҪÏÔʾ³öÀ´ËùÓеıðÃû×Ö¶ÎÐÅÏ¢ºÍÊý¾Ý.
ÒòΪÏÖÔÚHibernateÓõıȽϹ㷺, ËùÒÔÓÅÏÈ¿¼ÂÇÓÃHibernateÀ´ÊµÏÖ, ½á¹û·¢ÏÖÈç¹ûÊÇʵÌåÓ³Éä²éѯÓï¾ä, ¿ÉÒÔ·½±ãµÄÓÃ:List<String> Quer ......

OracleÖÐÓÅ»¯SQLµÄÔ­Ôò

.Frm644 { display:none; }
¡¡¡¡1¡£ÒѾ­¼ìÑéµÄÓï¾äºÍÒÑÔÚ¹²Ïí³ØÖеÄÓï¾äÖ®¼äÒªÍêÈ«Ò»Ñù
¡¡¡¡2¡£±äÁ¿Ãû³Æ¾¡Á¿Ò»ÖÂ
¡¡¡¡3¡£ºÏÀíʹÓÃÍâÁª½Ó
¡¡¡¡4¡£ÉÙ
Óöà²ãǶÌ×
¡¡¡¡5¡£¶àÓò¢·¢
¡¡¡¡
¡¡¡¡Óï¾äµÄÓÅ»¯²½ÖèÒ»°ãÓУº
¡¡¡¡1¡£µ÷ÕûsgaÇø£¬Ê¹µÃsgaÇøµÄÊÇÓÃ×îÓÅ¡£
¡¡
¡¡2¡£sqlÓï¾ä±¾ÉíµÄÓÅ»¯£¬¹¤¾ßÓÐexplain,sql trace ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ