访问路径:通过哪种方式对数据进行访问. 全表扫描、索引扫描或ROWID获取数据。

常见访问路径

1.TABLE ACCESS FULL(全表扫描)

  • 多块读
  • HINT:FULL(表名/别名)
  • 等待事件为db file scattered read.
  • 若为并行全表扫描,等待事件为direct path read.

2.TABLE ACCESS BY USER ROWID

  • 直接用ROWID获取数据,单块读。
  • 该访问路径在Oracle所有的访问路径中性能是最好的。

3.TABLE ACCESS BY ROWID RANGE

  • 表示ROWID 范围扫描,多块读。
  • 因为同一个块里面的ROWID是连续的,同一个EXTENT里面的ROWID也是连续的,所以可以多块读。

4.TABLE ACCESS BY INDEX ROWID

  • 回表,单块读

5.INDEX UNIQUE SCAN

  • 索引唯一扫描,单块读。
  • 对唯一索引或者主键列进行等值查询,就会走INDEX UNIQUE SCAN
  • 其性能仅次于TABLE ACCESS BY USER ROWID
scott@orclpdb1:orclcdb> set autot trace
scott@orclpdb1:orclcdb>
scott@orclpdb1:orclcdb>
scott@orclpdb1:orclcdb> select * from emp where empno=7369;1 row selected.Execution Plan
----------------------------------------------------------
Plan hash value: 2949544139--------------------------------------------------------------------------------------
| Id  | Operation                   | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |        |     1 |    38 |     1   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID| EMP    |     1 |    38 |     1   (0)| 00:00:01 |
|*  2 |   INDEX UNIQUE SCAN         | PK_EMP |     1 |       |     0   (0)| 00:00:01 |
--------------------------------------------------------------------------------------Predicate Information (identified by operation id):
---------------------------------------------------2 - access("EMPNO"=7369)Statistics
----------------------------------------------------------0  recursive calls0  db block gets2  consistent gets0  physical reads0  redo size961  bytes sent via SQL*Net to client385  bytes received via SQL*Net from client1  SQL*Net roundtrips to/from client0  sorts (memory)0  sorts (disk)1  rows processedscott@orclpdb1:orclcdb> 

6.INDEX RANGE SCAN

  • 索引范围扫描,单块读,返回的数据是有序的,
  • HINT:INDEX(表名/别名 索引名)
  • 对唯一索引或者主键索引进行范围查找(INDEX RANGE SCAN,等待事件db file sequential read)。对非唯一索引进行等值查找.
scott@orclpdb1:orclcdb> select * from test where object_id=100;1 row selected.Execution Plan
----------------------------------------------------------
Plan hash value: 3297604684----------------------------------------------------------------------------------------------
| Id  | Operation                           | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
----------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                    |        |     1 |   132 |     2   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID BATCHED| TEST   |     1 |   132 |     2   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN                  | IDX_ID |     1 |       |     1   (0)| 00:00:01 |
----------------------------------------------------------------------------------------------Predicate Information (identified by operation id):
---------------------------------------------------2 - access("OBJECT_ID"=100)Statistics
----------------------------------------------------------136  recursive calls0  db block gets408  consistent gets33  physical reads0  redo size2686  bytes sent via SQL*Net to client621  bytes received via SQL*Net from client2  SQL*Net roundtrips to/from client74  sorts (memory)0  sorts (disk)1  rows processedscott@orclpdb1:orclcdb> 

索引范围扫描默认是从索引中最左边的叶子块开始,然后往右边的叶子块扫描(从小到大),当检查到不匹配数据的时候,就停止扫描。

scott@orclpdb1:orclcdb> select * from test where object_id<100 order by object_id desc;98 rows selected.Execution Plan
----------------------------------------------------------
Plan hash value: 1069979465---------------------------------------------------------------------------------------
| Id  | Operation                    | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT             |        |    94 | 12408 |     5   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID | TEST   |    94 | 12408 |     5   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN DESCENDING| IDX_ID |    94 |       |     2   (0)| 00:00:01 |
---------------------------------------------------------------------------------------Predicate Information (identified by operation id):
---------------------------------------------------2 - access("OBJECT_ID"<100)Statistics
----------------------------------------------------------1  recursive calls0  db block gets18  consistent gets1  physical reads0  redo size14379  bytes sent via SQL*Net to client711  bytes received via SQL*Net from client8  SQL*Net roundtrips to/from client0  sorts (memory)0  sorts (disk)98  rows processedscott@orclpdb1:orclcdb> 

INDEX RANGE SCAN DESCENDING 表示索引降序范围扫描,从右往左扫描,返回的数据是降序显示的。

7.INDEX SKIP SCAN

  • 索引跳跃扫描,单块读。
  • 返回的数据是有序的
  • HINT:INDEX_SS(表名/别名 索引名)
  • 当组合索引的引导列(第一个列)没有在where条件中,并且组合索引的引导列/前几个列的基数很低,where过滤条件对组合索引中非引导列进行过滤的时候就会发生索引跳跃扫描。
  • 等待事件为 db file sequential read.
scott@orclpdb1:orclcdb> create index idx_ownerid on test(owner,object_id);Index created.scott@orclpdb1:orclcdb> drop index idx_id;Index dropped.scott@orclpdb1:orclcdb> select * from test where object_id<100;98 rows selected.Execution Plan
----------------------------------------------------------
Plan hash value: 607061290---------------------------------------------------------------------------------------------------
| Id  | Operation                           | Name        | Rows  | Bytes | Cost (%CPU)| Time     |
---------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                    |             |    94 | 12408 |    42   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID BATCHED| TEST        |    94 | 12408 |    42   (0)| 00:00:01 |
|*  2 |   INDEX SKIP SCAN                   | IDX_OWNERID |    94 |       |    39   (0)| 00:00:01 |
---------------------------------------------------------------------------------------------------Predicate Information (identified by operation id):
---------------------------------------------------2 - access("OBJECT_ID"<100)filter("OBJECT_ID"<100)Statistics
----------------------------------------------------------59  recursive calls0  db block gets92  consistent gets17  physical reads0  redo size14379  bytes sent via SQL*Net to client466  bytes received via SQL*Net from client8  SQL*Net roundtrips to/from client6  sorts (memory)0  sorts (disk)98  rows processedscott@orclpdb1:orclcdb> 

8.INDEX FULL SCAN

  • INDEX FULL SCAN 表示索引全扫描,单块读,返回的数据是有序的。
  • HINT:INDEX(表名/别名 索引名)
  • 索引全扫描会扫描索引中所有的叶子块(从左往右扫描)
  • 若索引很大,会产生严重的性能问题(因为是单块读)
  • 等待事件: db file sequential read
scott@orclpdb1:orclcdb> select * from test order by object_id,owner;73516 rows selected.Execution Plan
----------------------------------------------------------
Plan hash value: 2007178810-----------------------------------------------------------------------------------
| Id  | Operation          | Name | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
-----------------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |      | 73516 |  9476K|       |  2570   (1)| 00:00:01 |
|   1 |  SORT ORDER BY     |      | 73516 |  9476K|    13M|  2570   (1)| 00:00:01 |
|   2 |   TABLE ACCESS FULL| TEST | 73516 |  9476K|       |   399   (1)| 00:00:01 |
-----------------------------------------------------------------------------------Statistics
----------------------------------------------------------1  recursive calls0  db block gets1430  consistent gets0  physical reads0  redo size4868592  bytes sent via SQL*Net to client54537  bytes received via SQL*Net from client4903  SQL*Net roundtrips to/from client1  sorts (memory)0  sorts (disk)73516  rows processedscott@orclpdb1:orclcdb> create index idx_idowner on test(object_id,owner,0);Index created.scott@orclpdb1:orclcdb> select * from test order by object_id,owner;73516 rows selected.Execution Plan
----------------------------------------------------------
Plan hash value: 3870803568-------------------------------------------------------------------------------------------
| Id  | Operation                   | Name        | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |             | 73516 |  9476K|  1865   (1)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID| TEST        | 73516 |  9476K|  1865   (1)| 00:00:01 |
|   2 |   INDEX FULL SCAN           | IDX_IDOWNER | 73516 |       |   234   (1)| 00:00:01 |
-------------------------------------------------------------------------------------------Statistics
----------------------------------------------------------1  recursive calls0  db block gets11531  consistent gets232  physical reads0  redo size4868592  bytes sent via SQL*Net to client54316  bytes received via SQL*Net from client4903  SQL*Net roundtrips to/from client0  sorts (memory)0  sorts (disk)73516  rows processedscott@orclpdb1:orclcdb>

9.INDEX FAST FULL SCAN

  • 索引快速全扫描,多块读。
  • HINT:INDEX_FFS(表名/别名 索引名)
  • 等待事件 db file scattered read
scott@orclpdb1:orclcdb> drop index idx_ownername;Index dropped.scott@orclpdb1:orclcdb> create index idx_ownername on test(owner,object_name,0);Index created.scott@orclpdb1:orclcdb> select owner,object_name from test;73516 rows selected.Execution Plan
----------------------------------------------------------
Plan hash value: 3888663772--------------------------------------------------------------------------------------
| Id  | Operation            | Name          | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT     |               | 73516 |  2871K|   146   (0)| 00:00:01 |
|   1 |  INDEX FAST FULL SCAN| IDX_OWNERNAME | 73516 |  2871K|   146   (0)| 00:00:01 |
--------------------------------------------------------------------------------------Statistics
----------------------------------------------------------1  recursive calls0  db block gets5405  consistent gets537  physical reads0  redo size3773365  bytes sent via SQL*Net to client54307  bytes received via SQL*Net from client4903  SQL*Net roundtrips to/from client0  sorts (memory)0  sorts (disk)73516  rows processedscott@orclpdb1:orclcdb> create index idx_id on test(object_id);Index created.scott@orclpdb1:orclcdb> select object_name from test where object_id<100;98 rows selected.Execution Plan
----------------------------------------------------------
Plan hash value: 3297604684----------------------------------------------------------------------------------------------
| Id  | Operation                           | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
----------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                    |        |    94 |  3760 |     5   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID BATCHED| TEST   |    94 |  3760 |     5   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN                  | IDX_ID |    94 |       |     2   (0)| 00:00:01 |
----------------------------------------------------------------------------------------------Predicate Information (identified by operation id):
---------------------------------------------------2 - access("OBJECT_ID"<100)Statistics
----------------------------------------------------------1  recursive calls0  db block gets18  consistent gets1  physical reads0  redo size2851  bytes sent via SQL*Net to client476  bytes received via SQL*Net from client8  SQL*Net roundtrips to/from client0  sorts (memory)0  sorts (disk)98  rows processedscott@orclpdb1:orclcdb> create index idx_idname on test(object_id,object_name);Index created.scott@orclpdb1:orclcdb> select object_name from test where object_id<100;98 rows selected.Execution Plan
----------------------------------------------------------
Plan hash value: 3678957952-------------------------------------------------------------------------------
| Id  | Operation        | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------
|   0 | SELECT STATEMENT |            |    94 |  3760 |     2   (0)| 00:00:01 |
|*  1 |  INDEX RANGE SCAN| IDX_IDNAME |    94 |  3760 |     2   (0)| 00:00:01 |
-------------------------------------------------------------------------------Predicate Information (identified by operation id):
---------------------------------------------------1 - access("OBJECT_ID"<100)Statistics
----------------------------------------------------------1  recursive calls0  db block gets9  consistent gets1  physical reads0  redo size2851  bytes sent via SQL*Net to client476  bytes received via SQL*Net from client8  SQL*Net roundtrips to/from client0  sorts (memory)0  sorts (disk)98  rows processedscott@orclpdb1:orclcdb> select object_name from test where object_id>100;73415 rows selected.Execution Plan
----------------------------------------------------------
Plan hash value: 252646278-----------------------------------------------------------------------------------
| Id  | Operation            | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
-----------------------------------------------------------------------------------
|   0 | SELECT STATEMENT     |            | 73420 |  2867K|   142   (1)| 00:00:01 |
|*  1 |  INDEX FAST FULL SCAN| IDX_IDNAME | 73420 |  2867K|   142   (1)| 00:00:01 |
-----------------------------------------------------------------------------------Predicate Information (identified by operation id):
---------------------------------------------------1 - filter("OBJECT_ID">100)Statistics
----------------------------------------------------------1  recursive calls0  db block gets5386  consistent gets513  physical reads0  redo size3530801  bytes sent via SQL*Net to client54686  bytes received via SQL*Net from client4896  SQL*Net roundtrips to/from client0  sorts (memory)0  sorts (disk)73415  rows processedscott@orclpdb1:orclcdb> 

10.INDEX FULL SCAN(MIN/MAX)

  • 索引最小、最大值扫描、单块读
  • INDEX FULL SCAN(MIN/MAX) 只会访问“索引高度”个索引块,其性能与INDEX UNIQUE SCAN一样,其性能仅次于TABLE ACCESS BY USER ROWID

11.MAT_VIEW REWRITE ACCESS FULL

  • MAT_VIEW REWRITE ACCESS FULL 表示物化视图全表扫描、多块读。
  • 因为物化视图本质上也是一个表,所以其扫描方式与全表扫描一样。
scott@orclpdb1:orclcdb>
scott@orclpdb1:orclcdb>
scott@orclpdb1:orclcdb> create materialized view test_mv build immediate enable query rewrite 2  as select object_id,object_name from test;Materialized view created.scott@orclpdb1:orclcdb> select object_id,object_name from test;73516 rows selected.Execution Plan
----------------------------------------------------------
Plan hash value: 1627509066----------------------------------------------------------------------------------------
| Id  | Operation                    | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
----------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT             |         | 73516 |  2799K|   129   (1)| 00:00:01 |
|   1 |  MAT_VIEW REWRITE ACCESS FULL| TEST_MV | 73516 |  2799K|   129   (1)| 00:00:01 |
----------------------------------------------------------------------------------------Statistics
----------------------------------------------------------36  recursive calls12  db block gets5370  consistent gets453  physical reads1980  redo size4184006  bytes sent via SQL*Net to client54311  bytes received via SQL*Net from client4903  SQL*Net roundtrips to/from client2  sorts (memory)0  sorts (disk)73516  rows processedscott@orclpdb1:orclcdb> 

因为物化视图TEST_MV 已经包含查询需要的字段,所以该SQL会直接访问物化视图TEST_MV.

2单块单读与多块读

  • 单块读:从磁盘1次读取1个块到buffer cache.
  • 多块读:从磁盘1次读取多个块到buffer cache.
  • 如果数据块都已经缓存在buffer cache中,那就不需要物理I/O了,没有物理I/O也就不存在单块读与多块读。
  • 绝大数的平台,一次I/O最多只能读取或者写入1MB数据。
  • Oracle的块大小默认是8K,那么一次I/O最多只能写入128个块到磁盘,最多只能读取128个块到buffer cache.
  • 在判断哪个访问路径性能好的时候,通常是估算每次访问的I/O次数,谁的I/O次数少,谁的性能就好。在估算I/O次数的时候,我们只需要算个大概即可。

优化高手都需要深入的访问路径(ACCESS PATH)相关推荐

  1. 友盟页面访问路径全量统计功能上线啦!

    友盟友都知道,页面访问路径,不仅能够帮助开发者了解 App 各个页面的访问和跳转数据情况,也能对用户的行为做一个好的数据追踪. 友盟页面访问路径针对用户在具体操作过程中的行为,将已有的页面访问路径改版 ...

  2. SQL性能第2篇:查询分析和访问路径制定

    女主宣言 在SQL性能概述的第一部分中,我们研究了关系优化及其影响因素.在今天的文章中,我们将注意力转向查询分析以及SQL转换为可执行代码的方式.希望对大家在SQL性能优化方面有所帮助. PS:丰富的 ...

  3. idea 启动php项目路径,关于idea中Java Web项目的访问路径问题

    说明 这里只以 servlet 为例,没有涉及到框架,但其实路径的基本原理和框架的关系不大,所以学了框架的同学如果对路径有疑惑的也可以阅读此文 项目结构 在 idea 中新建一个 Java Web 项 ...

  4. 各种访问路径和路径跳转总结篇

    路径 从一个点到另一个点的过程称为路径. 从一个起点到某个具体资源的过程称为访问路径,访问路径的最后一个斜杠(/)后面的是资源名称. 绝对资源路径是从起点http://开始到某个具体资源的前面的最后一 ...

  5. 十步优化SQL Server中的数据访问

    故事开篇:你和你的团队经过不懈努力,终于使网站成功上线,刚开始时,注册用户较少,网站性能表现不错,但随着注册用户的增多,访问速度开始变慢,一些用户开始发来邮件表示抗议,事情变得越来越糟,为了留住用户, ...

  6. seo优化高手让你明白玩转seo其实并不难

    随着互联网的高速发展很多企业渐渐发现互联网营销的重要性以及seo的需求性,像seo这种免费的并且能够带来精准流量的好处,哪个企业会错过?不再局限于本地,直接面向全国甚至全球行业,相信几句话就能让你明白 ...

  7. 从零开始带你成为MySQL实战优化高手学习笔记(一)

    重复是有必要的. 很多新入职的小朋友可能和现在的我一样,对数据库的了解仅仅停留在建库建表增删改查这些操作,日常工作也都是用封装好的代码,别说底层原理了,数据库和系统之间是如何工作都不是很懂. 长此以往 ...

  8. SpringBoot系列三:SpringBoot基本概念(统一父 pom 管理、SpringBoot 代码测试、启动注解分析、配置访问路径、使用内置对象、项目打包发布)...

    声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 1.了解SpringBoot的基本概念 2.具体内容 在之前所建立的 SpringBoot 项目只是根据官方文档实现的一个基础程 ...

  9. HTML基础(四):注释、URL参数、访问路径、图片地图

    1.注释:<!- -内容- -> <body><iframesrc="http://www.sina.com.cn"height="300& ...

最新文章

  1. Mysql是时候学习一个存储过程了
  2. 【AI2】更新app inventor2离线开发环境AppInventor2021,安卓app图形化开发环境
  3. 4.1.3 文件目录
  4. 计算机专业是否限制语种,高考日语选什么专业(如果高考选日语,大学选专业有什么限制)...
  5. 00_设计模式6大原则
  6. angularjs初始化时不显示模板内容, 不显示html, 不显示template
  7. la环球乐园里的机器人_北京环球度假区核心工程完工,你知道这里面都有什么主题景区吗?...
  8. ef core中如何实现多对多的表映射关系
  9. 一大波人气博主袭来,现场直播华为全联接2020!
  10. 基于JAVA+Servlet+JSP+MYSQL的毕业生离校管理系统
  11. 【PAT乙】1038 统计同成绩学生 (20分) 裸桶排序
  12. js或css指定元素点击时内容不可被选中
  13. CSS—内联样式(行内样式)、内部样式、外部样式、选择器
  14. 数据结构课程设计——校园导游
  15. 16. Spring boot 错误页面
  16. 利用igraph包绘制网络图
  17. Allegro Design Entry CIS 和 Orcad Capture CIS 区别
  18. 你的睡眠时间和睡眠质量达标了么?
  19. 数仓、数据湖、湖仓一体、数据网格的探索与研究
  20. 罗德里格旋转公式推导

热门文章

  1. python第五章课后题答案超星_Python数据分析与数据可视化章节考试题库
  2. 语音合成(speech synthesis)方向六:歌唱合成(singing voice synthesis)
  3. 服务器上批量将.mp4格式的视频转化成.m3u8的shell脚本
  4. vs2019 android,VS2019无法安装Android SDK 28的问题
  5. eMMC工作模式 - 超详细原理讲解
  6. kali------kali更新源
  7. MT5016A-ASEMI三相电机整流桥MT5016A
  8. 建模之数据处理常用方法
  9. 算一个数的阶乘(例如100的阶乘)
  10. 精简70%、内存不到1G,可以装在显卡上的Win11来了