Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 与dbms_xplan.display()混淆_Sql_Oracle_Indexing - Fatal编程技术网

Sql 与dbms_xplan.display()混淆

Sql 与dbms_xplan.display()混淆,sql,oracle,indexing,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&g

我试着这样做:

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

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

在解释计划中,它显示为全表扫描,但扫描的行数仅为1,应该显示1000000行,对吗。创建索引后,CPU使用率和时间都有所减少,但在这两种情况下扫描的行是相同的

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

行值它是步骤估计要访问的行数,即基数,而不是它必须检查的行数。优化器使用基数来确定最佳联接和筛选顺序,以及如果存在索引,则使用索引是否有益


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

可能重复的问题最好修改旧问题,而不是询问新问题。如果前面的答案没有帮助,您可以添加注释以请求更改或更多信息。
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)