介绍Oracle Virtual Index虚拟索引(二)

2014-11-24 17:46:40 · 作者: · 浏览: 1
econds




我们可以从bo#编号,确定的确是数据表scott.t的索引对象。那么,我们思考一个问题,既然ind$中存在对应记录,为什么dba_indexes不能检索到这个信息呢?



通过抽取dba_indexes的源码信息,我们可以猜到端倪。




from sys.ts$ ts, sys.seg$ s,


sys.user$ iu, sys.obj$ io, sys.user$ u,sys.ind$ i,sys.obj$ o,


sys.user$ itu, sys.obj$ ito, sys.deferred_stg$ ds


where u.user# = o.owner#


and o.obj# = i.obj#


and i.bo# = io.obj#


and io.owner# = iu.user#


and bitand(i.flags, 4096) = 0


and bitand(o.flags, 128) = 0


and i.ts# = ts.ts# (+)


and i.file# = s.file# (+)


and i.block# = s.block# (+)


and i.ts# = s.ts# (+)


and i.obj# = ds.obj# (+)


and i.indmethod# = ito.obj# (+)


and ito.owner# = itu.user# (+);




虽然虚拟索引是没有段的,在seg$中必然没有对应记录。但是SQL语句中对于这个条件定义的是外连接。也就是说,即使没有段结构,索引也能显示出来。



疑点就落在对一些列flag标记的bitand操作上了。我们检查一下ind$的基础flags取值,就可以知道原因了。




SQL> select obj#, bitand(flags, 4096) from ind$ where obj# in (78019, 78020);



OBJ# BITAND(FLAGS,4096)


---------- ------------------


780190


780204096



Executed in 0.016 seconds



看来,虽然ind$中包括信息,但是不显示出来,也是Oracle的一个本意。


下面我们继续来看virtual index的实际工作效果。