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

📄 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>27.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 基础表的选择<BR><BR>&nbsp;<BR><BR>基础表(Driving Table)是指被最先访问的表(通常以全表扫描的方式被访问). 根据优化器的不同, SQL语句中基础表的选择是不一样的.<BR><BR>如果你使用的是CBO (COST BASED OPTIMIZER),优化器会检查SQL语句中的每个表的物理大小,索引的状态,然后选用花费最低的执行路径.<BR><BR>如果你用RBO (RULE BASED OPTIMIZER) , 并且所有的连接条件都有索引对应, 在这种情况下, 基础表就是FROM 子句中列在最后的那个表.<BR><BR>举例:<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; SELECT A.NAME , B.MANAGER<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; FROM WORKER A, <BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LODGING B<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; WHERE A.LODGING = B.LODING;<BR><BR>由于LODGING表的LODING列上有一个索引, 而且WORKER表中没有相比较的索引, WORKER表将被作为查询中的基础表.<BR><BR>&nbsp;<BR><BR>28.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 多个平等的索引<BR><BR>当SQL语句的执行路径可以使用分布在多个表上的多个索引时, ORACLE会同时使用多个索引并在运行时对它们的记录进行合并, 检索出仅对全部索引有效的记录.<BR><BR>在ORACLE选择执行路径时,唯一性索引的等级高于非唯一性索引. 然而这个规则只有<BR><BR>当WHERE子句中索引列和常量比较才有效.如果索引列和其他表的索引类相比较. 这种子句在优化器中的等级是非常低的.<BR><BR>如果不同表中两个想同等级的索引将被引用, FROM子句中表的顺序将决定哪个会被率先使用. FROM子句中最后的表的索引将有最高的优先级.<BR><BR>如果相同表中两个想同等级的索引将被引用, WHERE子句中最先被引用的索引将有最高的优先级.<BR><BR>举例:<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; DEPTNO上有一个非唯一性索引,EMP_CAT也有一个非唯一性索引.<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; SELECT ENAME,<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; FROM EMP<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; WHERE DEPT_NO = 20<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; AND EMP_CAT = ‘A’;<BR><BR>这里,DEPTNO索引将被最先检索,然后同EMP_CAT索引检索出的记录进行合并. 执行路径如下:<BR><BR>&nbsp;<BR><BR>TABLE ACCESS BY ROWID ON EMP<BR><BR>&nbsp;&nbsp;&nbsp; AND-EQUAL<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; INDEX RANGE SCAN ON DEPT_IDX<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; INDEX RANGE SCAN ON CAT_IDX<BR><BR>&nbsp;<BR><BR>29.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;等式比较和范围比较<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; 当WHERE子句中有索引列, ORACLE不能合并它们,ORACLE将用范围比较.<BR><BR>&nbsp;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; 举例:<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; DEPTNO上有一个非唯一性索引,EMP_CAT也有一个非唯一性索引.<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; SELECT ENAME<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; FROM EMP<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; WHERE DEPTNO &gt; 20<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; AND EMP_CAT = ‘A’;<BR><BR>&nbsp;&nbsp;&nbsp; <BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; 这里只有EMP_CAT索引被用到,然后所有的记录将逐条与DEPTNO条件进行比较. 执行路径如下:<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; TABLE ACCESS BY ROWID ON EMP <BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;INDEX RANGE SCAN ON CAT_IDX<BR><BR>&nbsp;<BR><BR>30.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 不明确的索引等级<BR><BR>&nbsp;<BR><BR>当ORACLE无法判断索引的等级高低差别,优化器将只使用一个索引,它就是在WHERE子句中被列在最前面的.<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; 举例:<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; DEPTNO上有一个非唯一性索引,EMP_CAT也有一个非唯一性索引.<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; <BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; SELECT ENAME<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; FROM EMP<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; WHERE DEPTNO &gt; 20<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; AND EMP_CAT &gt; ‘A’;<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="164558059816455832430_2.shtml">2</a>&nbsp;&nbsp;</div></p>
                  <P clear=all></P> 
                  </FONT></TD> 
              </TR> 
            </TBODY> 
          </TABLE> 
        </DIV> 
        <BR> 
		上一篇:<a href='../../2005-4/29/164558059816455829048.shtml' title ='说一说Oracle的优化器(Optimizer)'>说一说Oracle的优化器(Optimizer)</a> 下一篇:<a href='../../2005-4/29/16455905981645599656.shtml' title ='ORACLE常用傻瓜問題1000問(之四)'>ORACLE常用傻瓜問題1000問(之四)</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=059816455832430\"  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=8986\" 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/164559059816455980543.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/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/164558059816455832996.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/164559059816455960820.shtml title="ORACLE SQL性能优化系列 (十四) 完结篇">ORACLE&nbsp;SQL性能优化系列&nbsp;(十四)&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/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/164558059816455810544.shtml title="ORACLE SQL性能优化系列 (一)">ORACLE&nbsp;SQL性能优化系列&nbsp;(一)</a></td></tr>
<tr>

⌨️ 快捷键说明

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