您的位置:首页 > 数据库 > Oracle

oracle执行计划 操作符详述

2016-01-27 15:32 453 查看
1.Full Table Scan (FTS) 全表扫描

In a FTS operation, the whole table is read up to the high water mark (HWM). The HWM marks the last block in the table that has ever had data written to it. If you have deleted all the rows then you will still read up to the HWM. Truncate resets the HWM back to the start of the table. FTS uses multiblock i/o to read the blocks from disk.

全表扫描模式下会读数据到表的高水位线(HWM即表示表曾经扩展的最后一个数据块),读取速度依赖于Oracle初始化参db_block_multiblock_read_count(我觉得应该这样翻译:FTS扫描会使表使用上升到高水位(HWM),HWM标识了表最后写入数据的块,如果你用DELETE删除了所有的数据表仍然处于高水位(HWM),只有用TRUNCATE才能使表回归,FTS使用多IO从磁盘读取数据块)

2.Index Lookup 索引扫描

There are 5 methods of index lookup.

1)index unique scan --索引唯一扫描
Method for looking up a single key value via a unique index. always returns a single value, You must supply AT LEAST the leading column of the index to access data via the index.

SQL> select empno,ename from emp where empno=10;

2)index range scan --索引局部扫描Index range scan is a method for accessing a range values of a particular column. AT LEAST the leading column of the index must be supplied to access data via the index. Can be used for range operations (e.g. > < <> >= <= between) .

SQL> select empno from emp where empno>=7902;

3)index full scan --索引全局扫描Full index scans are only available in the CBO as otherwise we are unable to determine whether a full scan would be a good idea or not. We choose an index Full Scan when we have statistics that indicate that it is going to be more efficient than a Full table scan and a sort. For example we may do a Full index scan when we do an unbounded scan of an index and want the data to be ordered in the index order.

SQL> select empno from emp order by empno;

4)index fast full scan --索引快速全局扫描,不带order by情况下常发生
Scans all the block in the index, Rows are not returned in sorted order, Introduced in 7.3 and requires V733_PLANS_ENABLED=TRUE and CBO, may be hinted using INDEX_FFS hint, uses multiblock i/o, can be executed in parallel, can be used to access second column of concatenated indexes. This is because we are selecting all of the index.

SQL> select empno from emp;

5)index skip scan --索引跳跃扫描,where条件列是非索引的前导列情况下常发生

Index skip scan finds rows even if the column is not the leading column of a concatenated index. It skips the first column(s) during the search.

SQL> create index i_emp on emp(empno, ename);

SQL> select /*+ index_ss(emp i_emp)*/ job from emp where ename='SMITH';

3.Rowid 物理ID扫描
This is the quickest access method available.Oracle retrieves the specified block and extracts the rows it is interested in.

--Rowid扫描是最快的访问数据方式

SQL> select * from emp where rowid='AAAjFUAAEAAABZ1AAM';

b、运算符

1.sort --排序,很消耗资源

There are a number of different operations that promote sorts:

(1)order by clauses (2)group by (3)sort merge join –-这三个会产生排序运算

2.filter --过滤,如not in、min函数等容易产生

Has a number of different meanings, used to indicate partition elimination, may also indicate an actual filter step where one row source is filtering, another, functions such as min may introduce filter steps into query plans.

3.view --视图,大都由内联视图产生(可能深入到视图基表)
When a view cannot be merged into the main query you will often see a projection view operation. This indicates that the 'view' will be selected from directly as opposed to being broken down into joins on the base tables. A number of constructs make a view non mergeable. Inline views are also non mergeable.

SQL> select ename,tot from emp,(select empno,sum(empno) tot from emp group by empno) tmp where emp.empno = tmp.empno;

4.partition view --分区视图
Partition views are a legacy technology that were superceded by the partitioning option. This section of the article is provided as reference for such legacy systems.

3、让我们再看看统计信息部分

SQL> set autotrace traceonly;

SQL> select count(*) from emp;

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

5 recursive calls (归调用次数)

0 db block gets (从磁盘上读取的块数,即通过update/delete/select for update读的次数)

15 consistent gets (从内存里读取的块数,即通过不带for update的select 读的次数)

0 physical reads (物理读—从磁盘读到数据块数量,一般来说是'consistent gets' + 'db block gets')

0 redo size (重做数——执行SQL的过程中,产生的重做日志的大小)

515 bytes sent via SQL*Net to client

492 bytes received via SQL*Net from client

2 SQL*Net roundtrips to/from client

0 sorts (memory) (在内存中发生的排序)

0 sorts (disk) (在硬盘中发生的排序)

Cost:(Single block I/O cost+ Multiblock I/O cost+ CPU cost)/sreadtime

db block gets :从buffer cache中读取的block的数量

consistent gets :从buffer cache中读取的undo数据的block的数量

physical reads:从磁盘读取的block的数量

redo size:DML生成的redo的大小

sorts (memory):在内存执行的排序量

sorts (disk):在磁盘上执行的排序量
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: