?? oracle sql性能優(yōu)化系列 (十一)--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性能優(yōu)化系列 (十一)</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>網(wǎng)絡</FONT></TD>
</TR>
<TR>
<TD height=15></TD>
</TR>
<TR>
<TD class=l17><FONT class=f14 id=zoom><BR>36. 用UNION替換OR (適用于索引列)<BR><BR>通常情況下, 用UNION替換WHERE子句中的OR將會起到較好的效果. 對索引列使用OR將造成全表掃描. 注意, 以上規(guī)則只針對多個索引列有效. 如果有column沒有被索引, 查詢效率可能會因為你沒有選擇OR而降低. <BR><BR> 在下面的例子中, LOC_ID 和REGION上都建有索引.<BR><BR>高效:<BR><BR> SELECT LOC_ID , LOC_DESC , REGION<BR><BR> FROM LOCATION<BR><BR> WHERE LOC_ID = 10<BR><BR> UNION<BR><BR> SELECT LOC_ID , LOC_DESC , REGION<BR><BR> FROM LOCATION<BR><BR> WHERE REGION = “MELBOURNE”<BR><BR> <BR><BR>低效:<BR><BR> SELECT LOC_ID , LOC_DESC , REGION<BR><BR> FROM LOCATION<BR><BR> WHERE LOC_ID = 10 OR REGION = “MELBOURNE”<BR><BR> <BR><BR>如果你堅持要用OR, 那就需要返回記錄最少的索引列寫在最前面.<BR><BR> <BR><BR>注意:<BR><BR> <BR><BR>WHERE KEY1 = 10 (返回最少記錄)<BR><BR>OR KEY2 = 20 (返回最多記錄)<BR><BR> <BR><BR>ORACLE 內(nèi)部將以上轉(zhuǎn)換為<BR><BR>WHERE KEY1 = 10 AND<BR><BR>((NOT KEY1 = 10) AND KEY2 = 20) <BR><BR> <BR><BR>譯者按: <BR><BR> <BR><BR>下面的測試數(shù)據(jù)僅供參考: (a = 1003 返回一條記錄 , b = 1 返回1003條記錄)<BR><BR>SQL> select * from unionvsor /*1st test*/<BR><BR> 2 where a = 1003 or b = 1;<BR><BR>1003 rows selected.<BR><BR>Execution Plan<BR><BR>----------------------------------------------------------<BR><BR> 0 SELECT STATEMENT Optimizer=CHOOSE<BR><BR> 1 0 CONCATENATION<BR><BR> 2 1 TABLE ACCESS (BY INDEX ROWID) OF 'UNIONVSOR'<BR><BR> 3 2 INDEX (RANGE SCAN) OF 'UB' (NON-UNIQUE)<BR><BR> 4 1 TABLE ACCESS (BY INDEX ROWID) OF 'UNIONVSOR'<BR><BR> 5 4 INDEX (RANGE SCAN) OF 'UA' (NON-UNIQUE)<BR><BR>Statistics<BR><BR>----------------------------------------------------------<BR><BR> 0 recursive calls<BR><BR> 0 db block gets<BR><BR> 144 consistent gets<BR><BR> 0 physical reads<BR><BR> 0 redo size<BR><BR> 63749 bytes sent via SQL*Net to client<BR><BR> 7751 bytes received via SQL*Net from client<BR><BR> 68 SQL*Net roundtrips to/from client<BR><BR> 0 sorts (memory)<BR><BR> 0 sorts (disk)<BR><BR> 1003 rows processed<BR><BR>SQL> select * from unionvsor /*2nd test*/<BR><BR> 2 where b = 1 or a = 1003 ; <BR><BR>1003 rows selected.<BR><BR>Execution Plan<BR><BR>----------------------------------------------------------<BR><BR> 0 SELECT STATEMENT Optimizer=CHOOSE<BR><BR> 1 0 CONCATENATION<p><div align="right">本新聞共<font color=red>3</font>頁,當前在第<font color=red>1</font>頁 <font color="red">1</font> <a href="164559059816455975203_2.shtml">2</a> <a href="164559059816455975203_3.shtml">3</a> </div></p>
<P clear=all></P>
</FONT></TD>
</TR>
</TBODY>
</TABLE>
</DIV>
<BR>
上一篇:<a href='../../2005-4/29/164559059816455954036.shtml' title ='ORACLE常用傻瓜問題1000問(之五)'>ORACLE常用傻瓜問題1000問(之五)</a> 下一篇:<a href='../../2005-4/29/164559059816455980543.shtml' title ='ORACLE SQL性能優(yōu)化系列 (十二)'>ORACLE SQL性能優(yōu)化系列 (十二)</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=059816455975203\" target=\"_blank\">發(fā)送給好友</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=8994\" 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/16455905981645592205.shtml title="ORACLE SQL性能優(yōu)化系列 (十三)">ORACLE SQL性能優(yōu)化系列 (十三)</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/164558059816455832996.shtml title="ORACLE SQL性能優(yōu)化系列 (四)">ORACLE SQL性能優(yōu)化系列 (四)</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/164558059816455832253.shtml title="ORACLE SQL性能優(yōu)化系列 (八)">ORACLE SQL性能優(yōu)化系列 (八)</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/164559059816455944859.shtml title="ORACLE SQL性能優(yōu)化系列 (十)">ORACLE SQL性能優(yōu)化系列 (十)</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性能優(yōu)化系列 (二)">ORACLE SQL性能優(yōu)化系列 (二)</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/164558059816455831878.shtml title="ORACLE SQL性能優(yōu)化系列 (五)">ORACLE SQL性能優(yōu)化系列 (五)</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性能優(yōu)化系列 (一)">ORACLE SQL性能優(yōu)化系列 (一)</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性能優(yōu)化系列 (三)">ORACLE SQL性能優(yōu)化系列 (三)</a></td></tr>
<tr>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -