index的结构,non-unique index及unique index在row piece上存放的一些区别

index的结构,non-unique index及unique index在row piece上存放的一些区别:
non-unique index:
kdxledsz 0 --bytes in rowid data
row#0[7975] flag: ------, lock: 0, len=57
col 0; len 2; (2):  c1 02
col 1; len 2; (2):  c1 02
col 2; len 16; (16):  33 33 30 31 30 30 30 30 30 39 32 39 36 30 34 35
col 3; len 1; (1):  30
col 4; len 22; (22):
50 45 43 44 32 30 30 36 33 33 30 31 30 30 30 34 30 31 31 35 36 32
col 5; len 6; (6):  16 c4 a9 0f 00 26--rowid
rowid 存放在一个列里面;
unique index:
kdxledsz 6
kdxlebksz 8032
row#0[8020] flag: ——, lock: 0, len=12, data6):  01 00 00 3c 02 08 --rowidcol 0; len 3; (3):  c2 06 16
rowid 存放在行头里;
对于non-unique index,rowid 放在行的末尾的一个列中,可能是为了对于相同的key值来做排序用的;
但对unique index,为啥没有将rowid存放在行的末尾的一个列中,而存放在行头中,oracle是出于啥目的这样做的呢?
欢迎大家来猜测。。

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.

这个东西其实远没有想象地那么复杂。Oracle这样做,主要是为optimizer提供执行信息,出于sql语句的性能考虑。

考虑这样一个sql语句:
"select ...  where x =:x and y = :y and ...."
如果是uniqueue index,这个sql只会返回one row。
但是,如果是non-uniqueue index,这个sql会返回1...N行(本质上来说,就是“index range scan”)。
仅仅是这样,performance的影响是看不出来的。
但是,如果是多表连接,返回是one row或者N行,CBO会考虑不同的join方式(nestloop和sort-merge)。

结论是:
rowid存放到行尾,还是行头,只是uniqueue和non-uniqueue本身的的一个标志,没有什么本质区别。“bit for bit, byte for byte, they would be the same。”

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26188260/viewspace-713925/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/26188260/viewspace-713925/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值