浅谈Oracle B-tree索引扫描方式(下)

上篇再续,书接上一回

4.Index Fast Full Scans

  • 适用场景:当查询仅访问索引列的情况(逻辑上是无序的),可以理解为需要的数据可以通过访问索引获取,不需要通过回表获取数据。
  • 工作方式:数据库多块读取所有分支节点和叶子节点。数据库将忽略分支块和根块,并读取叶块上的索引条目。
  • 示例:
SYS@pudge> set linesize 200            
SYS@pudge> set autotrace on
SYS@pudge> select id from xiaom.test1;
Execution Plan
----------------------------------------------------------
Plan hash value: 4085392248

------------------------------------------------------------------------------------
| Id  | Operation            | Name        | Rows  | Bytes | Cost (%CPU)| Time     |
------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT     |             | 97463 |  1237K|    68   (0)| 00:00:01 |
|   1 |  INDEX FAST FULL SCAN| SYS_C005694 | 97463 |  1237K|    68   (0)| 00:00:01 |
------------------------------------------------------------------------------------

Note
-----
   - dynamic sampling used for this statement (level=2)


Statistics
----------------------------------------------------------
          0  recursive calls
          0  db block gets
       6900  consistent gets
          0  physical reads
          0  redo size
    1829390  bytes sent via SQL*Net to client
      73850  bytes received via SQL*Net from client
       6668  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
     100000  rows processed

5.Index Skip Scans

  • 适用场景:组合索引,过滤条件中未使用到前导列,前导列的基数很低,但是非前导列存在很多不同的值,选择性好。
  • 工作方式:在逻辑上将组合索引拆分成多个子索引
  • 示例:
SYS@pudge> create table xiaom.test2(tags varchar2(10),id number);
Table created.
SYS@pudge> create index xiaom.idx_2 on xiaom.test2(tags,id);
Index created.
SYS@pudge> 
SYS@pudge> 
SYS@pudge> 
SYS@pudge> 
SYS@pudge> 
SYS@pudge> begin
  2  for i in 1..5000 loop
  3  insert into xiaom.test2 values ('crmsb',i);
  4  end loop;
  5  commit;
  6  end;
  7  /
begin
for i in 5001..10000 loop
insert into xiaom.test2 values ('sbcrm',i);
end loop;
commit;
end;
/
PL/SQL procedure successfully completed.

SYS@pudge>   2    3    4    5    6    7  

PL/SQL procedure successfully completed.

SYS@pudge> 
SYS@pudge> 
SYS@pudge> set linesize 200
SYS@pudge> set autotrace on 
SYS@pudge> select * from xiaom.test2 where id = 200;

TAGS                                   ID
------------------------------ ----------
crmsb                                 200


Execution Plan
----------------------------------------------------------
Plan hash value: 274500185

------------------------------------------------------------------------------
| Id  | Operation            | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
------------------------------------------------------------------------------
|   0 | SELECT STATEMENT     |       |     1 |    20 |     9   (0)| 00:00:01 |
|*  1 |  INDEX FAST FULL SCAN| IDX_2 |     1 |    20 |     9   (0)| 00:00:01 |
------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter("ID"=200)

Note
-----
   - dynamic sampling used for this statement (level=2)


Statistics
----------------------------------------------------------
          5  recursive calls
          0  db block gets
         67  consistent gets
          0  physical reads
        124  redo size
        592  bytes sent via SQL*Net to client
        524  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed

你可能感兴趣的:(Oracle)