为什么Oracle联接在没有where子句的情况下不使用索引

dwbf0jvd  于 2023-04-29  发布在  Oracle
关注(0)|答案(2)|浏览(176)

我是一个长期的Oracle用户/开发人员。Oracle版本为19 c。
这个场景是,我有一个查询,它读取表A,并获得一个连接到表B的唯一标识符。

select A.unique_id, B.*
from A
inner join B on B.unique_id = A.unique_id
where A.unique_id = 123;

查询运行得很快,解释计划使用B显示它。unique_id的索引。
如果我想看所有的行像;

select A.unique_id, B.*
from A
inner join B on B.unique_id = A.unique_id;

它永远运行,解释计划说它正在做一个完整的表扫描。
我不清楚发生了什么事。这似乎是一个基本的问题,我必须错过。
有人能解释一下;
1.为什么会这样。
1.我能做什么来迫使它使用适当的索引。我尝试索引提示没有成功。

编辑:

表A目前有约700万行。表B有约2800万行
用where子句解释计划;

<TABLE class="TreeTableWidget" border=0 cellpadding=0 cellspacing=0 width=100% bgcolor=#efefef><tr><td> 

 <!-- ..........................data begin...........................  -->

    <TABLE class=TreeTableWidget border=0 cellspacing=0 cellpadding=1 align=center width=100%"  bgcolor=#ffffff> 
    <tr class="TableCell">

       <td valign=top bgcolor=#bbbbbb>&nbsp;<font color=#444477>OPERATION</font>&nbsp;</td>

       <td valign=top bgcolor=#aaaaaa>&nbsp;<font color=#444477>OBJECT_NAME</font>&nbsp;</td>

       <td valign=top bgcolor=#bbbbbb>&nbsp;<font color=#444477>OPTIONS</font>&nbsp;</td>

       <td valign=top bgcolor=#aaaaaa>&nbsp;<font color=#444477>CARDINALITY</font>&nbsp;</td>

       <td valign=top bgcolor=#bbbbbb>&nbsp;<font color=#444477>COST</font>&nbsp;</td>

    </tr>

   <tr>
      <td width=45% valign=top bgcolor=#ffffff ><font size=-1><table width=100% border=0 cellspacing=0 cellpadding=0><tr><td width=1%><table CELLSPACING=0 cellpadding=0><tr><td><IMG SRC="images/minus.gif" wWIDTH=16 hHEIGHT=16 BORDER=0><IMG SRC="images/gray.png" wWIDTH=16 hHEIGHT=16 BORDER=0></td><tr></table></td>  <td width=99%>&nbsp;SELECT STATEMENT&nbsp;</td></tr></table></font></td>
      <td width=11% valign=top bgcolor=#dfdfdf >&nbsp;&nbsp&nbsp;</td>
      <td width=11% valign=top bgcolor=#dfd5d1 >&nbsp;&nbsp&nbsp;</td>
      <td width=11% valign=top bgcolor=#dfdfdf >&nbsp;1&nbsp;</font></td>
      <td width=11% valign=top bgcolor=#dfd5d1 >&nbsp;3&nbsp;</font></td>
   </tr>
   <tr>
      <td width=45% valign=top bgcolor=#ffffff ><font size=-1><table width=100% border=0 cellspacing=0 cellpadding=0><tr><td width=1%><table CELLSPACING=0 cellpadding=0><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td><IMG SRC="images/minus.gif" wWIDTH=16 hHEIGHT=16 BORDER=0><IMG SRC="images/join.png" wWIDTH=16 hHEIGHT=16 BORDER=0></td><tr></table></td>  <td width=99%>&nbsp;NESTED LOOPS&nbsp;</td></tr></table></font></td>
      <td width=11% valign=top bgcolor=#ffffdf >&nbsp;&nbsp&nbsp;</td>
      <td width=11% valign=top bgcolor=#ffffd2 >&nbsp;&nbsp&nbsp;</td>
      <td width=11% valign=top bgcolor=#ffffdf >&nbsp;1&nbsp;</font></td>
      <td width=11% valign=top bgcolor=#ffffd2 >&nbsp;3&nbsp;</font></td>
   </tr>
   <tr>
      <td width=45% valign=top bgcolor=#ffffff ><table width=100% border=0 cellspacing=0 cellpadding=0><tr><td width=1%><table CELLSPACING=0 cellpadding=0><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td><IMG SRC="images/minus.gif" wWIDTH=16 hHEIGHT=16 BORDER=0><IMG SRC="images/index.png" wWIDTH=16 hHEIGHT=16 BORDER=0></td><tr></table></td>  <td width=99%>&nbsp;INDEX&nbsp;</td></tr></table></font></td>
      <td width=11% valign=top bgcolor=#dfdfdf ><font size=-1>&nbsp;IND_ABSGEOCODE&nbsp;</font></td>
      <td width=11% valign=top bgcolor=#dfd5d1 ><font size=-1>&nbsp;UNIQUE SCAN&nbsp;</font></td>
      <td width=11% valign=top bgcolor=#dfdfdf >&nbsp;1&nbsp;</font></td>
      <td width=11% valign=top bgcolor=#dfd5d1 >&nbsp;2&nbsp;</font></td>
   </tr>
   <tr>
      <td width=45% valign=top bgcolor=#ffffff ><table width=100% border=0 cellspacing=0 cellpadding=0><tr><td width=1%><table CELLSPACING=0 cellpadding=0><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td><IMG SRC="images/minus.gif" wWIDTH=16 hHEIGHT=16 BORDER=0><IMG SRC="images/index.png" wWIDTH=16 hHEIGHT=16 BORDER=0></td><tr></table></td>  <td width=99%>&nbsp;INDEX&nbsp;</td></tr></table></font></td>
      <td width=11% valign=top bgcolor=#ffffdf ><font size=-1>&nbsp;ABSHIST_RECORD_SEQ&nbsp;</font></td>
      <td width=11% valign=top bgcolor=#ffffd2 ><font size=-1>&nbsp;UNIQUE SCAN&nbsp;</font></td>
      <td width=11% valign=top bgcolor=#ffffdf >&nbsp;1&nbsp;</font></td>
      <td width=11% valign=top bgcolor=#ffffd2 >&nbsp;1&nbsp;</font></td>
   </tr>
</table>

 <!-- ..........................data end...........................  -->

</td></tr></TABLE>

不带where子句的解释计划;

<TABLE class="TreeTableWidget" border=0 cellpadding=0 cellspacing=0 width=100% bgcolor=#efefef><tr><td> 

 <!-- ..........................data begin...........................  -->

    <TABLE class=TreeTableWidget border=0 cellspacing=0 cellpadding=1 align=center width=100%"  bgcolor=#ffffff> 
    <tr class="TableCell">

       <td valign=top bgcolor=#bbbbbb>&nbsp;<font color=#444477>OPERATION</font>&nbsp;</td>

       <td valign=top bgcolor=#aaaaaa>&nbsp;<font color=#444477>OBJECT_NAME</font>&nbsp;</td>

       <td valign=top bgcolor=#bbbbbb>&nbsp;<font color=#444477>OPTIONS</font>&nbsp;</td>

       <td valign=top bgcolor=#aaaaaa>&nbsp;<font color=#444477>CARDINALITY</font>&nbsp;</td>

       <td valign=top bgcolor=#bbbbbb>&nbsp;<font color=#444477>COST</font>&nbsp;</td>

       <td valign=top bgcolor=#aaaaaa>&nbsp;<font color=#444477>OBJECT_NODE</font>&nbsp;</td>

       <td valign=top bgcolor=#bbbbbb>&nbsp;<font color=#444477>OTHER_TAG</font>&nbsp;</td>

    </tr>

   <tr>
      <td width=45% valign=top bgcolor=#ffffff ><font size=-2><table width=100% border=0 cellspacing=0 cellpadding=0><tr><td width=1%><table CELLSPACING=0 cellpadding=0><tr><td><IMG SRC="images/minus.gif" wWIDTH=16 hHEIGHT=16 BORDER=0><IMG SRC="images/gray.png" wWIDTH=16 hHEIGHT=16 BORDER=0></td><tr></table></td>  <td width=99%>&nbsp;SELECT STATEMENT&nbsp;</td></tr></table></font></td>
      <td width=7% valign=top bgcolor=#dfdfdf >&nbsp;&nbsp&nbsp;</td>
      <td width=7% valign=top bgcolor=#dfd5d1 >&nbsp;&nbsp&nbsp;</td>
      <td width=7% valign=top bgcolor=#dfdfdf ><font size=-1>&nbsp;6787518&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#dfd5d1 ><font size=-1>&nbsp;21297&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#dfdfdf >&nbsp;&nbsp&nbsp;</td>
      <td width=7% valign=top bgcolor=#dfd5d1 >&nbsp;&nbsp&nbsp;</td>
   </tr>
   <tr>
      <td width=45% valign=top bgcolor=#ffffff ><font size=-2><table width=100% border=0 cellspacing=0 cellpadding=0><tr><td width=1%><table CELLSPACING=0 cellpadding=0><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td><IMG SRC="images/minus.gif" wWIDTH=16 hHEIGHT=16 BORDER=0><IMG SRC="images/gray.png" wWIDTH=16 hHEIGHT=16 BORDER=0></td><tr></table></td>  <td width=99%>&nbsp;PX COORDINATOR&nbsp;</td></tr></table></font></td>
      <td width=7% valign=top bgcolor=#ffffdf >&nbsp;&nbsp&nbsp;</td>
      <td width=7% valign=top bgcolor=#ffffd2 >&nbsp;&nbsp&nbsp;</td>
      <td width=7% valign=top bgcolor=#ffffdf >&nbsp;&nbsp&nbsp;</td>
      <td width=7% valign=top bgcolor=#ffffd2 >&nbsp;&nbsp&nbsp;</td>
      <td width=7% valign=top bgcolor=#ffffdf >&nbsp;&nbsp&nbsp;</td>
      <td width=7% valign=top bgcolor=#ffffd2 >&nbsp;&nbsp&nbsp;</td>
   </tr>
   <tr>
      <td width=45% valign=top bgcolor=#ffffff ><font size=-1><table width=100% border=0 cellspacing=0 cellpadding=0><tr><td width=1%><table CELLSPACING=0 cellpadding=0><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td><IMG SRC="images/minus.gif" wWIDTH=16 hHEIGHT=16 BORDER=0><IMG SRC="images/gray.png" wWIDTH=16 hHEIGHT=16 BORDER=0></td><tr></table></td>  <td width=99%>&nbsp;PX SEND&nbsp;</td></tr></table></font></td>
      <td width=7% valign=top bgcolor=#dfdfdf ><font size=-2>&nbsp;SYS.:TQ10002&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#dfd5d1 ><font size=-2>&nbsp;QC (RANDOM)&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#dfdfdf ><font size=-1>&nbsp;6787518&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#dfd5d1 ><font size=-1>&nbsp;21297&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#dfdfdf ><font size=-1>&nbsp;:Q1002&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#dfd5d1 ><font size=-1>&nbsp;P->S&nbsp;</font></td>
   </tr>
   <tr>
      <td width=45% valign=top bgcolor=#ffffff ><font size=-1><table width=100% border=0 cellspacing=0 cellpadding=0><tr><td width=1%><table CELLSPACING=0 cellpadding=0><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td><IMG SRC="images/minus.gif" wWIDTH=16 hHEIGHT=16 BORDER=0><IMG SRC="images/join.png" wWIDTH=16 hHEIGHT=16 BORDER=0></td><tr></table></td>  <td width=99%>&nbsp;HASH JOIN&nbsp;</td></tr></table></font></td>
      <td width=7% valign=top bgcolor=#ffffdf >&nbsp;&nbsp&nbsp;</td>
      <td width=7% valign=top bgcolor=#ffffd2 ><font size=-1>&nbsp;BUFFERED&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#ffffdf ><font size=-1>&nbsp;6787518&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#ffffd2 ><font size=-1>&nbsp;21297&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#ffffdf ><font size=-1>&nbsp;:Q1002&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#ffffd2 ><font size=-1>&nbsp;PCWP&nbsp;</font></td>
   </tr>
   <tr>
      <td width=45% valign=top bgcolor=#ffffff ><font size=-2><table width=100% border=0 cellspacing=0 cellpadding=0><tr><td width=1%><table CELLSPACING=0 cellpadding=0><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td><IMG SRC="images/minus.gif" wWIDTH=16 hHEIGHT=16 BORDER=0><IMG SRC="images/gray.png" wWIDTH=16 hHEIGHT=16 BORDER=0></td><tr></table></td>  <td width=99%>&nbsp;PX RECEIVE&nbsp;</td></tr></table></font></td>
      <td width=7% valign=top bgcolor=#dfdfdf >&nbsp;&nbsp&nbsp;</td>
      <td width=7% valign=top bgcolor=#dfd5d1 >&nbsp;&nbsp&nbsp;</td>
      <td width=7% valign=top bgcolor=#dfdfdf ><font size=-1>&nbsp;6930390&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#dfd5d1 ><font size=-1>&nbsp;13149&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#dfdfdf ><font size=-1>&nbsp;:Q1002&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#dfd5d1 ><font size=-1>&nbsp;PCWP&nbsp;</font></td>
   </tr>
   <tr>
      <td width=45% valign=top bgcolor=#ffffff ><font size=-1><table width=100% border=0 cellspacing=0 cellpadding=0><tr><td width=1%><table CELLSPACING=0 cellpadding=0><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td><IMG SRC="images/minus.gif" wWIDTH=16 hHEIGHT=16 BORDER=0><IMG SRC="images/gray.png" wWIDTH=16 hHEIGHT=16 BORDER=0></td><tr></table></td>  <td width=99%>&nbsp;PX SEND&nbsp;</td></tr></table></font></td>
      <td width=7% valign=top bgcolor=#ffffdf ><font size=-2>&nbsp;SYS.:TQ10000&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#ffffd2 ><font size=-2>&nbsp;HYBRID HASH&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#ffffdf ><font size=-1>&nbsp;6930390&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#ffffd2 ><font size=-1>&nbsp;13149&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#ffffdf ><font size=-1>&nbsp;:Q1000&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#ffffd2 ><font size=-1>&nbsp;P->P&nbsp;</font></td>
   </tr>
   <tr>
      <td width=45% valign=top bgcolor=#ffffff ><font size=-2><table width=100% border=0 cellspacing=0 cellpadding=0><tr><td width=1%><table CELLSPACING=0 cellpadding=0><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td><IMG SRC="images/minus.gif" wWIDTH=16 hHEIGHT=16 BORDER=0><IMG SRC="images/gray.png" wWIDTH=16 hHEIGHT=16 BORDER=0></td><tr></table></td>  <td width=99%>&nbsp;STATISTICS COLLECTOR&nbsp;</td></tr></table></font></td>
      <td width=7% valign=top bgcolor=#dfdfdf >&nbsp;&nbsp&nbsp;</td>
      <td width=7% valign=top bgcolor=#dfd5d1 >&nbsp;&nbsp&nbsp;</td>
      <td width=7% valign=top bgcolor=#dfdfdf >&nbsp;&nbsp&nbsp;</td>
      <td width=7% valign=top bgcolor=#dfd5d1 >&nbsp;&nbsp&nbsp;</td>
      <td width=7% valign=top bgcolor=#dfdfdf ><font size=-1>&nbsp;:Q1000&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#dfd5d1 ><font size=-1>&nbsp;PCWC&nbsp;</font></td>
   </tr>
   <tr>
      <td width=45% valign=top bgcolor=#ffffff ><font size=-1><table width=100% border=0 cellspacing=0 cellpadding=0><tr><td width=1%><table CELLSPACING=0 cellpadding=0><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td><IMG SRC="images/minus.gif" wWIDTH=16 hHEIGHT=16 BORDER=0><IMG SRC="images/gray.png" wWIDTH=16 hHEIGHT=16 BORDER=0></td><tr></table></td>  <td width=99%>&nbsp;PX BLOCK&nbsp;</td></tr></table></font></td>
      <td width=7% valign=top bgcolor=#ffffdf >&nbsp;&nbsp&nbsp;</td>
      <td width=7% valign=top bgcolor=#ffffd2 ><font size=-1>&nbsp;ITERATOR&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#ffffdf ><font size=-1>&nbsp;6930390&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#ffffd2 ><font size=-1>&nbsp;13149&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#ffffdf ><font size=-1>&nbsp;:Q1000&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#ffffd2 ><font size=-1>&nbsp;PCWC&nbsp;</font></td>
   </tr>
   <tr>
      <td width=45% valign=top bgcolor=#ffffff ><font size=-2><table width=100% border=0 cellspacing=0 cellpadding=0><tr><td width=1%><table CELLSPACING=0 cellpadding=0><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td><IMG SRC="images/minus.gif" wWIDTH=16 hHEIGHT=16 BORDER=0><IMG SRC="images/table.png" wWIDTH=16 hHEIGHT=16 BORDER=0></td><tr></table></td>  <td width=99%>&nbsp;TABLE ACCESS&nbsp;</td></tr></table></font></td>
      <td width=7% valign=top bgcolor=#dfdfdf ><font size=-1>&nbsp;ABSHIST&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#dfd5d1 ><font size=-1>&nbsp;FULL&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#dfdfdf ><font size=-1>&nbsp;6930390&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#dfd5d1 ><font size=-1>&nbsp;13149&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#dfdfdf ><font size=-1>&nbsp;:Q1000&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#dfd5d1 ><font size=-1>&nbsp;PCWP&nbsp;</font></td>
   </tr>
   <tr>
      <td width=45% valign=top bgcolor=#ffffff ><font size=-2><table width=100% border=0 cellspacing=0 cellpadding=0><tr><td width=1%><table CELLSPACING=0 cellpadding=0><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td><IMG SRC="images/minus.gif" wWIDTH=16 hHEIGHT=16 BORDER=0><IMG SRC="images/gray.png" wWIDTH=16 hHEIGHT=16 BORDER=0></td><tr></table></td>  <td width=99%>&nbsp;PX RECEIVE&nbsp;</td></tr></table></font></td>
      <td width=7% valign=top bgcolor=#ffffdf >&nbsp;&nbsp&nbsp;</td>
      <td width=7% valign=top bgcolor=#ffffd2 >&nbsp;&nbsp&nbsp;</td>
      <td width=7% valign=top bgcolor=#ffffdf ><font size=-1>&nbsp;6787518&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#ffffd2 ><font size=-1>&nbsp;8147&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#ffffdf ><font size=-1>&nbsp;:Q1002&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#ffffd2 ><font size=-1>&nbsp;PCWP&nbsp;</font></td>
   </tr>
   <tr>
      <td width=45% valign=top bgcolor=#ffffff ><font size=-1><table width=100% border=0 cellspacing=0 cellpadding=0><tr><td width=1%><table CELLSPACING=0 cellpadding=0><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td><IMG SRC="images/minus.gif" wWIDTH=16 hHEIGHT=16 BORDER=0><IMG SRC="images/gray.png" wWIDTH=16 hHEIGHT=16 BORDER=0></td><tr></table></td>  <td width=99%>&nbsp;PX SEND&nbsp;</td></tr></table></font></td>
      <td width=7% valign=top bgcolor=#dfdfdf ><font size=-2>&nbsp;SYS.:TQ10001&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#dfd5d1 ><font size=-2>&nbsp;HYBRID HASH&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#dfdfdf ><font size=-1>&nbsp;6787518&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#dfd5d1 ><font size=-1>&nbsp;8147&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#dfdfdf ><font size=-1>&nbsp;:Q1001&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#dfd5d1 ><font size=-2>&nbsp;PARALLEL_FROM_SERIAL&nbsp;</font></td>
   </tr>
   <tr>
      <td width=45% valign=top bgcolor=#ffffff ><font size=-2><table width=100% border=0 cellspacing=0 cellpadding=0><tr><td width=1%><table CELLSPACING=0 cellpadding=0><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td><IMG SRC="images/minus.gif" wWIDTH=16 hHEIGHT=16 BORDER=0><IMG SRC="images/gray.png" wWIDTH=16 hHEIGHT=16 BORDER=0></td><tr></table></td>  <td width=99%>&nbsp;PX SELECTOR&nbsp;</td></tr></table></font></td>
      <td width=7% valign=top bgcolor=#ffffdf >&nbsp;&nbsp&nbsp;</td>
      <td width=7% valign=top bgcolor=#ffffd2 >&nbsp;&nbsp&nbsp;</td>
      <td width=7% valign=top bgcolor=#ffffdf >&nbsp;&nbsp&nbsp;</td>
      <td width=7% valign=top bgcolor=#ffffd2 >&nbsp;&nbsp&nbsp;</td>
      <td width=7% valign=top bgcolor=#ffffdf ><font size=-1>&nbsp;:Q1001&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#ffffd2 ><font size=-2>&nbsp;SINGLE_COMBINED_WITH_CHILD&nbsp;</font></td>
   </tr>
   <tr>
      <td width=45% valign=top bgcolor=#ffffff ><font size=-1><table width=100% border=0 cellspacing=0 cellpadding=0><tr><td width=1%><table CELLSPACING=0 cellpadding=0><tr><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;</td><td><IMG SRC="images/minus.gif" wWIDTH=16 hHEIGHT=16 BORDER=0><IMG SRC="images/index.png" wWIDTH=16 hHEIGHT=16 BORDER=0></td><tr></table></td>  <td width=99%>&nbsp;INDEX&nbsp;</td></tr></table></font></td>
      <td width=7% valign=top bgcolor=#dfdfdf ><font size=-2>&nbsp;IND_ABSGEOCODE&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#dfd5d1 ><font size=-2>&nbsp;RANGE SCAN&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#dfdfdf ><font size=-1>&nbsp;6787518&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#dfd5d1 ><font size=-1>&nbsp;8147&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#dfdfdf ><font size=-1>&nbsp;:Q1001&nbsp;</font></td>
      <td width=7% valign=top bgcolor=#dfd5d1 ><font size=-2>&nbsp;SINGLE_COMBINED_WITH_PARENT&nbsp;</font></td>
   </tr>
</table>

 <!-- ..........................data end...........................  -->

</td></tr></TABLE>
wnvonmuf

wnvonmuf1#

甲骨文将选择它认为是最好的计划。有时会使用索引,有时会使用全表扫描。这是很正常的行为,尤其是在去掉 predicate 的情况下。如果当前查询没有123 predicate ,除非table_A与table_B相比非常小,否则使用全扫描的散列连接实际上是最好的方法。你不想强迫它使用索引。
至于为什么“永远”,您应该获得一个执行计划,并查询v$active_session_history以获得SQLID,以查看发生了什么以及在哪里花费了时间,或者向DBA寻求帮助。
没有看到任何东西,我的初步猜测是:
1.这些表格很大,你要连续阅读
1.表很大,它必须使用大量的临时空间来进行连接,
1.由于您要求将所有行返回给您的客户端,可能它们正在被提取的过程中,这可能会花费很长时间通过您的网络以小批量的方式返回到您的客户端,但这不是数据库的错。
1.也许“永远”是相对的,你想知道为什么几分钟后你还没有看到第一排。那是因为哈希连接就是这样工作的。它必须从一个输入完全构建哈希表,然后才能开始用另一个输入探测它,只有这样你才能开始看到行。重要的是整个SQL的总体运行时间,而不是第一行的响应时间。
你当然可以通过使用并行来更快地获得哈希连接:

select /*+ parallel(8) */ A.unique_id, B.*
from A
inner join B on B.unique_id = A.unique_id;

也许还可以与DBA一起分配更多的PGA来减少临时空间和工作区,但这对总体运行时间没有多大好处,因为将所有这些结果取回到客户端需要更长的时间,这受到网络延迟和客户端获取调用大小的限制。

qmb5sa22

qmb5sa222#

Oracle不使用索引的另一个非常常见的原因是数据库统计信息丢失或过时。
使用以下方法检查上次分析表和索引的时间:

SELECT table_name, num_rows, last_analyzed FROM user_tables WHERE table_name = 'my_table';

SELECT index_name, num_rows, last_analyzed FROM user_indexes WHERE index_name = 'my_index';

如果您正在使用的数据库对象的统计信息过时,则应强制Oracle使用如下内容生成新的统计信息:

EXEC DBMS_STATS.gather_table_stats('SCOTT', 'EMPLOYEES', estimate_percent => 15, cascade => TRUE);

Cost-Based Optimizer (CBO) And Database Statistics在进入官方Oracle文档之前提供了一个很好的介绍。

相关问题