📄 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>20. 用表连接替换EXISTS<BR><BR> <BR><BR> 通常来说 , 采用表连接的方式比EXISTS更有效率<BR><BR> SELECT ENAME<BR><BR> FROM EMP E<BR><BR> WHERE EXISTS (SELECT ‘X’ <BR><BR> FROM DEPT<BR><BR> WHERE DEPT_NO = E.DEPT_NO<BR><BR> AND DEPT_CAT = ‘A’);<BR><BR> <BR><BR> (更高效)<BR><BR> SELECT ENAME<BR><BR> FROM DEPT D,EMP E<BR><BR> WHERE E.DEPT_NO = D.DEPT_NO<BR><BR> AND DEPT_CAT = ‘A’ ;<BR><BR> <BR><BR>(译者按: 在RBO的情况下,前者的执行路径包括FILTER,后者使用NESTED LOOP)<BR><BR> <BR><BR>21. 用EXISTS替换DISTINCT<BR><BR>当提交一个包含一对多表信息(比如部门表和雇员表)的查询时,避免在SELECT子句中使用DISTINCT. 一般可以考虑用EXIST替换<BR><BR> <BR><BR>例如:<BR><BR>低效:<BR><BR> SELECT DISTINCT DEPT_NO,DEPT_NAME<BR><BR> FROM DEPT D,EMP E<BR><BR> WHERE D.DEPT_NO = E.DEPT_NO<BR><BR>高效:<BR><BR> SELECT DEPT_NO,DEPT_NAME<BR><BR> FROM DEPT D<BR><BR> WHERE EXISTS ( SELECT ‘X’<BR><BR> FROM EMP E<BR><BR> WHERE E.DEPT_NO = D.DEPT_NO);<BR><BR> <BR><BR> EXISTS 使查询更为迅速,因为RDBMS核心模块将在子查询的条件一旦满足后,立刻返回结果.<BR><BR> <BR><BR>22. 识别’低效执行’的SQL语句<BR><BR> <BR><BR>用下列SQL工具找出低效SQL:<BR><BR> <BR><BR>SELECT EXECUTIONS , DISK_READS, BUFFER_GETS,<BR><BR> ROUND((BUFFER_GETS-DISK_READS)/BUFFER_GETS,2) Hit_radio,<BR><BR> ROUND(DISK_READS/EXECUTIONS,2) Reads_per_run,<BR><BR> SQL_TEXT<BR><BR>FROM V$SQLAREA<BR><BR>WHERE EXECUTIONS>0<BR><BR>AND BUFFER_GETS > 0 <BR><BR>AND (BUFFER_GETS-DISK_READS)/BUFFER_GETS < 0.8 <BR><BR>ORDER BY 4 DESC;<BR><BR> <BR><BR>(译者按: 虽然目前各种关于SQL优化的图形化工具层出不穷,但是写出自己的SQL工具来解决问题始终是一个最好的方法)<BR><BR> <BR><BR>23. 使用TKPROF 工具来查询SQL性能状态<BR><BR> <BR><BR>SQL trace 工具收集正在执行的SQL的性能状态数据并记录到一个跟踪文件中. 这个跟踪文件提供了许多有用的信息,例如解析次数.执行次数,CPU使用时间等.这些数据将可以用来优化你的系统.<BR><BR> <BR><BR>设置SQL TRACE在会话级别: 有效<BR><BR> <BR><BR> ALTER SESSION SET SQL_TRACE TRUE<BR><BR> <BR><BR>设置SQL TRACE 在整个<a href="/Html/DataBase/" target="_blank">数据库</a>有效仿, 你必须将SQL_TRACE参数在init.ora中设为TRUE, USER_DUMP_DEST参数说明了生成跟踪文件的目录<BR><BR> <BR><BR>(译者按: 这一节中,作者并没有提到TKPROF的用法, 对SQL TRACE的用法也不够准确, 设置SQL TRACE首先要在init.ora中设定TIMED_STATISTICS, 这样才能得到那些重要的时间状态. 生成的trace文件是不可读的,所以要用TKPROF工具对其进行转换,TKPROF有许多执行参数. 大家可以参考ORACLE手册来了解具体的配置. )<p><div align="right">本新闻共<font color=red>2</font>页,当前在第<font color=red>1</font>页 <font color="red">1</font> <a href="164558059816455850688_2.shtml">2</a> </div></p>
<P clear=all></P>
</FONT></TD>
</TR>
</TBODY>
</TABLE>
</DIV>
<BR>
上一篇:<a href='../../2005-4/29/164558059816455868215.shtml' title ='ORACLE坏块(ORA-01578)处理方法'>ORACLE坏块(ORA-01578)处理方法</a> 下一篇:<a href='../../2005-4/29/164558059816455868846.shtml' title ='ORACLE DBA常用SQL脚本工具-&gt;管理篇(1)'>ORACLE DBA常用SQL脚本工具-&gt;管理篇(1)</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=059816455850688\" 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=8971\" 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/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/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/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/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/SoftWare/SoftwareEducate/OracleAuthentication/2006-5/29/150826355.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/164559059816455975203.shtml title="ORACLE SQL性能优化系列 (十一)">ORACLE SQL性能优化系列 (十一)</a></td></tr>
<tr>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -