Oracle 表访问方式详解

表访问方式

表的访问方式 解释
table access full(全表扫描)
table access by rowid(通过 rowid 扫描)
table access by index scan(索引扫描) index unique scan(索引唯一扫描)
index range scan(索引范围扫描)
index full scan(索引全扫描).
index fast full scan(索引快速扫描)
index skip scan(索引跳跃扫描)

table access full(全表扫描)

  • Oracle 会读取表中所有的行,并检查每一行是否满足 where 限制条件
  • 全表扫描时可以使用多块读(一次 I/O 读取多块数据块)操作,提升吞吐量
  • 使用建议:数据量太大的表不建议使用全表扫描,除非本身需要取出的数据较多,占到表数据总量的 5% ~ 10% 或以上

在这里插入图片描述

table access by rowid(通过 rowid 扫描)

  • rowid:伪列,Oracle 自带的,不会存储 rowid 的值,不能被增、删、改
  • 一旦一行数据插入后,则其对应的 rowid 在该行的生命周期内是唯一的,即使发生行迁移,该行的 rowid 值也不变

在这里插入图片描述

table access by index scan(索引扫描)

在这里插入图片描述

  • 在索引块中,既存储每个索引的键值,也存储具有该键值行的 rowid
  • 所以索引扫描其实分为两步:
    • 扫描索引得到对应的 rowid
    • 通过 rowid 定位到具体的行读取数据

1. index unique scan(索引唯一扫描)

  • 每次至多返回一条记录
  • 有下列两种情况(当查询字段有下列约束时)
    • unique
    • primary key

在这里插入图片描述

2. index range scan(索引范围扫描)

  • 每次至少返回一条记录
  • 一般有下列三种情况
    • 在唯一索引列上使用了范围操作符(如:> < >= <= between)
    • 在组合索引上,只使用部分列进行查询(查询时必须包含前导列,否则会走全表扫描)
    • 对非唯一索引列上进行的任何查询

3. index full scan(索引全扫描)

  • order by 唯一索引列

在这里插入图片描述

4. index fast full scan(索引快速扫描)

  • 与 index full scan 类似,只是不进行排序

5. index skip scan(索引跳跃扫描)

  • 必须是 组合索引
  • 除了前导列(索引中第一列)外的其他列作为条件

猜你喜欢

转载自blog.csdn.net/qq_34745941/article/details/96475940