关于tom书中关于索引的一个问题

简介: 在英文的P469页,有一段描述:如下:There really is no such thing as a nonunique entry in a B*Tree index.

在英文的P469页,有一段描述:

如下:

There really is no such thing as a nonunique entry in a B*Tree index. In a nonunique index, Oracle simply stores the rowid by appending it to the key as an extra column with a length byte to make the key unique. For example, an index such as CREATE INDEX I ON T(X,Y)
is conceptually CREATE UNIQUE INDEX I ON T(X,Y,ROWID). In a unique index, as defined by you, Oracle does not add the rowid to the index key. In a nonunique index, you will find that the data is sorted first by index key values (in the order of the index key) and then by rowid
ascending. In a unique index, the data is sorted only by the index key values.

感谢NinGoo写的例子,记录如下:

/>/>

http://www.itpub.net/showthread.php?s=&threadid=718966&perpage=10&pagenumber=1

create table tt(id int, name varchar2(20));

create unique index ix_t on tt(id);

insert into tt values(1,'a');

insert into tt values(2,'a');

select file_id,block_id from dba_extents where segment_name='IX_T' and owner=USER;

FILE_ID BLOCK_ID
---------- ----------
32 240905

alter system dump datafile 32 block 240905;

检查发现索引数据应该在240905+4
0:Metadata 1:Metadata 2:Metadata 3:Metadata
4:25-50% free 5:unformatted 6:unformatted 7:unformatted

alter system dump datafile 32 block 240909;

检查trace文件

唯一索引:
row#0[8021] flag: ------, lock: 2, len=11, data:(6): 08 03 ac e5 00 00
col 0; len 2; (2): c1 02
row#1[8010] flag: ------, lock: 2, len=11, data:(6): 08 03 ac a9 00 00
col 0; len 2; (2): c1 03
----- end of leaf block dump -----
End dump data blocks tsn: 32 file#: 32 minblk 240909 maxblk 240909

删除索引,在建议非唯一索引,重复以上步骤:

非唯一索引:
row#0[8020] flag: ------, lock: 0, len=12
col 0; len 2; (2): c1 02
col 1; len 6; (6): 08 03 ac e5 00 00
row#1[8008] flag: ------, lock: 0, len=12
col 0; len 2; (2): c1 03
col 1; len 6; (6): 08 03 ac a9 00 00
----- end of leaf block dump -----

End dump data blocks tsn: 32 file#: 32 minblk 240909 maxblk 240909

select dump(rowid,16) from tt ;

DUMP(ROWID,16)
-----------------------------------------------------------
Typ=69 Len=10: 0,1,2a,34,8,3,ac,a9,0,0
Typ=69 Len=10: 0,1,2a,34,8,3,ac,e5,0,0

select * from tt ;

ID NAME
---- ---------
2 a
1 a

可以发现唯一索引中rowid在行头,非唯一索引rowid保存在最后一列中。而且可以发现非唯一索引的长度要大于唯一索引。

目录
相关文章
|
5月前
|
索引
一个简短的补充------对链表练习题的补充补充
一个简短的补充------对链表练习题的补充补充
28 0
|
10月前
|
算法
【错题集-编程题】小红的ABC(字符串 + 找规律)
【错题集-编程题】小红的ABC(字符串 + 找规律)
|
C语言
C语言程序设计(王立柱)第三章答案 指针和数组
只有聪明人才能看见的摘要~( ̄▽ ̄~)~
122 0
|
SQL 算法
​LeetCode刷题实战175:组合两个表
算法的重要性,我就不多说了吧,想去大厂,就必须要经过基础知识和业务逻辑面试+算法面试。所以,为了提高大家的算法能力,这个公众号后续每天带大家做一道算法题,题目就从LeetCode上面选 !
119 0
​LeetCode刷题实战175:组合两个表
|
SQL 存储 自然语言处理
面试官问我索引为什么这快?我好像解释不清楚了
阿粉相信大家肯定都知道,在数据库中加一定量的索引,会让你的查询语句,从原来的 3 秒缩短到零点几秒的程度,但是很多人都不知道为什么要加索引,为什么加了索引之后,你的查询语句就会起飞呢?今天阿粉来聊一下索引。
面试官问我索引为什么这快?我好像解释不清楚了
|
人工智能 算法 BI
​LeetCode刷题实战210:课程表 II
算法的重要性,我就不多说了吧,想去大厂,就必须要经过基础知识和业务逻辑面试+算法面试。所以,为了提高大家的算法能力,这个公众号后续每天带大家做一道算法题,题目就从LeetCode上面选 !
195 0
|
算法
​LeetCode刷题实战26:删除排序数组中的重复项
算法的重要性,我就不多说了吧,想去大厂,就必须要经过基础知识和业务逻辑面试+算法面试。所以,为了提高大家的算法能力,这个公众号后续每天带大家做一道算法题,题目就从LeetCode上面选 !
101 0
CTF从入门到提升(七)insert 等数据表相关操作注入及例题分享
本次分享内容:insert update delete对数据表操作的一些基本问题及例题分享。 insert语法介绍insert插入到某张表中,后面跟上设置的参数以及值。在insert的时候可以使用哪些注入方法呢? 比如这个报错的方法,如果报错可以使用,那么同理其他函数也是可以使用的。
|
存储 算法 数据库
七大查找算法zz
http://blog.jobbole.com/111629/ 原文出处: Poll的笔记    查找是在大量的信息中寻找一个特定的信息元素,在计算机应用中,查找是常用的基本运算,例如编译程序中符号表的查找。
1684 0