⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oracle sql性能优化系列 (四)--acnow_net.htm

📁 这是在网上收集的关于oracle的sql语句优化的文章
💻 HTM
📖 第 1 页 / 共 3 页
字号:
        <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>&nbsp;<BR><BR>13.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 计算记录条数<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; 和一般的观点相反, count(*) 比count(1)稍快 , 当然如果可以通过索引检索,对索引列的计数仍旧是最快的. 例如 COUNT(EMPNO)<BR><BR>&nbsp;<BR><BR>(译者按: 在CSDN论坛中,曾经对此有过相当热烈的讨论, 作者的观点并不十分准确,通过实际的测试,上述三种方法并没有显著的性能差别)<BR><BR>&nbsp;<BR><BR>14.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 用Where子句替换HAVING子句<BR><BR>&nbsp;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; 避免使用HAVING子句, HAVING 只会在检索出所有记录之后才对结果集进行过滤. 这个处理需要排序,总计等操作. 如果能通过WHERE子句限制记录的数目,那就能减少这方面的开销.<BR><BR>&nbsp;<BR><BR>例如:<BR><BR>&nbsp;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; 低效:<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; SELECT REGION,AVG(LOG_SIZE)<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; FROM LOCATION<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; GROUP BY REGION<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; HAVING REGION REGION != ‘SYDNEY’<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; AND REGION != ‘PERTH’<BR><BR>&nbsp;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; 高效<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; SELECT REGION,AVG(LOG_SIZE)<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; FROM LOCATION<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; WHERE REGION REGION != ‘SYDNEY’<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; AND REGION != ‘PERTH’<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; GROUP BY REGION<BR><BR>(译者按: HAVING 中的条件一般用于对一些集合函数的比较,如COUNT() 等等. 除此而外,一般的条件应该写在WHERE子句中)<BR><BR>&nbsp;<BR><BR>15.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 减少对表的查询<BR><BR>在含有子查询的SQL语句中,要特别注意减少对表的查询.<BR><BR>&nbsp;&nbsp; <BR><BR>例如: <BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; 低效<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SELECT TAB_NAME<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FROM TABLES<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WHERE TAB_NAME = ( SELECT TAB_NAME <BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs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ER)<BR><BR>&nbsp;= ( SELECT TAB_NAME,DB_VER) <BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FROM TAB_COLUMNS<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WHERE VERSION = 604)<p><div align="right">本新闻共<font color=red>2</font>页,当前在第<font color=red>1</font>页&nbsp;&nbsp;<font color="red">1</font>&nbsp;&nbsp;<a href="164558059816455832996_2.shtml">2</a>&nbsp;&nbsp;</div></p>
                  <P clear=all></P> 
                  </FONT></TD> 
              </TR> 
            </TBODY> 
          </TABLE> 
        </DIV> 
        <BR> 
		上一篇:<a href='../../2005-4/29/164558059816455885739.shtml' title ='在单机上创建物理的Oracle9i standby数据库'>在单机上创建物理的Oracle9i standby数据库</a> 下一篇:<a href='../../2005-4/29/164558059816455831878.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=059816455832996\"  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=8964\" 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/164559059816455944859.shtml title="ORACLE SQL性能优化系列 (十)">ORACLE&nbsp;SQL性能优化系列&nbsp;(十)</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&nbsp;SQL性能优化系列&nbsp;(七)</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&nbsp;SQL性能优化系列&nbsp;(十一)</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性能优化系列 (五)">ORACLE&nbsp;SQL性能优化系列&nbsp;(五)</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&nbsp;SQL性能优化系列&nbsp;(二)</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&nbsp;SQL性能优化系列&nbsp;(八)</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/164558059816455832430.shtml title="ORACLE SQL性能优化系列 (九)">ORACLE&nbsp;SQL性能优化系列&nbsp;(九)</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&nbsp;SQL性能优化系列&nbsp;(六)</a></td></tr>
<tr>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -