index ffs、index fs原理考究-1109
h2 { margin-top: 0.46cm; margin-bottom: 0.46cm; direction: ltr; line-height: 173%; text-align: justify; page-break-inside: avoid }
h2.western { font-family: "Cambria", serif; font-size: 16pt }
h2.cjk { font-family: "宋体"; font-size: 16pt }
h2.ctl { font-size: 16pt }
h1 { margin-top: 0.6cm; margin-bottom: 0.58cm; direction: ltr; line-height: 241%; text-align: justify; page-break-inside: avoid }
h1.western { font-family: "Calibri", serif; font-size: 22pt }
p { margin-bottom: 0.25cm; direction: ltr; line-height: 120%; text-align: justify }
a:link { color: rgb(0, 0, 255) }
1.创建测试表
SQL>
CREATE TABLE TEST AS SELECT * FROM dba_objects WHERE 0=1;
2.创建测试索引
SQL>
CREATE INDEX ind_test_id ON TEST(object_id);
3.插入测试数据
SQL>
INSERT INTO TEST SELECT * FROM dba_objects WHERE
object_id IS NOT NULL AND object_id > 10000 ORDER BY object_id
DESC;
17837
rows created.
4.分析表
附带索引等等
SQL>
analyze table test compute statistics for table for all columns for
all indexes;
Table
analyzed.
5.打开执行计划
SQL>
set autotrace trace;
6.FFS示例
SQL>
select object_id from test;
17837
rows selected.
Execution
Plan
----------------------------------------------------------
0
SELECT STATEMENT Optimizer=CHOOSE (Cost=68 Card=17837
Bytes=71348)
1
0 TABLE ACCESS (FULL) OF 'TEST' (Cost=68 Card=17837 Bytes=71348)
这时候
Oracle会选择全表扫描,因为
object_id
列默认是可以为null的,来修改成
not null
6.1修改字段属性
not null
SQL>alter
table test modify(object_id not null);
6.2再次验证
FFS
SQL>
select object_id from test;
17837
rows selected.
Execution
Plan
----------------------------------------------------------
0
SELECT STATEMENT Optimizer=CHOOSE (Cost=11 Card=17837
Bytes=71348)
1
0 INDEX (FAST FULL SCAN) OF 'IND_TEST_ID' (NON-UNIQUE) (Cost=11
Card=17837 Bytes=71348)
没有问题
7. IFS
示例
SQL>
select/*+ index(test ind_TEST_ID)*/ object_id from test;
17837
rows selected.
Execution
Plan
----------------------------------------------------------
0
SELECT STATEMENT Optimizer=CHOOSE (Cost=41 Card=17837
Bytes=71348)
1
0 INDEX (FULL SCAN) OF 'IND_TEST_ID' (NON-UNIQUE) (Cost=101
Card=17837 Bytes=71348)
没有问题
我们看到了两者都可以在这种情况下使用,那么他们有什么区别呢?有个地方可以看出两者的区别,
来看一下两者的输出结果,为了让大家看清楚一点,我们只取10行。
8结果验证
SQL>
set arraysize 1000;
SQL>
alter system flush buffer_cache; ----一定要刷新,不然观察不到
db file sequential
read
SQL>
alter system flush shared_pool;
SQL>
alter session set events '10046 trace name context forever, level 8';
8.1FFS(INDEX
FAST FULL SCAN)
SQL>
select object_id from test where rownum<11;
OBJECT_ID
----------
66266
66267
66268
66269
66270
66271
66272
66273
66274
66275
10
rows selected.
SQL>
alter session set events '10046 trace name context off';
检查该索引所属文件号、段头快
SQL>
select owner,header_file,header_block from dba_segments where
segment_name='IND_TEST_ID';
OWNER
HEADER_FILE HEADER_BLOCK
------------------------------
----------- ------------
OWNER
4 3562
段头块为
3562,后退一个即
索引的 root block
3563
SQL>
set arraysize 1000;
SQL>
alter system flush buffer_cache; ----一定要刷新,不然观察不到
db file sequential
read
SQL>
alter system flush shared_pool;
SQL>
alter session set events '10046 trace name context forever, level 8';
以下内容取自
10046 event trace文件
|
===================== PARSING select END PARSE EXEC WAIT WAIT WAIT WAIT WAIT WAIT FETCH WAIT WAIT FETCH STAT STAT WAIT *** 结论:FFS会读取 最开始扫描的是3562,它是索引的段头,并且是单块读(注意:段头都是单块读),然后才是从3563 |
8.2FS(INDEX
FULL SCAN)
SQL>
set arraysize 1000;
SQL>
alter system flush buffer_cache; ----一定要刷新,不然观察不到
db file sequential
read
SQL>
alter system flush shared_pool;
SQL>
alter session set events '10046 trace name context forever, level 8';
SQL>
select/*+ index(test ind_TEST_ID)*/ object_id from test where
rownum<11;
OBJECT_ID
----------
10616
12177
12178
12179
12301
13495
13536
13539
13923
16503
10
rows selected.
SQL>
alter session set events '10046 trace name context off';
以下内容取自
10046 event trace文件
|
===================== PARSING select/*+ END PARSE EXEC WAIT WAIT WAIT FETCH WAIT WAIT FETCH STAT STAT WAIT *** 结论:这个索引的段头块是3562,root |
结论:两者的结果完全不一样,这是为什么呢?
|
这是因为当进行index 而进行index |
9.原因考证
归纳:
|
索引类别 |
访问方式 |
是否排序 |
|
FFS |
先扫描 segment |
多一步 sort |
|
FS |
不扫描 segment |
自动的执行 sort |
详情
|
为什么 为什么 |
index ffs、index fs原理考究-1109的更多相关文章
- 【从翻译mos文章】采用高速全扫描索引(index ffs) 为了避免全表扫描
采用高速全扫描索引(index ffs) 为了避免全表扫描 参考原始: Index Fast Full Scan Usage To Avoid Full Table Scans (Doc ID 701 ...
- index index.html index.htm index.php
server { listen 80; server_name localhost; index index.html index.htm index.php;#前后顺序有关系,越在前优先级别越高 r ...
- nginx -t "nginx: [warn] only the last index in "index" directive should be absolute in 6 "的问题解决
修改完nginx的配置文件之后,执行nginx -t命令提示"nginx: [warn] only the last index in "index" directive ...
- 14.8.11 Physical Structure of an InnoDB Index InnoDB Index 的物理结构
14.8.11 Physical Structure of an InnoDB Index InnoDB Index 的物理结构 所有的InnoDB indexes 是 B-trees Index r ...
- 14.2.5.4 Physical Structure of an InnoDB Index InnoDB Index 的物理结构
14.2.5.4 Physical Structure of an InnoDB Index InnoDB Index 的物理结构 所有的InnoDB indexes 是B-trees ,index ...
- MySQL 执行计划中Extra(Using where,Using index,Using index condition,Using index,Using where)的浅析
关于如何理解MySQL执行计划中Extra列的Using where.Using Index.Using index condition,Using index,Using where这四者的区别 ...
- [Oacle][Partition]Partition操作与 Index, Global Index 的关系
[Oacle][Partition]Partition操作与 Index, Global Index 的关系: ■ Regarding the local index and the global i ...
- C 缓冲区过读 if (index >= 0 && index < len)
C 缓冲区过读 if (index >= 0 && index < len) CWE - CWE-126: Buffer Over-read (3.2) http://cw ...
- Sql Server中的表访问方式Table Scan, Index Scan, Index Seek
1.oracle中的表访问方式 在oracle中有表访问方式的说法,访问表中的数据主要通过三种方式进行访问: 全表扫描(full table scan),直接访问数据页,查找满足条件的数据 通过row ...
随机推荐
- android--使用Struts2服务端与android交互
一,服务器端: web.xml文件: <?xml version="1.0" encoding="UTF-8"?> <web-app vers ...
- lc面试准备:Reverse Bits
1 题目 Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represente ...
- SQL*Net more data from client
SQL*Net more data from client The server is waiting on the client to send more data to its client sh ...
- 分布式文件系统MFS(moosefs)实现存储共享(第二版)
分布式文件系统MFS(moosefs)实现存储共享(第二版) 作者:田逸(sery@163.com) 由于用户数量的不断攀升,我对访问量大的应用实现了可扩展.高可靠的集群部署(即lvs+keepali ...
- 对于利用pca 和 cca 进行fmri激活区识别的理解
1.pca 抛开fmri研究这个范畴,我们有一个超长向量,这个超长向量在fmri研究中,就是体素数据.向量中的每个数值,都代表在相应坐标轴下的坐标值.这些坐标轴所组成的坐标系,其实是标准单位坐标系.向 ...
- Ubuntu学习笔记-win7&Ubuntu双系统简单搭建系统指南
win7&Ubuntu双系统简单搭建系统指南 本文是自己老本子折腾Ubuntu的一些记录,主要是搭建了一个能够足够娱乐(不玩游戏)专注练习自己编程能力的内容.只是简单的写了关于系统的安装和一些 ...
- UVa 10294 Arif in Dhaka (First Love Part 2)(置换)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35397 [思路] Polya定理. 旋转:循环节为gcd(i,n) ...
- SQL Server阻止了对组件xp_cmdshell过程的解决方案
使用SQL tools连接sqlserver时候出现以下问题: SQL Server阻止了对组件xp_cmdshell过程的解决方案错误描述:SQL Server阻止了对组件‘xp_cmdshell’ ...
- 长沙Uber优步司机奖励政策(1月18日~1月24日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- 关于android 自己实现 back键 home键
今天在被问到一个问题的时候突然想要看看这些东西了.因为一直以来,我返回上个界面,和大家普遍的方法都是一样的. 1. finish()本页面. 2. intent 跳转到上个页面. 一 ,在 按下手机上 ...