?? oracle sql性能優化系列 (五)--acnow_net.htm
字號:
<DIV id=article>
<TABLE cellSpacing=0 cellPadding=0 width=540 border=0 style="TABLE-LAYOUT: fixed">
<TBODY>
<TR>
<TH class=f24><FONT color=#05006c>
<H1>ORACLE SQL性能優化系列 (五)</H1>
</FONT></TH>
</TR>
<TR>
<TD> <HR SIZE=1 bgcolor="#d9d9d9"> </TD>
</TR>
<TR>
<TD align=middle height=20>http://Tech.acnow.net 2005-4-29 <FONT color=#a20010>網絡</FONT></TD>
</TR>
<TR>
<TD height=15></TD>
</TR>
<TR>
<TD class=l17><FONT class=f14 id=zoom><BR>17. 使用表的別名(Alias)<BR><BR>當在SQL語句中連接多個表時, 請使用表的別名并把別名前綴于每個Column上.這樣一來,就可以減少解析的時間并減少那些由Column歧義引起的語法錯誤.<BR><BR> <BR><BR>(譯者注: Column歧義指的是由于SQL中不同的表具有相同的Column名,當SQL語句中出現這個Column時,SQL解析器無法判斷這個Column的歸屬)<BR><BR> <BR><BR>18. 用EXISTS替代IN<BR><BR>在許多基于基礎表的查詢中,為了滿足一個條件,往往需要對另一個表進行聯接.在這種情況下, 使用EXISTS(或NOT EXISTS)通常將提高查詢的效率.<BR><BR> <BR><BR>低效:<BR><BR>SELECT * <BR><BR>FROM EMP (基礎表)<BR><BR>WHERE EMPNO > 0<BR><BR>AND DEPTNO IN (SELECT DEPTNO <BR><BR>FROM DEPT <BR><BR>WHERE LOC = ‘MELB’)<BR><BR> <BR><BR>高效:<BR><BR>SELECT * <BR><BR>FROM EMP (基礎表)<BR><BR>WHERE EMPNO > 0<BR><BR>AND EXISTS (SELECT ‘X’ <BR><BR>FROM DEPT <BR><BR>WHERE DEPT.DEPTNO = EMP.DEPTNO<BR><BR>AND LOC = ‘MELB’)<BR><BR> <BR><BR> <BR><BR> (譯者按: 相對來說,用NOT EXISTS替換NOT IN 將更顯著地提高效率,下一節中將指出)<BR><BR> <BR><BR> <BR><BR>19. 用NOT EXISTS替代NOT IN<BR><BR>在子查詢中,NOT IN子句將執行一個內部的排序和合并. 無論在哪種情況下,NOT IN都是最低效的 (因為它對子查詢中的表執行了一個全表遍歷). 為了避免使用NOT IN ,我們可以把它改寫成外連接(Outer Joins)或NOT EXISTS.<BR><BR> <BR><BR>例如:<BR><BR>SELECT …<BR><BR>FROM EMP<BR><BR>WHERE DEPT_NO NOT IN (SELECT DEPT_NO <BR><BR> FROM DEPT <BR><BR> WHERE DEPT_CAT=’A’);<BR><BR> <BR><BR>為了提高效率.改寫為:<BR><BR> <BR><BR>(方法一: 高效)<BR><BR>SELECT ….<BR><BR>FROM EMP A,DEPT B<BR><BR>WHERE A.DEPT_NO = B.DEPT(+)<BR><BR>AND B.DEPT_NO IS NULL<BR><BR>AND B.DEPT_CAT(+) = ‘A’<BR><BR> <BR><BR> <BR><BR>(方法二: 最高效)<BR><BR>SELECT ….<BR><BR>FROM EMP E<BR><BR>WHERE NOT EXISTS (SELECT ‘X’ <BR><BR> FROM DEPT D<BR><BR> WHERE D.DEPT_NO = E.DEPT_NO<BR><BR> AND DEPT_CAT = ‘A’);<BR><BR> <BR><BR>(待續)<BR>
<P clear=all></P>
</FONT></TD>
</TR>
</TBODY>
</TABLE>
</DIV>
<BR>
上一篇:<a href='../../2005-4/29/164558059816455832996.shtml' title ='ORACLE SQL性能優化系列 (四)'>ORACLE SQL性能優化系列 (四)</a> 下一篇:<a href='../../2005-4/29/164558059816455824401.shtml' title ='如何在ORACLE中實現人民幣大寫的轉換'>如何在ORACLE中實現人民幣大寫的轉換</a>
<BR>
<BR>
<TABLE class="tf" cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD style="PADDING-RIGHT: 20px" align=right>
【<script type="text/javascript">
<!--
document.write("<a href=\"http:\/\/tech.acnow.net\/Sendmail.asp?NewsID=059816455831878\" target=\"_blank\">發送給好友</a>");
-->
</script>】
【<A href="http://bbs.acnow.net/Index.asp?boardid=103">論壇</A>】
【<script type="text/javascript">
<!--
document.write("<a target=\"_blank\" Href=\"http:\/\/tech.acnow.net\/Users\/AddFavorite.asp?NewsID=8965\" style=\"CURSOR:hand\" onClick=\"window.external.AddFavorite(document.location.href,document.title)\" onMouseMove=\"status='收藏本頁';\" onMouseOut=\"status='';\">添加到收藏夾</a>");
-->
</script>】
【<A target="_self" href="javascript:doZoom(16)">大</A>
<A target="_self" href="javascript:doZoom(14)">中</A>
<A target="_self" href="javascript:doZoom(12)">小</A>】
【<A target="_self" href="javascript:doPrint()">打印</A>】
【<A target="_self" href="javascript:window.close()">關閉</A>】</TD>
</TR>
</TBODY>
</TABLE>
<TABLE cellSpacing=0 cellPadding=0 width=545 border=0>
<TBODY>
<TR>
<TD height=19></TD>
</TR>
<TR>
<TD bgColor=#c6c9d1 height=1></TD>
</TR>
<TR>
<TD height=10></TD>
</TR>
</TBODY>
</TABLE>
<BR>
<DIV id=links>
<TABLE cellSpacing=0 cellPadding=0 width=542 border=0>
<TBODY>
<TR>
<TD><table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td><img src="http://tech.acnow.net/Files/Img/list_nav_spacer.gif"><a Class="a2" href= http://tech.acnow.net/Html/DataBase/Oracle/2005-4/29/164558059816455832253.shtml title="ORACLE SQL性能優化系列 (八)">ORACLE SQL性能優化系列 (八)</a></td></tr>
<tr>
<td Height=1 colspan="1">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td Height=1 background="http://tech.acnow.net/Files/Img/title_line.gif">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td><img src="http://tech.acnow.net/Files/Img/list_nav_spacer.gif"><a Class="a2" href= http://tech.acnow.net/Html/DataBase/Oracle/2005-4/29/164559059816455980543.shtml title="ORACLE SQL性能優化系列 (十二)">ORACLE SQL性能優化系列 (十二)</a></td></tr>
<tr>
<td Height=1 colspan="1">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td Height=1 background="http://tech.acnow.net/Files/Img/title_line.gif">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td><img src="http://tech.acnow.net/Files/Img/list_nav_spacer.gif"><a Class="a2" href= http://tech.acnow.net/Html/DataBase/Oracle/2005-4/29/164558059816455810544.shtml title="ORACLE SQL性能優化系列 (一)">ORACLE SQL性能優化系列 (一)</a></td></tr>
<tr>
<td Height=1 colspan="1">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td Height=1 background="http://tech.acnow.net/Files/Img/title_line.gif">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td><img src="http://tech.acnow.net/Files/Img/list_nav_spacer.gif"><a Class="a2" href= http://tech.acnow.net/Html/DataBase/Oracle/2005-4/29/16455905981645592205.shtml title="ORACLE SQL性能優化系列 (十三)">ORACLE SQL性能優化系列 (十三)</a></td></tr>
<tr>
<td Height=1 colspan="1">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td Height=1 background="http://tech.acnow.net/Files/Img/title_line.gif">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td><img src="http://tech.acnow.net/Files/Img/list_nav_spacer.gif"><a Class="a2" href= http://tech.acnow.net/Html/DataBase/Oracle/2005-4/29/164558059816455894796.shtml title="ORACLE SQL性能優化系列 (三)">ORACLE SQL性能優化系列 (三)</a></td></tr>
<tr>
<td Height=1 colspan="1">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td Height=1 background="http://tech.acnow.net/Files/Img/title_line.gif">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td><img src="http://tech.acnow.net/Files/Img/list_nav_spacer.gif"><a Class="a2" href= http://tech.acnow.net/Html/DataBase/Oracle/2005-4/29/164558059816455862139.shtml title="ORACLE SQL性能優化系列 (二)">ORACLE SQL性能優化系列 (二)</a></td></tr>
<tr>
<td Height=1 colspan="1">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td Height=1 background="http://tech.acnow.net/Files/Img/title_line.gif">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td><img src="http://tech.acnow.net/Files/Img/list_nav_spacer.gif"><a Class="a2" href= http://tech.acnow.net/Html/DataBase/Oracle/2005-4/29/164558059816455833067.shtml title="ORACLE SQL性能優化系列 (七)">ORACLE SQL性能優化系列 (七)</a></td></tr>
<tr>
<td Height=1 colspan="1">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td Height=1 background="http://tech.acnow.net/Files/Img/title_line.gif">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td><img src="http://tech.acnow.net/Files/Img/list_nav_spacer.gif"><a Class="a2" href= http://tech.acnow.net/html/SoftWare/SoftwareEducate/OracleAuthentication/2006-5/29/150826355.shtml title="ORACLE SQL性能優化系列 (一)">ORACLE SQL性能優化系列 (一)</a></td></tr>
<tr>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -