与dbms_xplan.display()混淆

时间:2014-08-05 14:09:54

标签: sql oracle indexing

我这样想:

create table btree_unique(num number,name varchar2(15));

在表格中插入了1000000行(都是唯一的)

analyze table btree_unique compute statistics;

现在我正在尝试搜索号码987653

解释计划看起来像这样

SQL> explain plan for select * from index_btree_unique where num=987653;

解释

SQL> select * from table(dbms_xplan.display());

PLAN_TABLE_OUTPUT

--------------------------------------------------------------------------------
Plan hash value: 453130233

--------------------------------------------------------------------------------
--------

| Id  | Operation         | Name               | Rows  | Bytes | Cost (%CPU)| Ti
me     |

--------------------------------------------------------------------------------
--------


PLAN_TABLE_OUTPUT

--------------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |                    |     1 |    11 |   697   (3)| 00
:00:09 |

|*  1 |  TABLE ACCESS FULL| INDEX_BTREE_UNIQUE |     1 |    11 |   697   (3)| 00
:00:09 |

--------------------------------------------------------------------------------
--------


Predicate Information (identified by operation id):

PLAN_TABLE_OUTPUT

--------------------------------------------------------------------------------
---------------------------------------------------

Create unique index i on btree_unique(num);

SQL> select * from table(dbms_xplan.display());
PLAN_TABLE_OUTPUT

--------------------------------------------------------------------------------
Plan hash value: 230012590

--------------------------------------------------------------------------------
----

| Id  | Operation                   | Name | Rows  | Bytes | Cost (%CPU)| Time
   |

--------------------------------------------------------------------------------
----


PLAN_TABLE_OUTPUT

--------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |      |     1 |    11 |     3   (0)| 00:00:
01 |

|   1 |  TABLE ACCESS BY INDEX ROWID| SS   |     1 |    11 |     3   (0)| 00:00:
01 |

|*  2 |   INDEX UNIQUE SCAN         | I1   |     1 |       |     2   (0)| 00:00:
01 |

--------------------------------------------------------------------------------
----

PLAN_TABLE_OUTPUT

--------------------------------------------------------------------------------


Predicate Information (identified by operation id):

---------------------------------------------------

   2 - access("NUM"=987653)

如果我们没有在列上创建任何索引,Oracle将执行顺序搜索。在没有创建索引的第一步中,我搜索了数字987653.

在解释计划中,它显示为“FUVER TABLE SCAN”,但扫描的行数仅为1,它应显示1000000对吗? 。创建索引后,CPU使用率和TIME都有所下降,但两种情况下扫描的行都相同。

有人可以解释解释计划中的行部分吗?

1 个答案:

答案 0 :(得分:3)

As the documentation explains ROWS值是估计步骤访问的估计行数(即基数),而不是它必须检查的行数。优化器使用基数来确定最佳连接和过滤顺序,以及使用索引(如果存在)是否有益。

如果您执行实际查询,而不仅仅是解释它的计划,您可以看到执行统计信息,它将显示逻辑和物理缓冲区获取的数量。