📄 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>39. 总是使用索引的第一个列<BR><BR>如果索引是建立在多个列上, 只有在它的第一个列(leading column)被where子句引用时,优化器才会选择使用该索引. <BR><BR> <BR><BR>译者按:<BR><BR>这也是一条简单而重要的规则. 见以下实例.<BR><BR> <BR><BR>SQL> create table multiindexusage ( inda number , indb number , descr varchar2(10));<BR><BR>Table created.<BR><BR>SQL> create index multindex on multiindexusage(inda,indb);<BR><BR>Index created.<BR><BR>SQL> set autotrace traceonly<BR><BR> <BR><BR>SQL> select * from multiindexusage where inda = 1;<BR><BR>Execution Plan<BR><BR>----------------------------------------------------------<BR><BR> 0 SELECT STATEMENT Optimizer=CHOOSE<BR><BR> 1 0 TABLE ACCESS (BY INDEX ROWID) OF 'MULTIINDEXUSAGE'<BR><BR> 2 1 INDEX (RANGE SCAN) OF 'MULTINDEX' (NON-UNIQUE)<BR><BR> <BR><BR>SQL> select * from multiindexusage where indb = 1;<BR><BR>Execution Plan<BR><BR>----------------------------------------------------------<BR><BR> 0 SELECT STATEMENT Optimizer=CHOOSE<BR><BR> 1 0 TABLE ACCESS (FULL) OF 'MULTIINDEXUSAGE'<BR><BR> <BR><BR>很明显, 当仅引用索引的第二个列时,优化器使用了全表扫描而忽略了索引<BR><BR> <BR><BR> <BR><BR>40. ORACLE内部操作<BR><BR>当执行查询时,ORACLE采用了内部的操作. 下表显示了几种重要的内部操作.<BR><BR>ORACLE Clause<BR><BR>内部操作<BR><BR>ORDER BY<BR><BR>SORT ORDER BY<BR><BR>UNION<BR><BR>UNION-ALL<BR><BR>MINUS<BR><BR>MINUS<BR><BR>INTERSECT<BR><BR>INTERSECT<BR><BR>DISTINCT,MINUS,INTERSECT,UNION<BR><BR>SORT UNIQUE<BR><BR>MIN,MAX,COUNT<BR><BR>SORT AGGREGATE<BR><BR>GROUP BY<BR><BR>SORT GROUP BY<BR><BR>ROWNUM<BR><BR>COUNT or COUNT STOPKEY<BR><BR>Queries involving Joins<BR><BR>SORT JOIN,MERGE JOIN,NESTED LOOPS<BR><BR>CONNECT BY<BR><BR>CONNECT BY<BR><BR> <BR><BR> <BR><BR>41. 用UNION-ALL 替换UNION ( 如果有可能的话)<BR><BR> <BR><BR>当SQL语句需要UNION两个查询结果集合时,这两个结果集合会以UNION-ALL的方式被合并, 然后在输出最终结果前进行排序.<BR><BR>如果用UNION ALL替代UNION, 这样排序就不是必要了. 效率就会因此得到提高.<BR><BR> <BR><BR>举例:<BR><BR> 低效:<BR><BR> SELECT ACCT_NUM, BALANCE_AMT<BR><BR> FROM DEBIT_TRANSACTIONS<BR><BR> WHERE TRAN_DATE = ’31-DEC-95’<BR><BR> UNION<BR><BR> SELECT ACCT_NUM, BALANCE_AMT<BR><BR> FROM DEBIT_TRANSACTIONS<BR><BR> WHERE TRAN_DATE = ’31-DEC-95’<BR><BR>高效:<BR><BR> SELECT ACCT_NUM, BALANCE_AMT<BR><BR> FROM DEBIT_TRANSACTIONS<BR><BR> WHERE TRAN_DATE = ’31-DEC-95’<BR><BR> UNION ALL<BR><BR> SELECT ACCT_NUM, BALANCE_AMT<BR><BR> FROM DEBIT_TRANSACTIONS<BR><BR> WHERE TRAN_DATE = ’31-DEC-95’<BR><BR> <BR><BR>译者按:<BR><BR>需要注意的是,UNION ALL 将重复输出两个结果集合中相同记录. 因此各位还是<BR><BR>要从业务需求分析使用UNION ALL的可行性.<BR><BR>UNION 将对结果集合排序,这个操作会使用到SORT_AREA_SIZE这块内存. 对于这<p><div align="right">本新闻共<font color=red>2</font>页,当前在第<font color=red>1</font>页 <font color="red">1</font> <a href="164559059816455980543_2.shtml">2</a> </div></p>
<P clear=all></P>
</FONT></TD>
</TR>
</TBODY>
</TABLE>
</DIV>
<BR>
上一篇:<a href='../../2005-4/29/164559059816455975203.shtml' title ='ORACLE SQL性能优化系列 (十一)'>ORACLE SQL性能优化系列 (十一)</a> 下一篇:<a href='../../2005-4/29/16455905981645592205.shtml' title ='ORACLE SQL性能优化系列 (十三)'>ORACLE SQL性能优化系列 (十三)</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=059816455980543\" 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=8995\" 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/164559059816455975203.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/164558059816455832996.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/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/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/164558059816455850688.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/164559059816455944859.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 + -